Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ __pycache__/

# C extensions
*.so
*.dll
*.dylib
*.lib
*.a
*.o
*.obj
*.exe
*.bin
*.app


# Distribution / packaging
.Python
Expand Down
68 changes: 50 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,74 @@
# <Project Name>
# spinterp

**<Project Description>**
**Sparse Grid Interpolation Toolbox for Python**

[![Tests](https://github.com/eggzec/<Project Name>/actions/workflows/code_test.yml/badge.svg)](https://github.com/eggzec/<Project Name>/actions/workflows/code_test.yml)
[![Documentation](https://github.com/eggzec/<Project Name>/actions/workflows/docs_build.yml/badge.svg)](https://github.com/eggzec/<Project Name>/actions/workflows/docs_build.yml)
[![Tests](https://github.com/eggzec/spinterp/actions/workflows/test.yml/badge.svg)](https://github.com/eggzec/spinterp/actions/workflows/test.yml)
[![Documentation](https://github.com/eggzec/spinterp/actions/workflows/docs.yml/badge.svg)](https://github.com/eggzec/spinterp/actions/workflows/docs.yml)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

[![codecov](https://codecov.io/github/eggzec/<Project Name>/graph/badge.svg)](https://codecov.io/github/eggzec/<Project Name>)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=eggzec_<Project Name>&metric=alert_status)](https://sonarcloud.io/project/overview?id=eggzec_<Project Name>)
[![codecov](https://codecov.io/github/eggzec/spinterp/graph/badge.svg)](https://codecov.io/github/eggzec/spinterp)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=eggzec_spinterp&metric=alert_status)](https://sonarcloud.io/project/overview?id=eggzec_spinterp)
[![License](https://img.shields.io/badge/license-GPL%203.0-blue.svg)](./LICENSE)

[![PyPI Downloads](https://img.shields.io/pypi/dm/<Project Name>.svg?label=PyPI%20downloads)](https://pypi.org/project/<Project Name>/)
[![Python versions](https://img.shields.io/pypi/pyversions/<Project Name>.svg)](https://pypi.org/project/<Project Name>/)
[![PyPI Downloads](https://img.shields.io/pypi/dm/spinterp.svg?label=PyPI%20downloads)](https://pypi.org/project/spinterp/)
[![Python versions](https://img.shields.io/pypi/pyversions/spinterp.svg)](https://pypi.org/project/spinterp/)

`<Project Description>`
Sparse Grid Interpolation Toolbox for Python.

## Grid types

| Grid type | Basis | Max depth |
|------------------|--------------------|-----------|
| Clenshaw-Curtis | Piecewise linear | 8 |
| Chebyshev | Polynomial (DCT) | 10 |
| Gauss-Patterson | Nested Gaussian | 6 |
| Maximum | Piecewise linear | 8 |
| NoBoundary | Piecewise linear | 8 |

## Routines

| Fortran subroutine | Python binding | Description |
|--------------------|-----------------|------------------------------------------------|
| `SPVALS` | `spvals` | Compute hierarchical surpluses |
| `SPINTERP` | `spinterp` | Evaluate interpolant (and gradient) at points |
| `SPQUAD` | `spquad` | Integrate interpolant over domain |
| `SPGRID` | `spgrid` | Return sparse grid node coordinates |
| `SPGETSEQ` | `spgetseq` | Generate multi-index level sequences |

## Quick example

```python
import <Project Name>
import spinterp

z = spinterp.spvals(lambda x, y, t: x**2 + y**2 - 2 * t, d=3)
f = spinterp.spinterp(z, 0.5, 0.2, 0.2)
q = spinterp.spquad(z)
```

## Installation

```bash
pip install <Project Name>
pip install spinterp
```

Requires Python 3.10+ and NumPy.

### Build from source

```bash
python bin/build.py install # build and install via uv
python bin/build.py wheel # produce a wheel in dist/
python bin/build.py clean # remove all build artifacts
```

Requires Python 3.10+ and NumPy. No external runtime dependencies. See the
[full installation guide](https://eggzec.github.io/<Project Name>/installation/) for
uv, poetry, and source builds.
Requires gfortran, Meson, and f2py (`numpy`).

## Documentation

- [Theory](https://eggzec.github.io/<Project Name>/theory/) — mathematical background, hierarchical basis, algorithms
- [Quickstart](https://eggzec.github.io/<Project Name>/quickstart/) — runnable examples
- [API Reference](https://eggzec.github.io/<Project Name>/api/) — class and function signature and arguments
- [References](https://eggzec.github.io/<Project Name>/references/) — literature citations
- [Theory](https://eggzec.github.io/spinterp/theory/) — hierarchical basis, Smolyak construction, algorithms
- [Quickstart](https://eggzec.github.io/spinterp/quickstart/) — runnable examples
- [API Reference](https://eggzec.github.io/spinterp/api/) — function signatures and arguments
- [References](https://eggzec.github.io/spinterp/references/) — literature citations

## License

Expand Down
16 changes: 12 additions & 4 deletions bin/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@

def run_command(command, cwd=None):
if cwd is None:
logger.warning("No working directory specified. Using current directory.")
logger.warning(
"No working directory specified. Using current directory."
)
cwd = Path.cwd()
else:
cwd = Path(cwd)
Expand Down Expand Up @@ -78,10 +80,16 @@ def wheel():
def clean():
logger.debug("Starting cleanup ...")

run_command("uv pip uninstall <Project Name>")
run_command("uv pip uninstall spinterp")

for entry in Path("").iterdir():
if entry.name in ["dist", "build", "lib", ".pytest_cache", ".ruff_cache"]:
if entry.name in [
"dist",
"build",
"lib",
".pytest_cache",
".ruff_cache",
]:
logger.info(f"Removing '{entry}'")
shutil.rmtree(entry)
if entry.name == "bin" and entry.is_dir():
Expand All @@ -103,7 +111,7 @@ def clean():


def main():
parser = argparse.ArgumentParser(description="<Project Name> Build Script")
parser = argparse.ArgumentParser(description="spinterp Build Script")
parser.add_argument(
"mode",
help="""Build mode:
Expand Down
Binary file added docs/_static/ex_firstexample_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/ex_firstexample_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/ex_linear_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/ex_performance_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/ex_plotgrid_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/ex_polynomial_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/ex_spderiv_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/ex_spderiv_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/ex_spderiv_03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/ex_spderiv_04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/timespderiv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/timespderiv_cheb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/timespderiv_cheb_abs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/timespderiv_cont.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion docs/api.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/assets/stylesheets/extra.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* spinterp documentation extra styles */
65 changes: 56 additions & 9 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,62 @@
# <Project Name>
# spinterp

**<Project Description>**
**Sparse Grid Interpolation Toolbox**

<Project Description>
`spinterp` is a high-performance toolkit for **multivariate interpolation, quadrature, and
gradient computation on sparse grids**. It supports five grid types — from piecewise-linear
Clenshaw-Curtis to polynomial Chebyshev and Gauss-Patterson grids — and scales to hundreds
of dimensions through hierarchical surpluses and dimension-adaptive refinement.

---

## Overview

## Documentation
Sparse grid methods overcome the *curse of dimensionality*: the exponential growth of grid
points in a full tensor-product discretisation. Using Smolyak's construction, one selects
only those grid points whose hierarchical surplus exceeds a tolerance, achieving accuracy
comparable to a full grid at a fraction of the cost — making interpolation, integration, and
optimisation in $d \gg 10$ dimensions practical.

The error of the sparse grid interpolant $A_{q,d}(f)$ satisfies

\[
\|f - A_{q,d}(f)\|_\infty = O\!\left(N^{-r}\,(\log N)^{(d-1)(r+1)}\right)
\]

where $N$ is the number of support nodes and $r$ depends on the smoothness of $f$ and the
chosen basis.

---

## Grid types

| Grid type | Basis | Max depth |
|---|---|---|
| **Clenshaw-Curtis** | Piecewise linear | 8 |
| **Chebyshev** | Polynomial (DCT) | 10 |
| **Gauss-Patterson** | Nested Gaussian | 6 |
| **Maximum** | Piecewise linear | 8 |
| **NoBoundary** | Piecewise linear | 8 |

---

## Core routines

| Function | Description |
|---|---|
| `spgetseq` | Generate multi-index level sequences |
| `spgrid_cc` / `spgrid_cb` / … | Sparse grid node coordinates per grid type |
| `spinterp_cc` / `spinterp_cb` / … | Evaluate the interpolant at query points |
| `spcmpvals_cc` / `spcmpvals_cb` / … | Compute hierarchical surpluses |
| `spderiv_cc` / `spderiv_cb` | Interpolant values and exact gradient vectors |
| `spquadw_cc` / `spquadw_cb` / … | Quadrature weight vectors for integration |

---

## Attribution

Original MATLAB toolbox by **W. Andreas Klimke**, Universität Stuttgart.

- [Theory](theory.md) - mathematical background, hierarchical basis, algorithms
- [Installation](installation.md) - installation guide
- [Quickstart](quickstart.md) - runnable examples
- [API Reference](api.md) - class and function signature and arguments
- [References](references.md) - literature citations
> Klimke, A., Wohlmuth, B. (2005).
> *Algorithm 847: spinterp — Piecewise Multilinear Hierarchical Sparse Grid Interpolation in MATLAB.*
> ACM Transactions on Mathematical Software, **31**(4), 561–579.
34 changes: 17 additions & 17 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# Installation

`<Project Name>` can be installed from PyPI or directly from source via GitHub.
`spinterp` can be installed from PyPI or directly from source via GitHub.

---

## [PyPI](https://pypi.org/project/<Project Name>)
## [PyPI](https://pypi.org/project/spinterp)

For using the PyPI package in your project, add it to your configuration file:

=== "pyproject.toml"

```toml
[project.dependencies]
<Project Name> = "*" # (1)!
spinterp = "*" # (1)!
```

1. Specifying a version is recommended

=== "requirements.txt"

```
<Project Name>>=0.1.0
spinterp>=0.1.0
```

### pip

=== "Installation for user"

```bash
pip install --upgrade --user <Project Name> # (1)!
pip install --upgrade --user spinterp # (1)!
```

1. You may need to use `pip3` instead of `pip` depending on your Python installation.
Expand All @@ -38,7 +38,7 @@ For using the PyPI package in your project, add it to your configuration file:
```bash
python -m venv .venv
source .venv/bin/activate
pip install --require-virtualenv --upgrade <Project Name> # (1)!
pip install --require-virtualenv --upgrade spinterp # (1)!
```

1. You may need to use `pip3` instead of `pip` depending on your Python installation.
Expand All @@ -52,59 +52,59 @@ For using the PyPI package in your project, add it to your configuration file:
=== "Adding to uv project"

```bash
uv add <Project Name>
uv add spinterp
uv sync
```

=== "Installing to uv environment"

```bash
uv venv
uv pip install <Project Name>
uv pip install spinterp
```

### pipenv

```bash
pipenv install <Project Name>
pipenv install spinterp
```

### poetry

```bash
poetry add <Project Name>
poetry add spinterp
```

### pdm

```bash
pdm add <Project Name>
pdm add spinterp
```

### hatch

```bash
hatch add <Project Name>
hatch add spinterp
```

---

## [GitHub](https://github.com/eggzec/<Project Name>)
## [GitHub](https://github.com/eggzec/spinterp)

Install the latest development version directly from the repository:

```bash
pip install --upgrade "git+https://github.com/eggzec/<Project Name>.git#egg=<Project Name>"
pip install --upgrade "git+https://github.com/eggzec/spinterp.git#egg=spinterp"
```

### Building locally

Clone and build from source if you want to modify or test local changes:

```bash
git clone https://github.com/eggzec/<Project Name>.git
cd <Project Name>
pip install -e .
git clone https://github.com/eggzec/spinterp.git
cd spinterp
python bin/build.py install
```

---
Loading
Loading