记忆功能
Call memoized function and cache results
描述
一种记忆功能
object maintains the memoization semantics of a function handle and a cache of the function call results. It has the same calling syntax as the function handle specified in theFunction
property. However, the记忆功能
object is not a function handle.
这first time you call the memoized function with a certain set of input values, MATLAB®executes the function specified by theFunction
property and caches the results. In later calls to the memoized function with the same set of inputs, MATLAB returns the cached results instead of executing the function again.
这记忆功能
object maintains the cache of inputs and the corresponding outputs. When it is invoked, MATLAB returns the associated cached output values if the following conditions are true.
输入参数在数值上等于缓存的输入。比较输入值时,MATLAB对待
南
s等于。这number of requested output arguments matches the number of cached outputs associated with the inputs.
警告
一种记忆功能
object is not aware of updates to the underlying function. If you modify the function associated with the memoized function, clear the cache with theClearCache
对象功能。
创建
To create a记忆功能
对象,打电话给备忘录
功能。
函数的核对与输入功能相关联,而不是与输入功能相关联记忆功能
目的。因此,请记住以下内容。
Constructing a new
记忆功能
对象到相同的函数创建了对相同数据的另一个引用。留下相同函数的两个变量共享缓存和对象属性值,例如缓存大小。在以下示例中,变量一种
一种ndB.
共享缓存并具有相同的缓存大小值。a = memoize(@svd);b = memoize(@svd);
B.
(B.。ClearCache
)也清除缓存一种
, and any other variables that memoize theSVD.
功能。ClearCache
是A.记忆功能
对象功能。分配A.
记忆功能
object to a new variable creates another reference to the same data. In the following example, the variablesC
一种ndD.
share data.C= memoize(@svd); d = c;
清除变量不会清除与输入功能关联的缓存。清除缓存的一个
记忆功能
object that no longer exists in the workspace, create a new记忆功能
object to the same function, and use theClearCache
在新对象上的函数。或者,您可以清除所有人的缓存记忆功能
objects using theclearallmemoizedCaches.
功能。
特性
对象功能
ClearCache |
MemoizedFunction对象清除缓存 |
统计 |
返回MemoizedFunction对象的缓存值和统计信息 |