ensure_vsa_tensor
- torchhd.ensure_vsa_tensor(data, vsa: Literal['BSC', 'MAP', 'HRR', 'FHRR', 'BSBC', 'VTB', 'MCR', 'CGR'] | None = None, dtype: dtype | None = None, device: device | None = None) VSATensor[source]
Converts data into a VSA model tensor.
If data is already a VSA model of the correct model, dtype and device then data itself is returned. A copy of the data is created when dtype or device don’t match using
torch.as_tensor(data, dtype=dtype, device=device).When no model is specified boolean tensors are converted to Binary Spatter Codes, complex valued tensors to Fourier Holographic Reduced Representations and otherwise to the Multiply Add Permute VSA model.
- Parameters:
data (array_like) – Initial data for the tensor. Can be a list, tuple, NumPy ndarray, scalar, and other types.
vsa – (
VSAOptions, optional): specifies the hypervector type to be instantiated.dtype (
torch.dtype, optional) – the desired data type of returned tensor.device (
torch.device, optional) – the desired device of returned tensor.
Examples:
>>> x = [True, False, False, True, False, False] >>> x = torchhd.ensure_vsa_tensor(x) >>> x tensor([ True, False, False, True, False, False]) >>> type(x) <class 'torchhd.tensors.bsc.BSCTensor'> >>> x = torch.rand(6) >>> x tensor([0.2083, 0.0665, 0.6302, 0.8650, 0.6618, 0.0886]) >>> x = torchhd.ensure_vsa_tensor(x) >>> x tensor([0.2083, 0.0665, 0.6302, 0.8650, 0.6618, 0.0886]) >>> type(x) <class 'torchhd.tensors.map.MAPTensor'>