Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal static void ApplyConnectionMatrix(double[] input, int inputSkip, double[] output, int outputSkip, double[,] weights)
- {
- int inputLength = weights.GetLength(0);
- int outputLength = weights.GetLength(1);
- for (int i = 0; i < outputLength; i++)
- {
- double outputValue = 0.0;
- {
- for (int j = 0; j < inputLength; j++)
- {
- outputValue += weights[j, i] * input[inputSkip + j];
- }
- }
- output[outputSkip + j] = outputValue;
- }
- }
- internal static void ApplyConnectionMatrix1(double[] input, int inputSkip, double[] output, int outputSkip, double[,] weights)
- {
- int inputLength = weights.GetLength(0);
- int outputLength = weights.GetLength(1);
- Gpu.Default.For(0, outputLength, delegate (int i)
- {
- double outputValue = 0.0;
- for (int j = 0; j < inputLength; j++)
- {
- outputValue += input[inputSkip + j] * weights[j, i];
- }
- output[outputSkip + i] = outputValue;
- });
- }
- internal static void ApplyConvolution(float[,,] input, float[,,] output, float[][,,] kernels, int kernelSide, int stride, int padding, Func<float, float> function)
- {
- int outputDepth = output.GetLength(0);
- int outputWidth = output.GetLength(1);
- int outputHeight = output.GetLength(2);
- int inputDepth = input.GetLength(0);
- int inputWidth = input.GetLength(1);
- int inputHeight = input.GetLength(2);
- for (int i = 0; i < outputDepth; i++)
- {
- for (int j = 0; j < outputWidth; j++)
- {
- for (int k = 0; k < outputHeight; k++)
- {
- float outputValue = 0.0F;
- for (int l = 0; l < kernelSide; l++)
- {
- for (int m = 0; m < kernelSide; m++)
- {
- int inputX = (j + l) * stride - padding;
- int inputY = (k + m) * stride - padding;
- if (0 <= inputX && inputX < inputWidth && 0 <= inputY && inputY < inputHeight)
- {
- for (int n = 0; n < inputDepth; n++)
- {
- outputValue += kernels[i][n, l, m] * input[n, inputX, inputY];
- }
- }
- }
- }
- output[i, j, k] = function(outputValue);
- }
- }
- }
- }
- internal static void ApplyConvolution1(float[,,] input, float[,,] output, float[][,,] kernels, int kernelSide, int stride, int padding, Func<float, float> function)
- {
- int outputDepth = output.GetLength(0);
- int outputWidth = output.GetLength(1);
- int outputHeight = output.GetLength(2);
- int inputDepth = input.GetLength(0);
- int inputWidth = input.GetLength(1);
- int inputHeight = input.GetLength(2);
- Gpu.Default.Launch(delegate
- {
- int w = blockIdx.x * 8 + threadIdx.x;
- int x = blockIdx.y * 8 + threadIdx.y;
- int y = blockIdx.z * 8 + threadIdx.z;
- float[] kernel = kernels[w];
- {
- float outputValue = 0.0F;
- for (int i = 0; i < kernelSide; i++)
- {
- for (int j = 0; j < kernelSide; j++)
- {
- int inputX = (x + i) * stride - padding;
- int inputY = (y + j) * stride - padding;
- if (0 <= inputX && inputX < inputWidth && 0 <= inputY && inputY < inputHeight)
- {
- for (int l = 0; l < inputDepth; l++)
- {
- outputValue += kernel[l, i, j] * input[l, inputX, inputY];
- }
- }
- }
- }
- output[w, x, y] = function(outputValue);
- }
- }, new LaunchParam(new dim3((outputDepth + 7) / 8, (outputWidth + 7) / 8, (outputHeight + 7) / 8), new dim3(8, 8, 8)));
- }
Add Comment
Please, Sign In to add comment