annotate armadillo-2.4.4/include/armadillo_bits/fn_svd.hpp @ 5:79b343f3e4b8

In thi version the problem of letters assigned to each segment has been solved.
author maxzanoni76 <max.zanoni@eecs.qmul.ac.uk>
date Wed, 11 Apr 2012 13:48:13 +0100
parents 8b6102e2a9b0
children
rev   line source
max@0 1 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
max@0 2 // Copyright (C) 2009-2011 Conrad Sanderson
max@0 3 //
max@0 4 // This file is part of the Armadillo C++ library.
max@0 5 // It is provided without any warranty of fitness
max@0 6 // for any purpose. You can redistribute this file
max@0 7 // and/or modify it under the terms of the GNU
max@0 8 // Lesser General Public License (LGPL) as published
max@0 9 // by the Free Software Foundation, either version 3
max@0 10 // of the License or (at your option) any later version.
max@0 11 // (see http://www.opensource.org/licenses for more info)
max@0 12
max@0 13
max@0 14 //! \addtogroup fn_svd
max@0 15 //! @{
max@0 16
max@0 17
max@0 18
max@0 19 template<typename T1>
max@0 20 inline
max@0 21 bool
max@0 22 svd
max@0 23 (
max@0 24 Col<typename T1::pod_type>& S,
max@0 25 const Base<typename T1::elem_type,T1>& X,
max@0 26 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
max@0 27 )
max@0 28 {
max@0 29 arma_extra_debug_sigprint();
max@0 30 arma_ignore(junk);
max@0 31
max@0 32 // it doesn't matter if X is an alias of S, as auxlib::svd() makes a copy of X
max@0 33
max@0 34 const bool status = auxlib::svd(S, X);
max@0 35
max@0 36 if(status == false)
max@0 37 {
max@0 38 S.reset();
max@0 39 arma_bad("svd(): failed to converge", false);
max@0 40 }
max@0 41
max@0 42 return status;
max@0 43 }
max@0 44
max@0 45
max@0 46
max@0 47 template<typename T1>
max@0 48 inline
max@0 49 Col<typename T1::pod_type>
max@0 50 svd
max@0 51 (
max@0 52 const Base<typename T1::elem_type,T1>& X,
max@0 53 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
max@0 54 )
max@0 55 {
max@0 56 arma_extra_debug_sigprint();
max@0 57 arma_ignore(junk);
max@0 58
max@0 59 Col<typename T1::pod_type> out;
max@0 60
max@0 61 const bool status = auxlib::svd(out, X);
max@0 62
max@0 63 if(status == false)
max@0 64 {
max@0 65 out.reset();
max@0 66 arma_bad("svd(): failed to converge");
max@0 67 }
max@0 68
max@0 69 return out;
max@0 70 }
max@0 71
max@0 72
max@0 73
max@0 74 template<typename T1>
max@0 75 inline
max@0 76 bool
max@0 77 svd
max@0 78 (
max@0 79 Mat<typename T1::elem_type>& U,
max@0 80 Col<typename T1::pod_type >& S,
max@0 81 Mat<typename T1::elem_type>& V,
max@0 82 const Base<typename T1::elem_type,T1>& X,
max@0 83 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
max@0 84 )
max@0 85 {
max@0 86 arma_extra_debug_sigprint();
max@0 87 arma_ignore(junk);
max@0 88
max@0 89 typedef typename T1::elem_type eT;
max@0 90
max@0 91 arma_debug_check
max@0 92 (
max@0 93 ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)(&V)) ),
max@0 94 "svd(): two or more output objects are the same object"
max@0 95 );
max@0 96
max@0 97 // auxlib::svd() makes an internal copy of X
max@0 98 const bool status = auxlib::svd(U, S, V, X);
max@0 99
max@0 100 if(status == false)
max@0 101 {
max@0 102 U.reset();
max@0 103 S.reset();
max@0 104 V.reset();
max@0 105 arma_bad("svd(): failed to converge", false);
max@0 106 }
max@0 107
max@0 108 return status;
max@0 109 }
max@0 110
max@0 111
max@0 112
max@0 113 template<typename T1>
max@0 114 inline
max@0 115 bool
max@0 116 svd_econ
max@0 117 (
max@0 118 Mat<typename T1::elem_type>& U,
max@0 119 Col<typename T1::pod_type >& S,
max@0 120 Mat<typename T1::elem_type>& V,
max@0 121 const Base<typename T1::elem_type,T1>& X,
max@0 122 const char mode = 'b',
max@0 123 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
max@0 124 )
max@0 125 {
max@0 126 arma_extra_debug_sigprint();
max@0 127 arma_ignore(junk);
max@0 128
max@0 129 typedef typename T1::elem_type eT;
max@0 130
max@0 131 arma_debug_check
max@0 132 (
max@0 133 ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)(&V)) ),
max@0 134 "svd_econ(): two or more output objects are the same object"
max@0 135 );
max@0 136
max@0 137 arma_debug_check
max@0 138 (
max@0 139 ( (mode != 'l') && (mode != 'r') && (mode != 'b') ),
max@0 140 "svd_econ(): parameter 'mode' is incorrect"
max@0 141 );
max@0 142
max@0 143
max@0 144 // auxlib::svd_econ() makes an internal copy of X
max@0 145 const bool status = auxlib::svd_econ(U, S, V, X, mode);
max@0 146
max@0 147 if(status == false)
max@0 148 {
max@0 149 U.reset();
max@0 150 S.reset();
max@0 151 V.reset();
max@0 152 arma_bad("svd_econ(): failed to converge", false);
max@0 153 }
max@0 154
max@0 155 return status;
max@0 156 }
max@0 157
max@0 158
max@0 159
max@0 160 template<typename T1>
max@0 161 arma_deprecated
max@0 162 inline
max@0 163 bool
max@0 164 svd_thin
max@0 165 (
max@0 166 Mat<typename T1::elem_type>& U,
max@0 167 Col<typename T1::pod_type >& S,
max@0 168 Mat<typename T1::elem_type>& V,
max@0 169 const Base<typename T1::elem_type,T1>& X,
max@0 170 const char mode = 'b',
max@0 171 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
max@0 172 )
max@0 173 {
max@0 174 arma_ignore(junk);
max@0 175
max@0 176 return svd_econ(U,S,V,X,mode);
max@0 177 }
max@0 178
max@0 179
max@0 180
max@0 181 //! @}