Mentions légales du service

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

Add a unit test for (faust_prod_opt) dynprog_multiply C++ function.

parent 99ef5d23
No related branches found
No related tags found
No related merge requests found
......@@ -193,7 +193,7 @@ if(MATIO_LIB_FILE AND MATIO_INC_DIR AND BUILD_READ_MAT_FILE AND NOT NOCPPTESTS)
# faust_multiplication : time comparison between Faust-vector product and Dense matrix-vector product
list(APPEND tests hierarchicalFactorization hierarchicalFactorizationFFT test_palm4MSA test_palm4MSAFFT faust_multiplication faust_matdense_conjugate GivensFGFT GivensFGFTSparse GivensFGFTParallel GivensFGFTParallelSparse test_MatDiag faust_matsparse_mul faust_matsparse_index_op GivensFGFTComplex GivensFGFTComplexSparse GivensFGFTParallelComplex faust_toeplitz faust_circ faust_hankel faust_sparse_prox_sp palm4msa_2020 hierarchical2020 hierarchical2020Hadamard hierarchicalFactorizationHadamard hierarchicalFactorizationButterfly hierarchicalFactorizationButterflyBalanced test_MatBSR)
list(APPEND tests hierarchicalFactorization hierarchicalFactorizationFFT test_palm4MSA test_palm4MSAFFT faust_multiplication faust_matdense_conjugate GivensFGFT GivensFGFTSparse GivensFGFTParallel GivensFGFTParallelSparse test_MatDiag faust_matsparse_mul faust_matsparse_index_op GivensFGFTComplex GivensFGFTComplexSparse GivensFGFTParallelComplex faust_toeplitz faust_circ faust_hankel faust_sparse_prox_sp palm4msa_2020 hierarchical2020 hierarchical2020Hadamard hierarchicalFactorizationHadamard hierarchicalFactorizationButterfly hierarchicalFactorizationButterflyBalanced test_MatBSR test_dynprog_mul_cpu)
if(FAUST_TORCH)
list(APPEND tests faust_torch)
......
#include "faust_TransformHelper.h"
#include "faust_prod_opt.h"
#include <cstdlib>
#include <ctime>
typedef @TEST_FPP@ FPP;
using namespace Faust;
int main()
{
srand(time(NULL));
unsigned int min_num_factors = 2;
unsigned int max_num_factors = 10;
unsigned int min_dim_size = 10;
unsigned int max_dim_size = 1024;
float density = .5f;
bool per_row = true;
auto F = TransformHelper<FPP, Cpu>::randFaust(MIXED, min_num_factors, max_num_factors, min_dim_size, max_dim_size, density, per_row);
//TODO: fix always two factors
F->display();
// convert the Faust to a vector of matrices
std::vector<MatGeneric<FPP, Cpu>*> data(F->begin(), F->end());
// for(auto f: data)
// f->Display();
// MatDense<FPP, Cpu> dynprog_multiply(std::vector<MatGeneric<FPP, Cpu>*>& factors, const char op/*='N'*/, const MatGeneric<FPP, Cpu>* A/*=nullptr*/)
auto res_mat = dynprog_multiply(data);
auto ref_mat = F->get_product();
auto test_mat = ref_mat;
test_mat -= res_mat;
auto re = test_mat.norm() / ref_mat.norm();
std::cout << "rel. err of test_mat vs ref_mat: " << re << std::endl;
assert(re < 1e-4);
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment