bugGNU Octave - Bugs: bug #54110, bitset: output is zero when first...


bug #54110: bitset: output is zero when first argument is vector and third argument is scalar

Submitted by:  Philipp Mengs <philwatcher>
Submitted on:  Wed 13 Jun 2018 01:16:54 PM UTC  
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  Closed
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.


( Jump to the original submission)

Fri 15 Jun 2018 05:48:05 AM UTC, comment #9:

That might be a very corner case: Maybe instead of always returning a 0x0 we should return A of whatever size that is...

Markus Mützel <mmuetzel>
Project Member
Fri 15 Jun 2018 05:24:53 AM UTC, comment #8:

According to testing, Matlab returns [] for an empty input rather than throwing an error. I added a special case for that in Octave's bitset.m (http://hg.savannah.gnu.org/hgweb/octave/rev/12bbea4dc840).

Rik <rik5>
Project Administrator
Thu 14 Jun 2018 05:57:50 PM UTC, comment #7:

I'll ask about this on the Octave Maintainer's list.

Rik <rik5>
Project Administrator
Thu 14 Jun 2018 05:53:10 PM UTC, comment #6:

The last change let to a few tests failing.
It seems to come down to the following being called:

which returned [](0x0) previously but now fails with an error.

I won't be able to test with Matlab until in two weeks.

Markus Mützel <mmuetzel>
Project Member
Thu 14 Jun 2018 02:31:33 PM UTC, comment #5:

This small little thread caused the whole sweater to unravel. I had to completely overhaul the input validation which I did in this cset (http://hg.savannah.gnu.org/hgweb/octave/rev/8109fe62ab8a). bitset now matches Matlab behavior for the inputs that it accepts. It also made the input validation simpler because I was able to rely on a single function call to common_size() rather than trying to work out each combination of scalar and array inputs and expand them individually.

Rik <rik5>
Project Administrator
Thu 14 Jun 2018 10:33:13 AM UTC, comment #4:

For the sake of completeness, in Matlab R2016a:

Markus Mützel <mmuetzel>
Project Member
Wed 13 Jun 2018 09:06:08 PM UTC, comment #3:

I fixed this on the development branch in this cset http://hg.savannah.gnu.org/hgweb/octave/rev/7a6e35d987bb. It will be a part of the 5.0 release, or you can fetch the m-file from Octave's Mercurial repository and replace your existing bitset.m with the new one.

Rik <rik5>
Project Administrator
Wed 13 Jun 2018 07:36:38 PM UTC, comment #2:

What does Matlab say about bitset([1,2,3,4,5],1,[1,1,1])?

Philipp Mengs <philwatcher>
Wed 13 Jun 2018 04:28:33 PM UTC, comment #1:

fwiw, in Matlab R2016a:

So this also is a compatibility issue.

Markus Mützel <mmuetzel>
Project Member
Wed 13 Jun 2018 01:16:54 PM UTC, original submission:

On Octave 4.4.0 on Windows:

input: bitset([1,2,3,4,5],1,1)
expected return: [1,3,3,5,5]
actually returns: [1,0,0,0,0]

Omitting the third argument ("val") works:
input: bitset([1,2,3,4,5],1)
expected return: [1,3,3,5,5]
actually returns: [1,3,3,5,5]

Setting the third argument to a ones vector works as well:
input: bitset([1,2,3,4,5],1,[1,1,1,1,1])
expected return: [1,3,3,5,5]
actually returns: [1,3,3,5,5]

From the documentation, I would expect that the third argument would be broadcast to all vector entries. In the current state, it is only applied to the first entry (more precisely, if val has n entries it is applied to the first n entries of the input vector).

In the code, if val is omitted, then the function creates it to the same size as the input. If val is present, there is no check if the sizes match. I am not sure if this is intended behavior.

A potential fix would be in bitset.m, around line 53:
if (isscalar(val))
val = logical(ones(sz) * val);
(or a more octavic broadcasting operation)

Philipp Mengs <philwatcher>


(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 (Updated the item)
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by philwatcher (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 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-06-15 rik5 StatusIn Progress => Fixed
        Open/ClosedOpen => Closed
        Release4.4.0 => dev
    2018-06-14 mmuetzel StatusFixed => In Progress
        Open/ClosedClosed => Open
    2018-06-13 rik5 StatusConfirmed => Fixed
        Open/ClosedOpen => Closed
        Operating SystemMicrosoft Windows => Any
    2018-06-13 mtmiller StatusNone => Confirmed
    2018-06-13 mtmiller Item GroupIncorrect Result => Matlab Compatibility

    Back to the top

    Powered by Savane 3.3