Esempio n. 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 Tensor arange(Scalar start, Scalar stop, Scalar step, torch.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 Tensor(res));
            }
Esempio n. 2
0
 public static Device InitializeDevice(torch.Device device)
 {
     if (device == null)
     {
         device = torch.CPU;
     }
     InitializeDeviceType(device.type);
     return(device);
 }
Esempio n. 3
0
 /// <summary>
 /// Moves the parameters and buffers.
 /// </summary>
 /// <param name="device">The target device</param>
 /// <returns></returns>
 public Module to(torch.Device device)
 {
     return(to(device.type, device.index));
 }
Esempio n. 4
0
 public Generator(ulong seed = 0, torch.Device?device = null) :
     this(THSGenerator_new(seed, (long)(device?.type ?? DeviceType.CPU), device?.index ?? -1))
 {
     this.device = device ?? torch.CPU;
 }
Esempio n. 5
0
 internal Generator(IntPtr nativeHandle)
 {
     Handle = nativeHandle;
     device = torch.CPU;
 }