1function test_failed = test_libltfat_ifftreal(varargin)
2test_failed = 0;
3
4fprintf(' ===============  %s ================ \n',upper(mfilename));
5
6definput.flags.complexity={'double','single'};
7[flags]=ltfatarghelper({},definput,varargin);
8dataPtr = [flags.complexity, 'Ptr'];
9
10[~,~,enuminfo]=libltfatprotofile;
11phaseconv = enuminfo.ltfat_phaseconvention;
12
13fftwflags = struct('FFTW_MEASURE',0,'FFTW_ESTIMATE',64,'FFTW_PATIENT',32,'FFTW_DESTROY_INPUT',1,...
14    'FFTW_UNALIGNED',2,'FFTW_EXHAUSTIVE',8,'FFTW_PRESERVE_INPUT',16);
15
16Larr  = [351];
17Warr  = [6];
18
19for idx = 1:numel(Larr)
20    L = Larr(idx);
21    W = Warr(idx);
22    M2 = floor(L/2) + 1;
23
24    f = randn(M2,W,flags.complexity) + 1i*randn(M2,W,flags.complexity);
25    fi = complex2interleaved(f);
26    fPtr = libpointer(dataPtr,fi);
27
28    c = cast(randn(L,W),flags.complexity);
29    coutPtr = libpointer(dataPtr,c);
30
31    truec = ifftreal(f,L)*L;
32
33    funname = makelibraryname('ifftreal',flags.complexity,0);
34    status = calllib('libltfat',funname,fPtr,L,W,coutPtr);
35
36    res = norm(truec - coutPtr.Value,'fro');
37    [test_failed,fail]=ltfatdiditfail(res+status,test_failed);
38    fprintf(['FFT   L:%3i, W:%3i, %s %s %s\n'],L,W,flags.complexity,ltfatstatusstring(status),fail);
39
40    % With plan
41    c = cast(randn(L,W),flags.complexity);
42    coutPtr = libpointer(dataPtr,c);
43
44    plan = libpointer();
45    funname = makelibraryname('ifftreal_init',flags.complexity,0);
46    statusInit = calllib('libltfat',funname,L,W,fPtr,coutPtr, fftwflags.FFTW_ESTIMATE, plan);
47
48    funname = makelibraryname('ifftreal_execute',flags.complexity,0);
49    statusExecute = calllib('libltfat',funname,plan);
50
51    res = norm(truec - coutPtr.Value,'fro');
52    [test_failed,fail]=ltfatdiditfail(res+statusInit,test_failed);
53    fprintf(['FFT L:%3i, W:%3i, %s %s %s\n'],L,W,flags.complexity,ltfatstatusstring(status),fail);
54
55    c = cast(randn(L,W),flags.complexity);
56    coutPtr = libpointer(dataPtr,c);
57
58    funname = makelibraryname('ifftreal_execute_newarray',flags.complexity,0);
59    statusExecute = calllib('libltfat',funname,plan,fPtr,coutPtr);
60
61    res = norm(truec - coutPtr.Value,'fro');
62    [test_failed,fail]=ltfatdiditfail(res+statusInit,test_failed);
63    fprintf(['FFT L:%3i, W:%3i, %s %s %s\n'],L,W,flags.complexity,ltfatstatusstring(status),fail);
64
65    funname = makelibraryname('ifftreal_done',flags.complexity,0);
66    statusDone = calllib('libltfat',funname,plan);
67
68
69    %%%%%% Inplace
70    c = f;
71    cout = complex2interleaved(c);
72    coutPtr = libpointer(dataPtr,cout);
73
74    plan = libpointer();
75    funname = makelibraryname('ifftreal_init',flags.complexity,0);
76    statusInit = calllib('libltfat',funname,L,W, coutPtr, coutPtr, fftwflags.FFTW_MEASURE, plan);
77
78    funname = makelibraryname('ifftreal_execute',flags.complexity,0);
79    statusExecute = calllib('libltfat',funname,plan);
80
81    ctmp = coutPtr.Value;
82    res = norm(truec - ctmp(1:L,:),'fro');
83    [test_failed,fail]=ltfatdiditfail(res+statusInit,test_failed);
84    fprintf(['FFT L:%3i, W:%3i, %s %s %s\n'],L,W,flags.complexity,ltfatstatusstring(status),fail);
85
86    c = f;
87    cout = complex2interleaved(c);
88    coutPtr = libpointer(dataPtr,cout);
89
90    funname = makelibraryname('ifftreal_execute_newarray',flags.complexity,0);
91    statusExecute = calllib('libltfat',funname,plan,coutPtr,coutPtr);
92
93    ctmp = (coutPtr.Value);
94    res = norm(truec - ctmp(1:L,:),'fro');
95    [test_failed,fail]=ltfatdiditfail(res+statusInit,test_failed);
96    fprintf(['FFT L:%3i, W:%3i, %s %s %s\n'],L,W,flags.complexity,ltfatstatusstring(status),fail);
97
98    funname = makelibraryname('ifftreal_done',flags.complexity,0);
99    statusDone = calllib('libltfat',funname,plan);
100end
101
102
103
104%-*- texinfo -*-
105%@deftypefn {Function} test_libltfat_ifftreal
106%@verbatim
107%@end verbatim
108%@strong{Url}: @url{http://ltfat.github.io/doc/libltfat/modules/libltfat/testing/mUnit/test_libltfat_ifftreal.html}
109%@end deftypefn
110
111% Copyright (C) 2005-2016 Peter L. Soendergaard <peter@sonderport.dk>.
112% This file is part of LTFAT version 2.3.1
113%
114% This program is free software: you can redistribute it and/or modify
115% it under the terms of the GNU General Public License as published by
116% the Free Software Foundation, either version 3 of the License, or
117% (at your option) any later version.
118%
119% This program is distributed in the hope that it will be useful,
120% but WITHOUT ANY WARRANTY; without even the implied warranty of
121% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
122% GNU General Public License for more details.
123%
124% You should have received a copy of the GNU General Public License
125% along with this program.  If not, see <http://www.gnu.org/licenses/>.
126
127