qubosolver.vectori
qubosolver.Vectori
module-attribute
1-D int64 tensor of shape (n,).
qubosolver.vectori
1-D integer vector utilities for QUBO solvers.
A Vectori is a 1-D torch.int64 tensor of shape (n,) used to
represent integer-valued quantities such as indices or counts.
Unlike qubosolver.vector, the dtype is fixed to int64
and is not affected by the global float precision setting.
This module provides factory functions for creating and converting integer vectors on the globally configured torch device.
Typical usage:
v = vectori.zeros(4) # 1-D zero int64 vector of length 4
v = vectori.tensor([0, 1, 2, 3]) # from a list of integers
v = vectori.as_tensor(some_tensor) # cast existing tensor to int64, no copy when possible
See also qubosolver.vector for float vectors.
Functions:
-
as_tensorβConvenience wrapper for
torch.as_tensorthat converts data to an integer vector tensor. -
deviceβReturns the globally configured torch device.
-
dtypeβReturns the dtype used for integer vectors (
torch.int64). -
tensorβCreates an integer vector tensor from the given data.
-
zerosβCreates a zero-filled integer vector of length n.
-
zeros_fieldβCreates a dataclass field defaulting to a zero-filled integer vector.
as_tensor
Convenience wrapper for torch.as_tensor that converts data to an integer vector tensor.
Avoids a copy when possible. If data is already a tensor with the right dtype and on
the right device, it is returned as-is, sharing the same underlying memory. A numpy
array is also shared rather than copied if it already has int64 dtype and the
global device is cpu (numpy arrays only live on CPU, so any other dtype or device
forces a copy). Lists, tuples, and other array-like inputs are always copied.
Parameters:
-
data(Any) βInput data (tensor, numpy array, list, tuple, etc.).
Returns:
-
VectoriβA 1-D
int64tensor on the global device.
Source code in qubosolver/types/vectori.py
device
dtype
tensor
Creates an integer vector tensor from the given data.
Parameters:
-
data(Any) βInput data (list, tuple, or array-like of integers).
-
device(torch.device | None, default:None) βTorch device for the tensor.
-
**kwargs(Any, default:{}) βExtra keyword arguments forwarded to
torch.tensor.
Returns:
-
VectoriβA 1-D
int64tensor.
Source code in qubosolver/types/vectori.py
zeros
Creates a zero-filled integer vector of length n.
Parameters:
-
n(int) βLength of the vector.
-
device(torch.device | None, default:None) βTorch device for the tensor.
Returns:
-
VectoriβA 1-D
int64tensor of zeros.
Source code in qubosolver/types/vectori.py
zeros_field
Creates a dataclass field defaulting to a zero-filled integer vector.
Parameters:
-
n(int) βLength of the vector.
-
device(torch.device | None, default:None) βTorch device for the tensor.
Returns:
-
VectoriβA dataclass field (typed as
Vectorifor the enclosing class) whose -
Vectoriβdefault_factorybuilds a fresh zero tensor per instance.