function_cache Derived Type

type, public :: function_cache

a vector function cache.


Inherits

type~~function_cache~~InheritsGraph type~function_cache function_cache type~fx fx type~function_cache->type~fx c

Components

Type Visibility Attributes Name Initial
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

  • private subroutine initialize_cache(me, isize, 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), 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]

procedure, public :: get => get_from_cache

  • private subroutine get_from_cache(me, x, i, f, found)

    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
    integer(kind=ip), intent(in), dimension(:) :: x

    independant variable vector

    integer(kind=ip), intent(out) :: i

    index in the hash table

    integer(kind=ip), intent(out), dimension(:), allocatable :: f

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

    logical, intent(out) :: found

    if x was found in the cache

procedure, public :: put => put_in_cache

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

    Put a value into the cache.

    Arguments

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

    index in the hash table

    integer(kind=ip), intent(in), dimension(:) :: x

    independant variable vector

    integer(kind=ip), intent(in), dimension(:) :: f

    function

procedure, public :: destroy => destroy_cache

  • private subroutine destroy_cache(me)

    Destroy a cache.

    Arguments

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

Source Code

    type,public :: function_cache
        !! a vector function cache.
        private
        type(fx),dimension(:),allocatable :: c  !! the cache of `f(x)`
        integer :: chunk_size = 100 !! for resizing vectors
                                    !! in the [[unique]] function
    contains
        private
        procedure,public :: initialize => initialize_cache
        procedure,public :: get        => get_from_cache
        procedure,public :: put        => put_in_cache
        procedure,public :: destroy    => destroy_cache
    end type function_cache