diff liboctave/numeric/svd.h @ 21273:cbced1c09916

better use of templates for svd classes * liboctave/numeric/svd.h, liboctave/numeric/svd.cc: New files for svd classes generated from CmplxSVD.cc, CmplxSVD.h, dbleSVD.cc, dbleSVD.h, fCmplxSVD.cc, fCmplxSVD.h, floatSVD.cc, and floatSVD.h and converted to templates. * liboctave/numeric/module.mk: Update. * __qp__.cc, svd.cc, CMatrix.cc, CMatrix.h, dDiagMatrix.h, dMatrix.cc, dMatrix.h, fCMatrix.cc, fCMatrix.h, fDiagMatrix.h, fMatrix.cc, fMatrix.h, oct-norm.cc, mx-defs.h, mx-ext.h: Use new classes.
author John W. Eaton <jwe@octave.org>
date Tue, 16 Feb 2016 14:41:06 -0500
parents liboctave/numeric/dbleSVD.h@1473547f50f5
children 469c817eb256
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/numeric/svd.h	Tue Feb 16 14:41:06 2016 -0500
@@ -0,0 +1,109 @@
+/*
+
+Copyright (C) 1994-2015 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#if ! defined (octave_svd_h)
+#define octave_svd_h 1
+
+#include "octave-config.h"
+
+#include <iosfwd>
+
+template <typename T>
+class
+svd
+{
+public:
+
+  typedef typename T::real_diag_matrix_type DM_T;
+
+  enum type
+  {
+    std,
+    economy,
+    sigma_only
+  };
+
+  enum driver
+  {
+    GESVD,
+    GESDD
+  };
+
+  svd (void)
+    : type_computed (), left_sm (), sigma (), right_sm ()
+  { }
+
+  svd (const T& a, type svd_type = svd::std, driver svd_driver = svd::GESVD)
+    : type_computed (), left_sm (), sigma (), right_sm ()
+  {
+    init (a, svd_type, svd_driver);
+  }
+
+  svd (const T& a, octave_idx_type& info, type svd_type = svd::std,
+       driver svd_driver = svd::GESVD)
+    : type_computed (), left_sm (), sigma (), right_sm ()
+  {
+    info = init (a, svd_type, svd_driver);
+  }
+
+  svd (const svd& a)
+    : type_computed (a.type_computed), left_sm (a.left_sm),
+      sigma (a.sigma), right_sm (a.right_sm)
+  { }
+
+  svd& operator = (const svd& a)
+  {
+    if (this != &a)
+      {
+        type_computed = a.type_computed;
+        left_sm = a.left_sm;
+        sigma = a.sigma;
+        right_sm = a.right_sm;
+      }
+
+    return *this;
+  }
+
+  ~svd (void) { }
+
+  T left_singular_matrix (void) const;
+
+  DM_T singular_values (void) const { return sigma; }
+
+  T right_singular_matrix (void) const;
+
+private:
+
+  svd::type type_computed;
+
+  T left_sm;
+  DM_T sigma;
+  T right_sm;
+
+  octave_idx_type
+  init (const T& a, type svd_type, driver svd_driver);
+
+  octave_idx_type
+  empty_init (octave_idx_type nr, octave_idx_type nc, type svd_type);
+};
+
+#endif