Mentions légales du service

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

Add TransformHelper::optimize() and a C++ test: it does a pruneout +...

Add TransformHelper::optimize() and a C++ test: it does a pruneout + optimize_storage and choose the quickest method for the Faust-matrix product.
parent 3b8495a9
No related branches found
No related tags found
No related merge requests found
if(BUILD_TESTING)
message(STATUS "CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
message(STATUS "TEST CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
#${FAUST_EXCEPTION_SRC_DIR}
include_directories(${FAUST_SRC_LINEAR_OPERATOR_DIR} ${FAUST_LINEAR_OPERATOR_CPU_SRC_DIR} ${FAUST_ALGORITHM_CONSTRAINT_SRC_DIR} ${FAUST_ALGORITHM_FACTORIZATION_SRC_DIR} ${EIGEN_INC_DIR} ${FAUST_UTILS_SRC_DIR})
......@@ -156,7 +156,7 @@ endif()
if(NOT NOCPPTESTS)
foreach(TEST_FPP float double)
foreach(FILE faust_mult faust_mult_cplx test_Vect_min test_MatDense_get_row test_MatDense_lower_upper_tri test_MatDense_nonzeros_indices test_Transform_move test_MatDense_min faust_transform_omp_mul faust_pruneout faust_transform_optimize_storage )
foreach(FILE faust_mult faust_mult_cplx test_Vect_min test_MatDense_get_row test_MatDense_lower_upper_tri test_MatDense_nonzeros_indices test_Transform_move test_MatDense_min faust_transform_omp_mul faust_pruneout faust_transform_optimize_storage faust_transform_optimize)
set(TEST_BIN_FILE ${FILE}_${TEST_FPP})
set(TEST_FILE_CPP ${TEST_BIN_FILE}.cpp)
message(STATUS ${TEST_FILE_CPP})
......
/* Copyright (2016): Nicolas Bellot, Adrien Leman, Thomas Gautrais, */
/* Luc Le Magoarou, Remi Gribonval */
/* INRIA Rennes, FRANCE */
/* http://www.inria.fr/ */
/* */
/* The FAuST Toolbox is distributed under the terms of the GNU Affero */
/* General Public License. */
/* This program is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU Affero General Public License as */
/* published by the Free Software Foundation. */
/* */
/* This program is distributed in the hope that it will be useful, but */
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */
/* See the GNU Affero General Public License for more details. */
/* */
/* You should have received a copy of the GNU Affero General Public */
/* License along with this program. */
/* If not, see <http://www.gnu.org/licenses/>. */
/* */
/* Contacts: */
/* Nicolas Bellot : nicolas.bellot@inria.fr */
/* Adrien Leman : adrien.leman@inria.fr */
/* Thomas Gautrais : thomas.gautrais@inria.fr */
/* Luc Le Magoarou : luc.le-magoarou@inria.fr */
/* Remi Gribonval : remi.gribonval@inria.fr */
/* */
/* References: */
/* [1] Le Magoarou L. and Gribonval R., "Flexible multi-layer sparse */
/* approximations of matrices and applications", Journal of Selected */
/* Topics in Signal Processing, 2016. */
/* <https://hal.archives-ouvertes.fr/hal-01167958v1> */
/****************************************************************************/
#include "faust_TransformHelper.h"
#include "faust_MatDense.h"
#include <string>
#include <sstream>
#include <chrono>
#include <iostream>
#include <iomanip>
#define _OPENMP_
/** \brief unitary test for testing multiplication by faust
*/
typedef @TEST_FPP@ FPP;
using namespace Faust;
int main(int argc, char* argv[])
{
if (typeid(FPP) == typeid(double))
{
cout<<"floating point precision == double"<<endl;
}
if (typeid(FPP) == typeid(float))
{
cout<<"floating point precision == float"<<endl;
}
//RandFaustType t, unsigned int min_num_factors, unsigned int max_num_factors, unsigned int min_dim_size, unsigned int max_dim_size, float density=.1f, bool per_row=true
TransformHelper<FPP,Cpu>* th = TransformHelper<FPP,Cpu>::randFaust(DENSE, 6, 6, 1024, 1024, .5);
th->display();
MatDense<FPP,Cpu>* M = MatDense<FPP,Cpu>::randMat(1024,1024);
auto start = std::chrono::system_clock::now();
auto FM = th->multiply(*M);
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> diff = end-start;
std::cout << "Time "<< diff.count() << " s\n";
FM.Display();
cout << "FM norm: " << FM.norm() << endl;
auto th2 = th->optimize();
cout << "opt meth:" << th2->get_mul_order_opt_mode() << endl;
start = std::chrono::system_clock::now();
auto FM3 = th2->multiply(*M);
end = std::chrono::system_clock::now();
diff = end-start;
std::cout << "Time opt.: "<< diff.count() << " s\n";
FM3.Display();
cout << "FM3 norm: " << FM3.norm() << endl;
return 0;
}
......@@ -96,6 +96,7 @@ namespace Faust {
// MatDense<FPP,Cpu> multiply(const MatDense<FPP,Cpu> A) const;
MatDense<FPP, Cpu> multiply(const MatDense<FPP,Cpu> A, const bool transpose=false, const bool conjugate=false);
void set_mul_order_opt_mode(const int mul_order_opt_mode);
int get_mul_order_opt_mode() const;
MatDense<FPP, Cpu> multiply(const MatSparse<FPP,Cpu> A, const bool transpose=false, const bool conjugate=false);
TransformHelper<FPP, Cpu>* multiply(TransformHelper<FPP, Cpu>*);
......@@ -161,6 +162,8 @@ namespace Faust {
TransformHelper<FPP,Cpu>* pruneout(const int nnz_tres, const int npasses=-1, const bool only_forward=false);
TransformHelper<FPP,Cpu>* optimize_storage(const bool time=true);
TransformHelper<FPP,Cpu>* optimize();
static TransformHelper<FPP,Cpu>* randFaust(RandFaustType t, unsigned int min_num_factors, unsigned int max_num_factors, unsigned int min_dim_size, unsigned int max_dim_size, float density=.1f, bool per_row=true);
static TransformHelper<FPP,Cpu>* hadamardFaust(unsigned int n, const bool norma=true);
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment