Skip to content

Convolutional Layers

2D hyperbolic convolutions and pooling for the Hyperboloid, Poincaré, and Proper Velocity models. For which conv to pick see the NN Layers guide.

Dimensional growth is internal, not in the output shape

HypConv2DHyperboloid / HypConv2DHyperboloidFHNN / FGGConv2D HCat-concatenate a d+1-ambient input over the N-pixel receptive field into a (d×N)+1-ambient intermediate, which the kernel projects down to out_channels. The output ambient width is always out_channels; a larger kernel costs parameters and compute, not output width. LorentzConv2D does no HCat, and its output is also out_channels.

Hyperboloid

HypConv2DHyperboloid (the robust default) uses HCat patch extraction + Lorentz FC (Bdeir et al. 2023). HypConv2DHyperboloidILNN is the intrinsic Lorentz conv (Shi et al. 2026): LogCat (log-radius-preserving concatenation) + PLFC, with origin padding. LorentzConv2D is the HRC-based variant (Euclidean conv on the spatial part; faster, lower accuracy — legacy/benchmarking).

hyperbolix.nn_layers.HypConv2DHyperboloid

HypConv2DHyperboloid(
    manifold_module: Hyperboloid,
    in_channels: int,
    out_channels: int,
    kernel_size: int | tuple[int, int],
    *,
    rngs: Rngs,
    stride: int | tuple[int, int] = 1,
    padding: str = "SAME",
    input_space: str = "manifold",
    reset_params: str = "fan_in",
    param_dtype: DTypeLike = jnp.float32,
)

Bases: Module

Hyperbolic 2D Convolutional Layer for Hyperboloid model.

This layer implements fully hyperbolic convolution as described in "Fully Hyperbolic Convolutional Neural Networks for Computer Vision".

Computation steps: 1) Extract receptive field (kernel_size x kernel_size) of hyperbolic points 2) Apply HCat (Lorentz direct concatenation) to combine receptive field points 3) Pass through hyperbolic linear layer (LFC)

Parameters:

Name Type Description Default
manifold_module object

Class-based Hyperboloid manifold instance

required
in_channels int

Number of input channels

required
out_channels int

Number of output channels

required
kernel_size int or tuple[int, int]

Size of the convolutional kernel

required
rngs Rngs

Random number generators for parameter initialization

required
stride int or tuple[int, int]

Stride of the convolution (default: 1)

1
padding str

Padding mode, either 'SAME' or 'VALID' (default: 'SAME')

'SAME'
input_space str

Type of the input tensor, either 'tangent' or 'manifold' (default: 'manifold'). Note: This is a static configuration - changing it after initialization requires recompilation.

'manifold'
reset_params str

Kernel initialization scheme; the bias starts at zero in every scheme (default: "fan_in").

  • "fan_in": normal, std = sqrt(1 / hcat_out_ambient_dim), where hcat_out_ambient_dim = (in_channels - 1) * kh * kw + 1 is the width of the HCat-ed receptive field. This fan-in init keeps the spread of the spatial coordinates: the output's stays within about 1.0x to 1.1x of the input's per layer (16 channels, 3x3 kernel, c = 1), so a deep stack neither freezes nor blows up. It is the analogue of _fgg_weight_init's "lorentz_kaiming" branch.
  • "uniform": U(-0.02, 0.02), the init of the library's FHCNN linear layer (:class:HypLinearHyperboloidFHCNN) and this layer's default up to 1.5.0. It is width-independent and contractive: in the same setting it shrinks that spread about 0.13x per layer (about 3e-4 after four layers), so a stack built with it stops passing input variation through, without any NaN. "default" is accepted as an alias for "uniform" and gives the same kernel bit for bit.

Neither is the reference init: the conv layer of Bdeir et al. 2023 (LorentzConv2d.reset_parameters in HyperbolicCV) draws kernel and bias from U(-s, s) with s = sqrt(2 / ((in_channels - 1) * kh * kw)), which shrinks the spread about 0.8x to 0.9x per layer in the same setting.

'fan_in'
param_dtype DTypeLike

Storage dtype of the trainable parameters (default: jnp.float32). Compute precision of manifold operations is set by manifold.dtype.

float32
Notes

JIT Compatibility: This layer is designed to work with nnx.jit. Configuration parameters (padding, input_space) are treated as static and will be baked into the compiled function.

References

Ahmad Bdeir, Kristian Schwethelm, and Niels Landwehr. "Fully hyperbolic convolutional neural networks for computer vision." arXiv preprint arXiv:2303.15919 (2023).

Source code in hyperbolix/nn_layers/hyperboloid_conv.py
def __init__(
    self,
    manifold_module: Hyperboloid,
    in_channels: int,
    out_channels: int,
    kernel_size: int | tuple[int, int],
    *,
    rngs: nnx.Rngs,
    stride: int | tuple[int, int] = 1,
    padding: str = "SAME",
    input_space: str = "manifold",
    reset_params: str = "fan_in",
    param_dtype: DTypeLike = jnp.float32,
):
    if padding not in ["SAME", "VALID"]:
        raise ValueError(f"padding must be either 'SAME' or 'VALID', got '{padding}'")
    if input_space not in ["tangent", "manifold"]:
        raise ValueError(f"input_space must be either 'tangent' or 'manifold', got '{input_space}'")
    if reset_params not in ("fan_in", "uniform", "default"):
        raise ValueError(
            f"reset_params must be 'fan_in', 'uniform' or 'default' (alias of 'uniform'), got '{reset_params}'"
        )

    # Static configuration
    validate_hyperboloid_manifold(manifold_module, required_methods=("expmap_0", "hcat"))
    self.manifold = manifold_module
    self.in_channels = in_channels
    self.out_channels = out_channels
    self.input_space = input_space
    self.padding = padding

    self.kernel_size = as_pair(kernel_size)
    self.stride = as_pair(stride)

    # HCat output ambient dim for the linear layer
    hcat_out_ambient_dim = hcat_ambient_dim(in_channels, self.kernel_size)

    # Trainable parameters — owned directly for flat parameter paths
    if reset_params in ("uniform", "default"):  # "default": its name up to 1.5.0, kept as an alias
        bound = 0.02
        kernel_init = jax.random.uniform(
            rngs.params(), (out_channels, hcat_out_ambient_dim), dtype=param_dtype, minval=-bound, maxval=bound
        )
    else:  # "fan_in"
        std = jnp.sqrt(1.0 / hcat_out_ambient_dim)
        kernel_init = jax.random.normal(rngs.params(), (out_channels, hcat_out_ambient_dim), dtype=param_dtype) * std
    self.kernel = nnx.Param(kernel_init)
    self.bias = nnx.Param(jnp.zeros((1, out_channels), dtype=param_dtype))
    self.scale = 2.3  # not learnable (matches FHCNN default)

__call__

__call__(
    x: Float[Array, "batch height width in_channels"],
    c: float = 1.0,
) -> Float[
    Array, "batch out_height out_width out_channels"
]

Forward pass through the hyperbolic convolutional layer.

Parameters:

Name Type Description Default
x Array of shape (batch, height, width, in_channels)

Input feature map where each pixel is a point on the Hyperboloid manifold

required
c float

Manifold curvature (default: 1.0)

1.0

Returns:

Name Type Description
out Array of shape (batch, out_height, out_width, out_channels)

Output feature map on the Hyperboloid manifold

Source code in hyperbolix/nn_layers/hyperboloid_conv.py
def __call__(
    self,
    x: Float[Array, "batch height width in_channels"],
    c: float = 1.0,
) -> Float[Array, "batch out_height out_width out_channels"]:
    """
    Forward pass through the hyperbolic convolutional layer.

    Parameters
    ----------
    x : Array of shape (batch, height, width, in_channels)
        Input feature map where each pixel is a point on the Hyperboloid manifold
    c : float
        Manifold curvature (default: 1.0)

    Returns
    -------
    out : Array of shape (batch, out_height, out_width, out_channels)
        Output feature map on the Hyperboloid manifold
    """
    # Map to manifold if needed (static branch - JIT friendly)
    x = _map_input_to_manifold(x, self.manifold, self.input_space, c)

    # Extract patches: (B, H, W, kh, kw, C)
    patches_BHWkhkwC = extract_patches(x, self.kernel_size, self.stride, self.padding, pad_mode="edge")
    batch, out_h, out_w, kh, kw, in_c = patches_BHWkhkwC.shape

    # Flatten batch+spatial for parallel processing: (B*H*W, K, C)
    patches_flat_NKC = patches_BHWkhkwC.reshape(-1, kh * kw, in_c)

    # HCat: (K, C) -> (hcat_dim,) per patch
    hcat_out_NA = jax.vmap(self.manifold.hcat, in_axes=(0, None))(patches_flat_NKC, c)  # (B*H*W, hcat_dim)

    # Linear: (hcat_dim,) -> (out_channels,)
    linear_out_NC = _fhcnn_forward(
        hcat_out_NA,
        self.kernel[...],
        self.bias[...],
        self.manifold,
        c,
        "manifold",
        None,
        False,
        self.scale,
        1e-5,
    )  # (B*H*W, out_channels)

    # Reshape back to spatial
    output_BHWC = linear_out_NC.reshape(batch, out_h, out_w, self.out_channels)

    return output_BHWC

hyperbolix.nn_layers.HypConv2DHyperboloidFHNN

HypConv2DHyperboloidFHNN(
    manifold_module: Hyperboloid,
    in_channels: int,
    out_channels: int,
    kernel_size: int | tuple[int, int],
    *,
    rngs: Rngs,
    stride: int | tuple[int, int] = 1,
    padding: str = "SAME",
    input_space: str = "manifold",
    init_scale: float = 2.3,
    eps: float = 1e-05,
    activation: Callable[[Array], Array] | None = None,
    dropout_rate: float | None = None,
    deterministic: bool = True,
    param_dtype: DTypeLike = jnp.float32,
)

Bases: Module

Fully Hyperbolic Neural Networks 2D convolutional layer (Chen et al. 2021).

Uses HCat (Lorentz direct concatenation) to combine receptive field points, then applies the FHNN linear transform (time-primary sigmoid parameterization) for channel mixing.

Computation steps: 1) Map input to manifold via expmap_0 if input_space="tangent" 2) Extract receptive field (kernel_size x kernel_size) of hyperbolic points 3) Apply HCat (Lorentz direct concatenation) to combine receptive field points 4) Pass through FHNN linear (sigmoid time + spatial rescaling)

Parameters:

Name Type Description Default
manifold_module Hyperboloid

Class-based Hyperboloid manifold instance

required
in_channels int

Number of input channels (ambient dimension, including time component)

required
out_channels int

Number of output channels (ambient dimension, including time component)

required
kernel_size int or tuple[int, int]

Size of the convolutional kernel

required
rngs Rngs

Random number generators for parameter initialization

required
stride int or tuple[int, int]

Stride of the convolution (default: 1)

1
padding str

Padding mode, either 'SAME' or 'VALID' (default: 'SAME')

'SAME'
input_space str

Type of the input tensor, either 'tangent' or 'manifold' (default: 'manifold'). Note: This is a static configuration - changing it after initialization requires recompilation.

'manifold'
init_scale float

Initial value for the learnable sigmoid scale (default: 2.3)

2.3
eps float

Numerical stability epsilon (default: 1e-5)

1e-05
activation callable or None

Activation function to apply before the linear transformation (default: None).

None
dropout_rate float or None

Dropout rate applied before the linear transformation (default: None).

None
deterministic bool

If True, dropout is disabled (default: True, so a layer built with a dropout_rate drops only after model.train() or an explicit deterministic=False). Overridable at call time.

True
param_dtype DTypeLike

Storage dtype of the trainable parameters (default: jnp.float32). Compute precision of manifold operations is set by manifold.dtype.

float32
Notes

JIT Compatibility: This layer is designed to work with nnx.jit. Configuration parameters (padding, input_space, activation) are treated as static and baked into the compiled function.

See Also

HypConv2DHyperboloid : Equivalent convolution using FHCNN linear instead of FHNN. HypLinearHyperboloidFHNN : The underlying FHNN linear layer.

References

Weize Chen, et al. "Fully hyperbolic neural networks." arXiv preprint arXiv:2105.14686 (2021).

Source code in hyperbolix/nn_layers/hyperboloid_conv.py
def __init__(
    self,
    manifold_module: Hyperboloid,
    in_channels: int,
    out_channels: int,
    kernel_size: int | tuple[int, int],
    *,
    rngs: nnx.Rngs,
    stride: int | tuple[int, int] = 1,
    padding: str = "SAME",
    input_space: str = "manifold",
    init_scale: float = 2.3,
    eps: float = 1e-5,
    activation: Callable[[Array], Array] | None = None,
    dropout_rate: float | None = None,
    deterministic: bool = True,
    param_dtype: DTypeLike = jnp.float32,
):
    if padding not in ["SAME", "VALID"]:
        raise ValueError(f"padding must be either 'SAME' or 'VALID', got '{padding}'")
    if input_space not in ["tangent", "manifold"]:
        raise ValueError(f"input_space must be either 'tangent' or 'manifold', got '{input_space}'")

    # Static configuration
    validate_hyperboloid_manifold(manifold_module, required_methods=("expmap_0", "hcat"))
    self.manifold = manifold_module
    self.in_channels = in_channels
    self.out_channels = out_channels
    self.input_space = input_space
    self.padding = padding
    self.eps = eps
    self.activation = activation

    self.kernel_size = as_pair(kernel_size)
    self.stride = as_pair(stride)

    # HCat output ambient dim
    hcat_out_ambient_dim = hcat_ambient_dim(in_channels, self.kernel_size)

    # FHNN weight init: U(-0.02, 0.02) with time column zeroed (tangent vectors at origin)
    bound = 0.02
    weight_init = jax.random.uniform(
        rngs.params(), (out_channels, hcat_out_ambient_dim), dtype=param_dtype, minval=-bound, maxval=bound
    )
    weight_init = weight_init.at[:, 0].set(0.0)
    self.kernel = nnx.Param(weight_init)
    self.bias = nnx.Param(jnp.zeros((1, out_channels), dtype=param_dtype))

    # Learnable scale for the sigmoid (always learnable in FHNN)
    self.scale = nnx.Param(jnp.array(init_scale, dtype=param_dtype))

    # Optional dropout
    if dropout_rate is not None and dropout_rate > 0:
        self.dropout = nnx.Dropout(dropout_rate, deterministic=deterministic, rngs=rngs)
    else:
        self.dropout = None

__call__

__call__(
    x: Float[Array, "batch height width in_channels"],
    c: float = 1.0,
    deterministic: bool | None = None,
) -> Float[
    Array, "batch out_height out_width out_channels"
]

Forward pass through the FHNN hyperbolic convolutional layer.

Parameters:

Name Type Description Default
x Array of shape (batch, height, width, in_channels)

Input feature map where each pixel is a point on the Hyperboloid manifold

required
c float

Manifold curvature (default: 1.0)

1.0
deterministic bool or None

If True, dropout is disabled. None uses the inner nnx.Dropout's setting, which the constructor sets and model.eval() / model.train() / nnx.view change (default: None).

None

Returns:

Name Type Description
out Array of shape (batch, out_height, out_width, out_channels)

Output feature map on the Hyperboloid manifold

Source code in hyperbolix/nn_layers/hyperboloid_conv.py
def __call__(
    self,
    x: Float[Array, "batch height width in_channels"],
    c: float = 1.0,
    deterministic: bool | None = None,
) -> Float[Array, "batch out_height out_width out_channels"]:
    """Forward pass through the FHNN hyperbolic convolutional layer.

    Parameters
    ----------
    x : Array of shape (batch, height, width, in_channels)
        Input feature map where each pixel is a point on the Hyperboloid manifold
    c : float
        Manifold curvature (default: 1.0)
    deterministic : bool or None
        If True, dropout is disabled. None uses the inner ``nnx.Dropout``'s
        setting, which the constructor sets and ``model.eval()`` /
        ``model.train()`` / ``nnx.view`` change (default: None).

    Returns
    -------
    out : Array of shape (batch, out_height, out_width, out_channels)
        Output feature map on the Hyperboloid manifold
    """
    # Map to manifold if needed (static branch - JIT friendly)
    x = _map_input_to_manifold(x, self.manifold, self.input_space, c)

    # Extract patches: (B, H, W, kh, kw, C)
    patches_BHWkhkwC = extract_patches(x, self.kernel_size, self.stride, self.padding, pad_mode="edge")
    batch, out_h, out_w, kh, kw, in_c = patches_BHWkhkwC.shape

    # Flatten batch+spatial for parallel processing: (B*H*W, K, C)
    patches_flat_NKC = patches_BHWkhkwC.reshape(-1, kh * kw, in_c)

    # HCat: (K, C) -> (hcat_dim,) per patch
    hcat_out_NA = jax.vmap(self.manifold.hcat, in_axes=(0, None))(patches_flat_NKC, c)  # (B*H*W, hcat_dim)

    # Build dropout closure for the pure function
    dropout_module = self.dropout
    if dropout_module is not None:
        dropout_fn = lambda z: dropout_module(z, deterministic=deterministic)  # noqa: E731
    else:
        dropout_fn = None

    # FHNN linear: (hcat_dim,) -> (out_channels,)
    linear_out_NC = _fhnn_forward(
        hcat_out_NA,
        self.kernel[...],
        self.bias[...],
        self.manifold,
        c,
        "manifold",  # HCat output is already on manifold
        self.activation,
        dropout_fn,
        self.scale[...],
        self.eps,
    )  # (B*H*W, out_channels)

    # Reshape back to spatial
    return linear_out_NC.reshape(batch, out_h, out_w, self.out_channels)

hyperbolix.nn_layers.HypConv2DHyperboloidILNN

HypConv2DHyperboloidILNN(
    manifold_module: Hyperboloid,
    in_channels: int,
    out_channels: int,
    kernel_size: int | tuple[int, int],
    *,
    rngs: Rngs,
    stride: int | tuple[int, int] = 1,
    padding: str = "SAME",
    pad_mode: str = "origin",
    input_space: str = "manifold",
    v_max: float = 10.0,
    use_gyro_bias: bool = False,
    kernel_init_std: float | None = None,
    param_dtype: DTypeLike = jnp.float32,
)

Bases: Module

Intrinsic Lorentz Neural Network (ILNN) 2D convolutional layer (Hyperboloid model).

Implements the Lorentz convolution of Shi et al. 2026, Eq. (11): y = PLFC(LogCat({x_patch})). Receptive-field points are combined with the log-radius-preserving concatenation (LogCat) and mixed across channels by the PLFC linear transform (MLR scores -> sinh diffeomorphism -> time reconstruction). This extends the HNN++ linearized-kernel convolution (Shimizu et al. 2020) by replacing the Euclidean FC and naive concatenation with their intrinsic Lorentz counterparts. Formerly named HypConv2DHyperboloidPP.

Computation steps: 1) Extract receptive field (kernel_size x kernel_size) of hyperbolic points, padding with the manifold origin if needed 2) Apply LogCat (log-radius-preserving concatenation) to combine receptive field points 3) Pass through PLFC linear (MLR scores -> guard -> sinh -> time reconstruction) 4) Optionally add an intrinsic gyro-bias y <- y (+) exp_0([0, b])

Parameters:

Name Type Description Default
manifold_module Hyperboloid

Class-based Hyperboloid manifold instance

required
in_channels int

Number of input channels (ambient dimension, including time component)

required
out_channels int

Number of output channels (ambient dimension, including time component)

required
kernel_size int or tuple[int, int]

Size of the convolutional kernel

required
rngs Rngs

Random number generators for parameter initialization

required
stride int or tuple[int, int]

Stride of the convolution (default: 1)

1
padding str

Padding mode, either 'SAME' or 'VALID' (default: 'SAME')

'SAME'
pad_mode str

How to fill padding pixels for 'SAME' padding: "origin" fills with the manifold origin (sqrt(1/c), 0, ..., 0) (matching the Shi et al. 2026 reference, which clamps zero-padded times up to sqrt(1/c)), "edge" replicates border values (default: "origin").

'origin'
input_space str

Type of the input tensor, either 'tangent' or 'manifold' (default: 'manifold'). Note: This is a static configuration - changing it after initialization requires recompilation.

'manifold'
v_max float

Output-side guard: the sinh argument sqrt(c)*v is hard-clipped to ±v_max, bounding the output spatial norm by sinh(v_max)/sqrt(c) (default: 10.0, matching the Shi et al. 2026 reference implementation). The clip is a plain jnp.clip, not a smooth clamp, so it zeroes the gradient in the saturated tail (matching the sibling PLFC layer).

10.0
use_gyro_bias bool

If True, add a learnable intrinsic bias via Lorentz gyroaddition, y <- y (+) exp_0([0, b]) with b initialized to zero — the gyrogroup identity, so the bias is a no-op at initialization (default: False).

False
kernel_init_std float or None

Standard deviation of the normal kernel init. The default None resolves to the fan-out, norm-preserving value sqrt(1 / out_spatial) with out_spatial = out_channels - 1 (per-layer spatial-norm gain ~= 1; see Notes). Pass kernel_init_std=0.02 to restore the Shi et al. 2026 PLFC reference value bit-for-bit, or 1.0 for the old HNN++-style init (Shimizu et al. 2020) — note that large values push the pre-guard scores into the v_max saturation regime (default: None).

None
param_dtype DTypeLike

Storage dtype of the trainable parameters (default: jnp.float32). Compute precision of manifold operations is set by manifold.dtype.

float32
Notes

Weight Initialization: The default std = sqrt(1 / out_spatial) is norm-preserving. Linearize the layer around the manifold origin, where the PLFC chain is small-signal: with the bias at its 0 init, compute_mlr reduces to v = ||z||/sqrt(c) * asinh(sqrt(c) <u_s, z> / ||z||) ~= <u_s, z> and the output map y_s = sinh(sqrt(c) v)/sqrt(c) ~= v, so y_s ~= W u_s — a plain matmul. For a Gaussian W of shape (O, I) with entry std sigma this has RMS gain sigma * sqrt(O), and the LogCat input u_s carries the per-pixel spatial radius by construction (that is what the digamma rescale buys), so sigma = 1/sqrt(O) gives an overall gain of 1. Measured on a depth-3 stack (c=0.1, 3x3 kernel, 8x8 input, float64), the per-layer mean spatial norm ratio is 0.82-0.95 across widths 8-64 — the residual shortfall is the origin-padded border, whose interior-only ratios are 0.92-0.98.

The previous fixed default ``0.02`` was tuned against the *pre-fix* LogCat,
which amplified the spatial radius by ~sqrt(N) per block instead of shrinking
it (a sign error in the digamma difference, shared with the Shi et al. 2026
reference; fixed 2026-07-31). The two errors cancelled at width ~64: gain
``0.02 * sqrt(64) * 9 ~= 1.4`` for a 3x3 kernel. Under the corrected LogCat
the same ``0.02`` is strongly contractive — probe-measured per-layer ratios
0.05-0.15, i.e. a depth-3 stack collapses onto the manifold origin at init —
so ``kernel_init_std=0.02`` now restores the Shi et al. 2026 regime, which
implicitly assumed the pre-fix LogCat amplification, rather than a safe
default. Use it only to reproduce that reference.

JIT Compatibility: This layer is designed to work with nnx.jit. Configuration parameters (padding, pad_mode, input_space, v_max) are treated as static and baked into the compiled function.

See Also

HypLinearHyperboloidPLFC : The underlying PLFC linear layer. hyperbolix.manifolds.hyperboloid.Hyperboloid.log_radius_concat : The LogCat operation.

References

Xianglong Shi, Ziheng Chen, Yunhan Jiang, and Nicu Sebe. "Intrinsic Lorentz Neural Network." ICLR 2026, arXiv:2602.23981 (Sec. 4.3: Lorentz convolution, log-radius concatenation). Shimizu Ryohei, Yusuke Mukuta, and Tatsuya Harada. "Hyperbolic neural networks++." arXiv preprint arXiv:2006.08210 (2020).

Source code in hyperbolix/nn_layers/hyperboloid_conv.py
def __init__(
    self,
    manifold_module: Hyperboloid,
    in_channels: int,
    out_channels: int,
    kernel_size: int | tuple[int, int],
    *,
    rngs: nnx.Rngs,
    stride: int | tuple[int, int] = 1,
    padding: str = "SAME",
    pad_mode: str = "origin",
    input_space: str = "manifold",
    v_max: float = 10.0,
    use_gyro_bias: bool = False,
    kernel_init_std: float | None = None,
    param_dtype: DTypeLike = jnp.float32,
):
    if padding not in ["SAME", "VALID"]:
        raise ValueError(f"padding must be either 'SAME' or 'VALID', got '{padding}'")
    if pad_mode not in ("origin", "edge"):
        raise ValueError(f"pad_mode must be 'origin' or 'edge', got '{pad_mode}'")
    if input_space not in ["tangent", "manifold"]:
        raise ValueError(f"input_space must be either 'tangent' or 'manifold', got '{input_space}'")

    # Static configuration
    required_methods = ("expmap_0", "compute_mlr", "log_radius_concat")
    if use_gyro_bias:
        required_methods = ("expmap_0", "compute_mlr", "log_radius_concat", "embed_spatial_0", "addition")
    validate_hyperboloid_manifold(manifold_module, required_methods=required_methods)
    self.manifold = manifold_module
    self.in_channels = in_channels
    self.out_channels = out_channels
    self.input_space = input_space
    self.padding = padding
    self.pad_mode = pad_mode
    _assert_v_max_safe(v_max)
    self.v_max = v_max

    self.kernel_size = as_pair(kernel_size)
    self.stride = as_pair(stride)

    # LogCat output ambient dim (same as HCat)
    logcat_out_ambient_dim = hcat_ambient_dim(in_channels, self.kernel_size)

    # Trainable parameters — fan-out normal init: the PLFC chain linearizes to
    # y_spatial ~= W @ u_spatial near the origin and the fixed LogCat hands over the
    # per-pixel spatial radius, so std = 1/sqrt(out_spatial) makes the layer norm-preserving.
    out_spatial = out_channels - 1
    logcat_spatial = logcat_out_ambient_dim - 1
    if kernel_init_std is None:
        # float(): `float.__pow__` is typed as returning Any, which would leave
        # `kernel_init_std` at its declared `float | None` for the type checker.
        kernel_init_std = float((1.0 / out_spatial) ** 0.5)
    kernel_init = kernel_init_std * jax.random.normal(rngs.params(), (out_spatial, logcat_spatial), dtype=param_dtype)
    self.kernel = nnx.Param(kernel_init)
    self.bias = nnx.Param(jnp.zeros((out_spatial, 1), dtype=param_dtype))

    # Gyro-bias: spatial tangent vector at the origin, zero-initialized
    if use_gyro_bias:
        self.gyro_bias = nnx.Param(jnp.zeros((out_spatial,), dtype=param_dtype))
    else:
        self.gyro_bias = None

__call__

__call__(
    x: Float[Array, "batch height width in_channels"],
    c: float = 1.0,
) -> Float[
    Array, "batch out_height out_width out_channels"
]

Forward pass through the ILNN hyperboloid convolutional layer (LogCat + PLFC).

Parameters:

Name Type Description Default
x Array of shape (batch, height, width, in_channels)

Input feature map where each pixel is a point on the Hyperboloid manifold

required
c float

Manifold curvature (default: 1.0)

1.0

Returns:

Name Type Description
out Array of shape (batch, out_height, out_width, out_channels)

Output feature map on the Hyperboloid manifold

Source code in hyperbolix/nn_layers/hyperboloid_conv.py
def __call__(
    self,
    x: Float[Array, "batch height width in_channels"],
    c: float = 1.0,
) -> Float[Array, "batch out_height out_width out_channels"]:
    """
    Forward pass through the ILNN hyperboloid convolutional layer (LogCat + PLFC).

    Parameters
    ----------
    x : Array of shape (batch, height, width, in_channels)
        Input feature map where each pixel is a point on the Hyperboloid manifold
    c : float
        Manifold curvature (default: 1.0)

    Returns
    -------
    out : Array of shape (batch, out_height, out_width, out_channels)
        Output feature map on the Hyperboloid manifold
    """
    # Map to manifold if needed (static branch - JIT friendly)
    x = _map_input_to_manifold(x, self.manifold, self.input_space, c)

    # Extract patches: (B, H', W', kh, kw, C)
    patches_BHWkhkwC = extract_patches(x, self.kernel_size, self.stride, self.padding, self.pad_mode, c)
    batch, out_h, out_w, kh, kw, in_c = patches_BHWkhkwC.shape

    # Flatten batch+spatial for parallel processing: (B*H'*W', K, C)
    patches_flat_NKC = patches_BHWkhkwC.reshape(-1, kh * kw, in_c)

    # LogCat: (K, C) -> (logcat_dim,) per patch — log-radius-preserving concatenation (Shi et al. 2026, Eq. 11)
    logcat_out_NA = jax.vmap(self.manifold.log_radius_concat, in_axes=(0, None))(patches_flat_NKC, c)

    # PLFC linear: (logcat_dim,) -> (out_channels,)
    linear_out_NC = _hyperboloid_plfc_forward(
        logcat_out_NA,
        self.kernel[...],
        self.bias[...],
        self.gyro_bias[...] if self.gyro_bias is not None else None,
        self.manifold,
        c,
        "manifold",  # LogCat output is already on manifold
        self.v_max,
    )  # (B*H'*W', out_channels)

    # Reshape back to spatial
    return linear_out_NC.reshape(batch, out_h, out_w, self.out_channels)

hyperbolix.nn_layers.FGGConv2D

FGGConv2D(
    manifold_module: Hyperboloid,
    in_channels: int,
    out_channels: int,
    kernel_size: int | tuple[int, int],
    *,
    rngs: Rngs,
    stride: int | tuple[int, int] = 1,
    padding: str = "SAME",
    pad_mode: str = "origin",
    activation: Callable | None = None,
    reset_params: str = "fan_out",
    use_weight_norm: bool = False,
    init_kernel_scale: float | None = None,
    init_bias: float = 0.0,
    gain: float = 1.0,
    eps: float = 1e-07,
    param_dtype: DTypeLike = jnp.float32,
)

Bases: Module

Fast and Geometrically Grounded Lorentz 2D convolutional layer.

Uses HCat (Lorentz direct concatenation) to combine receptive field points, then applies FGGLinear for the channel mixing. This matches the reference implementation pattern from Klis et al. 2026.

Computation steps: 1) Extract receptive field patches, pad with manifold origin if needed 2) Apply HCat (Lorentz direct concatenation) to combine patch points 3) Pass through FGGLinear for channel transformation

Parameters:

Name Type Description Default
manifold_module Hyperboloid

Class-based Hyperboloid manifold instance.

required
in_channels int

Input ambient channels (D_in + 1), including time component.

required
out_channels int

Output ambient channels (D_out + 1), including time component.

required
kernel_size int or tuple[int, int]

Size of the convolutional kernel.

required
rngs Rngs

Random number generators for parameter initialization.

required
stride int or tuple[int, int]

Stride of the convolution (default: 1).

1
padding str

Padding mode: "SAME" or "VALID" (default: "SAME").

'SAME'
pad_mode str

How to fill padding pixels: "origin" fills with the manifold origin (sqrt(1/c), 0, ..., 0) (matching reference), "edge" replicates border values (default: "origin").

'origin'
activation Callable or None

Euclidean activation for the FGGLinear (default: None).

None
reset_params str

Weight init for FGGLinear: "eye", "xavier", "kaiming", "lorentz_kaiming", "fan_out", or "mlr" (default: "fan_out"). The "fan_out" default (std sqrt(1/out_spatial)) is norm-preserving, a deliberate deviation from the Klis et al. 2026 classification reference for unnormalized stacks (e.g. an RL backbone feeding a bounded projection). Pass reset_params="lorentz_kaiming", init_bias=0.5 to recover the previous init.

'fan_out'
use_weight_norm bool

Weight normalization in FGGLinear (default: False). Note gain and the "fan_out" scale are renormalized away in this mode; each column's norm is softplus(kernel_scale).

False
init_kernel_scale float or None

Column norm of U at init under use_weight_norm=True (default: None). None keeps the reference init kernel_scale = sqrt(1/(hcat_in + out_channels)), where hcat_in is the HCat ambient dimension, a column norm of about 0.7. A float s > 0 stores kernel_scale = softplus^-1(s).

None
init_bias float

Initial bias for FGGLinear (default: 0.0). A zero bias removes the ~sqrt(out) * init_bias time-row term; pair with "fan_out" for norm preservation.

0.0
gain float

Multiplier on the random init (default: 1.0). With "fan_out" it sets the effective column std to gain / sqrt(out_spatial). No-op for "eye"; renormalized away under use_weight_norm=True.

1.0
eps float

Numerical stability floor (default: 1e-7).

1e-07
param_dtype DTypeLike

Storage dtype of the trainable parameters (default: jnp.float32). Compute precision of manifold operations is set by manifold.dtype.

float32
References

Klis et al. "Fast and Geometrically Grounded Lorentz Neural Networks" (2026).

Source code in hyperbolix/nn_layers/hyperboloid_conv.py
def __init__(
    self,
    manifold_module: Hyperboloid,
    in_channels: int,
    out_channels: int,
    kernel_size: int | tuple[int, int],
    *,
    rngs: nnx.Rngs,
    stride: int | tuple[int, int] = 1,
    padding: str = "SAME",
    pad_mode: str = "origin",
    activation: Callable | None = None,
    reset_params: str = "fan_out",
    use_weight_norm: bool = False,
    init_kernel_scale: float | None = None,
    init_bias: float = 0.0,
    gain: float = 1.0,
    eps: float = 1e-7,
    param_dtype: DTypeLike = jnp.float32,
):
    if init_kernel_scale is not None and not use_weight_norm:
        raise ValueError("init_kernel_scale requires use_weight_norm=True")
    if padding not in ("SAME", "VALID"):
        raise ValueError(f"padding must be either 'SAME' or 'VALID', got '{padding}'")
    if pad_mode not in ("origin", "edge"):
        raise ValueError(f"pad_mode must be 'origin' or 'edge', got '{pad_mode}'")

    validate_hyperboloid_manifold(manifold_module, required_methods=("hcat",))
    self.manifold = manifold_module
    self.in_channels = in_channels
    self.out_channels = out_channels
    self.padding = padding
    self.pad_mode = pad_mode
    self.eps = eps

    self.kernel_size = as_pair(kernel_size)
    self.stride = as_pair(stride)

    # HCat output ambient dim
    hcat_out_ambient = hcat_ambient_dim(in_channels, self.kernel_size)

    # Trainable parameters — owned directly for flat parameter paths
    in_spatial = hcat_out_ambient - 1  # I
    out_spatial = out_channels - 1  # O

    self.activation = activation
    self.use_weight_norm = use_weight_norm

    # Euclidean weight U (I, O). Default "fan_out" std sqrt(1/out_spatial) is
    # norm-preserving; gain scales the random init (no-op for "eye").
    U_init = _fgg_weight_init(
        rngs.params(), in_spatial, out_spatial, hcat_out_ambient, out_channels, reset_params, param_dtype, gain=gain
    )

    # Weight normalization: decompose kernel = softplus(kernel_scale) * kernel_dir / ||kernel_dir||
    if use_weight_norm:
        self.kernel_dir = nnx.Param(U_init)  # (I, O) direction
        if init_kernel_scale is None:
            g_init_val = jnp.sqrt(1.0 / (hcat_out_ambient + out_channels))
        else:
            g_init_val = _inv_softplus(init_kernel_scale)
        self.kernel_scale = nnx.Param(jnp.full((out_spatial,), g_init_val, dtype=param_dtype))  # (O,)
    else:
        self.kernel = nnx.Param(U_init)  # (I, O)

    self.bias = nnx.Param(jnp.full((out_spatial,), init_bias, dtype=param_dtype))  # (O,)

__call__

__call__(
    x: Float[Array, "batch height width in_channels"],
    c: float = 1.0,
) -> Float[
    Array, "batch out_height out_width out_channels"
]

Forward pass through the FGG convolutional layer.

Parameters:

Name Type Description Default
x (Array, shape(B, H, W, in_channels))

Input feature map on the hyperboloid.

required
c float

Curvature parameter (default: 1.0).

1.0

Returns:

Name Type Description
out Array, shape (B, H', W', out_channels)

Output feature map on the hyperboloid.

Source code in hyperbolix/nn_layers/hyperboloid_conv.py
def __call__(
    self,
    x: Float[Array, "batch height width in_channels"],
    c: float = 1.0,
) -> Float[Array, "batch out_height out_width out_channels"]:
    """Forward pass through the FGG convolutional layer.

    Parameters
    ----------
    x : Array, shape (B, H, W, in_channels)
        Input feature map on the hyperboloid.
    c : float, optional
        Curvature parameter (default: 1.0).

    Returns
    -------
    out : Array, shape (B, H', W', out_channels)
        Output feature map on the hyperboloid.
    """
    # Extract patches: (B, H', W', kh, kw, C)
    patches = extract_patches(x, self.kernel_size, self.stride, self.padding, self.pad_mode, c)
    batch, out_h, out_w, kh, kw, in_c = patches.shape

    # Flatten batch+spatial: (B*H'*W', K, C) where K = kh*kw
    patches_flat_NKC = patches.reshape(-1, kh * kw, in_c)

    # HCat: (K, C) -> (hcat_dim,) per patch
    hcat_out_NA = jax.vmap(self.manifold.hcat, in_axes=(0, None))(patches_flat_NKC, c)

    # FGG forward: (hcat_dim,) -> (out_channels,)
    # Unwrap the nnx.Param to a raw array before the helper (matching FGGLinear):
    # _get_effective_kernel is annotated Array | None and only worked here because
    # nnx.Param proxies array ops.
    U_IO = _get_effective_kernel(
        self.kernel[...] if not self.use_weight_norm else None,
        self.kernel_dir[...] if self.use_weight_norm else None,
        self.kernel_scale[...] if self.use_weight_norm else None,
        self.use_weight_norm,
        self.eps,
    )
    linear_out_NC = _fgg_linear_forward(hcat_out_NA, U_IO, self.bias[...], c, self.activation, self.eps)

    # Reshape back to spatial
    return linear_out_NC.reshape(batch, out_h, out_w, self.out_channels)

hyperbolix.nn_layers.LorentzConv2D

LorentzConv2D(
    manifold_module: Hyperboloid,
    in_channels: int,
    out_channels: int,
    kernel_size: int | tuple[int, int],
    *,
    rngs: Rngs,
    stride: int | tuple[int, int] = 1,
    padding: str = "SAME",
    param_dtype: DTypeLike = jnp.float32,
)

Bases: Module

Lorentz 2D Convolutional Layer using the Hyperbolic Layer (HL) approach.

This layer applies convolution to the space-like components of Lorentzian vectors and reconstructs the time-like component to maintain the manifold constraint. This is equivalent to an HRC (Hyperbolic Regularization Component) wrapper around a standard Conv2D.

Computation steps: 1) Extract space-like components x_s from input x = [x_t, x_s]^T 2) Apply Euclidean convolution: y_s = Conv2D(x_s) 3) Reconstruct time component: y_t = sqrt(||y_s||^2 + 1/c) 4) Return y = [y_t, y_s]^T

Parameters:

Name Type Description Default
manifold_module object

Class-based Hyperboloid manifold instance

required
in_channels int

Number of input channels (ambient dimension, including time component)

required
out_channels int

Number of output channels (ambient dimension, including time component)

required
kernel_size int or tuple[int, int]

Size of the convolutional kernel

required
rngs Rngs

Random number generators for parameter initialization

required
stride int or tuple[int, int]

Stride of the convolution (default: 1)

1
padding str or int or tuple

Padding mode: 'SAME', 'VALID', or explicit padding (default: 'SAME')

'SAME'
param_dtype DTypeLike

Storage dtype of the trainable parameters (default: jnp.float32). Compute precision follows Flax's promotion of the input's and the parameters' dtypes; manifold_module is used only to validate the input family, its dtype is not consulted.

float32
Notes

Superseded by :class:FGGConv2D and :class:HypConv2DHyperboloidILNN; kept for reproduction of the LResNet results (He et al. 2025). It is not a hyperbolic convolution: it applies a Euclidean convolution to the space-like components and reconstructs the time component from the constraint, so the receptive field is combined in the ambient tangent directions rather than intrinsically. That makes it cheaper than the HCat-based layers (:class:HypConv2DHyperboloid) but geometrically weaker — prefer the superseding layers for new work.

See Also

hyperbolix.nn_layers.hyperboloid_core.hrc : Core HRC function this layer is based on HypConv2DHyperboloid : Full hyperbolic convolution using HCat concatenation

References

He, Neil, Menglin Yang, and Rex Ying. "Lorentzian residual neural networks." Proceedings of the 31st ACM SIGKDD Conference on Knowledge Discovery and Data Mining V. 1. 2025.

Source code in hyperbolix/nn_layers/hyperboloid_conv.py
def __init__(
    self,
    manifold_module: Hyperboloid,
    in_channels: int,
    out_channels: int,
    kernel_size: int | tuple[int, int],
    *,
    rngs: nnx.Rngs,
    stride: int | tuple[int, int] = 1,
    padding: str = "SAME",
    param_dtype: DTypeLike = jnp.float32,
):
    # Static configuration
    validate_hyperboloid_manifold(manifold_module, required_methods=("hcat",))
    self.manifold = manifold_module
    self.in_channels = in_channels
    self.out_channels = out_channels

    # Create Euclidean conv layer for space components only
    # in_channels - 1: skip time component at index 0
    # out_channels - 1: time will be reconstructed from constraint
    self.conv = nnx.Conv(
        in_features=in_channels - 1,
        out_features=out_channels - 1,
        kernel_size=kernel_size,
        strides=stride,
        padding=padding,
        param_dtype=param_dtype,
        rngs=rngs,
    )

__call__

__call__(
    x: Float[Array, "batch height width in_channels"],
    c: float = 1.0,
) -> Float[
    Array, "batch out_height out_width out_channels"
]

Forward pass through the Lorentz convolutional layer.

This layer is a specific instance of the Hyperbolic Regularization Component (HRC) where the regularization function f_r is a 2D convolution. The HRC pattern: 1. Extracts space components 2. Applies Euclidean convolution 3. Reconstructs time component using Lorentz constraint

Parameters:

Name Type Description Default
x Array of shape (batch, height, width, in_channels)

Input feature map where x[..., 0] is time component and x[..., 1:] are space components on the Lorentz manifold

required
c float

Manifold curvature parameter (default: 1.0)

1.0

Returns:

Name Type Description
out Array of shape (batch, out_height, out_width, out_channels)

Output feature map on the Lorentz manifold

Notes

This implementation uses the hrc function from :mod:hyperbolix.nn_layers.hyperboloid_core, demonstrating that LorentzConv2D (from LResNet) and HRC (from Hypformer) are mathematically equivalent approaches to adapting Euclidean operations for hyperbolic geometry.

Source code in hyperbolix/nn_layers/hyperboloid_conv.py
def __call__(
    self,
    x: Float[Array, "batch height width in_channels"],
    c: float = 1.0,
) -> Float[Array, "batch out_height out_width out_channels"]:
    """
    Forward pass through the Lorentz convolutional layer.

    This layer is a specific instance of the Hyperbolic Regularization Component (HRC)
    where the regularization function f_r is a 2D convolution. The HRC pattern:
    1. Extracts space components
    2. Applies Euclidean convolution
    3. Reconstructs time component using Lorentz constraint

    Parameters
    ----------
    x : Array of shape (batch, height, width, in_channels)
        Input feature map where x[..., 0] is time component and
        x[..., 1:] are space components on the Lorentz manifold
    c : float
        Manifold curvature parameter (default: 1.0)

    Returns
    -------
    out : Array of shape (batch, out_height, out_width, out_channels)
        Output feature map on the Lorentz manifold

    Notes
    -----
    This implementation uses the ``hrc`` function from
    :mod:`hyperbolix.nn_layers.hyperboloid_core`, demonstrating that LorentzConv2D
    (from LResNet) and HRC (from Hypformer) are mathematically equivalent approaches
    to adapting Euclidean operations for hyperbolic geometry.
    """

    # Define convolution as the HRC regularization function f_r
    def conv_fn(x_space):
        return self.conv(x_space)

    # Apply HRC with curvature-preserving transformation (c_in = c_out = c)
    return hrc(x, conv_fn, c_in=c, c_out=c, eps=1e-8)

Poincaré

HypConv2DPoincare extracts patches, applies beta-concatenation (HNN++, Shimizu et al. 2020) over the receptive field, then a HypLinearPoincarePP layer. The concatenated K²·C_in patch is mapped to C_out. Input is tangent by default (input_space="manifold" accepts ball points); output is always tangent vectors.

hyperbolix.nn_layers.HypConv2DPoincare

HypConv2DPoincare(
    manifold_module: Poincare,
    in_channels: int,
    out_channels: int,
    kernel_size: int | tuple[int, int],
    *,
    rngs: Rngs,
    stride: int | tuple[int, int] = 1,
    padding: str = "SAME",
    input_space: str = "tangent",
    id_init: bool = True,
    param_dtype: DTypeLike = jnp.float32,
)

Bases: Module

Hyperbolic 2D Convolutional Layer for Poincaré ball model.

This layer implements hyperbolic convolution following the Poincaré ResNet (van Spengler et al. 2023) approach: beta-scaling in tangent space, patch extraction, expmap to manifold, HNN++ fully-connected, logmap back to tangent space.

The layer operates in tangent space internally and returns tangent-space output, matching the reference implementation. This design avoids the numerically unstable logmap_0 round-trips that cause NaN gradients when points approach the Poincaré ball boundary.

Computation steps: 1) Map to tangent space if input is on manifold 2) Scale tangent vectors by beta function ratio (beta-concatenation scaling) 3) Extract patches via im2col (zero-padding in tangent space) 4) Apply the HNN++ fully-connected layer to the patch vectors mapped to the manifold via expmap_0, and map its output back to tangent space via logmap_0 — both maps evaluated in closed form on the tangent vectors, without forming the ball points

Parameters:

Name Type Description Default
manifold_module Poincare

Class-based Poincaré manifold instance

required
in_channels int

Number of input channels (Poincaré ball dimension per pixel)

required
out_channels int

Number of output channels (Poincaré ball dimension per pixel)

required
kernel_size int or tuple[int, int]

Size of the convolutional kernel

required
rngs Rngs

Random number generators for parameter initialization

required
stride int or tuple[int, int]

Stride of the convolution (default: 1)

1
padding str

Padding mode, either 'SAME' or 'VALID' (default: 'SAME')

'SAME'
input_space str

Type of the input tensor, either 'tangent' or 'manifold' (default: 'tangent'). Note: This is a static configuration - changing it after initialization requires recompilation.

'tangent'
id_init bool

If True (default), initialize the linear sublayer weights as 1/2 · eye(C_out, K²·C_in), as the reference implementation does (0.5 * torch.eye over the nn.Unfold patch vector in HELM's hypercore/nn/conv/poincare_convolution.py). This is not an identity map on the channels. The patch vector is channel-major: entry c·K² + k is input channel c at kernel offset k (offsets row-major), so output channel j reads input channel j // K² at offset j mod K². With C_out ≤ K² every output channel reads input channel 0, each at a different offset, and input channels 1 and up start with zero weight; output channels j ≥ K²·C_in start with all-zero weights. The 1/2 factor compensates for the factor of 2 inside the HNN++ distance formula. If False, the weights are normal with std 1/sqrt(K²·C_in).

True
param_dtype DTypeLike

Storage dtype of the trainable parameters (default: jnp.float32). Compute precision of manifold operations is set by manifold.dtype.

float32
Notes

Output Space: This layer always returns tangent-space output (matching the reference). Between conv layers, use standard activations (e.g., jax.nn.relu) directly on the tangent-space features. Use expmap_0 to map back to the manifold only when needed (e.g., before the classification head).

JIT Compatibility: This layer is designed to work with nnx.jit. Configuration parameters (padding, input_space) are treated as static and will be baked into the compiled function.

Dimension math: - beta-scaling + patch extraction: (H, W, C_in) → (oh, ow, K^2 * C_in) - HNN++ linear: in_dim = K^2 * C_in, out_dim = C_out

References

Shimizu et al. "Hyperbolic neural networks++." arXiv:2006.08210 (2020). van Spengler et al. "Poincaré ResNet." ICML 2023.

Source code in hyperbolix/nn_layers/poincare_conv.py
def __init__(
    self,
    manifold_module: Poincare,
    in_channels: int,
    out_channels: int,
    kernel_size: int | tuple[int, int],
    *,
    rngs: nnx.Rngs,
    stride: int | tuple[int, int] = 1,
    padding: str = "SAME",
    input_space: str = "tangent",
    id_init: bool = True,
    param_dtype: DTypeLike = jnp.float32,
):
    if padding not in ["SAME", "VALID"]:
        raise ValueError(f"padding must be either 'SAME' or 'VALID', got '{padding}'")
    if input_space not in ["tangent", "manifold"]:
        raise ValueError(f"input_space must be either 'tangent' or 'manifold', got '{input_space}'")

    # Static configuration
    validate_poincare_manifold(
        manifold_module,
        required_methods=("logmap_0", "_compute_mlr_pp_tangent"),
    )
    self.manifold = manifold_module
    self.in_channels = in_channels
    self.out_channels = out_channels
    self.input_space = input_space
    self.padding = padding

    self.kernel_size = as_pair(kernel_size)
    self.stride = as_pair(stride)

    # Precompute beta function ratio for tangent-space scaling
    # B(n/2, 1/2) / B(n_i/2, 1/2) where n = K^2 * C_in, n_i = C_in
    kernel_h, kernel_w = self.kernel_size
    K2 = kernel_h * kernel_w
    concat_dim = K2 * in_channels
    # A Python float from static shapes: no JAX op, so the layer can be built inside a jit trace
    # and the value does not depend on `jax_enable_x64`.
    self.beta_scale = beta_concat_scale(concat_dim, in_channels)

    # Trainable parameters — owned directly for flat parameter paths
    # Weight initialization: the reference's 1/2 * eye (HELM's PoincareConvolution2d)
    # or scaled normal std = 1/sqrt(fan_in)
    if id_init:
        # W = 1/2 * eye(C_out, K^2*C_in), the reference layout. Not a channel identity: the
        # patch vector is channel-major, so output j reads input channel j // K^2 at kernel
        # offset j % K^2 (for C_out <= K^2, input channel 0 only).
        # The 1/2 factor compensates for the factor of 2 in the HNN++ distance formula.
        kernel_init = 0.5 * jnp.eye(out_channels, concat_dim, dtype=param_dtype)
    else:
        std = 1.0 / jnp.sqrt(concat_dim)
        kernel_init = jax.random.normal(rngs.params(), (out_channels, concat_dim), dtype=param_dtype) * std
    self.kernel = nnx.Param(kernel_init)
    self.bias = nnx.Param(jnp.zeros((out_channels, 1), dtype=param_dtype))

__call__

__call__(
    x: Float[Array, "batch height width in_channels"],
    c: float = 1.0,
) -> Float[
    Array, "batch out_height out_width out_channels"
]

Forward pass through the Poincaré convolutional layer.

Follows the reference computation flow: tangent-space beta-scaling, patch extraction, expmap_0, HNN++ FC, logmap_0 — with expmap_0 and logmap_0 evaluated on the tangent vectors, never forming the ball points.

Parameters:

Name Type Description Default
x Array of shape (batch, height, width, in_channels)

Input feature map. Can be tangent-space or manifold points depending on input_space setting.

required
c float

Manifold curvature (default: 1.0)

1.0

Returns:

Name Type Description
out Array of shape (batch, out_height, out_width, out_channels)

Output feature map in tangent space at the origin. Use standard activations (e.g., jax.nn.relu) between layers.

Source code in hyperbolix/nn_layers/poincare_conv.py
def __call__(
    self,
    x: Float[Array, "batch height width in_channels"],
    c: float = 1.0,
) -> Float[Array, "batch out_height out_width out_channels"]:
    """
    Forward pass through the Poincaré convolutional layer.

    Follows the reference computation flow: tangent-space beta-scaling,
    patch extraction, expmap_0, HNN++ FC, logmap_0 — with expmap_0 and logmap_0
    evaluated on the tangent vectors, never forming the ball points.

    Parameters
    ----------
    x : Array of shape (batch, height, width, in_channels)
        Input feature map. Can be tangent-space or manifold points
        depending on input_space setting.
    c : float
        Manifold curvature (default: 1.0)

    Returns
    -------
    out : Array of shape (batch, out_height, out_width, out_channels)
        Output feature map in tangent space at the origin.
        Use standard activations (e.g., jax.nn.relu) between layers.
    """
    # Step 1: Map to tangent space if input is on manifold
    if self.input_space == "manifold":
        orig_shape = x.shape
        x_flat_NC = x.reshape(-1, x.shape[-1])  # (B*H*W, C_in)
        x_flat_NC = jax.vmap(self.manifold.logmap_0, in_axes=(0, None))(x_flat_NC, c)
        x = x_flat_NC.reshape(orig_shape)

    # Now x is in tangent space: (B, H, W, C_in)

    # Step 2: Scale tangent vectors by beta ratio (matching reference)
    x = x * self.beta_scale

    # Step 3: Extract patches in tangent space using zero-padding
    kernel_h, kernel_w = self.kernel_size
    stride_h, stride_w = self.stride

    patches_BHWKC = jax.lax.conv_general_dilated_patches(
        lhs=x,
        filter_shape=(kernel_h, kernel_w),
        window_strides=(stride_h, stride_w),
        padding=self.padding,
        dimension_numbers=("NHWC", "OIHW", "NHWC"),
        # Pinned HIGHEST: XLA implements the patch extraction as a convolution against a
        # 0/1 filter, so this is a pure data copy — under TF32 it would round every input
        # value to a 10-bit mantissa before the layer's own GEMM ever sees it, for nothing.
        precision=MATMUL_PRECISION,
    )  # (B, H, W, K²·C_in)

    batch, out_h, out_w, concat_dim = patches_BHWKC.shape

    # Step 4: expmap_0 → HNN++ FC → logmap_0, tangent (N, K²·C_in) → tangent (N, C_out). The FC
    # scores the patch vectors directly and returns logmap_0 of its lift in closed form; the
    # ball round trip capped both ends at √c‖·‖ ≈ 6.32 in float32 at c = 1.
    patches_flat_NKC = patches_BHWKC.reshape(-1, concat_dim)  # (N, K²·C_in) where N=B*H*W
    tangent_out_NC = _poincare_pp_forward(
        patches_flat_NKC,
        self.kernel[...],
        self.bias[...],
        self.manifold,
        c,
        "tangent",
        tangent_output=True,
    )  # (N, C_out)

    # Reshape to spatial output
    output_BHWC = tangent_out_NC.reshape(batch, out_h, out_w, self.out_channels)

    return output_BHWC

Proper Velocity

HypConv2DPV (Chen et al. 2026, Sec 5.3). Because PV geometry is unconstrained \(\mathbb{R}^n\), patch concatenation coincides with Euclidean concatenation — no beta-scaling step; the output width is out_channels. Outputs live on the PV manifold, so Euclidean activations apply directly between conv layers.

hyperbolix.nn_layers.HypConv2DPV

HypConv2DPV(
    manifold_module: ProperVelocity,
    in_channels: int,
    out_channels: int,
    kernel_size: int | tuple[int, int],
    *,
    rngs: Rngs,
    stride: int | tuple[int, int] = 1,
    padding: str = "SAME",
    input_space: str = "manifold",
    inner_activation: Callable[[Array], Array]
    | None = None,
    kernel_init_std: float | None = None,
    param_dtype: DTypeLike = jnp.float32,
)

Bases: Module

Hyperbolic 2D Convolutional Layer for the Proper Velocity model.

Implements Chen et al. 2026, Sec 5.3. Because PV's geometry is unconstrained (ℝⁿ), patch concatenation coincides with Euclidean concatenation — no beta-scaling step is required (unlike HypConv2DPoincare). The layer returns points on the PV manifold; between conv layers, activations can be applied directly in PV space (paper Sec 5.3 "Activation").

Computation steps: 1) Optionally lift tangent-space input to the PV manifold via expmap_0. 2) Extract patches with zero-padding via jax.lax.conv_general_dilated_patches. 3) Flatten batch x spatial dimensions. 4) Apply the PV FC forward (_pv_fc_forward, shared with HypLinearPV). 5) Reshape back to spatial output.

Parameters:

Name Type Description Default
manifold_module ProperVelocity

Class-based Proper Velocity manifold instance.

required
in_channels int

Number of input channels (PV dimension per pixel).

required
out_channels int

Number of output channels (PV dimension per pixel).

required
kernel_size int or tuple[int, int]

Size of the convolutional kernel.

required
rngs Rngs

Random number generators for parameter initialization.

required
stride int or tuple[int, int]

Stride of the convolution (default: 1).

1
padding str

Padding mode, either 'SAME' or 'VALID' (default: 'SAME').

'SAME'
input_space str

Type of the input tensor, either 'tangent' or 'manifold' (default: 'manifold'). Note: This is a static configuration — changing it after initialization requires recompilation.

'manifold'
inner_activation Callable[[Array], Array] | None

Optional activation applied inside the outer sinh (paper Eq. 23). Default None.

None
kernel_init_std float | None

Standard deviation for the Gaussian kernel init. If None (default), uses He scaling sqrt(2 / (kernel_h * kernel_w * in_channels)) so stacked conv blocks preserve variance under ReLU (for small MLR arguments the PV output reduces to an Euclidean linear map per patch, so standard He analysis applies).

None
param_dtype DTypeLike

Storage dtype of the trainable parameters (default: jnp.float32). Compute precision of manifold operations is set by manifold.dtype.

float32
Notes

Output Space: Unlike HypConv2DPoincare (which returns tangent space), this layer returns points on the PV manifold. Between conv layers, apply activations directly on the PV features — no expmap_0/logmap_0 round-trips needed.

JIT Compatibility: Configuration parameters (padding, input_space, inner_activation) are treated as static and are baked into the compiled function.

Dimension math: - patch extraction: (H, W, C_in) → (oh, ow, K²·C_in) - PV FC: in_dim = K²·C_in, out_dim = C_out

References

Chen et al. "Proper Velocity Neural Networks." ICLR 2026.

Source code in hyperbolix/nn_layers/pv_conv.py
def __init__(
    self,
    manifold_module: ProperVelocity,
    in_channels: int,
    out_channels: int,
    kernel_size: int | tuple[int, int],
    *,
    rngs: nnx.Rngs,
    stride: int | tuple[int, int] = 1,
    padding: str = "SAME",
    input_space: str = "manifold",
    inner_activation: Callable[[Array], Array] | None = None,
    kernel_init_std: float | None = None,
    param_dtype: DTypeLike = jnp.float32,
):
    if padding not in ["SAME", "VALID"]:
        raise ValueError(f"padding must be either 'SAME' or 'VALID', got '{padding}'")
    if input_space not in ["tangent", "manifold"]:
        raise ValueError(f"input_space must be either 'tangent' or 'manifold', got '{input_space}'")

    validate_pv_manifold(
        manifold_module,
        required_methods=("expmap_0", "compute_mlr"),
    )
    self.manifold = manifold_module
    self.in_channels = in_channels
    self.out_channels = out_channels
    self.input_space = input_space
    self.padding = padding
    self.inner_activation = inner_activation

    self.kernel_size = as_pair(kernel_size)
    self.stride = as_pair(stride)

    kernel_h, kernel_w = self.kernel_size
    concat_dim = kernel_h * kernel_w * in_channels

    # Kernel init: He(fan_in) by default so deep conv stacks preserve
    # variance under ReLU. Bias init is uniform U(-1e-3, 1e-3), matching
    # the paper reference.
    std = (2.0 / concat_dim) ** 0.5 if kernel_init_std is None else kernel_init_std
    self.kernel = nnx.Param(jax.random.normal(rngs.params(), (out_channels, concat_dim), dtype=param_dtype) * std)
    self.bias = nnx.Param(
        jax.random.uniform(rngs.params(), (out_channels, 1), dtype=param_dtype, minval=-1e-3, maxval=1e-3)
    )

__call__

__call__(
    x: Float[Array, "batch height width in_channels"],
    c: float = 1.0,
) -> Float[
    Array, "batch out_height out_width out_channels"
]

Forward pass through the PV convolutional layer.

Parameters:

Name Type Description Default
x Array of shape (batch, height, width, in_channels)

Input feature map. PV manifold points or tangent-space vectors at the origin, depending on input_space.

required
c float

Manifold curvature (default: 1.0).

1.0

Returns:

Name Type Description
out Array of shape (batch, out_height, out_width, out_channels)

Output feature map on the PV manifold.

Source code in hyperbolix/nn_layers/pv_conv.py
def __call__(
    self,
    x: Float[Array, "batch height width in_channels"],
    c: float = 1.0,
) -> Float[Array, "batch out_height out_width out_channels"]:
    """
    Forward pass through the PV convolutional layer.

    Parameters
    ----------
    x : Array of shape (batch, height, width, in_channels)
        Input feature map. PV manifold points or tangent-space vectors at the
        origin, depending on ``input_space``.
    c : float
        Manifold curvature (default: 1.0).

    Returns
    -------
    out : Array of shape (batch, out_height, out_width, out_channels)
        Output feature map on the PV manifold.
    """
    # Step 1: Optionally lift tangent-space input to the PV manifold.
    if self.input_space == "tangent":
        orig_shape = x.shape
        x_flat_NC = x.reshape(-1, x.shape[-1])  # (B*H*W, C_in)
        x_flat_NC = jax.vmap(self.manifold.expmap_0, in_axes=(0, None))(x_flat_NC, c)
        x = x_flat_NC.reshape(orig_shape)

    # Step 2: Extract patches with zero-padding (raw concat — no beta scaling).
    kernel_h, kernel_w = self.kernel_size
    stride_h, stride_w = self.stride

    patches_BHWKC = jax.lax.conv_general_dilated_patches(
        lhs=x,
        filter_shape=(kernel_h, kernel_w),
        window_strides=(stride_h, stride_w),
        padding=self.padding,
        dimension_numbers=("NHWC", "OIHW", "NHWC"),
        # Pinned HIGHEST: XLA implements the patch extraction as a convolution against a
        # 0/1 filter, so this is a pure data copy — under TF32 it would round every input
        # value to a 10-bit mantissa before the layer's own GEMM ever sees it, for nothing.
        precision=MATMUL_PRECISION,
    )  # (B, H, W, K²·C_in)

    batch, out_h, out_w, concat_dim = patches_BHWKC.shape

    # Step 3: Flatten batch x spatial dims for the FC.
    patches_flat_NKC = patches_BHWKC.reshape(-1, concat_dim)  # (N, K²·C_in)

    # Step 4: PV FC — input is already on the PV manifold (no extra lift).
    fc_out_NC = _pv_fc_forward(
        patches_flat_NKC,
        self.kernel[...],
        self.bias[...],
        self.manifold,
        c,
        "manifold",
        self.inner_activation,
    )  # (N, C_out) on PV manifold

    # Step 5: Reshape to spatial output.
    return fc_out_NC.reshape(batch, out_h, out_w, self.out_channels)

Pooling & flattening (conv → FC bridge)

Two ways to turn an (B, H', W', C) hyperboloid feature map into one point per sample before a classification head. hyp_avg_pool2d averages the spatial parts over the grid and keeps the width (C in → C out). hyp_flatten2d keeps every pixel by LogCat-concatenating them, so the width grows to H'·W'·(C−1) + 1.

Do not flatten a feature map with a plain reshape

Concatenating N = H'·W' hyperboloid points without the LogCat digamma rescale inflates the flattened point's spatial radius by ≈ √(H'·W') — the same dimension-widening bias Hyperboloid.log_radius_concat exists to correct inside HypConv2DHyperboloidILNN's per-patch concat, but with N = the whole feature map instead of one 3×3 receptive field. Use hyp_flatten2d; see the numerical-stability guide.

hyperbolix.nn_layers.hyp_avg_pool2d

hyp_avg_pool2d(
    x: Float[Array, "... H W dim_plus_1"],
    c: float,
    eps: float = 1e-07,
) -> Float[Array, "... dim_plus_1"]

Global average pooling over 2D spatial dimensions on the hyperboloid.

Averages the spatial components over the height and width dimensions, then reconstructs the time component via the hyperboloid constraint. This is the HRC pattern with f_r = mean_over_spatial:

.. math::

\text{space} = \text{mean}_{H,W}(x[..., 1:])

x_0 = \sqrt{\|\text{space}\|^2 + 1/c}

\text{output} = [x_0, \text{space}]

The function expects the NHWC layout used throughout hyperbolix: (..., H, W, ambient_dim) where ambient_dim = spatial_dim + 1.

This operation is hyperboloid-only because it relies on the time/spatial decomposition x[..., 0] (time) and x[..., 1:] (spatial). Poincaré ball points do not have a time component. To pool Poincaré features, first convert to hyperboloid via :func:~hyperbolix.manifolds.isometry_mappings.poincare_to_hyperboloid, pool, then convert back.

Parameters:

Name Type Description Default
x (Array, shape(..., H, W, dim + 1))

Hyperboloid feature map with curvature c. The last axis is the ambient dimension (time + spatial). The two axes before it are the spatial height H and width W.

required
c float

Curvature parameter (positive, c > 0).

required
eps float

Numerical stability floor for the time reconstruction (default: 1e-7).

1e-07

Returns:

Type Description
(Array, shape(..., dim + 1))

Pooled hyperboloid points with curvature c.

See Also

spatial_to_hyperboloid : Low-level curvature scaling + time reconstruction. hrc : General HRC wrapper for arbitrary Euclidean functions. lorentz_midpoint : Weighted Lorentzian midpoint (geometrically exact aggregation).

Examples:

>>> import jax
>>> import jax.numpy as jnp
>>> from hyperbolix.manifolds import Hyperboloid
>>> from hyperbolix.nn_layers.hyperboloid_core import hyp_avg_pool2d
>>>
>>> hyperboloid = Hyperboloid(dtype=jnp.float32)
>>> key = jax.random.PRNGKey(0)
>>> v = jax.random.normal(key, (4, 7, 7, 64), dtype=jnp.float32) * 0.1
>>> v = v.at[..., 0].set(0.0)  # tangent vectors at the origin
>>> x = jax.vmap(jax.vmap(jax.vmap(
...     hyperboloid.expmap_0, in_axes=(0, None)
... ), in_axes=(0, None)), in_axes=(0, None))(v, 1.0)
>>> x.shape
(4, 7, 7, 64)
>>> y = hyp_avg_pool2d(x, c=1.0)
>>> y.shape
(4, 64)
Source code in hyperbolix/nn_layers/hyperboloid_core.py
def hyp_avg_pool2d(
    x: Float[Array, "... H W dim_plus_1"],
    c: float,
    eps: float = 1e-7,
) -> Float[Array, "... dim_plus_1"]:
    """Global average pooling over 2D spatial dimensions on the hyperboloid.

    Averages the spatial components over the height and width dimensions,
    then reconstructs the time component via the hyperboloid constraint.
    This is the HRC pattern with ``f_r = mean_over_spatial``:

    .. math::

        \\text{space} = \\text{mean}_{H,W}(x[..., 1:])

        x_0 = \\sqrt{\\|\\text{space}\\|^2 + 1/c}

        \\text{output} = [x_0, \\text{space}]

    The function expects the **NHWC** layout used throughout hyperbolix:
    ``(..., H, W, ambient_dim)`` where ``ambient_dim = spatial_dim + 1``.

    This operation is **hyperboloid-only** because it relies on the time/spatial
    decomposition ``x[..., 0]`` (time) and ``x[..., 1:]`` (spatial). Poincaré
    ball points do not have a time component. To pool Poincaré features, first
    convert to hyperboloid via
    :func:`~hyperbolix.manifolds.isometry_mappings.poincare_to_hyperboloid`,
    pool, then convert back.

    Parameters
    ----------
    x : Array, shape (..., H, W, dim+1)
        Hyperboloid feature map with curvature ``c``.  The last axis is
        the ambient dimension (time + spatial).  The two axes before it
        are the spatial height ``H`` and width ``W``.
    c : float
        Curvature parameter (positive, c > 0).
    eps : float, optional
        Numerical stability floor for the time reconstruction
        (default: 1e-7).

    Returns
    -------
    Array, shape (..., dim+1)
        Pooled hyperboloid points with curvature ``c``.

    See Also
    --------
    spatial_to_hyperboloid : Low-level curvature scaling + time reconstruction.
    hrc : General HRC wrapper for arbitrary Euclidean functions.
    lorentz_midpoint : Weighted Lorentzian midpoint (geometrically exact aggregation).

    Examples
    --------
    >>> import jax
    >>> import jax.numpy as jnp
    >>> from hyperbolix.manifolds import Hyperboloid
    >>> from hyperbolix.nn_layers.hyperboloid_core import hyp_avg_pool2d
    >>>
    >>> hyperboloid = Hyperboloid(dtype=jnp.float32)
    >>> key = jax.random.PRNGKey(0)
    >>> v = jax.random.normal(key, (4, 7, 7, 64), dtype=jnp.float32) * 0.1
    >>> v = v.at[..., 0].set(0.0)  # tangent vectors at the origin
    >>> x = jax.vmap(jax.vmap(jax.vmap(
    ...     hyperboloid.expmap_0, in_axes=(0, None)
    ... ), in_axes=(0, None)), in_axes=(0, None))(v, 1.0)
    >>> x.shape
    (4, 7, 7, 64)
    >>> y = hyp_avg_pool2d(x, c=1.0)
    >>> y.shape
    (4, 64)
    """
    # Dimension key: H=height, W=width, D=spatial_dim, A=ambient_dim (D+1)

    x_space_HWD = x[..., 1:]  # (..., H, W, D) — drop time coordinate
    x_pooled_D = jnp.mean(x_space_HWD, axis=(-3, -2))  # (..., D)
    return spatial_to_hyperboloid(x_pooled_D, c_in=c, c_out=c, eps=eps)  # (..., D+1)

hyperbolix.nn_layers.hyp_flatten2d

hyp_flatten2d(
    x: Float[Array, "... H W dim_plus_1"],
    manifold_module: Manifold,
    c: float,
) -> Float[Array, "... flat_dim_plus_1"]

LogCat-flatten a hyperboloid feature map into one point per sample (conv → FC boundary).

Concatenates the H·W per-pixel hyperboloid points of a feature map into a single hyperboloid point, using the log-radius-preserving concatenation :meth:~hyperbolix.manifolds.hyperboloid.Hyperboloid.log_radius_concat (LogCat, Shi et al. 2026, Sec. 4.3) rather than a plain reshape/hcat. This is the flatten step between a hyperboloid convolutional trunk and an FC / MLR head.

Why not a plain reshape. Stacking the N = H·W spatial blocks without a correction widens the spatial dimension from D to N·D while leaving each block's entries untouched. For Gaussian-ish spatial parts ‖v‖² ~ χ²_k, so E[log‖v‖] = ½·(ψ(k/2) + log 2) grows with the dimension k: the flattened point's spatial radius (and hence its geodesic radius from the origin) inflates by ≈ √(H·W). At a conv → FC boundary N is the whole feature map — tens to low hundreds — so the inflation is far larger than the √9 of a single 3x3 receptive field. Before the MLR asinh clamp was removed, an MLR head fed such a point sat pinned at that clamp at init, with near-zero gradients. LogCat rescales every block by the digamma ratio s = exp(½·(ψ(D/2) - ψ(N·D/2))) ≈ 1/√N before concatenating and then recomputes the time coordinate, so the expected log spatial radius of the flattened point matches that of one pixel.

Dimension bookkeeping (all hyperboloid channel counts are ambient, time first): H·W blocks of D = A - 1 spatial dims each become one point with H·W·D spatial dims plus a single time coordinate, i.e. A' = H·W·(A - 1) + 1. Note this grows the width — pair it with a dimensionality-reducing head, or pool with :func:hyp_avg_pool2d instead when a fixed-width global summary is what you want.

Parameters:

Name Type Description Default
x (Array, shape(..., H, W, A))

Hyperboloid feature map with curvature c in NHWC layout. The last axis is the ambient per-pixel dimension A = D + 1 (time + spatial); the two axes before it are height H and width W. Leading axes are treated as batch.

required
manifold_module Manifold

Hyperboloid manifold instance (e.g. hyperbolix.manifolds.Hyperboloid()); must provide log_radius_concat.

required
c float

Curvature parameter (positive, c > 0).

required

Returns:

Type Description
(Array, shape(..., H * W * (A - 1) + 1))

One hyperboloid point per sample, on the widened hyperboloid with curvature c.

Raises:

Type Description
ValueError

If x has fewer than 3 axes (no (H, W, A) tail to flatten).

TypeError

If manifold_module is not a Hyperboloid-like manifold.

See Also

hyperbolix.manifolds.hyperboloid.Hyperboloid.log_radius_concat : The LogCat operation. hyperbolix.manifolds.hyperboloid.Hyperboloid.hcat : Unscaled concatenation (inflates the radius). hyp_avg_pool2d : Dimension-preserving global pool — the alternative conv → FC bridge.

References

Shi et al. "Intrinsic Lorentz Neural Network." ICLR 2026, Sec. 4.3 (LogCat).

Examples:

>>> import jax
>>> import jax.numpy as jnp
>>> from hyperbolix.manifolds import Hyperboloid
>>> from hyperbolix.nn_layers.hyperboloid_core import hyp_flatten2d
>>>
>>> hyperboloid = Hyperboloid(dtype=jnp.float32)
>>> key = jax.random.PRNGKey(0)
>>> v = jax.random.normal(key, (4, 4, 4, 17), dtype=jnp.float32) * 0.1
>>> v = v.at[..., 0].set(0.0)  # tangent vectors at the origin
>>> x = jax.vmap(jax.vmap(jax.vmap(
...     hyperboloid.expmap_0, in_axes=(0, None)
... ), in_axes=(0, None)), in_axes=(0, None))(v, 1.0)
>>> x.shape
(4, 4, 4, 17)
>>> y = hyp_flatten2d(x, hyperboloid, c=1.0)
>>> y.shape  # 4*4 blocks of 16 spatial dims + 1 time coordinate
(4, 257)
Source code in hyperbolix/nn_layers/hyperboloid_core.py
def hyp_flatten2d(
    x: Float[Array, "... H W dim_plus_1"],
    manifold_module: Manifold,
    c: float,
) -> Float[Array, "... flat_dim_plus_1"]:
    """LogCat-flatten a hyperboloid feature map into one point per sample (conv → FC boundary).

    Concatenates the ``H·W`` per-pixel hyperboloid points of a feature map into a single
    hyperboloid point, using the log-radius-preserving concatenation
    :meth:`~hyperbolix.manifolds.hyperboloid.Hyperboloid.log_radius_concat` (LogCat, Shi
    et al. 2026, Sec. 4.3) rather than a plain ``reshape``/``hcat``. This is the flatten
    step between a hyperboloid convolutional trunk and an FC / MLR head.

    **Why not a plain reshape.** Stacking the ``N = H·W`` spatial blocks without a
    correction widens the spatial dimension from ``D`` to ``N·D`` while leaving each
    block's entries untouched. For Gaussian-ish spatial parts ``‖v‖² ~ χ²_k``, so
    ``E[log‖v‖] = ½·(ψ(k/2) + log 2)`` grows with the dimension ``k``: the flattened
    point's spatial radius (and hence its geodesic radius from the origin) inflates by
    ``≈ √(H·W)``. At a conv → FC boundary ``N`` is the whole feature map — tens to low
    hundreds — so the inflation is far larger than the ``√9`` of a single 3x3 receptive
    field. Before the MLR ``asinh`` clamp was removed, an MLR head fed such a point sat
    pinned at that clamp at init, with near-zero gradients.
    LogCat rescales every block by the digamma ratio
    ``s = exp(½·(ψ(D/2) - ψ(N·D/2))) ≈ 1/√N`` before concatenating and then recomputes
    the time coordinate, so the expected log spatial radius of the flattened point
    matches that of one pixel.

    Dimension bookkeeping (all hyperboloid channel counts are **ambient**, time first):
    ``H·W`` blocks of ``D = A - 1`` spatial dims each become one point with ``H·W·D``
    spatial dims plus a single time coordinate, i.e. ``A' = H·W·(A - 1) + 1``. Note this
    grows the width — pair it with a dimensionality-reducing head, or pool with
    :func:`hyp_avg_pool2d` instead when a fixed-width global summary is what you want.

    Parameters
    ----------
    x : Array, shape (..., H, W, A)
        Hyperboloid feature map with curvature ``c`` in **NHWC** layout. The last axis is
        the ambient per-pixel dimension ``A = D + 1`` (time + spatial); the two axes
        before it are height ``H`` and width ``W``. Leading axes are treated as batch.
    manifold_module : Manifold
        Hyperboloid manifold instance (e.g. ``hyperbolix.manifolds.Hyperboloid()``);
        must provide ``log_radius_concat``.
    c : float
        Curvature parameter (positive, c > 0).

    Returns
    -------
    Array, shape (..., H*W*(A-1)+1)
        One hyperboloid point per sample, on the widened hyperboloid with curvature ``c``.

    Raises
    ------
    ValueError
        If ``x`` has fewer than 3 axes (no ``(H, W, A)`` tail to flatten).
    TypeError
        If ``manifold_module`` is not a Hyperboloid-like manifold.

    See Also
    --------
    hyperbolix.manifolds.hyperboloid.Hyperboloid.log_radius_concat : The LogCat operation.
    hyperbolix.manifolds.hyperboloid.Hyperboloid.hcat : Unscaled concatenation (inflates the radius).
    hyp_avg_pool2d : Dimension-preserving global pool — the alternative conv → FC bridge.

    References
    ----------
    Shi et al. "Intrinsic Lorentz Neural Network." ICLR 2026, Sec. 4.3 (LogCat).

    Examples
    --------
    >>> import jax
    >>> import jax.numpy as jnp
    >>> from hyperbolix.manifolds import Hyperboloid
    >>> from hyperbolix.nn_layers.hyperboloid_core import hyp_flatten2d
    >>>
    >>> hyperboloid = Hyperboloid(dtype=jnp.float32)
    >>> key = jax.random.PRNGKey(0)
    >>> v = jax.random.normal(key, (4, 4, 4, 17), dtype=jnp.float32) * 0.1
    >>> v = v.at[..., 0].set(0.0)  # tangent vectors at the origin
    >>> x = jax.vmap(jax.vmap(jax.vmap(
    ...     hyperboloid.expmap_0, in_axes=(0, None)
    ... ), in_axes=(0, None)), in_axes=(0, None))(v, 1.0)
    >>> x.shape
    (4, 4, 4, 17)
    >>> y = hyp_flatten2d(x, hyperboloid, c=1.0)
    >>> y.shape  # 4*4 blocks of 16 spatial dims + 1 time coordinate
    (4, 257)
    """
    # Dimension key: H=height, W=width, N=H*W (blocks), D=per-pixel spatial dim,
    #                A=per-pixel ambient dim (D+1), B=flattened batch, Af=H*W*D+1

    validate_hyperboloid_manifold(manifold_module, ("log_radius_concat",))
    if x.ndim < 3:
        raise ValueError(
            f"hyp_flatten2d expects an NHWC-style array with at least 3 axes (H, W, ambient), got shape {x.shape}."
        )

    *lead_shape, height, width, ambient = x.shape

    # Collapse leading (batch) axes and the H/W grid: one (N, A) point sequence per sample.
    points_BNA = x.reshape(-1, height * width, ambient)  # (B, N, A)

    # LogCat per sample: (N, A) -> (N*D+1,). vmap because manifold ops are single-point.
    # `log_radius_concat` is Hyperboloid-only and therefore not on the `Manifold` protocol;
    # the `validate_hyperboloid_manifold` call above is what guarantees it is present.
    log_radius_concat = cast(Hyperboloid, manifold_module).log_radius_concat
    flat_BAf = jax.vmap(log_radius_concat, in_axes=(0, None))(points_BNA, c)  # (B, Af)

    return flat_BAf.reshape(*lead_shape, flat_BAf.shape[-1])  # (..., Af)

Example

import jax, jax.numpy as jnp
from flax import nnx
from hyperbolix.nn_layers import HypConv2DHyperboloid
from hyperbolix.manifolds import Hyperboloid

conv = HypConv2DHyperboloid(
    manifold_module=Hyperboloid(), in_channels=17, out_channels=32,
    kernel_size=(3, 3), stride=(1, 1), rngs=nnx.Rngs(0),
)
x = jax.random.normal(jax.random.PRNGKey(1), (8, 28, 28, 16))
x_amb = jnp.concatenate([jnp.sqrt(jnp.sum(x**2, -1, keepdims=True) + 1.0), x], -1)  # (8,28,28,17)
output = conv(x_amb, c=1.0)
print(output.shape)  # (8, 28, 28, 32) — output width is out_channels, independent of kernel size