matten-ndarray
Production-ready (
0.29.xfamily). A small conversion bridge betweenmatten::Tensorandndarray::ArrayD<f64>. The scope is closed and the API is stable; still pre-1.0, so pin the minor version.
Part of the matten workspace — see it for the full family.
Overview
matten-ndarray converts between matten's numeric Tensor and ndarray's
dynamic-dimension ArrayD<f64>, and nothing else. It is the first companion
crate in the matten workspace and exists to let you hand data off to the
ndarray ecosystem when you outgrow matten's family-car scope.
It adds no dependency to core matten, wraps none of the ndarray API, and
exposes no view or lifetime types.
Quick start
use Tensor;
use ;
let t = new;
let arr = to_arrayd?; // Tensor -> ArrayD<f64>
let back = from_arrayd?; // ArrayD<f64> -> Tensor
# Ok::
Dependency style. This crate depends on
matten, but official examples importTensor(and other core types) frommattendirectly:use Tensor; use to_arrayd;This keeps ownership and feature selection clear:
Tensorbelongs tomatten, and core features (e.g.dynamic) are enabled on themattendependency. Declare bothmattenand this crate in yourCargo.toml(RFC-032).
Design notes
- Both directions copy. No zero-copy is claimed; that would need layout guarantees out of scope for a copy-based bridge.
- Logical order is preserved.
from_arraydconverts a non-standard-layoutArrayD(transposed / sliced) by its logical element order, never the raw backing buffer. - Zero-sized axes are rejected. Core
mattendoes not support zero-length dimensions, sofrom_arraydreturns an error for them. - Dynamic tensors are rejected, not panicked. Passing a dynamic (
Element) tensor returnsMattenNdarrayError::DynamicTensorregardless of whether the companiondynamicfeature is enabled (RFC-031); convert it withTensor::try_numeric()first. - Supported
ndarray: the0.17minor (CI targets0.17.2).
Conversion contract
matten-ndarray follows the bridge conversion-contract
template. The full contract:
| Dimension | matten-ndarray |
|---|---|
| Source / target | matten::Tensor ↔ ndarray::ArrayD<f64> |
| Direction | Bidirectional: to_arrayd(&Tensor), from_arrayd(ArrayD<f64>) |
| Copy / view | Copies both directions; no zero-copy |
| Shape / rank | Shape preserved; rank bounded by core matten (over-rank → Matten error); a zero-length axis is rejected (→ ZeroSizedAxis) |
| Memory order | Row-major logical order both ways; from_arrayd honors non-standard layouts |
| Dynamic tensors | Rejected → DynamicTensor (unconditional; not a panic) |
| NaN | Passed through as ordinary f64 |
| Missing values | Not reachable (numeric-only; dynamic rejected first) |
| Integer / text / bool | Not reachable (f64-only; dynamic element kinds rejected) |
| Errors | Result<_, MattenNdarrayError>; variants DynamicTensor, ZeroSizedAxis, NdarrayShape, Matten |
| Performance | Allocates and copies — convert once at the boundary, not in a hot loop |
Compatibility
- SemVer: pre-1.0 (
0.x). A0.xminor bump may contain breaking changes; patch releases are additive only. Pin the prerelease explicitly (matten-ndarray = "0.29.0-pre.2"). - MSRV: Rust 1.85 (edition 2024).
matten: shares the0.29.xfamily version (RFC-030).ndarray: supports the0.17minor (requirement"0.17"; CI targets0.17.2). Becauseto_arrayd/from_arraydusendarray::ArrayD<f64>, the supportedndarrayminor is part of the bridge's public type identity — build againstndarray 0.17.ndarray 0.17.0is yanked; use a non-yanked0.17patch. Anndarrayminor bump is a compatibility event handled by amatten-ndarrayminor bump (RFC-025 §6).- A
1.0release requires explicit maintainer confirmation.
More detail
See the workspace ROADMAP.md, RFC-025 (bridge policy), and
RFC-027 (this crate's design) under rfcs/.
License
Apache-2.0 © nabbisen