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))); } } }
/// <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))); } } }
/// <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)); } } }
/// <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))); }