Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 39b82d57 authored by hhakim's avatar hhakim
Browse files

Add optional arguments to power_iteration: output buffer for copying the...

Add optional arguments to power_iteration: output buffer for copying the eigenvector and a boolean for random initialization.
parent ffbea0dc
No related branches found
No related tags found
No related merge requests found
...@@ -156,8 +156,12 @@ namespace Faust ...@@ -156,8 +156,12 @@ namespace Faust
template<typename FPP, typename FPP2 = double> template<typename FPP, typename FPP2 = double>
FPP power_iteration(const MatDense<FPP,Cpu> & A, const faust_unsigned_int nbr_iter_max,FPP2 threshold,faust_int & flag,BlasHandle<Cpu> & handle) FPP power_iteration(const MatDense<FPP,Cpu> & A, const faust_unsigned_int nbr_iter_max,FPP2 threshold,faust_int & flag,BlasHandle<Cpu> & handle)
{power_iteration(A,nbr_iter_max,threshold,flag);} {power_iteration(A,nbr_iter_max,threshold,flag);}
template<typename FPP, typename FPP2 = double> /**
FPP power_iteration(const LinearOperator<FPP,Cpu> & A, const faust_unsigned_int nbr_iter_max,FPP2 threshold,int & flag); * \param out_vec_data: output buffer for the eigenvector approximate.
* \param rand_init: true for random initialization (else the vector is full of ones).
*/
template<typename FPP, typename FPP2 = double>
FPP power_iteration(const LinearOperator<FPP,Cpu> & A, const faust_unsigned_int nbr_iter_max,FPP2 threshold,int & flag, FPP* out_vec_data=nullptr, bool rand_init=false);
//! surcharge d'operateur * pour multiplier des matrices et des vecteurs //! surcharge d'operateur * pour multiplier des matrices et des vecteurs
......
...@@ -786,9 +786,9 @@ A.t_add_ext.stop(); ...@@ -786,9 +786,9 @@ A.t_add_ext.stop();
// compute the biggest eigenvalue of A, A must be semi-definite positive // compute the largest eigenvalue of A, A must be semi-definite positive
template<typename FPP, typename FPP2> template<typename FPP, typename FPP2>
FPP Faust::power_iteration(const Faust::LinearOperator<FPP,Cpu> & A, const faust_unsigned_int nbr_iter_max, FPP2 threshold, int & flag) FPP Faust::power_iteration(const Faust::LinearOperator<FPP,Cpu> & A, const faust_unsigned_int nbr_iter_max, FPP2 threshold, int & flag, FPP* out_vec/*=nullptr*/, const bool rand_init/*=false*/)
{ {
#ifdef __COMPILE_TIMERS__ #ifdef __COMPILE_TIMERS__
A.t_power_iteration.start(); A.t_power_iteration.start();
...@@ -814,7 +814,10 @@ FPP Faust::power_iteration(const Faust::LinearOperator<FPP,Cpu> & A, const faus ...@@ -814,7 +814,10 @@ FPP Faust::power_iteration(const Faust::LinearOperator<FPP,Cpu> & A, const faus
handleError("linear_algebra "," power_iteration : Faust::Transform<FPP,Cpu> 1 must be a squared matrix"); handleError("linear_algebra "," power_iteration : Faust::Transform<FPP,Cpu> 1 must be a squared matrix");
} }
Faust::Vect<FPP,Cpu> xk(nb_col); Faust::Vect<FPP,Cpu> xk(nb_col);
xk.setOnes(); if(rand_init)
xk.setRand();
else
xk.setOnes();
Faust::Vect<FPP,Cpu> xk_norm(nb_col); Faust::Vect<FPP,Cpu> xk_norm(nb_col);
FPP lambda_old=1.0; FPP lambda_old=1.0;
FPP lambda = 0.0; FPP lambda = 0.0;
...@@ -836,10 +839,10 @@ FPP Faust::power_iteration(const Faust::LinearOperator<FPP,Cpu> & A, const faus ...@@ -836,10 +839,10 @@ FPP Faust::power_iteration(const Faust::LinearOperator<FPP,Cpu> & A, const faus
A.t_power_iteration.stop(); A.t_power_iteration.stop();
#endif #endif
return lambda; if(out_vec)
memcpy(out_vec, xk_norm.getData(), sizeof(FPP)*xk_norm.size());
return lambda;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment