Crate tenferro_ext_ndarray

Crate tenferro_ext_ndarray 

Source
Expand description

Bridge between ndarray arrays and tenferro tensors.

This crate provides typed canonical conversion helpers between generic ndarray::ArrayBase<S, D> inputs and [tenferro_tensor::Tensor<T>], plus export back to owned ndarray::ArrayD<T>. An optional frontend feature adds a convenience conversion into tenferro::Tensor.

The canonical bridge normalizes at the boundary:

  • ndarray -> tenferro_tensor::Tensor<T> first materializes a standard row-major ndarray layout, then converts into tenferro’s internal column-major canonical tensor layout
  • tenferro_tensor::Tensor<T> -> ndarray always materializes a standard row-major owned ndarray result

This keeps the interop contract simple and avoids exposing a separate zero-copy expert mode with layout-dependent reshape semantics.

§Examples

use ndarray::Array2;
use tenferro_ext_ndarray::{ndarray_to_tensor, tensor_to_ndarray};

let array = Array2::from_shape_vec((2, 2), vec![1.0_f64, 2.0, 3.0, 4.0]).unwrap();
let tensor = ndarray_to_tensor(array);
let roundtrip = tensor_to_ndarray(tensor);
assert_eq!(roundtrip.shape(), &[2, 2]);

Functions§

ndarray_to_tensor
Converts an owned ndarray array into a typed tenferro tensor, panicking on conversion failure.
tensor_to_ndarray
Converts a typed tenferro tensor into an owned ndarray array, panicking on conversion failure.
try_ndarray_to_tensor
Fallibly converts an ndarray array into a typed tenferro tensor.
try_tensor_to_ndarray
Fallibly converts a typed tenferro tensor into an owned ndarray array.