Expand description
Bridge between mdarray multidimensional arrays and tenferro tensors.
This crate provides conversion functions between mdarray’s
Array<T, DynRank> and tenferro’s Tensor<T>, enabling convenient data
exchange between the two ecosystems.
Due to Rust’s orphan rules, From/Into trait impls cannot be provided
for two external types. Instead, use the standalone conversion functions
mdarray_to_tensor and tensor_to_mdarray.
Zero-copy is a non-goal. Both conversion directions copy element data. The purpose of this crate is ergonomic interoperability, not performance- critical data sharing.
§Examples
ⓘ
use mdarray::{Array, DynRank};
use tenferro_tensor::Tensor;
use tenferro_mdarray::{mdarray_to_tensor, tensor_to_mdarray};
// mdarray -> tenferro
let md: Array<f64, DynRank> = mdarray::tensor![1.0, 2.0, 3.0, 4.0];
let t: Tensor<f64> = mdarray_to_tensor(md);
// tenferro -> mdarray
let t2: Tensor<f64> = Tensor::zeros(&[2, 3]);
let md2: Array<f64, DynRank> = tensor_to_mdarray(t2);Functions§
- mdarray_
to_ tensor - Converts an mdarray
Array<T, DynRank>into a tenferroTensor<T>. - tensor_
to_ mdarray - Converts a tenferro
Tensor<T>into an mdarrayArray<T, DynRank>.