Fast polynomial evaluation in Cython
Project description
poly_eval
Fast polynomial evaluation powered by Cython and NumPy.
Features
- Polynomial — real-valued coefficients and exponents
- StrictPolynomial — exponents constrained to non-negative integers
- Real evaluation —
evaluate_real(inp, mag_only=False) - Complex evaluation —
evaluate_complex(real, imag, mag_only=False) - Real→complex —
evaluate_real_to_complex(inp, mag_only=False) - Magnitude-only mode — applies exponent to |x| while preserving sign/direction
- Addition — O(n+m) merge of sorted exponent arrays
- Multiplication — convolution via dict merge
- Cython nogil kernels for all evaluation paths
Installation
pip install numpy Cython
python setup.py install
Quickstart
import numpy as np
from pyevalpoly import Polynomial
p = Polynomial([(1.0, 2.0), (2.0, 1.0), (0.5, 0.0)])
# 0.5 + 2x + x²
x = np.array([1.0, 2.0, 3.0])
print(p.evaluate_real(x))
# [3.5 8.5 15.5]
# Magnitude-only (|x|^e * sign(x))
print(p.evaluate_real(x, mag_only=True))
# Complex evaluation
re = np.array([1.0, -1.0])
im = np.array([2.0, -2.0])
out = p.evaluate_complex(re, im) # shape (2, 2)
# Arithmetic
q = Polynomial([(3.0, 1.0), (1.0, 0.0)])
r = p + q # terms with matching exponents are summed
s = p * q # convolution
Classes
Polynomial(terms) — terms: list of (coeff, exp) or PolyComponent
StrictPolynomial(terms) — same, but exponents must be non-negative integers
PolyComponent(coeff, exp) — named tuple for term construction
StrictPolyComponent(...) — named tuple for strict construction
Evaluation methods
Each method preserves the input shape on the real axis and appends a final dimension of size 2 for complex outputs.
| Method | Input shape | Output shape |
|---|---|---|
evaluate_real(inp) |
(...,) |
(...,) |
evaluate_complex(re, im) |
(...,) + (...,) |
(..., 2) |
evaluate_real_to_complex(inp) |
(...,) |
(..., 2) |
All methods accept the keyword argument mag_only=False. When True, each term
c·x^e is evaluated as c·sgn(x)·|x|^e, keeping the direction but applying the
exponent only to the magnitude.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyevalpoly-0.1.0.tar.gz.
File metadata
- Download URL: pyevalpoly-0.1.0.tar.gz
- Upload date:
- Size: 214.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a3971b7f0d2cc2461cdc9cade9d6fa37c44a836fb05c6004f282f16c521685c
|
|
| MD5 |
d1b74cad9d0d8b6c6b1a586ded07bd6e
|
|
| BLAKE2b-256 |
56431026cbee7e083bfe7e66b728bb9d2a991b5e5037cd45fe9dee9988d588f0
|
File details
Details for the file pyevalpoly-0.1.0-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: pyevalpoly-0.1.0-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 314.6 kB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aeb85ff5f083729cb20b9e69312622ec553ec3f8804c1e10fdf068f870c48a4e
|
|
| MD5 |
1def30c6004a220a6af0f5c68570ed9a
|
|
| BLAKE2b-256 |
dd3d75b153c34d84640542ac2c7f8d53d960ce06062d857c19e988dc30856dfc
|