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