Exemple #1
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>
        /// <remarks>In the case of complex element types, 'arange' will create a complex tensor with img=0 in all elements.</remarks>
        static public TorchTensor arange(TorchScalar start, TorchScalar stop, TorchScalar step, Device device = null, bool requiresGrad = false)
        {
            device = Torch.InitializeDevice(device);

            var handle = THSTensor_arange(start.Handle, stop.Handle, step.Handle, (sbyte)ScalarType.Float32, (int)device.Type, device.Index, requiresGrad);

            if (handle == IntPtr.Zero)
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                handle = THSTensor_arange(start.Handle, stop.Handle, step.Handle, (sbyte)ScalarType.Float32, (int)device.Type, device.Index, requiresGrad);
            }
            if (handle == IntPtr.Zero)
            {
                Torch.CheckForErrors();
            }

            var res = THSTensor_to_type(handle, (sbyte)ScalarType.ComplexFloat32);

            if (res == IntPtr.Zero)
            {
                Torch.CheckForErrors();
            }

            return(new TorchTensor(res));
        }
Exemple #2
0
        /// <summary>
        /// Fills the input Tensor with the value 'val'
        /// </summary>
        public static TorchTensor constant(TorchTensor tensor, TorchScalar val)
        {
            var res = THSInit_constant_(tensor.Handle, val.Handle);

            if (res == IntPtr.Zero)
            {
                Torch.CheckForErrors();
            }
            return(new TorchTensor(res));
        }
        /// <summary>
        /// Returns the cross product of vectors in dimension dim of input and other.
        /// input and other must have the same size, and the size of their dim dimension should be 3.
        /// </summary>
        public TorchTensor cross(TorchScalar other, long dim)
        {
            var res = THSTensor_cross(handle, other.Handle, dim);

            if (res == IntPtr.Zero)
            {
                Torch.CheckForErrors();
            }
            return(new TorchTensor(res));
        }