Crate tenferro_ext_mdarray

Crate tenferro_ext_mdarray 

Source
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_device::LogicalMemorySpace;
use tenferro_tensor::{MemoryOrder, Tensor};
use tenferro_ext_mdarray::{mdarray_to_tensor, tensor_to_mdarray};

// mdarray -> tenferro
let md: Array<f64, DynRank> = mdarray::tensor![1.0, 2.0, 3.0, 4.0].into_dyn();
let t: Tensor<f64> = mdarray_to_tensor(md);

// tenferro -> mdarray
let t2: Tensor<f64> = Tensor::zeros(
    &[2, 3],
    LogicalMemorySpace::MainMemory,
    MemoryOrder::ColumnMajor,
);
let md2: Array<f64, DynRank> = tensor_to_mdarray(t2);

Functions§

mdarray_to_tensor
Converts an mdarray Array<T, DynRank> into a tenferro Tensor<T>, panicking if conversion fails.
tensor_to_mdarray
Converts a tenferro Tensor<T> into an mdarray Array<T, DynRank>, panicking if conversion fails.
try_mdarray_to_tensor
Fallibly converts an mdarray Array<T, DynRank> into a tenferro Tensor<T>.
try_tensor_to_mdarray
Fallibly converts a tenferro Tensor<T> into an mdarray Array<T, DynRank>.