Skip to main content

rowwise_scoring/
rowwise_scoring.rs

1//! Row-wise weighted scoring: multiply each row by a weight vector.
2//!
3//! Run: cargo run --example rowwise_scoring
4
5use matten::Tensor;
6
7fn main() {
8    // 3 items × 4 features
9    let features = Tensor::new(
10        vec![0.8, 0.6, 0.9, 0.7, 0.4, 0.9, 0.5, 0.8, 0.7, 0.7, 0.8, 0.6],
11        &[3, 4],
12    );
13
14    // Importance weights per feature: shape [4], broadcast across rows
15    let weights = Tensor::new(vec![0.3, 0.2, 0.4, 0.1], &[4]);
16
17    // Weighted feature matrix: [3,4]
18    let weighted = &features * &weights;
19
20    // Score per item: sum across features (axis 1) -> shape [3]
21    let scores = weighted.sum_axis(1);
22    println!("scores = {:?}", scores.as_slice());
23
24    // Best item (highest score)
25    let best_score = scores.max();
26    println!("best score = {best_score:.3}");
27
28    assert_eq!(scores.shape(), &[3]);
29    println!("Row-wise scoring: OK");
30}