Example #1
0
        public static TorchTensor Sparse(TorchTensor indices, TorchTensor values, long[] size, string device = "cpu", bool requiresGrad = false)
        {
            TorchTensor.CheckForCUDA(device);

            unsafe
            {
                fixed(long *psizes = size)
                {
                    return(new TorchTensor(THSTensor_sparse(indices.Handle, values.Handle, (IntPtr)psizes, size.Length, (sbyte)ATenScalarMapping.Float, device, requiresGrad)));
                }
            }
        }
Example #2
0
        /// <summary>
        ///  Create a new tensor filled with random values taken from a normal distribution with mean 0 and variance 1.
        /// </summary>
        static public TorchTensor RandomN(long[] size, string device = "cpu", bool requiresGrad = false)
        {
            TorchTensor.CheckForCUDA(device);

            unsafe
            {
                fixed(long *psizes = size)
                {
                    return(new TorchTensor(THSTensor_randn((IntPtr)psizes, size.Length, (sbyte)ATenScalarMapping.Byte, device, requiresGrad)));
                }
            }
        }
Example #3
0
        /// <summary>
        ///  Create a new tensor filled with random values taken from a uniform distribution in [0, 1).
        /// </summary>
        static public TorchTensor Random(long[] size, string device = "cpu", bool requiresGrad = false)
        {
            TorchTensor.CheckForCUDA(device);

            unsafe
            {
                fixed(long *psizes = size)
                {
                    var tptr = THSTensor_rand((IntPtr)psizes, size.Length, (sbyte)ATenScalarMapping.Float, device, requiresGrad);

                    Torch.AssertNoErrors();
                    return(new TorchTensor(tptr));
                }
            }
        }
Example #4
0
        /// <summary>
        /// Creates 1-D tensor of size [(end - start) / step] with values from interval [start, end) and
        /// common difference step, starting from start
        /// </summary>
        static public TorchTensor Arange(float start, float stop, float step, string device = "cpu", bool requiresGrad = false)
        {
            TorchTensor.CheckForCUDA(device);

            return(new TorchTensor(THSTensor_arange(start.ToScalar().Handle, stop.ToScalar().Handle, step.ToScalar().Handle, (sbyte)ATenScalarMapping.Float, device, requiresGrad)));
        }