Wrapper for computing the function, using the cache.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
array of variables (size |
|
real(kind=wp), | intent(out), | dimension(:) | :: | f |
array of functions (size |
|
integer, | intent(in), | dimension(:) | :: | funcs_to_compute |
the elements of the function vector that need to be computed (the other are ignored) |
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