# HG changeset patch
# User Rik <rik@octave.org>
# Date 1509577074 25200
#      Wed Nov 01 15:57:54 2017 -0700
# Node ID 10b8f84a2cc49e54459184d2ffeb1d27cbfbf49a
# Parent  d5c38fdf77f93a307f5368c7c8655c28a7045e60
[mq]: inv

diff -r d5c38fdf77f9 -r 10b8f84a2cc4 liboctave/array/CMatrix.cc
--- a/liboctave/array/CMatrix.cc	Wed Nov 01 14:05:56 2017 -0700
+++ b/liboctave/array/CMatrix.cc	Wed Nov 01 15:57:54 2017 -0700
@@ -914,7 +914,9 @@ ComplexMatrix::inverse (MatrixType& matt
   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 = Complex (1,0) / (*this); 
+  else if (typ == MatrixType::Upper || typ == MatrixType::Lower)
     ret = tinverse (mattype, info, rcon, force, calc_cond);
   else
     {
@@ -938,11 +940,8 @@ ComplexMatrix::inverse (MatrixType& matt
 
       if ((calc_cond || mattype.ishermitian ()) && rcon == 0.)
         {
-          if (numel () == 1)
-            ret = ComplexMatrix (1, 1, 0.);
-          else
-            ret = ComplexMatrix (rows (), columns (),
-                                 Complex (octave::numeric_limits<double>::Inf (), 0.));
+          ret = ComplexMatrix (rows (), columns (),
+                               Complex (octave::numeric_limits<double>::Inf (), 0.));
         }
     }
 
diff -r d5c38fdf77f9 -r 10b8f84a2cc4 liboctave/array/dMatrix.cc
--- a/liboctave/array/dMatrix.cc	Wed Nov 01 14:05:56 2017 -0700
+++ b/liboctave/array/dMatrix.cc	Wed Nov 01 15:57:54 2017 -0700
@@ -619,7 +619,9 @@ Matrix::inverse (MatrixType& mattype, oc
   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 = 1 / (*this); 
+  else if (typ == MatrixType::Upper || typ == MatrixType::Lower)
     ret = tinverse (mattype, info, rcon, force, calc_cond);
   else
     {
@@ -641,8 +643,7 @@ 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))
+      if ((calc_cond || mattype.ishermitian ()) && rcon == 0.)
         ret = Matrix (rows (), columns (),
                       octave::numeric_limits<double>::Inf ());
     }
diff -r d5c38fdf77f9 -r 10b8f84a2cc4 liboctave/array/fCMatrix.cc
--- a/liboctave/array/fCMatrix.cc	Wed Nov 01 14:05:56 2017 -0700
+++ b/liboctave/array/fCMatrix.cc	Wed Nov 01 15:57:54 2017 -0700
@@ -916,7 +916,9 @@ FloatComplexMatrix::inverse (MatrixType&
   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
     {
@@ -940,11 +942,8 @@ FloatComplexMatrix::inverse (MatrixType&
 
       if ((calc_cond || mattype.ishermitian ()) && rcon == 0.)
         {
-          if (numel () == 1)
-            ret = FloatComplexMatrix (1, 1, 0.);
-          else
-            ret = FloatComplexMatrix (rows (), columns (),
-                                      FloatComplex (octave::numeric_limits<float>::Inf (), 0.));
+          ret = FloatComplexMatrix (rows (), columns (),
+                                    FloatComplex (octave::numeric_limits<float>::Inf (), 0.));
         }
     }
 
diff -r d5c38fdf77f9 -r 10b8f84a2cc4 liboctave/array/fMatrix.cc
--- a/liboctave/array/fMatrix.cc	Wed Nov 01 14:05:56 2017 -0700
+++ b/liboctave/array/fMatrix.cc	Wed Nov 01 15:57:54 2017 -0700
@@ -625,7 +625,9 @@ FloatMatrix::inverse (MatrixType& mattyp
   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 = 1 / (*this); 
+  else if (typ == MatrixType::Upper || typ == MatrixType::Lower)
     ret = tinverse (mattype, info, rcon, force, calc_cond);
   else
     {
@@ -647,8 +649,7 @@ FloatMatrix::inverse (MatrixType& mattyp
       if (! mattype.ishermitian ())
         ret = finverse (mattype, info, rcon, force, calc_cond);
 
-      if ((calc_cond || mattype.ishermitian ()) && rcon == 0.
-          && ! (numel () == 1))
+      if ((calc_cond || mattype.ishermitian ()) && rcon == 0.)
         ret = FloatMatrix (rows (), columns (),
                            octave::numeric_limits<float>::Inf ());
     }
