bugGNU Octave - Bugs: bug #48564, Octave does not accept "1 /...

 
 

bug #48564: Octave does not accept "1 / ND array", "mrdivide (1, ND array)", "mldivide (ND array, 1)"

Submitted by:  Philip Nienhuis <philipnienhuis>
Submitted on:  Tue 19 Jul 2016 09:03:29 PM UTC  
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Patch Submitted Assigned to:  None
Originator Name:  philipnienhuis Open/Closed:  Open
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)

Sun 29 Jan 2017 08:14:21 PM UTC, comment #9:

Admittedly I've been including this patch in my mxe cross-builds ever since July '16 but never came back to this bug report.

JWE noted additional tests are required as well.

AFAIR mldivide's behavior should still be patched as well, see comment #7. I just checked this in Matlab r2017a prerelease:

..while Octave (with John's patch) does:

(BTW where do those empty lines in Octave come from? they started appearing some months ago)

Philip Nienhuis <philipnienhuis>
Project Member
Sun 29 Jan 2017 07:35:54 PM UTC, comment #8:

Ping. This report was mostly solved and has a patch attached. It seems like documentation could be added and then the patch committed. Or, the patch could be changed to validate the dimensions rather than just the number of elements (see comment #7) and then committed.

Rik <rik5>
Project Administrator
Wed 20 Jul 2016 06:41:44 PM UTC, comment #7:

Patch works fine in Linux now, but indeed, when A is any 2D array, patched Octave will accepts constructs like

1 / A
-and-
mrdivide (1, A)

that Matlab doesn't accept. So I guess merely checking for number of dimensions should do the trick.

mldivide won't accept (A, 1), nor (if B = 3D array) (B, 1). The former should be OK, the latter not.

Philip Nienhuis <philipnienhuis>
Project Member
Wed 20 Jul 2016 02:34:11 PM UTC, comment #6:

If we consider Matlab as "authorative"....
Matlab won't accept any 2D matrix as divisor as in "1 / rand (2, 3)" or "mrdivide (1, rand 3, 2))"

Philip Nienhuis <philipnienhuis>
Project Member
Wed 20 Jul 2016 01:01:29 PM UTC, comment #5:

Oh, but maybe the test is not correct. Should it just be a test on the number of dimensions, or should element-by-element division also be done if the matrix is 2-dimensional but not square?

Also, this behavior should be documented.

John W. Eaton <jwe>
Project Administrator
Wed 20 Jul 2016 12:58:25 PM UTC, comment #4:

I think the attached patch should solve this problem. We could use tests for each combination of types (real, complex, float, float complex) that are affected.

(file #37954)

John W. Eaton <jwe>
Project Administrator
Wed 20 Jul 2016 10:14:24 AM UTC, comment #3:

Thanks John.

As the Matlab docs are unclear about right division by an array of arbitrary dimensions, I experimented a bit more.
It turns out that mrdivide, rdivide and "/", and for that matter, mldivide too, all perform element-by-element division for anything except square matrices. Obvious as that's the only useful outcome for arbitrary arrays.
Matlab r2016b prerelease:
+verbatim-

>> format long
>> format compact
>> MX = rand (3, 3, 3)

MX(:,:,1) =
0.327565434075205 0.833500595588975 0.861980478702072
0.671264370451740 0.768854252429615 0.989872153631504
0.438644982586956 0.167253545494722 0.514423456505704
MX(:,:,2) =
0.884281023126955 0.199862822857452 0.825583815786156
0.588026055308498 0.406954837138907 0.789963029944531
0.154752348656045 0.748705718215691 0.318524245398992
MX(:,:,3) =
0.534064127370726 0.136292548938299 0.189710406017580
0.089950678770581 0.678652304800188 0.495005824990221
0.111705744193203 0.495177019089661 0.147608221976689

>> (1 / MX) - mrdivide (1, MX)

ans(:,:,1) =
0 0 0
0 0 0
0 0 0
ans(:,:,2) =
0 0 0
0 0 0
0 0 0
ans(:,:,3) =
0 0 0
0 0 0
0 0 0

>> (1 / MX) - rdivide (1, MX)

ans(:,:,1) =
0 0 0
0 0 0
0 0 0
ans(:,:,2) =
0 0 0
0 0 0
0 0 0
ans(:,:,3) =
0 0 0
0 0 0
0 0 0

>> (1 / MX) - mldivide (MX, 1)

ans(:,:,1) =
0 0 0
0 0 0
0 0 0
ans(:,:,2) =
0 0 0
0 0 0
0 0 0
ans(:,:,3) =
0 0 0
0 0 0
0 0 0
-verbatim-

For square matrix:

Octave-4.1.0+ does:
+verbatim-

>> 1 / MX

error: operator /: nonconformant arguments (op1 is 1x1, op2 is 3x9)

>> mrdivide (1, MX)

error: mrdivide: operator /: nonconformant arguments (op1 is 1x1, op2 is 3x9)

>> rdivide (1, MX)

ans =
ans(:,:,1) =
3.05282516399582 1.19975919068585 1.16011908008143
1.48972602154801 1.30063662500396 1.01023146911583
2.27974795038665 5.97894649731989 1.94392379926188
ans(:,:,2) =
1.13086221896275 5.00343178237420 1.21126405445310
1.70060491533044 2.45727512917771 1.26588202497301
6.46193746773186 1.33563825635417 3.13947843671169
ans(:,:,3) =
1.87243431780963 7.33715825105533 5.27119213432779
11.11720349048724 1.47350858890021 2.02017824743730
8.95209111422619 2.01947982529240 6.77469037028254

>> mldivide (MX, 1)

error: mldivide: operator \: nonconformant arguments (op1 is 3x9, op2 is 1x1)>>
-verbatim-

Is "Matlab compatibility" the proper Item Group or should it rather be one of "Feature request", "WTF, Matlab?!?" or "Incorrect result"?

And do you want a separate bug report for the ND to 2x2 array conversion?

<title adapted>

Philip Nienhuis <philipnienhuis>
Project Member
Wed 20 Jul 2016 12:08:26 AM UTC, comment #2:

mrdivide is the functional equivalent of the "/" operator.

rdivide is the same as "./", the element-by-element operator.

However, it does look like a bug for Octave to be trying convert an N-d array to a 2-d matrix in this case.

John W. Eaton <jwe>
Project Administrator
Tue 19 Jul 2016 09:49:22 PM UTC, comment #1:

Checking a bit more it looks like Matlab interprets "1 / <ND_array>" as "rdivide (1, <matrix>)".

That is at least a workaround.

Why Matlab doesn't accept "1 / <2x2 matrix>" is beyond me, as "rdivide (1, <2x2 matrix>)" goes fine. Maybe because 1/<square matrix> does have a meaning different from element-wise division?

Philip Nienhuis <philipnienhuis>
Project Member
Tue 19 Jul 2016 09:03:29 PM UTC, original submission:

Matlab r2016b prerelease accepts "1 / rand (5, 5, 5);"
I'm unsure about how to interpret this but it seems to work fine in Matlab.

In Octave:

I don't know if this qualifies as a bug or just a Matlab feature not (yet?) implemented in Octave; provisionally I assumed the latter.
Octave's error message suggests the second & third dimension of "rand (5, 5, 5)" aren't recognized properly; does that suggest a different bug?

To be sure, Matlab in turn doesn't accept a simple 2D matrix at the RHS:

At least Octave and Matlab agree there :-)

I hit this when trying out reducepatch.m (patch #8912) with the examples from Matlab itself.

(Mageia5 64b, hg id ef91e43f162a "set DLL ....")

Philip Nienhuis <philipnienhuis>
Project Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #37954:  diffs.txt added by jwe (4KiB - text/plain)

 

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 jwe (Posted a comment)
  • -email is unavailable- added by philipnienhuis (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
    2016-07-20 jwe Attached File- => Added diffs.txt, #37954
        StatusNone => Patch Submitted
    2016-07-20 philipnienhuis SummaryOctave does not accept 1 / ND array => Octave does not accept "1 / ND array", "mrdivide (1, ND array)", "mldivide (ND array, 1)"

    Back to the top


    Powered by Savane 3.3