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 FunctionSeverity: 2 - Minor
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: ConfirmedAssigned to: None
Originator Name: Jochen WeberOriginator Email: -unavailable-
Open/Closed: OpenRelease: 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 File(s):

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


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

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

    Only project members can vote.


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



    Follow 8 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 17 Nov 2016 07:09:13 PM UTCrik5StatusNeed Info=>Confirmed
      Summarysubsasgn without LHS assignment Matlab incompatibility=>subsasgn without LHS should do in-place assignment for performance
    Sun 19 Jan 2014 11:16:03 PM UTCmtmillerCategoryNone=>Octave Function
      Severity3 - Normal=>2 - Minor
      Item GroupOther=>Matlab Compatibility
      StatusNone=>Need Info
      Operating SystemMac OS=>Any

    Back to the top

    Powered by Savane 3.1-cleanup1