The of Type System
Overview
The of type system provides a declarative way to specify parameter types for probabilistic programming. It is a lightweight, framework-agnostic type-annotation system that:
- Returns schema types (not instances) for downstream annotation systems
- Encodes specifications (dimensions, bounds) in type parameters
- Provides utilities for parameter manipulation (
rand,zero,flatten,unflatten)
It lives in AbstractPPL so that downstream packages can share a common vocabulary for describing the shape, element type, and support of model variables. JuliaBUGS, for example, uses it for @model parameter annotations.
The examples on this page are executed when the documentation is built. The imports are brought into scope here; later examples reuse them.
using AbstractPPL
using AbstractPPL: flatten, unflatten
using RandomCore Concepts
1. Type-Based Design
The of function returns types with specifications encoded in type parameters:
of(Array, dims...)→OfArray{Float64, N, (dim1, dim2, ...)}- Arrays with specified dimensionsof(Array, T, dims...)→OfArray{T, N, (dim1, dim2, ...)}- Typed numeric arrays (T <: Number)of(Float64)→OfReal{Float64, Nothing, Nothing}- Unbounded 64-bit floating point numbersof(Float32)→OfReal{Float32, Nothing, Nothing}- Unbounded 32-bit floating point numbersof(Float64, lower, upper)→OfReal{Float64, lower, upper}- Bounded 64-bit floatsof(Float32, lower, upper)→OfReal{Float32, lower, upper}- Bounded 32-bit floatsof(Real)→OfReal{Float64, Nothing, Nothing}- Unbounded real numbers (defaults to Float64)of(Real, lower, upper)→OfReal{Float64, lower, upper}- Bounded real numbers (defaults to Float64)of(Int)→OfInt{Nothing, Nothing}- Unbounded integersof(Int, lower, upper)→OfInt{lower, upper}- Bounded integers@of(field1=..., field2=...)→OfNamedTuple{(:field1, :field2), Tuple{Type1, Type2}}- Named tuples (use@ofmacro)of(...; constant=true)→OfConstantWrapper{T}- Marks a type as constant/hyperparameter (supported for float types andInt)
A few of(...) calls and the concrete types they return:
of(Float64, 0, 1)of(Float64, 0, 1)of(Array, 3, 4)of(Array, 3, 4)of(Int; constant=true)of(Int; constant=true)2. Type Parameter Encoding
The system encodes extra useful information into type parameters:
- Dimensions: Stored as tuple type parameters (e.g.,
(3, 4)for a 3×4 matrix) - Bounds: Numeric literals stored directly as type parameters (e.g.,
0.0,1.0), orNothingfor unbounded - Symbolic references: Encoded using
SymbolicRef{:symbol}for referencing earlier constant fields - Arithmetic expressions: Encoded using
SymbolicExpr{expr}for expressions liken+1,2*n, etc. Division operations must result in integers for array dimensions. - Field names: Stored as a tuple of symbols in
OfNamedTuple - Element types: Preserved as type parameters for numeric arrays and nested structures
3. Operations on Types
T(; kwargs...)whereT<:OfNamedTuple— Create instances with specified constants (returns values, not types). Useszero()as the default for missing values.T(default_value; kwargs...)whereT<:OfNamedTuple— Create instances with specified constants and initialise all element values todefault_value, e.g.T(missing; kwargs...)initialises all element values tomissing.T(...)returns instances, not types.of(T; kwargs...)whereT<:OfType— Create concrete types by resolving constantsrand([rng], T::Type{<:OfType})— Generate random values matching the type specification (pass anAbstractRNGfor reproducible draws)zero(T::Type{<:OfType})— Generate zero/default valuessize(T::Type{<:OfType})— Get the dimensions/shape of the typelength(T::Type{<:OfType})— Get the total number of elements when flattenedflatten(T::Type{<:OfType}, values)— Convert structured values to a flat vector (element type is the promotion of the declared leaf types)unflatten(T::Type{<:OfType}, vec)— Reconstruct structured values from a flat vector (float leaves takepromote_type(declared, eltype(vec)), so AD numbers flow through)unflatten(T::Type{<:OfType}, missing)— Create instances where element values are initialised tomissing
Only of and @of are exported. flatten, unflatten, the OfType subtypes, and the inspection helpers are public but not exported, so qualify them (AbstractPPL.flatten) or bring them into scope with using AbstractPPL: flatten, unflatten.
4. The @of Macro
The @of macro provides cleaner syntax by automatically converting references to earlier constant fields to symbols. Here n in the array dimension is automatically converted to the symbol :n:
T = @of(
n = of(Int; constant=true),
data = of(Array, n, 2) # 'n' is automatically converted to :n
)@of(n=of(Int; constant=true), data=of(Array, n, 2))5. Symbolic Dimensions and Bounds
For cases where dimensions need to be specified at runtime, declare the dimensions as constants and reference them in the array specifications:
MatrixType = @of(
rows = of(Int; constant=true),
cols = of(Int; constant=true),
data = of(Array, rows, cols),
)@of(
rows = of(Int; constant=true),
cols = of(Int; constant=true),
data = of(Array, rows, cols)
)Resolving the constants with of(MatrixType; ...) produces a concrete type with the symbolic dimensions filled in:
ConcreteType = of(MatrixType; rows=3, cols=4)@of(data=of(Array, 3, 4))The concrete type works with rand and zero. The draw uses a seeded RNG so the rendered output is reproducible:
rand(MersenneTwister(0), ConcreteType) # random 3×4 matrix wrapped in a NamedTuple(data = [0.44373084494754944 0.16983717354013406 0.9425709791902743 0.727832145515513; 0.012341715444441181 0.559106625669447 0.9632256863827882 0.7857840841423287; 0.07892681580529581 0.09920468528804882 0.48785917694153547 0.4504541380106568],)zero(ConcreteType) # zero 3×4 matrix wrapped in a NamedTuple(data = [0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0],)Concretization can be partial. Resolving only rows leaves cols symbolic (semiconcretized):
SemiConcreteType = of(MatrixType; rows=3)@of(cols=of(Int; constant=true), data=of(Array, 3, cols))Calling the type as a constructor builds an instance. With all constants provided, the non-constant data field defaults to zeros:
MatrixType(; rows=3, cols=4)(data = [0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0],)Passing missing initialises element values to missing:
MatrixType(missing; rows=3, cols=4)(data = [missing missing missing missing; missing missing missing missing; missing missing missing missing],)Specific data can be provided directly for non-constant fields:
MatrixType(; rows=3, cols=4, data=ones(3, 4))(data = [1.0 1.0 1.0 1.0; 1.0 1.0 1.0 1.0; 1.0 1.0 1.0 1.0],)A concrete type can be flattened and reconstructed. Here we flatten a 3×4 instance and recover it (flatten/unflatten are public, not exported):
instance = MatrixType(; rows=3, cols=4)
flat = flatten(ConcreteType, instance)12-element Vector{Float64}:
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0reconstructed = unflatten(ConcreteType, flat)(data = [0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0],)rand and zero also work directly on a concretized type:
rand(MersenneTwister(0), of(MatrixType; rows=3, cols=4)) # random instance(data = [0.44373084494754944 0.16983717354013406 0.9425709791902743 0.727832145515513; 0.012341715444441181 0.559106625669447 0.9632256863827882 0.7857840841423287; 0.07892681580529581 0.09920468528804882 0.48785917694153547 0.4504541380106568],)zero(of(MatrixType; rows=10, cols=5)) # zero instance(data = [0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0; … ; 0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0],)Operations that still need unresolved information error. Constructing with a missing constant throws, so we catch and display the message:
try
MatrixType(; rows=3) # `cols` is required but not provided
catch err
showerror(stdout, err)
endConstant `cols` is required but not providedLikewise, drawing from a type with unresolved symbolic dimensions throws:
try
rand(MatrixType) # symbolic dimensions are unresolved
catch err
showerror(stdout, err)
endCannot generate random values for constants. Use rand(of(T; const_name=value)) after providing the constant value.Arithmetic expressions in dimensions
Dimensions may be arithmetic expressions of constant fields. Division operations must result in integers for array dimensions:
ExpandedMatrixType = @of(
n = of(Int; constant=true),
original = of(Array, n, n),
padded = of(Array, n + 1, n + 1),
doubled = of(Array, 2 * n, n),
halved = of(Array, n / 2, n),
)@of(
n = of(Int; constant=true),
original = of(Array, n, n),
padded = of(Array, n + 1, n + 1),
doubled = of(Array, 2 * n, n),
halved = of(Array, n / 2, n)
)Creating an instance with n=10 evaluates each expression: original is 10×10, padded is 11×11, doubled is 20×10, and halved is 5×10. Non-constant fields default to zero. We display each field's shape:
instance = ExpandedMatrixType(; n=10)
map(size, instance)(original = (10, 10), padded = (11, 11), doubled = (20, 10), halved = (5, 10))A custom default value fills every matrix instead of using zeros:
instance = ExpandedMatrixType(1.0; n=10)
instance.original10×10 Matrix{Float64}:
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0If a division does not yield an integer dimension, instantiation throws. With n=9, n / 2 = 4.5 is not an integer:
try
ExpandedMatrixType(; n=9) # n / 2 = 4.5 is not an integer
catch err
showerror(stdout, err)
endDivision 9 / 2 = 4.5 is not an integer. Array dimensions must be integers.Flattening parameters
flatten/unflatten are useful for code that needs a flat parameter vector (for example, an optimiser or a sampler) while keeping a structured view of the parameters. We define a small parameter specification:
Params = @of(mu = of(Real), sigma = of(Real, 0, nothing), beta = of(Array, Float64, 3))@of(mu=of(Float64), sigma=of(Float64, 0, nothing), beta=of(Array, 3))The total flattened length is length(Params):
length(Params)5Flattening a structured value produces a flat vector:
values = (mu=0.5, sigma=1.2, beta=[0.1, 0.2, 0.3])
flat = flatten(Params, values)5-element Vector{Float64}:
0.5
1.2
0.1
0.2
0.3unflatten reconstructs the original (mu, sigma, beta) NamedTuple:
reconstructed = unflatten(Params, flat)(mu = 0.5, sigma = 1.2, beta = [0.1, 0.2, 0.3])flatten returns a vector whose element type is the promotion of the declared leaf types, and unflatten is automatic-differentiation transparent: floating-point leaves take promote_type(declared, eltype(flat)), so ForwardDiff.Dual (or BigFloat, …) numbers in the flat vector flow through to the reconstructed structure. This makes the pair suitable for gradient-based samplers and optimisers that differentiate through unflatten.
Constants (fields wrapped with constant=true) are excluded from the flattened representation and must be resolved with of(T; kwargs...) before flattening.
Use in models
Because of returns schema types, downstream packages can use those types in their own annotation systems. JuliaBUGS, for instance, accepts an of type as the parameter annotation of a @model's argument destructuring, e.g. (; mu, beta, sigma)::ParamsType. These schema types are not supertypes of raw values, so 1.0 isa of(Float64) is false; see the downstream package documentation for the modelling integration.
API Reference
AbstractPPL.of — Function
of(T, args...; constant::Bool=false)Create an OfType specification from various inputs.
Main Methods
Arrays
of(Array, dims...) # Float64 array with given dimensions
of(Array, T, dims...) # Array with numeric element type T and given dimensionsReal Numbers
of(Float64) # Unbounded Float64
of(Float64, lower, upper) # Bounded Float64
of(Float32) # Unbounded Float32
of(Float32, lower, upper) # Bounded Float32
of(Real) # Unbounded Real (defaults to Float64)
of(Real, lower, upper) # Bounded Real (defaults to Float64)Integers
of(Int) # Unbounded integer
of(Int, lower, upper) # Bounded integerNamed Tuples
of((;field1=spec1, field2=spec2, ...)) # NamedTuple with typed fieldsFrom Values (Type Inference)
of(1.0) # Infers of(Float64)
of([1, 2, 3]) # Infers of(Array, Int, 3)
of((a=1, b=2.0)) # Infers OfNamedTupleArguments
T: Type to create specification forargs...: Type-specific arguments (bounds, dimensions, etc.)constant: Mark type as constant/hyperparameter (default: false)
Returns
An OfType subtype encoding the specification in its type parameters.
Examples
# Basic types
T1 = of(Float64, 0, 1) # OfReal{Float64, 0, 1}
T2 = of(Array, 3, 4) # OfArray{Float64, 2, (3, 4)}
T3 = of(Int; constant=true) # OfConstantWrapper{OfInt{Nothing, Nothing}}
# With @of macro for cleaner syntax
T4 = @of(
n = of(Int; constant=true),
data = of(Array, n, 2) # Symbolic dimension
)
# Type concretization
T5 = of(T4; n=10) # Concrete type with n=10See also
of(::Type{T}, replacements::NamedTuple) where T<:OfType
of(::Type{T}; kwargs...) where T<:OfType
of(::Type{T}, pairs::Pair{Symbol}...) where T<:OfTypeCreate a concrete type by resolving symbolic dimensions and removing constants.
This function takes an OfType with symbolic dimensions or constants and creates a new type with some or all symbols resolved to concrete values. Constants that are provided are removed from the resulting type.
Arguments
T<:OfType: The type to concretizereplacements: Named tuple or keyword arguments mapping symbols to values
Returns
A new OfType with symbols replaced and constants removed.
Examples
# Define type with symbolic dimensions
T = @of(
n = of(Int; constant=true),
data = of(Array, n, 2)
)
# Create concrete type
ConcreteT = of(T; n=10) # @of(data=of(Array, 10, 2))
# Partial concretization
T2 = @of(
rows = of(Int; constant=true),
cols = of(Int; constant=true),
matrix = of(Array, rows, cols)
)
Partial = of(T2; rows=5) # @of(cols=of(Int; constant=true), matrix=of(Array, 5, :cols))See also
AbstractPPL.@of — Macro
@of(field1=spec1, field2=spec2, ...)Create an OfNamedTuple type with cleaner syntax for field references.
The @of macro provides a more intuitive syntax for creating named tuple types where fields can reference each other. Field names used in dimensions or bounds are automatically converted to symbolic references.
Syntax
@of(
field_name = of_specification,
...
)Features
- Direct references to earlier constant fields without quoting (e.g.,
ninstead of:n) - Support for arithmetic expressions in dimensions (e.g.,
n+1,2*n) - Automatic conversion to appropriate
OfNamedTupletype - Fields are processed in order, allowing later fields to reference earlier constants
Examples
# Basic usage with constants and arrays
T = @of(
n = of(Int; constant=true),
mu = of(Real),
data = of(Array, n, 2) # 'n' automatically converted to symbolic reference
)
# With arithmetic expressions
T = @of(
n = of(Int; constant=true),
original = of(Array, n, n),
padded = of(Array, n+1, n+1),
doubled = of(Array, 2*n, n)
)
# Nested structures: field references resolve within the @of that declares them, so keep
# a dimension's constants in the same block (cross-level paths like `dims.rows` are not
# supported), then concretize the whole tree at once.
Inner = @of(
rows = of(Int; constant=true),
cols = of(Int; constant=true),
matrix = of(Array, rows, cols)
)
T = @of(block = Inner)
CT = of(T; rows=3, cols=4)See also
AbstractPPL.flatten — Function
flatten(::Type{T}, values) where T<:OfTypeConvert structured values to a flat numeric vector.
Walks values in field order, vectorising arrays (column-major) and recursing into named tuples, and returns a flat vector whose element type is the promotion of the declared leaf element types (so a pure-Int structure stays Vector{Int}, while any float field widens the whole vector). This is the form an optimiser or sampler wants. Constants are excluded by construction, since a flattenable type has none.
Returns
A Vector{V} where V is promote_type of the declared leaf element types.
Examples
flatten(of(Float64), 3.14) # [3.14] (Vector{Float64})
flatten(of(Array, 2, 2), [1 2; 3 4]) # [1.0, 3.0, 2.0, 4.0]
T = @of(x=of(Real), y=of(Array, 2, 2))
flatten(T, (x=1.5, y=[1 2; 3 4])) # [1.5, 1.0, 3.0, 2.0, 4.0]Errors
- Throws if
valuesdo not match the specification (shape or bounds). - Throws for types with unresolved symbolic dimensions, bounds, or constants.
See also
AbstractPPL.unflatten — Function
unflatten(::Type{T}, flat_values::AbstractVector{<:Real}) where T<:OfType
unflatten(::Type{T}, ::Missing) where T<:OfTypeReconstruct structured values from a flat numeric vector (the inverse of flatten).
Arrays are reshaped, named tuples are rebuilt in field order, and bounds are validated. Floating-point leaves take promote_type(declared, eltype(flat_values)): the declared float type acts as a precision floor, while wider numbers in flat_values — AD numbers (ForwardDiff.Dual), BigFloat — flow through unchanged. Integer leaves are rounded to Int.
The missing method builds a structure with every element set to missing.
Examples
unflatten(of(Float64), [3.14]) # 3.14
unflatten(of(Array, 2, 2), [1, 3, 2, 4]) # [1.0 2.0; 3.0 4.0]
T = @of(x=of(Real), y=of(Array, 2, 2))
unflatten(T, [1.5, 1.0, 3.0, 2.0, 4.0]) # (x=1.5, y=[1.0 2.0; 3.0 4.0])
unflatten(T, missing) # (x=missing, y=[missing missing; missing missing])Errors
- Throws if
length(flat_values)differs fromlength(T). - Throws if values violate bounds.
- Throws for types with unresolved symbolic dimensions, bounds, or constants.
See also
Base.rand — Method
rand([rng::AbstractRNG], ::Type{T}) where T<:OfTypeGenerate random values matching the type specification.
Creates random instances that satisfy the constraints encoded in the OfType. Arrays are filled with random values, named tuples recurse over their fields, and bounded scalars respect their bounds. Pass an rng for reproducible draws; the method without one uses Random.default_rng().
The bounded/unbounded distributions are deliberate but unspecified conveniences:
OfReal: uniform on[lower, upper]; for a single bound, a (reflected) shifted exponential; standard normal when unbounded.OfInt: uniform onlower:upper; for a single bound, an arbitrary 100-wide window anchored at it;-100:100when unbounded.OfArray: each element drawn as for its element type.OfNamedTuple: each field drawn recursively.OfConstantWrapper: not supported (throws).
Examples
using Random
rand(of(Float64, 0, 1)) # a Float64 in [0, 1]
rand(of(Array, 3, 4)) # a 3×4 Matrix{Float64}
rand(StableRNG(1), @of(x=of(Real, 0, 1))) # reproducible NamedTuple draw
T = @of(n=of(Int; constant=true), data=of(Array, n, 2))
rand(of(T; n=5)) # (data = <random 5×2 array>,)Errors
- Throws for types with unresolved symbolic dimensions or bounds.
- Throws for constant wrapper types.
See also
Base.zero — Function
zero(::Type{T}) where T<:OfTypeGenerate zero/default values matching the type specification.
Creates instances initialized to appropriate zero values that satisfy the constraints. For bounded types where zero is outside the bounds, returns the nearest bound value.
Behavior by Type
OfReal: Returns 0.0 if within bounds, otherwise nearest boundOfInt: Returns 0 if within bounds, otherwise nearest boundOfArray: Returns array filled with zerosOfNamedTuple: Recursively generates zero values for all fieldsOfConstantWrapper: Not supported (throws error)
Examples
# Unbounded types
zero(of(Float64)) # 0.0
zero(of(Int)) # 0
zero(of(Array, 3, 2)) # 3×2 matrix of zeros
# Bounded types respect bounds
zero(of(Real, 1.0, 2.0)) # 1.0 (lower bound since 0 is outside)
zero(of(Int, -10, -5)) # -5 (upper bound since 0 is outside)
# Named tuples
T = @of(x=of(Real), y=of(Array, 2, 2))
zero(T) # (x=0.0, y=[0.0 0.0; 0.0 0.0])
# With resolved constants
T = @of(n=of(Int; constant=true), data=of(Array, n, n))
zero(of(T; n=3)) # (data = 3×3 zero matrix)Errors
- Throws error for types with unresolved symbolic dimensions
- Throws error for constant wrapper types
See also
Base.size — Function
size(::Type{T}) where T<:OfTypeGet the dimensions/shape of an OfType specification.
Returns the size information encoded in the type. For arrays, returns a tuple of dimensions. For scalars, returns an empty tuple. For named tuples, returns a named tuple with the size of each field.
Returns
OfArray: Tuple of dimensionsOfReal,OfInt: Empty tuple()OfNamedTuple: Named tuple with sizes of each fieldOfConstantWrapper: Delegates to wrapped type
Examples
size(of(Array, 3, 4)) # (3, 4)
size(of(Float64)) # ()
size(of(Int, 0, 10)) # ()
T = @of(x=of(Real), y=of(Array, 2, 3))
size(T) # (x=(), y=(2, 3))Errors
- Throws error for arrays with unresolved symbolic dimensions
See also
Base.length — Function
length(::Type{T}) where T<:OfTypeGet the total number of elements when the type is flattened.
Returns the total count of numerical values that would be in a flattened representation. Arrays contribute their total element count, scalars contribute 1, and named tuples sum the lengths of all fields. Constants (wrapped in OfConstantWrapper) contribute 0 as they are not part of the flattened representation.
Returns
OfArray: Product of dimensions (total elements)OfReal,OfInt: 1OfNamedTuple: Sum of lengths of all fieldsOfConstantWrapper: 0 (constants excluded from flattening)
Examples
length(of(Array, 3, 4)) # 12
length(of(Float64)) # 1
length(of(Int, 0, 10)) # 1
T = @of(x=of(Real), y=of(Array, 2, 3))
length(T) # 7 (1 + 6)
# Constants contribute 0; concrete fields still count
T2 = @of(n=of(Int; constant=true), data=of(Array, 3, 3))
length(T2) # 9 (n contributes 0, data contributes 9)
length(of(T2; n=5)) # 9 (n removed; data unchanged)Errors
- Throws error for arrays with unresolved symbolic dimensions
See also
AbstractPPL.OfType — Type
OfTypeAbstract base type for all types in the of type system.
The of type system provides a declarative way to specify parameter types for probabilistic programming. All of types encode their specifications (dimensions, bounds, etc.) in type parameters so downstream libraries can use them as schema types in their own annotation systems.
Subtypes
OfReal{T,Lower,Upper}: Bounded or unbounded floating-point numbersOfInt{Lower,Upper}: Bounded or unbounded integersOfArray{T,N,Dims}: Arrays with specified element type and dimensionsOfNamedTuple{Names,Types}: Named tuples with typed fieldsOfConstantWrapper{T}: Wrapper marking a type as constant/hyperparameter
See also
AbstractPPL.OfReal — Type
OfReal{T<:AbstractFloat,Lower,Upper}Type specification for bounded or unbounded floating-point numbers.
Type Parameters
T<:AbstractFloat: The concrete floating-point type (e.g.,Float64,Float32)Lower: Lower bound (numeric value,Nothingfor unbounded, orSymbolicRef)Upper: Upper bound (numeric value,Nothingfor unbounded, orSymbolicRef)
Examples
of(Float64) # OfReal{Float64, Nothing, Nothing}
of(Float32, 0.0, 1.0) # OfReal{Float32, 0.0, 1.0}
of(Real, 0, nothing) # OfReal{Float64, 0, Nothing} (defaults to Float64)See also
AbstractPPL.OfInt — Type
OfInt{Lower,Upper}Type specification for bounded or unbounded integers.
Type Parameters
Lower: Lower bound (integer value,Nothingfor unbounded, orSymbolicRef)Upper: Upper bound (integer value,Nothingfor unbounded, orSymbolicRef)
Examples
of(Int) # OfInt{Nothing, Nothing}
of(Int, 1, 10) # OfInt{1, 10}
of(Int, 0, nothing) # OfInt{0, Nothing}See also
AbstractPPL.OfArray — Type
OfArray{T,N,Dims}Type specification for arrays with fixed element type and dimensions.
Type Parameters
T: Element type of the arrayN: Number of dimensionsDims: Tuple type encoding the size of each dimension (can includeSymbolicReforSymbolicExpr)
Examples
of(Array, 3, 4) # OfArray{Float64, 2, (3, 4)}
of(Array, Float32, 10) # OfArray{Float32, 1, (10,)}
@of(n=of(Int; constant=true), data=of(Array, n, 2)) # Symbolic dimensionSee also
AbstractPPL.OfNamedTuple — Type
OfNamedTuple{Names,Types<:Tuple}Type specification for named tuples with typed fields.
Type Parameters
Names: Tuple of field names as symbolsTypes<:Tuple: Tuple of field types (each must be anOfType)
Examples
@of(mu=of(Real), tau=of(Real, 0, nothing))
of((a=of(Int), b=of(Array, 3, 3)))See also
AbstractPPL.OfConstantWrapper — Type
OfConstantWrapper{T<:OfType}Wrapper type marking a field as a constant/hyperparameter.
Constants are not included in flattened representations and must be provided when creating instances or concretizing types with symbolic dimensions.
Type Parameters
T<:OfType: The wrapped type specification
Examples
of(Int; constant=true) # OfConstantWrapper{OfInt{Nothing, Nothing}}
of(Real; constant=true) # OfConstantWrapper{OfReal{Float64, Nothing, Nothing}}See also
AbstractPPL.SymbolicRef — Type
SymbolicRef{S}Wrapper type for symbolic references in bounds and dimensions.
Used internally to encode references to earlier constant fields when specifying bounds or dimensions. For example, when using @of(n=of(Int; constant=true), data=of(Array, n, 2)), the reference to n in the array dimension is encoded as SymbolicRef{:n}.
Type Parameters
S: The symbol being referenced
See also
AbstractPPL.SymbolicExpr — Type
SymbolicExpr{E}Wrapper type for symbolic expressions in dimensions.
Used internally to encode arithmetic expressions involving earlier constant fields. For example, when using @of(n=of(Int; constant=true), padded=of(Array, n+1, n+1)), the expression n+1 is encoded as SymbolicExpr{(:+, :n, 1)}.
Supported operations: +, -, *, /. Division operations must result in integers when used for array dimensions.
Type Parameters
E: A tuple representing the expression in prefix notation
See also