Go to the documentation of this file.00001
00002 #ifndef vnl_svd_economy_txx_
00003 #define vnl_svd_economy_txx_
00004
00005 #include "vnl_svd_economy.h"
00006
00007 #include <vcl_iostream.h>
00008 #include <vcl_algorithm.h>
00009 #include <vcl_cmath.h>
00010
00011 #include <vnl/vnl_fortran_copy.h>
00012 #include <vnl/algo/vnl_netlib.h>
00013 #include <vnl/vnl_matlab_print.h>
00014
00015 #define macro(p, T) \
00016 inline void vnl_linpack_svdc_economy(vnl_netlib_svd_proto(T)) \
00017 { v3p_netlib_##p##svdc_(vnl_netlib_svd_params); }
00018 macro(s, float);
00019 macro(d, double);
00020 macro(c, vcl_complex<float>);
00021 macro(z, vcl_complex<double>);
00022 #undef macro
00023
00024 template <class real_t>
00025 vnl_svd_economy<real_t>::vnl_svd_economy( vnl_matrix<real_t> const& M ) :
00026 m_(M.rows()), n_(M.columns()),
00027 V_(n_,n_),
00028 sv_(n_)
00029 {
00030 vnl_fortran_copy<real_t> X(M);
00031
00032 int mm = vcl_min(m_+1L,n_);
00033
00034
00035 vnl_vector<real_t> work(m_, real_t(0));
00036 vnl_vector<real_t> vspace(n_*n_, real_t(0));
00037 vnl_vector<real_t> wspace(mm, real_t(0));
00038 vnl_vector<real_t> espace(n_, real_t(0));
00039
00040
00041 long ldu = 0;
00042 long info = 0;
00043 const long job = 01;
00044 vnl_linpack_svdc_economy((real_t*)X, &m_, &m_, &n_,
00045 wspace.data_block(),
00046 espace.data_block(),
00047 0, &ldu,
00048 vspace.data_block(), &n_,
00049 work.data_block(),
00050 &job, &info);
00051
00052
00053 if (info != 0)
00054 {
00055
00056
00057
00058
00059
00060
00061
00062 M.assert_finite();
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 vcl_cerr << __FILE__ ": suspicious return value (" << info << ") from SVDC\n"
00083 << __FILE__ ": M is " << M.rows() << 'x' << M.cols() << vcl_endl;
00084
00085 vnl_matlab_print(vcl_cerr, M, "M", vnl_matlab_print_format_long);
00086
00087 }
00088 #if 0
00089 else
00090 valid_ = true;
00091 #endif
00092
00093 for (int j = 0; j < mm; ++j)
00094 sv_[j] = vcl_abs(wspace(j));
00095
00096 for (int j = mm; j < n_; ++j)
00097 sv_[j] = 0;
00098
00099 {
00100 const real_t *d = vspace.data_block();
00101 for (int j = 0; j < n_; ++j)
00102 for (int i = 0; i < n_; ++i)
00103 V_[i][j] = *(d++);
00104 }
00105 }
00106
00107 template <class real_t>
00108 vnl_vector<real_t>
00109 vnl_svd_economy<real_t>::nullvector()
00110 {
00111 return V_.get_column( n_ - 1 );
00112 }
00113
00114 #undef VNL_SVD_ECONOMY_INSTANTIATE
00115 #define VNL_SVD_ECONOMY_INSTANTIATE(T) template class vnl_svd_economy<T >
00116
00117 #endif // vnl_svd_economy_txx_