Пример #1
0
        /// <summary>
        /// Elements the count.
        /// </summary>
        /// <returns>System.Int64.</returns>
        public long ElementCount()
        {
            if (elementCount.HasValue)
            {
                return(elementCount.Value);
            }

            elementCount = TensorDimensionHelpers.ElementCount(shape);
            return(elementCount.Value);
        }
Пример #2
0
        /// <summary>
        /// Views the specified sizes.
        /// </summary>
        /// <param name="sizes">The sizes.</param>
        /// <returns>Tensor.</returns>
        /// <exception cref="InvalidOperationException">
        /// Cannot use View on a non-contiguous tensor000
        /// or
        /// Output tensor must have the same number of elements as the input
        /// </exception>
        public NDArray 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 NDArray(sizes, TensorDimensionHelpers.GetContiguousStride(sizes), this.storage, this.storageOffset));
        }