xlnstorch#
The xlnstorch package provides an LNSTensor class, analogous to PyTorch’s Tensor, which is designed to handle LNS arithmetic. The LNSTensor class is built on top of PyTorch’s Tensor, allowing it to leverage PyTorch’s features such as automatic differentiation, while also providing specialized methods for LNS operations.
Tensor Creation Ops#
Constructs an |
|
Returns an LNSTensor filled with zeros, with the specified shape and properties. |
|
Returns an LNSTensor filled with zeros, with the same shape and properties as the input tensor. |
|
Returns an LNSTensor filled with ones, with the specified shape and properties. |
|
Returns an LNSTensor filled with ones, with the same shape and properties as the input tensor. |
|
Returns an LNSTensor filled with fill_value, with the specified shape and properties. |
|
Returns an LNSTensor filled with fill_value, with the same shape and properties as the input tensor. |
|
Returns an LNSTensor filled with random numbers from a uniform distribution on the interval [0, 1], with the specified shape and properties. |
|
Returns an LNSTensor filled with random numbers from a uniform distribution on the interval [0, 1], with the same shape and properties as the input tensor. |
|
Returns an LNSTensor filled with random numbers from a normal distribution with mean 0 and variance 1, with the specified shape and properties. |
|
Returns an LNSTensor filled with random numbers from a normal distribution with mean 0 and variance 1, with the same shape and properties as the input tensor. |
|
Returns an uninitialized LNSTensor with the specified shape and properties. |
|
Returns an uninitialized LNSTensor with the same shape and base (unless otherwise specified) as the input tensor. |
Constants#
- xlnstorch.LNS_ZERO#
A float64 scalar tensor representing zero in the LNS. This is a special value defined to be \(\left( -2^{52} \ll 1 \right) \mid 1 = -9007199254740991\). It is independent of an LNS object’s base.
- xlnstorch.LNS_INF#
A float64 scalar tensor representing positive infinity in the LNS. This is a special value defined to be \(2^{53} = 9007199254740992\). It is independent of an LNS object’s base.
- xlnstorch.LNS_NEG_INF#
A float64 scalar tensor representing negative infinity in the LNS. This is a special value defined to be \(\left( 2^{53} \right) - 1 = 9007199254740991\). It is independent of an LNS object’s base.
- xlnstorch.LNS_ONE#
A float64 scalar tensor representing one in the LNS. For any LNS base \(B\), we have \(\log_B(1) = 0\), so this value is independent of base. It is defined to be \(\left( 0 \ll 1 \right) \mid 0 = 0\).
- xlnstorch.LNS_NEG_ONE#
A float64 scalar tensor representing one in the LNS. For any LNS base \(B\), we have \(\log_B(1) = 0\), so this value is independent of base. It is defined to be \(\left( 0 \ll 1 \right) \mid 1 = 1\).
- xlnstorch.CSRC_AVAILABLE#
A boolean flag indicating whether the C++ extension is available. When True, high-performance C++ implementations are used; when False, pure Python implementations are used as fallback. To find out why the C++ extension is not available, install the xlnstorch package with the
--verboseflag to see the build logs. The internal C++ functions can be accessed via thecsrcsubmodule.
Custom Operations#
The xlnstorch package provides a set of analogous operations to
PyTorch’s built-in operations. These operations are registered with
PyTorch’s internal dispatch mechanism, so that they can be used in
the same way as PyTorch’s built-in operations. For example,
import xlnstorch as xltorch
x = xltorch.lnstensor([1.0, 2.0], f=23)
y = xltorch.lnstensor([3.0, 4.0], f=23)
z = torch.add(x, y)
print(z)
# LNSTensor(value=[4.0000, 6.0000], prec=23)
If you want to implement your own custom implementation of an operation, define a new operation, or use an alternative implementation of an operation, you can use the following functions.
A decorator to register a custom implementation for a given torch function. |
|
Get the implementation tuple for a given torch function and implementation key. |
|
Set the default implementation for a given torch function. |
|
Get the default implementation key for a given torch function. |
|
Temporarily override the default implementation for a torch function within a context. |
|
A decorator to register a custom sbdb implementation. |
|
Set the default implementation for the sbdb function. |
|
Temporarily override the default sbdb implementation within a context. |
|
Registers an implementation of the sbdb function using a ufunc from the xlnsconf packed. |
|
Computes the Gaussian logarithm for the given inputs z and s. |
|
Aligns the bases of a sequence of LNSTensors to a common base. |
|
Converts a variable number of operands to LNSTensor objects, aligning all operands to the base of the first operand that is an LNSTensor. |