SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 #include <shogun/lib/SGVector.h>
13 #include <shogun/lib/SGMatrix.h>
14 #include <shogun/io/SGIO.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 }
std::complex< float64_t > complex128_t
Definition: common.h:67
const index_t get_dimension() const
Definition: SGMatrix.h:20
#define REQUIRE(x,...)
Definition: SGIO.h:206
index_t num_cols
Definition: SGMatrix.h:376
index_t num_rows
Definition: SGMatrix.h:374
shogun matrix
index_t vlen
Definition: SGVector.h:494
#define SG_GCDEBUG(...)
Definition: SGIO.h:102
virtual const char * get_name() const
virtual SGVector< complex128_t > solve(CLinearOperator< complex128_t > *A, SGVector< float64_t > b)
double float64_t
Definition: common.h:50
Class that represents a dense-matrix linear operator. It computes matrix-vector product in its apply...
Abstract template base class that provides an abstract solve method for linear systems, that takes a linear operator , a vector , solves the system and returns the vector .
Definition: LinearSolver.h:25
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
#define SG_WARNING(...)
Definition: SGIO.h:128

SHOGUN Machine Learning Toolbox - Documentation