bugGNU Octave - Bugs: bug #33221, subsasgn without LHS should do...


bug #33221: subsasgn without LHS should do in-place assignment for performance

Submitted by:  None
Submitted on:  Tue 03 May 2011 02:41:31 PM UTC  
Category:  Octave Function Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Jochen Weber Originator Email:  -email is unavailable-
Open/Closed:  Open Release:  dev
Operating System:  Any

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Thu 17 Nov 2016 07:09:13 PM UTC, comment #2:

The optimization may be possible. The operators such as '+=' or '-=' use in-place optimization and are significantly faster.

It already appears that indexing in the normal case is in-place.

Thus, it is a question of whether there is a way to hook in to the operator based function or not.

Rik <rik5>
Project Administrator
Sun 19 Jan 2014 11:16:03 PM UTC, comment #1:

I can't confirm whether this is the behavior in Matlab or not, but confirmed that subsasgn does not modify the value argument in place. I don't think any Octave function modifies the value of its argument.

Can someone confirm whether this is the behavior in a current version of Matlab?

Mike Miller <mtmiller>
Project Administrator
Tue 03 May 2011 02:41:31 PM UTC, original submission:

**This seems to be rather a Matlab-internal, undocumented features**

In some of my code I've been making use of the undocumented feature that if a call to subsasgn (only on a built-in type!) does not have a LHS assignment, the assignment is done "in place" (speed gain):

The previous code actually alters 'r', which is, to my knowledge, NOT documented by Mathworks.

The reason to use this syntax is that there is no cost to keep another copy of the variable in memory (to allow error handling, etc.).

So the following two subsasgn calls in Matlab work (and produce the same result), but the first is instantaneous, whereas the second one takes quite a while and might even end with an out-of-memory error:

While this is not a big deal, it would be nice to also have this "speedup" available in Octave (particularly when working on large, full matrices, such as 4D datasets that require a large amount of memory).

In Octave, a "manual" call of subsasgn on a large array always requires a copy, whereas using

is instantaneous, which is a little "inconsistent", I guess...



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

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-11-17 rik5 StatusNeed Info => Confirmed
        Summarysubsasgn without LHS assignment Matlab incompatibility => subsasgn without LHS should do in-place assignment for performance
    2014-01-19 mtmiller CategoryNone => Octave Function
        Severity3 - Normal => 2 - Minor
        Item GroupOther => Matlab Compatibility
        StatusNone => Need Info
        Release3.4.0 => dev
        Operating SystemMac OS => Any

    Back to the top

    Powered by Savane 3.3