Mercurial > hg > segmenter-vamp-plugin
comparison armadillo-3.900.4/include/armadillo_bits/fn_svd.hpp @ 49:1ec0e2823891
Switch to using subrepo copies of qm-dsp, nnls-chroma, vamp-plugin-sdk; update Armadillo version; assume build without external BLAS/LAPACK
author | Chris Cannam |
---|---|
date | Thu, 13 Jun 2013 10:25:24 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
48:69251e11a913 | 49:1ec0e2823891 |
---|---|
1 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) | |
2 // Copyright (C) 2009-2011 Conrad Sanderson | |
3 // | |
4 // This Source Code Form is subject to the terms of the Mozilla Public | |
5 // License, v. 2.0. If a copy of the MPL was not distributed with this | |
6 // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
7 | |
8 | |
9 //! \addtogroup fn_svd | |
10 //! @{ | |
11 | |
12 | |
13 | |
14 template<typename T1> | |
15 inline | |
16 bool | |
17 svd | |
18 ( | |
19 Col<typename T1::pod_type>& S, | |
20 const Base<typename T1::elem_type,T1>& X, | |
21 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0 | |
22 ) | |
23 { | |
24 arma_extra_debug_sigprint(); | |
25 arma_ignore(junk); | |
26 | |
27 // it doesn't matter if X is an alias of S, as auxlib::svd() makes a copy of X | |
28 | |
29 const bool status = auxlib::svd(S, X); | |
30 | |
31 if(status == false) | |
32 { | |
33 S.reset(); | |
34 arma_bad("svd(): failed to converge", false); | |
35 } | |
36 | |
37 return status; | |
38 } | |
39 | |
40 | |
41 | |
42 template<typename T1> | |
43 inline | |
44 Col<typename T1::pod_type> | |
45 svd | |
46 ( | |
47 const Base<typename T1::elem_type,T1>& X, | |
48 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0 | |
49 ) | |
50 { | |
51 arma_extra_debug_sigprint(); | |
52 arma_ignore(junk); | |
53 | |
54 Col<typename T1::pod_type> out; | |
55 | |
56 const bool status = auxlib::svd(out, X); | |
57 | |
58 if(status == false) | |
59 { | |
60 out.reset(); | |
61 arma_bad("svd(): failed to converge"); | |
62 } | |
63 | |
64 return out; | |
65 } | |
66 | |
67 | |
68 | |
69 template<typename T1> | |
70 inline | |
71 bool | |
72 svd | |
73 ( | |
74 Mat<typename T1::elem_type>& U, | |
75 Col<typename T1::pod_type >& S, | |
76 Mat<typename T1::elem_type>& V, | |
77 const Base<typename T1::elem_type,T1>& X, | |
78 const char* method = "", | |
79 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0 | |
80 ) | |
81 { | |
82 arma_extra_debug_sigprint(); | |
83 arma_ignore(junk); | |
84 | |
85 arma_debug_check | |
86 ( | |
87 ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)(&V)) ), | |
88 "svd(): two or more output objects are the same object" | |
89 ); | |
90 | |
91 bool use_divide_and_conquer = false; | |
92 | |
93 const char sig = method[0]; | |
94 | |
95 switch(sig) | |
96 { | |
97 case '\0': | |
98 case 's': | |
99 break; | |
100 | |
101 case 'd': | |
102 use_divide_and_conquer = true; | |
103 break; | |
104 | |
105 default: | |
106 { | |
107 arma_stop("svd(): unknown method specified"); | |
108 return false; | |
109 } | |
110 } | |
111 | |
112 // auxlib::svd() makes an internal copy of X | |
113 const bool status = (use_divide_and_conquer == false) ? auxlib::svd(U, S, V, X) : auxlib::svd_dc(U, S, V, X); | |
114 | |
115 if(status == false) | |
116 { | |
117 U.reset(); | |
118 S.reset(); | |
119 V.reset(); | |
120 arma_bad("svd(): failed to converge", false); | |
121 } | |
122 | |
123 return status; | |
124 } | |
125 | |
126 | |
127 | |
128 template<typename T1> | |
129 inline | |
130 bool | |
131 svd_econ | |
132 ( | |
133 Mat<typename T1::elem_type>& U, | |
134 Col<typename T1::pod_type >& S, | |
135 Mat<typename T1::elem_type>& V, | |
136 const Base<typename T1::elem_type,T1>& X, | |
137 const char mode = 'b', | |
138 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0 | |
139 ) | |
140 { | |
141 arma_extra_debug_sigprint(); | |
142 arma_ignore(junk); | |
143 | |
144 arma_debug_check | |
145 ( | |
146 ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)(&V)) ), | |
147 "svd_econ(): two or more output objects are the same object" | |
148 ); | |
149 | |
150 arma_debug_check | |
151 ( | |
152 ( (mode != 'l') && (mode != 'r') && (mode != 'b') ), | |
153 "svd_econ(): parameter 'mode' is incorrect" | |
154 ); | |
155 | |
156 | |
157 // auxlib::svd_econ() makes an internal copy of X | |
158 const bool status = auxlib::svd_econ(U, S, V, X, mode); | |
159 | |
160 if(status == false) | |
161 { | |
162 U.reset(); | |
163 S.reset(); | |
164 V.reset(); | |
165 arma_bad("svd_econ(): failed to converge", false); | |
166 } | |
167 | |
168 return status; | |
169 } | |
170 | |
171 | |
172 | |
173 template<typename T1> | |
174 arma_deprecated | |
175 inline | |
176 bool | |
177 svd_thin | |
178 ( | |
179 Mat<typename T1::elem_type>& U, | |
180 Col<typename T1::pod_type >& S, | |
181 Mat<typename T1::elem_type>& V, | |
182 const Base<typename T1::elem_type,T1>& X, | |
183 const char mode = 'b', | |
184 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0 | |
185 ) | |
186 { | |
187 arma_ignore(junk); | |
188 | |
189 return svd_econ(U,S,V,X,mode); | |
190 } | |
191 | |
192 | |
193 | |
194 //! @} |