Module Nx_wide
Double-word numbers.
A value of type ('s, 'd) t is an array of real numbers on the device set 'd, each held as the sum hi + lo of two floats of the format 's, with hi that sum rounded to nearest. It carries 106 significand bits at float64 and 48 at float32. Bounds use u, the format's unit roundoff, and hold where operands and results are zero or of magnitude between 2^-969 and 2^969 at float64 (2^-102 and 2^102 at float32), where every error term is a normal float. A number whose sum is infinite or NaN is held as that sum with a zero lo; an operation on it gives the float result of the hi words with a zero lo, and comparisons compare hi, so NaN compares false.
Operations broadcast as nx's arithmetic does and compute where their operands lie. Each is a fixed program of nx's elementwise operations, with every sum and product rounded once as written.
type ('s, 'd) tThe type for arrays of double-word numbers of the float format 's on the set 'd.
Constructing
v ~lo hi is the number hi + lo, exactly. lo defaults to zero. The two broadcast against each other. A pair already normalised is returned unchanged.
Raises Invalid_argument unless the dtype is float32 or float64, or if the shapes do not broadcast.
Arithmetic
sub a b is a - b within 3u² / (1 - 4u) relative, and exactly zero when a = b.
mul a b is a * b within 4u² relative, exactly when both have a zero lo.
Comparisons
Sums
sum ~axes w adds w along axes (default all, a negative axis counting from the end) in a balanced tree of adds, ⌈log₂ n⌉ deep for n summands, whose association depends only on the shape: within ((1 + 3u² / (1 - 4u))^⌈log₂ n⌉ - 1) · Σ|wᵢ|. It sums from +0, so a sum of -0 terms is +0, as is a sum of no summand; one that is not finite is the float sum of the high words in the same tree.
Raises Invalid_argument if an axis is outside w's rank or repeated.
Structures
val walk : ('a, 'b, 'd, 'e) Nx.Ptree.Walk.cursor -> ('s, 'd) t -> ('s, 'e) twalk c w walks w as two fixed arrays (Nx.Ptree.Walk.tensor) at c's path then "hi" and "lo": hi and lo for a value an operation or v made, and the words it was rebuilt from for one a walk rebuilt. It rebuilds the number the words it returns sum to, which an operation, hi and lo read normalised through v: words returned unchanged rebuild w, and leafwise arithmetic (Nx.Ptree.map2, Nx.Ptree.axpy) rebuilds the number its words make. A structure holding a number walks it with field c "x" Nx_wide.walk x; Nx.Ptree.v Nx_wide.walk describes a number alone.