示例#1
0
        public static NDArray Maximum(float a, NDArray b)
        {
            var a_t = new NDArray(b.Allocator, b.ElementType, b.Shape);

            TOps.Fill(a_t, a);
            return(Maximum(a_t, b));
        }
示例#2
0
        public static NDArray Constant(float value, IAllocator allocator, DType dtype, params long[] sizes)
        {
            NDArray tensor = new NDArray(allocator, dtype, sizes);

            TOps.Fill(tensor, value);
            return(tensor);
        }
示例#3
0
        public static NDArray Maximum(NDArray a, float b)
        {
            var b_t = new NDArray(a.Allocator, a.ElementType, a.Shape);

            TOps.Fill(b_t, b);
            return(Maximum(a, b_t));
        }
示例#4
0
        public Tensor RandomBernoulli(long[] shape, float p)
        {
            var result = new NDArray(DeviceManager.Current, DType.Float32, shape);

            TOps.RandomBernoulli(result, new SeedSource(), p);
            return(Out(result));
        }
示例#5
0
        /// <summary>
        /// Transposes the specified dimension1.
        /// </summary>
        /// <param name="dimension1">The dimension1.</param>
        /// <param name="dimension2">The dimension2.</param>
        /// <returns>Tensor.</returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// dimension1
        /// or
        /// dimension2
        /// </exception>
        private NDArray Transpose(int dimension1, int dimension2, bool NewContiguous = false)
        {
            if (dimension1 < 0 || dimension1 >= DimensionCount)
            {
                throw new ArgumentOutOfRangeException("dimension1");
            }
            if (dimension2 < 0 || dimension2 >= DimensionCount)
            {
                throw new ArgumentOutOfRangeException("dimension2");
            }

            if (dimension1 == dimension2)
            {
                storage.AddRef();
                return(this);
            }

            var newSizes   = (long[])shape.Clone();
            var newStrides = (long[])strides.Clone();

            ArraySwap(newSizes, dimension1, dimension2);
            ArraySwap(newStrides, dimension1, dimension2);

            if (NewContiguous)
            {
                return(TOps.NewContiguous(new NDArray(newSizes, newStrides, storage, storageOffset)).Reshape(newSizes));
            }

            return(new NDArray(newSizes, newStrides, storage, storageOffset));
        }
示例#6
0
        public Tensor StdDev(Tensor x, int dim)
        {
            if (dim < 0)
            {
                dim = x.Shape.Length + dim;
            }

            return(Out(TOps.Std(In(x), dim, false)));
        }
示例#7
0
        public Tensor RandomNormal(long[] shape, float mean, float stddev, int?seed = null)
        {
            var result     = new NDArray(DeviceManager.Current, DType.Float32, shape);
            var seedSource = new SeedSource();

            if (seed.HasValue)
            {
                seedSource = new SeedSource(seed.Value);
            }
            TOps.RandomNormal(result, seedSource, mean, stddev);
            return(Out(result));
        }
示例#8
0
        public Tensor RandomUniform(long[] shape, float min, float max, int?seed = null)
        {
            var result     = new NDArray(DeviceManager.Current, DType.Float32, shape);
            var seedSource = new SeedSource();

            if (seed.HasValue)
            {
                seedSource = new SeedSource(seed.Value);
            }

            TOps.RandomUniform(result, seedSource, min, max);
            return(Out(result));
        }
示例#9
0
 public Tensor Prod(Tensor x, int dim)
 {
     return(Out(TOps.Prod(In(x), dim)));
 }
示例#10
0
 public float Min(Tensor x)
 {
     return(TOps.MinF(In(x)));
 }
示例#11
0
 public Tensor EqualTo(Tensor a, Tensor b)
 {
     return(Out(TOps.EqualTo(In(a), In(b))));
 }
示例#12
0
 public Tensor Atan2(Tensor lhs, Tensor rhs)
 {
     return(Out(TOps.Atan2(In(lhs), In(rhs))));
 }
示例#13
0
 public Tensor Clip(Tensor x, float min, float max)
 {
     return(Out(TOps.Clip(In(x), min, max)));
 }
示例#14
0
 public Tensor Var(Tensor x, int dim)
 {
     return(Out(TOps.Var(In(x), dim, false)));
 }
示例#15
0
 public float StdDev(Tensor x)
 {
     return(TOps.StdF(In(x)));
 }
示例#16
0
 public float Var(Tensor x)
 {
     return(TOps.VarF(In(x)));
 }
示例#17
0
 public Tensor Acos(Tensor x)
 {
     return(Out(TOps.Acos(In(x))));
 }
示例#18
0
 public Tensor Mean(Tensor x, params int[] dim)
 {
     return(Out(TOps.Mean(In(x), dim)));
 }
示例#19
0
 public Tensor Mean(Tensor x, int dim)
 {
     return(Out(TOps.Mean(In(x), dim)));
 }
示例#20
0
 public float Mean(Tensor x)
 {
     return(TOps.MeanF(In(x)));
 }
示例#21
0
 public Tensor Diag(Tensor x)
 {
     return(Out(TOps.Diag(In(x))));
 }
示例#22
0
 public float Max(Tensor x)
 {
     return(TOps.MaxF(In(x)));
 }
示例#23
0
 public Tensor Atan(Tensor x)
 {
     return(Out(TOps.Atan(In(x))));
 }
示例#24
0
 public float Prod(Tensor x)
 {
     return(TOps.ProdF(In(x)));
 }
示例#25
0
 public Tensor Ceil(Tensor x)
 {
     return(Out(TOps.Ceil(In(x))));
 }
示例#26
0
 public Tensor Maximum(Tensor a, float b)
 {
     return(Out(TOps.Maximum(In(a), b)));
 }
示例#27
0
 public Tensor Cosh(Tensor x)
 {
     return(Out(TOps.Cosh(In(x))));
 }
示例#28
0
 public Tensor Max(Tensor x, int dim)
 {
     return(Out(TOps.Max(In(x), dim)));
 }
示例#29
0
 public Tensor Maximum(Tensor a, Tensor b)
 {
     return(Out(TOps.Maximum(In(a), In(b))));
 }
示例#30
0
 public Tensor Sum(Tensor x, params int[] dim)
 {
     return(Out(TOps.Sum(In(x), dim)));
 }