bugGNU Octave - Bugs: bug #62291, "zeros" with vector...

 
 

bug #62291: "zeros" with vector input is incompatible with Matlab

Submitted by:  Alexander Paul <erwin55>
Submitted on:  Mon 11 Apr 2022 02:43:43 PM UTC
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Missed Error or Warning
Status:  Ready For Test Assigned to:  None
Originator Name:  zeros Open/Closed:  * Open
Release:  * dev Operating System:  * Any
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

( Jump to the original submission )

Thu 14 Apr 2022 07:06:06 AM UTC, comment #8: 

comment #7:

> IMHO, this is on the edge though. Do you need this change to get something to work that didn't work previously?


It's not a big issue and could be fixed in one of the next releases. If you are programming correctly, you won't have a problem. But if you make a mistake (as me) and you get an result istead of an error message, it can take a lot of time to investigate the problem.

Alexander Paul <erwin55>
Thu 14 Apr 2022 05:27:27 AM UTC, comment #7: 

While the previous behavior was not documented and apparently not compatible to Matlab's, it's not completely unreasonable.
This patch changes behavior. It could cause user code that worked previously to fail now. Usually, we try to avoid that between minor releases.
IMHO, this is on the edge though. Do you need this change to get something to work that didn't work previously?

Markus Mützel <mmuetzel>
Project Member
Wed 13 Apr 2022 08:11:15 PM UTC, comment #6: 

The patch works properly for me and it passes all BISTs.

Should this also be grafted into the stable branch so it's available for 7.2 when it happens?

Arun Giridhar <arungiridhar>
Project Member
Wed 13 Apr 2022 05:37:02 PM UTC, comment #5: 

I pushed that change to the default branch here:
https://hg.savannah.gnu.org/hgweb/octave/rev/d7f799e6d836

Marking as ready for test.

Markus Mützel <mmuetzel>
Project Member
Tue 12 Apr 2022 04:38:57 PM UTC, comment #4: 

Preview ate my patch. Here it is.

(file #53082)

Markus Mützel <mmuetzel>
Project Member
Tue 12 Apr 2022 04:37:15 PM UTC, comment #3: 

I'm attaching a patch that should check that the dimensions in the input to ones/zeros/Inf/NaN/eps/... are scalars (instead of silently taking the first element and ignoring the rest).

Exemplary output:

>> zeros(1, 1:3)
error: zeros: dimensions must be scalars.

Markus Mützel <mmuetzel>
Project Member
Tue 12 Apr 2022 02:11:53 AM UTC, comment #2: 

trying a few other options in octave:

zeros (1, [1 2 3])
ans = 0

zeros (1, [2 3])
ans =
  0  0

zeros (1, [5 4 2])
  0  0  0  0  0

so seems like octave is just taking input_two(1) for the second term and ignoring what follows.

I disagree with comment #0 that zeros (1, 1:10) should give you the same output as zeros(1,10).  vector inputs should only be valid with a single input ( zeros([1 3 4]) = zeros(1,3,4).  mixing scalar and vector inputs is ambiguous.  for zeros(1,1:10), how should octave determine from [1 2 3 4 5 6 7 8 9 10] that it is to use 10 as the second input? 

If anything, I could see it be consistent with other usage and easily deterministic for zeros(1, [2 3]) to be equivalent to zeros(1, 2, 3), and I would even find it quite convenient at times.  But I could see that resulting in quite a few user errors, and is a bit beyond scope of this report.

I agree that an error message for nonscalars when nargin>1 makes the most sense.

Nicholas Jankowski <nrjank>
Project Member
Mon 11 Apr 2022 02:58:41 PM UTC, comment #1: 

For comparison, in Matlab R2021a:

>> zeros(1,1:10)
Error using zeros
Size inputs must be scalar.

Also looks like an input error to me.

Octave should probably also error out for this kind of input imho.

Markus Mützel <mmuetzel>
Project Member
Mon 11 Apr 2022 02:43:43 PM UTC, original submission:  

My system: MINGW32_NT-6.1 Windows 7 Service Pack 1 x86_64
Octave:  7.1.0 (hg id: 04120d65778a)

The function
zeros(1,1:10) answeres
ans = 0

It should have the same result as in
zeros(1,10)
ans =
   0   0   0   0   0   0   0   0   0   0

Alexander Paul <erwin55>

 

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

Attach Files:
   
   
Comment:
   

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by arungiridhar (Posted a comment)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by erwin55 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only project members can vote.

     

     

     

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-04-13 mmuetzel StatusPatch Submitted => Ready For Test
        Release7.1.0 => dev
    2022-04-12 mmuetzel Attached File- => Added bug62291-ones-zeros-scalars-dims.patch, #53082
    2022-04-12 mmuetzel Item GroupMatlab Compatibility => Missed Error or Warning
    2022-04-12 mmuetzel StatusConfirmed => Patch Submitted
        Operating SystemMicrosoft Windows => Any
    2022-04-11 mmuetzel StatusNone => Confirmed
        SummaryThe operation of "zeros" is not compatible with the equivalent function in Matlab => "zeros" with vector input is incompatible with Matlab

    Back to the top


    Powered by Savane 3.9