Mentions légales du service

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

Add a C++ unit test for MatButterfly-vector multiplication.

parent baef45a6
Branches
Tags
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) ...@@ -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 # 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 test_dynprog_mul_cpu faust_butterfly_transform faust_butterfly_transform2) 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 faust_butterfly_transform faust_butterfly_transform2 faust_butterfly_mat)
if(FAUST_TORCH) if(FAUST_TORCH)
list(APPEND tests faust_torch) list(APPEND tests faust_torch)
......
#include "faust_TransformHelperButterfly.h"
#include "faust_MatButterfly.h"
#include <cstdio>
typedef @TEST_FPP@ FPP;
using namespace Faust;
int main(int argc, char** argv)
{
int log2size = 4;
if(argc > 1)
log2size = std::atoi(argv[1]);
std::cout << "log2size: " << log2size << std::endl;
int size = 1 << log2size;
auto F = TransformHelper<FPP, Cpu>::fourierFaust(log2size, false);
auto dsButterflyMat = F->get_fact(0);
MatSparse<FPP, Cpu> spButterflyMat(dsButterflyMat);
MatButterfly<FPP, Cpu> butterflyMat(spButterflyMat, /* level */ 0);
Vect<FPP, Cpu> x(size);
x.setRand();
const Vect<FPP, Cpu> x_(x);
// x.setOnes();
Vect<FPP, Cpu> ref_v = spButterflyMat.multiply(x_);
Vect<FPP, Cpu> test_v = butterflyMat.multiply(x_);
ref_v.Display();
test_v.Display();
auto err = test_v;
err -= ref_v;
assert(err.norm() <= 1e-6);
std::cout << "butterfly-vector product OK" << std::endl;
// // test multiplying a MatDense
// auto X = MatDense<FPP, Cpu>::randMat(size, size);
// // X->setOnes();
//
// auto refY = spButterflyMat.multiply(*X);
// auto testY = butterflyMat.multiply(*X);
//
//
// auto errY = testY;
// errY -= refY;
// assert(errY.norm() <= 1e-6);
//
// std::cout << "Faust-dense matrix product OK" << std::endl;
//
// // test multiplying a MatSparse
// auto spX = MatSparse<FPP, Cpu>::randMat(size, size, .2);
// // X->setOnes();
//
// auto refYsp = spButterflyMat.multiply(*spX);
// auto testYsp = butterflyMat.multiply(*spX, 'N');
//
// auto errYsp = testYsp;
// errYsp -= refYsp;
// assert(errYsp.norm() <= 1e-6);
//
// std::cout << "Faust-sparse matrix product OK" << std::endl;
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment