[6db11f]: mex / vect2cell.c Maximize Restore History

Download this file

vect2cell.c    126 lines (96 with data), 2.7 kB

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