NcmFunctionCache

NcmFunctionCache — A generic cache for functions values

Stability Level

Stable, unless otherwise indicated

Functions

Properties

double abstol Read / Write / Construct Only
guint dimension Read / Write / Construct Only
double reltol Read / Write / Construct Only

Types and Values

Object Hierarchy

    GEnum
    ╰── NcmFunctionCacheSearchType
    GObject
    ╰── NcmFunctionCache

Includes

#include <numcosmo/math/ncm_function_cache.h>

Description

A simple cache that saves function values at different argument values. It can be used to find an already computed value or the value of the function closest to an already computed point.

Functions

ncm_function_cache_new ()

NcmFunctionCache *
ncm_function_cache_new (guint n,
                        gdouble abstol,
                        gdouble reltol);

Creates a new NcmFunctionCache for a n dimensional function. The points are considered the same within the tolerance described by abstol and reltol .

Parameters

n

function dimension

 

abstol

relative tolerance

 

reltol

absolute tolerance

 

Returns

the newly created NcmFunctionCache.


ncm_function_cache_ref ()

NcmFunctionCache *
ncm_function_cache_ref (NcmFunctionCache *cache);

Increase the reference of cache by one.

Parameters

cache

a NcmFunctionCache

 

Returns

cache .

[transfer full]


ncm_function_cache_free ()

void
ncm_function_cache_free (NcmFunctionCache *cache);

Decrease the reference count of cache by one.

Parameters

cache

a NcmFunctionCache

 

ncm_function_cache_clear ()

void
ncm_function_cache_clear (NcmFunctionCache **cache);

Decrease the reference count of cache by one, and sets the pointer *cache to NULL.

Parameters

cache

a NcmFunctionCache

 

ncm_function_cache_get_reltol ()

gdouble
ncm_function_cache_get_reltol (NcmFunctionCache *cache);

Parameters

cache

a NcmFunctionCache

 

Returns

the relative tolerance.


ncm_function_cache_get_abstol ()

gdouble
ncm_function_cache_get_abstol (NcmFunctionCache *cache);

Parameters

cache

a NcmFunctionCache

 

Returns

the relative tolerance.


ncm_function_cache_empty_cache ()

void
ncm_function_cache_empty_cache (NcmFunctionCache *cache);

Empties the content of cache .

Parameters

cache

a NcmFunctionCache

 

ncm_function_cache_insert ()

void
ncm_function_cache_insert (NcmFunctionCache *cache,
                           gdouble x,
                           ...);

Insert a new point in the cache.

[skip]

Parameters

cache

a NcmFunctionCache

 

x

the argument $x$

 

...

function value at $x$

 

ncm_function_cache_insert_vector ()

void
ncm_function_cache_insert_vector (NcmFunctionCache *cache,
                                  gdouble x,
                                  NcmVector *p);

Insert a new point in the cache.

Parameters

cache

a NcmFunctionCache

 

x

the argument $x$

 

p

function value at $x$

 

ncm_function_cache_get ()

gboolean
ncm_function_cache_get (NcmFunctionCache *cache,
                        gdouble *x_ptr,
                        NcmVector **v);

Searches the cache and returns the value of the function at $x$.

[skip]

Parameters

cache

a NcmFunctionCache

 

x_ptr

the argument $x$

 

v

the function at $x$ or NULL if no point was not found.

[out][transfer none]

Returns

whether a point $x$ was found.


ncm_function_cache_get_near ()

gboolean
ncm_function_cache_get_near (NcmFunctionCache *cache,
                             gdouble x,
                             gdouble *x_found_ptr,
                             NcmVector **v,
                             NcmFunctionCacheSearchType type);

Searches the cache and returns the value of the function closest to $x$, $x_c$.

Parameters

cache

a NcmFunctionCache

 

x

the argument $x$

 

x_found_ptr

Whether a point $x_c$ close to $x$ was found in the cache

 

v

the function at $x_c$ or NULL if no point was not found.

[out callee-allocates][transfer full]

type

a NcmFunctionCacheSearchType

 

Returns

whether a point $x_c$ was found.

Types and Values

NCM_TYPE_FUNCTION_CACHE

#define NCM_TYPE_FUNCTION_CACHE (ncm_function_cache_get_type ())

enum NcmFunctionCacheSearchType

Cache search direction.

Members

NCM_FUNCTION_CACHE_SEARCH_BOTH

Searches both directions.

 

NCM_FUNCTION_CACHE_SEARCH_GT

Searches cache upwards.

 

NCM_FUNCTION_CACHE_SEARCH_LT

Searches cache downwards.

 

NcmFunctionCache

typedef struct _NcmFunctionCache NcmFunctionCache;

Property Details

The “abstol” property

  “abstol”                   double

Absolute tolerance.

Owner: NcmFunctionCache

Flags: Read / Write / Construct Only

Allowed values: >= 0

Default value: 0


The “dimension” property

  “dimension”                guint

Function dimension.

Owner: NcmFunctionCache

Flags: Read / Write / Construct Only

Allowed values: >= 1

Default value: 1


The “reltol” property

  “reltol”                   double

Relative tolerance.

Owner: NcmFunctionCache

Flags: Read / Write / Construct Only

Allowed values: [1e-15,1]

Default value: 1e-07