Helper utilities
This page documents utility types and functions that appear at the boundaries of the inference engine — primarily in custom node and rule implementations. They are not needed for everyday inference with built-in nodes, but become useful when writing @rule definitions or building new factor node types.
Iteration helpers
When a message update rule computes the outgoing message on edge k of a factor node, it needs the incoming messages from all other edges — every edge except k. The ReactiveMP.SkipIndexIterator provides an allocation-free view of a collection that skips one index.
The constructor skipindex is the standard way to create one:
# messages is a length-3 collection; compute outgoing message for edge 2
# by iterating over edges 1 and 3 only
other = ReactiveMP.skipindex(messages, 2)
collect(other) # [messages[1], messages[3]]This is used internally inside @rule dispatch to pass only the relevant inbound messages to the rule computation.
ReactiveMP.SkipIndexIterator — Type
SkipIndexIteratorA special type of iterator that simply iterates over internal iterator, but skips index skip.
Arguments
iterator: internal iteratorskip: index to skip (integer)
See also: skipindex
ReactiveMP.skipindex — Function
skipindex(iterator, skip)Creation operator for SkipIndexIterator.
julia> s = ReactiveMP.skipindex(1:3, 2)
2-element ReactiveMP.SkipIndexIterator{Int64, UnitRange{Int64}}:
1
3
julia> collect(s)
2-element Vector{Int64}:
1
3See also: SkipIndexIterator
Macro utilities
The ReactiveMP.MacroHelpers submodule contains building blocks used by the @node and @rule macros to parse and transform Julia type expressions. These are implementation details of the macro system, but they are documented here for completeness and for users who want to understand or extend the macro infrastructure.
| Function | Purpose |
|---|---|
ReactiveMP.MacroHelpers.ensure_symbol | Assert that an expression is a Symbol; error otherwise |
ReactiveMP.MacroHelpers.bottom_type | Extract the base type T from expressions like Type{<:T}, typeof(T), or T |
ReactiveMP.MacroHelpers.upper_type | Wrap a type expression into Type{<:T} form for dispatch |
ReactiveMP.MacroHelpers.proxy_type | Wrap a type with a proxy type as ProxyType{<:T} |
ReactiveMP.MacroHelpers.@proxy_methods | Generate forwarding method definitions for a proxy wrapper type |
@proxy_methods is the most user-facing of these. It generates a set of method forwarding stubs so that a thin wrapper type transparently delegates calls to its wrapped type, without hand-writing each delegation.
ReactiveMP.MacroHelpers.proxy_type — Function
proxy_type(proxy, type)Returns a type wrapped with a proxy type in a form of ProxyType{ <: Type }.
Arguments
proxy: Proxy type used to wraptypetype: Type to be wrapped
ReactiveMP.MacroHelpers.ensure_symbol — Function
ensure_symbol(input)This function ensures that the given argument has a Symbol type
ReactiveMP.MacroHelpers.@proxy_methods — Macro
@proxy_methods(proxy_type, proxy_getter, proxy_methods)Generates proxy methods for a specified proxy_type using proxy_getter. For example:
@proxy_methods Message getdata [
Distributions.mean,
Distributions.var
]generates:
Distributions.mean(proxy::Message) = Distributions.mean(getdata(proxy))
Distributions.var(proxy::Message) = Distributions.mean(getdata(proxy))ReactiveMP.MacroHelpers.upper_type — Function
upper_type(type)This function returns Type{ <: T } expression for the following input expressions:
- typeof(T)
- Type{ <: T }
- Type{ T }
- T
Arguments
type: Type expression to be extended
ReactiveMP.MacroHelpers.bottom_type — Function
bottom_type(type)This function returns T expression for the following input expressions:
- typeof(T)
- Type{ <: T }
- Type{ T }
- T
Arguments
type: Type expression to be lowered