Mentions légales du service

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

Add GPU2 wrapper in matfaust for Faust functions: nnz, optimize_time,...

Add GPU2 wrapper in matfaust for Faust functions: nnz, optimize_time, optimize_storage, optimize, multiply.
parent 3ab0cd33
No related branches found
No related tags found
No related merge requests found
Showing with 418 additions and 118 deletions
/****************************************************************************/
/* Description: */
/* file where the C++ class Faust::TransformHelper is interfaced */
/* with Matlab */
/* */
/* For more information on the FAuST Project, please visit the website */
/* of the project : <http://faust.inria.fr> */
/* */
/* License: */
/* Copyright (2021): Hakim HADJ-DJILANI */
/* 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 */
/* Hakim hadj-djilani : hakim.hadj-djilani@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-01167948v1> */
#ifndef __MEX_FAUST_MULTIPLY__
#define __MEX_FAUST_MULTIPLY__
template <typename SCALAR, FDevice DEV>
void faust_multiply(const mxArray **prhs, const int nrhs, mxArray **plhs, const int nlhs);
#include "faust_multiply.hpp"
#endif
#include "class_handle.hpp"
#include "faust_TransformHelper.h"
template <typename SCALAR, FDevice DEV>
void faust_multiply(const mxArray **prhs, const int nrhs, mxArray **plhs, const int nlhs)
{
Faust::TransformHelper<SCALAR,DEV>* core_ptr = convertMat2Ptr<Faust::TransformHelper<SCALAR,DEV> >(prhs[1]);
if (nlhs > 1 || nrhs != 4)
mexErrMsgTxt("Multiply: Unexcepted number of arguments.");
mwSize nelem = mxGetNumberOfElements(prhs[3]);
if (nelem != 1)
mexErrMsgTxt("invalid char argument.");
// boolean flag to know if the faust needs to be transposed
bool transpose_flag = (bool) mxGetScalar(prhs[3]);
// input matrix or vector from MATLAB
const mxArray * inMatlabMatrix = prhs[2];
if(mxIsSparse(inMatlabMatrix))
{
Faust::MatSparse<SCALAR,Cpu> spA;
mxArray2FaustspMat<SCALAR>(inMatlabMatrix, spA);
Faust::MatDense<SCALAR,Cpu> B;
B = (*core_ptr).multiply(spA, transpose_flag);
plhs[0] = FaustMat2mxArray(B);
}
else
{
const size_t nbRowA = mxGetM(inMatlabMatrix);
const size_t nbColA = mxGetN(inMatlabMatrix);
faust_unsigned_int nbRowOp_,nbColOp_;
const size_t nbRowOp = core_ptr->getNbRow();
const size_t nbColOp = core_ptr->getNbCol();
const size_t nbRowB = nbRowOp;
const size_t nbColB = nbColA;
/** Check parameters **/
//check dimension match
if (mxGetNumberOfDimensions(inMatlabMatrix) != 2
|| nbRowA != nbColOp && (nbRowA != nbRowOp && transpose_flag))
mexErrMsgTxt("Multiply : Wrong number of dimensions for the input vector or matrix (third argument).");
SCALAR* ptr_data = NULL;
if (typeid(Faust::TransformHelper<double,DEV>) == typeid(Faust::TransformHelper<SCALAR,DEV>) && mxIsComplex(inMatlabMatrix) )
mexErrMsgTxt("impossibile to multiply a real Faust with complex matrix");
mxArray2Ptr(inMatlabMatrix, ptr_data);
if(nbColA == 1)
{
// applying the Faust to a vector
Faust::Vect<SCALAR,Cpu> A(nbRowA, ptr_data);
Faust::Vect<SCALAR,Cpu> B(nbRowB);
B = (*core_ptr).multiply(A, transpose_flag);
plhs[0]=FaustVec2mxArray(B);
}
else
{ // applying the Faust to a matrix
Faust::MatDense<SCALAR,Cpu> A(ptr_data, nbRowA, nbColA);
Faust::MatDense<SCALAR,Cpu> B(nbRowB, nbColA);
B = (*core_ptr).multiply(A, transpose_flag);
plhs[0]=FaustMat2mxArray(B);
}
if(ptr_data) {delete [] ptr_data ; ptr_data = NULL;}
}
}
/****************************************************************************/
/* Description: */
/* file where the C++ class Faust::TransformHelper is interfaced */
/* with Matlab */
/* */
/* For more information on the FAuST Project, please visit the website */
/* of the project : <http://faust.inria.fr> */
/* */
/* License: */
/* Copyright (2021): Hakim HADJ-DJILANI */
/* 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 */
/* Hakim hadj-djilani : hakim.hadj-djilani@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-01167948v1> */
#ifndef __MEX_FAUST_NNZ__
#define __MEX_FAUST_NNZ__
template <typename SCALAR, FDevice DEV>
void faust_nnz(const mxArray **prhs, const int nrhs, mxArray **plhs, const int nlhs);
#include "faust_nnz.hpp"
#endif
#include "class_handle.hpp"
#include "faust_TransformHelper.h"
template <typename SCALAR, FDevice DEV>
void faust_nnz(const mxArray **prhs, const int nrhs, mxArray **plhs, const int nlhs)
{
// return the number of nonzeros coefficients of the matrix
Faust::TransformHelper<SCALAR,DEV>* core_ptr = convertMat2Ptr<Faust::TransformHelper<SCALAR,DEV> >(prhs[1]);
if (nlhs > 1 || nrhs != 2)
{
mexErrMsgTxt("nnz : incorrect number of arguments.");
}
long long int nnz = core_ptr->get_total_nnz();
plhs[0]=mxCreateDoubleScalar(nnz);
}
...@@ -6,7 +6,6 @@ void faust_normalize(const mxArray **prhs, const int nrhs, mxArray **plhs, const ...@@ -6,7 +6,6 @@ void faust_normalize(const mxArray **prhs, const int nrhs, mxArray **plhs, const
Faust::TransformHelper<SCALAR,DEV>* core_ptr = convertMat2Ptr<Faust::TransformHelper<SCALAR,DEV> >(prhs[1]); Faust::TransformHelper<SCALAR,DEV>* core_ptr = convertMat2Ptr<Faust::TransformHelper<SCALAR,DEV> >(prhs[1]);
core_ptr->display(); core_ptr->display();
int ord = (int) mxGetScalar(prhs[2]); int ord = (int) mxGetScalar(prhs[2]);
std::cout << "ord:" << ord << std::endl;
Faust::TransformHelper<SCALAR,DEV>* th = core_ptr->normalize(ord); Faust::TransformHelper<SCALAR,DEV>* th = core_ptr->normalize(ord);
th->display(); th->display();
plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR,DEV> >(th); plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR,DEV> >(th);
......
/****************************************************************************/
/* Description: */
/* file where the C++ class Faust::TransformHelper is interfaced */
/* with Matlab */
/* */
/* For more information on the FAuST Project, please visit the website */
/* of the project : <http://faust.inria.fr> */
/* */
/* License: */
/* Copyright (2021): Hakim HADJ-DJILANI */
/* 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 */
/* Hakim hadj-djilani : hakim.hadj-djilani@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-01167948v1> */
#ifndef __MEX_FAUST_OPTIMIZE__
#define __MEX_FAUST_OPTIMIZE__
template <typename SCALAR, FDevice DEV>
void faust_optimize(const mxArray **prhs, const int nrhs, mxArray **plhs, const int nlhs);
#include "faust_optimize.hpp"
#endif
#include "class_handle.hpp"
#include "faust_TransformHelper.h"
template <typename SCALAR, FDevice DEV>
void faust_optimize(const mxArray **prhs, const int nrhs, mxArray **plhs, const int nlhs)
{
Faust::TransformHelper<SCALAR,DEV>* core_ptr = convertMat2Ptr<Faust::TransformHelper<SCALAR,DEV> >(prhs[1]);
if(nrhs != 3)
mexErrMsgTxt("optimize mex error: invalid number of arguments.");
bool transp = (bool) mxGetScalar(prhs[2]);
Faust::TransformHelper<SCALAR,DEV>* th = core_ptr->optimize(transp);
plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR,DEV> >(th);
}
/****************************************************************************/
/* Description: */
/* file where the C++ class Faust::TransformHelper is interfaced */
/* with Matlab */
/* */
/* For more information on the FAuST Project, please visit the website */
/* of the project : <http://faust.inria.fr> */
/* */
/* License: */
/* Copyright (2021): Hakim HADJ-DJILANI */
/* 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 */
/* Hakim hadj-djilani : hakim.hadj-djilani@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-01167948v1> */
#ifndef __MEX_FAUST_OPTIMIZE_STORAGE__
#define __MEX_FAUST_OPTIMIZE_STORAGE__
template <typename SCALAR, FDevice DEV>
void faust_optimize_storage(const mxArray **prhs, const int nrhs, mxArray **plhs, const int nlhs);
#include "faust_optimize_storage.hpp"
#endif
#include "class_handle.hpp"
#include "faust_TransformHelper.h"
template <typename SCALAR, FDevice DEV>
void faust_optimize_storage(const mxArray **prhs, const int nrhs, mxArray **plhs, const int nlhs)
{
Faust::TransformHelper<SCALAR,DEV>* core_ptr = convertMat2Ptr<Faust::TransformHelper<SCALAR,DEV> >(prhs[1]);
if(nrhs != 3)
mexErrMsgTxt("optimize_storage mex error: invalid number of arguments.");
bool timeCrit = (bool) mxGetScalar(prhs[2]);
Faust::TransformHelper<SCALAR,DEV>* th = core_ptr->optimize_storage(timeCrit);
plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR,DEV> >(th);
}
/****************************************************************************/
/* Description: */
/* file where the C++ class Faust::TransformHelper is interfaced */
/* with Matlab */
/* */
/* For more information on the FAuST Project, please visit the website */
/* of the project : <http://faust.inria.fr> */
/* */
/* License: */
/* Copyright (2021): Hakim HADJ-DJILANI */
/* 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 */
/* Hakim hadj-djilani : hakim.hadj-djilani@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-01167948v1> */
#ifndef __MEX_FAUST_OPTIMIZE_TIME__
#define __MEX_FAUST_OPTIMIZE_TIME__
template <typename SCALAR, FDevice DEV>
void faust_optimize_time(const mxArray **prhs, const int nrhs, mxArray **plhs, const int nlhs);
#include "faust_optimize_time.hpp"
#endif
#include "class_handle.hpp"
#include "faust_TransformHelper.h"
template <typename SCALAR, FDevice DEV>
void faust_optimize_time(const mxArray **prhs, const int nrhs, mxArray **plhs, const int nlhs)
{
Faust::TransformHelper<SCALAR,DEV>* core_ptr = convertMat2Ptr<Faust::TransformHelper<SCALAR,DEV> >(prhs[1]);
if(nrhs != 5)
mexErrMsgTxt("optimize_time mex error: invalid number of arguments.");
if(nlhs != 1 && nlhs != 0)
mexErrMsgTxt("optimize_time mex error: this function doesn't return more than one argument.");
bool transp = (bool) mxGetScalar(prhs[2]);
bool inplace = (bool) mxGetScalar(prhs[3]);
int nsamples = (int) mxGetScalar(prhs[4]);
Faust::TransformHelper<SCALAR,DEV>* th = core_ptr->optimize_time(transp, inplace, nsamples);
if(inplace /*th == nullptr*/)
return;
plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR,DEV> >(th);
}
...@@ -79,7 +79,12 @@ ...@@ -79,7 +79,12 @@
#include "faust_conj.h" #include "faust_conj.h"
#include "faust_transpose.h" #include "faust_transpose.h"
#include "faust_ctranspose.h" #include "faust_ctranspose.h"
#include "faust_nnz.h"
#include "faust_pruneout.h"
#include "faust_optimize_storage.h"
#include "faust_optimize.h"
#include "faust_optimize_time.h"
#include "faust_multiply.h"
typedef @FAUST_SCALAR@ SCALAR; typedef @FAUST_SCALAR@ SCALAR;
typedef @FAUST_FPP@ FPP; typedef @FAUST_FPP@ FPP;
...@@ -360,16 +365,10 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -360,16 +365,10 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
plhs[0] = mxCreateDoubleScalar((double) core_ptr->isReal()); plhs[0] = mxCreateDoubleScalar((double) core_ptr->isReal());
return; return;
} }
// return the number of non zeros coefficients of the matrix
if (!strcmp("nnz",cmd)) if (!strcmp("nnz",cmd))
{ {
if (nlhs > 1 || nrhs != 2) faust_nnz<SCALAR, Cpu>(prhs, nrhs, plhs, nlhs);
{
mexErrMsgTxt("nnz : incorrect number of arguments.");
}
long long int nnz = core_ptr->get_total_nnz();
plhs[0]=mxCreateDoubleScalar(nnz);
return; return;
} }
...@@ -428,78 +427,9 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -428,78 +427,9 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
return; return;
} }
if (!strcmp("multiply", cmd))
if (!strcmp("multiply", cmd)) { {
faust_multiply<SCALAR, Cpu>(prhs, nrhs, plhs, nlhs);
if (nlhs > 1 || nrhs != 4)
mexErrMsgTxt("Multiply: Unexcepted number of arguments.");
mwSize nelem = mxGetNumberOfElements(prhs[3]);
if (nelem != 1)
mexErrMsgTxt("invalid char argument.");
// boolean flag to know if the faust needs to be transposed
bool transpose_flag = (bool) mxGetScalar(prhs[3]);
// input matrix or vector from MATLAB
const mxArray * inMatlabMatrix = prhs[2];
if(mxIsSparse(inMatlabMatrix))
{
Faust::MatSparse<SCALAR,Cpu> spA;
mxArray2FaustspMat<SCALAR>(inMatlabMatrix, spA);
Faust::MatDense<SCALAR,Cpu> B;
B = (*core_ptr).multiply(spA, transpose_flag);
plhs[0] = FaustMat2mxArray(B);
}
else
{
const size_t nbRowA = mxGetM(inMatlabMatrix);
const size_t nbColA = mxGetN(inMatlabMatrix);
faust_unsigned_int nbRowOp_,nbColOp_;
const size_t nbRowOp = core_ptr->getNbRow();
const size_t nbColOp = core_ptr->getNbCol();
const size_t nbRowB = nbRowOp;
const size_t nbColB = nbColA;
/** Check parameters **/
//check dimension match
if (mxGetNumberOfDimensions(inMatlabMatrix) != 2
|| nbRowA != nbColOp && (nbRowA != nbRowOp && transpose_flag))
mexErrMsgTxt("Multiply : Wrong number of dimensions for the input vector or matrix (third argument).");
SCALAR* ptr_data = NULL;
if ((core_ptr->isReal() ) && ( mxIsComplex(inMatlabMatrix) ) )
mexErrMsgTxt("impossibility to multiply a real Faust with complex matrix");
mxArray2Ptr(inMatlabMatrix, ptr_data);
if(nbColA == 1)
{
// applying the Faust to a vector
Faust::Vect<SCALAR,Cpu> A(nbRowA, ptr_data);
Faust::Vect<SCALAR,Cpu> B(nbRowB);
B = (*core_ptr).multiply(A, transpose_flag);
plhs[0]=FaustVec2mxArray(B);
}
else
{ // applying the Faust to a matrix
Faust::MatDense<SCALAR,Cpu> A(ptr_data, nbRowA, nbColA);
Faust::MatDense<SCALAR,Cpu> B(nbRowB, nbColA);
B = (*core_ptr).multiply(A, transpose_flag);
plhs[0]=FaustMat2mxArray(B);
}
if(ptr_data) {delete [] ptr_data ; ptr_data = NULL;}
}
return; return;
} }
...@@ -508,55 +438,26 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -508,55 +438,26 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
if(!strcmp("optimize_storage", cmd)) { //TODO: verify no arguments passed or if(!strcmp("optimize_storage", cmd)) {
if(nrhs != 3) faust_optimize_storage<SCALAR, Cpu>(prhs, nrhs, plhs, nlhs);
mexErrMsgTxt("optimize_storage mex error: invalid number of arguments.");
bool timeCrit = (bool) mxGetScalar(prhs[2]);
Faust::TransformHelper<SCALAR,Cpu>* th = core_ptr->optimize_storage(timeCrit);
plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR,Cpu> >(th);
return; return;
} }
if(!strcmp("optimize", cmd)) { if(!strcmp("optimize", cmd)) {
if(nrhs != 3) faust_optimize<SCALAR, Cpu>(prhs, nrhs, plhs, nlhs);
mexErrMsgTxt("optimize mex error: invalid number of arguments.");
bool transp = (bool) mxGetScalar(prhs[2]);
Faust::TransformHelper<SCALAR,Cpu>* th = core_ptr->optimize(transp);
plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR,Cpu> >(th);
return; return;
} }
if(!strcmp("optimize_time", cmd)) if(!strcmp("optimize_time", cmd))
{ {
if(nrhs != 5) faust_optimize_time<SCALAR, Cpu>(prhs, nrhs, plhs, nlhs);
mexErrMsgTxt("optimize_time mex error: invalid number of arguments.");
if(nlhs != 1 && nlhs != 0)
mexErrMsgTxt("optimize_time mex error: this function doesn't return more than one argument.");
bool transp = (bool) mxGetScalar(prhs[2]);
bool inplace = (bool) mxGetScalar(prhs[3]);
int nsamples = (int) mxGetScalar(prhs[4]);
Faust::TransformHelper<SCALAR,Cpu>* th = core_ptr->optimize_time(transp, inplace, nsamples);
if(inplace /*th == nullptr*/)
return;
plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR,Cpu> >(th);
return; return;
} }
if(! strcmp("pruneout", cmd)) if(! strcmp("pruneout", cmd))
{ {
int nnz_tres = 0; faust_pruneout<SCALAR, Cpu>(prhs, nrhs, plhs, nlhs);
int npasses = -1;
bool only_forward = false;
if (nlhs == 1 || nrhs == 5)
{
nnz_tres = (int) mxGetScalar(prhs[2]);
npasses = (int) mxGetScalar(prhs[3]);
only_forward = (bool) mxGetScalar(prhs[4]);
}
else
mexErrMsgTxt("pruneout mex error: number of arguments must be 3.");
Faust::TransformHelper<SCALAR,Cpu>* th = core_ptr->pruneout(nnz_tres, npasses, only_forward);
plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR,Cpu> >(th);
return; return;
} }
......
...@@ -79,7 +79,12 @@ ...@@ -79,7 +79,12 @@
#include "faust_conj.h" #include "faust_conj.h"
#include "faust_transpose.h" #include "faust_transpose.h"
#include "faust_ctranspose.h" #include "faust_ctranspose.h"
#include "faust_nnz.h"
#include "faust_pruneout.h"
#include "faust_optimize_storage.h"
#include "faust_optimize.h"
#include "faust_optimize_time.h"
#include "faust_multiply.h"
typedef @FAUST_SCALAR@ SCALAR; typedef @FAUST_SCALAR@ SCALAR;
typedef @FAUST_FPP@ FPP; typedef @FAUST_FPP@ FPP;
...@@ -122,6 +127,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -122,6 +127,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
faust_delete<SCALAR,GPU2>(prhs, nrhs, plhs, nlhs); faust_delete<SCALAR,GPU2>(prhs, nrhs, plhs, nlhs);
else if(!strcmp("size", cmd)) else if(!strcmp("size", cmd))
faust_size<SCALAR,GPU2>(prhs, nrhs, plhs, nlhs); faust_size<SCALAR,GPU2>(prhs, nrhs, plhs, nlhs);
else if(!strcmp("nnz", cmd))
faust_nnz<SCALAR, GPU2>(prhs, nrhs, plhs, nlhs);
else if(!strcmp("full", cmd)) else if(!strcmp("full", cmd))
faust_full<SCALAR,GPU2>(prhs, nrhs, plhs, nlhs); faust_full<SCALAR,GPU2>(prhs, nrhs, plhs, nlhs);
else if(!strcmp("norm", cmd)) else if(!strcmp("norm", cmd))
...@@ -146,6 +153,16 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -146,6 +153,16 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
faust_transpose<SCALAR,GPU2>(prhs, nrhs, plhs, nlhs); faust_transpose<SCALAR,GPU2>(prhs, nrhs, plhs, nlhs);
else if(!strcmp("ctranspose", cmd)) else if(!strcmp("ctranspose", cmd))
faust_ctranspose<SCALAR,GPU2>(prhs, nrhs, plhs, nlhs); faust_ctranspose<SCALAR,GPU2>(prhs, nrhs, plhs, nlhs);
else if(! strcmp("pruneout", cmd))
faust_pruneout<SCALAR, GPU2>(prhs, nrhs, plhs, nlhs);
else if(!strcmp("optimize_storage", cmd))
faust_optimize_storage<SCALAR, GPU2>(prhs, nrhs, plhs, nlhs);
else if(!strcmp("optimize_time", cmd))
faust_optimize_time<SCALAR, GPU2>(prhs, nrhs, plhs, nlhs);
else if(!strcmp("optimize", cmd))
faust_optimize<SCALAR, GPU2>(prhs, nrhs, plhs, nlhs);
else if (!strcmp("multiply", cmd))
faust_multiply<SCALAR, GPU2>(prhs, nrhs, plhs, nlhs);
} }
catch (const std::exception& e) catch (const std::exception& e)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment