Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 741fa57e authored by Nicolas Bellot's avatar Nicolas Bellot Committed by hhakim
Browse files

faust_transform peut etre multiplié avec des matrices denses

parent 9db54c4c
Branches
Tags
No related merge requests found
Showing
with 223 additions and 91 deletions
...@@ -201,11 +201,11 @@ option(BUILD_WRAPPER_MATLAB "Enable building Matlab MEX files." OFF) ...@@ -201,11 +201,11 @@ option(BUILD_WRAPPER_MATLAB "Enable building Matlab MEX files." OFF)
option(BUILD_OPENBLAS "Using openBLAS for matrix and vector computations" OFF) option(BUILD_OPENBLAS "Using openBLAS for matrix and vector computations" OFF)
# different type of files # different type of files
option(BUILD_READ_XML_FILE "Using xml configuration to read xml files" OFF) option(BUILD_READ_XML_FILE "Using xml configuration to read xml files" OFF)
option(BUILD_READ_MAT_FILE "Using matio library to read mat files" OFF) option(BUILD_READ_MAT_FILE "Using matio library to read mat files" ON)
#set(BUILD_READ_XML_FILE OFF) #set(BUILD_READ_XML_FILE OFF)
#set(BUILD_READ_MAT_FILE OFF) #set(BUILD_READ_MAT_FILE OFF)
option(BUILD_WRAPPER_PYTHON "Enable building PyFaust (Python librairie)." ON) option(BUILD_WRAPPER_PYTHON "Enable building PyFaust (Python librairie)." OFF)
#set(BUILD_WRAPPER_PYTHON OFF) #set(BUILD_WRAPPER_PYTHON OFF)
#CMAKE_DEPENDENT_OPTION #CMAKE_DEPENDENT_OPTION
...@@ -511,7 +511,7 @@ set(CMAKE_CXX_FLAGS "") ...@@ -511,7 +511,7 @@ set(CMAKE_CXX_FLAGS "")
#if( (CMAKE_BUILD_TYPE MATCHES "Debug") OR (CMAKE_BUILD_TYPE MATCHES "debug") OR (CMAKE_BUILD_TYPE MATCHES "DEBUG") ) #if( (CMAKE_BUILD_TYPE MATCHES "Debug") OR (CMAKE_BUILD_TYPE MATCHES "debug") OR (CMAKE_BUILD_TYPE MATCHES "DEBUG") )
if (BUILD_DEBUG OR (CMAKE_BUILD_TYPE MATCHES "Debug") OR (CMAKE_BUILD_TYPE MATCHES "debug") OR (CMAKE_BUILD_TYPE MATCHES "DEBUG") ) if (BUILD_DEBUG OR (CMAKE_BUILD_TYPE MATCHES "Debug") OR (CMAKE_BUILD_TYPE MATCHES "debug") OR (CMAKE_BUILD_TYPE MATCHES "DEBUG") )
if (UNIX) if (UNIX)
set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS_DEBUG} -O1") set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS_DEBUG} -O1 -g")
if(APPLE) if(APPLE)
#message(STATUS "APPLE OPERATING SYSTEM") #message(STATUS "APPLE OPERATING SYSTEM")
...@@ -858,6 +858,7 @@ INCLUDE(CPack) ...@@ -858,6 +858,7 @@ INCLUDE(CPack)
#check_cxx_compiler_flag(-std=c++0x COMPILER_SUPPORTS_CXX0X) #check_cxx_compiler_flag(-std=c++0x COMPILER_SUPPORTS_CXX0X)
#if(COMPILER_SUPPORTS_CXX11) #if(COMPILER_SUPPORTS_CXX11)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" CACHE STRING "compile flags" FORCE) # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" CACHE STRING "compile flags" FORCE)
# message(STATUS "C++ compiler supprt c++11")
#elseif(COMPILER_SUPPORTS_CXX0X) #elseif(COMPILER_SUPPORTS_CXX0X)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x" CACHE STRING "compile flags" FORCE) # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x" CACHE STRING "compile flags" FORCE)
#else() #else()
......
...@@ -207,7 +207,10 @@ int main(int argc, char* argv[]) ...@@ -207,7 +207,10 @@ int main(int argc, char* argv[])
outputFilename<<"@FAUST_BIN_TEST_OUTPUT_DIR@/"<<configFileBodyFile<<"_factorisation.mat"; outputFilename<<"@FAUST_BIN_TEST_OUTPUT_DIR@/"<<configFileBodyFile<<"_factorisation.mat";
std::cout<<"**************** WRITING FACTORISATION INTO ****************"<<std::endl; std::cout<<"**************** WRITING FACTORISATION INTO ****************"<<std::endl;
std::cout<<"output filename : "<<outputFilename.str(); std::cout<<"output filename : "<<outputFilename.str();
write_faust_core_into_matfile(hierFactCore,outputFilename.str().c_str(),"fact"); //WARNING no implemented
// hierFactCore.print_file(outputFile.c_str());
// modif NB : v1102 not implemented
//write_faust_core_into_matfile(hierFactCore,outputFilename.str().c_str(),"fact");
//relativeError //relativeError
......
...@@ -292,19 +292,22 @@ void Faust::HierarchicalFact<FPP,DEVICE>::compute_errors() ...@@ -292,19 +292,22 @@ void Faust::HierarchicalFact<FPP,DEVICE>::compute_errors()
{ {
vector<Faust::MatSparse<FPP,DEVICE> > sp_facts; vector<Faust::MatSparse<FPP,DEVICE> > sp_facts;
get_facts(sp_facts); get_facts(sp_facts);
int nb_factor = sp_facts.size();
vector< Faust::MatGeneric<FPP,DEVICE> *> Transform_facts;
Transform_facts.resize(sp_facts.size());
for (int i=0; i < nb_factor;i++)
Transform_facts[i] = sp_facts[i].Clone();
Faust::Transform<FPP,DEVICE> faust_Transform_tmp(Transform_facts, get_lambda());
Faust::Transform<FPP,DEVICE> faust_Transform_tmp(sp_facts, get_lambda());
const Faust::MatDense<FPP,DEVICE> estimate_mat = faust_Transform_tmp.get_product(cublas_handle, cusparse_handle); const Faust::MatDense<FPP,DEVICE> estimate_mat = faust_Transform_tmp.get_product(cublas_handle, cusparse_handle);
Faust::MatDense<FPP,DEVICE> data(palm_global.get_data()); Faust::MatDense<FPP,DEVICE> data(palm_global.get_data());
FPP data_norm = data.norm(); FPP data_norm = data.norm();
data -= estimate_mat; data -= estimate_mat;
errors[0][m_indFact] = estimate_mat.norm()/data_norm; errors[0][m_indFact] = estimate_mat.norm()/data_norm;
errors[1][m_indFact] = faust_Transform_tmp.get_total_nnz()/data.getNbRow()/data.getNbCol(); errors[1][m_indFact] = faust_Transform_tmp.get_total_nnz()/data.getNbRow()/data.getNbCol();
......
...@@ -223,11 +223,28 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & ...@@ -223,11 +223,28 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> &
//\brief : return the number of non-zeros coefficient nnz //\brief : return the number of non-zeros coefficient nnz
faust_unsigned_int getNonZeros()const; faust_unsigned_int getNonZeros()const;
void multiply(Faust::Vect<FPP,Cpu> & vec, char opThis='N') const //! \brief compute MatGeneric-vector multiplication
//! \param vec : the vector
//! \param opThis : character
//! vec = (*this) * vec if opThis='N'
// vec = (*this)' * vec if opThis='T'
void multiply(Faust::Vect<FPP,Cpu> & vec,const char opThis) const
{Faust::gemv((*this),vec,vec,(FPP) 1.0, (FPP) 0.0,opThis);} {Faust::gemv((*this),vec,vec,(FPP) 1.0, (FPP) 0.0,opThis);}
///********* FIN METHOD INHERITED FROM VIRTUAL MATGENERIC *********///
//! \brief compute MatGeneric-MatDense multiplication
//! \param M : the dense matrix
//! \param opThis : character
//! M = (*this) * M if opThis='N'
// M = (*this)' * M if opThis='T'
void multiply(Faust::MatDense<FPP,Cpu> & M, const char opThis) const
{Faust::gemm<FPP>((*this),M,M,1.0,0.0,opThis,'N');}
///********* FIN METHOD INHERITED FROM VIRTUAL MATGENERIC *********///
//! \brief resize the MatDense //! \brief resize the MatDense
...@@ -240,7 +257,11 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & ...@@ -240,7 +257,11 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> &
//! \param nbRow : new number of row and column of the matrix //! \param nbRow : new number of row and column of the matrix
//! \warning nbRow must be greater or equal to 0 //! \warning nbRow must be greater or equal to 0
void resize(const faust_unsigned_int nbRow){resize(nbRow,nbRow);} void resize(const faust_unsigned_int nbRow){resize(nbRow,nbRow);}
//! \brief Check if the dimension of the matrix are consistent, if not throws an error //! \brief Check if the dimension of the matrix are consistent, if not throws an error
void check_dim_validity(); void check_dim_validity();
...@@ -272,10 +293,16 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & ...@@ -272,10 +293,16 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> &
const FPP& operator()(faust_unsigned_int i, faust_unsigned_int j)const{return mat.data()[j*this->dim1+i];} const FPP& operator()(faust_unsigned_int i, faust_unsigned_int j)const{return mat.data()[j*this->dim1+i];}
void operator*=(const Faust::MatSparse<FPP,Cpu>& M); void operator*=(const Faust::MatSparse<FPP,Cpu>& M);
void operator+=(const Faust::MatSparse<FPP,Cpu>& M);
void operator-=(const Faust::MatSparse<FPP,Cpu>& M);
void multiplyLeft(const Faust::MatSparse<FPP,Cpu>& S,const char TransS='N'); void operator+=(const Faust::MatSparse<FPP,Cpu>& M);
// modif NB : v1102 comment useless function
/*
void operator-=(const Faust::MatSparse<FPP,Cpu>& M);
*/
void multiplyLeft(const Faust::MatSparse<FPP,Cpu>& S,const char TransS='N');
FPP* getData(){isZeros=false; isIdentity=false;return mat.data();} FPP* getData(){isZeros=false; isIdentity=false;return mat.data();}
const FPP* getData()const{return mat.data();} const FPP* getData()const{return mat.data();}
...@@ -318,8 +345,7 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & ...@@ -318,8 +345,7 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> &
//! \brief Replace this by (this) * A //! \brief Replace this by (this) * A
void multiplyRight(MatDense<FPP,Cpu> const& A); void multiplyRight(MatDense<FPP,Cpu> const& A);
//! \brief Replace this by A * (*this)
void multiplyLeft(MatDense<FPP,Cpu> const& A);
//! \brief replace this by lambda * (*this) //! \brief replace this by lambda * (*this)
...@@ -360,6 +386,9 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & ...@@ -360,6 +386,9 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> &
void operator/=(FPP lambda){scalarMultiply(1.0/lambda);} void operator/=(FPP lambda){scalarMultiply(1.0/lambda);}
// friend void gemm_core<>(const MatDense<FPP,Cpu> & A,const MatDense<FPP,Cpu> & B, MatDense<FPP,Cpu> & C,const FPP alpha, const FPP beta, char typeA, char typeB); // friend void gemm_core<>(const MatDense<FPP,Cpu> & A,const MatDense<FPP,Cpu> & B, MatDense<FPP,Cpu> & C,const FPP alpha, const FPP beta, char typeA, char typeB);
// friend void multiply<>(const MatDense<FPP,Cpu> & A,const MatDense<FPP,Cpu> & B, MatDense<FPP,Cpu> & C); // friend void multiply<>(const MatDense<FPP,Cpu> & A,const MatDense<FPP,Cpu> & B, MatDense<FPP,Cpu> & C);
// friend void spgemm<>(const Faust::MatSparse<FPP,Cpu> & A,const MatDense<FPP,Cpu> & B, MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB); // friend void spgemm<>(const Faust::MatSparse<FPP,Cpu> & A,const MatDense<FPP,Cpu> & B, MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB);
...@@ -371,7 +400,7 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & ...@@ -371,7 +400,7 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> &
friend void Faust::spgemm<>(const Faust::MatSparse<FPP,Cpu> & A,const MatDense<FPP,Cpu> & B, MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB); friend void Faust::spgemm<>(const Faust::MatSparse<FPP,Cpu> & A,const MatDense<FPP,Cpu> & B, MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB);
friend void Faust::multiply<>(const Faust::Transform<FPP,Cpu> & A, const MatDense<FPP,Cpu> & B, MatDense<FPP,Cpu> & C,const FPP & alpha, char typeA, char typeMult); friend void Faust::multiply<>(const Faust::Transform<FPP,Cpu> & A, const MatDense<FPP,Cpu> & B, MatDense<FPP,Cpu> & C,const FPP & alpha, char typeA, char typeMult);
friend void Faust::gemv<>(const MatDense<FPP,Cpu> & A,const Faust::Vect<FPP,Cpu> & x,Faust::Vect<FPP,Cpu> & y,const FPP & alpha, const FPP & beta, char typeA); friend void Faust::gemv<>(const MatDense<FPP,Cpu> & A,const Faust::Vect<FPP,Cpu> & x,Faust::Vect<FPP,Cpu> & y,const FPP & alpha, const FPP & beta, char typeA);
friend void Faust::MatSparse<FPP,Cpu>::multiply(MatDense<FPP,Cpu> & M,const char opThis) const;
bool estIdentite()const{return isIdentity;} bool estIdentite()const{return isIdentity;}
bool estNulle()const{return isZeros;} bool estNulle()const{return isZeros;}
......
...@@ -306,7 +306,7 @@ t_mult_right.stop(); ...@@ -306,7 +306,7 @@ t_mult_right.stop();
} }
/*
template<typename FPP> template<typename FPP>
void Faust::MatDense<FPP,Cpu>::multiplyLeft(Faust::MatDense<FPP,Cpu> const& A) void Faust::MatDense<FPP,Cpu>::multiplyLeft(Faust::MatDense<FPP,Cpu> const& A)
{ {
...@@ -359,7 +359,7 @@ template<typename FPP> ...@@ -359,7 +359,7 @@ template<typename FPP>
#endif #endif
} }
*/
...@@ -419,57 +419,61 @@ FPP Faust::MatDense<FPP,Cpu>::spectralNorm(const faust_unsigned_int nbr_iter_max ...@@ -419,57 +419,61 @@ FPP Faust::MatDense<FPP,Cpu>::spectralNorm(const faust_unsigned_int nbr_iter_max
template<typename FPP> template<typename FPP>
void Faust::MatDense<FPP,Cpu>::scalarMultiply(FPP const lambda) void Faust::MatDense<FPP,Cpu>::scalarMultiply(FPP const lambda)
{ {
#ifdef __COMPILE_TIMERS__ #ifdef __COMPILE_TIMERS__
t_scalar_multiply.start(); t_scalar_multiply.start();
#endif #endif
mat = lambda * mat; mat = lambda * mat;
#ifdef __COMPILE_TIMERS__ #ifdef __COMPILE_TIMERS__
t_scalar_multiply.stop(); t_scalar_multiply.stop();
#endif #endif
} }
template<typename FPP> template<typename FPP>
void Faust::MatDense<FPP,Cpu>::add(Faust::MatDense<FPP,Cpu> const& A) void Faust::MatDense<FPP,Cpu>::add(Faust::MatDense<FPP,Cpu> const& A)
{ {
#ifdef __COMPILE_TIMERS__ #ifdef __COMPILE_TIMERS__
t_add.start(); t_add.start();
#endif #endif
if ((this->getNbCol() != A.getNbCol()) || (this->getNbRow() != A.getNbRow())) if ((this->getNbCol() != A.getNbCol()) || (this->getNbRow() != A.getNbRow()))
{ {
handleError(m_className, "add : matrix dimension not equal"); handleError(m_className, "add : matrix dimension not equal");
} }
mat = mat + A.mat; mat = mat + A.mat;
isZeros = false; isZeros = false;
isIdentity = false; isIdentity = false;
#ifdef __COMPILE_TIMERS__ #ifdef __COMPILE_TIMERS__
t_add.stop(); t_add.stop();
#endif #endif
} }
template<typename FPP> template<typename FPP>
void Faust::MatDense<FPP,Cpu>::sub(Faust::MatDense<FPP,Cpu> const& A) void Faust::MatDense<FPP,Cpu>::sub(Faust::MatDense<FPP,Cpu> const& A)
{ {
#ifdef __COMPILE_TIMERS__ #ifdef __COMPILE_TIMERS__
t_sub.start(); t_sub.start();
#endif #endif
if ((this->getNbCol() != A.getNbCol()) || (this->getNbRow() != A.getNbRow())) if ((this->getNbCol() != A.getNbCol()) || (this->getNbRow() != A.getNbRow()))
{ {
handleError(m_className, "sub : matrix dimension not equal"); std::cout<<"sub"<<std::endl;
} std::cout<<" this dimension ("<<this->getNbRow()<<","<<this->getNbCol()<<")"<<std::endl;
mat = mat - A.mat; std::cout<<" A dimension ("<<A.getNbRow()<<","<<A.getNbCol()<<")"<<std::endl;
handleError(m_className, "sub : matrix dimension not equal");
}
mat = mat - A.mat;
isZeros = false; isZeros = false;
isIdentity = false; isIdentity = false;
#ifdef __COMPILE_TIMERS__ #ifdef __COMPILE_TIMERS__
t_sub.stop(); t_sub.stop();
#endif #endif
} }
// Affichage // Affichage
template<typename FPP> template<typename FPP>
void Faust::MatDense<FPP,Cpu>::Display() const void Faust::MatDense<FPP,Cpu>::Display() const
...@@ -539,7 +543,9 @@ void Faust::MatDense<FPP,Cpu>::operator=(Faust::MatSparse<FPP,Cpu> const& S) ...@@ -539,7 +543,9 @@ void Faust::MatDense<FPP,Cpu>::operator=(Faust::MatSparse<FPP,Cpu> const& S)
resize(S.getNbRow(),S.getNbCol()); resize(S.getNbRow(),S.getNbCol());
setZeros(); setZeros();
FPP*const ptr_data = getData(); FPP*const ptr_data = getData();
for(int i=0 ; i< S.mat.outerSize() ; i++) for(int i=0 ; i< S.mat.outerSize() ; i++)
{ {
for(typename Eigen::SparseMatrix<FPP,Eigen::RowMajor>::InnerIterator it(S.mat,i); it; ++it) for(typename Eigen::SparseMatrix<FPP,Eigen::RowMajor>::InnerIterator it(S.mat,i); it; ++it)
...@@ -547,8 +553,8 @@ void Faust::MatDense<FPP,Cpu>::operator=(Faust::MatSparse<FPP,Cpu> const& S) ...@@ -547,8 +553,8 @@ void Faust::MatDense<FPP,Cpu>::operator=(Faust::MatSparse<FPP,Cpu> const& S)
ptr_data[it.col() * this->dim1 + it.row()] = it.value(); ptr_data[it.col() * this->dim1 + it.row()] = it.value();
} }
} }
isZeros = false; isZeros = false;
isIdentity = false; isIdentity = false;
} }
...@@ -585,7 +591,7 @@ void Faust::MatDense<FPP,Cpu>::operator*=(const Faust::MatSparse<FPP,Cpu>& S) ...@@ -585,7 +591,7 @@ void Faust::MatDense<FPP,Cpu>::operator*=(const Faust::MatSparse<FPP,Cpu>& S)
template<typename FPP> template<typename FPP>
void Faust::MatDense<FPP,Cpu>::operator+=(const Faust::MatSparse<FPP,Cpu>& S) void Faust::MatDense<FPP,Cpu>::operator+=(const Faust::MatSparse<FPP,Cpu>& S)
{ {
if(this->dim1!=S.dim1 || this->dim2!=S.dim2) if(this->dim1!=S.getNbRow() || this->dim2!=S.getNbCol())
{ {
handleError(m_className,"operator+= : incorrect matrix dimensions"); handleError(m_className,"operator+= : incorrect matrix dimensions");
} }
...@@ -594,17 +600,6 @@ void Faust::MatDense<FPP,Cpu>::operator+=(const Faust::MatSparse<FPP,Cpu>& S) ...@@ -594,17 +600,6 @@ void Faust::MatDense<FPP,Cpu>::operator+=(const Faust::MatSparse<FPP,Cpu>& S)
isZeros = false; isZeros = false;
} }
template<typename FPP>
void Faust::MatDense<FPP,Cpu>::operator-=(const Faust::MatSparse<FPP,Cpu>& S)
{
if(this->dim1!=S.dim1 || this->dim2!=S.dim2)
{
handleError(m_className,"operator-= : incorrect matrix dimensions");
}
mat -= S.mat;
isIdentity = false;
isZeros = false;
}
template<typename FPP> template<typename FPP>
......
...@@ -61,8 +61,7 @@ ...@@ -61,8 +61,7 @@
//! \param FPP scalar numeric type, e.g float or double //! \param FPP scalar numeric type, e.g float or double
//! //!
//! Faust::MatDense class template of dense matrix
template<typename FPP,Device DEVICE> class MatDense;
//! Faust::MatSparse class template of sparse matrix //! Faust::MatSparse class template of sparse matrix
template<typename FPP,Device DEVICE> class MatSparse; template<typename FPP,Device DEVICE> class MatSparse;
...@@ -77,9 +76,13 @@ template<Device DEVICE> class SpBlasHandle; ...@@ -77,9 +76,13 @@ template<Device DEVICE> class SpBlasHandle;
template<typename FPP> template<typename FPP>
void Faust::multiply(const Faust::Transform<FPP,Cpu> & A, const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C,const FPP & alpha, char typeA, char typeMult); void Faust::multiply(const Faust::Transform<FPP,Cpu> & A, const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C,const FPP & alpha, char typeA, char typeMult);
//! modif NB v1102 : comment useless function
template<typename FPP> template<typename FPP>
void Faust::spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB); void Faust::spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB);
//! \namespace Faust //! \namespace Faust
//! \brief Faust namespace contains the principal class of the project. //! \brief Faust namespace contains the principal class of the project.
namespace Faust namespace Faust
...@@ -87,9 +90,18 @@ namespace Faust ...@@ -87,9 +90,18 @@ namespace Faust
template<typename FPP,Device DEVICE> class MatGeneric; template<typename FPP,Device DEVICE> class MatGeneric;
//! Faust::MatDense class template of dense matrix
template<typename FPP,Device DEVICE> class MatDense;
template<typename FPP> template<typename FPP>
class MatSparse<FPP,Cpu> : public Faust::MatGeneric<FPP,Cpu> class MatSparse<FPP,Cpu> : public Faust::MatGeneric<FPP,Cpu>
{ {
friend class MatDense<FPP,Cpu>;
//friend void MatDense<FPP,Cpu>::operator+=(const MatSparse<FPP,Cpu>& S);
public: public:
MatSparse(); MatSparse();
...@@ -230,6 +242,14 @@ namespace Faust ...@@ -230,6 +242,14 @@ namespace Faust
void multiply(Faust::Vect<FPP,Cpu> & vec, char opThis='N') const void multiply(Faust::Vect<FPP,Cpu> & vec, char opThis='N') const
{ vec.multiplyLeft((*this),opThis);} { vec.multiplyLeft((*this),opThis);}
//! \brief compute MatSparse-MatDense multiplication
//! \param M : the dense matrix
//! \param opThis : character
//! M = (*this) * M if opThis='N'
// M = (*this)' * M if opThis='T'
void multiply(Faust::MatDense<FPP,Cpu> & M, char opThis) const;
//! Destructor //! Destructor
~MatSparse(){} ~MatSparse(){}
...@@ -244,15 +264,17 @@ namespace Faust ...@@ -244,15 +264,17 @@ namespace Faust
//! number of non-zero //! number of non-zero
faust_unsigned_int nnz; faust_unsigned_int nnz;
friend void Faust::MatDense<FPP,Cpu>::operator=(MatSparse<FPP,Cpu> const& S); // ** modif NB v1102 ** : comment friend function
//friend void Faust::MatDense<FPP,Cpu>::operator=(MatSparse<FPP,Cpu> const& S);
//! *this = (*this) * S //! *this = (*this) * S
friend void Faust::MatDense<FPP,Cpu>::operator*=(const MatSparse<FPP,Cpu>& S); //friend void Faust::MatDense<FPP,Cpu>::operator*=(const MatSparse<FPP,Cpu>& S);
//! *this = (*this) + S //! *this = (*this) + S
friend void Faust::MatDense<FPP,Cpu>::operator+=(const MatSparse<FPP,Cpu>& S); //friend void Faust::MatDense<FPP,Cpu>::operator+=(const MatSparse<FPP,Cpu>& S);
//! *this = (*this) - S //! *this = (*this) - S
friend void Faust::MatDense<FPP,Cpu>::operator-=(const MatSparse<FPP,Cpu>& S); //friend void Faust::MatDense<FPP,Cpu>::operator-=(const MatSparse<FPP,Cpu>& S);
...@@ -260,12 +282,15 @@ namespace Faust ...@@ -260,12 +282,15 @@ namespace Faust
//! *this = S * (*this) //! *this = S * (*this)
friend void Faust::Vect<FPP,Cpu>::multiplyLeft(MatSparse<FPP,Cpu> const& S,const char TransS); friend void Faust::Vect<FPP,Cpu>::multiplyLeft(MatSparse<FPP,Cpu> const& S,const char TransS);
friend void Faust::MatDense<FPP,Cpu>::multiplyLeft(MatSparse<FPP,Cpu> const& S,const char TransS); /*friend void Faust::MatDense<FPP,Cpu>::multiplyLeft(MatSparse<FPP,Cpu> const& S,const char TransS);*/
// MODIF AL WARNING, ERROR WITH VISUAL STUDIO 2013 compiler // MODIF AL WARNING, ERROR WITH VISUAL STUDIO 2013 compiler
//friend void Faust::multiply<>(const Faust::Transform<FPP,Cpu> & A, const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C,const FPP & alpha, char typeA, char typeMult); //friend void Faust::multiply<>(const Faust::Transform<FPP,Cpu> & A, const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C,const FPP & alpha, char typeA, char typeMult);
friend void Faust::spgemm<>(const MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB);
//! modif NB v1102 : comment useless function
friend void Faust::spgemm<>(const MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB);
}; };
} }
......
...@@ -167,8 +167,44 @@ Faust::MatSparse<FPP,Cpu>::MatSparse(const faust_unsigned_int nnz_, const faust_ ...@@ -167,8 +167,44 @@ Faust::MatSparse<FPP,Cpu>::MatSparse(const faust_unsigned_int nnz_, const faust_
} }
template<typename FPP>
void Faust::MatSparse<FPP,Cpu>::multiply(Faust::MatDense<FPP,Cpu> & M, char opThis) const
{
faust_unsigned_int nbColOpS,nbRowOpS;
this->setOp(opThis,nbRowOpS,nbColOpS);
if(nbColOpS != M.getNbRow())
{
handleError(m_className,"multiply : incorrect matrix dimensions\n");
}
if (M.isIdentity)
{
M = (*this);
M.isIdentity = false;
M.isZeros = false;
if (opThis == 'T')
M.transpose();
}
else if (M.isZeros)
{
M.resize(nbRowOpS, this->dim2);
M.setZeros();
}
else
{
if (opThis == 'N')
M.mat = this->mat * M.mat;
else
M.mat = this->mat.transpose() * M.mat;
M.dim1 = nbRowOpS;
}
}
......
...@@ -211,7 +211,7 @@ void Faust::Transform<FPP,Cpu>::check_factors_validity() const ...@@ -211,7 +211,7 @@ void Faust::Transform<FPP,Cpu>::check_factors_validity() const
for (int i=0;i<=size()-2;i++) for (int i=0;i<=size()-2;i++)
{ {
if (data[i].getNbCol() != data[i+1].getNbRow()) if (data[i]->getNbCol() != data[i+1]->getNbRow())
handleError(m_className,"check_factors_validity : dimensions of the factors mismatch"); handleError(m_className,"check_factors_validity : dimensions of the factors mismatch");
} }
...@@ -313,15 +313,24 @@ Faust::Transform<FPP,Cpu>::Transform(const std::vector<Faust::MatDense<FPP,Cpu> ...@@ -313,15 +313,24 @@ Faust::Transform<FPP,Cpu>::Transform(const std::vector<Faust::MatDense<FPP,Cpu>
template<typename FPP> template<typename FPP>
Faust::MatDense<FPP,Cpu> Faust::Transform<FPP,Cpu>::get_product(const char opThis)const Faust::MatDense<FPP,Cpu> Faust::Transform<FPP,Cpu>::get_product(const char opThis)const
{ {
//complexity of evaluating a Faust::Transform
// from left to right is (dim1*total_nnz)
// from right to left is (dim2*total_nnz)
if (size() == 0) if (size() == 0)
{ {
handleError(m_className,"get_product : empty Faust::Transform"); handleError(m_className,"get_product : empty Faust::Transform");
} }
// modif NB v1102 : new method compatible with factor as MatGeneric
Faust::MatDense<FPP,Cpu> prod(data[0]->getNbCol());
prod.setEyes();
return this->multiply(prod,'N');
/* modif NB v1102 : factor are no longer MatSparse, they are MatGeneric now
Faust::MatDense<FPP,Cpu> prod(data[0].getNbRow()); Faust::MatDense<FPP,Cpu> prod(data[0].getNbRow());
if(getNbRow()<getNbCol()) if(getNbRow()<getNbCol())
...@@ -339,6 +348,10 @@ Faust::MatDense<FPP,Cpu> Faust::Transform<FPP,Cpu>::get_product(const char opThi ...@@ -339,6 +348,10 @@ Faust::MatDense<FPP,Cpu> Faust::Transform<FPP,Cpu>::get_product(const char opThi
} }
if (opThis == 'T') if (opThis == 'T')
prod.transpose(); prod.transpose();
*/
//complexity of evaluating a Faust::Transform
// from left to right is (dim1*total_nnz)
// from right to left is (dim2*total_nnz)
/*Faust::MatDense<FPP,Cpu> prod; /*Faust::MatDense<FPP,Cpu> prod;
if ( (data[0].getNonZeros()+getNbRow()*(totalNonZeros-data[0].getNonZeros())) < (data[size()-1].getNonZeros()+getNbCol()*(totalNonZeros-data[size()-1].getNonZeros())) ) if ( (data[0].getNonZeros()+getNbRow()*(totalNonZeros-data[0].getNonZeros())) < (data[size()-1].getNonZeros()+getNbCol()*(totalNonZeros-data[size()-1].getNonZeros())) )
...@@ -355,7 +368,7 @@ Faust::MatDense<FPP,Cpu> Faust::Transform<FPP,Cpu>::get_product(const char opThi ...@@ -355,7 +368,7 @@ Faust::MatDense<FPP,Cpu> Faust::Transform<FPP,Cpu>::get_product(const char opThi
return prod; //return prod;
} }
template<typename FPP> template<typename FPP>
...@@ -639,16 +652,30 @@ Faust::MatDense<FPP,Cpu> Faust::Transform<FPP,Cpu>::multiply(const Faust::MatDen ...@@ -639,16 +652,30 @@ Faust::MatDense<FPP,Cpu> Faust::Transform<FPP,Cpu>::multiply(const Faust::MatDen
if (opThis == 'N') if (opThis == 'N')
{ {
for (int i=this->size()-1 ; i >= 0 ; i--) for (int i=this->size()-1 ; i >= 0 ; i--)
mat.multiplyLeft(data[i]); {
//#ifdef __COMPILE_TIMERS__
// this->t_multiply_mat[i].start();
//#endif
data[i]->multiply(mat,opThis);
//#ifdef __COMPILE_TIMERS__
// this->t_multiply_mat[i].stop();
//#endif
}
}else }else
{ {
for (int i=0 ; i < this->size() ; i++) for (int i=0 ; i < this->size() ; i++)
{ {
mat.multiplyLeft(data[i],opThis); //#ifdef __COMPILE_TIMERS__
// this->t_multiply_mat[i].start();
//#endif
data[i]->multiply(mat,opThis);
//#ifdef __COMPILE_TIMERS__
// this->t_multiply_mat[i].start();
//#endif
} }
} }
return mat; return mat;
......
...@@ -59,11 +59,13 @@ namespace Faust ...@@ -59,11 +59,13 @@ namespace Faust
//! \brief (*this) = (*this) + A //! \brief (*this) = (*this) + A
template<typename FPP> template<typename FPP>
void add(const Faust::MatDense<FPP,Cpu> & A, const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C); void add(const Faust::MatDense<FPP,Cpu> & A, const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C);
//! \fn Faust::spgemm //! \fn Faust::spgemm
//! \brief performs Sparse matrices multiplication //! \brief performs Sparse matrices multiplication
template<typename FPP> template<typename FPP>
void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB); void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB);
/*! \fn gemm /*! \fn gemm
* \brief Performs a matrix calculation of the form a(AB) +bC, with three matrices and two real constants you supply. <br> * \brief Performs a matrix calculation of the form a(AB) +bC, with three matrices and two real constants you supply. <br>
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
template<typename FPP> template<typename FPP>
void Faust::spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB) void Faust::spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB)
{ {
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "faust_constant.h" #include "faust_constant.h"
#include "faust_LinearOperator.h" #include "faust_LinearOperator.h"
#include "faust_Vect.h" #include "faust_Vect.h"
#include "faust_MatDense.h"
/** /**
* \class MatGeneric faust_MatGeneric.h * \class MatGeneric faust_MatGeneric.h
* \brief This MatGeneric class serves as a base class for the derived class Faust::MatDense and Faust::MatSparse . * \brief This MatGeneric class serves as a base class for the derived class Faust::MatDense and Faust::MatSparse .
...@@ -105,6 +106,14 @@ namespace Faust ...@@ -105,6 +106,14 @@ namespace Faust
virtual void multiply(Faust::Vect<FPP,DEVICE> & vec, char opThis='N') const; virtual void multiply(Faust::Vect<FPP,DEVICE> & vec, char opThis='N') const;
//! \brief compute MatGeneric-MatDense multiplication
//! \param M : the dense matrix
//! \param opThis : character
//! M = (*this) * M if opThis='N'
// M = (*this)' * M if opThis='T'
virtual void multiply(Faust::MatDense<FPP,DEVICE> & M, char opThis) const;
//! \brief transpose the matrix //! \brief transpose the matrix
virtual void transpose()=0; virtual void transpose()=0;
......
...@@ -89,11 +89,11 @@ Faust::MatGeneric<FPP,Cpu>* Faust::optimize(Faust::MatDense<FPP,Cpu> const & M,F ...@@ -89,11 +89,11 @@ Faust::MatGeneric<FPP,Cpu>* Faust::optimize(Faust::MatDense<FPP,Cpu> const & M,F
x_dense=x; x_dense=x;
t_sparse.start(); t_sparse.start();
S.multiply(x_sparse); S.multiply(x_sparse,'N');
t_sparse.stop(); t_sparse.stop();
t_dense.start(); t_dense.start();
M.multiply(x_dense); M.multiply(x_dense,'N');
t_dense.stop(); t_dense.stop();
......
...@@ -10,10 +10,12 @@ ...@@ -10,10 +10,12 @@
########################################################################## ##########################################################################
version 1103 :
-> test MATFILE marche
version 1100 : version 1100 :
début [trunk] merge avec branch Faust_mat_generic : les faust sont une liste de matrice generique, pas forcement des matrice creuses début [trunk] **** merge avec branch Faust_mat_generic **** : les faust sont une liste de matrice generique, pas forcement des matrice creuses
-> wrapper matlab HS -> wrapper matlab HS
-> wrapper python HS -> wrapper python HS
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment