Class PowerSeriesModule
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
numpy.polynomial.polynomial — power series p(x) = c[0] + c[1]*x + … + c[n]*x**n, reachable
as np.polynomial.polynomial. Coefficients are LOW degree first.
[ModuleName("np.polynomial.polynomial")]
public class PowerSeriesModule
- Inheritance
-
PowerSeriesModule
- Inherited Members
Remarks
Not the legacy functions. np.polynomial.polynomial.polyval(x, c) takes the point first
and the coefficients low→high; the legacy polyval(NDArray, NDArray) takes
(p, x) with p high→low. Same name, different function.
https://numpy.org/doc/stable/reference/routines.polynomials.polynomial.html
Properties
polydomain
polydomain — the default domain of the power series class, float64 [-1.0, 1.0].
public NDArray polydomain { get; }
Property Value
Remarks
NumPy's module constants are ordinary WRITEABLE ndarrays, the same object on every access, and so is this one: a process-wide instance (a write through it persists, as in NumPy). It is shared — do not dispose it (a dispose is harmless: the buffer is pinned for the process lifetime) and copy it before mutating unless the change is meant to be global.
https://numpy.org/doc/stable/reference/generated/numpy.polynomial.polynomial.html
polyone
polyone — the power series representing 1, int64 [1] (shared and writeable, see polydomain).
public NDArray polyone { get; }
Property Value
Remarks
polyx
polyx — the power series representing x, int64 [0, 1] (shared and writeable, see polydomain).
public NDArray polyx { get; }
Property Value
Remarks
polyzero
polyzero — the power series representing 0, int64 [0] (shared and writeable, see polydomain).
public NDArray polyzero { get; }
Property Value
Remarks
Methods
Polynomial(object, object, object, string)
NumPy's numpy.polynomial.polynomial.Polynomial(coef, domain=None, window=None, symbol='x'): a power series — a new
NDPolynomial (the class itself; its class methods fit, fromroots, identity,
basis and cast are static members of NDPolynomial).
public NDPolynomial Polynomial(object coef, object domain = null, object window = null, string symbol = "x")
Parameters
coefobjectThe coefficients, low degree first (see NDPolynomial(object, object, object, string)).
domainobjectThe domain, or null for the class default.
windowobjectThe window, or null for the class default.
symbolstringThe variable's name for printing: a Python identifier.
Returns
- NDPolynomial
The series (dispose it when done).
Remarks
Exceptions
- ValueError
The constructor's errors (an empty or non-1-d series, a domain or window of the wrong length, an invalid symbol).
- TypeError
A null symbol.
- NotSupportedException
Coefficients NumPy keeps as an object array.
polyadd(object, object)
Adds two power series (polyutils._add): both converted to their common type (integers become float64),
the shorter added into a copy of the longer, trailing zeros trimmed.
public NDArray polyadd(object c1, object c2)
Parameters
c1objectFirst series, low degree first (an array, a C# array or list, or a single number).
c2objectSecond series.
Returns
- NDArray
The sum: a new array, or a VIEW of one when trailing zeros were trimmed (as in NumPy).
Remarks
Exceptions
- ValueError
An empty or non-1-d series, or no common type (a bool series).
- NotSupportedException
A null series, or one holding None, a non-numeric object or a Python int past uint64 (NumPy's object array), raised after both series' checks.
polycompanion(object)
The companion matrix of the power series c: ones on the sub-diagonal and -c[:-1] / c[-1] in the last column, so its eigenvalues are the series' roots. Unlike the orthogonal bases' companions it cannot be made symmetric by scaling the basis. The matrix keeps the series' common type and is computed in it throughout (the quotient, then 0 - quotient into the zero column). Bit-identical to NumPy 2.4.2's polycompanion.
public NDArray polycompanion(object c)
Parameters
cobjectThe coefficients, LOW degree first: an NDArray (any layout), a typed C# array, a Python list or tuple (
object[], aValueTuple, a jagged array — np.array's coercion), or a single number. Trailing zeros are trimmed first; integer series are computed in float64; a bool series has no common type.
Returns
- NDArray
A new owning (deg, deg) matrix of the series' common type; a two-term series gives the 1x1 matrix
[[-c[0] / c[1]]](NumPy's arithmetic on the two coefficients: scalarmath, or — for an object series — the items' own: CPython for Python numbers, ufuncs for 0-d arrays; the 1x1 array is numeric either way).
Remarks
Exceptions
- ValueError
An empty series (
Coefficient array is empty), a series that is not 1-d (Coefficient array is not 1-d), or no common type (a bool or str series), in NumPy's order; a ragged list (np.array's inhomogeneous-shape text). Fewer than two terms after trimming:Series must have maximum degree of at least 1.- NotSupportedException
An OBJECT series (None, a non-numeric object or a Python int past uint64 among the terms makes NumPy's as_series copy an object array) of three or more terms after trimming whose arithmetic does not raise — NumPy's result is an object matrix, a dtype NumSharp does not have; or one where NumPy's object arithmetic reaches None or a str (CPython's TypeError there). A two-term object series of numbers computes: NumPy's linear root of the items is a numeric 1x1 array. A str series is NumPy's ValueError (no common type).
- OverflowError
An object series whose arithmetic meets a Python int too large for a float — CPython's
integer division result too large for a floatwhen it is divided by a Python int,int too large to convert to floatwhen it meets anything else — whichever NumPy's statements raise first.
polyder(object, int, object, int)
Differentiates the power series c m times along axis,
multiplying by scl at every order (the chain-rule factor of a linear change of variable).
Bit-identical to NumPy 2.4.2's polyder: its recurrence der[j-1] = j*c[j], with c *= scl
before every order, in NumPy's statement order and NEP 50 dtypes — one IL kernel pass per call, where NumPy
runs a Python loop per coefficient.
public NDArray polyder(object c, int m = 1, object scl = null, int axis = 0)
Parameters
cobjectThe coefficients, LOW degree first: an NDArray (any layout; an N-D array holds one series per position of its other axes), a typed C# array (
double[],float[,]— an ndarray of its dtype), a Python list or tuple (object[],List<T>, aValueTuple, a jaggeddouble[][]orNDArray[]— nested to any depth, its dtype discovered likenp.array's: C# ints are Python ints, so[1, 2.5]is float64), or a single number. Integer and bool series are differentiated as float64.mintHow many times to differentiate (≥ 0). 0 returns a copy;
m >= len(c)returnsc[:1]*0— zeros, except NaN where c[0] is inf or NaN.sclobjectThe multiplier applied at each order: null for NumPy's default (the Python int 1); a C# number — a Python scalar that ADOPTS the series dtype (
0.1on a float32 series multiplies by float32 0.1); a Half/char/decimalor a 0-d NDArray — a NumPy scalar that may WIDEN the arithmetic (np.float64on a float32 series multiplies in float64, then rounds); or an array — an NDArray, typed C# array, or Python list / tuple — that broadcasts against the series in place (one factor per column, say). Even the default 1 is applied: a complex inf coefficient becomesinf+nanjexactly as in NumPy. A Python int of any size (BigInteger) converts with NumPy's rounding.axisintThe axis the series runs along (negative counts from the end).
Returns
- NDArray
The derivative's coefficients, of the series' dtype: a new array — a view of it in NumPy's layout (the series axis back in place), so
flags.owndatais false, as in NumPy.
Remarks
Exceptions
- ValueError
The order of derivation must be non-negative, an arraysclwhose broadcast would stretch the series, or a ragged list / tuple (corscl: np.array's inhomogeneous-shape text).- AxisError
axisis out of range.- TypeError
A
sclthe series cannot absorb in place — NumPy's UFuncTypeError, e.g. a complex scl on a real series.- IncorrectShapeException
An array
sclthat does not broadcast with the series.- OverflowError
A Python-int
scltoo large for the series' dtype.- NotSupportedException
A null or string series, a list holding one, or a Python int past uint64 in the series (NumPy's object/str arrays).
polydiv(object, object)
Divides the power series c1 by c2, returning quotient and remainder:
NumPy's synthetic division in place on a copy of c1 (c1[i:j] -= (c2[:-1]/c2[-1]) * c1[j]); the remainder is a VIEW of that copy (c1[:lc2-1], trimmed), as NumPy returns it. A dividend shorter than the divisor gives (c1[:1]*0, c1), a one-term divisor
(c1/c2[-1], c1[:1]*0). Bit-identical to NumPy 2.4.2's polydiv.
public (NDArray quo, NDArray rem) polydiv(object c1, object c2)
Parameters
c1objectThe dividend. The coefficients, LOW degree first: an NDArray (any layout), a typed C# array, a Python list or tuple (
object[], aValueTuple, a jagged array — np.array's coercion), or a single number. Integer series are computed in float64; a bool series has no common type.c2objectThe divisor.
Returns
Remarks
Exceptions
- ValueError
An empty series (
Coefficient array is empty), a series that is not 1-d (Coefficient array is not 1-d), or no common type (a bool or str series), in NumPy's order; a ragged list (np.array's inhomogeneous-shape text).- NotSupportedException
A null series, or one holding None, a non-numeric object or a Python int past uint64 (NumPy's object array, a dtype NumSharp does not have) — raised where NumPy starts computing with it, after every series check. A str series is NumPy's ValueError (no common type).
- ZeroDivisionError
The divisor is zero (all its coefficients, after trimming) — NumPy's bare
ZeroDivisionError, empty message.
polyfit(object, object, object, object, bool, object)
The least-squares fit of a power series to data: the coefficients c that minimise the weighted squared error
sum_j w_j**2 * |y_j - polyval(x_j, c)|**2, computed as NumPy 2.4.2 writes it (polyutils._fit: the
polyvander(object, int) design matrix with its columns scaled to unit norm, solved by
np.linalg.lstsq), so the coefficients are NumPy's bit for bit with the OpenBLAS backend NumPy loads.
public NDPolyFitResult polyfit(object x, object y, object deg, object rcond = null, bool full = false, object w = null)
Parameters
xobjectThe x-coordinates of the M sample points: anything
np.asarraytakes that is 1-D — a list, a typed C# array, an NDArray of any real or complex dtype (bool and integers compute in float64, float32 in float32).yobjectThe y-coordinates: 1-D (M,), or 2-D (M, K) to fit K data sets that share the x-coordinates (one per column).
degobjectThe degree of the fit: an integer (every term up to it is fitted), or a 1-D array_like of integer degrees (only those terms are fitted; the others are zero in the result). A bool, a float or an empty list is refused.
rcondobjectThe relative cutoff below which singular values of the scaled design matrix count as zero, or null for NumPy's default
len(x)*epsof x's float dtype.fullboolAlso return the residuals, rank, singular values and rcond of the least-squares problem (NumPy's
full=True): the result then deconstructs as(c, (residuals, rank, singular_values, rcond)).wobjectWeights of the sample points (1-D, length M), multiplying each point's residual, or null. For Gaussian uncertainties use
1/sigma.
Returns
- NDPolyFitResult
The coefficients, low degree first, as an NDPolyFitResult: an NDArray of shape (deg + 1,) or (deg + 1, K) in the dtype lstsq computes in (float64; float32 for float32 x and y; complex128), carrying the statistics when
fullis true.
Remarks
NumPy warns (RankWarning: The fit may be poorly conditioned) when the rank falls short of the number
of fitted terms and full is false; NumSharp emits no warnings — read rank with
full: true.
https://numpy.org/doc/stable/reference/generated/numpy.polynomial.polynomial.polyfit.html
Exceptions
- TypeError
NumPy's argument TypeErrors (
deg must be an int or non-empty 1-D array of int,expected 1D vector for x,expected non-empty vector for x,expected 1D or 2D array for y,expected x and y to have same length,expected 1D vector for w,expected x and w to have same length); a null x / y / w (Python'sunsupported operand type(s) for +: 'NoneType' and 'float') or a str one (the ufunc add's no-loop text); a float16 x (lstsq'sarray type float16 is unsupported in linalg); a complex or str rcond.- ValueError
expected deg >= 0; np.asarray's inhomogeneous-shape text for a ragged list; a degree too large for the design matrix (Maximum allowed dimension exceeded,array is too big; …).- NotSupportedException
No LAPACK backend (
np.linalg.lstsqneedsNumSharp.Interop.OpenBLAS); an argument NumPy computes with as Python objects; an rcond array with one or more dimensions (NumPy broadcasts lstsq over it).- MemoryError
A design matrix the machine cannot hold (NumPy's MemoryError).
polyfromroots(object)
The power series whose roots are roots: the roots sorted, one linear factor per root
(polyline(-r, 1) = [-r, 1]), multiplied pairwise as a balanced tree (polyutils._fromroots) with polymul.
Empty roots give [1.]. The factors are built by np.array([-r, …]), whose coercion promotes a
float16 / float32 root to float64 — so the series is float64 (complex128 for complex roots). Bit-identical to
NumPy 2.4.2's polyfromroots (the product's parity notes on polymul(object, object) apply); one documented difference: roots that compare equal but differ in bits (+0.0 and -0.0) are ordered
deterministically here, where NumPy's unstable SIMD sort decides by CPU, which can flip the sign of a zero
coefficient.
public NDArray polyfromroots(object roots)
Parameters
rootsobjectThe roots: an NDArray, a typed C# array, a Python list or tuple, … (anything with a length — NumPy's
len(roots)runs first).
Returns
- NDArray
A new array of
len(roots) + 1coefficients.
Remarks
Exceptions
- TypeError
A scalar (
object of type 'float' has no len()) or a 0-d array (len() of unsized object).- ValueError
Roots that are not 1-d, a zero-size array of nonzero length, or no common type (bool roots).
- NotSupportedException
An object root array (None, or roots holding None, a non-numeric object or a Python int past uint64), raised after its checks; str roots are NumPy's ValueError (no common type).
polygrid2d(object, object, object)
Evaluates the 2-D power series on the Cartesian product of x and y
(NumPy's _gridnd: two tensor passes). Unlike polyval2d(object, object, object) the coordinates are NOT
converted first, so a Python-scalar coordinate stays weak.
public NDArray polygrid2d(object x, object y, object c)
Parameters
xobjectFirst-axis points (array or Python scalar, as in polyval(object, object, bool)).
yobjectSecond-axis points.
cobjectCoefficients (anything
np.arrayaccepts — an NDArray of any layout, a typed C# array, a Python tuple / list such as a ValueTuple,object[]or a jagged /NDArray[]array, nested to any depth, or a scalar);c[i,j]multipliesxi * yj.
Returns
- NDArray
The grid, shape
c.shape[2:] + x.shape + y.shape.
Remarks
Exceptions
- ArgumentNullException
A coordinate (or
pts) is null; a null c is NotSupportedException (NumPy's object array).- IndexError
cis empty along an evaluated axis.- ValueError
A ragged tuple / list c or point argument (np.array's inhomogeneous-shape text; c is converted before the first points).
- NotSupportedException
A null or str
c, or a tuple / list holding a str / null.
polygrid3d(object, object, object, object)
Evaluates the 3-D power series on the Cartesian product of x, y
and z (NumPy's _gridnd: three tensor passes).
public NDArray polygrid3d(object x, object y, object z, object c)
Parameters
xobjectFirst-axis points.
yobjectSecond-axis points.
zobjectThird-axis points.
cobjectCoefficients (anything
np.arrayaccepts — an NDArray of any layout, a typed C# array, a Python tuple / list such as a ValueTuple,object[]or a jagged /NDArray[]array, nested to any depth, or a scalar);c[i,j,k]multipliesxi * yj * z**k.
Returns
- NDArray
The grid, shape
c.shape[3:] + x.shape + y.shape + z.shape.
Remarks
Exceptions
- ArgumentNullException
A coordinate (or
pts) is null; a null c is NotSupportedException (NumPy's object array).- IndexError
cis empty along an evaluated axis.- ValueError
A ragged tuple / list c or point argument (np.array's inhomogeneous-shape text; c is converted before the first points).
- NotSupportedException
A null or str
c, or a tuple / list holding a str / null.
polyint(object, int, object, object, object, int)
Integrates the power series c m times along axis:
each order multiplies by scl, integrates (tmp[j+1] = c[j]/(j+1)) and adds the
constant that makes the new series equal k[i] at lbnd
(tmp[0] += k[i] - polyval(lbnd, tmp)). Bit-identical to NumPy 2.4.2's polyint, NumPy's
statement order and NEP 50 dtypes included.
public NDArray polyint(object c, int m = 1, object k = null, object lbnd = null, object scl = null, int axis = 0)
Parameters
cobjectThe coefficients, LOW degree first (see polyder(object, int, object, int)).
mintHow many times to integrate (≥ 0); 0 returns a copy.
kobjectThe integration constants, one per order (missing ones are 0; more than
mis an error): null for none, a single number, a Python list or tuple (object[],IList, aValueTuple— Python numbers, which adopt the series dtype, or nested lists / tuples, each converted only when its order uses it, as NumPy does), or an array (an NDArray or typed C# array — NumPy scalars of its dtype; for an N-D series a row per order that broadcasts over the series' columns).lbndobjectThe lower bound (null for NumPy's 0); a scalar, Python (weak — a BigInteger too) or NumPy (strong). A list or tuple is not a scalar.
sclobjectThe multiplier applied at each order (null for NumPy's 1); a scalar — see polyder(object, int, object, int).
axisintThe axis the series runs along.
Returns
- NDArray
The integral's coefficients, of the series' dtype (a view of a new array in NumPy's layout).
Remarks
Exceptions
- ValueError
NumPy's texts:
The order of integration must be non-negative,Too many integration constants,lbnd must be a scalar.,scl must be a scalar.,setting an array element with a sequence.(an array constant for a 1-D series), a constant that would stretch the series, or a ragged list / tuple (np.array's inhomogeneous-shape text).- AxisError
axisis out of range.- IndexError
An empty series (
index 0 is out of bounds for axis 0 with size 0).- TypeError
An array constant for a complex 1-D series (NumPy's
complex()text).- TypeError
A scl, constant or complex lbnd the (N-D) series cannot absorb in place — NumPy's UFuncTypeError. (A 1-D series keeps the real part, as NumPy's setitem does.)
- IncorrectShapeException
Constants that do not broadcast with the series' columns.
- OverflowError
A Python-int scl, lbnd or constant too large for the series' dtype.
- NotSupportedException
A null or string series; a str / null constant, or a str bound, when an order uses it (NumPy fails there with its str-dtype error).
polyline(object, object)
The power series of the line off + scl*x: [off, scl] when scl != 0, else [off] — built
with np.array, so the dtype is the one NumPy DISCOVERS for the entries (polyline(1, 2) is int64,
polyline(1.0, 2) float64, a bool pair stays bool) rather than a coefficient dtype.
public NDArray polyline(object off, object scl)
Parameters
offobjectThe offset: a Python number (C# bool / integer / float / double / Complex), a NumPy scalar (Half,
char,decimal, a 0-d NDArray) or an array.sclobjectThe scale; its truth value
scl != 0picks the one- or two-coefficient form (NaN is nonzero).
Returns
- NDArray
A new 1-D array (2-D when the entries are equal-shape arrays, as NumPy stacks them).
Remarks
Exceptions
- ValueError
An array scale with several elements or none (NumPy's truth-value errors), or entries of different shapes (
setting an array element with a sequence…).- TypeError
NumPy's boolean negative / subtract.
- OverflowError
A Python int out of a NumPy integer dtype's range, or CPython's int/float overflow.
- NotSupportedException
An entry NumPy would store in an object array: a Python int beyond uint64, null, a string.
polymul(object, object)
Multiplies two power series: np.convolve(c1, c2), trailing zeros trimmed. The product is np.convolve's arithmetic — NumPy's sequential sum for real series whose shorter factor has at most ~15 terms, cblas ?dot beyond that and for every complex product; with NumSharp.Interop.OpenBLAS installed those run through NumPy's own BLAS and are byte-identical, without it they agree to a few ULP.
public NDArray polymul(object c1, object c2)
Parameters
c1objectFirst factor. The coefficients, LOW degree first: an NDArray (any layout), a typed C# array, a Python list or tuple (
object[], aValueTuple, a jagged array — np.array's coercion), or a single number. Integer series are computed in float64; a bool series has no common type.c2objectSecond factor.
Returns
- NDArray
The product: a new array, or a VIEW of one when trailing zeros were trimmed (as in NumPy).
Remarks
Exceptions
- ValueError
An empty series (
Coefficient array is empty), a series that is not 1-d (Coefficient array is not 1-d), or no common type (a bool or str series), in NumPy's order; a ragged list (np.array's inhomogeneous-shape text).- NotSupportedException
A null series, or one holding None, a non-numeric object or a Python int past uint64 (NumPy's object array, a dtype NumSharp does not have) — raised where NumPy starts computing with it, after every series check. A str series is NumPy's ValueError (no common type).
polymulx(object)
Multiplies the power series c by x: prd[0] = c[0]*0; prd[1:] = c — the coefficients shift up one degree (c[0]*0 keeps NaN/inf and the sign of zero NumPy's way). The zero series [0] is returned as is.
Bit-identical to NumPy 2.4.2's polymulx — one IL kernel pass where NumPy runs a Python loop.
public NDArray polymulx(object c)
Parameters
cobjectThe coefficients, LOW degree first: an NDArray (any layout), a typed C# array, a Python list or tuple (
object[], aValueTuple, a jagged array — np.array's coercion), or a single number. Integer series are computed in float64; a bool series has no common type.
Returns
- NDArray
A new array one coefficient longer (the zero series: a one-element copy), of
np.common_type(c).
Remarks
Exceptions
- ValueError
An empty series (
Coefficient array is empty), a series that is not 1-d (Coefficient array is not 1-d), or no common type (a bool or str series), in NumPy's order; a ragged list (np.array's inhomogeneous-shape text).- NotSupportedException
A null series, or one holding None, a non-numeric object or a Python int past uint64 (NumPy's object array, a dtype NumSharp does not have) — raised where NumPy starts computing with it, after every series check. A str series is NumPy's ValueError (no common type).
polypow(object, int, int?)
Raises the power series c to the power pow: [1] of the series' dtype
for 0, the (trimmed) series for 1, otherwise np.convolve applied pow - 1 times (no trimming between steps). Bit-identical to NumPy 2.4.2's polypow (the product's parity notes on polymul(object, object) apply).
public NDArray polypow(object c, int pow, int? maxpower = null)
Parameters
cobjectThe coefficients, LOW degree first: an NDArray (any layout), a typed C# array, a Python list or tuple (
object[], aValueTuple, a jagged array — np.array's coercion), or a single number. Integer series are computed in float64; a bool series has no common type.powintThe power (≥ 0).
maxpowerint?The largest power allowed: null (NumPy's None: no limit). NumPy's default keeps an accidental huge power from running away.
Returns
- NDArray
The power series, a new array of
np.common_type(c).
Remarks
Exceptions
- ValueError
The series' errors (see polymul(object, object)), then
Power must be a non-negative integer., thenPower is too large— NumPy's order.- NotSupportedException
An object series (see polymul(object, object)), raised after the power checks.
polyroots(object)
The roots of the power series c: the eigenvalues of polycompanion(object)'s matrix (not rotated: the power series is the one basis NumPy does not rotate), computed by
eigvals(NDArray) and sorted in place, ascending (complex numbers lexicographically, real part
first). A constant series has no roots — an empty array of its dtype — and a linear one the single root
-c[0] / c[1] (scalarmath, in its own dtype). Roots far from the origin, and multiple roots, carry larger
errors (NumPy's documented caveat). With NumSharp.Interop.OpenBLAS referenced the eigenvalues come from NumPy's
own LAPACK geev and are bit-identical to NumPy 2.4.2's polyroots (one BLAS thread); where
+0.0 and -0.0 roots meet, NumPy's SIMD sort orders them by CPU and NumSharp's sort deterministically.
public NDArray polyroots(object c)
Parameters
cobjectThe coefficients, LOW degree first: an NDArray (any layout), a typed C# array, a Python list or tuple (
object[], aValueTuple, a jagged array — np.array's coercion), or a single number. Trailing zeros are trimmed first; integer series are computed in float64; a bool series has no common type.
Returns
- NDArray
The sorted roots: REAL when every eigenvalue is — NumPy 2.5's
_to_real_if_imag_zeroover the always complex eigvals: a view of the eigenvalues' real parts (OWNDATA false, every other element of its buffer, as NumPy'sw.real), float64 for a float64 series and float32 for a float32 one — otherwise complex128 (NumPy's complex64 for a float32 series: NumSharp has one complex width).
Remarks
Exceptions
- ValueError
An empty series (
Coefficient array is empty), a series that is not 1-d (Coefficient array is not 1-d), or no common type (a bool or str series), in NumPy's order; a ragged list (np.array's inhomogeneous-shape text).- TypeError
A float16 (or decimal) series of degree 2 or more: linalg's
array type float16 is unsupported in linalg. An OBJECT series of three or more terms whose arithmetic does not raise: eigvals'ufunc 'isfinite' not supported for the input types, …on NumPy's object companion matrix (raised before LAPACK — no backend needed).- LinAlgError
A companion matrix holding an infinity or NaN (
Array must not contain infs or NaNs, checked before the dtype), or eigenvalues that do not converge.- MissingBackendException
Degree 2 or more with no LAPACK backend: reference NumSharp.Interop.OpenBLAS (NumSharp.Core ships no eigensolver).
- NotSupportedException
An OBJECT series (None, a non-numeric object or a Python int past uint64 among the terms) of one term — NumPy returns
np.array([], dtype=object)— or one where NumPy's object arithmetic reaches None or a str (CPython's TypeError there). A two-term object series of numbers computes: NumPy's linear root of the items is a numeric array.- OverflowError
An object series whose arithmetic meets a Python int too large for a float — CPython's
integer division result too large for a floatwhen it is divided by a Python int,int too large to convert to floatwhen it meets anything else — whichever NumPy's statements raise first.
polysub(object, object)
Subtracts the power series c2 from c1 (polyutils._sub): both converted
to their common type; when c2 is at least as long it is NEGATED first and
c1 added into it (NumPy's operation order, visible in which NaN survives), then trailing
zeros are trimmed.
public NDArray polysub(object c1, object c2)
Parameters
Returns
- NDArray
The difference: a new array, or a VIEW of one when trailing zeros were trimmed.
Remarks
Exceptions
- ValueError
An empty or non-1-d series, or no common type (a bool series).
- NotSupportedException
A null series, or one holding None, a non-numeric object or a Python int past uint64 (NumPy's object array), raised after both series' checks.
polytrim(object, double)
polytrim — NumPy's alias of trimcoef(object, double): removes the trailing coefficients whose
magnitude is at most tol (np.abs(c) > tol decides what stays) and returns the
rest as a fresh copy of the coefficient dtype; when nothing exceeds the tolerance the result is
c[:1]*0.
public NDArray polytrim(object c, double tol = 0)
Parameters
cobjectThe series (1-D).
toldoubleThe non-negative tolerance, NumPy's Python number (0, the default, trims only exact zeros): it adopts the coefficients' precision, so a float16 series compares against the float16-rounded tolerance; a NaN tolerance trims everything.
Returns
- NDArray
The trimmed copy (
c[:1]*0when nothing exceeds the tolerance).
Remarks
https://numpy.org/doc/stable/reference/generated/numpy.polynomial.polynomial.polytrim.html
API-parity batch 11 (the owner's decision 2, typed parameters only): one signature with NumPy's
default; the (object c) and (object c, object tol) forms went, so a NumPy scalar or a 0-d
array tolerance (compared in the promoted dtype) is no longer a C# spelling - pass the number.
Exceptions
- ValueError
tol must be non-negative, an empty or non-1-d series, or no common type.
polyval(object, object, bool)
Evaluates the power series c[0] + c[1]x + … + c[n]x**n at x by NumPy's
Horner loop (c0 = c[-1] + x0; c0 = c[-i] + c0x), bit-identical to NumPy 2.4.2 — including
0inf = nan from the x0 seed and every intermediate's NEP 50 dtype.
public NDArray polyval(object x, object c, bool tensor = true)
Parameters
xobjectThe points. An NDArray (any layout) or a C# array is an array; a C#
bool, integer,float,doubleor Complex is a Python scalar — it adopts the coefficients' dtype (polyval(2.0, float32_c)is float32) and a 1-D series then yields a 0-d result.char/Half/decimalare strong 0-d arrays.cobjectCoefficients (anything
np.arrayaccepts — an NDArray of any layout, a typed C# array, a Python tuple / list such as a ValueTuple,object[]or a jagged /NDArray[]array, nested to any depth, or a scalar), low degree first; for an N-D array the series run along axis 0 and the other axes index independent series. Integer and bool coefficients are evaluated as float64.tensorboolWhen true (the default) and x is an array, every series is evaluated at every point and the result has shape
c.shape[1:] + x.shape; when false x is broadcast over the series (c.shape[1:]againstx.shape). Irrelevant for a 1-D series or a scalar x.
Returns
- NDArray
The values, of NumPy's result dtype (float64 for integer coefficients; the promotion of x and c otherwise, float32 staying float32 against a Python-scalar x).
Remarks
Exceptions
- ArgumentNullException
xis null.- ValueError
A ragged tuple / list
corx(np.array's inhomogeneous-shape text; c is converted first, so its error wins).- NotSupportedException
A null or str
c, or a tuple / list holding a str or null (NumPy builds an object / str array, dtypes NumSharp does not have).- IndexError
cis empty:index -1 is out of bounds for axis 0 with size 0.- IncorrectShapeException
tensoris false and the shapes do not broadcast (NumPy's ValueError text).
polyval2d(object, object, object)
Evaluates the 2-D power series Σ c[i,j] * xi * yj at the point pairs (x, y).
NumPy's _valnd: polyval(x, c) then polyval(y, ·, tensor=False) — its exact
intermediate, so the bits match.
public NDArray polyval2d(object x, object y, object c)
Parameters
xobjectFirst coordinates: an NDArray, a typed C# array, a Python tuple / list (np.array's coercion) or a scalar, converted before anything else (NumPy's
np.asanyarray) — so a scalar is a STRONG 0-d array (a Python int an int64 one).yobjectSecond coordinates (converted like
x); must have x's shape.cobjectCoefficients (anything
np.arrayaccepts — an NDArray of any layout, a typed C# array, a Python tuple / list such as a ValueTuple,object[]or a jagged /NDArray[]array, nested to any depth, or a scalar);c[i,j]is the coefficient ofxi * yj. Extra trailing axes index independent series (they lead the result's shape).
Returns
- NDArray
The values, shape
c.shape[2:] + x.shape.
Remarks
Exceptions
- ArgumentNullException
A coordinate (or
pts) is null; a null c is NotSupportedException (NumPy's object array).- ValueError
x and y differ in shape (
x, y are incompatible), or a tuple / list argument is ragged (np.array's inhomogeneous-shape text: the coordinates' before the shape check, c's after it).- NotSupportedException
A null or str
c, a str coordinate, or a tuple / list holding one (NumPy's object / str arrays).- IndexError
cis empty along axis 0.
polyval3d(object, object, object, object)
Evaluates the 3-D power series Σ c[i,j,k] * xi * yj * z**k at the point triples
(x, y, z) (NumPy's _valnd: one tensor pass, then two per-point passes).
public NDArray polyval3d(object x, object y, object z, object c)
Parameters
xobjectFirst coordinates: an NDArray, a typed C# array, a Python tuple / list (np.array's coercion) or a scalar, converted before anything else (NumPy's
np.asanyarray) — so a scalar is a STRONG 0-d array (a Python int an int64 one).yobjectSecond coordinates (converted like
x; x's shape).zobjectThird coordinates (converted like
x; x's shape).cobjectCoefficients (anything
np.arrayaccepts — an NDArray of any layout, a typed C# array, a Python tuple / list such as a ValueTuple,object[]or a jagged /NDArray[]array, nested to any depth, or a scalar);c[i,j,k]multipliesxi * yj * z**k.
Returns
- NDArray
The values, shape
c.shape[3:] + x.shape.
Remarks
Exceptions
- ArgumentNullException
A coordinate (or
pts) is null; a null c is NotSupportedException (NumPy's object array).- ValueError
The coordinates differ in shape (
x, y, z are incompatible), or a tuple / list argument is ragged (the coordinates' before the shape check, c's after it).- NotSupportedException
A null or str
c, a str coordinate, or a tuple / list holding one (NumPy's object / str arrays).- IndexError
cis empty along axis 0.
polyvalfromroots(object, object, bool)
Evaluates the monic polynomial whose roots are r at x,
(x - r[0]) * (x - r[1]) * … * (x - r[n]), bit-identical to NumPy 2.4.2's
np.prod(x - r, axis=0) — in ONE pass, without NumPy's x - r temporary (nr times the result).
Prefer it over polyval(x, polyfromroots(r)) when the roots are known: no coefficient expansion, and each
factor is exact before it is multiplied.
public NDArray polyvalfromroots(object x, object r, bool tensor = true)
Parameters
xobjectThe points. An NDArray (any layout), a typed C# array or a Python tuple / list (a ValueTuple,
object[], a jagged orNDArray[]array — NumPy'snp.asarray(x)) is an array; a C#bool, integer, BigInteger,float,doubleor Complex is a Python scalar, which adopts the roots' dtype (polyvalfromroots(2.0, float32_r)is float32);char/ Half /decimalare strong 0-d values. A str or null is NumPy's str / None (an error, see below).robjectThe roots (anything
np.arrayaccepts — an NDArray of any layout, a typed C# array, a Python tuple / list nested to any depth, or a scalar). Axis 0 holds the roots of one polynomial; further axes index independent polynomials. Integer and bool roots are evaluated as float64; an empty r gives ones.tensorboolWhen true (the default) and x is an array, every polynomial is evaluated at every point: the result has shape
r.shape[1:] + x.shape. When false, x broadcasts over the polynomials (r.shape[1:]againstx.shape), and x must have fewer dimensions than r. Irrelevant for a scalar x.
Returns
- NDArray
The values: a fresh array of NumPy's dtype (the promotion of x and r, float64 for integer roots) and layout (x's memory order under tensor); a 0-d array for a scalar x with a 1-D r.
Remarks
Not polyval. The roots are not coefficients: polyvalfromroots(x, [1, 2]) is
(x - 1)(x - 2), while polyval(x, [1, 2]) is 1 + 2x.
Complex and float16 results depend on the call's shape, as in NumPy. When np.prod's inner loop walks the
roots (one result element, or an F-ordered r with tensor=False), NumPy multiplies with its reduce loops —
the contracted complex product, a float32 float16 accumulation rounded once — and otherwise with its elementwise
ones (one rounding per root). Both are reproduced bit for bit.
https://numpy.org/doc/stable/reference/generated/numpy.polynomial.polynomial.polyvalfromroots.html
Exceptions
- ValueError
A ragged tuple / list (r is converted first, so its error wins), or
tensoris false withx.ndim >= r.ndim:x.ndim must be < r.ndim when tensor == False.- IncorrectShapeException
tensoris false and the shapes do not broadcast (NumPy's ValueError text).- TypeError
A str operand (NumPy's
ufunc 'subtract' did not contain a loop …), or None meeting an element (unsupported operand type(s) for -: 'NoneType' and 'float').- OverflowError
A Python int x too large for the result's float dtype (
int too large to convert to float).- NotSupportedException
NumPy's result would be an object array (None with an empty r of two or more dimensions, an object sequence such as one holding None or a Python int past uint64), or its object arithmetic meets an item NumSharp cannot read as a number.
polyvalnd(object[], object)
Evaluates the N-D power series at the points pts = (x, y, …) — the n-dimensional
polyval2d(object, object, object). NumPy 2.5's addition (gh-30857): pu._valnd(polyval, c, *pts), the computation NumPy
2.4 kept private as polyutils._valnd.
public NDArray polyvalnd(object[] pts, object c)
Parameters
ptsobject[]The coordinates, all of one shape (one per series axis evaluated): each an NDArray, a typed C# array, a Python tuple / list or a scalar, converted first as in
_valnd(a scalar is a STRONG 0-d array). AnNDArray[]passes as it is.cobjectCoefficients (anything
np.arrayaccepts — an NDArray of any layout, a typed C# array, a Python tuple / list such as a ValueTuple,object[]or a jagged /NDArray[]array, nested to any depth, or a scalar); axis i ispts[i]'s degree.
Returns
- NDArray
The values, shape
c.shape[len(pts):] + pts[0].shape.
Remarks
Exceptions
- ArgumentNullException
A coordinate (or
pts) is null; a null c is NotSupportedException (NumPy's object array).- IndexError
ptsis empty (list index out of range).- ValueError
The coordinates differ in shape, or a tuple / list argument is ragged.
- NotSupportedException
A null or str
c, or a str coordinate.
polyvander(object, int)
The Vandermonde matrix of degree deg: V[..., i] = x**i, by NumPy's forward recurrence
v[0] = x*0 + 1; v[1] = x; v[i] = v[i-1] * x — so polyvander(x, n) @ c == polyval(x, c) for a
series of n + 1 coefficients (up to rounding). Bit-identical to NumPy 2.4.2's polyvander: one IL kernel pass
where NumPy runs a Python loop over the degrees; every statement is NumPy's array op in its dtype.
public NDArray polyvander(object x, int deg)
Parameters
xobjectThe points: an NDArray of any layout (a 0-d one is one point), a typed C# array, a Python list or tuple (
object[], aValueTuple, a jagged array — np.array's coercion), or a scalar. The matrix is computed in(x + 0.0).dtype: float16 / float32 / float64 / complex128 are kept (a float32 x gives a float32 matrix), bool, integer and char points become float64; -0.0 reads as +0.0.degintThe degree (≥ 0).
Returns
- NDArray
A view of shape
x.shape + (deg + 1,)((1, deg + 1)for a scalar x) over a new array — the degree axis last, as NumPy'snp.moveaxisleaves it (OWNDATA false; F-contiguous for a 1-D x).
Remarks
Exceptions
- ValueError
deg must be non-negative; a ragged list x (np.array's inhomogeneous-shape text); a matrix too large to describe (array is too big; …).- MemoryError
The matrix cannot be allocated (NumPy's MemoryError).
- NotSupportedException
A null or str x, or a list holding a str / None / a Python int past uint64 (NumPy's str / object arrays, dtypes NumSharp does not have).
polyvander2d(object, object, object)
The 2-D Vandermonde matrix: column a*(deg[1] + 1) + b is xa * yb at every point pair — NumPy's
polyutils._vander_nd_flat, the outer product V_x[..., :, None] * V_y[..., None, :] of the two 1-D
matrices, flattened. Bit-identical to NumPy 2.4.2's polyvander2d: one IL kernel pass builds each block of
points' per-axis matrices in cache and writes the products straight into the result.
public NDArray polyvander2d(object x, object y, object deg)
Parameters
xobjectThe first coordinates. x and y are STACKED as
np.asarray((x, y))— they must have exactly the same shape (no broadcasting), and the matrix dtype is np.promote_types over both (array coercion's rule: a Python float is float64 there, so a float16 array with a Python-float y is float64) plus 0.0.yobjectThe second coordinates (same shape as x).
degobjectThe two degrees
[x_deg, y_deg]: a list / tuple, a typed C# array, an NDArray or a str of length 2, each item read as NumPy'spolyutils._as_int(Python'soperator.index: an integer, a bool, a NumPy integer scalar or 0-d integer array; anything else isdeg must be an integer, received …).
Returns
- NDArray
A view of shape
x.shape + ((deg[0] + 1) * (deg[1] + 1),)over a new array (OWNDATA false; a scalar x, y is one point).
Remarks
Exceptions
- TypeError
A deg without a length (
object of type 'int' has no len(),len() of unsized object) — before the points are converted — or a non-integer degree (checked axis by axis, after the points).- ValueError
Expected 2 dimensions of degrees, got {len}; points of different shapes (np.array's inhomogeneous-shape text);deg must be non-negative;array is too big; ….- IncorrectShapeException
No points (an empty x, y): NumPy's reshape text
cannot reshape array of size 0 into shape (0,newaxis).- MemoryError
A matrix NumPy allocates on the way cannot be allocated.
- OverflowError
Scalar points with a Python int past the float range (NumPy's
int too large to convert to floatat its per-element+ 0.0).- NotSupportedException
Points NumPy stacks into a str array, or into an object array it computes with as Python objects or fails on. Scalar points that are all numbers but stack into an object array (a Python int past uint64 among them) ARE computed: each dimension gets its own number, as in NumPy.
polyvander3d(object, object, object, object)
The 3-D Vandermonde matrix: column (a*(deg[1] + 1) + b)*(deg[2] + 1) + c is xa * yb * z**c —
NumPy's ((V_x[..., :, None, None] * V_y[..., None, :, None]) * V_z[..., None, None, :]) flattened, the
first product rounded to the dtype before the second. Bit-identical to NumPy 2.4.2's polyvander3d.
public NDArray polyvander3d(object x, object y, object z, object deg)
Parameters
xobjectThe first coordinates (x, y and z are stacked: one shape — see polyvander2d(object, object, object)).
yobjectThe second coordinates.
zobjectThe third coordinates.
degobjectThe three degrees
[x_deg, y_deg, z_deg](see polyvander2d(object, object, object)).
Returns
- NDArray
A view of shape
x.shape + ((deg[0] + 1) * (deg[1] + 1) * (deg[2] + 1),)over a new array.
Remarks
Exceptions
- TypeError
A deg without a length, or a non-integer degree (see polyvander2d(object, object, object)).
- ValueError
Expected 3 dimensions of degrees, got {len}, and polyvander2d(object, object, object)'s other errors.- IncorrectShapeException
No points (NumPy's reshape text).
- MemoryError
A matrix NumPy allocates on the way cannot be allocated.
- OverflowError
Scalar points with a Python int past the float range (NumPy's
int too large to convert to floatat its per-element+ 0.0).- NotSupportedException
Points NumPy stacks into a str array, or into an object array it computes with as Python objects or fails on. Scalar points that are all numbers but stack into an object array (a Python int past uint64 among them) ARE computed: each dimension gets its own number, as in NumPy.