mex_eig.cpp 768 Bytes
Newer Older
MAIRAL Julien's avatar
MAIRAL Julien committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <linalg.h>
#include <mexutils.h>

template <typename T>
inline void callFunction(mxArray* plhs[], const mxArray*prhs[]) {
   Matrix<T> X;
   getMatrix(prhs[0],X);
   const int m = X.m();
   plhs[0]=createMatrix<T>(m,m);
   Matrix<T> U;
   getMatrix(plhs[0],U);
   plhs[1]=createMatrix<T>(m,1);
   Vector<T> S;
   getVector(plhs[1],S);
   Matrix<T> Y;
   Y.copy(X);
   Y.SymEig(U,S);
}



void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]) {
   if (nrhs != 1)
      mexErrMsgTxt("Bad number of inputs arguments");

   if (nlhs != 2)
      mexErrMsgTxt("Bad number of output arguments");

   if (mxGetClassID(prhs[0]) == mxDOUBLE_CLASS) {
      callFunction<double>(plhs,prhs);
   } else {
      callFunction<float>(plhs,prhs);
   }
}