tenferro_mdarray/lib.rs
1//! Bridge between [mdarray](https://docs.rs/mdarray) multidimensional arrays
2//! and [tenferro](https://docs.rs/tenferro-tensor) tensors.
3//!
4//! This crate provides conversion functions between mdarray's
5//! `Array<T, DynRank>` and tenferro's `Tensor<T>`, enabling convenient data
6//! exchange between the two ecosystems.
7//!
8//! Due to Rust's orphan rules, [`From`]/[`Into`] trait impls cannot be provided
9//! for two external types. Instead, use the standalone conversion functions
10//! [`mdarray_to_tensor`] and [`tensor_to_mdarray`].
11//!
12//! **Zero-copy is a non-goal.** Both conversion directions copy element data.
13//! The purpose of this crate is ergonomic interoperability, not performance-
14//! critical data sharing.
15//!
16//! # Examples
17//!
18//! ```ignore
19//! use mdarray::{Array, DynRank};
20//! use tenferro_tensor::Tensor;
21//! use tenferro_mdarray::{mdarray_to_tensor, tensor_to_mdarray};
22//!
23//! // mdarray -> tenferro
24//! let md: Array<f64, DynRank> = mdarray::tensor![1.0, 2.0, 3.0, 4.0];
25//! let t: Tensor<f64> = mdarray_to_tensor(md);
26//!
27//! // tenferro -> mdarray
28//! let t2: Tensor<f64> = Tensor::zeros(&[2, 3]);
29//! let md2: Array<f64, DynRank> = tensor_to_mdarray(t2);
30//! ```
31
32use mdarray::{Array, DynRank};
33use tenferro_algebra::Scalar;
34use tenferro_tensor::Tensor;
35
36/// Converts an mdarray `Array<T, DynRank>` into a tenferro `Tensor<T>`.
37///
38/// This conversion copies all element data from the mdarray array into a
39/// newly allocated tenferro tensor on the CPU. The shape is preserved.
40///
41/// # Examples
42///
43/// ```ignore
44/// use mdarray::{Array, DynRank};
45/// use tenferro_tensor::Tensor;
46/// use tenferro_mdarray::mdarray_to_tensor;
47///
48/// let md: Array<f64, DynRank> = mdarray::tensor![1.0, 2.0, 3.0];
49/// let t: Tensor<f64> = mdarray_to_tensor(md);
50/// ```
51pub fn mdarray_to_tensor<T: Scalar>(_array: Array<T, DynRank>) -> Tensor<T> {
52 todo!()
53}
54
55/// Converts a tenferro `Tensor<T>` into an mdarray `Array<T, DynRank>`.
56///
57/// This conversion copies all element data from the tenferro tensor into a
58/// newly allocated mdarray array. The shape is preserved.
59///
60/// # Examples
61///
62/// ```ignore
63/// use mdarray::{Array, DynRank};
64/// use tenferro_tensor::Tensor;
65/// use tenferro_mdarray::tensor_to_mdarray;
66///
67/// let t: Tensor<f64> = Tensor::zeros(&[3, 4]);
68/// let md: Array<f64, DynRank> = tensor_to_mdarray(t);
69/// ```
70pub fn tensor_to_mdarray<T: Scalar>(_tensor: Tensor<T>) -> Array<T, DynRank> {
71 todo!()
72}