Skip to main content

array-api-signal

Signal processing primitives (windows, filters, integration) for the Python Array API Standard.

PyPI version License Pipeline Status

array-api-signal is a lightweight extension library that brings scientific computing capabilities—similar to scipy.signal and scipy.integrate—to the Python Array API ecosystem.

It allows you to write signal processing code that runs unmodified on NumPy, PyTorch, CuPy, JAX, and * Dask*.

Why?

The Python Array API Standard unifies basic array operations (sin, matmul, reshape), and array-api-extra provides common utilities (pad, kron).

However, scientific domains often need higher-level primitives like Simpson's rule integration, **window generation **, or smoothing filters. array-api-signal fills this gap, providing a single namespace that:

  1. Implements missing primitives (like xp.simpson) using backend-agnostic operations.
  2. Re-exports array-api-extra functions (like xp.pad).
  3. Dispatches standard API calls (like xp.sin) to the underlying backend.

This library is designed to be the "SciPy" companion to array-api-compat's "NumPy".

Installation

pip install array-api-signal

Quick Start: The Unified Namespace

The core philosophy is the Unified Namespace. You rarely need to import numpy or torch directly for your processing logic.

import array_api_signal as aps
import numpy as np
import torch

# 1. Start with any array (NumPy or Torch)
x_np = np.linspace(0, 10, 100)
x_torch = torch.linspace(0, 10, 100, device='cuda')

# 2. Get the unified 'xp' namespace
# This object has EVERYTHING: standard API + signal extensions + extra utils
xp = aps.array_namespace(x_torch)

# 3. Write backend-agnostic code
y = xp.sin(x_torch)                # Calls torch.sin (Standard API)
y = xp.pad(y, (2, 2))              # Calls array_api_extra.pad (Extra API)
area = xp.simpson(y, dx=0.1)       # Calls array_api_signal.simpson (Signal API)

print(f"Area on GPU: {area}")      # Returns a Torch tensor

API Reference

1. Integration (xp.integrate)

Robust numerical integration with support for native backend optimizations (e.g., torch.trapezoid).

  • xp.trapezoid(y, x=None, dx=1.0, axis=-1): Composite trapezoidal rule.
  • xp.simpson(y, x=None, dx=1.0, axis=-1): Composite Simpson's rule. Matches scipy.integrate.simpson behavior (using the trapezoidal rule for the last interval if samples are even).

2. Signal Processing (xp.signal)

Filtering and convolution tools. Dispatches to scipy.ndimage (NumPy) or torch.nn.functional (Torch) for maximum performance.

  • xp.gaussian_filter1d(input, sigma, ...): 1D Gaussian smoothing.
  • xp.convolve(in1, in2, mode='full'): General 1D convolution (via FFT).

3. Window Functions (xp.windows)

Backend-agnostic window generation. If you use the unified xp object, these functions automatically return arrays on the correct backend.

  • xp.hann(M, sym=True): Hann window.
  • xp.hamming(M, sym=True): Hamming window.
  • xp.tukey(M, alpha=0.5, sym=True): Tukey (tapered cosine) window.

4. Special Functions (xp.special)

Backend-native special functions the Array API standard omits.

  • xp.i0e(x): Exponentially scaled modified Bessel function I_0(x) * exp(-|x|).
  • xp.ndtr(x): Standard normal CDF Phi(x).
  • xp.logsumexp(x, axis=None, keepdims=False): Overflow-safe log(sum(exp(x))).
  • xp.interp(x, x_ref, f_ref): Edge-clamped 1-D linear interpolation (matches numpy.interp, including infinite f_ref values).

Backend support: logsumexp and interp have portable fallbacks and work on every backend. i0e and ndtr dispatch to scipy.special (NumPy) or torch (PyTorch); they have no portable Array API formulation, so on other backends (JAX, CuPy, Dask) they raise NotImplementedError.

5. Extensions from array-api-extra

We re-export widely used extensions so you only need one import.

  • xp.pad
  • xp.sinc
  • xp.cov
  • xp.kron

Contributing

We welcome contributions! If you have implemented a scipy function (like a specific filter, window, or transform) using only standard Array API primitives, please submit a PR.

Running Tests

We use pytest to verify correctness against scipy (Gold Standard) across all installed backends.

# Run tests
pytest tests/

# Test specific backend
pytest tests/ --backend=torch

Metadata

Release files for array-api-signal 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for array-api-signal 0.2.0
File Size Uploaded
array_api_signal-0.2.0.tar.gz 32.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for array-api-signal 0.2.0
File Interpreter ABI Platform
array_api_signal-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 55.0 kB

Release files / array_api_signal-0.2.0.tar.gz

Download URL array_api_signal-0.2.0.tar.gz
Size 32.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a5e728f5487749f2f13e91fc650fc20a12461900055b349366ba4ccf9927c6c3
BLAKE2b-256 checksum
How to use checksums
037315c23c59fd478fa123901134e7ba476782e00ed44afc0c4a3dae43b9a0be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / array_api_signal-0.2.0-py3-none-any.whl

Download URL array_api_signal-0.2.0-py3-none-any.whl
Size 22.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bbadd5126d5951a859ffd44ef58d65330f96f9b1999986d464f4031250a80e5f
BLAKE2b-256 checksum
How to use checksums
26f21a9164b11b35e28f4f3971b48891a8f446b78a8fe7bd94983aacb698ce07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page