Skip to main content

sparse_row_softmax

Function sparse_row_softmax 

Source
pub fn sparse_row_softmax(row_offsets: &[usize], values: &[f64]) -> Vec<f64>
Expand description

Row-wise softmax over sparse matrix values.

For each row defined by row_offsets, computes:

softmax(v_i) = exp(v_i - max_row) / sum_j exp(v_j - max_row)

Uses the numerically stable log-sum-exp trick.

§Arguments

  • row_offsets – CSR row pointer.
  • values – Sparse matrix values (modified in place conceptually; returns new vector).

§Returns

A new vector of softmax-normalized values with the same sparsity pattern.