0

I'm using MathsNet.Numerics lib. I want to do operations on Complex Vectors i.e. I'm
using MathNet.Numerics.LinearAlgebra.Complex
which gives me Vector as Complex version of MathNet.Numerics.LinearAlgebra.Generic.Vector<T>
Operatations on Vectors however don't return objects assignable to Vector:

Complex[] complexData = new Complex[n]
... fill data, fft etc ...
Vector vectorReference = new DenseVector(complexData);
vectorReference = vectorReference.Conjugate(); // Error.

error CS0266: Cannot implicitly convert type 'MathNet.Numerics.LinearAlgebra.Generic.Vector<System.Numerics.Complex>' to 'MathNet.Numerics.LinearAlgebra.Complex.Vector'

Why are the return values of methods that operate on Vectors (e.g. Conjugate and PointwiseMultiply) not assignable to Vectors?

4

1 回答 1

1

类型层次结构:Vector<T> <- Complex.Vector <- Complex.DenseVector

.Net 不支持在覆盖方法时专门返回类型(协方差),因此我们在技术上不能修改Conjugate为返回Complex.Vector,甚至Complex.DenseVector是派生类型。

一般来说,我们建议仅Vector<Complex>在字段和方法参数中期望和使用泛型类型(即) - 或者当您打算重用变量时。在 Math.NET Numerics v3 中,这已被简化,因此几乎不需要使用实际的实现类型。

于 2013-12-04T16:21:27.317 回答