Differences from NumPy and SciPy#
NumericAL answers as NumPy 2 and SciPy do wherever it carries their names. This page lists where a program written
for them meets something else: a default chosen between the two, a refusal where they compute, a dtype or an
operation that is not there yet. The differential fuzzers (make fuzz-linalg, make fuzz-scipy, make fuzz-edges)
hold everything else to NumPy’s and SciPy’s answers.
Names that NumPy and SciPy both use#
One namespace carries both libraries’ names. Where they disagree on a default, NumericAL takes NumPy’s and accepts SciPy’s arguments:
Function |
NumericAL, as NumPy |
SciPy’s default |
The SciPy call |
|---|---|---|---|
|
the lower factor |
the upper factor |
|
|
the reduced factors |
the full factors |
|
|
— |
the pencil |
the same: a matrix in NumPy’s |
|
|
|
|
|
the full factors, as both |
— |
|
A port from SciPy that relies on cholesky’s or qr’s default changes its answer without a word: pass the argument
explicitly.
Refusals where NumPy and SciPy compute#
A NaN or an infinity in a matrix a decomposition reads (in the triangle read, where only one is) raises
numerical.LinAlgError, where NumPy returns NaN factors or raises depending on the routine.A negative or NaN tolerance raises, where NumPy’s
pinvandmatrix_rankreturn infinities or a rank of 0.lu_solvewith a zero onU’s diagonal raises, where SciPy’s divides by it.A singular system raises in
solveandinv, as NumPy’s; an ill-conditioned one warns withnumerical.LinAlgWarning, as SciPy’s.
A LinAlgError is a ValueError, as NumPy’s is, and a numerical.error. Where NumPy is loaded, it is also a
numpy.linalg.LinAlgError (SciPy’s is the same class), so
except np.linalg.LinAlgError catches it, and an axis out of range, a numerical.AxisError (a ValueError
and an IndexError), is also a numpy.exceptions.AxisError; where scipy.linalg is loaded, the warning is also a
scipy.linalg.LinAlgWarning.
Answers that differ on purpose#
2-norms never overflow or underflow where their value is in range:
vector_norm([1e200, 1e200])is 1.414e200, where NumPy’s is infinite.maximum,minimum,fmax,fmin,maxandminorder the zeros as IEEE 754-2019: +0 above −0, whatever the order they come in. NumPy on arm64 agrees; NumPy on x86-64 keeps the sign its loops meet first.powerof float64 on an x86-64 processor with AVX-512 is the C library’s, as NumPy’s on other processors; NumPy’s there is its own vector kernel, whose last bit differs from it in some 5 % of the powers.expof float64 is NumericAL’s own, in vectors (a table of 2^(j/128) and a polynomial): within 0.506 ulp of the exact value, the same bits on every processor with fused multiply-add, three times faster than the C library’s on one core. NumPy’s is the C library’s (its own vector kernel on x86-64 with AVX-512): the last bit differs in some 0.2 % of the values. A subnormal or zero result is the C library’s; an x86-64 processor without FMA, and a build by MSVC, take the C library’s throughout.expm1of float64 is NumericAL’s own too, onexp’s table, its leading sums exact: within 0.503 ulp of the exact value (the C library’s, NumPy’s, 0.6 or so), the same bits on every processor with fused multiply-add. The last bit differs from NumPy’s in some 0.2 % of the values; ±0, the values below 2^-54 (themselves) and those below −40 (−1) are the library’s. Whereexptakes the C library’s, so doesexpm1.tanhof float64 is NumericAL’s own as well, t/(t + 2) of t = expm1(2|x|) carried in two parts: within 0.502 ulp of the exact value, the same bits on every processor with fused multiply-add. NumPy’s is its own vector kernel (within 1.1 ulp or so on arm64) or the C library’s: the last bit differs from it in some 20 % of the values on arm64. ±0, the values below 2^-27 (themselves) and those past 22 (±1) are the library’s. Whereexptakes the C library’s, so doestanh.arctanof float64 is NumericAL’s own too, by a table of atan(k/64) and the series of the remainder: within 0.501 ulp of the exact value (macOS’s C library, NumPy’s there, 0.86), the same bits on every processor with fused multiply-add. The last bit differs from NumPy’s in some 9 % of the values on macOS. ±0, the values below 2^-27 (themselves), those past 2^54 (±π/2) and NaN are the library’s. Whereexptakes the C library’s, so doesarctan.sinandcosof float64 are NumericAL’s own, by a table of sin(jπ/32) and cos(jπ/32) and short series, the reduction by π/32 in three parts: within 0.502 ulp of the exact value (macOS’s C library, NumPy’s there, 0.86), the same bits on every processor with fused multiply-add, under every compiler. The last bit differs from NumPy’s in some 4 % of the values on macOS. The values below 2^-27 (themselves, and 1) are exact; past 2^20, and for an infinity or a NaN, the C library’s. Whereexptakes the C library’s, so dosinandcos.eigandeigvalsanswer in complex numbers whatever the eigenvalues, as NumPy 2.5’s and SciPy’s; NumPy before 2.5 made them real where it could.A float32 or complex64 decomposition is computed in double precision and rounded to single, below order 500 (see Linear algebra): the double answer of the same values, rounded once, where NumPy’s LAPACK computes in single. From order 500,
solve,inv,det,slogdet,cholesky,lu_factorandlu_solvefactorise in single precision, as NumPy’s LAPACK does, and differ from it in the last bits; the other decompositions stay in double. A float32 or complex64 FFT computes in single precision at every length, as NumPy’s pocketfft, its last bits NumPy’s or not.A float32 sum of more than a thousand elements on 32-bit Windows: NumPy’s build there ends on other last bits than its other builds, whose bits NumericAL’s are everywhere.
A sum along an axis that is not the last (
sum(a, axis=0)of a matrix, and themean,varandstdover it) adds each column pairwise, as NumPy adds along the last axis; NumPy adds such an axis row after row, in order. The last bits differ where the terms are of very different sizes, ours nearer the exact sum. Withinitial=, each column starts with it, the first term of its pairwise sum, where NumPy’s rows add to it in order: the same bits below 8 terms (4 complex ones), where a pairwise sum is in order.A sum in another dtype (
sum(a, dtype="float64")of a float32a) converts every element and adds them pairwise, as a sum of that dtype; NumPy converts 8192 elements at a time, adds each block pairwise and the blocks in order. The last bits differ past 8192 elements.roundto many places, and an integer’s to tens or hundreds, is exact: NumPy’s scales by 10ᵈ in floating point, which moves a last bit (round(x, 15)near 10) or overflows (round(1e307, 2): inf), and rounds an integer through float64 (not exact past 2⁵³).sortkeeps equal elements in their order whateverkind; NumPy’s default sort may order them otherwise, which only a zero’s sign or a NaN’s payload shows. Ahistogramwith weights between given edges sums the weights of equal values in their order too; NumPy’s, in its sort’s, which can move a last bit.median,nanmedianand the quantiles of the largest values answer them exactly: NumPy averages a middle value with itself (or interpolates between two equal ones), which overflows past half the largest float, sonanmedian([1.7976931348623157e308])is infinite there.geomspaceis within 3 ulps of the exact values: NumPy’s takes10 ** ybetween thelog10of its ends, whose roundings carry into each value up to some 2·(|ln start| + |ln stop|) ulps (1500 over 10^±300); ours give their exponents’ roundings back. The last bits differ where NumPy’s are that far.takewithmode="wrap"from an empty axis raises IndexError, as NumPy does for a result with elements; for one without, NumPy’s loop never ends (numpy/numpy#11677).partitionandargpartitionselect as NumPy’s do (the element at eachkththe sorted one, none larger before it, none smaller after), the rest in no order specified, which is not NumPy’s own arrangement: compare the elements at thekthpositions, not the whole lines.bitwise_countanswers int64, NumPy’s uint8 (NumericAL has no unsigned dtype). An int64 shifted by 64 places or more (or a negative count) is 0, or −1 to the right of a negative number, as NumPy defines it; its 32-bit Windows build shifts as the processor does, the count taken modulo 64.frexp’s exponents are int64, NumPy’s int32, and 0 for an infinity or a NaN, where NumPy’s are its C library’s (0 from glibc and macOS, −1 from MSVC);emptygives zeros (no element of a Tensor is ever unset).Floating-point warnings. An invalid operation, a division by zero or an overflow answers IEEE 754’s NaN or infinity without NumPy’s
RuntimeWarning(“invalid value encountered…”); there is noerrstate.insertbefore a list of bools inserts before each true position, as NumPy does for a bool array; NumPy 2.4 raises AttributeError for a list (it asks the list for its rank).nanquantileandnanpercentilewith weights of the axis’s shape answer as with those weights broadcast to the array’s; NumPy raises IndexError there (numpy/numpy#29709).The special matrices (
hilbert,pascal,invpascal…) are float64 where SciPy’s exact ones are integers: each entry computed exactly, then rounded once.The complex elementary functions (
exp,log,sqrt,sin,cos,tan,tanh,sinh,coshand the inverse ones,arcsin,arccos,arctan,arcsinh,arccosh,arctanh, of a complex number) are glibc’s, NumPy’s on Linux; macOS’s and Windows’ libraries, NumPy’s there, differ among infinities and NaNs and past their last bits.log2,log10,exp2andexpm1are NumPy’s formulas,expm1past exp’s overflowexp(z) − 1(NumPy’s is NaN at+∞ + 0iand infinite at710.2 + 0.1i);log1pkeeps a small number’s digits and a zero’s signs, where NumPy’slog(hypot(1 + re, im))is 0 below ε, and stays finite where|1 + z|passes the largest double (NumPy’s is infinite).
What is not there yet#
Integer dtypes. NumPy’s integer arrays are read as float64 unless
dtype="int64"is asked (by default from 2026.12.0); an int64 tensor compares, selects, moves, computes, reduces and multiplies (@,einsum,dot,tensordot) as NumPy’s integers, wrapped past 2^63, but not yet through the linear algebra, and the index functions answer in it. A real converted to int64 that it cannot hold (NaN, an infinity, a value out of range) raises, as Python’sint(); NumPy’s answer depends on the processor.Bool arithmetic and the small dtypes.
+,-,*(andadd,multiply…) refuse two bool tensors, where NumPy’s are a logical or and a logical and; there is no float16 nor int8, NumPy’s dtype forfabs,arcsin… orreciprocalof a bool, which raise here.Views and assignment. A
Tensoris immutable:t[i] = xraisesTypeError, so a view never writes through to its base, where a NumPy view does. A permutation of its axes (t.T,transpose…) and a slice (t[1:3],t[::-1, 2]) are views, as NumPy’s, except a slice of 512 elements or fewer, which is copied at once (and so keeps no larger tensor alive); a reshape of a view is a view where NumPy’s is (its axes join or split without a copy), a copy otherwise, and a NumPy array passed in is a copy.NumPy’s file input and output, printing and datetimes. No
load,save,loadtxtorgenfromtxt, noset_printoptions, no datetime functions, nopoly; and none of the functions that write into an array (put,copyto,fill_diagonal,place…), which an immutableTensorhas no place for.Complex ordering.
max,min,maximum,minimumandcliptake real dtypes only; NumPy orders complex numbers by real, then imaginary part (sortdoes too).Namespaces. Everything lives at the root, with
numpy.fft’s names innumerical.fftandnumpy.linalg’s innumerical.linalg; the root is also a Tensor’s array API namespace (__array_namespace__), with the standard’s keywords (device,copy,correction,descending…) beside NumPy’s.diagonalandtraceat the root arenumpy.linalg’s: the diagonals of the last two axes, wherenumpy.diagonalandnumpy.tracetake the first two (axis1=0,axis2=1). A matrix’s are the same.Domains. No
random, no sparse matrices, nooptimize,stats,signal,interpolateorspecial: they are outside NumericAL’s scope, for libraries built on it.