Mentions légales du service

Skip to content
Snippets Groups Projects
Commit db99f6c3 authored by Nicolas Bellot's avatar Nicolas Bellot Committed by hhakim
Browse files

wrapper matlab : mexFaust (preparation a la compatibilite complexe)

parent a9c11edf
No related branches found
No related tags found
No related merge requests found
...@@ -272,7 +272,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -272,7 +272,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
const size_t SIZE_B2 = nbColOp; const size_t SIZE_B2 = nbColOp;
Faust::MatDense<FFPP,Cpu> prod=core_ptr->get_product(op); Faust::MatDense<FFPP,Cpu> prod=core_ptr->get_product(op);
const mwSize dims[2]={SIZE_B1,SIZE_B2}; const mwSize dims[2]={SIZE_B1,SIZE_B2};
if(sizeof(FFPP)==sizeof(float)) /*if(sizeof(FFPP)==sizeof(float))
plhs[0] = mxCreateNumericArray(2, dims, mxSINGLE_CLASS, mxREAL); plhs[0] = mxCreateNumericArray(2, dims, mxSINGLE_CLASS, mxREAL);
else if(sizeof(FFPP)==sizeof(double)) else if(sizeof(FFPP)==sizeof(double))
plhs[0] = mxCreateNumericArray(2, dims, mxDOUBLE_CLASS, mxREAL); plhs[0] = mxCreateNumericArray(2, dims, mxDOUBLE_CLASS, mxREAL);
...@@ -281,7 +281,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -281,7 +281,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
FFPP* ptr_out = static_cast<FFPP*> (mxGetData(plhs[0])); FFPP* ptr_out = static_cast<FFPP*> (mxGetData(plhs[0]));
memcpy(ptr_out, prod.getData(), SIZE_B1*SIZE_B2*sizeof(FFPP)); memcpy(ptr_out, prod.getData(), SIZE_B1*SIZE_B2*sizeof(FFPP));
*/
plhs[0] = FaustMat2mxArray(prod);
return; return;
} }
...@@ -381,7 +382,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -381,7 +382,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
mexErrMsgTxt("Multiply : Wrong scalar compatibility (real/complex)"); mexErrMsgTxt("Multiply : Wrong scalar compatibility (real/complex)");
/*
FFPP* ptr_data = NULL; FFPP* ptr_data = NULL;
const mxClassID V_CLASS_ID = mxGetClassID(inMatlabMatrix); const mxClassID V_CLASS_ID = mxGetClassID(inMatlabMatrix);
...@@ -458,8 +459,11 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -458,8 +459,11 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
} }
else else
mexErrMsgTxt("Unknown matlab type."); mexErrMsgTxt("Unknown matlab type.");
*/
FFPP* ptr_data = NULL;
mxArray2Ptr(inMatlabMatrix, ptr_data);
// Si inMatlabMatrix est un vecteur // Si inMatlabMatrix est un vecteur
if(nbColA == 1) if(nbColA == 1)
{ {
...@@ -469,7 +473,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -469,7 +473,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
//B = (*core_ptr)*A; //B = (*core_ptr)*A;
B = (*core_ptr).multiply(A,op); B = (*core_ptr).multiply(A,op);
const mwSize dims[2]={nbRowB,nbColB}; /*const mwSize dims[2]={nbRowB,nbColB};
if(sizeof(FFPP)==sizeof(float)) if(sizeof(FFPP)==sizeof(float))
plhs[0] = mxCreateNumericArray(2, dims, mxSINGLE_CLASS, mxREAL); plhs[0] = mxCreateNumericArray(2, dims, mxSINGLE_CLASS, mxREAL);
else if(sizeof(FFPP)==sizeof(double)) else if(sizeof(FFPP)==sizeof(double))
...@@ -478,7 +482,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -478,7 +482,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
mexErrMsgTxt("FFPP type is neither double nor float"); mexErrMsgTxt("FFPP type is neither double nor float");
FFPP* ptr_out = static_cast<FFPP*> (mxGetData(plhs[0])); FFPP* ptr_out = static_cast<FFPP*> (mxGetData(plhs[0]));
memcpy(ptr_out, B.getData(), nbRowB*nbColB*sizeof(FFPP)); memcpy(ptr_out, B.getData(), nbRowB*nbColB*sizeof(FFPP));*/
plhs[0]=FaustVec2mxArray(B);
} }
// Si inMatlabMatrix est une matrice // Si inMatlabMatrix est une matrice
else else
...@@ -486,7 +491,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -486,7 +491,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Faust::MatDense<FFPP,Cpu> A(ptr_data, nbRowA, nbColA); Faust::MatDense<FFPP,Cpu> A(ptr_data, nbRowA, nbColA);
Faust::MatDense<FFPP,Cpu> B(nbRowB, nbColA); Faust::MatDense<FFPP,Cpu> B(nbRowB, nbColA);
B = (*core_ptr).multiply(A,op); B = (*core_ptr).multiply(A,op);
const mwSize dims[2]={nbRowB,nbColB}; /*const mwSize dims[2]={nbRowB,nbColB};
if(sizeof(FFPP)==sizeof(float)) if(sizeof(FFPP)==sizeof(float))
plhs[0] = mxCreateNumericArray(2, dims, mxSINGLE_CLASS, mxREAL); plhs[0] = mxCreateNumericArray(2, dims, mxSINGLE_CLASS, mxREAL);
else if(sizeof(FFPP)==sizeof(double)) else if(sizeof(FFPP)==sizeof(double))
...@@ -496,6 +501,9 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -496,6 +501,9 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
FFPP* ptr_out = static_cast<FFPP*> (mxGetData(plhs[0])); FFPP* ptr_out = static_cast<FFPP*> (mxGetData(plhs[0]));
memcpy(ptr_out, B.getData(), nbRowB*nbColB*sizeof(FFPP)); memcpy(ptr_out, B.getData(), nbRowB*nbColB*sizeof(FFPP));
*/
plhs[0]=FaustMat2mxArray(B);
} }
if(ptr_data) {delete [] ptr_data ; ptr_data = NULL;} if(ptr_data) {delete [] ptr_data ; ptr_data = NULL;}
......
...@@ -98,7 +98,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -98,7 +98,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
// initialization of the matrix that will be factorized // initialization of the matrix that will be factorized
Faust::MatDense<FFPP,Cpu> matrix; Faust::MatDense<FFPP,Cpu> matrix;
getFaustMat(matlab_matrix,matrix); mxArray2FaustMat(matlab_matrix,matrix);
// nrow of the matrix that will be factorized // nrow of the matrix that will be factorized
int nb_row = -1; int nb_row = -1;
......
...@@ -96,7 +96,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -96,7 +96,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{ {
mxCurrentField = mxGetField(prhs[0],0,"data"); mxCurrentField = mxGetField(prhs[0],0,"data");
getFaustMat( mxCurrentField,data ) ; mxArray2FaustMat( mxCurrentField,data ) ;
/*mexPrintf("DATA"); /*mexPrintf("DATA");
for (int i = 0;i<data.getNbRow();i++) for (int i = 0;i<data.getNbRow();i++)
{ {
......
...@@ -74,7 +74,7 @@ bool isScalarCompatible(const Faust::LinearOperator<FPP,Cpu> & L,const mxArray * ...@@ -74,7 +74,7 @@ bool isScalarCompatible(const Faust::LinearOperator<FPP,Cpu> & L,const mxArray *
* \tparam vec : Faust::Vect<FPP,Cpu> * \tparam vec : Faust::Vect<FPP,Cpu>
*/ */
template<typename FPP> template<typename FPP>
void getFaustVec(const mxArray * vec_array,Faust::Vect<FPP,Cpu> & vec); void mxArray2FaustVec(const mxArray * vec_array,Faust::Vect<FPP,Cpu> & vec);
/*! /*!
* \brief convert the matlab mxArray* into a Faust::MatDense<FPP,Cpu>, no shared memory * \brief convert the matlab mxArray* into a Faust::MatDense<FPP,Cpu>, no shared memory
...@@ -82,7 +82,7 @@ void getFaustVec(const mxArray * vec_array,Faust::Vect<FPP,Cpu> & vec); ...@@ -82,7 +82,7 @@ void getFaustVec(const mxArray * vec_array,Faust::Vect<FPP,Cpu> & vec);
* \tparam Mat : Faust::MatDense<FPP,Cpu> * \tparam Mat : Faust::MatDense<FPP,Cpu>
*/ */
template<typename FPP> template<typename FPP>
void getFaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat); void mxArray2FaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat);
/*! /*!
* \brief convert the matlab mxArray* into a Faust::Vect<FPP,Cpu>, no shared memory * \brief convert the matlab mxArray* into a Faust::Vect<FPP,Cpu>, no shared memory
...@@ -90,16 +90,27 @@ void getFaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat); ...@@ -90,16 +90,27 @@ void getFaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat);
* \tparam S : Faust::MatSparse<FPP,Cpu> * \tparam S : Faust::MatSparse<FPP,Cpu>
*/ */
template<typename FPP> template<typename FPP>
void getFaustspMat(const mxArray* spMat_array,Faust::MatSparse<FPP,Cpu> & S); void mxArray2FaustspMat(const mxArray* spMat_array,Faust::MatSparse<FPP,Cpu> & S);
/*! /*!
* \brief return a matlab mxArray* dense matrix from a Faust::MatDense<FPP,Cpu>, no shared memory * \brief return a matlab mxArray* dense matrix from a Faust::MatDense<FPP,Cpu>, no shared memory
* \param[out] mxArray* : pointer to the mxArray* (matlab format) representing a dense matrix * \param[out] mxArray* : pointer to the mxArray* (matlab format) representing a dense matrix
* \tparam[in] S : Faust::MatDense<FPP,Cpu> * \tparam[in] M : Faust::MatDense<FPP,Cpu>
*/ */
template<typename FPP> template<typename FPP>
mxArray* FaustMat2mxArray(const Faust::MatDense<FPP,Cpu>& M); mxArray* FaustMat2mxArray(const Faust::MatDense<FPP,Cpu>& M);
/*!
* \brief return a matlab mxArray* dense matrix from a Faust::MatVec<FPP,Cpu>, no shared memory
* \param[out] mxArray* : pointer to the mxArray* (matlab format) representing a dense matrix
* \tparam[in] M : Faust::Vec<FPP,Cpu>
*/
template<typename FPP>
mxArray* FaustVec2mxArray(const Faust::Vect<FPP,Cpu>& M);
/*! /*!
* \brief return a matlab mxArray** representing a cell-array of matlab matrix from a std::vector<Faust::MatDense<FPP,Cpu> >, no shared memory * \brief return a matlab mxArray** representing a cell-array of matlab matrix from a std::vector<Faust::MatDense<FPP,Cpu> >, no shared memory
* \param[out] cellfacts : matlab cell-array of matlab dense matrix * \param[out] cellfacts : matlab cell-array of matlab dense matrix
...@@ -123,6 +134,12 @@ void getConstraint(std::vector<const Faust::ConstraintGeneric<FPP,Cpu>*> & consS ...@@ -123,6 +134,12 @@ void getConstraint(std::vector<const Faust::ConstraintGeneric<FPP,Cpu>*> & consS
template<typename FPP>
void mxArray2Ptr(const mxArray* mxMat, FPP* & data_ptr);
/*! /*!
* \brief convert the matlab mxMat* into a Faust::MatSparse<FPP,Cpu> and push it to the end of the list vec_spmat * \brief convert the matlab mxMat* into a Faust::MatSparse<FPP,Cpu> and push it to the end of the list vec_spmat
* \param * mxMat : pointer to the matlab matrix format * \param * mxMat : pointer to the matlab matrix format
......
...@@ -69,7 +69,7 @@ bool isScalarCompatible(Faust::LinearOperator<FPP,Cpu> & L, const mxArray * Matl ...@@ -69,7 +69,7 @@ bool isScalarCompatible(Faust::LinearOperator<FPP,Cpu> & L, const mxArray * Matl
template<typename FPP> template<typename FPP>
void getFaustVec(const mxArray * vec_array,Faust::Vect<FPP,Cpu> & vec) void mxArray2FaustVec(const mxArray * vec_array,Faust::Vect<FPP,Cpu> & vec)
{ {
int nbRow,nbCol; int nbRow,nbCol;
...@@ -142,7 +142,7 @@ void getFaustVec(const mxArray * vec_array,Faust::Vect<FPP,Cpu> & vec) ...@@ -142,7 +142,7 @@ void getFaustVec(const mxArray * vec_array,Faust::Vect<FPP,Cpu> & vec)
template<typename FPP> template<typename FPP>
void getFaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat) void mxArray2FaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat)
{ {
int nbRow,nbCol; int nbRow,nbCol;
...@@ -153,12 +153,12 @@ void getFaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat) ...@@ -153,12 +153,12 @@ void getFaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat)
if (mxIsEmpty(Mat_array)) if (mxIsEmpty(Mat_array))
{ {
mexErrMsgTxt("tools_mex.h:getFaustMat :input matrix is empty."); mexErrMsgTxt("tools_mex.h:mxArray2FaustMat :input matrix is empty.");
} }
mwSize nb_dim=mxGetNumberOfDimensions(Mat_array); mwSize nb_dim=mxGetNumberOfDimensions(Mat_array);
if (nb_dim != 2) if (nb_dim != 2)
{ {
mexErrMsgTxt("tools_mex.h:getFaustMat :input matrix must be a 2D array."); mexErrMsgTxt("tools_mex.h:mxArray2FaustMat :input matrix must be a 2D array.");
} }
const mwSize *dimsMat; const mwSize *dimsMat;
dimsMat = mxGetDimensions(Mat_array); dimsMat = mxGetDimensions(Mat_array);
...@@ -166,7 +166,7 @@ void getFaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat) ...@@ -166,7 +166,7 @@ void getFaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat)
nbRow = (int) dimsMat[0]; nbRow = (int) dimsMat[0];
nbCol = (int) dimsMat[1]; nbCol = (int) dimsMat[1];
if ((nbRow == 0) || (nbCol == 0)) if ((nbRow == 0) || (nbCol == 0))
mexErrMsgIdAndTxt("tools_mex.h:getFaustMat", "empty matrix"); mexErrMsgIdAndTxt("tools_mex.h:mxArray2FaustMat", "empty matrix");
if (mxIsSparse(Mat_array)) if (mxIsSparse(Mat_array))
{ {
//mexErrMsgTxt("sparse matrix entry instead of dense matrix"); //mexErrMsgTxt("sparse matrix entry instead of dense matrix");
...@@ -175,7 +175,7 @@ void getFaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat) ...@@ -175,7 +175,7 @@ void getFaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat)
//check scalar compayibility //check scalar compayibility
if (!isScalarCompatible(Mat,Mat_array)) if (!isScalarCompatible(Mat,Mat_array))
mexErrMsgTxt("getFaustMat scalar type (complex/real) are not compatible"); mexErrMsgTxt("mxArray2FaustMat scalar type (complex/real) are not compatible");
const mxClassID V_CLASS_ID = mxGetClassID(Mat_array); const mxClassID V_CLASS_ID = mxGetClassID(Mat_array);
FPP* MatPtr; FPP* MatPtr;
...@@ -201,7 +201,7 @@ void getFaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat) ...@@ -201,7 +201,7 @@ void getFaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat)
}else }else
{ {
mexErrMsgTxt("getFaustMat :input matrix format must be single or double"); mexErrMsgTxt("mxArray2FaustMat :input matrix format must be single or double");
} }
} }
...@@ -218,17 +218,17 @@ void getFaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat) ...@@ -218,17 +218,17 @@ void getFaustMat(const mxArray* Mat_array,Faust::MatDense<FPP,Cpu> & Mat)
} }
template<typename FPP> template<typename FPP>
void getFaustspMat(const mxArray* spMat_array,Faust::MatSparse<FPP,Cpu> & S) void mxArray2FaustspMat(const mxArray* spMat_array,Faust::MatSparse<FPP,Cpu> & S)
{ {
if (!mxIsSparse(spMat_array)) if (!mxIsSparse(spMat_array))
{ {
mexErrMsgIdAndTxt("tools_mex.h:getFaustspMat", mexErrMsgIdAndTxt("tools_mex.h:mxArray2FaustspMat",
"input array must be sparse"); "input array must be sparse");
} }
//check scalar compayibility //check scalar compayibility
if (!isScalarCompatible(S,spMat_array)) if (!isScalarCompatible(S,spMat_array))
mexErrMsgTxt("getFaustspMat scalar type (complex/real) are not compatible"); mexErrMsgTxt("mxArray2FaustspMat scalar type (complex/real) are not compatible");
int nnzMax = mxGetNzmax(spMat_array); int nnzMax = mxGetNzmax(spMat_array);
int nbCol = mxGetN(spMat_array); int nbCol = mxGetN(spMat_array);
int nbRow = mxGetM(spMat_array); int nbRow = mxGetM(spMat_array);
...@@ -259,11 +259,15 @@ void getFaustspMat(const mxArray* spMat_array,Faust::MatSparse<FPP,Cpu> & S) ...@@ -259,11 +259,15 @@ void getFaustspMat(const mxArray* spMat_array,Faust::MatSparse<FPP,Cpu> & S)
template<typename FPP> template<typename FPP>
mxArray* FaustMat2mxArray(const Faust::MatDense<FPP,Cpu>& M) mxArray* FaustMat2mxArray(const Faust::MatDense<FPP,Cpu>& M)
{ {
mxArray * mxMat; if (!M.isReal())
int row,col; mexErrMsgTxt("FaustMat2mxArray : Faust::MatDense must be real");
row = M.getNbRow();
mxArray * mxMat;
int row,col;
row = M.getNbRow();
col = M.getNbCol(); col = M.getNbCol();
mxMat = mxCreateDoubleMatrix(row,col,mxREAL);
/*mxMat = mxCreateDoubleMatrix(row,col,mxREAL);
double* mxMatdata = mxGetPr(mxMat); double* mxMatdata = mxGetPr(mxMat);
if (typeid(double) == typeid(FPP)) if (typeid(double) == typeid(FPP))
...@@ -279,13 +283,70 @@ mxArray* FaustMat2mxArray(const Faust::MatDense<FPP,Cpu>& M) ...@@ -279,13 +283,70 @@ mxArray* FaustMat2mxArray(const Faust::MatDense<FPP,Cpu>& M)
memcpy(mxMatdata,mat_ptr,sizeof(double)*row*col); memcpy(mxMatdata,mat_ptr,sizeof(double)*row*col);
mxFree(mat_ptr); mxFree(mat_ptr);
} }*/
const mwSize dims[2]={row,col};
if(typeid(FFPP)==typeid(float))
{
mxMat = mxCreateNumericArray(2, dims, mxSINGLE_CLASS, mxREAL);
}else if(sizeof(FFPP)==sizeof(double))
{
mxMat = mxCreateNumericArray(2, dims, mxDOUBLE_CLASS, mxREAL);
}
FPP* ptr_out = static_cast<FPP*> (mxGetData(mxMat));
memcpy(ptr_out, M.getData(),row*col*sizeof(FPP));
return mxMat;
}
template<typename FPP>
mxArray* FaustVec2mxArray(const Faust::Vect<FPP,Cpu>& M)
{
if (!M.isReal())
mexErrMsgTxt("FaustMat2mxArray : Faust::MatDense must be real");
mxArray * mxMat;
int row,col;
row = M.size();
col = 1;
const mwSize dims[2]={row,col};
if(typeid(FFPP)==typeid(float))
{
mxMat = mxCreateNumericArray(2, dims, mxSINGLE_CLASS, mxREAL);
}else if(sizeof(FFPP)==sizeof(double))
{
mxMat = mxCreateNumericArray(2, dims, mxDOUBLE_CLASS, mxREAL);
}
FPP* ptr_out = static_cast<FPP*> (mxGetData(mxMat));
memcpy(ptr_out, M.getData(),row*col*sizeof(FPP));
return mxMat; return mxMat;
} }
template<typename FPP> template<typename FPP>
void setCellFacts(mxArray ** cellFacts,std::vector<Faust::MatDense<FPP,Cpu> >& facts) void setCellFacts(mxArray ** cellFacts,std::vector<Faust::MatDense<FPP,Cpu> >& facts)
{ {
...@@ -344,7 +405,7 @@ void setVectorFaustMat(std::vector<Faust::MatDense<FPP,Cpu> > &vecMat,mxArray *C ...@@ -344,7 +405,7 @@ void setVectorFaustMat(std::vector<Faust::MatDense<FPP,Cpu> > &vecMat,mxArray *C
mexErrMsgTxt("tools_mex.h:setVectorFaustMat :input matrix is empty."); mexErrMsgTxt("tools_mex.h:setVectorFaustMat :input matrix is empty.");
} }
mexPrintf("mxMat test_empty\n",i); mexPrintf("mxMat test_empty\n",i);
getFaustMat(mxMat,mat); mxArray2FaustMat(mxMat,mat);
mexPrintf("mat set\n",i); mexPrintf("mat set\n",i);
vecMat.push_back(mat); vecMat.push_back(mat);
} }
...@@ -406,7 +467,7 @@ void getConstraint(std::vector<const Faust::ConstraintGeneric<FPP,Cpu>*> & consS ...@@ -406,7 +467,7 @@ void getConstraint(std::vector<const Faust::ConstraintGeneric<FPP,Cpu>*> & consS
{ {
mxConsParams=mxGetCell(mxCons,1); mxConsParams=mxGetCell(mxCons,1);
Faust::MatDense<FPP,Cpu> matParameter; Faust::MatDense<FPP,Cpu> matParameter;
getFaustMat(mxConsParams,matParameter); mxArray2FaustMat(mxConsParams,matParameter);
consS.push_back((new Faust::ConstraintMat<FPP,Cpu>(consNameType,matParameter,nbRowCons,nbColCons))); consS.push_back((new Faust::ConstraintMat<FPP,Cpu>(consNameType,matParameter,nbRowCons,nbColCons)));
break; break;
} }
...@@ -431,12 +492,12 @@ void concatMatGeneric(const mxArray * mxMat,std::vector<Faust::MatGeneric<FPP,Cp ...@@ -431,12 +492,12 @@ void concatMatGeneric(const mxArray * mxMat,std::vector<Faust::MatGeneric<FPP,Cp
if (!mxIsSparse(mxMat)) if (!mxIsSparse(mxMat))
{ {
Faust::MatDense<FPP,Cpu> denseM; Faust::MatDense<FPP,Cpu> denseM;
getFaustMat(mxMat,denseM); mxArray2FaustMat(mxMat,denseM);
M=denseM.Clone(); M=denseM.Clone();
}else }else
{ {
Faust::MatSparse<FPP,Cpu> spM; Faust::MatSparse<FPP,Cpu> spM;
getFaustspMat(mxMat,spM); mxArray2FaustspMat(mxMat,spM);
M=spM.Clone(); M=spM.Clone();
} }
...@@ -447,6 +508,114 @@ void concatMatGeneric(const mxArray * mxMat,std::vector<Faust::MatGeneric<FPP,Cp ...@@ -447,6 +508,114 @@ void concatMatGeneric(const mxArray * mxMat,std::vector<Faust::MatGeneric<FPP,Cp
template<typename FPP>
void mxArray2Ptr(const mxArray* mxMat, FPP* & ptr_data)
{
const mxClassID V_CLASS_ID = mxGetClassID(mxMat);
const size_t NB_ELEMENTS = mxGetNumberOfElements(mxMat);
if(V_CLASS_ID == mxDOUBLE_CLASS)
{
double* ptr_data_tmp = static_cast<double*> (mxGetData(mxMat));
ptr_data = new FFPP[NB_ELEMENTS];
for (size_t i =0 ; i<NB_ELEMENTS ; i++)
ptr_data[i] = static_cast<FFPP> (ptr_data_tmp[i]);
}
else if(V_CLASS_ID == mxSINGLE_CLASS)
{
float* ptr_data_tmp = static_cast<float*> (mxGetData(mxMat));
ptr_data = new FFPP[NB_ELEMENTS];
for (size_t i =0 ; i<NB_ELEMENTS ; i++)
ptr_data[i] = static_cast<FFPP> (ptr_data_tmp[i]);
}
else if(V_CLASS_ID == mxINT8_CLASS)
{
char* ptr_data_tmp = static_cast<char*> (mxGetData(mxMat));
ptr_data = new FFPP[NB_ELEMENTS];
for (size_t i =0 ; i<NB_ELEMENTS ; i++)
ptr_data[i] = static_cast<FFPP> (ptr_data_tmp[i]);
}
else if(V_CLASS_ID == mxUINT8_CLASS)
{
unsigned char* ptr_data_tmp = static_cast<unsigned char*> (mxGetData(mxMat));
ptr_data = new FFPP[NB_ELEMENTS];
for (size_t i =0 ; i<NB_ELEMENTS ; i++)
ptr_data[i] = static_cast<FFPP> (ptr_data_tmp[i]);
}
else if(V_CLASS_ID == mxINT16_CLASS)
{
short* ptr_data_tmp = static_cast<short*> (mxGetData(mxMat));
ptr_data = new FFPP[NB_ELEMENTS];
for (size_t i =0 ; i<NB_ELEMENTS ; i++)
ptr_data[i] = static_cast<FFPP> (ptr_data_tmp[i]);
}
else if (V_CLASS_ID == mxUINT16_CLASS)
{
unsigned short* ptr_data_tmp = static_cast<unsigned short*> (mxGetData(mxMat));
ptr_data = new FFPP[NB_ELEMENTS];
for (size_t i =0 ; i<NB_ELEMENTS ; i++)
ptr_data[i] = static_cast<FFPP> (ptr_data_tmp[i]);
}
else if (V_CLASS_ID == mxINT32_CLASS)
{
int* ptr_data_tmp = static_cast<int*> (mxGetData(mxMat));
ptr_data = new FFPP[NB_ELEMENTS];
for (size_t i =0 ; i<NB_ELEMENTS ; i++)
ptr_data[i] = static_cast<FFPP> (ptr_data_tmp[i]);
}
else if (V_CLASS_ID == mxUINT32_CLASS)
{
unsigned int* ptr_data_tmp = static_cast<unsigned int*> (mxGetData(mxMat));
ptr_data = new FFPP[NB_ELEMENTS];
for (size_t i =0 ; i<NB_ELEMENTS ; i++)
ptr_data[i] = static_cast<FFPP> (ptr_data_tmp[i]);
}
else if (V_CLASS_ID == mxINT64_CLASS)
{
long long* ptr_data_tmp = static_cast<long long*> (mxGetData(mxMat));
ptr_data = new FFPP[NB_ELEMENTS];
for (size_t i =0 ; i<NB_ELEMENTS ; i++)
ptr_data[i] = static_cast<FFPP> (ptr_data_tmp[i]);
}
else if (V_CLASS_ID == mxUINT64_CLASS)
{
unsigned long long* ptr_data_tmp = static_cast<unsigned long long*> (mxGetData(mxMat));
ptr_data = new FFPP[NB_ELEMENTS];
for (size_t i =0 ; i<NB_ELEMENTS ; i++)
ptr_data[i] = static_cast<FFPP> (ptr_data_tmp[i]);
}
else
mexErrMsgTxt("Unknown matlab type.");
}
// void testCoherence(const mxArray* params,std::vector<bool> & presentFields) // void testCoherence(const mxArray* params,std::vector<bool> & presentFields)
// { // {
// int nbr_field=mxGetNumberOfFields(params); // int nbr_field=mxGetNumberOfFields(params);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment