bugGNU Octave - Bugs: bug #54275, repelem error if a repeat...


bug #54275: repelem error if a repeat instruction is a vector that ends with 0

Submitted by:  None
Submitted on:  Mon 09 Jul 2018 09:38:53 AM UTC  
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error
Status:  Fixed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  4.4.0
Operating System:  Any

Add a New Comment(Rich Markup)

You are not logged in

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


Mon 09 Jul 2018 06:34:31 PM UTC, comment #2:

Confirmed. As noted in the title, this is a problem only when the last position is a 0.

I would prefer not to call out to a second function (repelems) because there is a fair amount of interpreter overhead in calling a function.

Since methods 1 and 3 both work, the only question is performance. I made a small benchmark

The results are

Patch three is the winner (although we're only talking about 20 milliseconds).

I committed the patch to the stable branch here (http://hg.savannah.gnu.org/hgweb/octave/rev/9277b77dd28f).

Marking as fixed and closing report.

Rik <rik5>
Project Administrator
Mon 09 Jul 2018 12:04:31 PM UTC, comment #1:

The first solution in the original submission is a little ugly.
If we didn't want to use the second solution (using "repelems"),
here is a third solution.

Besides, in fact, in the subfuntion prepareIdx, the variable "idx" is actually a row vector
except for the last line "idx = (find (v != 0))(cumsum (idx))".
The problem is that "find(v!=0)" might be a row or column vector according to the shape of "v".
If we really wanted the output "idx" to be a row vector,
we could change that line into "idx = find (v != 0)(:).'(cumsum (idx))".

Mon 09 Jul 2018 09:38:53 AM UTC, original submission:

For example,

One possible solution is as follow.
(Besides, note that the comment "idx2 output will be a row vector" is wrong; in fact the output can be either row or column vector.)

Another solution is to use built-in function "repelems" directly.

And below is some proposed test case.



(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 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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-07-09 rik5 StatusNone => Fixed
        Open/ClosedOpen => Closed
        Summaryrepelem error if a repeat instruction is a vector ends with 0 => repelem error if a repeat instruction is a vector that ends with 0

    Back to the top

    Powered by Savane 3.4