如何从具有2维的ILRetArray获取System.Array(double [,])? 有一个方法ExportValues,但结果是double []。
答案 0 :(得分:1)
我找到了How to convert ILArray into double[,] array? 修改T [,]作为结果:
private T[,] ToSystemMatrix<T>(ILInArray<T> A)
{
using (ILScope.Enter(A))
{
// some error checking (to be improved...)
if (object.Equals(A, null)) throw new ArgumentException("A may not be null");
if (!A.IsMatrix) throw new ArgumentException("Matrix expected");
var dims = A.S.ToIntArray();
if (dims.Length != 2) throw new ArgumentException("Matrix with 2 Dimensions expected");
// create return array
var ret = new T[dims[0], dims[1]];
// fetch underlying system array
T[] workArr = A.GetArrayForRead();
// copy memory block
Buffer.BlockCopy(workArr, 0, ret, 0, Marshal.SizeOf(typeof(T)) * A.S.NumberOfElements);
return ret;
}
}