Пример #1
0
        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 = new NDStorage();
            Storage.Allocate(dotNetArray.GetType().GetElementType(), new Shape(dims), 1);

            Array internalStrg = Storage.GetData();

            var pufferShape = new Shape(dims);

            pufferShape.ChangeTensorLayout(2);

            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));
            }
        }
Пример #2
0
        /// <summary>
        /// Create a NDStorage by data type and array shape
        /// </summary>
        /// <param name="dtype">The type of arrays elements</param>
        /// <param name="shape">The shape of array/param>
        /// <returns>The constructed NDStorage</returns>
        public static NDStorage CreateByShapeAndType(Type dtype, Shape shape)
        {
            var storage = new NDStorage(dtype);

            storage.Shape = shape;
            storage.Allocate(shape.Size);
            return(storage);
        }
Пример #3
0
        public object Clone()
        {
            var puffer = new NDStorage();

            puffer.Allocate(_DType, new Shape(_Shape.Dimensions), _TensorLayout);
            puffer.SetData((Array)_values.Clone());

            return(puffer);
        }
Пример #4
0
 /// <summary>
 /// Constructor which initialize elements with 0
 /// type and shape are given.
 /// </summary>
 /// <param name="dtype">internal data type</param>
 /// <param name="shape">Shape of NDArray</param>
 public NDArray(Type dtype, Shape shape)
 {
     Storage = new NDStorage();
     Storage.Allocate(dtype, shape, 1);
 }