Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 0ff2ef60 authored by hhakim's avatar hhakim
Browse files

Handle division by zero error in MatDense::Normalize().

parent 98034e21
No related branches found
No related tags found
No related merge requests found
......@@ -345,7 +345,7 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> &
Real<FPP> norm() const {return mat.norm();}
//! \brief Normalize the matrix according to its Frobenius norm
void normalize() {scalarMultiply(FPP(1.0/norm()));}
void normalize();
//! \param nbr_iter_max : maximum number of iteration for the power algo
......
......@@ -1050,6 +1050,16 @@ Real<FPP> Faust::MatDense<FPP, Cpu>::normL1(const bool transpose /* default fals
return normL1(id, transpose);
}
template<typename FPP>
void Faust::MatDense<FPP,Cpu>::normalize()
{
auto n = norm();
if(n != FPP(0))
scalarMultiply(FPP(1.0/n));
else
throw std::domain_error("the norm is zero, can't normalize");
}
template<typename FPP>
Faust::Vect<FPP,Cpu> Faust::MatDense<FPP,Cpu>::get_col(faust_unsigned_int id) const
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment