Diff of /mex/vect2cell.c [000000] .. [6db11f]  Maximize  Restore

Switch to unified view

a b/mex/vect2cell.c
1
#ifndef _LTFAT_MEX_FILE
2
#define _LTFAT_MEX_FILE
3
4
#define ISNARGINEQ 2
5
#define TYPEDEPARGS 0
6
#define SINGLEARGS
7
#define COMPLEXINDEPENDENT
8
#define NOCOMPLEXFMTCHANGE
9
10
#endif // _LTFAT_MEX_FILE - INCLUDED ONCE
11
12
/* Assuming __BASE_FILE__ is known by the compiler.
13
   Otherwise specify this filename
14
   e.g. #define MEX_FILE "comp_col2diag.c"  */
15
#define MEX_FILE __BASE_FILE__
16
#include "ltfat_mex_template_helper.h"
17
18
#if defined(LTFAT_SINGLE) || defined(LTFAT_DOUBLE)
19
#include "ltfat_types.h"
20
21
// LTFAT_COMPLEXTYPE, LTFAT_SINGLE, LTFAT_DOUBLE
22
23
/* Calling convention:
24
 *  c=vect2cell(x,idx);
25
 */
26
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] )
27
{
28
    mwSize L = mxGetM(prhs[0]);
29
    mwSize W = mxGetN(prhs[0]);
30
    mwSize M = mxGetNumberOfElements(prhs[1]);
31
    double* Lc = mxGetData(prhs[1]);
32
33
    plhs[0] = mxCreateCellMatrix(M,1);
34
    LTFAT_REAL* cPr[M];
35
    LTFAT_REAL* cPi[M];
36
37
    for(mwIndex ii=0;ii<M;ii++)
38
    {
39
        mxArray* tmpA = ltfatCreateMatrix((mwSize)Lc[ii], W,LTFAT_MX_CLASSID,LTFAT_MX_COMPLEXITY);
40
        mxSetCell(plhs[0],ii,tmpA);
41
        cPr[ii] = (LTFAT_REAL*) mxGetPr(tmpA);
42
        cPi[ii] = (LTFAT_REAL*) mxGetPi(tmpA);
43
    }
44
45
    LTFAT_REAL* xPr = (LTFAT_REAL*) mxGetPr(prhs[0]);
46
    LTFAT_REAL* xPi = (LTFAT_REAL*) mxGetPi(prhs[0]);
47
48
49
    for(mwIndex w=0;w<W;w++)
50
    {
51
       LTFAT_REAL* xTmp = xPr + w*L;
52
       for(mwIndex ii=0;ii<M;ii++)
53
       {
54
           mwSize LcTmp = (mwSize)Lc[ii];
55
           LTFAT_REAL* cTmp = cPr[ii] + w*LcTmp;
56
           memcpy(cTmp,xTmp,LcTmp*sizeof(LTFAT_REAL));
57
           xTmp+=LcTmp;
58
       }
59
    }
60
61
      #ifdef LTFAT_COMPLEXTYPE
62
    for(mwIndex w=0;w<W;w++)
63
    {
64
       LTFAT_REAL* xTmp = xPi + w*L;
65
       for(mwIndex ii=0;ii<M;ii++)
66
       {
67
           mwSize LcTmp = (mwSize)Lc[ii];
68
           LTFAT_REAL* cTmp = cPi[ii] + w*LcTmp;
69
           memcpy(cTmp,xTmp,LcTmp*sizeof(LTFAT_REAL));
70
           xTmp+=LcTmp;
71
       }
72
    }
73
      #endif
74
75
}
76
#endif
77
78
79
80
81
/* Calling convention:
82
 *  cout=comp_col2diag(cin);
83
 */
84
/*
85
void mexFunction( int nlhs, mxArray *plhs[],
86
        int nrhs, const mxArray *prhs[] )
87
88
{
89
90
91
   int L;
92
   double *cin_r,*cin_i, *cout_r,*cout_i;
93
94
   // Get matrix dimensions.
95
   L = mxGetM(prhs[0]);
96
97
   cin_r=mxGetPr(prhs[0]);
98
99
   if (mxIsComplex(prhs[0]))
100
   {
101
      plhs[0] = mxCreateDoubleMatrix(L,L, mxCOMPLEX);
102
   }
103
   else
104
   {
105
      plhs[0] = mxCreateDoubleMatrix(L,L, mxREAL);
106
   }
107
108
   // Treat the real part
109
   cout_r=mxGetPr(plhs[0]);
110
   col2diag_r((double*)cin_r, L, (double*)cout_r);
111
112
   if (mxIsComplex(prhs[0]))
113
   {
114
      // Treat the imaginary part
115
      cin_i=mxGetPi(prhs[0]);
116
      cout_i=mxGetPi(plhs[0]);
117
      col2diag_r((double*)cin_i, L, (double*)cout_i);
118
   }
119
120
   return;
121
122
}
123
*/
124
125

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks