1 /////////////////////////////////////////////////////////////////////////////// 2 // // 3 // The Template Matrix/Vector Library for C++ was created by Mike Jarvis // 4 // Copyright (C) 1998 - 2016 // 5 // All rights reserved // 6 // // 7 // The project is hosted at https://code.google.com/p/tmv-cpp/ // 8 // where you can find the current version and current documention. // 9 // // 10 // For concerns or problems with the software, Mike may be contacted at // 11 // mike_jarvis17 [at] gmail. // 12 // // 13 // This software is licensed under a FreeBSD license. The file // 14 // TMV_LICENSE should have bee included with this distribution. // 15 // It not, you can get a copy from https://code.google.com/p/tmv-cpp/. // 16 // // 17 // Essentially, you can use this software however you want provided that // 18 // you include the TMV_LICENSE file in any distribution that uses it. // 19 // // 20 /////////////////////////////////////////////////////////////////////////////// 21 22 23 //--------------------------------------------------------------------------- 24 // 25 // This file defines the TMV Divider class. 26 // 27 // There are currently 4 algorithms for doing division (and Inverse and Det) 28 // 29 // LU Decomposition 30 // QR Decomposition (with or without Permutation) 31 // Singular Value Decomposition (compact or full) 32 // Cholskey (only for SymMatrix) 33 // 34 // To tell a Matrix to use a particular algorithm, use the command: 35 // m.divideUsing(ALG) 36 // where ALG is LU, QR, QRP, SV or CH for the algorithms above. 37 // 38 // The default algorithm is LU for square matrices or QR for non-square. 39 // 40 // By default, the appropriate Divider class is created the first 41 // time it is needed (eg. when the statement v = b/m is called). 42 // However, you can also setup the Divider class beforehand manually 43 // by calling m.setDiv(). 44 // 45 // You can also query whether the Divider class is already set up. 46 // This will only be true, if it was previously set up, _and_ the 47 // Matrix hasn't been modified since then. 48 // 49 // If you want access to the various Divider functions directly, 50 // They can be accessed by: 51 // 52 // m.lud() 53 // m.qrd() 54 // m.svd() 55 // m.chd() 56 // 57 // The one of these that is probably most useful to access is svd(), 58 // since it is generally a good idea to look for small 59 // singular values and zero them out before using SVD for division. 60 // 61 // To set to zero all singular value which are less than thresh * 62 // the largest singular value use: 63 // 64 // m.svd()->setThresh(thresh); 65 // 66 // To use only the largest nsv singular values use: 67 // 68 // m.svd()->setTop(nsv); 69 // 70 // Also, the singular value decomposition can be used for principal 71 // component analysis of a Matrix. The principal component vectors 72 // are the rows of V. You can access the decomposition using: 73 // 74 // m.svd()->getU(); 75 // m.svd()->getS(); // A DiagMatrix 76 // m.svd()->getV(); 77 // 78 // 79 80 81 #ifndef TMV_Divider_H 82 #define TMV_Divider_H 83 84 #include "tmv/TMV_BaseMatrix.h" 85 86 namespace tmv { 87 88 template <typename T> 89 class Divider 90 { 91 92 typedef TMV_RealType(T) RT; 93 typedef TMV_ComplexType(T) CT; 94 95 public : 96 Divider()97 Divider() {} ~Divider()98 virtual ~Divider() {} 99 isSV()100 virtual inline bool isSV() const { return false; } 101 102 virtual T det() const =0; 103 virtual RT logDet(T* sign) const =0; 104 virtual void makeInverseATA(MatrixView<T> minv) const =0; 105 virtual bool isSingular() const =0; norm2()106 virtual inline RT norm2() const 107 { TMVAssert(TMV_FALSE); return RT(0); } condition()108 virtual inline RT condition() const 109 { TMVAssert(TMV_FALSE); return RT(0); } 110 111 #define DefDivEq(T) \ 112 virtual void LDivEq(MatrixView<T>) const =0; \ 113 virtual void RDivEq(MatrixView<T>) const =0; \ 114 virtual void makeInverse(MatrixView<T> minv) const =0 115 116 DefDivEq(RT); 117 DefDivEq(CT); 118 #undef DefDivEq 119 120 #define DefDiv(T1,T2) \ 121 virtual void LDiv(const GenMatrix<T1>& b, MatrixView<T2> x) const =0; \ 122 virtual void RDiv(const GenMatrix<T1>& b, MatrixView<T2> x) const =0 123 124 DefDiv(RT,RT); 125 DefDiv(RT,CT); 126 DefDiv(CT,CT); 127 #undef DefDiv 128 129 virtual bool checkDecomp( 130 const BaseMatrix<T>& m, std::ostream* fout) const=0; 131 }; 132 133 template <typename T> TMV_Text(const Divider<T> & d)134 inline std::string TMV_Text(const Divider<T>& d) 135 { return std::string("Divider<")+TMV_Text(T())+">"; } 136 137 } // namespace tmv 138 139 #endif 140