diff liboctave/array/fCMatrix.cc @ 30313:98400baa509f

Return Inf for inv(0) for compatibility with division operator and Matlab (bug #52285). * CMatrix.cc, dMatrix.cc, fCMatrix.cc, fMatrix.cc (inverse): Check early for MatrixType::Diagonal which implies a scalar. In scalar case, just calculate 1 / *this. * inv.cc (Finverse): Add BIST tests for new behavior.
author Rik <rik@octave.org>
date Sun, 21 Nov 2021 16:53:49 -0800
parents 1e277c6b6626
children f3f3e3793fb5
line wrap: on
line diff
--- a/liboctave/array/fCMatrix.cc	Sun Nov 21 13:39:19 2021 -0800
+++ b/liboctave/array/fCMatrix.cc	Sun Nov 21 16:53:49 2021 -0800
@@ -938,7 +938,9 @@
   if (typ == MatrixType::Unknown)
     typ = mattype.type (*this);
 
-  if (typ == MatrixType::Upper || typ == MatrixType::Lower)
+  if (typ == MatrixType::Diagonal)  // a scalar is also classified as Diagonal.
+    ret = FloatComplex (1,0) / (*this);
+  else if (typ == MatrixType::Upper || typ == MatrixType::Lower)
     ret = tinverse (mattype, info, rcon, force, calc_cond);
   else
     {
@@ -962,11 +964,8 @@
 
       if ((calc_cond || mattype.ishermitian ()) && rcon == 0.0)
         {
-          if (numel () == 1)
-            ret = FloatComplexMatrix (1, 1, 0.0);
-          else
-            ret = FloatComplexMatrix (rows (), columns (),
-                                      FloatComplex (octave::numeric_limits<float>::Inf (), 0.0));
+          ret = FloatComplexMatrix (rows (), columns (),
+                                    FloatComplex (octave::numeric_limits<float>::Inf (), 0.0));
         }
     }