cross_product

torchhd.cross_product(input: VSATensor, other: VSATensor) VSATensor[source]

Cross product between two sets of hypervectors.

First creates a multiset from both tensors input (\(A\)) and other (\(B\)). Then binds those together to generate all cross products, i.e., \(A_1 * B_1 + A_1 * B_2 + \dots + A_1 * B_m + \dots + A_n * B_m\).

\[\big( \bigoplus_{i=0}^{n-1} A_i \big) \otimes \big( \bigoplus_{i=0}^{m-1} B_i \big)\]
Parameters:
  • input (VSATensor) – first set of input hypervectors

  • other (VSATensor) – second set of input hypervectors

Shapes:
  • Input: \((*, n, d)\)

  • Other: \((*, m, d)\)

  • Output: \((*, d)\)

Examples:

>>> a = torchhd.random(2, 6)
>>> a
tensor([[ 1.,  1.,  1., -1.,  1.,  1.],
        [-1., -1.,  1., -1., -1.,  1.]])
>>> b = torchhd.random(5, 6)
>>> b
tensor([[ 1., -1.,  1.,  1., -1., -1.],
        [-1.,  1.,  1., -1., -1.,  1.],
        [-1.,  1.,  1., -1., -1., -1.],
        [ 1., -1.,  1., -1., -1.,  1.],
        [ 1., -1.,  1.,  1., -1., -1.]])
>>> torchhd.cross_product(a, b)
tensor([ 0., -0., 10.,  2., -0., -2.])