Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungYour AI Agent Is a Confused Deputy(19.09.2026 um 21:39 Uhr)
Sichere ProgrammierungJour 1/100 · 75 minutes(19.09.2026 um 21:40 Uhr)
Sichere ProgrammierungMOGP: A SCSS Layout System That Only Does One Thing(19.09.2026 um 21:42 Uhr)
Sichere ProgrammierungAuto-localize prices in React with react-currency-localizer-realtime(19.09.2026 um 21:50 Uhr)
Sichere ProgrammierungYour AI Agent Is a Confused Deputy(19.09.2026 um 21:39 Uhr)
Sichere ProgrammierungJour 1/100 · 75 minutes(19.09.2026 um 21:40 Uhr)
Sichere ProgrammierungMOGP: A SCSS Layout System That Only Does One Thing(19.09.2026 um 21:42 Uhr)
Sichere ProgrammierungAuto-localize prices in React with react-currency-localizer-realtime(19.09.2026 um 21:50 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

matten: The core `Tensor`

This is the second of four short posts about matten. The first post explained the motivation. This one shows what the library looks like in practice.

Getting started

# Cargo.toml
[dependencies]
matten = "0.28"

The default feature set includes serde, json, and csv. If you want the smallest possible dependency footprint, you can turn them off:

matten = { version = "0.28", default-features = false }

Creating tensors

The whole import is use matten::Tensor;. No generic parameters, no lifetime annotations.

use matten::Tensor;

// From data and an explicit shape
let a = Tensor::new(vec![1.0, 2.0, 3.0, 4.0], &[2, 2]);
assert_eq!(a.shape(), &[2, 2]);
assert_eq!(a.ndim(), 2);

// Convenience constructors
let z = Tensor::zeros(&[3, 3]);
let o = Tensor::ones(&[3, 3]);
let f = Tensor::full(&[2, 4], 5.0);

Shape mismatches produce an actionable error rather than a panic when you use the boundary-style constructor:

use matten::{MattenError, Tensor};

let result = Tensor::try_new(vec![1.0, 2.0, 3.0], &[2, 2]);
assert!(matches!(result, Err(MattenError::Shape { .. })));

Arithmetic and broadcasting

The operators work on references, so you keep ownership of the originals. Shape broadcasting follows NumPy-style right-alignment rules.

use matten::Tensor;

let a = Tensor::new(vec![1.0, 2.0, 3.0, 4.0], &[2, 2]);
let b = Tensor::ones(&[2, 2]);

let c = &a + &b;          // [2.0, 3.0, 4.0, 5.0]
let d = &a * 2.0;         // scalar broadcast: [2.0, 4.0, 6.0, 8.0]

// Broadcasting a row across a matrix
let row = Tensor::new(vec![1.0, 2.0], &[1, 2]);
let mat = Tensor::ones(&[3, 2]);
let result = &mat + &row; // shape [3, 2]

Shape operations

use matten::Tensor;

let t = Tensor::new(vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0], &[2, 3]);

let flat = t.flatten();           // shape [6]
let reshaped = t.reshape(&[3, 2])?;
let transposed = t.transpose()?;  // shape [3, 2]

// Reductions
let s = t.sum();          // scalar
let m = t.mean()?;
let col_sums = t.sum_axis(0)?;    // shape [3]

JSON and CSV

Both are on by default. The API returns Result at the boundary, so a malformed input gives you an error rather than a panic.

use matten::Tensor;

// JSON — two accepted forms
let t = Tensor::from_json(r#"{"shape":[2,2],"data":[1.0,2.0,3.0,4.0]}"#)?;
let t = Tensor::from_json("[[1.0, 2.0], [3.0, 4.0]]")?;

// From a file
let t = Tensor::load_json("data/tensor.json")?;

// CSV
let t = Tensor::from_csv("1.0,2.0,3.0\n4.0,5.0,6.0\n")?;
let t = Tensor::load_csv("data/matrix.csv")?;

Serialisation goes through serde, so serde_json::to_string(&t) and serde_json::from_str(&json_str) round-trip correctly when the json or serde feature is active.

Error handling

matten has two deliberate error zones. Internal shape operations (constructing from new, reshaping, slicing) panic with an actionable message — useful during fast prototyping because you see the problem immediately. External boundary operations (from_json, from_csv, load_*) always return Result<Tensor, MattenError>, because real input data is not always clean.

MattenError is #[non_exhaustive], so match on the variant you care about and use a wildcard for the rest:

use matten::{MattenError, Tensor};

match Tensor::from_csv("1.0,not_a_number\n") {
    Ok(t) => println!("got shape {:?}", t.shape()),
    Err(MattenError::Parse { .. }) => println!("bad input"),
    Err(e) => println!("other error: {e:?}"),
}

That covers the everyday numeric core. The next post covers something different:

what happens when the input data is not a clean f64 matrix — when it has mixed types, missing values, or integers alongside floats.

Links: crates.io · docs.rs · mdBook · repository

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten matten: The core `Tensor`

Thematisch verwandte Begriffe: matten, core, Tensor · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-93987 | rclone versions 1.56.0 through 1.75.0 contain a path traversal vulnerabi…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick