Skip to main content

arraybridge

ArrayBridge provides explicit conversion and shared lifecycle utilities for NumPy, CuPy, PyTorch, TensorFlow, JAX, and pyclesperanto arrays.

Core dependencies are NumPy and metaclass-registry. Other frameworks are optional.

Quick start

import numpy as np

from arraybridge import convert_memory, detect_memory_type

value = np.arange(6).reshape(2, 3)
assert detect_memory_type(value) == "numpy"

copy = convert_memory(
    value,
    source_type="numpy",
    target_type="numpy",
    gpu_id=0,
)

convert_memory requires the declared source type, target type, and device id. The source and target MemoryType declarations perform conversion directly. The device id is required even for CPU conversions so call sites have one stable signature. A GPU target must declare that identifier as available; ArrayBridge does not silently place the value on the CPU.

Declarative decorators

from arraybridge import numpy

@numpy
def normalize(image):
    return image / max(float(image.max()), 1.0)

The framework decorators attach input_memory_type, output_memory_type, and execution_memory_type metadata, provide dtype/slice runtime parameters, and add framework-specific stream/OOM handling where supported. They do not convert inputs or outputs between frameworks and do not accept a gpu_id argument. A host runtime must call convert_memory at the boundary it plans and scope execution using the execution declaration.

Stack utilities

import numpy as np

from arraybridge import stack_slices, unstack_slices

slices = [np.zeros((8, 8)), np.ones((8, 8))]
stack = stack_slices(slices, memory_type="numpy", gpu_id=0)
restored = unstack_slices(stack, memory_type="numpy", gpu_id=0)

stack_slices requires non-empty 2D inputs. unstack_slices requires a 3D array. Both validate shape and use explicit target memory/device declarations.

Installation

pip install arraybridge
pip install "arraybridge[torch]"
pip install "arraybridge[cupy]"

Documentation: https://arraybridge.readthedocs.io

Native array geometry

MemoryType.reshape(array, shape) and MemoryType.broadcast_to(array, shape) operate in the array's framework and device. MemoryType.ones_like(reference, shape=..., dtype=...) allocates on the reference's device; omitting shape retains its shape. Reshape and broadcast preserve views where the backend can represent them. Broadcasting is not a promise of a writable, independent buffer.

These operations never silently project pixels to NumPy. Pyclesperanto cannot provide native changed-shape reshape or broadcasting, so those requests raise NotImplementedError. Its native ones allocation supports one to three dimensions and its supported integer/float32 dtypes; boolean allocation is explicitly unsupported. Existing conversion and disk boundaries remain separate.

Metadata

Release files for arraybridge 0.3.8

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

Source distribution (sdist)

Source distribution for arraybridge 0.3.8
File Size Uploaded
arraybridge-0.3.8.tar.gz 103.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for arraybridge 0.3.8
File Interpreter ABI Platform
arraybridge-0.3.8-py3-none-any.whl Python 3 none any Details

Total release size: 139.8 kB

Release files / arraybridge-0.3.8.tar.gz

Download URL arraybridge-0.3.8.tar.gz
Size 103.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9ab7f1efbfb764267a950341500e3bcdd7f501e5e15e9d21d8672166fd117e4c
BLAKE2b-256 checksum
How to use checksums
80f24f729e772f40e2a1cfc3fe33615249e45d14a51067fc43649a16a66c3af3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / arraybridge-0.3.8-py3-none-any.whl

Download URL arraybridge-0.3.8-py3-none-any.whl
Size 36.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a97f2f03780cf68173cb509b8e5fa6aa391cb283199b97393e5e0d9875d99bc1
BLAKE2b-256 checksum
How to use checksums
eb3dcd4f2b5c4b66dce3e85c80c9c5890e610ae3a88c968282a3ae39109200bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

This release

0.3.8 This release

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.0

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