Mercurial > octave
annotate scripts/miscellaneous/private/__memoize__.m @ 31551:fd29c7a50a78 stable
maint: use commas, semicolons consistently with Octave conventions.
* makeValidName.m: Remove %!test and move BIST %!asserts to column 1.
* base64decode.m, base64encode.m, which.m, logm.m, uniquetol.m, perms.m:
Delete semicolon (';') at end of %!assert BIST.
* lin2mu.m, interp2.m, interpn.m, lsqnonneg.m, pqpnonneg.m, uniquetol.m,
betainc.m, normalize.m: Add semicolon (';') to end of assert statement within
%!test BIST.
* __memoize__.m, tar_is_bsd.m, publish.m: Add semicolon (';') to line with
keyword "persistent".
* stft.m: Use comma (',') after "case" keyword when code immediately follows.
* gallery.m: Align commas used in case statements in massive switch block.
Remove unnecessary parentheses around a numeric case argument.
* ranks.m: Remove semicolon (';') from case statemnt argument.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 26 Nov 2022 06:32:08 -0800 |
parents | a40c0b7aa376 |
children | 0f93c3a756f7 |
rev | line source |
---|---|
31245
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
1 ######################################################################## |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
2 ## |
31253
a40c0b7aa376
maint: changes to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
31245
diff
changeset
|
3 ## Copyright (C) 2022 The Octave Project Developers |
31245
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
4 ## |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
7 ## |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
8 ## This file is part of Octave. |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
9 ## |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
11 ## under the terms of the GNU General Public License as published by |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
13 ## (at your option) any later version. |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
14 ## |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
15 ## Octave is distributed in the hope that it will be useful, but |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
18 ## GNU General Public License for more details. |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
19 ## |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
21 ## along with Octave; see the file COPYING. If not, see |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
23 ## |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
24 ######################################################################## |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
25 |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
26 ## -*- texinfo -*- |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
27 ## @deftypefn {} {@var{mem_fcn_handle} =} __memoize__ (@var{fcn_handle}) |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
28 ## @deftypefn {} {} __memoize__ () |
31253
a40c0b7aa376
maint: changes to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
31245
diff
changeset
|
29 ## Internal function used by @code{memoize}. |
31245
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
30 ## |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
31 ## @seealso{clearAllMemoizedCaches, memoize} |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
32 ## @end deftypefn |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
33 |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
34 function mem_fcn_handle = __memoize__ (fcn_handle) |
31551
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31253
diff
changeset
|
35 persistent cached_mem_fcn_handle; |
31245
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
36 |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
37 if (nargin) |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
38 |
31253
a40c0b7aa376
maint: changes to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
31245
diff
changeset
|
39 for i = 1:numel (cached_mem_fcn_handle) |
31245
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
40 if (isequal (cached_mem_fcn_handle{i}.Function, fcn_handle)) |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
41 mem_fcn_handle = cached_mem_fcn_handle{i}; |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
42 return; |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
43 endif |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
44 endfor |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
45 |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
46 mem_fcn_handle = matlab.lang.MemoizedFunction (fcn_handle); |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
47 cached_mem_fcn_handle{end+1} = mem_fcn_handle; |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
48 |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
49 else |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
50 |
31253
a40c0b7aa376
maint: changes to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
31245
diff
changeset
|
51 for i = 1:numel (cached_mem_fcn_handle) |
31245
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
52 clearCache (cached_mem_fcn_handle{i}); |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
53 endfor |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
54 |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
55 endif |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
56 |
a887ffb997a7
New function memoize to optimize repetitive function calls (bug #60860).
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff
changeset
|
57 endfunction |