pub trait Array:
Any
+ Send
+ Sync {
// Required methods
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
fn shape(&self) -> Vec<usize>;
fn dtype(&self) -> DLDataType;
fn device(&self) -> DLDevice;
fn as_dlpack(
&self,
device: DLDevice,
stream: Option<i64>,
max_version: DLPackVersion,
) -> Result<DLPackTensor, ParseError>;
fn copy(&self) -> Box<dyn Array>;
}Expand description
Storage hook for one per-atom field of a ConFrameBuilder.
Implementors hold the raw bytes for a single field (e.g. all atom
positions as a (N, 3) f64 block) and expose them via DLPack so
downstream consumers can map a numpy / Eigen / torch view onto
the same memory zero-copy.
Required Methods§
Sourcefn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
&mut dyn Any access for downcast.
Sourcefn dtype(&self) -> DLDataType
fn dtype(&self) -> DLDataType
DLPack dtype of the elements.
Sourcefn as_dlpack(
&self,
device: DLDevice,
stream: Option<i64>,
max_version: DLPackVersion,
) -> Result<DLPackTensor, ParseError>
fn as_dlpack( &self, device: DLDevice, stream: Option<i64>, max_version: DLPackVersion, ) -> Result<DLPackTensor, ParseError>
Export a DLPack-managed tensor view of this array.
device requests the consumer’s preferred device; CPU
implementors return Err(ParseError::ValidationError(...))
when asked for a non-CPU device they cannot service.
stream is the consumer’s stream (CUDA / ROCm / SYCL); CPU
backings ignore it.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<T> Array for Arc<RwLock<ArrayD<T>>>
Default Rust backing for the Array trait: shared, lockable,
dynamic-rank ndarray. Matches metatensor v2’s
Arc<RwLock<ArrayD<T>>> choice and inherits its DLPack +
concurrency semantics.
impl<T> Array for Arc<RwLock<ArrayD<T>>>
Default Rust backing for the Array trait: shared, lockable,
dynamic-rank ndarray. Matches metatensor v2’s
Arc<RwLock<ArrayD<T>>> choice and inherits its DLPack +
concurrency semantics.
as_dlpack shares the buffer and holds a read lock until the tensor is
deleted: other exports and reads proceed, try_write fails and write
blocks meanwhile. A write on a thread that still holds a live tensor
therefore never returns. Once a writer is waiting, std’s RwLock lets no
new reader in, so as_dlpack returns an error until that writer is done.
Delete each tensor exactly once: the deleter frees the tensor, so a second
call is a use-after-free. Like dlpk’s own lock-holding tensors, a tensor
handed through C must be deleted on a thread where releasing a std
RwLock read lock is allowed; std’s futex and queue locks allow any
thread.