예제 #1
0
/*** Reduce Functions ***/

        public FloatTensor Reduce(
            Func <float, float, long, float[], float> reducer,
            Func <float, long, float> mapper
            )
        {
            int[]   outDims = { 1 };
            float[] output  = new float[1];
            output[0] = mapper(MultiThread.Reduce <float>(data, reducer), Size);

            return(new FloatTensor(ctrl, outDims, output));
        }
예제 #2
0
/*** Reduce Functions ***/

        public FloatTensor Reduce(
            Func <float, float, int, float[], float> reducer,
            Func <float, int, float> mapper
            )
        {
            int[] outDims = { 1 };
            var   output  = new float[1];

            output[0] = mapper(MultiThread.Reduce(data, reducer), Size);

            return(new FloatTensor(controller, outDims, output));
        }
예제 #3
0
/*** Reduce Functions ***/

        public FloatTensor Reduce(
            Func <float, float, int, float[], float> reducer,
            Func <float, int, float> mapper
            )
        {
            int[] outDims = { 1 };
            var   output  = new float[1];

            output[0] = mapper(MultiThread.Reduce(data, reducer), Size);

            return(factory.Create(_shape: outDims, _data: output));
        }
예제 #4
0
        private void _dimForEach(
            int interations,
            int values,
            int stride,
            Action <float[], int, int> iterator
            )
        {
            MultiThread.For(interations, (i, len) =>
            {
                var temp = new float[values];

                int offset = GetDimReduceOffset(i, values, stride);

                for (int v = 0; v < values; v++)
                {
                    temp[v] = this[offset + v * stride];
                }

                iterator(temp, i, temp.Length);
            });
        }
        private void _dimForEach(
            long interations,
            long values,
            long stride,
            Action <float[], long, long> iterator
            )
        {
            MultiThread.For(interations, (i, len) =>
            {
                float[] temp = new float[values];

                long offset = GetDimReduceOffset(i, values, stride);

                for (long v = 0; v < values; v++)
                {
                    temp[v] = data[offset + v * stride];
                }

                iterator(temp, i, temp.Length);
            });
        }
예제 #6
0
        internal void ForEach(
            int dim,
            Action <float[], int, int> iterator
            )
        {
            int interations = size / shape[dim];
            int values      = shape[dim];
            var stride      = strides[dim];

            MultiThread.For(interations, (i, len) =>
            {
                var temp   = new float[values];
                var offset = GetDimReduceOffset(i, values, stride);

                for (int v = 0; v < values; v++)
                {
                    temp[v] = this[offset + v * stride];
                }

                iterator(temp, offset, stride);
            });
        }
예제 #7
0
        internal void ForEach(
            long dim,
            Action <float[], long, long> iterator
            )
        {
            long interations = size / shape[dim];
            long values      = shape[dim];
            var  stride      = strides[dim];

            MultiThread.For(interations, (i, len) =>
            {
                var temp   = new float[values];
                var offset = GetDimReduceOffset(i, values, stride);

                for (long v = 0; v < values; v++)
                {
                    temp[v] = data[offset + v * stride];
                }

                iterator(temp, offset, stride);
            });
        }
 // proccess each item of and array on multiple threads
 public static void ForEach <T>(T[] data, Action <T, long, long> func)
 {
     MultiThread.For(data.Length, (index, len) => func(data[index], index, len));
 }