conv

Perform convolution to given tensor, using given kernel. Convolution is supported for 1, 2, and 3 dimensional tensors.

InputTensor
conv
(
InputTensor
KernelTensor
MaskTensor = KernelTensor
)
(
InputTensor input
,
KernelTensor kernel
,
InputTensor prealloc = InputTensor.init
,
MaskTensor mask = MaskTensor.init
,
TaskPool pool = taskPool
)
in { static assert (isSlice!InputTensor, "Input tensor has to be of type mir.ndslice.slice.Slice"); static assert (isSlice!KernelTensor, "Kernel tensor has to be of type mir.ndslice.slice.Slice"); static assert (isSlice!MaskTensor, "Mask tensor has to be of type mir.ndslice.slice.Slice"); static assert (isBoundaryCondition!bc, "Invalid boundary condition test function."); static assert (isAssignable!(DeepElementType!InputTensor, DeepElementType!KernelTensor), "Incompatible types for input and kernel"); immutable N = InputTensor.init.shape.length; immutable NK = KernelTensor.init.shape.length; static assert (MaskTensor.init.shape.length == NK, "Mask tensor has to be of same dimension as the kernel tensor."); immutable invalidKernelMsg = "Invalid kernel dimension"; static if (N == 1) static assert (NK == 1, invalidKernelMsg); else static if (N == 2) static assert (NK == 2, invalidKernelMsg); else static if (N == 3) static assert (NK == 2, invalidKernelMsg); else static assert (0, "Convolution not implemented for given tensor dimension."); assert (input._iterator != prealloc._iterator, "Preallocated and input buffer cannot point to the same memory."); if (!mask.empty) { assert (mask.shape == input.shape, "Invalid mask size. Should be of same size as input tensor."); assert (input.strides == mask.strides, "Input input and mask need to have same strides."); } if (prealloc.empty) assert (input._stride!(N - 1) == 1, "Input tensor has to be contiguous (i.e. input.stride!(N-1) == 1)."); else assert (input.strides == prealloc.strides, "Input input and result(preallocated) buffer need to have same strides."); }

Parameters

bc

(Template parameter) Boundary Condition function used while indexing the image matrix.

input
Type: InputTensor

Input tensor.

kernel
Type: KernelTensor

Convolution kernel tensor. For 1D input, 1D kernel is expected. For 2D input, 2D kernel is expected. For 3D input, 2D or 3D kernel is expected - if 2D kernel is given, each item in kernel matrix is applied to each value in corresponding 2D coordinate in the input.

prealloc
Type: InputTensor

Pre-allocated buffer where convolution result can be stored. Default value is emptySlice, where resulting array will be newly allocated. Also if prealloc is not of same shape as input input, resulting array will be newly allocated.

mask
Type: MaskTensor

Masking input. Convolution will skip each element where mask is 0. Default value is empty slice, which tells that convolution will be performed on the whole input.

pool
Type: TaskPool

Optional TaskPool instance used to parallelize computation.

Return Value

Type: InputTensor

Resulting image after convolution, of same type as input tensor.

Note: Input, mask and pre-allocated slices' strides must be the same.

Meta