Tannic
A C++ Tensor Library
Loading...
Searching...
No Matches
tannic::transformation::Convolution2D Class Reference

Expression for 2D convolution operations. More...

#include <convolutions.hpp>

Public Member Functions

constexpr type promote (type signal, type kernel) const
 Type promotion for 2D convolution.
 
constexpr Shape transform (Shape const &signal, Shape const &kernel) const
 Computes output shape for 2D convolution.
 
void forward (Tensor const &signal, Tensor const &kernel, Tensor &result) const
 Performs the forward pass of 2D convolution.
 

Public Attributes

std::array< std::size_t, 2 > strides
 Stride values for height and width dimensions.
 
std::array< std::size_t, 2 > padding
 Padding values for height and width dimensions.
 

Detailed Description

Expression for 2D convolution operations.

Implements 2D convolution with:

  • Input and kernel dtype validation
  • Automatic output shape calculation
  • Support for strides and padding in both spatial dimensions

Member Function Documentation

◆ forward()

void tannic::transformation::Convolution2D::forward ( Tensor const &  signal,
Tensor const &  kernel,
Tensor result 
) const

Performs the forward pass of 2D convolution.

Parameters
signalInput signal tensor
kernelConvolution kernel tensor
resultOutput tensor to store convolution result

◆ promote()

constexpr type tannic::transformation::Convolution2D::promote ( type  signal,
type  kernel 
) const
inlineconstexpr

Type promotion for 2D convolution.

Requires both signal and kernel to have identical data types.

Parameters
signalData type of the input signal tensor
kernelData type of the kernel tensor
Returns
Data type (same as inputs)
Exceptions
Exceptionif signal and kernel dtypes don't match

◆ transform()

constexpr Shape tannic::transformation::Convolution2D::transform ( Shape const &  signal,
Shape const &  kernel 
) const
inlineconstexpr

Computes output shape for 2D convolution.

Calculates the output shape based on input signal shape, kernel shape, strides, and padding using the standard 2D convolution formula.

Parameters
signalShape of the input signal tensor (N, C_in, H_in, W_in)
kernelShape of the kernel tensor (C_out, K_in, K_h, K_w)
Returns
Output shape after 2D convolution (N, C_out, H_out, W_out)
Exceptions
Exceptionif input ranks are not 4 or channel dimensions don't match

Expected input shapes:

  • Signal: [batch_size, input_channels, height, width]
  • Kernel: [output_channels, input_channels, kernel_height, kernel_width]
  • Output: [batch_size, output_channels, output_height, output_width]

Output dimension formulas:

  • H_out = (H_in + 2*padding_h - K_h) / stride_h + 1
  • W_out = (W_in + 2*padding_w - K_w) / stride_w + 1

Member Data Documentation

◆ padding

std::array<std::size_t, 2> tannic::transformation::Convolution2D::padding

Padding values for height and width dimensions.

◆ strides

std::array<std::size_t, 2> tannic::transformation::Convolution2D::strides

Stride values for height and width dimensions.


The documentation for this class was generated from the following file: