Metadata-Version: 2.4
Name: pyevalpoly
Version: 0.1.0
Summary: Fast polynomial evaluation in Cython
License-Expression: MIT
Project-URL: Homepage, https://github.com/anomalyco/poly_eval
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Dynamic: license-file

# 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

```bash
pip install numpy Cython
python setup.py install
```

## Quickstart

```python
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
