Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

VariableIndex

A VariableIndex provides an efficient way to look up which factors in a FactorGraph involve a particular variable (Key). It stores, for each variable, a list of the indices of the factors that include that variable.

This structure is often computed internally by GTSAM algorithms (like ordering methods or elimination) but can also be created explicitly if needed, for example, to improve performance when multiple operations need this information.

Open In Colab

Creating a VariableIndex

A VariableIndex is typically created from an existing FactorGraph.

VariableIndex: nEntries = 13, nFactors = 7
var l1: 3 4
var l2: 5 6
var x0: 0 1 3
var x1: 1 2 4 5
var x2: 2 6

Accessing Information

You can query the number of variables, factors, and entries, and look up the factors associated with a specific variable.

Number of variables (size): 5
Number of factors (nFactors): 7
Number of variable-factor entries (nEntries): 13
Factors involving x1: [1, 2, 4, 5]
Factors involving l1: [3, 4]

Usage in Algorithms

VariableIndex is primarily used as input to other algorithms, particularly ordering methods like Ordering.Colamd.

COLAMD Ordering from VariableIndex: Position 0: l1, x0, x1, l2, x2