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.SkipIndexIteratorType
SkipIndexIterator

A special type of iterator that simply iterates over internal iterator, but skips index skip.

Arguments

  • iterator: internal iterator
  • skip: index to skip (integer)

See also: skipindex

source
ReactiveMP.skipindexFunction
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
 3

See also: SkipIndexIterator

source

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.

FunctionPurpose
ReactiveMP.MacroHelpers.ensure_symbolAssert that an expression is a Symbol; error otherwise
ReactiveMP.MacroHelpers.bottom_typeExtract the base type T from expressions like Type{<:T}, typeof(T), or T
ReactiveMP.MacroHelpers.upper_typeWrap a type expression into Type{<:T} form for dispatch
ReactiveMP.MacroHelpers.proxy_typeWrap a type with a proxy type as ProxyType{<:T}
ReactiveMP.MacroHelpers.@proxy_methodsGenerate 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_typeFunction
proxy_type(proxy, type)

Returns a type wrapped with a proxy type in a form of ProxyType{ <: Type }.

Arguments

  • proxy: Proxy type used to wrap type
  • type: Type to be wrapped
source
ReactiveMP.MacroHelpers.@proxy_methodsMacro
@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))
source
ReactiveMP.MacroHelpers.upper_typeFunction
upper_type(type)

This function returns Type{ <: T } expression for the following input expressions:

  1. typeof(T)
  2. Type{ <: T }
  3. Type{ T }
  4. T

Arguments

  • type: Type expression to be extended
source
ReactiveMP.MacroHelpers.bottom_typeFunction
bottom_type(type)

This function returns T expression for the following input expressions:

  1. typeof(T)
  2. Type{ <: T }
  3. Type{ T }
  4. T

Arguments

  • type: Type expression to be lowered
source