Skip to main content

matten_ndarray/
lib.rs

1//! `matten-ndarray` — an experimental conversion bridge between
2//! [`matten::Tensor`] and [`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//! **Experimental (0.1.x).** The API may change. Pin the version if you depend
22//! on it. 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//! - With the `dynamic` feature, a dynamic tensor passed to [`to_arrayd`]
32//!   returns [`MattenNdarrayError::DynamicTensor`] instead of panicking.
33
34#![forbid(unsafe_code)]
35
36mod convert;
37mod error;
38
39pub use crate::convert::{from_arrayd, to_arrayd};
40pub use crate::error::MattenNdarrayError;