[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #61705] Wrong number of columns when removing
From: |
Rik |
Subject: |
[Octave-bug-tracker] [bug #61705] Wrong number of columns when removing entry from empty vector |
Date: |
Wed, 22 Dec 2021 19:19:56 -0500 (EST) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 |
Update of bug #61705 (project octave):
Severity: 3 - Normal => 2 - Minor
Priority: 5 - Normal => 3 - Low
Item Group: Incorrect Result => Matlab Compatibility
_______________________________________________________
Follow-up Comment #3:
This is a minor nuisance, and Matlab isn't much better. To quickly summarize,
you cannot rely on columns() when a matrix is empty. If your code will
encounter empty matrices you may need to separate them and use different code
for them in a special case. You can separate them using isempty() or "if
(numel (x) == 0)".
For a slightly longer explanation, both Matlab and Octave allow you to create
arbitrarily-sized N-dimensional matrices. And you can request the number of
columns for these matrices regardless of whether they actually hold anything.
Here's some code that shows that:
x = zeros (0, 101, 5)
x = [](0x101x5)
columns (x)
ans = 101
Now if you do indexing the result is the size of the index. This applies even
to empty indexing.
x = 1:10;
idx = zeros (0,3)
idx = [](0x3)
y = x(idx)
y = [](0x3)
Of course, this is where it gets silly/stupid. The expression "x != 2" should
be of size 0x0. It is when it is executed directly, but not when it is
executed as part of an indexing operation.
x = []
x = [](0x0)
x ~= 2
ans = [](0x0)
x(x ~= 2)
ans = [](0x1)
I've lowered the severity since this is a minor issue that can be more
appropriately handled by detecting empty matrices. I've also changed the Item
Group to Matlab Compatibility since it seems to generate a 0x0 matrix for the
test case.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?61705>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/