numdiff_cache_module Module

For caching function evaluations.


Uses

  • module~~numdiff_cache_module~~UsesGraph module~numdiff_cache_module numdiff_cache_module iso_fortran_env iso_fortran_env module~numdiff_cache_module->iso_fortran_env module~numdiff_kinds_module numdiff_kinds_module module~numdiff_cache_module->module~numdiff_kinds_module module~numdiff_utilities_module numdiff_utilities_module module~numdiff_cache_module->module~numdiff_utilities_module module~numdiff_kinds_module->iso_fortran_env module~numdiff_utilities_module->module~numdiff_kinds_module

Used by

  • module~~numdiff_cache_module~~UsedByGraph module~numdiff_cache_module numdiff_cache_module module~numerical_differentiation_module numerical_differentiation_module module~numerical_differentiation_module->module~numdiff_cache_module

Derived Types

type, private ::  fx

an [x,f(x)] cached pair.

Components

Type Visibility Attributes Name Initial
real(kind=wp), private, dimension(:), allocatable :: x

vector of input values

real(kind=wp), private, dimension(:), allocatable :: f

vector of output functions f(x) note: only the elements indicated by ifs will have valid values. The others will be dummy values.

integer, private, dimension(:), allocatable :: ifs

elements of f present in the cache (this is just an array of the indices present in f)

type, public ::  function_cache

a vector function cache.

Components

Type Visibility Attributes Name Initial
integer, private :: n = 0

size of x

integer, private :: m = 0

size of f

type(fx), private, dimension(:), allocatable :: c

the cache of f(x)

integer, private :: chunk_size = 100

for resizing vectors in the unique function

Type-Bound Procedures

procedure, public :: initialize => initialize_cache
procedure, public :: get => get_from_cache
procedure, public :: put => put_in_cache
procedure, public :: destroy => destroy_cache
procedure, public :: print => print_cache

Functions

private pure function vector_djb_hash(r) result(hash)

DJB hash algorithm for a real(wp) vector.

Read more…

Arguments

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

the vector

Return Value integer(kind=ip)

the hash value


Subroutines

private subroutine initialize_cache(me, isize, n, m, chunk_size)

Initialize the cache. Must be called first before use.

Arguments

Type IntentOptional Attributes Name
class(function_cache), intent(inout) :: me
integer, intent(in) :: isize

the size of the hash table

integer, intent(in) :: n

number of independant variables (x)

integer, intent(in) :: m

number of functions (f)

integer, intent(in), optional :: chunk_size

chunk size to speed up reallocation of arrays. A good value is a guess for the actual number of elements of f that will be saved per value of x [default is 100]

private subroutine print_cache(me, iunit)

Print the contents of the cache. Used for debugging.

Arguments

Type IntentOptional Attributes Name
class(function_cache), intent(inout) :: me
integer, intent(in) :: iunit

file unit for writing (assumed to be opened)

private subroutine get_from_cache(me, x, ifs, i, f, xfound, ffound)

Check if the x vector is in the cache, if so return f. Note that only some of the elements may be present, so it will return the ones there are there, and indicate which ones were found.

Arguments

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

independant variable vector

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

elements of f needed

integer, intent(out) :: i

index in the hash table

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

f(x) from the cache (if it was found)

logical, intent(out) :: xfound

if x was found in the cache

logical, intent(out), dimension(size(ifs)) :: ffound

which ifs were found in the cache

private subroutine put_in_cache(me, i, x, f, ifs)

Put a value into the cache.

Arguments

Type IntentOptional Attributes Name
class(function_cache), intent(inout) :: me
integer, intent(in) :: i

index in the hash table

real(kind=wp), intent(in), dimension(:) :: x

independant variable vector (dimension n)

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

function vector f(x) (dimension m)

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

elements of f to add (should all be >0, <=m)

private subroutine destroy_cache(me)

Destroy a cache.

Arguments

Type IntentOptional Attributes Name
class(function_cache), intent(out) :: me