Skip to main content

11_csv_numeric_loading/
11_csv_numeric_loading.rs

1//! Loading numeric CSV data into a tensor.
2//!
3//! Run: cargo run --example 11_csv_numeric_loading
4//!
5//! Phase 1 accepts rectangular numeric-only CSV. Shape is inferred as
6//! [rows, cols]. Each field must be a valid f64.
7
8use matten::Tensor;
9
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    // ── from_csv: inline string ──────────────────────────────────────────
12    let t = Tensor::from_csv("1.0,2.0,3.0\n4.0,5.0,6.0\n")?;
13    println!(
14        "inline CSV:   shape={:?}  data={:?}",
15        t.shape(),
16        t.as_slice()
17    );
18
19    // ── load_csv: from file ──────────────────────────────────────────────
20    let t2 = Tensor::load_csv("examples/data/numeric_2x3.csv")?;
21    println!(
22        "from file:    shape={:?}  data={:?}",
23        t2.shape(),
24        t2.as_slice()
25    );
26
27    let t3 = Tensor::load_csv("examples/data/numeric_3x3.csv")?;
28    println!("3×3 from file: shape={:?}", t3.shape());
29
30    Ok(())
31}