Skip to content

affine

Per-channel affine transformation as a function and a learnable module.

Classes:

  • Affine –

    Applies an affine transformation to the input.

Functions:

  • affine –

    Apply a per-channel affine transformation \(y = x \cdot \text{weight} + \text{bias}\).

Affine

Affine(
    num_features: int,
    bias: bool = True,
    device: Optional[device] = None,
    dtype: Optional[dtype] = None,
)

Bases: Module

Applies an affine transformation to the input. This layer will apply the following transformation to the input tensor \(x\):

\[ y = x \cdot \text{weight} + \text{bias} \]

Parameters:

  • num_features (int) –

    The number of features in the input.

  • bias (bool, default: True ) –

    Whether to use bias.

  • device (Optional[device], default: None ) –

    The device to use.

  • dtype (Optional[dtype], default: None ) –

    The dtype to use.

Shape
  • Input: \((N, *, C)\) where \(*\) means any number of additional dimensions.
  • Output: \((N, *, C)\) where \(*\) means any number of additional dimensions.

affine

affine(
    x: Tensor, weight: Tensor, bias: Optional[Tensor] = None
) -> Tensor

Apply a per-channel affine transformation \(y = x \cdot \text{weight} + \text{bias}\).

Parameters:

  • x (Tensor) –

    Input tensor.

  • weight (Tensor) –

    Per-channel scale, broadcastable against x.

  • bias (Optional[Tensor], default: None ) –

    Optional per-channel offset, broadcastable against x. None skips the addition.

Returns:

  • Tensor –

    The transformed tensor, same shape as x.

Shape

Input: \((N, *, C)\) where \(*\) means any number of additional dimensions. Output: \((N, *, C)\), same as the input.

Example
import torch
from torch_pointcloud.layers import affine

x = torch.randn(4, 8)
y = affine(x, weight=torch.ones(8), bias=torch.zeros(8))
assert torch.equal(y, x)