I have the following function

- Code: Select all
`array ConvLayer::ConvolveValid3d2d(const array& a, const array& b) {`

array c = convolve(a, b, true);

int output_size0 = a.dims(0) - b.dims(0) + 1;

int output_size1 = a.dims(1) - b.dims(1) + 1;

int full_size0 = a.dims(0) + b.dims(0) - 1;

int full_size1 = a.dims(1) + b.dims(1) - 1;

int start0 = floor(float(full_size0 - output_size0) / 2);

int start1 = floor(float(full_size1 - output_size1) / 2);

c = c(seq(start0, start0 + output_size0 - 1), seq(start1, start1 + output_size1 - 1), span);

return c;

}

I profiled this code using Visual Studio Profiler to see if I can improve its performance.

It turns out that the slowest line in the function is the one before the end:

- Code: Select all
`c = c(seq(start0, start0 + output_size0 - 1), seq(start1, start1 + output_size1 - 1), span);`

Is there might be a faster alternative to this assignment?

Thanks!