Diff of /mex/ltfat_mex_template_helper.h [164e09] .. [a5c381]  Maximize  Restore

Switch to unified view

a/mex/ltfat_mex_template_helper.h b/mex/ltfat_mex_template_helper.h
...
...
17
    AT COMPILE-TIME:
17
    AT COMPILE-TIME:
18
    AT RUNTIME: Ensures correct number of the input parameters.
18
    AT RUNTIME: Ensures correct number of the input parameters.
19
    WHEN MISSING: No input argument checks ale included in the final code.
19
    WHEN MISSING: No input argument checks ale included in the final code.
20
20
21
#define ISNARGINEQ 5
21
#define ISNARGINEQ 5
22
 TYPEDEPARGS
22
 TYPEDEPARGS -- used when determining the data type (float, double, float _Complex, double _Complex)
23
 MATCHEDARGS
23
 MATCHEDARGS -- used when determining the data type but only float and double
24
    AT COMPILE-TIME: Defines integer array from the specified values.
24
    AT COMPILE-TIME: Defines integer array from the specified values.
25
    AT RUNTIME: The array is used to identify input arguments to be checked/reformated. Accepted inputs are numeric arrays,
25
    AT RUNTIME: The array is used to identify input arguments to be checked/reformated. Accepted inputs are numeric arrays,
26
                cell arrays containing only numeric arrays, structures having at least one field beeing numeric array.
26
                cell arrays containing only numeric arrays, structures having at least one field beeing a numeric array.
27
    WHEN MISSING: No input modifications/checks are included in the code.
27
    WHEN MISSING: No input modifications/checks are included in the code.
28
28
29
#define TYPEDEPARGS 0, 1
29
#define TYPEDEPARGS 0, 1
30
 SINGLEARGS
30
 SINGLEARGS
31
    AT COMPILE-TIME: Includes this file for the second time with TYPEDEPARGS input args. recast to float arrays (cells, structs).
31
    AT COMPILE-TIME: Includes this file for the second time with TYPEDEPARGS input args. recast to float arrays (cells, structs).
...
...
52
52
53
53
54
#define COMPLEXINDEPENDENT 
54
#define COMPLEXINDEPENDENT 
55
  
55
  
56
NOCOMPLEXFMTCHANGE
56
NOCOMPLEXFMTCHANGE
57
    Macro overrides the default complex number format change. 
57
  
58
  
58
************************************************************************************/
59
************************************************************************************/
59
60
60
/** Allow including this file only if MEX_FILE is defined */
61
/** Allow including this file only if MEX_FILE is defined */
61
#if defined(MEX_FILE)
62
#if defined(MEX_FILE)
...
...
67
/** Adds symbol exporting function decorator to mexFunction.
68
/** Adds symbol exporting function decorator to mexFunction.
68
    On Windows, a separate def file is no longer needed. For MinGW, it
69
    On Windows, a separate def file is no longer needed. For MinGW, it
69
    suppresses the default "export-all-symbols" behavior. **/
70
    suppresses the default "export-all-symbols" behavior. **/
70
#if defined(_WIN32) || defined(__WIN32__)
71
#if defined(_WIN32) || defined(__WIN32__)
71
#  define DLL_EXPORT_SYM __declspec(dllexport)
72
#  define DLL_EXPORT_SYM __declspec(dllexport)
73
#else
74
#  define DLL_EXPORT_SYM __attribute__((visibility("public")))
72
#endif
75
#endif
76
77
73
78
74
/** Template macros */
79
/** Template macros */
75
#define LTFAT_CAT(prefix,name) prefix##name
80
#define LTFAT_CAT(prefix,name) prefix##name
76
#define LTFAT_TEMPLATE(prefix,name) LTFAT_CAT(prefix,name)
81
#define LTFAT_TEMPLATE(prefix,name) LTFAT_CAT(prefix,name)
77
82
...
...
103
#if (defined(COMPLEXINDEPENDENT)||defined(COMPLEXARGS)) && !defined(NOCOMPLEXFMTCHANGE)
108
#if (defined(COMPLEXINDEPENDENT)||defined(COMPLEXARGS)) && !defined(NOCOMPLEXFMTCHANGE)
104
#  include <complex.h>
109
#  include <complex.h>
105
//#  include <tgmath.h>
110
//#  include <tgmath.h>
106
#endif
111
#endif
107
112
108
/** Helper function headers, to allow them to be used in the MEX_FILE */
113
114
#ifdef EXPORTALIAS
115
DLL_EXPORT_SYM
116
void EXPORTALIAS( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] );
117
118
void EXPORTALIAS( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] )
119
{
120
   mexFunction(nlhs,plhs,nrhs,prhs);
121
}
122
#endif
123
124
125
/** Helper function headers.
126
    Defined here to allow them to be used in the MEX_FILE */
109
/*
127
/*
110
Replacement for:
128
Replacement for:
111
mxArray *mxCreateNumericMatrix(mwSize m, mwSize n, mxClassID classid, mxComplexity ComplexFlag);
129
mxArray *mxCreateNumericMatrix(mwSize m, mwSize n, mxClassID classid, mxComplexity ComplexFlag);
112
*/
130
*/
113
mxArray *ltfatCreateMatrix(mwSize M, mwSize N,mxClassID classid,mxComplexity complexFlag);
131
mxArray *ltfatCreateMatrix(mwSize M, mwSize N,mxClassID classid,mxComplexity complexFlag);
...
...
135
    LTFAT_COMPLEX        fftw_complex       fftwf_complex      fftw_complex          fftwf_complex
153
    LTFAT_COMPLEX        fftw_complex       fftwf_complex      fftw_complex          fftwf_complex
136
    LTFAT_COMPLEXH       double _Complex    float _Complex     double _Complex       float _Complex
154
    LTFAT_COMPLEXH       double _Complex    float _Complex     double _Complex       float _Complex
137
    LTFAT_TYPE           LTFAT_REAL         LTFAT_REAL         LTFAT_COMPLEXH        LTFAT_COMPLEXH
155
    LTFAT_TYPE           LTFAT_REAL         LTFAT_REAL         LTFAT_COMPLEXH        LTFAT_COMPLEXH
138
    LTFAT_MX_CLASSID     mxDOUBLE_CLASS     mxSINGLE_CLASS     mxDOUBLE_CLASS        mxSINGLE_CLASS
156
    LTFAT_MX_CLASSID     mxDOUBLE_CLASS     mxSINGLE_CLASS     mxDOUBLE_CLASS        mxSINGLE_CLASS
139
    LTFAT_MX_COMPLEXITY  mxREAL             mxREAL             mxCOMPLEX             mxCOMPLEX
157
    LTFAT_MX_COMPLEXITY  mxREAL             mxREAL             mxCOMPLEX             mxCOMPLEX
140
    LTFAT_FFTW(name)     fftw_##name        fftw_##name        fftw_##name           fftw_##name
158
    LTFAT_FFTW(name)     fftw_##name        fftwf_##name       fftw_##name           fftwf_##name
141
    LTFAT_NAME(name)     name               s##name            c##name               cs##name
159
    LTFAT_NAME(name)     name_d             name_s             name_cd               name_cs
142
160
143
    By default, a macro set (double) is used.
161
    By default, a macro set (double) is used.
144
*/
162
*/
145
163
146
164
147
#define LTFAT_DOUBLE
165
#define LTFAT_DOUBLE
148
#include "ltfat_mex_typeindependent.h"
166
#include "ltfat_mex_typeindependent.h"
149
#include "ltfat_mex_typecomplexindependent.h"
167
#include "ltfat_mex_typecomplexindependent.h"
168
// Including the MEX source file
150
#include MEX_FILE
169
#include MEX_FILE
151
#ifdef COMPLEXINDEPENDENT
170
#ifdef COMPLEXINDEPENDENT
152
#  define LTFAT_COMPLEXTYPE
171
#  define LTFAT_COMPLEXTYPE
153
#  include "ltfat_mex_typecomplexindependent.h"
172
#  include "ltfat_mex_typecomplexindependent.h"
173
// Including the MEX source file
154
#  include MEX_FILE
174
#  include MEX_FILE
155
#  undef LTFAT_COMPLEXTYPE
175
#  undef LTFAT_COMPLEXTYPE
156
#endif
176
#endif
157
#undef LTFAT_DOUBLE
177
#undef LTFAT_DOUBLE
158
178
159
#ifdef SINGLEARGS
179
#ifdef SINGLEARGS
160
#  define LTFAT_SINGLE
180
#  define LTFAT_SINGLE
161
#  include "ltfat_mex_typeindependent.h"
181
#  include "ltfat_mex_typeindependent.h"
162
#  include "ltfat_mex_typecomplexindependent.h"
182
#  include "ltfat_mex_typecomplexindependent.h"
183
// Including the MEX source file
163
#  include MEX_FILE
184
#  include MEX_FILE
164
#  ifdef COMPLEXINDEPENDENT
185
#  ifdef COMPLEXINDEPENDENT
165
#    define LTFAT_COMPLEXTYPE
186
#    define LTFAT_COMPLEXTYPE
166
#    include "ltfat_mex_typecomplexindependent.h"
187
#    include "ltfat_mex_typecomplexindependent.h"
188
// Including the MEX source file
167
#    include MEX_FILE
189
#    include MEX_FILE
168
#    undef LTFAT_COMPLEXTYPE
190
#    undef LTFAT_COMPLEXTYPE
169
#  endif
191
#  endif
170
#  undef LTFAT_SINGLE
192
#  undef LTFAT_SINGLE
171
#endif
193
#endif
...
...
260
282
261
      mxFree(mxGetPr(out));
283
      mxFree(mxGetPr(out));
262
      mxFree(mxGetPi(out));
284
      mxFree(mxGetPi(out));
263
      mxSetData(out,(void*)mxCalloc(L,2*sizeofClassid(classid)));
285
      mxSetData(out,(void*)mxCalloc(L,2*sizeofClassid(classid)));
264
      /*
286
      /*
265
      Allocate array of length 1 to keep the array complex and to avoid automatic deallocation
287
      Allocate array of length 1 to keep the array beeing identified as complex and to avoid automatic deallocation
266
      issue. 
288
      issue. 
267
      */
289
      */
268
      mxSetImagData(out,mxCalloc(1,1));
290
      mxSetImagData(out,mxCalloc(1,1));
269
291
270
      return out;
292
      return out;
...
...
300
}
322
}
301
323
302
/* Helper recasting functions */
324
/* Helper recasting functions */
303
mxArray* recastToSingle(mxArray* prhsEl)
325
mxArray* recastToSingle(mxArray* prhsEl)
304
{
326
{
327
305
   // return the input pointer if the input parameter already contains single prec. data
328
   // return the input pointer if the input parameter already contains single prec. data
306
   if(checkIsSingle(prhsEl))
329
   if(checkIsSingle(prhsEl))
307
   {
330
   {
308
     return prhsEl;
331
     return prhsEl;
309
   }
332
   }
...
...
331
      {
354
      {
332
         fieldnames[ii] = mxGetFieldNameByNumber(prhsEl,ii);
355
         fieldnames[ii] = mxGetFieldNameByNumber(prhsEl,ii);
333
      }
356
      }
334
      // Create duplicate struct
357
      // Create duplicate struct
335
      mxArray* tmpStructArr = mxCreateStructArray(ndim,dims,nfields,fieldnames);
358
      mxArray* tmpStructArr = mxCreateStructArray(ndim,dims,nfields,fieldnames);
359
    
336
      for(mwIndex jj=0;jj<mxGetNumberOfElements(prhsEl);jj++)
360
      for(mwIndex jj=0;jj<mxGetNumberOfElements(prhsEl);jj++)
337
      {
361
      {
338
         for(mwIndex ii=0;ii<nfields;ii++)
362
         for(mwIndex ii=0;ii<nfields;ii++)
339
         {
363
         {
364
          bool fieldnameMatch = 0;
365
          #if defined(STRUCTFIELD1)
366
             fieldnameMatch = fieldnameMatch || !strcmp(fieldnames[ii],STRUCTFIELD1);
367
          #endif
368
          
369
          #if defined(STRUCTFIELD2)
370
             fieldnameMatch = fieldnameMatch || !strcmp(fieldnames[ii],STRUCTFIELD2);
371
          #endif
372
            
340
            mxSetFieldByNumber(prhsEl,jj,ii,recastToSingle(mxGetFieldByNumber(prhsEl,jj,ii)));
373
         mxSetFieldByNumber(tmpStructArr,jj,ii,recastToSingle(mxGetFieldByNumber(prhsEl,jj,ii)));
374
341
         }
375
         }
342
      }
376
      }
377
    
343
         return tmpStructArr;
378
      return tmpStructArr;
344
   }
379
   }
345
380
346
381
347
   // Just copy pointer if the element is not numeric.
382
   // Just copy pointer if the element is not numeric.
348
   if(!mxIsNumeric(prhsEl))
383
   if(!mxIsNumeric(prhsEl))
...
...
386
   return tmpEl;
421
   return tmpEl;
387
}
422
}
388
423
389
bool checkIsSingle(const mxArray *prhsEl)
424
bool checkIsSingle(const mxArray *prhsEl)
390
{
425
{
426
#define STRUCTFIELDCHECK(NO)                                        \
427
                                                                    \
428
    gfield = mxGetField(prhsEl,0,NO);                             \
429
    if(gfield!=NULL)                                              \
430
    {                                                             \
431
         for(mwIndex jj=0;jj<mxGetNumberOfElements(prhsEl);jj++)    \
432
       {                                                          \
433
            if(!checkIsSingle(mxGetField(prhsEl,jj,NO)))            \
434
            {                                                       \
435
               return false;                                        \
436
            }                                                     \
437
       }                                                          \
438
      }        
439
440
441
391
   if(mxIsCell(prhsEl))
442
   if(mxIsCell(prhsEl))
392
   {
443
   {
393
      for(mwIndex jj=0;jj<mxGetNumberOfElements(prhsEl);jj++)
444
      for(mwIndex jj=0;jj<mxGetNumberOfElements(prhsEl);jj++)
394
      {
445
      {
395
         if(!checkIsSingle(mxGetCell(prhsEl, jj)))
446
         if(!checkIsSingle(mxGetCell(prhsEl, jj)))
396
            return false;
447
            return false;
397
      }
448
      }
398
      return true;
449
      return true;
399
   }
450
   }
451
   
452
   if(mxIsStruct(prhsEl))
453
   {
454
      mxArray* gfield = NULL;
455
      #ifdef STRUCTFIELD1
456
       STRUCTFIELDCHECK(STRUCTFIELD1)
457
    #endif
458
    
459
    #ifdef STRUCTFIELD2
460
       STRUCTFIELDCHECK(STRUCTFIELD2)
461
    #endif
462
    
463
    if(gfield==NULL)
464
       return true;
465
    else
466
       return false;
467
   }
468
   
469
   #undef STRUCTFIELDCHECK  
400
   return mxIsSingle(prhsEl);
470
   return mxIsSingle(prhsEl);
401
}
471
}
402
472
403
bool checkIsReal(const mxArray *prhsEl)
473
bool checkIsReal(const mxArray *prhsEl)
404
{
474
{
...
...
411
            break;
481
            break;
412
      }
482
      }
413
      return isAllReal;
483
      return isAllReal;
414
   }
484
   }
415
485
416
    return !mxIsComplex(prhsEl);
486
   return !mxIsComplex(prhsEl);
417
}
487
}
418
488
419
/** MEX entry function
489
/** MEX entry function
420
    Handles recasting all defined inputs to a defined data type
490
    Handles recasting all defined inputs to a defined data type
421
 */
491
 */
...
...
559
        if(!checkIsReal(plhs[0]))
629
        if(!checkIsReal(plhs[0]))
560
          plhs[0] = LTFAT_NAME_DOUBLE(mexCombined2split)(plhs[0]);
630
          plhs[0] = LTFAT_NAME_DOUBLE(mexCombined2split)(plhs[0]);
561
631
562
        #endif
632
        #endif
563
633
564
634
        mxFree(prhsAlt);
565
      }
635
      }
566
636
567
637
568
638
569
    #endif // TYPEDEPARGS
639
    #endif // TYPEDEPARGS

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

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks