Skip to content

Continuous Spaces

A space gives the admissible values of a continuous variable and the shape of one value. The module gives Euclidean, simplex, positive, Cholesky factor, covariance, correlation, orthogonal, Stiefel, sphere, ball, triangular, diagonal, and product spaces. A positive scalar can hold a standard deviation, and a simplex holds nonnegative vectors whose entries sum to one. Repeated observations add batch dimensions (Pyro Developers, n.d.-e) around this value shape.

spaces

Continuous measurable spaces for the hybrid architecture.

Continuous space objects serve as domains and codomains for continuous morphisms. They complement quivers.core.objects (FinSet etc.) used by discrete morphisms.

The space family is a sum type:

  • Euclidean — :math:\mathbb{R}^d with optional bounds
  • Simplex — probability simplex over d components
  • PositiveReals — :math:(0, \infty)^d
  • ProductSpace — cartesian product of continuous spaces

UnitInterval is a convenience factory for [0, 1]^d.

ContinuousSpace didactic-model

ContinuousSpace()

Bases: TaggedUnion

Continuous measurable space (Euclidean, Simplex, PositiveReals, Product).

Variants expose name: str and dim: int either as fields (the atomic variants) or as derived properties (ProductSpace), plus a contains predicate over the support.

event_shape property

event_shape: tuple[int, ...]

Shape of a single sample.

contains

contains(x: Tensor) -> Tensor

Check whether points lie in the support.

Source code in src/quivers/continuous/spaces.py
def contains(self, x: torch.Tensor) -> torch.Tensor:
    """Check whether points lie in the support."""
    raise NotImplementedError(f"{type(self).__name__}.contains")

sample_uniform

sample_uniform(n: int) -> Tensor

Sample n points uniformly from the space.

Source code in src/quivers/continuous/spaces.py
def sample_uniform(self, n: int) -> torch.Tensor:
    """Sample n points uniformly from the space."""
    raise NotImplementedError(
        f"{type(self).__name__} does not support uniform sampling"
    )

Euclidean didactic-model

Euclidean(*, name: str, dim: int, low: float | None = None, high: float | None = None, plate_rows: int | None = None, intrinsic_shape: tuple[int, ...] | None = None, kind: Literal['euclidean'] = 'euclidean')

Bases: ContinuousSpace

Euclidean space :math:\mathbb{R}^d, optionally bounded.

plate_rows marks the space as the flattened codomain of a plate draw: :math:\mathbb{R}^{d} read as plate_rows independent rows of width dim // plate_rows. The distinction matters wherever a plate variable is consumed as a parameter rather than as a value, because the plate axis is a batch axis there and the per-row parameter width is row_width, never the flat dim.

intrinsic_shape optionally records the tensor axes of one event. Its product must equal dim. Without it, events retain the legacy flat vector shape (dim,); neither a singleton axis nor a rectangle is inferred from the number of entries.

PARAMETER DESCRIPTION
name

Carrier label.

TYPE: str

dim

Total scalar entries in one event.

TYPE: int

low

Optional common lower bound on each entry.

TYPE: float or None DEFAULT: None

high

Optional common upper bound on each entry.

TYPE: float or None DEFAULT: None

plate_rows

Number of rows represented by a flattened plate carrier.

TYPE: int or None DEFAULT: None

intrinsic_shape

Explicit tensor event axes, including any singleton or empty axes.

TYPE: tuple of int or None DEFAULT: None

kind

Tagged-union discriminator.

TYPE: Literal['euclidean'] DEFAULT: 'euclidean'

event_shape property

event_shape: tuple[int, ...]

Declared tensor event axes, or the legacy flat vector shape.

is_bounded property

is_bounded: bool

Whether the space has finite bounds on all sides.

row_width property

row_width: int

Width of a single row of the space.

For an ordinary Euclidean space this is dim. For a flattened plate codomain it is the per-row width, i.e. dim // plate_rows.

contains

contains(x: Tensor) -> Tensor

Check bounds over the event axes, retaining every batch axis.

PARAMETER DESCRIPTION
x

Points with the declared trailing event shape.

TYPE: Tensor

RETURNS DESCRIPTION
Tensor

Boolean membership with only the leading batch axes.

RAISES DESCRIPTION
ValueError

If an explicitly shaped point has incompatible event axes.

Source code in src/quivers/continuous/spaces.py
def contains(self, x: torch.Tensor) -> torch.Tensor:
    """Check bounds over the event axes, retaining every batch axis.

    Parameters
    ----------
    x : torch.Tensor
        Points with the declared trailing event shape.

    Returns
    -------
    torch.Tensor
        Boolean membership with only the leading batch axes.

    Raises
    ------
    ValueError
        If an explicitly shaped point has incompatible event axes.
    """
    rank = len(self.event_shape)
    if self.intrinsic_shape is not None and (
        x.ndim < rank or rank and tuple(x.shape[-rank:]) != self.event_shape
    ):
        raise ValueError(
            f"expected trailing event shape {self.event_shape}, got {tuple(x.shape)}"
        )
    batch_shape = x.shape[:-rank] if rank else x.shape
    result = torch.ones(batch_shape, dtype=torch.bool, device=x.device)
    axes = tuple(range(x.ndim - rank, x.ndim))
    if self.low is not None:
        valid = x >= self.low
        result = result & (valid.all(dim=axes) if axes else valid)
    if self.high is not None:
        valid = x <= self.high
        result = result & (valid.all(dim=axes) if axes else valid)
    return result

sample_uniform

sample_uniform(n: int) -> Tensor

Sample bounded events while retaining their declared tensor axes.

PARAMETER DESCRIPTION
n

Number of independently sampled events.

TYPE: int

RETURNS DESCRIPTION
Tensor

Samples of shape (n, *event_shape).

RAISES DESCRIPTION
ValueError

If the space has no finite pair of bounds.

Source code in src/quivers/continuous/spaces.py
def sample_uniform(self, n: int) -> torch.Tensor:
    """Sample bounded events while retaining their declared tensor axes.

    Parameters
    ----------
    n : int
        Number of independently sampled events.

    Returns
    -------
    torch.Tensor
        Samples of shape ``(n, *event_shape)``.

    Raises
    ------
    ValueError
        If the space has no finite pair of bounds.
    """
    if not self.is_bounded:
        raise ValueError("cannot sample uniformly from unbounded Euclidean space")
    assert self.low is not None and self.high is not None
    return torch.rand(n, *self.event_shape) * (self.high - self.low) + self.low

Simplex didactic-model

Simplex(*, name: str, dim: int, kind: Literal['simplex'] = 'simplex')

Bases: ContinuousSpace

The probability simplex :math:\{x \in \mathbb{R}^d : x_i \geq 0, \sum x_i = 1\}.

PositiveReals didactic-model

PositiveReals(*, name: str, dim: int, kind: Literal['positive_reals'] = 'positive_reals')

Bases: ContinuousSpace

The positive reals :math:(0, \infty)^d.

CholeskyFactor didactic-model

CholeskyFactor(*, name: str, dim: int, kind: Literal['cholesky_factor'] = 'cholesky_factor')

Bases: ContinuousSpace

The manifold of :math:K \times K lower-triangular Cholesky factors.

Each element is a lower-triangular matrix :math:L whose rows have unit norm: :math:L_{ii}^2 + \sum_{j<i} L_{ij}^2 = 1 for every :math:i. The product :math:L L^T is then a correlation matrix. The standard parameterization places :math:L on a :math:K(K-1)/2-dimensional manifold.

Carrier represented as a flat :math:K \times K array (row-major); the on-manifold constraint is enforced by the sampling family (quivers.continuous.families.LKJCorrelationFactor) and not by the type itself.

ProductSpace didactic-model

ProductSpace(*, components: tuple[ContinuousSpace | SetObject, ...] = field(default=(), converter=_flatten_spaces), kind: Literal['product_space'] = 'product_space')

Bases: ContinuousSpace

Cartesian product of continuous spaces (and discrete objects).

Components may be a mix of ContinuousSpace variants and quivers.core.objects.SetObject variants — programs whose domain or codomain combines discrete and continuous variables produce such a ProductSpace at compile time. Nested products are flattened on construction; name and dim are derived from components (for SetObject components, dim falls back to len(component.shape)).

Sphere didactic-model

Sphere(*, name: str, dim: int, kind: Literal['sphere'] = 'sphere')

Bases: ContinuousSpace

The unit sphere :math:S^{N-1} = \{x \in \mathbb{R}^N : \|x\|_2 = 1\}.

Ambient dimension is dim = N; the manifold dimension is N - 1. Carrier represented as an (N,) tensor; the unit-norm constraint is enforced by the sampling family (e.g. von Mises-Fisher), not by the type itself.

Ball didactic-model

Ball(*, name: str, dim: int, radius: float = 1.0, kind: Literal['ball'] = 'ball')

Bases: ContinuousSpace

The closed ball :math:\{x \in \mathbb{R}^N : \|x\|_2 \le r\}.

Carrier represented as an (N,) tensor. The radius field fixes r; the default r = 1 produces the unit ball.

Covariance didactic-model

Covariance(*, name: str, dim: int, kind: Literal['covariance'] = 'covariance')

Bases: ContinuousSpace

The cone of :math:D \times D symmetric positive-definite matrices.

Used as the codomain of Wishart-shaped families. Carrier represented as a flat (D*D,) tensor (row-major); the positivity constraint is enforced by the sampling family.

Correlation didactic-model

Correlation(*, name: str, dim: int, kind: Literal['correlation'] = 'correlation')

Bases: ContinuousSpace

The manifold of :math:D \times D correlation matrices.

A correlation matrix is symmetric positive-definite with unit diagonal: :math:R_{ii} = 1 and :math:R \succ 0. Used as the codomain of LKJ correlation priors. Carrier represented as a flat (D*D,) tensor.

Orthogonal didactic-model

Orthogonal(*, name: str, dim: int, kind: Literal['orthogonal'] = 'orthogonal')

Bases: ContinuousSpace

The orthogonal group :math:O(D) = \{Q \in \mathbb{R}^{D \times D} : Q^T Q = I\}.

Carrier represented as a flat (D*D,) tensor. The orthogonality constraint is enforced by the sampling family; sample_uniform produces Haar-distributed elements via QR decomposition of a standard Gaussian (the Mezzadri construction).

Stiefel didactic-model

Stiefel(*, name: str, rows: int, cols: int, kind: Literal['stiefel'] = 'stiefel')

Bases: ContinuousSpace

The Stiefel manifold :math:V_K(\mathbb{R}^N) = \{X \in \mathbb{R}^{N \times K} : X^T X = I_K\}.

Generalises Orthogonal to rectangular orthonormal-column matrices. rows is :math:N, cols is :math:K; require :math:K \le N. The base dim field is :math:N, kept for the standard event_shape = (dim,) contract; the actual carrier is flat with shape (N*K,).

LowerTriangular didactic-model

LowerTriangular(*, name: str, dim: int, kind: Literal['lower_triangular'] = 'lower_triangular')

Bases: ContinuousSpace

The space of :math:D \times D lower-triangular matrices.

The carrier holds a flat (D*D,) tensor; the structural zero constraint on the strictly upper-triangular entries is enforced by the sampling family / parameterization. Used as a parameterization carrier for Cholesky-style decompositions when no diagonal-sign constraint is required.

Diagonal didactic-model

Diagonal(*, name: str, dim: int, kind: Literal['diagonal'] = 'diagonal')

Bases: ContinuousSpace

The space of :math:D \times D diagonal matrices.

Identified with :math:\mathbb{R}^D via the natural diagonal embedding; the carrier holds a flat (D,) tensor of diagonal entries. Used as the codomain of independent-variance parameterizations where each component carries its own scalar variance.

UnitInterval

UnitInterval(name: str, dim: int = 1) -> Euclidean

Create a :math:[0, 1]^d bounded Euclidean space.

Source code in src/quivers/continuous/spaces.py
def UnitInterval(name: str, dim: int = 1) -> Euclidean:
    """Create a :math:`[0, 1]^d` bounded Euclidean space."""
    return Euclidean(name=name, dim=dim, low=0.0, high=1.0)

Cited sources

Pyro Developers. Tensor shapes in Pyro. Pyro Tutorials, version 1.9.1, n.d.-e. URL: https://pyro.ai/examples/tensor_shapes.html (visited on 2026-11-06).