Skip to main content

Iterator-style transformations for numeric arrays, similar to itertools but for array.array

Project description

arraystream

Iterator-style transformations for numeric arrays, similar to itertools but optimized for array.array and buffer-protocol objects.

Overview

arraystream provides composable, allocation-aware transformations for numeric arrays, complementing arrayops which focuses on fast, Rust-backed numeric kernels.

Mental model: itertools, but for numeric arrays and memory buffers.

Where arrayops provides the execution engine (numeric kernels), arraystream provides the transformation language (structural & stream transforms).

Features

  • Operate on array.array and buffer-protocol objects
  • Favor zero-copy views where possible
  • Avoid Python scalar iteration
  • Small, predictable, and fast
  • Composes naturally with arrayops
  • No dependency on NumPy or Pandas

Installation

pip install arraystream

For development:

git clone https://github.com/eddiethedean/arraystream
cd arraystream
pip install -r requirements-dev.txt
maturin develop

Quick Start

import array
from arraystream import windowed, scan, diff

# Create an array
data = array.array('i', [1, 2, 3, 4, 5, 6, 7, 8])

# Sliding windows
for window in windowed(data, size=3):
    print(list(window))  # [1, 2, 3], [2, 3, 4], ...

# Differences between consecutive elements
diffs = diff(data)
print(list(diffs))  # [1, 1, 1, 1, 1, 1, 1]

# Prefix sum (scan)
prefix_sums = scan(data, op="sum")
print(list(prefix_sums))  # [1, 3, 6, 10, 15, 21, 28, 36]

Relationship to arrayops

arrayops arraystream
Numeric kernels Structural & stream transforms
In-place math Shape-changing operations
Minimal API Rich combinators
Low-level Expressive

arrayops acts as the execution engine
arraystream acts as the transformation language

API Categories

Structural Transforms

Operations that rearrange or expose structure without computing new values:

  • chunked(arr, size) - Return views of chunks
  • windowed(arr, size, step=1) - Sliding windows
  • take(arr, n) - First n elements (view)
  • drop(arr, n) - Skip first n elements (view)
  • interleave(a, b) - Interleave two arrays
  • repeat_each(arr, n) - Repeat each element n times

Numeric Stream Operations

Operations that compute new values:

  • scan(arr, op="sum") - Prefix reduce
  • diff(arr) - Differences between consecutive elements
  • pairwise(arr) - Return pairs of consecutive elements
  • clip(arr, min, max) - Clip values to range

Boolean & Index Operations

  • where(arr, predicate) - Filter elements by predicate
  • argwhere(arr) - Return indices where condition is true
  • mask(arr, mask_array) - Apply boolean mask

Grouping & Segmentation

  • run_length_encode(arr) - Run-length encoding
  • groupby_runs(arr) - Group consecutive equal elements
  • segment_by(arr, boundaries) - Split at boundary indices

Supported Types

Supports the same 10 typecodes as arrayops:

  • b - signed char
  • B - unsigned char
  • h - signed short
  • H - unsigned short
  • i - signed int
  • I - unsigned int
  • l - signed long
  • L - unsigned long
  • f - float
  • d - double

Performance

  • Structural operations: Python + buffer protocol (zero-copy views)
  • Numeric transforms: Rust (PyO3) for performance
  • Zero-copy wherever semantics allow
  • Explicit copies when safety or clarity requires them

Use Cases

  • Streaming numeric pipelines
  • Signal processing
  • Sensor data preprocessing
  • Embedded or constrained environments
  • ETL micro-kernels
  • Teaching numeric programming without NumPy

Development

# Run tests
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=arraystream --cov-report=html

# Format code
ruff format .

# Lint code
ruff check .

# Type checking
mypy arraystream tests

License

MIT License - see LICENSE file for details.

Acknowledgments

  • Built with PyO3 for Python-Rust interop
  • Built with maturin for packaging
  • Complements arrayops

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arraystream-0.1.0.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arraystream-0.1.0-cp38-cp38-macosx_11_0_arm64.whl (247.6 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

Details for the file arraystream-0.1.0.tar.gz.

File metadata

  • Download URL: arraystream-0.1.0.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for arraystream-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e0318489dee852412302099ff63656c54bd635fd2df7a56e282f3787d0e89dd8
MD5 45875be21bca06de5f9d2ed7a8a5f84d
BLAKE2b-256 7132cf9dd824c4831e3df3481908b1c37060073aca7026bb476bff6d1a16167a

See more details on using hashes here.

File details

Details for the file arraystream-0.1.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for arraystream-0.1.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 abb2c03890773ba746f285eab90c84ada44efbb3cf122cab199fc82ddb857b1b
MD5 3f9120ca8ef0c8b82c6da1ed0075e92d
BLAKE2b-256 42dcf95d04702594f5da83e95f0c6e082261423533a4f69b6cc80ee46c83dc45

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page