示例#1
0
        protected V ApplyKernels <NumT, T, V, S>(S state, Func <S, V, int, int, int, int, T> applyKernel, V input) where NumT : struct, Num <T, V> where V : IList <T>
        {
            V   output = default(NumT).CreateVector(OutputDimension);
            int stride = Stride;

            int jbound = Utils.UImageCoordinate.ComputeOutputCounts(KernelDimension, InputCoordinates.RowCount, Stride, Padding, true);
            int kbound = Utils.UImageCoordinate.ComputeOutputCounts(KernelDimension, InputCoordinates.ColumnCount, Stride, Padding, true);

            for (int i = 0; i < InputCoordinates.ChannelCount; i++)
            {
                for (int j = 0; j < jbound; j++)
                {
                    for (int k = 0; k < kbound; k++)
                    {
                        int index = OutputCoordinates.GetIndex(i, j, k);
                        T   value = applyKernel(state, input, index, i, j * stride, k * stride);
                        output[index] = value;
                    }
                }
            }
            return(output);
        }
示例#2
0
        public void Evaluate <NumT, T, V>(V input, V output)
            where NumT : struct, Num <T, V>
            where V : IList <T>
        {
            var jBound = Utils.UImageCoordinate.ComputeOutputCounts(KernelDimension, InputCoordinates.RowCount, 1, Padding, false);
            var kBound = Utils.UImageCoordinate.ComputeOutputCounts(KernelDimension, InputCoordinates.ColumnCount, 1, Padding, false);

            Parallel.For(0, KernelCount, new ParallelOptions {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            }, i =>
            {
                for (int j = 0; j < jBound; j++)
                {
                    for (int k = 0; k < kBound; k++)
                    {
                        int outIndex = OutputCoordinates.GetIndex(i, j, k);
                        var tmp      = default(NumT).Const(0.0);
                        ApplyKernel <NumT, T, V>(ref tmp, input, Padding, i, j, k);
                        output[outIndex] = tmp;
                    }
                }
            });
        }