7.1 Typed tensors with tenferro
Explanation
For this course, tenferro typed tensors are the standard path for two-dimensional and higher numerical arrays. In the current tenferro-rs layout, the type is imported as tenferro_tensor::TypedTensor from the tenferro-tensor crate. One-dimensional owned data should still normally use Vec<f64>, with functions accepting &[f64] or &mut [f64] at their boundaries.
A tensor is not just a block of numbers. It carries data together with shape information and, in typed-tensor code, meaning for the axes. For example, one axis might represent grid position and another might represent physical variables. That meaning is part of the scientific specification.
Shape validation is part of correctness. If an algorithm expects a time x variable tensor, accepting a variable x time tensor by accident can produce a number that looks plausible but means the wrong thing.
At the time of this writing, tenferro-rs has no all-in-one tenferro facade crate. Use the tensor crate directly when an exercise project needs typed tensors:
tenferro-tensor = { git = "https://github.com/tensor4all/tenferro-rs", branch = "main" }Complete exercise projects should commit Cargo.lock. The lock file records the resolved Git revision, which matters because tenferro is under active development. Before trusting AI-generated tensor code, verify the current repository or documentation, crate names, import paths, and resolved revision.
Things to look up
tenferrotenferro-tensorTypedTensor- Tensor shape
- Tensor axis
Cargo.lock- Git dependency
Exercise
Ask an AI agent to inspect the current tenferro documentation or repository and create a tiny Rust example that constructs a two-dimensional typed tensor. Do not ask for a large program.
In your answer, record:
- The documentation or repository source that the agent inspected.
- The resolved Git revision from
Cargo.lock. - The intended meaning of each axis.
- One shape check that would catch a wrong input.
Notes for the exercise
- Do not trust generated tensor code without checking the current repository or API.
- Check the current crate name and import path before copying generated code.
- Shape and axis meaning are part of the scientific specification.
- A small working example with a recorded revision is more useful than a long example that silently depends on an outdated API.