MyraMath
SparseNormalSolver.h
Go to the documentation of this file.
1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
6 #ifndef MYRAMATH_MULTIFRONTAL_SPARSENORMALSOLVER_H
7 #define MYRAMATH_MULTIFRONTAL_SPARSENORMALSOLVER_H
8 
14 #include <myramath/MYRAMATH_EXPORT.h>
16 
18 
24 
25 namespace myra {
26 
27 // Forward declarations, A type.
28 template<class Number> class SparseMatrixRange;
29 template<class Number> class CSparseMatrixRange;
30 
31 // Forward declarations, X/B types.
32 template <class Number> class Matrix;
33 template <class Number> class MatrixRange;
34 template <class Number> class CMatrixRange;
35 template <class Number> class Vector;
36 template <class Number> class VectorRange;
37 template <class Number> class CVectorRange;
38 
39 // Forward declarations, serialization.
40 class InputStream;
41 class OutputStream;
42 
43 // Reflects the underlying cholesky-like solver to use.
44 template<class Number> class ReflectNormal;
45 /*
46 template<> class ReflectNormal<float>
47  { public: typedef SparseRCholeskySolver<float> type; };
48 template<> class ReflectNormal<double>
49  { public: typedef SparseRCholeskySolver<double> type; };
50 template<> class ReflectNormal<std::complex<float> >
51  { public: typedef SparseZCholeskySolver<float> type; };
52 template<> class ReflectNormal<std::complex<double> >
53  { public: typedef SparseZCholeskySolver<double> type; };
54 */
55 template<> class ReflectNormal<float>
56  { public: typedef SparseRLDLTSolver<float> type; };
57 template<> class ReflectNormal<double>
58  { public: typedef SparseRLDLTSolver<double> type; };
59 template<> class ReflectNormal<std::complex<float> >
60  { public: typedef SparseZLDLHSolver<float> type; };
61 template<> class ReflectNormal<std::complex<double> >
62  { public: typedef SparseZLDLHSolver<double> type; };
63 
64 // Sparse direct solver for general systems, solves the normal equations.
65 template<class Number> class MYRAMATH_EXPORT SparseNormalSolver
66  {
67  public:
68 
69  // Useful typedefs for various dense/sparse ranges.
70  typedef typename ReflectPrecision<Number>::type Precision;
71  typedef MatrixRange<Number> DRange; // Dense range type (e.g. right hand sides)
72  typedef CSparseMatrixRange<Number> SRange; // Sparse range type (e.g. underlying A)
73 
74  // Typedef for Options pack.
75  typedef ::myra::multifrontal::Options Options;
76 
78  SparseNormalSolver(const SRange& in_A, Options options = defaults());
79 
81  explicit SparseNormalSolver(InputStream& in);
82 
84  void write(OutputStream& out) const;
85 
88 
90  int size() const;
91 
93  // side = Solve by A from the 'L'eft or from the 'R'ight?
94  // op = Apply an operation to A? ('T'ranspose, 'H'ermitian, 'C'onjugate or 'N'othing)
95  void solve(const DRange& B, char side = 'L', char op = 'N', Options options = defaults().set_nthreads(1)) const;
96 
98  // side = Solve by A from the 'L'eft or from the 'R'ight?
99  // op = Apply an operation to A? ('T'ranspose, 'H'ermitian, 'C'onjugate or 'N'othing)
100  // Note, this is more expensive because it calls solve() multiple times, and spmm() too.
101  // Returns the history of the relative residual, frobenius(A*X-B)/frobenius(B)
102  std::vector<Precision> refine(const DRange& B, char side = 'L', char op = 'N', Precision tolerance = default_tolerance(), int iterations = default_iterations(), Options options = defaults().set_nthreads(1)) const;
103 
104  private:
105 
106  // Returns default options.
107  static Options defaults();
108 
109  // Default parameters for refine().
110  static Precision default_tolerance();
111  static int default_iterations();
112 
113  // Holds forward operator A.
116 
117  // Underlying cholesky-like solver.
118  typedef typename ReflectNormal<Number>::type Solver;
119  Solver solver;
120 
121  };
122 
123 // ReflectNumber for SparseNormalSolver
124 template<class Number> class ReflectNumber <SparseNormalSolver<Number> >
125  { public: typedef Number type; };
126 
127 } // namespace myra
128 
129 #endif
Reflects Number trait for a Container, containers of Numbers (Matrix&#39;s, Vector&#39;s, etc) should special...
Definition: Number.h:55
Options pack for routines in /multifrontal.
Definition: Options.h:24
Sparse direct solver suitable for complex hermitian indefinite systems.
A std::hash for JobID, so it can be in a std::unordered_set / std::unordered_map. ...
Definition: hashes.h:30
Sparse direct solver suitable for hermitian positive definite systems.
Sparse direct solver suitable for real symmetric indefinite systems.
Definition: SparseRLDLTSolver.h:61
Sparse direct solver suitable for complex hermitian indefinite systems.
Definition: SparseZLDLHSolver.h:60
General purpose compressed-sparse-column (CSC) container.
Definition: syntax.dox:1
Definition: SparseNormalSolver.h:65
Abstraction layer, serializable objects write themselves to these.
Definition: Streams.h:39
Various utility functions/classes related to scalar Number types.
Represents a mutable MatrixRange.
Definition: conjugate.h:26
Abstraction layer, deserializable objects read themselves from these.
Definition: Streams.h:47
Represents a const SparseMatrixRange.
Definition: bothcat.h:24
Options pack for routines in /multifrontal.
Sparse direct solver suitable for real symmetric positive definite systems.
Reflects Precision trait for a Number, scalar Number types should specialize it.
Definition: Number.h:33
Sparse direct solver suitable for real symmetric indefinite systems.
Stores an IxJ matrix A in compressed sparse column format.
Definition: bothcat.h:23
Definition: SparseNormalSolver.h:44