Class ChebyshevModule
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
numpy.polynomial.chebyshev — Chebyshev series of the first kind p(x) = c[0]*T_0(x) + c[1]*T_1(x) + …, reachable as
np.polynomial.chebyshev. Coefficients are LOW degree first.
[ModuleName("np.polynomial.chebyshev")]
public class ChebyshevModule
- Inheritance
-
ChebyshevModule
- Inherited Members
Remarks
Properties
chebdomain
chebdomain — the default domain of the Chebyshev series class, float64 [-1.0, 1.0].
public NDArray chebdomain { 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.chebyshev.html
chebone
chebone — the Chebyshev series representing 1, int64 [1] (shared and writeable, see chebdomain).
public NDArray chebone { get; }
Property Value
Remarks
chebx
chebx — the Chebyshev series representing x, int64 [0, 1] (shared and writeable, see chebdomain).
public NDArray chebx { get; }
Property Value
Remarks
chebzero
chebzero — the Chebyshev series representing 0, int64 [0] (shared and writeable, see chebdomain).
public NDArray chebzero { get; }
Property Value
Remarks
Methods
Chebyshev(object, object, object, string)
NumPy's numpy.polynomial.chebyshev.Chebyshev(coef, domain=None, window=None, symbol='x'): a Chebyshev series — a new
NDChebyshev (the class itself; its class methods fit, fromroots, identity,
basis and cast are static members of NDChebyshev).
public NDChebyshev Chebyshev(object coef, object domain = null, object window = null, string symbol = "x")
Parameters
coefobjectThe coefficients, low degree first (see NDChebyshev(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
- NDChebyshev
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.
cheb2poly(object)
Converts the Chebyshev series c to a power series — NumPy's backward recurrence over power-series
ops (polyadd, polysub, polymulx) from the highest coefficient down; a series of fewer than three terms is returned as is. Keeps the
series' common type. Bit-identical to NumPy 2.4.2's cheb2poly.
public NDArray cheb2poly(object c)
Parameters
cobjectThe Chebyshev series's coefficients. 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.
Returns
- NDArray
The power-series coefficients, low degree first (a new array, or a view of one when trailing zeros were trimmed).
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).
chebadd(object, object)
Adds two Chebyshev 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 chebadd(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.
chebcompanion(object)
The scaled companion matrix of the Chebyshev series c: the basis is scaled (T_0 by 1, the others by sqrt(1/2)) so that the matrix is symmetric when c is a single Chebyshev polynomial, which gives better eigenvalue estimates — off-diagonals sqrt(.5) then 1/2, and the last column reduced by (c[:-1] / c[-1]) * (scl / scl[-1]) * .5. NumPy's scale vector is float64, so a float16 / float32 series' last column is computed in float64 and rounded once into the matrix (the in-place op's output cast) and its off-diagonals are float64 values cast by assignment; a complex series runs the complex128 loops. Bit-identical to NumPy 2.4.2's chebcompanion.
public NDArray chebcompanion(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.
chebder(object, int, object, int)
Differentiates the Chebyshev series c m times along axis,
multiplying by scl at every order. Bit-identical to NumPy 2.4.2's chebder: its
recurrence der[j-1] = (2j)c[j]; c[j-2] += (jc[j])/(j-2) (then der[1] = 4c[2],
der[0] = c[1]), with c *= scl before every order, in NumPy's statement order and NEP 50 dtypes.
public NDArray chebder(object c, int m = 1, object scl = null, int axis = 0)
Parameters
cobjectThe coefficients, LOW degree first (see polyder(object, int, object, int)).
mintHow many times to differentiate (≥ 0). 0 returns a copy;
m >= len(c)returnsc[:1]*0.sclobjectThe multiplier applied at each order (null for NumPy's 1; a scalar or a broadcasting array — see polyder(object, int, object, int)).
axisintThe axis the series runs along (negative counts from the end).
Returns
- NDArray
The derivative's coefficients, of the series' dtype (a view of a new array in NumPy's layout).
Remarks
Exceptions
- ValueError
The order of derivation must be non-negative, or an array scl whose broadcast would stretch the series.- AxisError
axisis out of range.- TypeError
A scl the series cannot absorb in place (NumPy's UFuncTypeError).
- IncorrectShapeException
An array scl that does not broadcast with the series.
- NotSupportedException
A null or string series.
chebdiv(object, object)
Divides the Chebyshev series c1 by c2, returning quotient and remainder:
the z-series division (chebyshev._zseries_div): both series as z-series, a symmetric synthetic division from both ends, the quotient and remainder folded back and trimmed. 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 chebdiv.
public (NDArray quo, NDArray rem) chebdiv(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.
chebfit(object, object, object, object, bool, object)
The least-squares fit of a Chebyshev series to data: the coefficients c that minimise the weighted squared error
sum_j w_j**2 * |y_j - chebval(x_j, c)|**2, computed as NumPy 2.4.2 writes it (polyutils._fit: the
chebvander(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 chebfit(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.chebyshev.chebfit.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).
chebfromroots(object)
The Chebyshev series whose roots are roots: the roots sorted, one linear factor per root
(chebline(-r, 1) = [-r, 1]), multiplied pairwise as a balanced tree (polyutils._fromroots) with chebmul.
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 chebfromroots (the product's parity notes on chebmul(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 chebfromroots(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).
chebgauss(object)
Gauss-Chebyshev quadrature: the nodes x_k = cos(pi*(2k + 1)/(2deg)) (DECREASING, the roots of
T_deg) and the weights w_k = pi/deg, so that Σ w_k f(x_k) integrates
f(x)/sqrt(1 - x**2) over [-1, 1] exactly for every polynomial f of degree up to 2deg - 1.
Computed as NumPy 2.4.2 writes it (np.cos(np.pi * np.arange(1, 2deg, 2) / (2.0deg)),
np.ones(deg) * (np.pi/deg)); bit-identical to NumPy.
public (NDArray x, NDArray w) chebgauss(object deg)
Parameters
degobjectThe number of nodes: an integer — a C# integer, BigInteger,
boolorchar, or a 0-d integer NDArray (Python'soperator.index). A float, even an integral one, is refused.
Returns
Remarks
cos is the C runtime's on both sides.
https://numpy.org/doc/stable/reference/generated/numpy.polynomial.chebyshev.chebgauss.html
Exceptions
- TypeError
deg must be an integer, received {deg}, withdegas NumPy's f-string formats it (received 3.0,received Truefor a 0-d bool array).- ValueError
deg must be a positive integer, or a count too large to allocate:array is too big; …,Maximum allowed dimension exceeded(np.ones' shape past int64, for the counts whose np.arange came back empty) orMaximum allowed size exceeded.- OutOfMemoryException
A count below the byte limit that the machine cannot hold.
chebgrid2d(object, object, object)
Evaluates the 2-D Chebyshev series of the first kind on the Cartesian product of x and y
(NumPy's _gridnd: two tensor passes). Unlike chebval2d(object, object, object) the coordinates are NOT
converted first, so a Python-scalar coordinate stays weak.
public NDArray chebgrid2d(object x, object y, object c)
Parameters
xobjectFirst-axis points (array or Python scalar, as in chebval(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]is the coefficient of the degree (i, j) term.
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.
chebgrid3d(object, object, object, object)
Evaluates the 3-D Chebyshev series of the first kind on the Cartesian product of x, y and
z (NumPy's _gridnd: three tensor passes).
public NDArray chebgrid3d(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]is the coefficient of the degree (i, j, k) term.
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.
chebint(object, int, object, object, object, int)
Integrates the Chebyshev series c m times along axis:
each order multiplies by scl, integrates (tmp[j+1] = c[j]/(2*(j+1));
tmp[j-1] -= c[j]/(2*(j-1)), with tmp[2] = c[1]/4) and adds the constant that makes the new series
equal k[i] at lbnd (tmp[0] += k[i] - chebval(lbnd, tmp)). Bit-identical to
NumPy 2.4.2's chebint.
public NDArray chebint(object c, int m = 1, object k = null, object lbnd = null, object scl = null, int axis = 0)
Parameters
cobjectThe coefficients, LOW degree first.
mintHow many times to integrate (≥ 0); 0 returns a copy.
kobjectThe integration constants (see polyint(object, int, object, object, object, int)).
lbndobjectThe lower bound (null for NumPy's 0); a scalar.
sclobjectThe multiplier applied at each order (null for NumPy's 1); a scalar.
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 argument checks (see polyint(object, int, object, object, object, int)).
- AxisError
axisis out of range.- IndexError
An empty series.
- TypeError
An array constant for a complex 1-D series (NumPy's
complex()text).- TypeError
A value an N-D series cannot absorb in place (NumPy's UFuncTypeError).
- IncorrectShapeException
Constants that do not broadcast with the series' columns.
- NotSupportedException
A null or string series, constant or bound.
chebinterpolate(Func<NDArray, object[], object>, object, object)
Interpolates func at the deg + 1 Chebyshev points of the first kind
(chebpts1(object)) on [-1, 1]: the Chebyshev series of degree deg through those points,
which tends to the minimax approximation of a continuous function as the degree grows. Computed as NumPy 2.4.2
writes it — c = np.dot(chebvander(x, deg).T, func(x, args)), then c[0] /= deg + 1 and
c[1:] /= 0.5(deg + 1), the discrete orthogonality of the Chebyshev polynomials at those points — so the
coefficients are NumPy's bit for bit wherever np.dot is (with NumSharp.Interop.OpenBLAS referenced, the
OpenBLAS products NumPy calls; without it the managed product, within a few ULP).
public NDArray chebinterpolate(Func<NDArray, object[], object> func, object deg, object args = null)
Parameters
funcFunc<NDArray, object[], object>The function to approximate, called ONCE as
func(x, args):xis the points (a new float64 array ofdeg + 1elements in increasing order) andargsthe unpackedargs(empty when there are none) — NumPy'sfunc(x, args). It returns anythingnp.dotaccepts: an NDArray of the values at the points (any dtype; a 2-D(deg + 1, k)array interpolates k functions at once, and an N-D one contracts its second-to-last axis), a Python list or tuple of them, a typed C# array, or a scalar (np.dot of a 0-d operand is a product, so the result is then the matrixchebvander(x, deg).T * ywith row 0 divided bydeg + 1and the rest by0.5(deg + 1)).degobjectThe degree of the interpolating series: a non-negative integer — a C# integer or BigInteger, a
char(np.uint16), or a 0-d integer NDArray (NumPy'snp.asarray(deg)of an integer kind). A bool, a float (even3.0), a list (even[3]) or a sized array is refused.deg + 1is computed in deg's dtype and wraps there, as in NumPy: a 0-d uint8 array holding 255 asks chebpts1 for 0 points.argsobjectExtra arguments for
func, unpacked as Python's*args: anobject[], a tuple, any other enumerable, an NDArray (its first-axis items), a string (its characters as one-character strings) or a dictionary (its keys); null (the default) is NumPy's().
Returns
- NDArray
The coefficients, low degree first: a new array of np.dot's dtype (float64, or complex128 for a complex result), of shape
(deg + 1,)for a vector result,(deg + 1,) + y.shape[:-2] + y.shape[-1:]for an N-D one and(deg + 1, deg + 1)for a scalar one.
Remarks
Ownership. The points handed to func and every array it creates are intermediates
of this call and are reclaimed when it returns (NDScopedAttribute): to keep one, call
Detach(NDArray) on it inside func. An array func returns that was created
before the call stays the caller's.
Exceptions func throws propagate unchanged.
A numpy.matrix result is computed as a plain array (NumPy returns a matrix): the numpy.polynomial
package computes plain.
https://numpy.org/doc/stable/reference/generated/numpy.polynomial.chebyshev.chebinterpolate.html
Exceptions
- TypeError
deg must be an int; args that cannot be unpacked (Value after * must be an iterable, not …, oriteration over a 0-d array); a nullfunc('NoneType' object is not callable, raised after args are unpacked, as in Python).- ValueError
expected deg >= 0;npts must be >= 1from chebpts1 whendeg + 1wrapped (a 0-d integer array at its dtype's maximum, or 2**63 - 1); a degree too large to allocate (array is too big; …,Maximum allowed dimension exceeded); a ragged sequence (np.asarray's inhomogeneous-shape text).- ArgumentException
np.dot's
shapes … not aligned: …— a result whose length is notdeg + 1(NumPy's ValueError, with NumPy's text).- NotSupportedException
A result NumPy turns into an OBJECT array (null, or a list holding null or a Python int past uint64): NumPy then computes the product with Python objects, a dtype NumSharp does not have.
- MemoryError
A degree whose matrix the machine cannot hold (NumPy's MemoryError).
chebline(object, object)
The Chebyshev 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 (chebline(1, 2) is int64,
chebline(1.0, 2) float64, a bool pair stays bool) rather than a coefficient dtype.
public NDArray chebline(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.
chebmul(object, object)
Multiplies two Chebyshev series: the z-series product: both series doubled into Laurent z-series (zs[n-1:] = c/2; zs + zs[::-1]), convolved (np.convolve) and folded back (c[1:n] *= 2), trailing zeros trimmed. The product is np.convolve's arithmetic on the z-series — NumPy's sequential sum for real series whose shorter factor has at most ~8 terms (a z-series doubles the length), 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 chebmul(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).
chebmulx(object)
Multiplies the Chebyshev series c by x: xT_0 = T_1, xT_i = (T_{i-1} + T_{i+1})/2: NumPy's prd[0] = c[0]*0; prd[1] = c[0]; tmp = c[1:]/2; prd[2:] = tmp; prd[0:-2] += tmp. The zero series [0] is returned as is.
Bit-identical to NumPy 2.4.2's chebmulx — one IL kernel pass where NumPy runs a Python loop.
public NDArray chebmulx(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).
chebpow(object, int, int?)
Raises the Chebyshev series c to the power pow: [1] of the series' dtype
for 0, the (trimmed) series for 1, otherwise the z-series convolved pow - 1 times and folded back (no final trimming). Bit-identical to NumPy 2.4.2's chebpow (the product's parity notes on chebmul(object, object) apply).
public NDArray chebpow(object c, int pow, int? maxpower = 16)
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: 16; null for 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 chebmul(object, object)), then
Power must be a non-negative integer., thenPower is too large— NumPy's order.- NotSupportedException
An object series (see chebmul(object, object)), raised after the power checks.
chebpts1(object)
The Chebyshev points of the first kind: sin(0.5pi/npts * k) for k = -npts+1, -npts+3, …, npts-1,
i.e. -cos(pi(2j + 1)/(2*npts)) in increasing order — the roots of the Chebyshev polynomial
T_npts, the classic interpolation nodes. Computed as NumPy 2.4.2 writes it (an integer ramp, one product,
np.sin) in one pass with no intermediate arrays; bit-identical to NumPy.
public NDArray chebpts1(object npts)
Parameters
nptsobjectThe number of points, which must be integral: a C# integer, BigInteger or
bool; afloat/double/ Half /decimalor a 0-d NDArray equal to an integer (3.0); or a str of an integer — which NumPy accepts inint()and then rejects, since'3' != 3. Python'sint(npts)decides everything else.
Returns
- NDArray
A new float64 array of
nptspoints in [-1, 1].
Remarks
sin is the C runtime's on both sides (Math.Sin, NumPy's float64 loop on win-amd64), so the speed gain is NumPy's ramp, product and temporaries, not the sine.
https://numpy.org/doc/stable/reference/generated/numpy.polynomial.chebyshev.chebpts1.html
Exceptions
- ValueError
npts must be integer(a fraction, or a str),npts must be >= 1, int()'scannot convert float NaN to integer/invalid literal for int() with base 10: '…', or a count too large to allocate:array is too big; …(from2**60) orMaximum allowed size exceeded(past npy_intp, NumPy's np.arange length rule).- TypeError
int()'s
int() argument must be a string, a bytes-like object or a real number, not '…'(null, a Complex, a list or tuple) oronly 0-dimensional arrays can be converted to Python scalars(an array of one or more dims).- OverflowError
int() of an infinity (
cannot convert float infinity to integer), or a count past the float range (int too large to convert to float, from0.5*np.pi / npts).- NotSupportedException
A count in
[263 + 2, 263 + 1024], where NumPy's np.arange length rounds to263and returns an EMPTY object array (a dtype NumSharp does not have). The counts[263 - 512, 2**63 + 1]return an empty float64 array, as NumPy's do.- MemoryError
A count below the byte limit that the machine cannot hold (NumPy's MemoryError).
chebpts2(object)
The Chebyshev points of the second kind: cos(linspace(-pi, 0, npts)), i.e. -cos(pi*k/(npts - 1))
in increasing order — the extrema of T_(npts-1) together with both endpoints ±1. Computed as NumPy 2.4.2
writes it (linspace's ramp times its step plus its start, the endpoint stored as 0, then np.cos) in one
pass; bit-identical to NumPy.
public NDArray chebpts2(object npts)
Parameters
nptsobjectThe number of points (at least 2), which must be integral: the same kinds as chebpts1(object)'s.
Returns
- NDArray
A new float64 array of
nptspoints from -1 to 1.
Remarks
cos is the C runtime's on both sides.
https://numpy.org/doc/stable/reference/generated/numpy.polynomial.chebyshev.chebpts2.html
Exceptions
- ValueError
npts must be integer,npts must be >= 2, int()'s ValueErrors, or a count too large to allocate (array is too big; …,Maximum allowed size exceeded).- TypeError
int()'s TypeErrors (see chebpts1(object)).
- OverflowError
int() of an infinity.
- IndexError
A count in
[263 - 512, 263 + 1024]: np.arange returns an empty ramp there and NumPy's linspace fails ony[-1, ...] = stop(index -1 is out of bounds for axis 0 with size 0).- OutOfMemoryException
A count below the byte limit that the machine cannot hold.
chebroots(object)
The roots of the Chebyshev series c: the eigenvalues of chebcompanion(c)[::-1, ::-1] — the ROTATED companion matrix, which NumPy notes reduces the error, 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 chebroots (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 chebroots(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: for degree 2 or more the eigenvalue array eigvals(NDArray) returned, sorted in place — always complex128 since NumPy 2.5 (real roots carry zero imaginary parts; NumPy's complex64 for a float32 series: NumSharp has one complex width); a linear series' single root keeps the series dtype.
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.
chebsub(object, object)
Subtracts the Chebyshev 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 chebsub(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.
chebtrim(object, double)
chebtrim — 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 chebtrim(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.chebyshev.chebtrim.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.
chebval(object, object, bool)
Evaluates the Chebyshev series of the first kind with coefficients c at x by Clenshaw's recurrence exactly as NumPy writes it (x2 = 2x; c0 = c[-i] - c1; c1 = tmp + c1x2; return c0 + c1*x),
bit-identical to NumPy 2.4.2: the first steps run in the COEFFICIENTS' dtype exactly as NumPy's
do, and every intermediate carries NumPy's NEP 50 dtype.
public NDArray chebval(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 (chebval(2.0, float32_c)is float32), Python-level arithmetic on it (2*x,1 - x) is done in double as CPython does, 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.
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 -2 is out of bounds for axis 0 with size 0.- IncorrectShapeException
tensoris false and the shapes do not broadcast (NumPy's ValueError text).- OverflowError
A Python int of the recurrence does not fit an integer x dtype (NumPy's OverflowError).
chebval2d(object, object, object)
Evaluates the 2-D Chebyshev series of the first kind Σ c[i,j] * T_i(x) * T_j(y) at the point pairs (x, y).
NumPy's _valnd: chebval(x, c) then chebval(y, ·, tensor=False) — its exact
intermediate, so the bits match.
public NDArray chebval2d(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 of the degree (i, j) term. 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.
chebval3d(object, object, object, object)
Evaluates the 3-D Chebyshev series of the first kind at the point triples (x, y, z) (NumPy's _valnd: one tensor
pass, then two per-point passes).
public NDArray chebval3d(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]is the coefficient of the degree (i, j, k) term.
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.
chebvalnd(object[], object)
Evaluates the N-D Chebyshev series of the first kind at the points pts = (x, y, …) — the n-dimensional
chebval2d(object, object, object). NumPy 2.5's addition (gh-30857): pu._valnd(chebval, c, *pts), the computation NumPy
2.4 kept private as polyutils._valnd.
public NDArray chebvalnd(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.
chebvander(object, int)
The pseudo-Vandermonde matrix of degree deg: V[..., i] = T_i(x), by NumPy's forward
recurrence v[0] = x0 + 1; x2 = 2x; v[1] = x; v[i] = v[i-1]*x2 - v[i-2] — so
chebvander(x, n) @ c == chebval(x, c) up to rounding. Bit-identical to NumPy 2.4.2's chebvander
(one IL kernel pass; x2 is computed once per block of points, as NumPy computes it once).
public NDArray chebvander(object x, int deg)
Parameters
xobjectThe points (see polyvander(object, int): any layout; the matrix dtype is
(x + 0.0).dtype).degintThe degree (≥ 0).
Returns
- NDArray
A view of shape
x.shape + (deg + 1,)over a new array, the degree axis last (OWNDATA false).
Remarks
Exceptions
- ValueError
deg must be non-negative; a ragged list x;array is too big; ….- MemoryError
The matrix cannot be allocated (NumPy's MemoryError).
- NotSupportedException
A null or str x, or a list NumPy makes a str / object array of.
chebvander2d(object, object, object)
The 2-D pseudo-Vandermonde matrix: column a*(deg[1] + 1) + b is T_a(x) * T_b(y) — NumPy's
_vander_nd_flat outer product of the two 1-D matrices. Bit-identical to NumPy 2.4.2's chebvander2d.
public NDArray chebvander2d(object x, object y, object deg)
Parameters
xobjectThe first coordinates (stacked with y: one shape, one promoted dtype — see polyvander2d(object, object, object)).
yobjectThe second coordinates.
degobjectThe two degrees
[x_deg, y_deg].
Returns
- NDArray
A view of shape
x.shape + ((deg[0] + 1) * (deg[1] + 1),)over a new array.
Remarks
Exceptions
- TypeError
A deg without a length, or a non-integer degree.
- ValueError
Expected 2 dimensions of degrees, got {len}; points of different shapes;deg must be non-negative;array is too big; ….- 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.
chebvander3d(object, object, object, object)
The 3-D pseudo-Vandermonde matrix: column (a*(deg[1] + 1) + b)*(deg[2] + 1) + c is
T_a(x) * T_b(y) * T_c(z), the first product rounded before the second (NumPy's reduce). Bit-identical to
NumPy 2.4.2's chebvander3d.
public NDArray chebvander3d(object x, object y, object z, object deg)
Parameters
xobjectThe first coordinates (x, y, z stacked: one shape).
yobjectThe second coordinates.
zobjectThe third coordinates.
degobjectThe three degrees.
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.
- ValueError
Expected 3 dimensions of degrees, got {len}, and the 2-D form'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.
chebweight(object)
The Chebyshev weight function 1/sqrt(1 - x**2), computed as NumPy 2.4.2 writes it,
1.0/(np.sqrt(1.0 + x)*np.sqrt(1.0 - x)) — two square roots and a product, not the textbook formula,
so the bits are NumPy's. It is nan outside [-1, 1] and inf at ±1. An ndarray is computed in one fused pass
(no intermediate arrays).
public NDArray chebweight(object x)
Parameters
xobjectThe points: an NDArray of any layout and dtype, or a typed C# array (an ndarray); a Python scalar — a C#
bool, integer, BigInteger,float,doubleor Complex, computed with CPython's arithmetic up to the first NumPy call, as NumPy does (chebweight(2)is nan); or a NumPy scalar (Half,char,decimal). x is not converted first, so a Python list or tuple is refused by Python's+.
Returns
- NDArray
The weights: an array of x's shape for an ndarray x (float64 for an integer or bool x, x's own dtype for a float or complex x), a 0-d array for a scalar x.
Remarks
A complex x inherits np.sqrt's complex accuracy (a few ULP from NumPy's C runtime
csqrt); every real dtype is bit-identical to NumPy.
https://numpy.org/doc/stable/reference/generated/numpy.polynomial.chebyshev.chebweight.html
Exceptions
- TypeError
xis a Python list or tuple (anobject[], a C# list, aValueTuple), null or a string: Python'sunsupported operand type(s) for +: 'float' and 'list'('tuple','NoneType','str'). Or a string array:np.add's no-loop error.- OverflowError
A Python int too large for a float: CPython's
int too large to convert to floatfrom1.0 + x. Or a decimal x outside [-1, 1]: decimal (no NumPy dtype) has no NaN, so the house decimal square root of a negative number raises.- DivideByZeroException
A decimal x of ±1 (
1.0/0: decimal has no infinity).
poly2cheb(object)
Converts the power series pol to a Chebyshev series — Horner's scheme over the Chebyshev series's own ops:
res = chebadd(chebmulx(res), pol[i]) from the highest coefficient down, starting from the Python int 0,
which makes the result float64 for any real series (complex128 for a complex one). Bit-identical to NumPy
2.4.2's poly2cheb.
public NDArray poly2cheb(object pol)
Parameters
polobjectThe power-series coefficients. 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.
Returns
- NDArray
The Chebyshev series's coefficients, low degree first (a new array, or a view of one when trailing zeros were trimmed).
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).