bugGNU Octave - Bugs: bug #52285, inv(0) gives 0 (instead of inf)

 
 

bug #52285: inv(0) gives 0 (instead of inf)

Submitted by:  Colin Macdonald <cbm>
Submitted on:  Thu 26 Oct 2017 08:20:24 AM UTC  
 
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Regression
Status: ConfirmedAssigned to: None
Originator Name: Open/Closed: Open
Release: devOperating System: GNU/Linux

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 Jump to the original submission)

Mon 06 Nov 2017 02:19:44 PM UTC, comment #13:

I wonder if it mostly depends on what version of gcc/glibc MW used to compiled a particular version....

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 06 Nov 2017 08:42:35 AM UTC, comment #12:

I confirm all NaNs for the example in comment #9

Marco Caliari <caliari>
Project Member
Mon 06 Nov 2017 05:43:05 AM UTC, comment #11:

I also get the all-nans-with-zero-in-lower-right result on 2008b. But strangely on 2014a, I get all nans:

Colin Macdonald <cbm>
Sat 04 Nov 2017 09:32:18 PM UTC, comment #10:

Rik,And you thought you could not have it both ways:

>> inv (repmat (Inf, [2,2]))

Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND =
NaN.

ans =

NaN NaN
NaN 0

>> version


ans =

'9.3.0.713579 (R2017b)'

>>


Michael Godfrey <godfrey>
Project Member
Sat 04 Nov 2017 08:23:59 PM UTC, comment #9:

The number of corner cases is just ridiculous. What does Matlab return for

I'm guessing it is either all zeros or all NaNs.

Rik <rik5>
Project Administrator
Sat 04 Nov 2017 10:05:01 AM UTC, comment #8:

>> inv (complex (0,0))

Warning: Matrix is singular to working precision.

ans =

Inf

>> version


ans =

'9.3.0.713579 (R2017b)'

>>

Michael Godfrey <godfrey>
Project Member
Sat 04 Nov 2017 04:20:08 AM UTC, comment #7:

@Colin: Can you check this corner case?

In Octave the result is strange

I think better thing would be to do automatic narrowing before calling inv() so that the result would be Inf.

Rik <rik5>
Project Administrator
Fri 03 Nov 2017 09:32:56 PM UTC, comment #6:

Yes your guess is correct: Matlab gives the 2x2 matrix of Infs.

Colin Macdonald <cbm>
Fri 03 Nov 2017 03:52:39 PM UTC, comment #5:

Another test case that needs to be run through Matlab

In Octave, this produces a special Diagonal matrix with Inf only on the diagonal.

On the other hand, my guess is that Matlab will return all Inf as in

Rik <rik5>
Project Administrator
Wed 01 Nov 2017 11:01:08 PM UTC, comment #4:

I stepped through the code in dMatrix.cc and in fact the MatrixType is set to Diagonal for the case of a scalar. It looks like the general question is why there isn't an early decision to take care of diagonal matrices which would be very easy

Find attached a quick test (inv.diff). It seems to pass "make check" with no problems. To be complete there should also be some BIST tests for the correct behavior of scalars of all types (double, single, double complex, single complex) with respect to the various operations '1 / x', 'inv (x)', x^-1, 'pinv (x)'.

(file #42320)

Rik <rik5>
Project Administrator
Mon 30 Oct 2017 10:49:42 AM UTC, comment #3:

The problem is around line 646 of dMatrix.cc. If the condition number is zero, any result is set Inf, except for the (numel() == 1 ) case. What was the purpose of such an explicit exclusion?
I have a more general question: why a scalar is treated as a full matrix and not (at least) as a triangular matrix?

Marco Caliari <caliari>
Project Member
Thu 26 Oct 2017 03:24:56 PM UTC, comment #2:

There have been some previous reports on this.

See bug #49690: inv(inf) behaves differently from inf^-1, 1/inf, inf\1

See bug #51246: pinv(0) different from Matlab

As of 10/26/17 and hg id 857b553177a5, I get

The only problem is 'inv (0)'.

Rik <rik5>
Project Administrator
Thu 26 Oct 2017 09:22:38 AM UTC, comment #1:

Another edge case:

That should be 0.

Ceral Paquet <octavebugs>
Thu 26 Oct 2017 08:20:24 AM UTC, original submission:

That should be "Inf" (e.g., in 4.2.1).

I think it changed sometime in the last few months but I have not bisected it yet to be sure.

Colin Macdonald <cbm>

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #42320:  inv.diff added by rik5 (5KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by dasergatskov (Posted a comment)
  • -unavailable- added by godfrey (Posted a comment)
  • -unavailable- added by caliari (Posted a comment)
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by octavebugs (Posted a comment)
  • -unavailable- added by cbm (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 01 Nov 2017 11:01:08 PM UTCrik5Attached File-=>Added inv.diff, #42320
    Thu 26 Oct 2017 03:24:56 PM UTCrik5StatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup1