fn count_nonzeros<T>(rows: &[Vec<(usize, T)>]) -> (Vec<usize>, Vec<usize>) {
    let n = rows.len();
    debug_assert!(n > 0);
    debug_assert!(rows.iter().all(|row| row.iter().all(|&(i, _)| i < n)));

    let nnz_row = rows.iter()
        .map(Vec::len)
        .collect::<Vec<_>>();

    let nnz_column = {
        let mut counts = vec![0; n];
        for column in rows {
            for &(i, _) in column {
                counts[i] += 1;
            }
        }
        counts
    };

    debug_assert_eq!(nnz_column.len(), n);
    debug_assert_eq!(nnz_row.len(), n);
    // We should be working with an invertible matrix
    debug_assert!(nnz_column.iter().all(|&count| count > 0));
    debug_assert!(nnz_row.iter().all(|&count| count > 0));

    (nnz_row, nnz_column)
}
/// Count the number of nonzero values in each row and column.
///
/// Requires iterating over all values once.
Count the number of nonzero values in each row and column.
Requires iterating over all values once.
Count the number of nonzero values in each row and column . Requires iterating over all values once .
fn count_nonzeros<T>(rows: &[Vec<(usize, T)>]) -> (Vec<usize>, Vec<usize>) {
    let n = rows.len();
    debug_assert!(n > 0);
    debug_assert!(rows.iter().all(|row| row.iter().all(|&(i, _)| i < n)));
    let nnz_row = rows.iter()
        .map(Vec::len)
        .collect::<Vec<_>>();
    let nnz_column = {
        let mut counts = vec![0; n];
        for column in rows {
            for &(i, _) in column {
                counts[i] += 1;
            }
        }
        counts
    };
    debug_assert_eq!(nnz_column.len(), n);
    debug_assert_eq!(nnz_row.len(), n);
    // We should be working with an invertible matrix
    debug_assert!(nnz_column.iter().all(|&count| count > 0));
    debug_assert!(nnz_row.iter().all(|&count| count > 0));
    (nnz_row, nnz_column)
}
fn count_nonzeros < T > ( rows : & [ Vec < ( usize , T ) > ] ) -> ( Vec < usize > , Vec < usize > ) { let n = rows . len ( ) ; debug_assert ! ( n 0 ) ; debug_assert ! ( rows iter ( ) all ( row row iter ( ) all ( ( i ) i n ) ) ) ; let nnz_row = rows . iter ( ) . map ( Vec :: len ) . collect :: < Vec < _ > > ( ) ; let nnz_column = { let mut counts = vec ! [ 0 n ] ; for column in rows { for & ( i , _ ) in column { counts [ i ] += 1 ; } } counts } ; debug_assert_eq ! ( nnz_column len ( ) n ) ; debug_assert_eq ! ( nnz_row len ( ) n ) ; // We should be working with an invertible matrix debug_assert ! ( nnz_column iter ( ) all ( count count 0 ) ) ; debug_assert ! ( nnz_row iter ( ) all ( count count 0 ) ) ; ( nnz_row , nnz_column ) }
Count the number of nonzero values in each row and column.
Count the number of nonzero values in each row and column .
rows
&[Vec<(usize, T)>]
rows
&[Vec<(usize, T)>]