示例#1
0
        /// <summary>
        /// Create a ndarray of a certain buffer and shape.
        /// </summary>
        /// <param name="buffer">The buffer to back this ndarray.</param>
        /// <param name="shape">The shape.</param>
        public ADNDArray(IDataBuffer <T> buffer, long[] shape)
        {
            if (buffer.Length < ArrayUtils.Product(shape))
            {
                throw new ArgumentException($"Buffer must contain the entire shape, but buffer length was {buffer.Length} and total shape length {ArrayUtils.Product(shape)} (shape = {ArrayUtils.ToString(shape)}).");
            }

            Initialise(NDArrayUtils.CheckShape(shape), NDArrayUtils.GetStrides(shape));

            Data = buffer;
        }
示例#2
0
        /// <summary>
        /// Create an ndarray of a certain array (array will be COPIED into a data buffer) and shape.
        /// Total shape length must be smaller or equal than the data array length.
        /// </summary>
        /// <param name="data">The data to use to fill this ndarray.</param>
        /// <param name="shape">The shape.</param>
        public ADNDArray(T[] data, params long[] shape)
        {
            if (data.Length < ArrayUtils.Product(shape))
            {
                throw new ArgumentException($"Data must contain the entire shape, but data length was {data.Length} and total shape length {ArrayUtils.Product(shape)} (shape = {ArrayUtils.ToString(shape)}).");
            }

            Initialise(NDArrayUtils.CheckShape(shape), NDArrayUtils.GetStrides(shape));

            Data = new DataBuffer <T>(data, 0L, Length);
        }
示例#3
0
        /// <inheritdoc />
        public virtual INDArray ReshapeSelf(params long[] newShape)
        {
            if (Length != ArrayUtils.Product(newShape))
            {
                throw new ArgumentException($"Reshaping cannot change total ndarray length ({Length}), only array shape" +
                                            $" (attempted change from [{string.Join(", ", Shape)}] to [{string.Join(", ", newShape)}]).");
            }

            Reinitialise(NDArrayUtils.CheckShape(newShape), NDArrayUtils.GetStrides(newShape));

            return(this);
        }
示例#4
0
        public static LayerConstruct Construct(string name, string inputAlias, params long[] shape)
        {
            NDArrayUtils.CheckShape(shape);

            LayerConstruct construct = new LayerConstruct(name, typeof(InputLayer));

            construct.ExternalInputs = new[] { inputAlias };
            construct.Parameters["external_input_alias"] = inputAlias;
            construct.Parameters["shape"] = shape;
            construct.Parameters["size"]  = (int)ArrayUtils.Product(shape);

            return(construct);
        }
示例#5
0
 public CudaFloat32NDArray(CudaSigmaDiffDataBuffer <float> buffer, long[] shape) : this(new DNDArray(buffer, NDArrayUtils.CheckShape(shape)))
 {
 }
示例#6
0
 public ADNDFloat32Array(long backendTag, IDataBuffer <float> buffer, long[] shape) : this(new DNDArray(new SigmaDiffDataBuffer <float>(buffer, 0, buffer.Length, backendTag), NDArrayUtils.CheckShape(shape)))
 {
 }
示例#7
0
 public ADNDFloat32Array(long backendTag, float[] data, params long[] shape) : this(new DNDArray(new SigmaDiffDataBuffer <float>(data, backendTag), NDArrayUtils.CheckShape(shape)))
 {
 }
示例#8
0
 public ADFloat32NDArray(long backendTag, params long[] shape) : this(new DNDArray(new SigmaDiffDataBuffer <float>(ArrayUtils.Product(shape), backendTag), NDArrayUtils.CheckShape(shape)))
 {
 }
示例#9
0
        /// <summary>
        /// Create an ndarray of a certain shape (initialised with zeros).
        /// </summary>
        /// <param name="shape">The shape.</param>
        public ADNDArray(params long[] shape)
        {
            Initialise(NDArrayUtils.CheckShape(shape), NDArrayUtils.GetStrides(shape));

            Data = new DataBuffer <T>(Length);
        }