qubosolver.vector
qubosolver.Vector
module-attribute
1-D float tensor using the globally configured precision (float32 by default).
qubosolver.vector
1-D vector utilities for QUBO solvers.
A Vector is a 1-D float tensor of shape (n,) using the globally
configured dtype (float32 by default, float64 when double precision is enabled).
This module provides factory functions for creating and converting such vectors
on the globally configured torch device.
Typical usage:
v = vector.zeros(4) # 1-D zero vector of length 4
v = vector.tensor([1.0, 0.5, -1.0]) # from a list
v = vector.as_tensor(some_tensor) # cast existing tensor, no copy when possible
For higher-rank variants see qubosolver.matrix (2-D square) and
qubosolver.tensor (arbitrary rank).
Functions:
-
as_tensorβConvenience wrapper for
torch.as_tensorthat converts data to a vector tensor. -
deviceβReturns the globally configured torch device.
-
dtypeβReturns the globally configured float dtype.
-
tensorβCreates a 1-D vector tensor from the given data.
-
zerosβCreates a zero-filled 1-D vector of length n.
-
zeros_fieldβCreates a dataclass field defaulting to a zero-filled 1-D vector.
as_tensor
Convenience wrapper for torch.as_tensor that converts data to a 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 the global float 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:
-
VectorβA 1-D tensor on the global dtype and device.
Source code in qubosolver/types/vector.py
device
dtype
tensor
tensor(data: Any, *, dtype: torch.dtype | None = None, device: torch.device | None = None, **kwargs: Any) -> torch.Tensor
Creates a 1-D vector tensor from the given data.
Parameters:
-
data(Any) βInput data (list, tuple, or array-like).
-
dtype(torch.dtype | None, default:None) βData type of the tensor.
-
device(torch.device | None, default:None) βTorch device for the tensor.
-
**kwargs(Any, default:{}) βExtra keyword arguments forwarded to
torch.tensor.
Returns:
Source code in qubosolver/types/vector.py
zeros
zeros(n: int, *, dtype: torch.dtype | None = None, device: torch.device | None = None) -> torch.Tensor
Creates a zero-filled 1-D vector of length n.
Parameters:
-
n(int) βLength of the vector.
-
dtype(torch.dtype | None, default:None) βData type of the tensor.
-
device(torch.device | None, default:None) βTorch device for the tensor.
Returns:
Source code in qubosolver/types/vector.py
zeros_field
zeros_field(n: int, *, dtype: torch.dtype | None = None, device: torch.device | None = None) -> Vector
Creates a dataclass field defaulting to a zero-filled 1-D vector.
Parameters:
-
n(int) βLength of the vector.
-
dtype(torch.dtype | None, default:None) βData type of the tensor.
-
device(torch.device | None, default:None) βTorch device for the tensor.
Returns:
-
VectorβA dataclass field (typed as
Vectorfor the enclosing class) whose -
Vectorβdefault_factorybuilds a fresh zero tensor per instance.