2
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3
* Copyright (C) 2006/2007 - INRIA - Alan LAYEC
4
* Copyright (C) 2007 - INRIA - Allan CORNET
5
* Copyright (C) 2012 - DIGITEO - Allan CORNET
6
* Copyright (C) 2012 - INRIA - Serge STEER
8
* This file must be used under the terms of the CeCILL.
9
* This source file is licensed as described in the file COPYING, which
10
* you should have received as part of this distribution. The terms
11
* are also available at
12
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
2
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3
* Copyright (C) 2006/2007 - INRIA - Alan LAYEC
4
* Copyright (C) 2007 - INRIA - Allan CORNET
5
* Copyright (C) 2012 - DIGITEO - Allan CORNET
6
* Copyright (C) 2012 - INRIA - Serge STEER
8
* This file must be used under the terms of the CeCILL.
9
* This source file is licensed as described in the file COPYING, which
10
* you should have received as part of this distribution. The terms
11
* are also available at
12
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
15
15
/*--------------------------------------------------------------------------*/
16
16
#include "stack-c.h"
17
17
#include "fftw_utilities.h"
39
39
static SciErr getScalarIntArg(void* _pvCtx, int _iVar, char *fname, int *value);
40
40
static SciErr getVectorIntArg(void* _pvCtx, int _iVar, char *fname, int *pndims, int **pDim);
41
41
static BOOL isHyperMatrixMlist(void* _pvCtx, int *piAddressVar);
42
static int sci_fft_gen(char *fname, int ndimsA, int *dimsA, double *Ar, double *Ai, int isn, int iopt, guru_dim_struct gdim);
43
static int sci_fft_2args(char *fname, int ndimsA, int *dimsA, double *Ar, double *Ai, int isn, int iopt);
44
static int sci_fft_3args(char *fname, int ndimsA, int *dimsA, double *Ar, double *Ai, int isn, int iopt);
45
static int sci_fft_4args(char *fname, int ndimsA, int *dimsA, double *Ar, double *Ai, int isn, int iopt);
42
static int sci_fft_gen(void* _pvCtx, char *fname, int ndimsA, int *dimsA, double *Ar, double *Ai, int isn, int iopt, guru_dim_struct gdim);
43
static int sci_fft_2args(void* _pvCtx, char *fname, int ndimsA, int *dimsA, double *Ar, double *Ai, int isn, int iopt);
44
static int sci_fft_3args(void* _pvCtx, char *fname, int ndimsA, int *dimsA, double *Ar, double *Ai, int isn, int iopt);
45
static int sci_fft_4args(void* _pvCtx, char *fname, int ndimsA, int *dimsA, double *Ar, double *Ai, int isn, int iopt);
46
46
/*--------------------------------------------------------------------------*/
51
* Scilab Calling sequence :
53
* fftw(A,sign [,option])
54
* fftw(A,sel,sign [,option])
55
* fftw(A,sign,dim,incr [,option])
57
* Input : A : a scilab double complex or real vector, matrix or hypermatrix
59
* sign : a scilab double or integer scalar (-1 or 1): the sign
60
* in the exponential component
62
* sel : a scilab double or integer vector, the selection of dimensions
51
* Scilab Calling sequence :
53
* fftw(A,sign [,option])
54
* fftw(A,sel,sign [,option])
55
* fftw(A,sign,dim,incr [,option])
57
* Input : A : a scilab double complex or real vector, matrix or hypermatrix
59
* sign : a scilab double or integer scalar (-1 or 1): the sign
60
* in the exponential component
62
* sel : a scilab double or integer vector, the selection of dimensions
64
* dim : a scilab double or integer vector: the dimensions
65
* of the Fast Fourier Transform to perform
67
* incr : a scilab double or integer vector: the increments
68
* of the Fast Fourier Transform to perform
70
* Output : a scilab double complex or real array with same shape as A that
71
* gives the result of the transform.
64
* dim : a scilab double or integer vector: the dimensions
65
* of the Fast Fourier Transform to perform
67
* incr : a scilab double or integer vector: the increments
68
* of the Fast Fourier Transform to perform
70
* Output : a scilab double complex or real array with same shape as A that
71
* gives the result of the transform.
74
74
int sci_fftw(char *fname, unsigned long fname_len)
204
204
/* fftw(A ,sign [,option])*/
205
sci_fft_2args(fname, ndimsA, dimsA, Ar, Ai, isn, iopt);
205
sci_fft_2args(pvApiCtx, fname, ndimsA, dimsA, Ar, Ai, isn, iopt);
207
207
else if (rhs == 3)
209
209
/* fftw(A ,sign ,sel [,option])*/
210
sci_fft_3args(fname, ndimsA, dimsA, Ar, Ai, isn, iopt);
210
sci_fft_3args(pvApiCtx, fname, ndimsA, dimsA, Ar, Ai, isn, iopt);
212
212
else if (rhs == 4)
214
214
/* fftw(A ,sign ,dim,incr [option])*/
215
sci_fft_4args(fname, ndimsA, dimsA, Ar, Ai, isn, iopt);
215
sci_fft_4args(pvApiCtx, fname, ndimsA, dimsA, Ar, Ai, isn, iopt);
509
509
getMatrixOfIntegerPrecision(_pvCtx, piAddr, &iPrec);
513
getMatrixOfInteger8(_pvCtx, piAddr, &mDim, &nDim, &p_c);
514
for (i = 0; i < ndims; i++) Dim[i] = (int)(p_c[i]);
517
getMatrixOfInteger16(_pvCtx, piAddr, &mDim, &nDim, &p_s);
518
for (i = 0; i < ndims; i++) Dim[i] = (int)(p_s[i]);
521
getMatrixOfInteger32(_pvCtx, piAddr, &mDim, &nDim, &p_i);
522
for (i = 0; i < ndims; i++) Dim[i] = (int)(p_i[i]);
525
getMatrixOfUnsignedInteger8(_pvCtx, piAddr, &mDim, &nDim, &p_uc);
526
for (i = 0; i < ndims; i++) Dim[i] = (int)(p_uc[i]);
529
getMatrixOfUnsignedInteger16(_pvCtx, piAddr, &mDim, &nDim, &p_us);
530
for (i = 0; i < ndims; i++) Dim[i] = (int) p_us[i];
533
getMatrixOfUnsignedInteger32(_pvCtx, piAddr, &mDim, &nDim, &p_ui);
534
for (i = 0; i < ndims; i++) Dim[i] = (int)(p_ui[i]);
513
getMatrixOfInteger8(_pvCtx, piAddr, &mDim, &nDim, &p_c);
514
for (i = 0; i < ndims; i++) Dim[i] = (int)(p_c[i]);
517
getMatrixOfInteger16(_pvCtx, piAddr, &mDim, &nDim, &p_s);
518
for (i = 0; i < ndims; i++) Dim[i] = (int)(p_s[i]);
521
getMatrixOfInteger32(_pvCtx, piAddr, &mDim, &nDim, &p_i);
522
for (i = 0; i < ndims; i++) Dim[i] = (int)(p_i[i]);
525
getMatrixOfUnsignedInteger8(_pvCtx, piAddr, &mDim, &nDim, &p_uc);
526
for (i = 0; i < ndims; i++) Dim[i] = (int)(p_uc[i]);
529
getMatrixOfUnsignedInteger16(_pvCtx, piAddr, &mDim, &nDim, &p_us);
530
for (i = 0; i < ndims; i++) Dim[i] = (int) p_us[i];
533
getMatrixOfUnsignedInteger32(_pvCtx, piAddr, &mDim, &nDim, &p_ui);
534
for (i = 0; i < ndims; i++) Dim[i] = (int)(p_ui[i]);
542
542
addErrorMessage(&sciErr, API_ERROR_GET_INT,
543
_("%s: Wrong type for argument #%d: An array of floating point or integer numbers expected.\n"), fname, _iVar);
543
_("%s: Wrong type for argument #%d: An array of floating point or integer numbers expected.\n"), fname, _iVar);
549
int sci_fft_2args(char *fname, int ndimsA, int *dimsA, double *Ar, double *Ai, int isn, int iopt)
549
int sci_fft_2args(void* _pvCtx, char *fname, int ndimsA, int *dimsA, double *Ar, double *Ai, int isn, int iopt)
551
551
/*FFTW specific library variable */
552
552
guru_dim_struct gdim = {0, NULL, 0, NULL};
601
601
gdim.howmany_dims = NULL;
604
if (!sci_fft_gen(fname, ndimsA, dimsA, Ar, Ai, isn, iopt, gdim)) goto ERR;
604
if (!sci_fft_gen(_pvCtx, fname, ndimsA, dimsA, Ar, Ai, isn, iopt, gdim)) goto ERR;
607
607
/***********************************
608
* Return results in lhs argument *
609
***********************************/
608
* Return results in lhs argument *
609
***********************************/
611
ReturnArguments(_pvCtx);
614
614
FREE(gdim.howmany_dims);
786
if (!sci_fft_gen(fname, ndimsA, dimsA, Ar, Ai, isn, iopt, gdim)) goto ERR;
786
if (!sci_fft_gen(_pvCtx, fname, ndimsA, dimsA, Ar, Ai, isn, iopt, gdim)) goto ERR;
787
787
/***********************************
788
* Return results in lhs argument *
789
***********************************/
788
* Return results in lhs argument *
789
***********************************/
791
ReturnArguments(_pvCtx);
794
794
FREE(gdim.howmany_dims);
798
int sci_fft_4args(char *fname, int ndimsA, int *dimsA, double *Ar, double *Ai, int isn, int iopt)
798
int sci_fft_4args(void* _pvCtx, char *fname, int ndimsA, int *dimsA, double *Ar, double *Ai, int isn, int iopt)
800
800
/* API variables */
1044
if (!sci_fft_gen(fname, ndimsA, dimsA, Ar, Ai, isn, iopt, gdim)) goto ERR;
1044
if (!sci_fft_gen(_pvCtx, fname, ndimsA, dimsA, Ar, Ai, isn, iopt, gdim)) goto ERR;
1046
1046
/***********************************
1047
* Return results in lhs argument *
1048
***********************************/
1047
* Return results in lhs argument *
1048
***********************************/
1050
ReturnArguments(_pvCtx);
1225
1226
scale = None; /*no scaling needed */
1226
1227
if (isn == FFTW_BACKWARD) scale = Divide;
1228
if (isrealA & !WITHMKL) /* To have type = C2C_PLAN*/
1232
1233
/*r2r = isrealA && issymA*/
1233
1234
/* there is no general plan able to compute r2r transform so it is tranformed into
1234
a R2c plan. The computed imaginary part will be zero*/
1235
sciErr = allocMatrixOfDouble(pvApiCtx, Rhs + 1, 1, lA, &io);
1235
a R2c plan. The computed imaginary part will be zero*/
1236
sciErr = allocMatrixOfDouble(pvApiCtx, *getNbInputArgument(_pvCtx) + 1, 1, lA, &io);
1236
1237
if (sciErr.iErr)
1238
1239
Scierror(999, _("%s: Cannot allocate more memory.\n"), fname);
1246
1247
/*r2c = isrealA && ~issymA;*/
1247
1248
/* transform cannot be done in place */
1248
sciErr = allocComplexArrayOfDouble(pvApiCtx, Rhs + 1, ndimsA, dimsA, &ro, &io);
1249
sciErr = allocComplexArrayOfDouble(pvApiCtx, *getNbInputArgument(_pvCtx) + 1, ndimsA, dimsA, &ro, &io);
1249
1250
if (sciErr.iErr)
1251
1252
Scierror(999, _("%s: Cannot allocate more memory.\n"), fname);
1254
LhsVar(1) = Rhs + 1;
1255
AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(_pvCtx) + 1;
1255
1256
type = R2C_PLAN; /* fftw_plan_guru_split_dft_r2c plans for an FFTW_FORWARD transform*/
1256
1257
if (isn == FFTW_BACKWARD)
1323
1325
/* Post treatment */
1329
if (complete_array(ro, NULL, gdim) == -1)
1331
Scierror(999, _("%s: Cannot allocate more memory.\n"), fname);
1340
/*R2C has been used to solve an r2r problem*/
1327
1341
if (complete_array(ro, NULL, gdim) == -1)
1329
1343
Scierror(999, _("%s: Cannot allocate more memory.\n"), fname);
1338
/*R2C has been used to solve an r2r problem*/
1339
if (complete_array(ro, NULL, gdim) == -1)
1341
Scierror(999, _("%s: Cannot allocate more memory.\n"), fname);
1349
if (complete_array(ro, io, gdim) == -1)
1351
Scierror(999, _("%s: Cannot allocate more memory.\n"), fname);
1354
if (isn == FFTW_BACKWARD)
1356
/*conjugate result */
1358
C2F(dscal)(&lA, &ak, io, &one);
1363
if (WITHMKL && isrealA_save)
1365
if (isn == FFTW_FORWARD)
1347
1367
if (complete_array(ro, io, gdim) == -1)
1349
1369
Scierror(999, _("%s: Cannot allocate more memory.\n"), fname);
1352
if (isn == FFTW_BACKWARD)
1354
/*conjugate result */
1356
C2F(dscal)(&lA, &ak, io, &one);
1361
if (WITHMKL && isrealA_save)
1363
if (isn == FFTW_FORWARD)
1365
if (complete_array(ro, io, gdim) == -1)
1367
Scierror(999, _("%s: Cannot allocate more memory.\n"), fname);
1373
if (complete_array(io, ro, gdim) == -1)
1375
Scierror(999, _("%s: Cannot allocate more memory.\n"), fname);
1375
if (complete_array(io, ro, gdim) == -1)
1377
Scierror(999, _("%s: Cannot allocate more memory.\n"), fname);