Impure wrapper function for f_lin_mahalanobis_core.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | x(:) |
input vector 1 |
||
| real(kind=wp), | intent(in) | :: | y(:) |
input vector 2 |
||
| real(kind=wp), | intent(in), | optional | :: | cov(:,:) |
covariance matrix |
Mahalanobis distance
impure function f_lin_mahalanobis(x, y, cov) result(dist) ! ==== Description !! Impure wrapper function for `f_lin_mahalanobis_core`. ! ==== Declarations real(wp), intent(in) :: x(:) !! input vector 1 real(wp), intent(in) :: y(:) !! input vector 2 real(wp), intent(in), optional :: cov(:,:) !! covariance matrix real(wp) :: dist !! Mahalanobis distance ! ==== Instructions ! ---- handle input ! check if size is valid if (size(x) .le. 1 .or. size(y) .le. 1) then ! write error message and assign NaN value if invalid call s_err_print(fsml_error(4)) dist = f_utl_assign_nan() return endif if (present(cov)) then ! check if dims match if (size(cov, 1) .ne. size(x)) then ! write error message and assign NaN value if invalid call s_err_print(fsml_error(3)) dist = f_utl_assign_nan() return endif ! check if dims match if (size(cov, 1) .ne. size(cov, 2)) then ! write error message and assign NaN value if invalid call s_err_print(fsml_error(3)) dist = f_utl_assign_nan() return endif endif ! ---- compute Mahalanobis distance ! call pure function if (present(cov)) then dist = f_lin_mahalanobis_core(x, y, cov) else dist = f_lin_mahalanobis_core(x, y) endif end function f_lin_mahalanobis