1%feature("docstring") OT::MemoizeFunction 2"Function which keeps tracks of input and output. 3 4When this function is evaluated, it calls the 5:class:`~openturns.Function` passed as argument, and store 6input and output :class:`~openturns.Sample`. 7It also has a caching behavior, enabled by default. 8 9Parameters 10---------- 11function : :class:`~openturns.Function` 12 Delegate function 13historyStrategy : :class:`~openturns.HistoryStrategy` (optional) 14 Strategy used to store points, default is :class:`~openturns.Full`. 15 16Notes 17----- 18 19When the function passed as argument is a :class:`~openturns.MemoizeFunction`, 20its input and output history are copied into current instance. This allows 21to retrieve this history from a :class:`~openturns.Function` object which 22is in fact a :class:`~openturns.MemoizeFunction`. 23Thus, if you create a :class:`~openturns.MemoizeFunction` from an unknown 24:class:`~openturns.Function`, it is better to call :meth:`clearHistory`. 25The cache size is initialized by the value of the :class:`~openturns.ResourceMap` `Cache-MaxSize` entry. 26 27See also 28-------- 29Function, HistoryStrategy, Full, Last, Compact, Null 30 31Examples 32-------- 33 34>>> import openturns as ot 35>>> f = ot.SymbolicFunction('x', 'x^2') 36>>> inputSample = ot.Sample([[1], [2], [3], [4]]) 37>>> f = ot.MemoizeFunction(f) 38>>> outputSample = f(inputSample) 39 40Retrieve input sample: 41 42>>> print(f.getInputHistory()) 430 : [ 1 ] 441 : [ 2 ] 452 : [ 3 ] 463 : [ 4 ] 47 48Retrieve output sample: 49 50>>> print(f.getOutputHistory()) 510 : [ 1 ] 521 : [ 4 ] 532 : [ 9 ] 543 : [ 16 ]" 55 56// --------------------------------------------------------------------- 57 58%feature("docstring") OT::MemoizeFunction::enableCache 59"Enable the cache mechanism." 60 61// --------------------------------------------------------------------- 62 63%feature("docstring") OT::MemoizeFunction::disableCache 64"Disable the cache mechanism." 65 66// --------------------------------------------------------------------- 67 68%feature("docstring") OT::MemoizeFunction::clearCache 69"Empty the content of the cache." 70 71// --------------------------------------------------------------------- 72 73%feature("docstring") OT::MemoizeFunction::isCacheEnabled 74"Test whether the cache mechanism is enabled or not. 75 76Returns 77------- 78isCacheEnabled : bool 79 Flag telling whether the cache mechanism is enabled. 80 It is enabled by default." 81 82// --------------------------------------------------------------------- 83 84%feature("docstring") OT::MemoizeFunction::getCacheHits 85"Accessor to the number of computations saved thanks to the cache mecanism. 86 87Returns 88------- 89cacheHits : int 90 Integer that counts the number of computations saved thanks to the cache 91 mecanism." 92 93// --------------------------------------------------------------------- 94 95%feature("docstring") OT::MemoizeFunction::getCacheInput 96"Accessor to all the input numerical points stored in the cache mecanism. 97 98Returns 99------- 100cacheInput : :class:`~openturns.Sample` 101 All the input numerical points stored in the cache mecanism." 102 103// --------------------------------------------------------------------- 104 105%feature("docstring") OT::MemoizeFunction::getCacheOutput 106"Accessor to all the output numerical points stored in the cache mecanism. 107 108Returns 109------- 110cacheInput : :class:`~openturns.Sample` 111 All the output numerical points stored in the cache mecanism." 112 113// --------------------------------------------------------------------- 114 115%feature("docstring") OT::MemoizeFunction::addCacheContent 116"Add input numerical points and associated output to the cache. 117 118Parameters 119---------- 120input_sample : 2-d sequence of float 121 Input numerical points to be added to the cache. 122output_sample : 2-d sequence of float 123 Output numerical points associated with the input_sample to be added to the 124 cache." 125 126// --------------------------------------------------------------------- 127 128%feature("docstring") OT::MemoizeFunction::getInputHistory 129"Get the input sample. 130 131Returns 132------- 133inputSample : :class:`~openturns.Sample` 134 Input points which have been evaluated." 135 136// --------------------------------------------------------------------- 137 138%feature("docstring") OT::MemoizeFunction::getOutputHistory 139"Get the output sample. 140 141Returns 142------- 143outputSample : :class:`~openturns.Sample` 144 Output points which have been evaluated." 145 146// --------------------------------------------------------------------- 147 148%feature("docstring") OT::MemoizeFunction::enableHistory 149"Enable the history mechanism." 150 151// --------------------------------------------------------------------- 152 153%feature("docstring") OT::MemoizeFunction::disableHistory 154"Disable the history mechanism." 155 156// --------------------------------------------------------------------- 157 158%feature("docstring") OT::MemoizeFunction::isHistoryEnabled 159"Test whether the history mechanism is enabled or not. 160 161Returns 162------- 163isHistoryEnabled : bool 164 Flag telling whether the history mechanism is enabled." 165 166// --------------------------------------------------------------------- 167 168%feature("docstring") OT::MemoizeFunction::clearHistory 169"Clear input and output history." 170 171// --------------------------------------------------------------------- 172%feature("docstring") OT::MemoizeFunction::getMarginal 173"Accessor to marginal. 174 175Parameters 176---------- 177indices : int or list of ints 178 Set of indices for which the marginal is extracted. 179 180Returns 181------- 182marginal : :class:`~openturns.Function` 183 Function corresponding to either :math:`f_i` or 184 :math:`(f_i)_{i \in indices}`, with :math:`f:\Rset^n \rightarrow \Rset^p` 185 and :math:`f=(f_0 , \dots, f_{p-1})`. 186 Marginal is wrapped into a :class:`~openturns.MemoizeFunction` object, 187 and history is activated with the same :class:`~openturns.HistoryStrategy` 188 class which had been used for this function." 189