public void FromMultiDimArray(Array dotNetArray) { if (dotNetArray.GetType().GetElementType().IsArray) { throw new Exception("Jagged arrays are not allowed here!"); } int[] dims = new int[dotNetArray.Rank]; for (int idx = 0; idx < dims.Length; idx++) { dims[idx] = dotNetArray.GetLength(idx); } Storage = BackendFactory.GetStorage(dotNetArray.GetType().GetElementType()); Storage.Allocate(new Shape(dims)); Array internalStrg = Storage.GetData(); var pufferShape = new Shape(dims); pufferShape.ChangeTensorLayout(); int[] idxDims = null; object valueIdx = null; for (int idx = 0; idx < Storage.Shape.Size; idx++) { idxDims = pufferShape.GetDimIndexOutShape(idx); valueIdx = dotNetArray.GetValue(pufferShape.GetDimIndexOutShape(idx)); internalStrg.SetValue(valueIdx, Storage.Shape.GetIndexInShape(idxDims)); } }
/// <summary> /// Constructor for init data type /// internal storage is 1D with 1 element /// </summary> /// <param name="dtype">Data type of elements</param> public NDArray(Type dtype) { TensorEngine = BackendFactory.GetEngine(); Storage = BackendFactory.GetStorage(dtype); }