Metadata-Version: 2.4
Name: rustymath
Version: 0.1.34
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Requires-Dist: fastship>=0.0.11 ; extra == 'dev'
Requires-Dist: fastws-cli>=0.0.26 ; extra == 'dev'
Requires-Dist: maturin>=1.0,<2.0 ; extra == 'dev'
Requires-Dist: pytest ; extra == 'dev'
Requires-Dist: nbdev ; extra == 'dev'
Requires-Dist: numpy ; extra == 'dev'
Requires-Dist: scipy ; extra == 'dev'
Provides-Extra: dev
License-File: LICENSE
Summary: Maths in plain Rust, from fast f16, f32 and f64 functions to exact rationals.
Author-email: Jeremy Howard <github@jhoward.fastmail.fm>
License: Apache-2.0
Requires-Python: >=3.11
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Documentation, https://answerdotai.github.io/rustymath
Project-URL: Homepage, https://github.com/AnswerDotAI/rustymath
Project-URL: Issues, https://github.com/AnswerDotAI/rustymath/issues
Project-URL: Repository, https://github.com/AnswerDotAI/rustymath

# rustymath


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

Rustymath provides fast elementary and special functions, statistics, searching and sorting, random sampling, linear algebra, optimization, polynomials and exact arithmetic in Rust and Python. It is the numerical core of [BasedPL](https://answerdotai.github.io/basedpl/).

The Python package needs no NumPy. Its eager operations use the same broadcasting, selection and tolerant-comparison rules as the shared Rust core. For richer array notation, operators and fusion, use BasedPL.

Elementary float functions target four units in the last place (ulps). Rustymath prioritizes speed over last-bit agreement and reproducibility.

## Install

``` sh
pip install rustymath
```

Rust users can add the crate to `Cargo.toml`. See [Using rustymath from Rust](https://answerdotai.github.io/rustymath/rust.html) for scalar and slice forms, build settings, accuracy and speed.

``` python
import rustymath as rm
```

## Arrays and indexing

Functions take Python numbers, nested lists, rustymath arrays or buffer exporters such as NumPy arrays. Broadcasting aligns leading axes. A two-item vector adds one value to each row of this matrix:

``` python
rm.add([[1, 2, 3], [4, 5, 6]], [10, 20])
```

    Array([[11, 12, 13], [24, 25, 26]], dtype=int64)

[Arrays and indexing](https://answerdotai.github.io/rustymath/arrays.html) covers construction, dtypes, selection, reshaping, axis names, keys and interoperability.

## Maths and statistics

Real and complex functions operate on whole arrays. Float comparisons use a relative tolerance by default:

``` python
rm.exp([0., 1, 2]), rm.equal(0.1 + 0.2, 0.3)
```

    (Array([1.0, 2.7182818, 7.3890561], dtype=float64), True)

[Maths and statistics](https://answerdotai.github.io/rustymath/math.html) covers elementary and special functions, reductions, scans, statistics and tolerant comparison.

## Searching, sorting and selection

`unique` retains first-occurrence order and reports each value’s position, class number and count:

``` python
rm.unique([3, 1, 3, 2])
```

    Unique(values=Array([3, 1, 2], dtype=int64), firsts=Array([0, 1, 3], dtype=int64), numbers=Array([0, 1, 0, 2], dtype=int64), counts=Array([2, 1, 1], dtype=int64))

[Searching, sorting and selection](https://answerdotai.github.io/rustymath/search.html) distinguishes tolerant matching from exact ordering.

## Random numbers and distributions

Distributions provide density, cumulative probability, quantiles and seeded sampling:

``` python
normal = rm.distribution.normal()
normal.cdf([-1.96, 0, 1.96]), normal.sample(3, seed=0)
```

    (Array([0.024997895, 0.5, 0.9750021], dtype=float64),
     Array([0.11623959, -0.78285485, -2.3346353], dtype=float64))

[Random numbers and distributions](https://answerdotai.github.io/rustymath/random.html) covers sampling and probability functions.

## Linear algebra

Solve real or complex systems, including least-norm solutions for singular or non-square matrices:

``` python
rm.linalg.solve([[4., 1], [1, 3]], [1., 2])
```

    Array([0.090909091, 0.63636364], dtype=float64)

[Linear algebra](https://answerdotai.github.io/rustymath/linalg.html) covers matrix products, reusable factorizations, decompositions and least squares.

## Optimization and iterative solves

Minimize functions, fit residuals or find roots. Here Brent’s method finds where cos x = x:

``` python
rm.optimize.root_scalar(lambda x: rm.cos(x) - x, [0, 1]).root
```

    0.7390851350713886

[Optimization and iterative solves](https://answerdotai.github.io/rustymath/optimize.html) also covers matrix-free linear systems.

## Polynomials, exact arithmetic and number theory

Polynomial coefficients start from the constant term. Number-theory functions accept Python integers of any size:

``` python
rm.polynomial.polyroots([-6, 11, -6, 1]), rm.number_theory.factor(2**64 + 1)
```

    (Array([(1+0j), (2-0j), (3+0j)], dtype=complex128),
     [(274177, 1), (67280421310721, 1)])

[Polynomials, exact arithmetic and number theory](https://answerdotai.github.io/rustymath/exact.html) includes rational matrix solves and calculations with [`fractions.Fraction`](https://docs.python.org/3/library/fractions.html#fractions.Fraction).

## Accuracy and speed

The Rust page’s [Accuracy and speed](https://answerdotai.github.io/rustymath/rust.html#accuracy-and-speed) section compares each function’s speed with Rust’s standard library. It also explains how the 4-ulp bound holds for `f16`, with and without fused multiply-add, and for `pow` and `root`.

## Licence

Apache-2.0. Some algorithms and constants come from SLEEF and Arm Optimized Routines. `THIRD-PARTY.md` has their notices.

