bugGNU Octave - Bugs: bug #67761, clear all causes problem in memoize

 
 

bug #67761: clear all causes problem in memoize

Submitter:  None
Submitted:  Tue 02 Dec 2025 02:06:21 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Confirmed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * 10.3.0
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Post a Comment

Add a New Comment Rich Markup
   

Discussion

Fri 05 Dec 2025 01:22:14 PM UTC, comment #3: 

The implementation of memoize isn't very efficient as it uses a for loop and isequal over the number of functions that have been memoized.

But, there is something strange here that probably leads back to classdef implementation.

Minimal working example

M = magic (3);
minv = memoize (@inv);
debug_on_error (1);
minv (M);
clear -f
minv (M)


With results

error: max_recursion_depth exceeded
error: called from
    subsref
    subsref at line 60 column 15
    subsref at line 75 column 15
stopped in subsref at line 60 [./scripts/+matlab/+lang/MemoizedFunction.m]
60:               varargout{1} = this.Enabled;


It would seem that the specialized subsref() function within the classdef object is being cleared, even though the object itself is not. 

Rik <rik5>
Group administrator
Thu 04 Dec 2025 08:03:11 AM UTC, comment #2: 

I can confirm some weird behavior. I used the following function (which I attached as a function file) for testing:


function retval = memofcn (input1, input2)
  mlock ();
  persistent a = rand (5e3);
  persistent minv = memoize (@inv);
  minv (a);
endfunction


I used mlock() to prevent the persistent variables from being cleared by "clear all".

Here is the output:


octave:1> tic; memofcn(); toc
Elapsed time is 2.16334 seconds.
octave:2> tic; memofcn(); toc
Elapsed time is 0.056947 seconds.
octave:3> clear all
octave:4> tic; memofcn(); toc
*error: max_recursion_depth exceeded
error: called from
    subsref
    subsref at line 60 column 15
    subsref at line 75 column 15
    memofcn at line 5 column 3


Pantxo Diribarne <pantxo>
Group Member
Wed 03 Dec 2025 10:33:08 AM UTC, comment #1: 

What is "nuxe"?

Rik <rik5>
Group administrator
Tue 02 Dec 2025 02:06:21 PM UTC, original submission:  

memoize() is nuxe but contrary to its description its memoization table is not private. The command "clear all" removes private memoization table even if outside the function.

Anonymous

 

Attached Files

Attached Files
file #57912:  memofcn.m added by pantxo (144B - text/x-objcsrc)

(Note: upload size limit is set to 4.0MiB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

 

Dependencies

This item does not depend on any other items.

No items depend on this one.

 

Mail Notification Carbon-Copy List

Carbon-Copy List
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  •  

    Votes

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

    History

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-12-04 pantxo Attached File- Added memofcn.m, #57912
    2025-12-04 pantxo StatusNeed Info Confirmed
        Release7.2.0 10.3.0
    2025-12-04 pantxo CategoryNone Octave Function
        Item GroupNone Unexpected Error or Warning
    2025-12-03 rik5 StatusNone Need Info

    Back to the top

    Powered by Savane 3.16-a7ba.
    Corresponding source code