Arrays¶
tinax.arrays owns NumPy, JAX, DLPack, host materialization, and logical array inspection. Its conversion functions make copying and ownership explicit.
See the Array Ownership guide for task-oriented usage.
from_numpy
¶
Create a JAX array from a NumPy array with explicit copy and placement policy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
Source NumPy array to convert. |
required |
copy
|
bool
|
If |
required |
device
|
Device | Sharding | None
|
Device or sharding to place the result on. |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
A JAX array holding the converted data, placed according to |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
from_dlpack
¶
from_dlpack(
array: object,
*,
copy: bool | None = None,
device: Device | Sharding | None = None,
) -> Array
Import a DLPack provider, completing copy=True before returning independent storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
object
|
Object exposing the DLPack protocol to import. |
required |
copy
|
bool | None
|
Copy policy. |
None
|
device
|
Device | Sharding | None
|
Device or sharding for the imported array. |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
A JAX array backed by the imported buffer. When |
Array
|
storage is guaranteed independent, including for same-device JAX providers. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
to_numpy
¶
Synchronize a fully addressable JAX array and return a writable copy or read-only host value.
Blocks until the array is ready, then materializes its data on the host.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
Array
|
Fully addressable JAX array to materialize on the host. |
required |
writable
|
bool
|
If |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The array's data as a |
ndarray
|
copies; read-only results are a synchronized host view. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
inspect_array
¶
inspect_array(array: Array) -> ArrayInfo
Inspect logical metadata without synchronizing or materializing array data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
Array
|
JAX array to inspect. Its data is never copied to the host. |
required |
Returns:
| Type | Description |
|---|---|
ArrayInfo
|
An |
ArrayInfo
|
commitment, and addressability. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ArrayInfo
dataclass
¶
ArrayInfo(
shape: tuple[int, ...],
dtype: object,
logical_nbytes: int | None,
committed: bool,
fully_addressable: bool,
)
Immutable logical metadata whose byte count is nominal rather than allocator memory.
Attributes:
| Name | Type | Description |
|---|---|---|
shape |
tuple[int, ...]
|
Logical shape of the array. |
dtype |
object
|
Array dtype. Extended dtypes report |
logical_nbytes |
int | None
|
Logical size in bytes, or |
committed |
bool
|
Whether the array is committed to a specific device. |
fully_addressable |
bool
|
Whether every shard is addressable by the current process. |