Metadata-Version: 2.4
Name: uiuapy
Version: 0.2.0
Summary: Use the Uiua array programming language from Python
Project-URL: Homepage, https://github.com/bergkvist/uiuapy
Project-URL: Repository, https://github.com/bergkvist/uiuapy
Keywords: uiuapy,uiua,apl,J,kdb,numpy,pyo3,array,programming,language,vectorized
Classifier: Development Status :: 4 - Beta
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: MacOS
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.9
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 :: Python :: Implementation :: CPython
Classifier: License :: OSI Approved :: MIT License
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Compilers
Classifier: Topic :: Software Development :: Interpreters
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Financial and Insurance Industry
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.21.0
Dynamic: license-file

# UiuaPy

A bridge between [Uiua](https://www.uiua.org/) and [NumPy](https://numpy.org/) - enabling you to do tacit array processing in Python.

## Installation
```sh
pip install uiuapy
```

If building the source distribution, rather than installing a precompiled wheel, you will need to have [rustup](https://rustup.rs/) installed on your machine.

## Usage
```py
import uiua

print(uiua.compile('/+')([1, 2, 3]))
# 6.0

print(uiua.compile('⌕')('ab', 'abracabra')) 
# [1 0 0 0 0 1 0 0 0]
```

### Flags
You can allow thread spawning either specific to a program, or specific to an invocation. Invocation flags take precedence over program flags.
```py
import numpy as np
import uiua

xs = np.linspace(0, 1, 10_000)

print(uiua.compile('/+', allow_threads=True)(xs))
# 50000.0

print(uiua.compile('/+')(xs, allow_threads=True))
# 50000.0

```

## NumPy integration
UiuaPy uses the [NumPy C-API](https://numpy.org/doc/2.1/reference/c-api/index.html) for taking in Python inputs and returning Python results.

Uiua supports 5 data-types for arrays/scalars:

|Uiua type|NumPy equivalent dtype|
|---------|----------------------|
|Num|float64|
|Byte|uint8|
|Complex|complex128|
|Char|Unicode (32-bit characters)|
|Box|object|

If you pass in a NumPy array that does not have one of the above dtypes, it will be automatically converted according to the table below:
|NumPy dtype|Converted NumPy dtype|Uiua type|
|-|-|-|
|float32|float64|Num|
|uint64|float64|Num|
|uint32|float64|Num|
|uint16|float64|Num|
|int64|float64|Num|
|int32|float64|Num|
|int16|float64|Num|
|bool|uint8|Byte|

#### Interfacing overhead
Passing a numpy array to uiua requires copying its memory (using `memcpy`/ [`std::ptr::copy_nonoverlapping`](https://doc.rust-lang.org/beta/std/ptr/fn.copy_nonoverlapping.html) in Rust). The same is true for the values returned from the Uiua computation.

If using anything other than float64, uint8, complex128 or unicode data - there are also type conversion costs to take into account.

## Development

### Dependencies
- [rustup](https://rustup.rs/)
- [uv](https://docs.astral.sh/uv/getting-started/installation/)

```sh
# Format code
uv run ruff format
cargo fmt

# Fix/report lints
uv run ruff check --fix
cargo clippy

# Run tests
uv run pytest

# Build wheels
uv build
```
