Convolution
simplegrad.functions.conv.pad(x: Tensor, width: int | tuple[int, int, int, int], mode: str = 'constant', value: int = 0) -> Tensor
Pad a tensor along its spatial dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor. |
required |
width
|
int | tuple[int, int, int, int]
|
Padding widths. An int or nested tuples as accepted by |
required |
mode
|
str
|
Padding mode (e.g. |
'constant'
|
value
|
int
|
Fill value for |
0
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Padded tensor. |
Source code in simplegrad/functions/conv.py
simplegrad.functions.conv.conv2d(x: Tensor, weight: Tensor, bias: Tensor | None = None, stride: int | tuple[int, int] = 1, pad_width: int | tuple[int, int, int, int] = 0, pad_mode: str = 'constant', pad_value: int = 0) -> Tensor
Apply a 2D convolution over the input tensor.
Implements convolution as a single matrix multiplication (im2col). Supports batched inputs (4D) and single-sample inputs (3D).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor of shape |
required |
weight
|
Tensor
|
Kernel tensor of shape |
required |
bias
|
Tensor | None
|
Optional bias of shape |
None
|
stride
|
int | tuple[int, int]
|
Convolution stride. Int or |
1
|
pad_width
|
int | tuple[int, int, int, int]
|
Padding to apply before convolution. Int (same on all sides)
or |
0
|
pad_mode
|
str
|
Padding mode passed to |
'constant'
|
pad_value
|
int
|
Fill value for constant padding. Defaults to 0. |
0
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Output tensor of shape |