octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #51246] pinv(0) different from Matlab


From: Rik
Subject: [Octave-bug-tracker] [bug #51246] pinv(0) different from Matlab
Date: Fri, 16 Jun 2017 14:23:08 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0

Follow-up Comment #9, bug #51246 (project octave):

Attached is a quick hack (inverse.diff) which applies only to double matrices.
 It explicitly checks for the case of a scalar which is either 0 or Inf and
returns the correct output value.


diff -r 5e0acf41a9e1 -r 26ead836cbea liboctave/array/dMatrix.cc
--- a/liboctave/array/dMatrix.cc        Fri Jun 16 09:03:10 2017 -0700
+++ b/liboctave/array/dMatrix.cc        Fri Jun 16 11:18:36 2017 -0700
@@ -639,10 +639,19 @@ Matrix::inverse (MatrixType& mattype, oc
       if (! mattype.ishermitian ())
         ret = finverse (mattype, info, rcon, force, calc_cond);
 
-      if ((calc_cond || mattype.ishermitian ()) && rcon == 0.
-          && ! (numel () == 1))
-        ret = Matrix (rows (), columns (),
-                      octave::numeric_limits<double>::Inf ());
+      if ((calc_cond || mattype.ishermitian ()) && rcon == 0.)
+        {
+          if (numel () == 1)
+            {
+              if (octave::math::isinf (this->xelem (0)))
+                ret = Matrix (1, 1, 0.0); 
+              else
+                ret = Matrix (1, 1, octave::numeric_limits<double>::Inf ());

+            }
+          else
+            ret = Matrix (rows (), columns (),
+                          octave::numeric_limits<double>::Inf ());
+        }
     }
 
   return ret;


What does Matlab return for these two cases


inv (zeros (2,2))
inv (repmat (inf, [2,2]))





    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?51246>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]