Mentions légales du service

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

Implement MatButterfly::toMatSparse along with its unit test.

parent 694ada4d
Branches
No related tags found
No related merge requests found
...@@ -162,6 +162,15 @@ void testNorm2(const MatButterfly<FPP, Cpu>& butterflyMat, const MatSparse<FPP, ...@@ -162,6 +162,15 @@ void testNorm2(const MatButterfly<FPP, Cpu>& butterflyMat, const MatSparse<FPP,
std::cout << "MatButterfly fro-norm OK" << std::endl; std::cout << "MatButterfly fro-norm OK" << std::endl;
} }
void testToMatSparse(const MatButterfly<FPP, Cpu>& butterflyMat, const MatSparse<FPP, Cpu>& spButterflyMat)
{
auto convSpButterflyMat = butterflyMat.toMatSparse();
assert(verifyMatEq(MatDense<FPP, Cpu>(convSpButterflyMat), MatDense<FPP, Cpu>(spButterflyMat), 1e-6));
std::cout << "MatButterfly::toMatSparse OK" << std::endl;
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int log2size = 4; int log2size = 4;
...@@ -228,5 +237,6 @@ int main(int argc, char** argv) ...@@ -228,5 +237,6 @@ int main(int argc, char** argv)
testScalMul(butterflyMat, spButterflyMat); testScalMul(butterflyMat, spButterflyMat);
testNorm2(butterflyMat, spButterflyMat); testNorm2(butterflyMat, spButterflyMat);
testToMatSparse(butterflyMat, spButterflyMat);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
...@@ -90,7 +90,9 @@ namespace Faust ...@@ -90,7 +90,9 @@ namespace Faust
std::list<std::pair<int,int>> nonzeros_indices() const; std::list<std::pair<int,int>> nonzeros_indices() const;
void setZeros(); void setZeros();
bool containsNaN()const; bool containsNaN()const;
const FPP& operator()(faust_unsigned_int i, faust_unsigned_int j)const ; const FPP& operator()(faust_unsigned_int i, faust_unsigned_int j)const;
MatSparse<FPP, Cpu> toMatSparse() const;
void faust_gemm(const MatDense<FPP,Cpu> & B, MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB)const; //from LinearOperator void faust_gemm(const MatDense<FPP,Cpu> & B, MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB)const; //from LinearOperator
}; };
......
...@@ -353,7 +353,6 @@ namespace Faust ...@@ -353,7 +353,6 @@ namespace Faust
template<typename FPP> template<typename FPP>
void MatButterfly<FPP, Cpu>::setZeros() void MatButterfly<FPP, Cpu>::setZeros()
{ {
//TODO
} }
template<typename FPP> template<typename FPP>
...@@ -368,4 +367,31 @@ namespace Faust ...@@ -368,4 +367,31 @@ namespace Faust
//TODO //TODO
} }
template<typename FPP>
MatSparse<FPP, Cpu> MatButterfly<FPP, Cpu>::toMatSparse() const
{
auto s = this->getNbRow();
auto k = s >> (level + 1); // D2 diagonal offset
vector<Eigen::Triplet<FPP> > tripletList;
const FPP *d1_ptr, *d2_ptr;
d1_ptr = D1.diagonal().data();
d2_ptr = D2.diagonal().data();
for(int i=0; i < s; i++)
{
tripletList.push_back(Eigen::Triplet<FPP>(i, i, d1_ptr[i]));
if((i / k) & 1)
{
// d2 coeff is the first elt of row i
tripletList.push_back(Eigen::Triplet<FPP>(i, i - k, d2_ptr[i]));
}
else
{
// d2 coeff is the last elt of row i
tripletList.push_back(Eigen::Triplet<FPP>(i, i + k, d2_ptr[i]));
}
}
return MatSparse<FPP, Cpu>(tripletList, s, s);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment