Mentions légales du service

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

Optimize FaustFactory.wht() C++ backend; only one factor is really created in...

Optimize FaustFactory.wht() C++ backend; only one factor is really created in memory because all others are in fact the same.

If a hadamard tranform was created calling FaustFactory.wht(n), then the space used is now divided by n compared to what it was before this commit.

This commit is related to issue #17.
parent 74c0fe07
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ namespace Faust { ...@@ -8,7 +8,7 @@ namespace Faust {
* \brief Fast Walsh-Hadamard Transform. * \brief Fast Walsh-Hadamard Transform.
*/ */
template<typename FPP> template<typename FPP>
void wht_factors(unsigned int n, vector<MatGeneric<FPP,Cpu>*>& factors); void wht_factors(unsigned int n, vector<MatGeneric<FPP,Cpu>*>& factors, const bool cloning_fact=true);
} }
#include "faust_WHT.hpp" #include "faust_WHT.hpp"
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
namespace Faust { namespace Faust {
template<typename FPP> template<typename FPP>
void wht_factors(unsigned int n, vector<MatGeneric<FPP,Cpu>*>& factors) void wht_factors(unsigned int n, vector<MatGeneric<FPP,Cpu>*>& factors, const bool cloning_fact)
{ {
if(n == 0) if(n == 0)
{ {
...@@ -88,7 +88,10 @@ namespace Faust { ...@@ -88,7 +88,10 @@ namespace Faust {
factors[0] = factor; factors[0] = factor;
for(int i=1; i < n; i++) for(int i=1; i < n; i++)
factors[i] = factor->Clone(); if(cloning_fact)
factors[i] = factor->Clone();
else
factors[i] = factor;
} }
} }
......
...@@ -86,7 +86,7 @@ template<typename FPP> ...@@ -86,7 +86,7 @@ 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);
template<typename FPP> template<typename FPP>
void Faust::wht_factors(unsigned int n, vector<MatGeneric<FPP,Cpu>*>& factors); void Faust::wht_factors(unsigned int n, vector<MatGeneric<FPP,Cpu>*>& factors, const bool);
//! \namespace Faust //! \namespace Faust
//! \brief Faust namespace contains the principal class of the project. //! \brief Faust namespace contains the principal class of the project.
...@@ -106,7 +106,7 @@ namespace Faust ...@@ -106,7 +106,7 @@ namespace Faust
{ {
friend Faust::TransformHelper<FPP,Cpu>; // TODO: limit to needed member functions only friend Faust::TransformHelper<FPP,Cpu>; // TODO: limit to needed member functions only
friend void Faust::wht_factors<>(unsigned int n, vector<MatGeneric<FPP,Cpu>*>& factors); friend void Faust::wht_factors<>(unsigned int n, vector<MatGeneric<FPP,Cpu>*>& factors, const bool);
friend class MatDense<FPP,Cpu>; friend class MatDense<FPP,Cpu>;
//friend void MatDense<FPP,Cpu>::operator+=(const MatSparse<FPP,Cpu>& S); //friend void MatDense<FPP,Cpu>::operator+=(const MatSparse<FPP,Cpu>& S);
......
...@@ -954,8 +954,10 @@ namespace Faust { ...@@ -954,8 +954,10 @@ namespace Faust {
{ {
TransformHelper<FPP,Cpu>* hadamardFaust = nullptr; TransformHelper<FPP,Cpu>* hadamardFaust = nullptr;
vector<MatGeneric<FPP,Cpu>*> factors; vector<MatGeneric<FPP,Cpu>*> factors;
bool cloning_fact = false; // big opt. allowed only because of the RefManager used in Transform class
//this opt. avoids to duplicate the same factor
try { try {
wht_factors(n, factors); wht_factors(n, factors, cloning_fact);
hadamardFaust = new TransformHelper<FPP, Cpu>(factors, 1.0, false, false); hadamardFaust = new TransformHelper<FPP, Cpu>(factors, 1.0, false, false);
} }
catch(std::bad_alloc) catch(std::bad_alloc)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment