BindSequence

class torchhd.structures.BindSequence(dimensions: int, vsa: Literal['BSC', 'MAP', 'HRR', 'FHRR', 'BSBC', 'VTB', 'MCR', 'CGR'] = 'MAP', *, device=None, dtype=None)[source]
class torchhd.structures.BindSequence(input: VSATensor, *, size=0)

Hypervector binding-based sequence data structure.

Creates an empty sequence of dim dimensions or from an input tensor.

Parameters:
  • dimensions (int) – number of dimensions of the sequence.

  • vsa – (VSAOptions, optional): specifies the hypervector type and operations used (Default: "MAP").

  • dtype (torch.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see torch.set_default_tensor_type()).

  • device (torch.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

  • input (VSATensor) – tensor representing a binding-based sequence.

  • size (int, optional) – the length of the sequence provided as input. Default: 0.

Examples:

>>> DS = structures.BindSequence(10000)
__len__() int[source]

Returns the length of the sequence.

Examples:

>>> len(DS)
0
append(input: VSATensor) None[source]

Appends the input tensor to the right of the sequence.

Parameters:

input (VSATensor) – Hypervector to append to the sequence.

Examples:

>>> letters = list(string.ascii_lowercase)
>>> letters_hv = torchhd.random(len(letters), 10000)
>>> DS.append(letters_hv[0])
appendleft(input: VSATensor) None[source]

Appends the input tensor to the left of the sequence.

Parameters:

input (VSATensor) – Hypervector to append to the right of the sequence.

Examples:

>>> DS.appendleft(letters_hv[1])
clear() None[source]

Empties the sequence.

Examples:

>>> DS.clear()
classmethod from_tensor(input: VSATensor)[source]

Creates a sequence from tensor.

See: bind_sequence().

Parameters:

input (VSATensor) – Tensor containing hypervectors that form the sequence.

Examples::
>>> letters_hv = torchhd.random(len(letters), 10000)
>>> DS = structures.BindSequence.from_tensor(letters_hv)
pop(input: VSATensor) None[source]

Pops the input tensor from the right of the sequence.

Parameters:

input (VSATensor) – Hypervector to pop from the sequence.

Examples:

>>> DS.pop(letters_hv[0])
popleft(input: VSATensor) None[source]

Pops the input tensor from the left of the sequence.

Parameters:

input (VSATensor) – Hypervector to pop left from the sequence.

Examples:

>>> DS.popleft(letters_hv[1])
replace(index: int, old: VSATensor, new: VSATensor) None[source]

Replace the old hypervector value from the given index, for the new hypervector value.

Parameters:
  • index (int) – Index from the sequence to replace its value.

  • old (VSATensor) – Old value hypervector.

  • new (VSATensor) – New value hypervector.

Examples:

>>> DS1 = structures.BindSequence(dimensions=10000)
>>> DS.concat(DS1)