An EdgeKey
is a utility class in GTSAM used to encode a pair of 32-bit unsigned integers into a single 64-bit gtsam.Key
. This can be useful for representing edges in a graph or other paired relationships where each element of the pair fits within 32 bits.
import gtsam
from gtsam import EdgeKey
Initialization¶
An EdgeKey
can be created by providing two 32-bit unsigned integers (i
and j
). It can also be created by decoding an existing gtsam.Key
(integer), assuming it was encoded using the EdgeKey
format.
# Create EdgeKey from integers i=10, j=20
ekey1 = EdgeKey(10, 20)
print(f"EdgeKey from (10, 20): {ekey1}") # Uses __str__ which calls operator std::string
# Get the underlying integer key
key1 = ekey1.key()
# Reconstruct EdgeKey from the key
ekey2 = EdgeKey(key1)
print(f"EdgeKey from key {key1}: {ekey2}")
EdgeKey from (10, 20): {10, 20}
EdgeKey from key 42949672980: {10, 20}
Properties and Usage¶
You can access the original i
and j
values and the combined Key
.
edge = EdgeKey(123, 456)
print(f"EdgeKey: {edge}")
print(f" i: {edge.i()}")
print(f" j: {edge.j()}")
print(f" Key: {edge.key()}")
EdgeKey: {123, 456}
i: 123
j: 456
Key: 528280977864