Metadata-Version: 2.4
Name: coshape
Version: 0.0.1
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Typing :: Typed
License-File: LICENSES/LICENSE-APACHE
License-File: LICENSES/LICENSE-MIT
Summary: Shape-preserving 1-D spline interpolation: concavity- and monotonicity-preserving C2 splines
Keywords: interpolation,spline,shape-preserving,concave,numerics
Author-email: Feiyang Chen <feiyangc@outlook.com>
License-Expression: MIT OR Apache-2.0
Requires-Python: >=3.11
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Issues, https://github.com/Feiyang472/coshape/issues
Project-URL: Repository, https://github.com/Feiyang472/coshape

# coshape

Shape-preserving 1-D spline interpolation, implemented in Rust.

Given concave data the fitted spline passes through the knots exactly, keeps
`f'' <= 0` everywhere, and is at least C². Convex data gives the mirror image;
the tension and variable-degree methods also follow data that changes curvature.

```python
import array
from coshape import EndSlopes, Tension

x = array.array("d", [0.0, 1.0, 2.0, 3.0, 4.0])    # any float64 buffer, e.g. numpy
y = array.array("d", [0.0, 4.0, 7.0, 7.5, 7.9])    # concave

fitter = Tension().with_boundary(EndSlopes.clamped(4.5, 0.3))   # configuration only
spline = fitter.fit(x, y)                                     # a separate, fitted object

spline(2.5)                           # value
spline.second_derivative(2.5)         # <= 0 on concave data

grid = array.array("d", (i / 100 for i in range(401)))
spline.value_batch(grid)                   # a new array.array('d')
out = array.array("d", bytes(8 * len(grid)))
spline.value_batch_into(grid, out)         # fills your buffer, no allocation
```

| Fitter | Produces | Method |
|---|---|---|
| `RationalCubic` | `RationalCubicSpline` | convexity/concavity-preserving C² rational cubic (Abbas–Majid–Ali) |
| `Tension` | `TensionSpline` | exponential tension spline (Renka, TSPACK); `with_uniform_tension(sigma)` for a fixed factor |
| `VariableDegree` | `VariableDegreeSpline` | co-convex C² variable-degree polynomial spline (Kaklis–Pandelis); accepts inflections |

Fitters are immutable: each `with_*` returns a new fitter. Arrays go through the
buffer protocol — numpy float64
arrays, `array.array('d')`, or memoryviews of them — with no numpy dependency,
which is why Python 3.11 or newer is required. Invalid data raises `ValueError`.
Type stubs are included.

Dual-licensed under MIT OR Apache-2.0. Source:
<https://github.com/Feiyang472/coshape>

