quax.examples.unitful¤
A worked example of a quax.Value that carries metadata and refuses to give it up:
an array tagged with physical units. It is the type most of these docs use for
demonstrations, because unit errors are easy to recognise as errors.
Rules are registered for add, mul, integer_pow, lt, broadcast_in_dim,
copy and select_n -- enough to differentiate through, and to run a lax loop
or a diffrax solve. Anything else raises rather than dropping the units.
quax.examples.unitful.Unitful
¤
An array with physical units attached.
Arithmetic propagates the units rather than checking them after the fact:
multiplying two Unitfuls adds their exponents, raising to an integer power
multiplies them, and adding or comparing arrays whose units disagree raises.
Refuses to quax.Value.materialise. A primitive with no registered rule is
therefore an error rather than a silent unit loss -- see
Sharp bits.
Arguments:
array: the array to attach units to.units: either a singleDimension, or a dict fromDimensionto integer exponent -- e.g.{meters: 1, seconds: -2}for an acceleration.
__init__(array: jax.Array | numpy.ndarray | numpy.bool | numpy.number | bool | int | float | complex, units: quax.examples.unitful._core.Dimension | dict[quax.examples.unitful._core.Dimension, int]) -> None
¤
Initialize self. See help(type(self)) for accurate signature.
quax.examples.unitful.Dimension
¤
A base physical dimension, e.g. metres.
Three are provided ready-made: kilograms, meters and seconds. Make others
by instantiating this class with a name.
__dict__ = mappingproxy({'__module__': 'quax.examples.unitful._core', '__firstlineno__': 12, '__doc__': 'A base physical dimension, e.g. metres.\n\nThree are provided ready-made: `kilograms`, `meters` and `seconds`. Make others\nby instantiating this class with a name.\n', '__init__': <function Dimension.__init__ at 0x7f877a0ec5c0>, '__repr__': <function Dimension.__repr__ at 0x7f877a0ece00>, '__static_attributes__': ('name',), '__dict__': <attribute '__dict__' of 'Dimension' objects>, '__weakref__': <attribute '__weakref__' of 'Dimension' objects>})
class-attribute
¤
Read-only proxy of a mapping.
__doc__ = 'A base physical dimension, e.g. metres.\n\nThree are provided ready-made: `kilograms`, `meters` and `seconds`. Make others\nby instantiating this class with a name.\n'
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__firstlineno__ = 12
class-attribute
¤
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer iteral.
int('0b100', base=0) 4
__module__ = 'quax.examples.unitful._core'
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__static_attributes__ = ('name',)
class-attribute
¤
Built-in immutable sequence.
If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.
If the argument is a tuple, the return value is the same object.
__weakref__
property
¤
list of weak references to the object