xlnstorch.lnstensor#
- xlnstorch.lnstensor(data, from_lns=False, requires_grad=False, detach=True, f=None, b=None)#
Constructs an
LNSTensorfrom some array-like data.The function accepts ordinary numeric data (tensors, NumPy arrays, scalars) and every non-redundant xlns type. Redundant formats (
xlnsrandxlnsnpr) are not supported.The LNSTensor
baseis chosen in the following order:If
fis given,base= 2.0 ^ (2 ^ -f).Else if
b is given, useb(float or scalar tensor).Else, default to
xlns.xlnsB(global constant).
- Parameters:
data (LNSTensor, torch.Tensor, numpy.ndarray, numbers, xlns types) –
A real-valued tensor/array/scalar to encode or
A pre-packed representation (when
from_lnsisTrue) orAn existing
LNSTensor(which will be copied or converted base).
from_lns (bool, optional) – If
True, treat data as already packed. Defaults toFalse.requires_grad (bool, optional) – If
True, the LNSTensor will track gradients. Defaults toFalse. If a pre-packed LNSTensor or a torch.Tensor is provided, this parameter is ignored.detach (bool, optional) – If
Trueand data is atorch.Tensorand notfrom_lns, data will be detached from its computation graph, i.e. this tensor will become a leaf node.f (int, optional) – The number of fractional exponent bits. mutually exclusive with
b.b (float, int, torch.Tensor, optional) – The explicit logarithm base; mutually exclusive with
f.
- Returns:
The constructed LNSTensor.
- Return type:
- Raises:
ValueError – If both
fandbare provided, or if neither can be resolved to a valid base.TypeError – If data is of an unsupported type (i.e. not array-like).