Skip to main content

submatrix_argmax

Function submatrix_argmax 

Source
pub fn submatrix_argmax<T: Scalar>(
    a: &Matrix<T>,
    rows: Range<usize>,
    cols: Range<usize>,
) -> (usize, usize, T)
Expand description

Find the position and value of the maximum absolute value in a submatrix.

Searches within the rectangular region defined by rows x cols ranges. Returns (row, col, value) of the element with the largest |value|^2.

§Panics

Panics if either range is empty.

§Examples

use tensor4all_tcicore::{from_vec2d, matrix::submatrix_argmax};

let m = from_vec2d(vec![
    vec![1.0_f64, 2.0, 3.0],
    vec![4.0, 9.0, 6.0],
    vec![7.0, 8.0, 5.0],
]);
let (row, col, val) = submatrix_argmax(&m, 0..3, 0..3);
assert_eq!(row, 1);
assert_eq!(col, 1);
assert_eq!(val, 9.0);