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.

Key

A Key in GTSAM is simply a typedef for std::uint64_t. It serves as a unique identifier for variables within a factor graph or values within a Values container. While you can use raw integer keys, GTSAM provides helper classes like Symbol and LabeledSymbol to create semantically meaningful keys that encode type and index information within the 64-bit integer.

Open In Colab

Basic Usage

Keys are typically created using Symbol or LabeledSymbol and then implicitly or explicitly cast to the Key type (integer).

Symbol Key (x0): 8646911284551352320
Type: <class 'int'>
LabeledSymbol Key (aB1): 7008163970141913089
Type: <class 'int'>
Plain Integer Key: 12345
Type: <class 'int'>

Key Formatting

When printing GTSAM objects that contain keys (like Factor Graphs or Values), you can specify a KeyFormatter to control how keys are displayed. The default formatter tries to interpret keys as Symbols.

Default Formatter:
  Symbol Key: x0
  LabeledSymbol Key: a18577348
  Plain Key: 12345
Custom Formatter:
  Symbol Key: KEY[x0]
  LabeledSymbol Key: KEY[a18577348]
  Plain Key: KEY[12345]