Goto Chapter: Top 1 2 3 Ind
 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 

2 Commands
 2.1 Memoised functions

2 Commands

2.1 Memoised functions

2.1-1 MemoisedFunction
‣ MemoisedFunction( func[, opts] )( function )

Return a special function object in the category IsMemoisedFunction. This will be functionally the same as func, but using persistent memoisation to store and retrieve results from a cache.

If the optional argument opts is specified, it should be a record of options that customise how this memoisation is done. The following options are supported:

A function func should only be memoised if it is purely functional. It does not make sense to memoise a function if it has important side-effects, or if its output does not depend solely on its inputs.

gap> triple := x -> x * 3;
function( x ) ... end
gap> mtriple := MemoisedFunction(triple);
<memoised function( x ) ... end>
gap> mtriple(3);
#I  Memo key: [ 3 ]
#I  Key unknown.  Computing result...
9
gap> mtriple(3);
#I  Memo key: [ 3 ]
#I  Key known!  Loading result from cache...
9
gap> msize := MemoisedFunction(Size, rec(key := GeneratorsOfGroup,
>                                        storekey := true,
>                                        cache := "file://~/Desktop/mycache"));
<memoised <Attribute "Size">>
gap> msize(SymmetricGroup(6));
#I  Memo key: [ (1,2,3,4,5,6), (1,2) ]
#I  Key unknown.  Computing result...
720
gap> msize(Group((5,6,1,2,3,4), (1,2)));
#I  Memo key: [ (1,2,3,4,5,6), (1,2) ]
#I  Key known!  Loading result from cache...
720

2.1-2 IsMemoisedFunction
‣ IsMemoisedFunction( arg )( filter )

Returns: true or false

This category contains all memoised functions, special objects which wrap a function and store previously computed results in a cache, avoiding recomputation wherever possible.

For more information, and to create these objects, see MemoisedFunction.

2.1-3 ClearMemoisedFunction
‣ ClearMemoisedFunction( memo )( operation )

Returns: true or false

Clear all known memoised results from the cache of this memoised function. Return true if the operation was successful, and false otherwise.

gap> triple := MemoisedFunction(x -> x*3,
>                               rec(storekey := true,
>                                   key := IdFunc,
>                                   hash := String,
>                                   funcname := "triple_any_number"));;
gap> ClearMemoisedFunction(triple);
true

2.1-4 InfoMemoisation
‣ InfoMemoisation( info class )

Info class for the Memoisation package. Set this to the following levels for different levels of information:

Set this using, for example SetInfoLevel(InfoMemoisation, 1). Default value is 2.

 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 
Goto Chapter: Top 1 2 3 Ind

generated by GAPDoc2HTML