Example #1
0
        public Scalar Item()
        {
            var sptr = THSTensor_item(Handle);

            Torch.AssertNoErrors();
            return(new Scalar(sptr));
        }
Example #2
0
 public TorchTensor this[long i1]
 {
     get { return(new TorchTensor(THSTensor_get1(handle, i1))); }
     set
     {
         THSTensor_set1(handle, i1, value.Item().Handle);
         Torch.AssertNoErrors();
     }
 }
Example #3
0
 public static Loss PoissonNLL(bool logInput = true, bool full = false, float eps = 1e-8f, Reduction reduction = Reduction.Mean)
 {
     return((TorchTensor src, TorchTensor target) =>
     {
         var tptr = THSNN_loss_poisson_nll(src.Handle, target.Handle, logInput, full, eps, (long)reduction);
         Torch.AssertNoErrors();
         return new TorchTensor(tptr);
     });
 }
Example #4
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));
                }
            }
        }