diff src/DLD-FUNCTIONS/pinv.cc @ 8840:c690e3772583

support diagonal matrices in pinv
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 23 Feb 2009 14:54:56 +0100
parents 82be108cc558
children a2878ba31a9e
line wrap: on
line diff
--- a/src/DLD-FUNCTIONS/pinv.cc	Mon Feb 23 13:55:44 2009 +0100
+++ b/src/DLD-FUNCTIONS/pinv.cc	Mon Feb 23 14:54:56 2009 +0100
@@ -29,6 +29,13 @@
 #include "gripes.h"
 #include "oct-obj.h"
 #include "utils.h"
+#include "ops.h"
+#include "ov-re-diag.h"
+#include "ov-cx-diag.h"
+#include "ov-flt-re-diag.h"
+#include "ov-flt-cx-diag.h"
+#include "ov-perm.h"
+#include "ov-flt-perm.h"
 
 DEFUN_DLD (pinv, args, ,
   "-*- texinfo -*-\n\
@@ -65,7 +72,56 @@
   else if (arg_is_empty > 0)
     return octave_value (Matrix ());
 
-  if (arg.is_single_type ())
+  bool isfloat = arg.is_single_type ();
+
+  if (arg.is_diag_matrix ())
+    {
+      if (nargin == 2)
+        warning ("pinv: tol is ignored for diagonal matrices");
+
+      const octave_base_value& a = arg.get_rep ();
+      if (arg.is_complex_type ())
+        {
+          if (isfloat)
+            {
+              CAST_CONV_ARG (const octave_float_complex_diag_matrix&);
+              retval = v.float_complex_diag_matrix_value ().pseudo_inverse ();
+            }
+          else
+            {
+              CAST_CONV_ARG (const octave_complex_diag_matrix&);
+              retval = v.complex_diag_matrix_value ().pseudo_inverse ();
+            }
+        }
+      else
+        {
+          if (isfloat)
+            {
+              CAST_CONV_ARG (const octave_float_diag_matrix&);
+              retval = v.float_diag_matrix_value ().pseudo_inverse ();
+            }
+          else
+            {
+              CAST_CONV_ARG (const octave_diag_matrix&);
+              retval = v.diag_matrix_value ().pseudo_inverse ();
+            }
+        }
+    }
+  else if (arg.is_perm_matrix ())
+    {
+      const octave_base_value& a = arg.get_rep ();
+      if (isfloat)
+        {
+          CAST_CONV_ARG (const octave_float_perm_matrix&);
+          retval = v.perm_matrix_value ().inverse ();
+        }
+      else
+        {
+          CAST_CONV_ARG (const octave_perm_matrix&);
+          retval = v.perm_matrix_value ().inverse ();
+        }
+    }
+  else if (isfloat)
     {
       float tol = 0.0;
       if (nargin == 2)