[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #60860] Implementation of memoize
From: |
Guillaume |
Subject: |
[Octave-bug-tracker] [bug #60860] Implementation of memoize |
Date: |
Wed, 30 Jun 2021 10:48:44 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0 |
URL:
<https://savannah.gnu.org/bugs/?60860>
Summary: Implementation of memoize
Project: GNU Octave
Submitted by: gyom
Submitted on: Wed 30 Jun 2021 02:48:42 PM UTC
Category: Octave Function
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Feature Request
Status: None
Assigned to: None
Originator Name: Guillaume
Originator Email:
Open/Closed: Open
Release: dev
Discussion Lock: Any
Operating System: Any
_______________________________________________________
Details:
There is a memoize functionality in Matlab wince R2017a:
https://www.mathworks.com/help/matlab/ref/memoize.html
I attach an early attempt to implement it and would welcome feedback.
Running the following in Matlab indicates that a handle class
matlab.lang.MemoizedFunction has to be defined. To implement the fact that the
memoizing the same function handle returns the same object, I store all of
them in a persistent variable in the memoize function. That said, the
clearAllMemoizedCaches function would require access to that variable too so
there could be an undocumented syntax in memoize that could be called from
clearAllMemoizedCaches or there need to be a separate function to take on the
role of keeping track of all memoized function handles.
>> a = memoize(@sin);
>> whos a
Name Size Bytes Class
a 1x1 8 matlab.lang.MemoizedFunction
>> a
a =
MemoizedFunction with properties:
Function: @sin
Enabled: 1
CacheSize: 10
>> b = a;
>> a.Enabled = 0;
>> b
b =
MemoizedFunction with properties:
Function: @sin
Enabled: 0
CacheSize: 10
>> c = memoize(@sin)
c =
MemoizedFunction with properties:
Function: @sin
Enabled: 0
CacheSize: 10
>> struct(c)
ans =
struct with fields:
Function: @sin
Enabled: 0
CacheSize: 10
Cache: [1x1 struct]
PrivateCacheSize: 10
TracingEnabled: 0
Version: 1
CachingPolicy: 'CB'
>> ans.Cache
ans =
struct with fields:
Inputs: {}
Nargout: []
Outputs: {}
HitCount: []
Load: 0
TotalHits: 0
TotalMisses: 0
_______________________________________________________
File Attachments:
-------------------------------------------------------
Date: Wed 30 Jun 2021 02:48:42 PM UTC Name: memoize.zip Size: 4KiB By:
gyom
<http://savannah.gnu.org/bugs/download.php?file_id=51629>
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?60860>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #60860] Implementation of memoize,
Guillaume <=