Metadata-Version: 2.4
Name: nrumpy
Version: 0.1.0
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Rust
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Typing :: Typed
Requires-Dist: numpy>=1.26
Requires-Dist: pytest>=8 ; extra == 'test'
Provides-Extra: test
Summary: Strassen matrix multiplication for NumPy arrays and nested lists
Keywords: matrix,linear-algebra,strassen,numpy
Author-email: Jayadithya Dhurwey <jayadithya.dhurwey@gmail.com>
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Documentation, https://github.com/jaysit-gif/rumpy/blob/main/DOCS.md
Project-URL: Homepage, https://github.com/jaysit-gif/rumpy
Project-URL: Repository, https://github.com/jaysit-gif/rumpy

# rumpy

`rumpy-core` multiplies row-major `f64` matrices with Strassen's algorithm.

Library documentation: [DOCS.md](DOCS.md).

## Algorithm

Strassen splits a square into four quadrants and forms seven products instead of eight:

```text
M1 = (A11 + A22) (B11 + B22)
M2 = (A21 + A22) B11
M3 = A11 (B12 - B22)
M4 = A22 (B21 - B11)
M5 = (A11 + A12) B22
M6 = (A21 - A11) (B11 + B12)
M7 = (A12 - A22) (B21 + B22)
```

The quadrants of the product are

```text
C11 = M1 + M4 - M5 + M7
C12 = M3 + M5
C21 = M2 + M4
C22 = M1 - M2 + M3 + M6
```

Each product uses the same recurrence until the side is at most `leaf_size`, then a cache-blocked triple loop. `leaf_size == 0` skips Strassen and uses the plain triple loop. `matmul_parallel` runs the seven products with `rayon::join` while the side is at least 256.

## Padding

The recursive step needs a square whose side is a power of two. `matmul` accepts any compatible shapes `m×k` and `k×n`. Let `s` be the next power of two of `max(m, k, n)`. Each input is copied into the top-left of an `s×s` matrix of zeros, those squares are multiplied, and the result is the top-left `m×n` block. The extra zeros do not change the product. A `5×7` times a `7×3` pads to `8×8` and crops back to `5×3`. A square that is already a power of two is copied as itself.

A zero side is not padded. `next_power_of_two(0)` is `1`, which would turn an empty product into a `1×1`, so a zero side uses the triple loop on the original shapes. `leaf_size == 0` takes that same path.

## Python

```python
from rumpy import matmul

matmul([[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]])
```

`matmul` accepts nested lists, tuples of rows, and 2-D NumPy arrays. A NumPy left-hand matrix returns a `float64` array. Any other left-hand matrix returns a nested list. `leaf_size` defaults to 64. `leaf_size=0` skips Strassen and uses the plain triple loop. Importing `rumpy` does not require the extension to be built.

`pyproject.toml` sets `extension-module`, so these commands from the repository root pass that feature through:

```bash
# editable install, debug
maturin develop

# editable install, release
maturin develop --release

# wheel, then install
maturin build --release
pip install target/wheels/rumpy-*.whl
```

`make dev`, `make test`, `make fmt`, and `make lint` run those steps from the repository root. `make dev` is `maturin develop --release`.

