Пример #1
0
        // Prepend singleton dimensions until DimensionCount equals newDimCount
        private Tensor PadToDimCount(int newDimCount)
        {
            long[] newSizes = Pad1Prepend(sizes, newDimCount);

            long[] newStrides = TensorDimensionHelpers.GetContiguousStride(newSizes);
            Array.Copy(strides, 0, newStrides, newStrides.Length - strides.Length, strides.Length);

            return(new Tensor(newSizes, newStrides, storage, storageOffset));
        }
Пример #2
0
        // Prepend singleton dimensions until DimensionCount equals newDimCount
        private Tensor PadToDimCount(int newDimCount)
        {
            var newSizes = Pad1Prepend(this.sizes, newDimCount);

            var newStrides = TensorDimensionHelpers.GetContiguousStride(newSizes);

            Array.Copy(this.strides, 0, newStrides, newStrides.Length - this.strides.Length, this.strides.Length);

            return(new Tensor(newSizes, newStrides, this.storage, this.storageOffset));
        }
Пример #3
0
        public Tensor View(params long[] sizes)
        {
            if (!this.IsContiguous())
            {
                throw new InvalidOperationException("Cannot use View on a non-contiguous tensor");
            }

            if (this.ElementCount() != TensorDimensionHelpers.ElementCount(sizes))
            {
                throw new InvalidOperationException("Output tensor must have the same number of elements as the input");
            }

            return(new Tensor(sizes, TensorDimensionHelpers.GetContiguousStride(sizes), this.storage, this.storageOffset));
        }
Пример #4
0
 /// <summary>
 /// Construct a new tensor, using the given allocator to construct a storage. The new tensor
 /// will be contiguous in memory. The tensor's elements will not be initialized.
 /// </summary>
 /// <param name="allocator"></param>
 /// <param name="elementType"></param>
 /// <param name="sizes"></param>
 public Tensor(IAllocator allocator, DType elementType, params long[] sizes)
     : this(allocator, elementType, sizes, TensorDimensionHelpers.GetContiguousStride(sizes))
 {
 }