SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DirectLinearSolverComplex.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2013 Soumyajit De
8  */
9 
10 #include <shogun/lib/config.h>
11 
12 #ifdef HAVE_EIGEN3
13 #include <shogun/lib/SGVector.h>
14 #include <shogun/lib/SGMatrix.h>
18 
19 using namespace Eigen;
20 
21 namespace shogun
22 {
23 
24 CDirectLinearSolverComplex::CDirectLinearSolverComplex()
26  m_type(DS_QR_NOPERM)
27 {
28  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
29 }
30 
33  m_type(type)
34 {
35  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
36 }
37 
39 {
40  SG_GCDEBUG("%s destroyed (%p)\n", this->get_name(), this)
41 }
42 
45 {
47 
48  REQUIRE(A, "Operator is NULL!\n");
49  REQUIRE(A->get_dimension()==b.vlen, "Dimension mismatch!\n");
50 
52  dynamic_cast<CDenseMatrixOperator<complex128_t>*>(A);
53  REQUIRE(op, "Operator is not CDenseMatrixOperator<complex128_t, float64_t> type!\n");
54 
55  SGMatrix<complex128_t> mat_A=op->get_matrix_operator();
56  Map<MatrixXcd> map_A(mat_A.matrix, mat_A.num_rows, mat_A.num_cols);
57  Map<VectorXd> map_b(b.vector, b.vlen);
58  Map<VectorXcd> map_x(x.vector, x.vlen);
59 
60  switch (m_type)
61  {
62  case DS_LLT:
63  {
64  LLT<MatrixXcd> llt(map_A);
65  map_x=llt.solve(map_b.cast<complex128_t>());
66 
67  // checking for success
68  if (llt.info()==NumericalIssue)
69  SG_WARNING("Matrix is not Hermitian positive definite!\n");
70  }
71  break;
72  case DS_QR_NOPERM:
73  map_x=map_A.householderQr().solve(map_b.cast<complex128_t>());
74  break;
75  case DS_QR_COLPERM:
76  map_x=map_A.colPivHouseholderQr().solve(map_b.cast<complex128_t>());
77  break;
78  case DS_QR_FULLPERM:
79  map_x=map_A.fullPivHouseholderQr().solve(map_b.cast<complex128_t>());
80  break;
81  case DS_SVD:
82  map_x=map_A.jacobiSvd(ComputeThinU|ComputeThinV).solve(map_b.cast<complex128_t>());
83  break;
84  }
85 
86  return x;
87 }
88 
89 }
90 #endif // HAVE_EIGEN3

SHOGUN Machine Learning Toolbox - Documentation