Mentions légales du service

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

Add MatDense::get_row() with a test.

MatDense::get_col() was already implemented but not get_row().
parent 4174df30
Branches
No related tags found
No related merge requests found
...@@ -156,7 +156,7 @@ endif() ...@@ -156,7 +156,7 @@ endif()
foreach(TEST_FPP float double) foreach(TEST_FPP float double)
foreach(FILE faust_mult faust_mult_cplx test_Vect_min test_MatDense_min) foreach(FILE faust_mult faust_mult_cplx test_Vect_min test_MatDense_min test_MatDense_get_row)
set(TEST_BIN_FILE ${FILE}_${TEST_FPP}) set(TEST_BIN_FILE ${FILE}_${TEST_FPP})
set(TEST_FILE_CPP ${TEST_BIN_FILE}.cpp) set(TEST_FILE_CPP ${TEST_BIN_FILE}.cpp)
message(STATUS ${TEST_FILE_CPP}) message(STATUS ${TEST_FILE_CPP})
......
#include "faust_MatDense.h"
#include <complex>
#include <random>
using namespace Faust;
typedef @TEST_FPP@ FPP;
int main()
{
std::random_device rd; //random device gives the seed
std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
std::uniform_int_distribution<> dis(0, 2);
MatDense<FPP,Cpu>* M = MatDense<FPP,Cpu>::randMat(3,4);
cout << "Random matrix for the test:" << endl;
for(int i=0;i<3;i++) {
for(int j=0;j<4;j++)
cout << M->getData()[j*3+i] << " ";
cout << endl;
}
int rid = dis(gen);
Faust::Vect<FPP,Cpu> row = M->get_row(rid);
cout << "row id: " << rid << endl;
cout << "row: " << endl;
row.Display();
return 0;
}
...@@ -394,6 +394,7 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & ...@@ -394,6 +394,7 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> &
FPP normL1(const bool transpose=false) const; FPP normL1(const bool transpose=false) const;
FPP normL1(faust_unsigned_int&, const bool transpose=false) const; FPP normL1(faust_unsigned_int&, const bool transpose=false) const;
Faust::Vect<FPP,Cpu> get_col(faust_unsigned_int id) const; Faust::Vect<FPP,Cpu> get_col(faust_unsigned_int id) const;
Faust::Vect<FPP,Cpu> get_row(faust_unsigned_int id) const;
Faust::MatDense<FPP,Cpu>* get_cols(faust_unsigned_int start_col_id, faust_unsigned_int num_cols) const; Faust::MatDense<FPP,Cpu>* get_cols(faust_unsigned_int start_col_id, faust_unsigned_int num_cols) const;
Faust::MatDense<FPP,Cpu>* get_cols(faust_unsigned_int* col_ids, faust_unsigned_int n) const; Faust::MatDense<FPP,Cpu>* get_cols(faust_unsigned_int* col_ids, faust_unsigned_int n) const;
Faust::MatDense<FPP,Cpu>* get_rows(faust_unsigned_int start_row_id, faust_unsigned_int num_rows) const; Faust::MatDense<FPP,Cpu>* get_rows(faust_unsigned_int start_row_id, faust_unsigned_int num_rows) const;
......
...@@ -870,6 +870,16 @@ Faust::Vect<FPP,Cpu> Faust::MatDense<FPP,Cpu>::get_col(faust_unsigned_int id) co ...@@ -870,6 +870,16 @@ Faust::Vect<FPP,Cpu> Faust::MatDense<FPP,Cpu>::get_col(faust_unsigned_int id) co
return Vect<FPP,Cpu>(this->getNbRow(),vec.data()); return Vect<FPP,Cpu>(this->getNbRow(),vec.data());
} }
template<typename FPP>
Faust::Vect<FPP,Cpu> Faust::MatDense<FPP,Cpu>::get_row(faust_unsigned_int id) const
{
if(id > this->getNbRow())
handleError("Faust::MatDense", "Too big row index passed to get_col().");
Eigen::Matrix<FPP, Eigen::Dynamic,1> vec;
vec = mat.row(id);
return Vect<FPP,Cpu>(this->getNbCol(),vec.data());
}
template<typename FPP> template<typename FPP>
Faust::MatDense<FPP,Cpu>* Faust::MatDense<FPP,Cpu>::get_cols(faust_unsigned_int start_col_id, faust_unsigned_int num_cols) const Faust::MatDense<FPP,Cpu>* Faust::MatDense<FPP,Cpu>::get_cols(faust_unsigned_int start_col_id, faust_unsigned_int num_cols) const
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment