[a5c381]: mex / ltfat_mex_template_helper.h Maximize Restore History

Download this file

ltfat_mex_template_helper.h    646 lines (522 with data), 21.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
/***********************************************************************************
This file serves as a helper for the MEX files. It helps with the following issues:
1) Avoids code repetition by introducing type-independent code.
2) Handles Matlab complex numbers arrays format conversion (split to interleaved)
on-the-fly.
This header is meant to be included from a MEX file having MEX_FILE macro set to
#define MEX_FILE __BASE_FILE__
The MEX source file itself is not processed directly, but it is included from this
header possibly more than once. How the MEX file is treated depends on a control
macros which are set in the MEX source file. The supported are:
ISNARGINEQ, ISNARGINLE, ISNARGINGE
AT COMPILE-TIME:
AT RUNTIME: Ensures correct number of the input parameters.
WHEN MISSING: No input argument checks ale included in the final code.
#define ISNARGINEQ 5
TYPEDEPARGS -- used when determining the data type (float, double, float _Complex, double _Complex)
MATCHEDARGS -- used when determining the data type but only float and double
AT COMPILE-TIME: Defines integer array from the specified values.
AT RUNTIME: The array is used to identify input arguments to be checked/reformated. Accepted inputs are numeric arrays,
cell arrays containing only numeric arrays, structures having at least one field beeing a numeric array.
WHEN MISSING: No input modifications/checks are included in the code.
#define TYPEDEPARGS 0, 1
SINGLEARGS
AT COMPILE-TIME: Includes this file for the second time with TYPEDEPARGS input args. recast to float arrays (cells, structs).
AT RUNTIME: If at least one of the TYPEDEPARGS input args. is float (single in MatLab), all TYPEDEPARGS are recast to floats.
WHEN MISSING: TYPEDEPARGS input args can be only double arrays.
#define SINGLEARGS
COMPLEXARGS, REALARGS
AT COMPILE-TIME: (COMPLEXARGS) adds code for on-the-fly conversion from the Matlab complex number format to the
complex.h (interleaved) complex data format.
(REALARGS) and (COMPLEXARGS) allows both real and complex inputs. Have to be handled here.
AT RUNTIME: (COMPLEXARGS) TYPEDEPARGS input args are recast to complex format even in they are real.
(REALARGS) TYPEDEPARGS args are accepted only if they are real.
(REALARGS) and (COMPLEXARGS) If at least one of the TYPEDEPARGS is complex do as (COMPLEXARGS), otherwise let
the inputs untouched.
WHEN MISSING: Real/Complex are not checked. No complex data format change.
COMPLEXINDEPENDENT
AT COMPILE-TIME: As if both COMPLEXARGS, REALARGS were defined.
AT RUNTIME: As if both COMPLEXARGS, REALARGS were defined plus it is assumed that the called functions from the LTFAT
backend are from ltfat_typecomplexindependent.h, e.i. there are
WHEN MISSING: No input checks REAL/COMPLEX checks are included in the final code.
#define COMPLEXINDEPENDENT
NOCOMPLEXFMTCHANGE
Macro overrides the default complex number format change.
************************************************************************************/
/** Allow including this file only if MEX_FILE is defined */
#if defined(MEX_FILE)
/** Allow including this file only once */
#ifndef _LTFAT_MEX_TEMPLATEHELPER_H
#define _LTFAT_MEX_TEMPLATEHELPER_H 1
/** Adds symbol exporting function decorator to mexFunction.
On Windows, a separate def file is no longer needed. For MinGW, it
suppresses the default "export-all-symbols" behavior. **/
#if defined(_WIN32) || defined(__WIN32__)
# define DLL_EXPORT_SYM __declspec(dllexport)
#else
# define DLL_EXPORT_SYM __attribute__((visibility("public")))
#endif
/** Template macros */
#define LTFAT_CAT(prefix,name) prefix##name
#define LTFAT_TEMPLATE(prefix,name) LTFAT_CAT(prefix,name)
/** Undefine LTFAT_DOUBLE, LTFAT_SINGLE and LTFAT_COMPLEXTYPE if they are set */
#ifdef LTFAT_DOUBLE
# undef LTFAT_DOUBLE
#endif
#ifdef LTFAT_SINGLE
# undef LTFAT_SINGLE
#endif
#ifdef LTFAT_COMPLEXTYPE
# undef LTFAT_COMPLEXTYPE
#endif
/** Helper MACROS */
#ifdef _DEBUG
#define DEBUGINFO mexPrintf("File: %s, func: %s \n",__BASE_FILE__,__func__);
#else
#define DEBUGINFO
#endif
/** HEADERS */
#include "ltfat.h"
#include <stdio.h>
#include <string.h>
#include "mex.h"
/** C99 headers for a generic complex number manipulations */
#if (defined(COMPLEXINDEPENDENT)||defined(COMPLEXARGS)) && !defined(NOCOMPLEXFMTCHANGE)
# include <complex.h>
//# include <tgmath.h>
#endif
#ifdef EXPORTALIAS
DLL_EXPORT_SYM
void EXPORTALIAS( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] );
void EXPORTALIAS( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] )
{
mexFunction(nlhs,plhs,nrhs,prhs);
}
#endif
/** Helper function headers.
Defined here to allow them to be used in the MEX_FILE */
/*
Replacement for:
mxArray *mxCreateNumericMatrix(mwSize m, mwSize n, mxClassID classid, mxComplexity ComplexFlag);
*/
mxArray *ltfatCreateMatrix(mwSize M, mwSize N,mxClassID classid,mxComplexity complexFlag);
/*
Replacement for:
mxArray *mxCreateNumericArray(mwSize ndim, const mwSize *dims, mxClassID classid, mxComplexity ComplexFlag);
*/
mxArray *ltfatCreateNdimArray(mwSize ndim, const mwSize *dims,mxClassID classid,mxComplexity complexFlag);
/**
Include MEX source code (MEX_FILE) for each template data type according to the control macros:
TYPEDEPARGS
COMPLEXARGS
REALARGS
COMPLEXINDEPENDENT
For each inclusion a whole set of macros is defined (see src/ltfat_types.h):
MACRO SETS (from ltfat_types.h)
MACRO EXPANDS TO
(double) (single) (complex double) (complex single)
------------------------------------------------------------------------------------------------------
LTFAT_REAL double float double float
LTFAT_COMPLEX fftw_complex fftwf_complex fftw_complex fftwf_complex
LTFAT_COMPLEXH double _Complex float _Complex double _Complex float _Complex
LTFAT_TYPE LTFAT_REAL LTFAT_REAL LTFAT_COMPLEXH LTFAT_COMPLEXH
LTFAT_MX_CLASSID mxDOUBLE_CLASS mxSINGLE_CLASS mxDOUBLE_CLASS mxSINGLE_CLASS
LTFAT_MX_COMPLEXITY mxREAL mxREAL mxCOMPLEX mxCOMPLEX
LTFAT_FFTW(name) fftw_##name fftwf_##name fftw_##name fftwf_##name
LTFAT_NAME(name) name_d name_s name_cd name_cs
By default, a macro set (double) is used.
*/
#define LTFAT_DOUBLE
#include "ltfat_mex_typeindependent.h"
#include "ltfat_mex_typecomplexindependent.h"
// Including the MEX source file
#include MEX_FILE
#ifdef COMPLEXINDEPENDENT
# define LTFAT_COMPLEXTYPE
# include "ltfat_mex_typecomplexindependent.h"
// Including the MEX source file
# include MEX_FILE
# undef LTFAT_COMPLEXTYPE
#endif
#undef LTFAT_DOUBLE
#ifdef SINGLEARGS
# define LTFAT_SINGLE
# include "ltfat_mex_typeindependent.h"
# include "ltfat_mex_typecomplexindependent.h"
// Including the MEX source file
# include MEX_FILE
# ifdef COMPLEXINDEPENDENT
# define LTFAT_COMPLEXTYPE
# include "ltfat_mex_typecomplexindependent.h"
// Including the MEX source file
# include MEX_FILE
# undef LTFAT_COMPLEXTYPE
# endif
# undef LTFAT_SINGLE
#endif
/**
* MACRO-FU
*/
#define LTFAT_MEXERRMSG(s,...) \
do{ \
char sChars[256]; \
snprintf(sChars,255,(s),__VA_ARGS__); \
mexErrMsgTxt(sChars); \
}while(0)
#define FOREACH(item, array) \
for(size_t keep = 1, \
count = 0, \
size = sizeof (array) / sizeof *(array); \
keep && count != size; \
keep = !keep, count++) \
for(item = (array) + count; keep; keep = !keep)
#define FORSUBSET(item, array, subset) \
for(size_t keep = 1, \
count = 0, \
size = sizeof (subset) / sizeof *(subset); \
keep && count != size; \
keep = !keep, count++) \
for(item = (array) + (subset)[count]; keep; keep = !keep)
#define FORSUBSETIDX(itemIdx, array, subset) \
for(size_t keep = 1, \
count = 0, \
size = sizeof (subset) / sizeof *(subset); \
keep && count != size; \
keep = !keep, count++) \
for(itemIdx=&(subset)[count]; keep; keep = !keep)
/** Function prototypes */
bool checkIsReal(const mxArray *prhsEl);
bool checkIsSingle(const mxArray *prhsEl);
mxArray* recastToSingle(mxArray* prhsEl);
void checkArgs(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]);
mwSize sizeofClassid(mxClassID classid);
mwSize sizeofClassid(mxClassID classid)
{
switch(classid)
{
case mxSINGLE_CLASS:
return sizeof(float);
case mxDOUBLE_CLASS:
return sizeof(double);
case mxUNKNOWN_CLASS:
case mxCELL_CLASS:
case mxSTRUCT_CLASS:
case mxFUNCTION_CLASS:
default:
mexErrMsgTxt("Usnupported data type. Add more if you need..");
return 0;
break;
}
}
mxArray *ltfatCreateMatrix(mwSize M, mwSize N,mxClassID classid,mxComplexity complexFlag)
{
const mwSize dims[]= {M,N};
return ltfatCreateNdimArray(2, dims,classid,complexFlag);
}
mxArray *ltfatCreateNdimArray(mwSize ndim, const mwSize *dims,mxClassID classid, mxComplexity complexFlag)
{
if(complexFlag==mxREAL)
return mxCreateNumericArray(ndim,dims,classid,mxREAL);
#if (!defined(COMPLEXINDEPENDENT) && !defined(COMPLEXARGS) && !defined(REALARGS)) || defined(NOCOMPLEXFMTCHANGE)
if(complexFlag==mxCOMPLEX)
return mxCreateNumericArray(ndim,dims,classid,mxCOMPLEX);
#else
if(complexFlag==mxCOMPLEX)
{
// Ugly...
mwIndex dummyndim = 1;
const mwSize dummyDims[] = {1};
mxArray* out = mxCreateNumericArray(dummyndim,dummyDims,classid,mxCOMPLEX);
// Set correct dimensions
mxSetDimensions(out,dims,ndim);
mwSize L = mxGetNumberOfElements(out);
mxFree(mxGetPr(out));
mxFree(mxGetPi(out));
mxSetData(out,(void*)mxCalloc(L,2*sizeofClassid(classid)));
/*
Allocate array of length 1 to keep the array beeing identified as complex and to avoid automatic deallocation
issue.
*/
mxSetImagData(out,mxCalloc(1,1));
return out;
}
#endif
mexErrMsgTxt("Error in ltfatCreateNumericArray. Very strange...");
return NULL;
}
void checkArgs(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[])
{
#ifdef ISNARGINEQ
if(nrhs!=ISNARGINEQ)
{
LTFAT_MEXERRMSG("Expected %i input arguments. Only %i passed.",ISNARGINEQ,nrhs);
}
#endif
#if defined(ISNARGINLE)&&!defined(ISNARGINEQ)
if(nrhs<=ISNARGINLE)
{
LTFAT_MEXERRMSG("Too many input arguments. Expected %i or less input arguments. Passed %i arg.",ISNARGINLE,nrhs);
}
#endif
#if defined(ISNARGINGE)&&!defined(ISNARGINEQ)
if(nrhs>=ISNARGINLE)
{
LTFAT_MEXERRMSG("Too few input arguments. Expected %i or more input arguments. Passed %i arg.",ISNARGINLE,nrhs);
}
#endif
}
/* Helper recasting functions */
mxArray* recastToSingle(mxArray* prhsEl)
{
// return the input pointer if the input parameter already contains single prec. data
if(checkIsSingle(prhsEl))
{
return prhsEl;
}
// if the input is cell array, cast all it's elements to single
if(mxIsCell(prhsEl))
{
mxArray* tmpCell = mxCreateCellMatrix(mxGetM(prhsEl), mxGetN(prhsEl));
for(unsigned int jj=0;jj<mxGetNumberOfElements(prhsEl);jj++)
{
mxSetCell(tmpCell, (mwIndex) jj, recastToSingle(mxGetCell(prhsEl, jj)));
}
return tmpCell;
}
// if the input is struct, find all numeric fields and cast them to single
if(mxIsStruct(prhsEl))
{
mwSize nfields = mxGetNumberOfFields(prhsEl);
const mwSize *dims = mxGetDimensions(prhsEl);
mwSize ndim = mxGetNumberOfDimensions(prhsEl);
const char **fieldnames = mxMalloc(nfields*sizeof(const char *));
for(mwSize ii=0;ii<nfields;ii++)
{
fieldnames[ii] = mxGetFieldNameByNumber(prhsEl,ii);
}
// Create duplicate struct
mxArray* tmpStructArr = mxCreateStructArray(ndim,dims,nfields,fieldnames);
for(mwIndex jj=0;jj<mxGetNumberOfElements(prhsEl);jj++)
{
for(mwIndex ii=0;ii<nfields;ii++)
{
bool fieldnameMatch = 0;
#if defined(STRUCTFIELD1)
fieldnameMatch = fieldnameMatch || !strcmp(fieldnames[ii],STRUCTFIELD1);
#endif
#if defined(STRUCTFIELD2)
fieldnameMatch = fieldnameMatch || !strcmp(fieldnames[ii],STRUCTFIELD2);
#endif
mxSetFieldByNumber(tmpStructArr,jj,ii,recastToSingle(mxGetFieldByNumber(prhsEl,jj,ii)));
}
}
return tmpStructArr;
}
// Just copy pointer if the element is not numeric.
if(!mxIsNumeric(prhsEl))
{
return prhsEl;
}
mwSize ndim = mxGetNumberOfDimensions(prhsEl);
const mwSize* dims = mxGetDimensions(prhsEl);
mxArray* tmpEl = 0;
mwSize elToCopy = mxGetNumberOfElements(prhsEl);
if(mxIsComplex(prhsEl))
{
tmpEl = mxCreateNumericArray(ndim,dims,mxSINGLE_CLASS,mxCOMPLEX);
}
else
{
tmpEl = mxCreateNumericArray(ndim,dims,mxSINGLE_CLASS,mxREAL);
}
double* prhsElPtr = (double*) mxGetPr(prhsEl);
float* tmpElPtr = (float*) mxGetPr(tmpEl);
for(mwIndex jj=0;jj<elToCopy;jj++)
{
*(tmpElPtr++) = (float)( *(prhsElPtr++) );
}
if(mxIsComplex(prhsEl))
{
double* prhsElPtr_i = (double*) mxGetPi(prhsEl);
float* tmpElPtr_i = (float*) mxGetPi(tmpEl);
for(mwIndex jj=0;jj<elToCopy;jj++)
{
*(tmpElPtr_i++) = (float)( *(prhsElPtr_i++) );
}
}
return tmpEl;
}
bool checkIsSingle(const mxArray *prhsEl)
{
#define STRUCTFIELDCHECK(NO) \
\
gfield = mxGetField(prhsEl,0,NO); \
if(gfield!=NULL) \
{ \
for(mwIndex jj=0;jj<mxGetNumberOfElements(prhsEl);jj++) \
{ \
if(!checkIsSingle(mxGetField(prhsEl,jj,NO))) \
{ \
return false; \
} \
} \
}
if(mxIsCell(prhsEl))
{
for(mwIndex jj=0;jj<mxGetNumberOfElements(prhsEl);jj++)
{
if(!checkIsSingle(mxGetCell(prhsEl, jj)))
return false;
}
return true;
}
if(mxIsStruct(prhsEl))
{
mxArray* gfield = NULL;
#ifdef STRUCTFIELD1
STRUCTFIELDCHECK(STRUCTFIELD1)
#endif
#ifdef STRUCTFIELD2
STRUCTFIELDCHECK(STRUCTFIELD2)
#endif
if(gfield==NULL)
return true;
else
return false;
}
#undef STRUCTFIELDCHECK
return mxIsSingle(prhsEl);
}
bool checkIsReal(const mxArray *prhsEl)
{
if(mxIsCell(prhsEl))
{
bool isAllReal = false;
for(mwIndex jj=0;jj<mxGetNumberOfElements(prhsEl);jj++)
{
if(!(isAllReal = checkIsReal(mxGetCell(prhsEl, jj))))
break;
}
return isAllReal;
}
return !mxIsComplex(prhsEl);
}
/** MEX entry function
Handles recasting all defined inputs to a defined data type
*/
void mexFunction( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] )
{
#if defined(ISNARGINEQ) || defined(ISNARGINLE) || defined(ISNARGINGE)
checkArgs(nlhs, plhs,nrhs,prhs);
#endif
#ifndef TYPEDEPARGS
LTFAT_NAME_DOUBLE(ltfatMexFnc)(nlhs,plhs,nrhs,prhs); // pass trough
#else
// Create array of indexes to be checked
int prhsToCheckIfComplex[] = { TYPEDEPARGS };
#ifndef MATCHEDARGS
int prhsToCheckIfSingle[] = { TYPEDEPARGS };
#else
int prhsToCheckIfSingle[] = { TYPEDEPARGS, MATCHEDARGS };
#endif
// Check if any of the indexes is less than nrhs
int maxPrhsToCheck = 0;
FOREACH(int* valPr, prhsToCheckIfSingle)
if(*valPr+1>maxPrhsToCheck)
maxPrhsToCheck = *valPr;
if(!((maxPrhsToCheck)<nrhs))
LTFAT_MEXERRMSG("To few input arguments. Expected at least %i args.",maxPrhsToCheck+1);
// Indicator array defining which input arg. should be reformated.
bool recastToComplexIndArr[nrhs];
memset(recastToComplexIndArr,0,sizeof(recastToComplexIndArr));
bool isAnyComplex = false;
FORSUBSET(const mxArray **prhsElPtr, prhs, prhsToCheckIfComplex)
if( (isAnyComplex = !checkIsReal(*prhsElPtr))) break;
#if !defined(COMPLEXARGS) && defined(REALARGS) && !defined(COMPLEXINDEPENDENT)
FORSUBSET(const mxArray **prhsElPtr, prhs, prhsToCheckIfComplex)
if( !checkIsReal(*prhsElPtr))
{
mexErrMsgTxt("Complex input arguments are not alowed.");
break;
}
#endif
#if (defined(COMPLEXARGS) && !defined(REALARGS)) && !defined(COMPLEXINDEPENDENT)
FORSUBSETIDX(int* prhsElIdx,prhs, prhsToCheckIfComplex)
recastToComplexIndArr[*prhsElIdx]=true;
#endif
#if (defined(COMPLEXARGS) && defined(REALARGS)) || defined(COMPLEXINDEPENDENT)
if(isAnyComplex)
FORSUBSETIDX(int* prhsElIdx,prhs, prhsToCheckIfComplex)
recastToComplexIndArr[*prhsElIdx]=true;
#endif
// Copy input parameters
const mxArray **prhsAlt = mxMalloc(nrhs*sizeof(mxArray *));
memcpy((void *)prhsAlt,(void *)prhs,nrhs*sizeof(mxArray *));
bool isAnySingle = false;
#ifdef SINGLEARGS
FORSUBSET(const mxArray **prhsElPtr, prhs, prhsToCheckIfSingle)
if( (isAnySingle = checkIsSingle(*prhsElPtr))) break;
if(isAnySingle)
{
FORSUBSETIDX(int* prhsElIdx,prhs, prhsToCheckIfSingle)
prhsAlt[*prhsElIdx] = recastToSingle((mxArray *)prhs[*prhsElIdx]);
#if (defined(COMPLEXINDEPENDENT) || defined(COMPLEXARGS)) && !defined(NOCOMPLEXFMTCHANGE)
for(int ii=0;ii<nrhs;ii++)
if(recastToComplexIndArr[ii])
prhsAlt[ii] = LTFAT_NAME_SINGLE(mexSplit2combined)(prhsAlt[ii]);
#endif
#if defined(COMPLEXINDEPENDENT)
bool isAllReal = false;
bool isAllComplex = false;
FORSUBSET(const mxArray **prhsElPtr, prhsAlt, prhsToCheckIfComplex)
if( !(isAllReal = checkIsReal(*prhsElPtr))) break;
FORSUBSET(const mxArray **prhsElPtr, prhsAlt, prhsToCheckIfComplex)
if( !(isAllComplex = !checkIsReal(*prhsElPtr))) break;
if(!(isAllReal ^ isAllComplex))
mexErrMsgTxt("Template subsystem error. My bad .");
if(isAllReal)
LTFAT_NAME_SINGLE(ltfatMexFnc)(nlhs,plhs,nrhs, prhsAlt);
else if(isAllComplex)
LTFAT_NAME_COMPLEXSINGLE(ltfatMexFnc)(nlhs,plhs,nrhs, prhsAlt);
#else
LTFAT_NAME_SINGLE(ltfatMexFnc)(nlhs,plhs,nrhs, prhsAlt);
#endif //COMPLEXINDEPENDENT
#if (defined(COMPLEXINDEPENDENT) || defined(COMPLEXARGS) || defined(REALARGS)) && !defined(NOCOMPLEXFMTCHANGE)
if(!checkIsReal(plhs[0]))
plhs[0] = LTFAT_NAME_SINGLE(mexCombined2split)(plhs[0]);
#endif
}
#endif // SINGLEARGS
if(!isAnySingle)
{
#if (defined(COMPLEXINDEPENDENT) || defined(COMPLEXARGS)) && !defined(NOCOMPLEXFMTCHANGE)
for(int ii=0;ii<nrhs;ii++)
if(recastToComplexIndArr[ii])
prhsAlt[ii] = LTFAT_NAME_DOUBLE(mexSplit2combined)(prhsAlt[ii]);
#endif
#if defined(COMPLEXINDEPENDENT)
bool isAllReal = false;
bool isAllComplex = false;
FORSUBSET(const mxArray **prhsElPtr, prhsAlt, prhsToCheckIfComplex)
if( !(isAllReal = checkIsReal(*prhsElPtr))) break;
FORSUBSET(const mxArray **prhsElPtr, prhsAlt, prhsToCheckIfComplex)
if( !(isAllComplex = !checkIsReal(*prhsElPtr))) break;
if((isAllReal == isAllComplex))
mexErrMsgTxt("Template subsystem error. My bad...");
if(isAllReal)
LTFAT_NAME_DOUBLE(ltfatMexFnc)(nlhs,plhs,nrhs,prhsAlt);
else if(isAllComplex)
LTFAT_NAME_COMPLEXDOUBLE(ltfatMexFnc)(nlhs,plhs,nrhs, prhsAlt);
#else
LTFAT_NAME_DOUBLE(ltfatMexFnc)(nlhs,plhs,nrhs,prhsAlt);
#endif
#if (defined(COMPLEXINDEPENDENT) || defined(COMPLEXARGS) || defined(REALARGS)) && !defined(NOCOMPLEXFMTCHANGE)
if(!checkIsReal(plhs[0]))
plhs[0] = LTFAT_NAME_DOUBLE(mexCombined2split)(plhs[0]);
#endif
mxFree(prhsAlt);
}
#endif // TYPEDEPARGS
}
#endif // _LTFAT_MEX_TEMPLATEHELPER_H
#endif // defined(MEX_FILE)