Mentions légales du service

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

Add MatDense::lower_tri()/upper_tri() and a small unit test.

parent e8ebf4bf
Branches
Tags
No related merge requests found
......@@ -156,7 +156,7 @@ endif()
foreach(TEST_FPP float double)
foreach(FILE faust_mult faust_mult_cplx test_Vect_min test_MatDense_min test_MatDense_get_row)
foreach(FILE faust_mult faust_mult_cplx test_Vect_min test_MatDense_min test_MatDense_get_row test_MatDense_lower_upper_tri)
set(TEST_BIN_FILE ${FILE}_${TEST_FPP})
set(TEST_FILE_CPP ${TEST_BIN_FILE}.cpp)
message(STATUS ${TEST_FILE_CPP})
......
#define DEBUG_TRI 1
#include "faust_MatDense.h"
#include <complex>
#include <random>
using namespace Faust;
typedef @TEST_FPP@ FPP;
int main()
{
MatDense<FPP,Cpu>* M = MatDense<FPP,Cpu>::randMat(5,5);
Faust::MatSparse<FPP,Cpu> ltri_M = M->lower_tri();
ltri_M.Display();
ltri_M = M->lower_tri(false);
ltri_M.Display();
Faust::MatSparse<FPP,Cpu> utri_M = M->upper_tri();
utri_M.Display();
utri_M = M->upper_tri(false);
utri_M.Display();
return 0;
}
......@@ -448,6 +448,19 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> &
static Faust::MatDense<FPP,Cpu>* randMat(faust_unsigned_int num_rows, faust_unsigned_int num_cols, float density);
//\param : per_row means the density applies for each line rather than globally for the matrix
static Faust::MatDense<FPP,Cpu>* randMat(faust_unsigned_int num_rows, faust_unsigned_int num_cols, float density, bool per_row);
/**
* \brief Returns the lower-triangular matrix with or without the diagonal.
*
* param diag true to include the diagonal, false otherwise.
*/
Faust::MatDense<FPP,Cpu> lower_tri(const bool diag=true) const;
/**
* \brief Returns the upper-triangular matrix with or without the diagonal.
*
* param diag true to include the diagonal, false otherwise.
*/
Faust::MatDense<FPP,Cpu> upper_tri(const bool diag=true) const;
private:
Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic> mat;
bool isIdentity;
......
......@@ -153,6 +153,44 @@ void Faust::MatDense<FPP,Cpu>::check_dim_validity()
#endif
}
template<typename FPP>
Faust::MatDense<FPP,Cpu> Faust::MatDense<FPP,Cpu>::lower_tri(const bool diag) const
{
Faust::MatDense<FPP,Cpu> tri = Faust::MatDense<FPP,Cpu>(this->dim1, this->dim2);
if(diag)
tri.mat = mat.template triangularView<Eigen::Lower>();
else
tri.mat = mat.template triangularView<Eigen::StrictlyLower>();
#ifdef DEBUG_TRI
cout << "MatDense::lower_tri(" << diag << ")" << endl;
cout << "orig. mat.:" << endl;
cout << mat << endl;
cout << "tri. mat.:" << endl;
cout << tri.mat << endl;
#endif
return tri;
}
template<typename FPP>
Faust::MatDense<FPP,Cpu> Faust::MatDense<FPP,Cpu>::upper_tri(const bool diag) const
{
Faust::MatDense<FPP,Cpu> tri = Faust::MatDense<FPP,Cpu>(this->dim1, this->dim2);
if(diag)
tri.mat = mat.template triangularView<Eigen::Upper>();
else
tri.mat = mat.template triangularView<Eigen::StrictlyUpper>();
#ifdef DEBUG_TRI
cout << "MatDense::upper_tri(" << diag << ")" << endl;
cout << "orig. mat.:" << endl;
cout << mat << endl;
cout << "tri. mat.:" << endl;
cout << tri.mat << endl;
#endif
return tri;
}
template<typename FPP>
void Faust::MatDense<FPP,Cpu>::setOnes()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment