Skip to main content

validate_dist_mat

Function validate_dist_mat 

Source
pub fn validate_dist_mat(
    dist_mat: &FdMatrix,
    expected_n: Option<usize>,
) -> Result<usize, FdarError>
Expand description

Validate that a distance matrix is square and optionally matches an expected size.

Returns the number of rows/columns n.

§Errors

Returns FdarError::InvalidDimension if the matrix is not square or does not match the expected size.

§Examples

use fdars_core::validation::validate_dist_mat;
use fdars_core::matrix::FdMatrix;

let dm = FdMatrix::zeros(5, 5);
assert_eq!(validate_dist_mat(&dm, None).unwrap(), 5);
assert_eq!(validate_dist_mat(&dm, Some(5)).unwrap(), 5);
assert!(validate_dist_mat(&dm, Some(4)).is_err());