Ejemplo n.º 1
0
        public static XArray Reduce(XArray x, int[] axes, double p1, int p2, int p3, ReduceFunc op)
        {
            unsafe
            {
                List <long> newshape = new List <long>();
                for (int i = 0; i < x.Shape.Data.Length; i++)
                {
                    if (!axes.Contains(i))
                    {
                        newshape.Add(x.Shape[i]);
                    }
                    else
                    {
                        newshape.Add(1);
                    }
                }

                fixed(int *axes_ptr = axes)
                {
                    XArray r = new XArray(new Shape(newshape.ToArray()), x.DataType);

                    NativeWrapper.TS_Reduce(x.GetRef(), axes_ptr, axes.Length, r.GetRef(), p1, p2, p3, (int)op);
                    return(r);
                }
            }
        }
Ejemplo n.º 2
0
        public static XArray ReduceAll(XArray x, ReduceFunc op, double p1 = 0, int p2 = 0)
        {
            XArray r = new XArray(new Shape(1), x.DataType);

            NativeWrapper.TS_ReduceAll(x.GetRef(), r.GetRef(), (int)op, p1, p2);
            return(r);
        }
Ejemplo n.º 3
0
 //The A syncronous function that will run the Reduce function Asyncronoulsly
 public async Task <T> ReduceAsync(ReduceFunc rf)
 {
     return(await Task.Run(() =>
     {
         Reduce(rf);
         return accum;
     }));
 }
Ejemplo n.º 4
0
 //Reduce function that will take the given lamda function
 //and pass the accumulator and the given values to the function
 public void Reduce(ReduceFunc rf)
 {
     //if the list is empty return default value
     if (Count == 0)
     {
         accum = default(T);
     }
     else
     {
         //Assign the first value to the accumulator
         accum = lvals[0];
         for (int i = 1; i < Count; i++)
         {
             //Call the function
             accum = rf(accum, lvals[i]);
         }
     }
 }
Ejemplo n.º 5
0
        public static XArray Accumulating(XArray x, int axis, ReduceFunc op)
        {
            List <long> newshape = new List <long>();

            for (int i = 0; i < x.Shape.Data.Length; i++)
            {
                if (i != axis)
                {
                    newshape.Add(x.Shape[i]);
                }
                else
                {
                    newshape.Add(1);
                }
            }

            XArray r = new XArray(new Shape(newshape.ToArray()), x.DataType);

            NativeWrapper.TS_Accumulating(x.GetRef(), axis, r.GetRef(), (int)op);
            return(r);
        }