Skip to main content

matten_ndarray/
lib.rs

1//! `matten-ndarray` — a conversion bridge between [`matten::Tensor`] and
2//! [`ndarray::ArrayD<f64>`].
3//!
4//! This is a deliberately *boring* companion crate (RFC-025, RFC-027): it
5//! converts between the two owned representations and does nothing else. It adds
6//! no dependency to core `matten`, wraps none of the `ndarray` API, and exposes
7//! no view or lifetime types.
8//!
9//! ```
10//! use matten::Tensor;
11//! use matten_ndarray::{from_arrayd, to_arrayd};
12//!
13//! let t = Tensor::new(vec![1.0, 2.0, 3.0, 4.0], &[2, 2]);
14//! let arr = to_arrayd(&t).unwrap();
15//! let back = from_arrayd(arr).unwrap();
16//! assert_eq!(back.as_slice(), t.as_slice());
17//! ```
18//!
19//! # Status
20//!
21//! **Production-ready candidate.** The API is stable for the `0.19` family.
22//! Supported `ndarray`: the `0.16` minor.
23//!
24//! # Behavior
25//!
26//! - Both conversions **copy**; no zero-copy is claimed.
27//! - [`from_arrayd`] preserves *logical* element order even for non-standard
28//!   (transposed / sliced) `ArrayD` inputs.
29//! - [`from_arrayd`] rejects shapes with a zero-length axis ([`matten`] forbids
30//!   zero-sized dimensions).
31//! - A dynamic tensor passed to [`to_arrayd`] always returns
32//!   [`MattenNdarrayError::DynamicTensor`] — this guard is unconditional and
33//!   does not depend on the companion `dynamic` feature (RFC-031).
34//!
35//! # Feature flags
36//!
37//! - `dynamic` — Compatibility forwarding feature. No longer required for
38//!   dynamic rejection as of v0.19.1. Dynamic tensors are rejected at companion
39//!   boundaries regardless of whether this feature is enabled. Reconsider
40//!   removal no earlier than v0.20.0.
41
42#![forbid(unsafe_code)]
43
44mod convert;
45mod error;
46
47pub use crate::convert::{from_arrayd, to_arrayd};
48pub use crate::error::MattenNdarrayError;