compute_function_with_cache Subroutine

private subroutine compute_function_with_cache(me, x, f, funcs_to_compute)

Wrapper for computing the function, using the cache.

Arguments

Type IntentOptional Attributes Name
class(numdiff_type), intent(inout) :: me
real(kind=wp), intent(in), dimension(:) :: x

array of variables (size n)

real(kind=wp), intent(out), dimension(:) :: f

array of functions (size m)

integer, intent(in), dimension(:) :: funcs_to_compute

the elements of the function vector that need to be computed (the other are ignored)


Calls

proc~~compute_function_with_cache~~CallsGraph proc~compute_function_with_cache numerical_differentiation_module::compute_function_with_cache proc~get_from_cache numdiff_cache_module::function_cache%get_from_cache proc~compute_function_with_cache->proc~get_from_cache proc~put_in_cache numdiff_cache_module::function_cache%put_in_cache proc~compute_function_with_cache->proc~put_in_cache proc~vector_djb_hash numdiff_cache_module::vector_djb_hash proc~get_from_cache->proc~vector_djb_hash interface~unique numdiff_utilities_module::unique proc~put_in_cache->interface~unique proc~unique_int numdiff_utilities_module::unique_int interface~unique->proc~unique_int proc~unique_real numdiff_utilities_module::unique_real interface~unique->proc~unique_real interface~expand_vector numdiff_utilities_module::expand_vector proc~unique_int->interface~expand_vector interface~sort_ascending numdiff_utilities_module::sort_ascending proc~unique_int->interface~sort_ascending proc~unique_real->interface~expand_vector proc~unique_real->interface~sort_ascending proc~expand_vector_int numdiff_utilities_module::expand_vector_int interface~expand_vector->proc~expand_vector_int proc~expand_vector_real numdiff_utilities_module::expand_vector_real interface~expand_vector->proc~expand_vector_real proc~sort_ascending_int numdiff_utilities_module::sort_ascending_int interface~sort_ascending->proc~sort_ascending_int proc~sort_ascending_real numdiff_utilities_module::sort_ascending_real interface~sort_ascending->proc~sort_ascending_real interface~swap numdiff_utilities_module::swap proc~sort_ascending_int->interface~swap proc~sort_ascending_real->interface~swap proc~swap_int numdiff_utilities_module::swap_int interface~swap->proc~swap_int proc~swap_real numdiff_utilities_module::swap_real interface~swap->proc~swap_real

Source Code

    subroutine compute_function_with_cache(me,x,f,funcs_to_compute)

    implicit none

    class(numdiff_type),intent(inout) :: me
    real(wp),dimension(:),intent(in) :: x !! array of variables (size `n`)
    real(wp),dimension(:),intent(out) :: f !! array of functions (size `m`)
    integer,dimension(:),intent(in) :: funcs_to_compute !! the elements of the
                                                        !! function vector that need
                                                        !! to be computed (the other
                                                        !! are ignored)

    integer :: i !! index in the cache
    logical,dimension(size(funcs_to_compute)) :: ffound  !! functions found in the cache
    logical :: xfound  !! if `x` was found in the cache

    if (me%exception_raised) return ! check for exceptions

    call me%cache%get(x,funcs_to_compute,i,f,xfound,ffound)

    if (xfound .and. any(ffound)) then

        ! at least one of the functions was found
        if (all(ffound)) return ! all were found

        ! compute the ones that weren't found,
        ! and add them to the cache:
        call me%problem_func(x,f,pack(funcs_to_compute,mask=(.not. ffound)))
        call me%cache%put(i,x,f,pack(funcs_to_compute,mask=(.not. ffound)))

    else

        ! compute the function and add it to the cache:
        call me%problem_func(x,f,funcs_to_compute)
        call me%cache%put(i,x,f,funcs_to_compute)

    end if

    end subroutine compute_function_with_cache