equal_within_tol Function

public pure function equal_within_tol(vals, tol, relative) result(equal)

Returns true if the values in the array are the same (to within the specified absolute or relative tolerance).

For the relative test, the tolerance is scaled by the largest magnitude in vals, so a set of zeros is equal, and (for tol<1) any set containing both zero and a nonzero value is not.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: vals

a set of values

real(kind=wp), intent(in) :: tol

a positive tolerance value

logical, intent(in), optional :: relative

if true, tol is relative [default is false: absolute]

Return Value logical

true if they are equal within the tolerance


Called by

proc~~equal_within_tol~~CalledByGraph proc~equal_within_tol equal_within_tol proc~compute_sparsity_random compute_sparsity_random proc~compute_sparsity_random->proc~equal_within_tol proc~compute_sparsity_random_2 compute_sparsity_random_2 proc~compute_sparsity_random_2->proc~equal_within_tol

Source Code

    pure function equal_within_tol(vals,tol,relative) result (equal)

    implicit none

    real(wp),dimension(:),intent(in) :: vals     !! a set of values
    real(wp),intent(in)              :: tol      !! a positive tolerance value
    logical,intent(in),optional      :: relative !! if true, `tol` is relative
                                                 !! [default is false: absolute]
    logical                          :: equal    !! true if they are equal
                                                 !! within the tolerance

    real(wp) :: scale !! scale factor for the tolerance

    scale = 1.0_wp
    if (present(relative)) then
        if (relative) scale = maxval(abs(vals))
    end if

    equal = all ( abs(vals - vals(1)) <= abs(tol)*scale )

    end function equal_within_tol