For caching function evaluations.
an [x,f(x)] cached pair.
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 |
||
integer, | private, | dimension(:), allocatable | :: | ifs |
elements of |
a vector function cache.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | private | :: | n | = | 0 |
size of |
|
integer, | private | :: | m | = | 0 |
size of |
|
type(fx), | private, | dimension(:), allocatable | :: | c |
the cache of |
||
integer, | private | :: | chunk_size | = | 100 |
for resizing vectors in the unique function |
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 |
DJB hash algorithm for a real(wp)
vector.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(:) | :: | r |
the vector |
the hash value
Initialize the cache. Must be called first before use.
Type | Intent | Optional | 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 |
Print the contents of the cache. Used for debugging.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(function_cache), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | iunit |
file unit for writing (assumed to be opened) |
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.
Type | Intent | Optional | 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 |
|
integer, | intent(out) | :: | i |
index in the hash table |
||
real(kind=wp), | intent(out), | dimension(:) | :: | f |
|
|
logical, | intent(out) | :: | xfound |
if |
||
logical, | intent(out), | dimension(size(ifs)) | :: | ffound |
which |
Put a value into the cache.
Type | Intent | Optional | 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 |
|
real(kind=wp), | intent(in), | dimension(:) | :: | f |
function vector |
|
integer, | intent(in), | dimension(:) | :: | ifs |
elements of |
Destroy a cache.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(function_cache), | intent(out) | :: | me |