jax.numpy.polydiv#
- jax.numpy.polydiv(u, v, *, trim_leading_zeros=False)[source]#
Returns the quotient and remainder of polynomial division.
JAX implementation of
numpy.polydiv()
.- Parameters:
u (ArrayLike) – Array of dividend polynomial coefficients.
v (ArrayLike) – Array of divisor polynomial coefficients.
trim_leading_zeros (bool) – Default is
False
. IfTrue
removes the leading zeros in the return value to match the result of numpy. But prevents the function from being able to be used in compiled code. Due to differences in accumulation of floating point arithmetic errors, the cutoff for values to be considered zero may lead to inconsistent results between NumPy and JAX, and even between different JAX backends. The result may lead to inconsistent output shapes whentrim_leading_zeros=True
.
- Returns:
A tuple of quotient and remainder arrays. The dtype of the output is always promoted to inexact.
- Return type:
Note
jax.numpy.polydiv()
only accepts arrays as input unlikenumpy.polydiv()
which accepts scalar inputs as well.See also
jax.numpy.polyadd()
: Computes the sum of two polynomials.jax.numpy.polysub()
: Computes the difference of two polynomials.jax.numpy.polymul()
: Computes the product of two polynomials.
Examples
>>> x1 = jnp.array([5, 7, 9]) >>> x2 = jnp.array([4, 1]) >>> np.polydiv(x1, x2) (array([1.25 , 1.4375]), array([7.5625])) >>> jnp.polydiv(x1, x2) (Array([1.25 , 1.4375], dtype=float32), Array([0. , 0. , 7.5625], dtype=float32))
If
trim_leading_zeros=True
, the result matches withnp.polydiv
’s.>>> jnp.polydiv(x1, x2, trim_leading_zeros=True) (Array([1.25 , 1.4375], dtype=float32), Array([7.5625], dtype=float32))