我正在使用MathsNet.Numerics库。我想在复杂向量上做运算,也就是
using MathNet.Numerics.LinearAlgebra.Complex
这给了我Vector作为MathNet.Numerics.LinearAlgebra.Generic.Vector<T>的复杂版本
然而,Vector上的操作不返回可分配给Vector的对象
Complex[] complexData = new Complex[n]
... fill data, fft etc ...
Vector vectorReference = new DenseVector(complexData);
vectorReference = vectorReference.Conjugate(); // Error.错误CS0266:无法隐式将“
MathNet.Numerics.LinearAlgebra.Generic.Vector<System.Numerics.Complex>”类型转换为“MathNet.Numerics.LinearAlgebra.Complex.Vector”
为什么在Vectors (例如Conjugate和PointwiseMultiply)上操作的方法的返回值不能分配给Vectors?
发布于 2013-12-04 16:21:27
类型层次结构:Vector<T> <- Complex.Vector <- Complex.DenseVector
.Net不支持在重写方法时专门化返回类型(协方差),因此我们在技术上不能修改Conjugate以返回Complex.Vector,甚至不能在派生类型中返回Complex.DenseVector。
通常,我们建议只在字段和方法参数中使用泛型类型(即Vector<Complex>) --或者当您打算重用变量时。在Math.NET数字v3中,这已经被简化了,因此几乎不需要使用实际的实现类型。
https://stackoverflow.com/questions/19663833
复制相似问题