/// <summary> /// Constructor which takes .NET array /// dtype and shape is determined from array /// </summary> /// <param name="values"></param> /// <returns>Array with values</returns> public NDArray(Array values, Shape shape = null) : this(values.GetType().GetElementType()) { int[] strgDim = new int[values.Rank]; for (int idx = 0; idx < strgDim.Length; idx++) { strgDim[idx] = values.GetLength(idx); } Storage = new NDStorage(dtype); Storage.Allocate(dtype, new Shape(strgDim)); switch (values.Rank) { case 1: { Storage.SetData(values); break; } } if (!(shape is null)) { Storage.Reshape(shape); } }
//[TestMethod] public void CheckChangeTensorLayout2D() { var strg2DCpy = (NDStorage)strg2D.Clone(); Assert.IsTrue(Enumerable.SequenceEqual(strg2DCpy.Shape.Dimensions, new int[] { 3, 3 })); Assert.IsTrue(Enumerable.SequenceEqual(strg2DCpy.GetData <Int64>(), new Int64[] { 0, 3, 6, 1, 4, 7, 2, 5, 8 })); Assert.IsTrue(Enumerable.SequenceEqual(strg2DCpy.Shape.Dimensions, new int[] { 3, 3 })); Assert.IsTrue(Enumerable.SequenceEqual(strg2DCpy.GetData <Int64>(), strg2D.GetData <Int64>())); strg2DCpy = (NDStorage)strg2DNonFull.Clone(); Assert.IsTrue(Enumerable.SequenceEqual(strg2DCpy.Shape.Dimensions, new int[] { 5, 2 })); Assert.IsTrue(Enumerable.SequenceEqual(strg2DCpy.GetData <Int64>(), new Int64[] { 0, 5, 1, 6, 2, 7, 3, 8, 4, 9 })); Assert.IsTrue(Enumerable.SequenceEqual(strg2DCpy.Shape.Dimensions, new int[] { 5, 2 })); Assert.IsTrue(Enumerable.SequenceEqual(strg2DCpy.GetData <Int64>(), strg2DNonFull.GetData <Int64>())); strg2DCpy = new NDStorage(typeof(Int64)); strg2DCpy.Allocate(new Shape(5, 2)); strg2DCpy.SetData(strg2DNonFull.GetData()); Assert.IsTrue(Enumerable.SequenceEqual(strg2DCpy.GetData <Int64>(), new Int64[] { 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 })); }
public StorageTester() { strg1D = new NDStorage(np.float64); strg1D.Allocate(np.float64, new Shape(10), 1); strg1D.SetData(new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); strg2D = new NDStorage(np.int64); strg2D.Allocate(np.int64, new Shape(3, 3), 1); strg2D.SetData(new Int64[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }); strg2DNonFull = new NDStorage(np.float32); strg2DNonFull.Allocate(np.float32, new Shape(5, 2), 1); strg2DNonFull.SetData(new float[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); strg3D = new NDStorage(typeof(Complex)); strg3D.Allocate(typeof(Complex), new Shape(2, 2, 2)); strg3D.SetData(new Complex[] { 1, 2, 3, 4, 5, 6, 7, 8 }); strg3DNonFull = new NDStorage(typeof(Complex)); strg3DNonFull.Allocate(typeof(Complex), new Shape(2, 3, 4)); var puffer = new Complex[24]; for (int idx = 1; idx < 25; idx++) { puffer[idx - 1] = new Complex(idx, 0); } strg3DNonFull.SetData(puffer); }
/// <summary> /// Constructor which takes .NET array /// dtype and shape is determined from array /// </summary> /// <param name="values"></param> /// <returns>Array with values</returns> public NDArray(Array values, Shape shape = null) : this(values.GetType().GetElementType()) { if (shape is null) { shape = new Shape(values.Length); } Storage = new NDStorage(dtype); Storage.Allocate(new Shape(shape)); Storage.SetData(values); }
public StorageTester() { Storage1DInt = NDStorage.CreateByShapeAndType(typeof(int), new Shape(6)); Storage1DInt.SetData(new int[] { 0, 1, 2, 3, 4, 5 }); Storage1DDouble = NDStorage.CreateByShapeAndType(typeof(double), new Shape(6)); Storage1DDouble.SetData(new double[] { 0.1, 1.5, 2.2, 3.5, 4.9, 5.0 }); Storage2DInt = NDStorage.CreateByShapeAndType(typeof(int), new Shape(2, 3)); Storage2DInt.SetData(new int[] { 0, 1, 2, 3, 4, 5 }); }