|
22 | 22 | "dot_similarity",
|
23 | 23 | "multiset",
|
24 | 24 | "multibind",
|
| 25 | + "cross_product", |
25 | 26 | "sequence",
|
26 | 27 | "distinct_sequence",
|
27 | 28 | "ngrams",
|
@@ -629,6 +630,45 @@ def multibind(input: Tensor, *, dim=-2, keepdim=False, dtype=None, out=None) ->
|
629 | 630 | return torch.prod(input, dim=dim, keepdim=keepdim, dtype=dtype, out=out)
|
630 | 631 |
|
631 | 632 |
|
| 633 | +def cross_product(input: Tensor, other: Tensor) -> Tensor: |
| 634 | + r"""Cross product between two sets of hypervectors. |
| 635 | +
|
| 636 | + First creates a multiset from both tensors ``input`` (:math:`A`) and ``other`` (:math:`B`). |
| 637 | + Then binds those together to generate all cross products, i.e., :math:`A_1 * B_1 + A_1 * B_2 + \dots + A_1 * B_m + \dots + A_n * B_m`. |
| 638 | +
|
| 639 | + .. math:: |
| 640 | +
|
| 641 | + \big( \bigoplus_{i=0}^{n-1} A_i \big) \otimes \big( \bigoplus_{i=0}^{m-1} B_i \big) |
| 642 | +
|
| 643 | + Args: |
| 644 | + input (Tensor): first set of input hypervectors |
| 645 | + other (Tensor): second set of input hypervectors |
| 646 | +
|
| 647 | + Shapes: |
| 648 | + - Input: :math:`(*, n, d)` |
| 649 | + - Other: :math:`(*, m, d)` |
| 650 | + - Output: :math:`(*, d)` |
| 651 | +
|
| 652 | + Examples:: |
| 653 | +
|
| 654 | + >>> a = functional.random_hv(2, 3) |
| 655 | + >>> a |
| 656 | + tensor([[ 1., 1., -1.], |
| 657 | + [ 1., -1., 1.]]) |
| 658 | + >>> b = functional.random_hv(5, 3) |
| 659 | + >>> b |
| 660 | + tensor([[ 1., -1., 1.], |
| 661 | + [-1., -1., -1.], |
| 662 | + [-1., -1., -1.], |
| 663 | + [ 1., 1., -1.], |
| 664 | + [ 1., -1., -1.]]) |
| 665 | + >>> functional.cross_product(a, b) |
| 666 | + tensor([2., -0., -0.]) |
| 667 | +
|
| 668 | + """ |
| 669 | + return bind(multiset(input), multiset(other)) |
| 670 | + |
| 671 | + |
632 | 672 | def ngrams(input: Tensor, n: int = 3) -> Tensor:
|
633 | 673 | r"""Creates a hypervector with the :math:`n`-gram statistics of the input.
|
634 | 674 |
|
|
0 commit comments