コード例 #1
0
        /// <summary>
        /// Creates a new NdArray filled with the integers from zero to the specified maximum.
        /// </summary>
        /// <param name="device">The device to create the NdArray on.</param>
        /// <param name="numElements">The number of elements of the new NdArray.</param>
        /// <returns>The new NdArray.</returns>
        public static NdArray <T> Counting(IDevice device, int numElements)
        {
            var newArray = new NdArray <T>(new[] { numElements }, device);

            newArray.FillIncrementing(Primitives.Zero <T>(), Primitives.One <T>());

            return(newArray);
        }
コード例 #2
0
        /// <summary>
        /// Creates a new NdArray filled with equaly spaced values using a specifed increment.
        /// </summary>
        /// <param name="device">The device to create the NdArray on.</param>
        /// <param name="start">The starting value.</param>
        /// <param name="stop">The end value, which is not included.</param>
        /// <param name="step">The increment between successive element.</param>
        /// <typeparam name="T">The new NdArray.</typeparam>
        public static NdArray <T> Arange(IDevice device, T start, T stop, T step)
        {
            var op  = ScalarPrimitivesRegistry.For <T, T>();
            var opc = ScalarPrimitivesRegistry.For <int, T>();

            var numberOfElementT   = op.Divide(op.Subtract(stop, start), step);
            var numberOfElementInt = opc.Convert(numberOfElementT);
            var numberOfElement    = Math.Max(0, numberOfElementInt);

            var shape = new[] { numberOfElement };

            var newArray = new NdArray <T>(shape, device);

            newArray.FillIncrementing(start, step);

            return(newArray);
        }
コード例 #3
0
        /// <summary>
        /// Creates a new NdArray of given size filled with equaly spaced values.
        /// </summary>
        /// <param name="device">The device to create the NdArray on.</param>
        /// <param name="start">The starting value.</param>
        /// <param name="stop">The end value, which is not included.</param>
        /// <param name="numElement">The size of the vector.</param>
        /// <returns>The new NdArray.</returns>
        public static NdArray <T> Linspace(IDevice device, T start, T stop, int numElement)
        {
            if (numElement < 2)
            {
                throw new ArgumentException("Linspace requires at least two elements.", "numElement");
            }

            var op = ScalarPrimitivesRegistry.For <T, int>();

            var numElementT = op.Convert(numElement - 1);
            var increment   = op.Divide(op.Subtract(stop, start), numElementT);

            var newArray = new NdArray <T>(new[] { numElement }, device);

            newArray.FillIncrementing(start, increment);

            return(newArray);
        }