Custom Types API Reference

Custom type definitions for SciStanPy models.

This module provides type aliases and unions for various components used throughout the SciStanPy package, including parameter types, distribution types, and utility types for type checking and documentation purposes.

All imports are conditional on TYPE_CHECKING to avoid circular imports while maintaining proper type hints for development and documentation tools.

Note

SciStanPy enforces strict type checking for all callables using the typeguard package.

Scalar Types

These types combine both NumPy and PyTorch scalar types for convenience.

scistanpy.custom_types.Integer

Type alias for integer values.

Accepts both Python’s built-in int and NumPy integer types.

Type:

Union[int, np.integer]

alias of int | np.integer

scistanpy.custom_types.Float

Type alias for floating-point values.

Accepts both Python’s built-in float and NumPy floating-point types.

Type:

Union[float, np.floating]

alias of float | np.floating

Parameter Types

These types represent different groupings of objects that can be used within SciStanPy models.

scistanpy.custom_types.SampleType

Type alias for sample values that can be returned from distributions.

Used to represent values that can be sampled from probability distributions, including scalars and arrays.

Type:

Union[int, float, npt.NDArray]

alias of int | float | npt.NDArray

scistanpy.custom_types.BaseParameterType

Composite type of transformed parameters and constants, whihc are the types typically used to define hyperparameters.

Type:

Union[transformed_parameters.TransformedParameter, constants.Constant]

alias of transformed_parameters.TransformedParameter | constants.Constant

scistanpy.custom_types.ContinuousParameterType

Type alias for continuous-valued parameters.

Encompasses all parameter types that can take continuous values, including base parameters, continuous distributions, and numeric values.

Type:

Union[BaseParameterType, parameters.ContinuousDistribution, float, npt.NDArray[np.floating]]

alias of transformed_parameters.TransformedParameter | constants.Constant | parameters.ContinuousDistribution | float | npt.NDArray[np.floating]

scistanpy.custom_types.DiscreteParameterType

Type alias for discrete-valued parameters.

Encompasses all parameter types that can take discrete values, including base parameters, discrete distributions, and integer values.

Type:

Union[BaseParameterType, parameters.DiscreteDistribution, int, npt.NDArray[np.integer]]

alias of transformed_parameters.TransformedParameter | constants.Constant | parameters.DiscreteDistribution | int | npt.NDArray[np.integer]

scistanpy.custom_types.CombinableParameterType

Type alias for parameters that can be combined in model operations.

Represents any parameter type that can be used in mathematical operations and model construction, covering both continuous and discrete parameters.

Type:

Union[ContinuousParameterType, DiscreteParameterType]

alias of transformed_parameters.TransformedParameter | constants.Constant | parameters.ContinuousDistribution | float | npt.NDArray[np.floating] | parameters.DiscreteDistribution | int | npt.NDArray[np.integer]

Distribution Types

scistanpy.custom_types.SciStanPyDistribution

Type alias for PyTorch-compatible probability distributions used in SciStanPy.

Encompasses both PyTorch distributions and custom SciStanPy distribution implementations.

Type:

Union[dist.Distribution, custom_torch_dists.CustomDistribution]

alias of dist.Distribution | custom_torch_dists.CustomDistribution

Diagnostic Types

scistanpy.custom_types.ProcessedTestRes

Type alias for processed diagnostic test results.

Used for storing test results with associated metadata.

Type:

dict[str, tuple[tuple[npt.NDArray, …], int]]

alias of dict[str, tuple[tuple[npt.NDArray, …], int]]

scistanpy.custom_types.StrippedTestRes

Type alias for stripped diagnostic test results.

Simplified version of ProcessedTestRes containing only the essential array data.

Type:

dict[str, tuple[npt.NDArray, …]]

alias of dict[str, tuple[npt.NDArray, …]]

Utility Types

scistanpy.custom_types.IndexType

Type alias for array indexing operations.

Covers all valid indexing types for NumPy arrays and similar data structures, including integer arrays, slices, single integers, ellipsis, and None.

Type:

Union[npt.NDArray[np.integer], slice, int, Ellipsis, None]

alias of npt.NDArray[np.integer] | slice | int | … | None

Usage Examples

Type Checking in Functions:

from scistanpy.custom_types import ContinuousParameterType

def process_parameter(param: ContinuousParameterType) -> float:
    """Process a continuous parameter."""
    # Function accepts any continuous parameter type
    return float(param)