Mentions légales du service

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

Add MatDense::rowwise_min(), rowwise_min(int* col_indices), MatDense::min() and a test.

It will be useful for FGFT Jocobi algorithms.
parent df6f1f1e
No related branches found
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) foreach(FILE faust_mult faust_mult_cplx test_Vect_min test_MatDense_min)
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_real_distribution<> dis(1.0, 200);
FPP *data = new FPP[9];
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++)
data[3*j+i] = dis(gen);
}
MatDense<FPP,Cpu> M(data, 3, 3);
cout << "Random matrix for the test:" << endl;
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++)
cout << M.getData()[j*3+i] << " ";
cout << endl;
}
cout << "M.min():" << M.min() << endl;
int indices[3];
cout << "M.rowwise_min()" << endl;
Faust::Vect<FPP, Cpu> vec = M.rowwise_min();
vec.Display();
cout << "M.rowwise_min(indices)" << endl;
Faust::Vect<FPP, Cpu> vec2 = M.rowwise_min(indices);
vec2.Display();
cout << "indices: " << endl;
for(int i=0;i<3;i++)
cout << " " << indices[i] << endl;
return 0;
}
...@@ -398,6 +398,11 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & ...@@ -398,6 +398,11 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> &
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;
Faust::MatDense<FPP,Cpu>* get_rows(faust_unsigned_int* row_ids, faust_unsigned_int n) const; Faust::MatDense<FPP,Cpu>* get_rows(faust_unsigned_int* row_ids, faust_unsigned_int n) const;
FPP min() const {return mat.minCoeff();}
Faust::Vect<FPP,Cpu> rowwise_min() const;
Faust::Vect<FPP,Cpu> rowwise_min(int* col_indices) const;
void operator=(MatDense<FPP,Cpu> const& A); void operator=(MatDense<FPP,Cpu> const& A);
template<typename FPP1> template<typename FPP1>
......
...@@ -167,7 +167,7 @@ void Faust::MatDense<FPP,Cpu>::setEyes() ...@@ -167,7 +167,7 @@ void Faust::MatDense<FPP,Cpu>::setEyes()
{ {
setZeros(); setZeros();
FPP* ptr_data = getData(); FPP* ptr_data = getData();
for (int i=0 ; i<min(this->dim1,this->dim2); i++) for (int i=0 ; i<std::min(this->dim1,this->dim2); i++)
ptr_data[i*this->dim1+i] = FPP(1.0); ptr_data[i*this->dim1+i] = FPP(1.0);
if (this->dim1 == this->dim2) if (this->dim1 == this->dim2)
isIdentity = true; isIdentity = true;
...@@ -920,6 +920,22 @@ Faust::MatDense<FPP,Cpu>* Faust::MatDense<FPP,Cpu>::get_rows(faust_unsigned_int* ...@@ -920,6 +920,22 @@ Faust::MatDense<FPP,Cpu>* Faust::MatDense<FPP,Cpu>::get_rows(faust_unsigned_int*
return rows; return rows;
} }
template<typename FPP>
Faust::Vect<FPP,Cpu> Faust::MatDense<FPP,Cpu>::rowwise_min() const
{
return Faust::Vect<FPP,Cpu>(this->getNbCol(), mat.rowwise().minCoeff().eval().data());
}
template<typename FPP>
Faust::Vect<FPP,Cpu> Faust::MatDense<FPP,Cpu>::rowwise_min(int* col_indices) const
{
Faust::Vect<FPP,Cpu> vec(this->getNbRow());
for(int i=0;i<this->getNbRow();i++)
vec.getData()[i] = mat.row(i).minCoeff(col_indices+i);
return vec;
}
template<typename FPP> template<typename FPP>
Faust::MatDense<FPP, Cpu>* Faust::MatDense<FPP, Cpu>::randMat(faust_unsigned_int num_rows, faust_unsigned_int num_cols) Faust::MatDense<FPP, Cpu>* Faust::MatDense<FPP, Cpu>::randMat(faust_unsigned_int num_rows, faust_unsigned_int num_cols)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment