Skip to main content

Module array

Module array 

Source
Expand description

Opaque numeric storage for builders and frames (metatensor v0.2.x shape).

Design: internal data is DLPack-shaped (shape / dtype / device / as_dlpack(device, stream, max_version)), not “AoS structs with a DLPack export bolt-on.” Callers query storage dtype/device, then as_dlpack with a requested device (and stream / max version)—same contract as metatensor mts_array_t. Choosing f32 vs f64 is choosing storage (or a future typed builder), not passing a cast-target on every export.

ConFrame keeps row-major ArcArray blocks for positions and optional sections; atom_data is the CON-text AoS projection for the writer.

Implementors can swap dtypes (f32 / f64 / u64 / bool), devices (CPU / future GPU), and ownership (ArrayD, Arc<RwLock<...>>, …) without changing the public surface.

The default backing is Arc<RwLock<ndarray::ArrayD<T>>>

  • Arc : multiple DLPack views can share the same buffer across threads / FFI consumers.
  • RwLock : enforces aliasing soundness; concurrent reads are non-blocking, concurrent writes contend.
  • ndarray::ArrayD<T> : type-erased dimension, generic dtype, ndarray’s allocator (8-byte aligned, fine for f64; future SIMD-aligned variants implement this trait separately).

See docs/orgmode/spec.org §17 for the public contract.

Structs§

DeviceTaggedF64Array
Host-resident f64 buffer tagged with a DLPack device (CPU or non-CPU).

Traits§

Array
Storage hook for one per-atom field of a ConFrameBuilder.

Functions§

allocate_array_on_device
Allocate a new zeroed array on device.
array_from_host_f64_on_device
Install a device-tagged f64 array (caller-supplied buffer / logical device).
array_from_shape
Convenience constructor for the default backing.
from_dlpack_f64
Ingest from a DLPack tensor: preserve tensor.device() and copy f64 host elements when the tensor is CPU-addressable; for non-CPU tensors in this build we still preserve the device tag using host staging only when the tensor reports f64 data that is readable (host tests tag CUDA with host bytes). Pure allocate-on-GPU without a backend is allocate_array_on_device.