Skip to content

Commit db8d068

Browse files
authored
Merge pull request #54 from FastNFT/release-0.4
Release 0.4.1
2 parents 31bbf74 + 7f6c0cd commit db8d068

12 files changed

+636
-36
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## [0.4.1] -- 2020-07-13
4+
5+
### Changed
6+
7+
- Number of samples for fnft_nsep again has to be a power of two.
8+
9+
### Fixed
10+
11+
- misc_downsample could return incorrect values for first_last_index[1]
12+
313
## [0.4.0] -- 2020-07-08
414

515
### Added

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ project(fnft C)
2121

2222
set(FNFT_VERSION_MAJOR 0)
2323
set(FNFT_VERSION_MINOR 4)
24-
set(FNFT_VERSION_PATCH 0)
24+
set(FNFT_VERSION_PATCH 1)
2525
set(FNFT_VERSION_SUFFIX "") # should not be longer than FNFT_SUFFIX_MAXLEN
2626
set(FNFT_VERSION ${FNFT_VERSION_MAJOR}.${FNFT_VERSION_MINOR}.${FNFT_VERSION_PATCH}${FNFT_VERSION_SUFFIX})
2727

examples/mex_fnft_nsep_example.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
% conditions can be computed using mex_fnft_nsep. The signal is the same
2222
% plane wave as in the paper https://doi.org/10.1109/TIT.2015.2485944
2323

24-
2524
clear all;
2625
close all;
2726

2827
%%% Setup parameters %%%
2928

3029
T = [0, 2*pi]; % T(1) is the beginning of the period, T(2) is the end
31-
D = 300; % number of samples(NOTE: This has to be a even positive integer)
30+
D = 2^9; % number of samples (has to be a power of two)
3231
kappa = +1; % focusing nonlinear Schroedinger equation
3332

3433
%%% Setup the signal %%%

include/fnft_nsep.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fnft_nsep_opts_t fnft_nsep_default_opts();
189189
* - Prins and Wahls, <a href="https://doi.org/10.1109/ICASSP.2018.8461708">&quot;Higher order exponential splittings for the fast non-linear Fourier transform of the KdV equation,&quot;</a>in Proc.ICASSP 2018, Calgary, AB, 2018, pp. 4524-4528.
190190
* - Mertsching, <a href="https://doi.org/10.1002/prop.2190350704">&quot; Quasiperiodie Solutions of the Nonlinear Schrödinger Equation,&quot;</a> Fortschr. Phys. 35:519-536, 1987.
191191
*
192-
* * The routine supports the following discretizations of type \link fnft_nse_discretization_t \endlink:
192+
* The routine supports the following discretizations of type \link fnft_nse_discretization_t \endlink:
193193
* - fnft_nse_discretization_2SPLIT1A
194194
* - fnft_nse_discretization_2SPLIT1B
195195
* - fnft_nse_discretization_2SPLIT2A
@@ -211,7 +211,7 @@ fnft_nsep_opts_t fnft_nsep_default_opts();
211211
* - fnft_nse_discretization_2SPLIT8B
212212
* - fnft_nse_discretization_4SPLIT4A
213213
*
214-
* @param[in] D Number of samples. Has to be even.
214+
* @param[in] D Number of samples. Should be power of two and \f$ D\geq 2\f$.
215215
* @param[in] q Array of length D, contains samples \f$ q(t_n)=q(x_0, t_n) \f$,
216216
* where \f$ t_n = T[0] + n*L/D \f$, where \f$L=T[1]-T[0]\f$ is the period and
217217
* \f$n=0,1,\dots,D-1\f$, of the to-be-transformed signal in ascending order

matlab/mex_fnft_nsep.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
6464
kappa = (int)mxGetScalar(prhs[2]);
6565

6666
/* Check values of first three inputs */
67-
if ( D<2 || D%2 != 0 )
68-
mexErrMsgTxt("Length of the first input q should be even.");
67+
if ( D<2 || (D & (D-1)) != 0 )
68+
mexErrMsgTxt("Length of the first input q should be >=2 and a power of two.");
6969
if ( T[0] >= T[1] )
7070
mexErrMsgTxt("T(1) >= T(2).");
7171
if ( kappa != +1 && kappa != -1 )
@@ -174,26 +174,26 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
174174
} else if ( strcmp(str, "quiet") == 0 ) {
175175

176176
fnft_errwarn_setprintf(NULL);
177-
177+
178178
} else if ( strcmp(str, "discr_modal") == 0 ) {
179-
179+
180180
opts.discretization = fnft_nse_discretization_2SPLIT2_MODAL;
181-
181+
182182
} else if ( strcmp(str, "discr_2split2A") == 0 ) {
183-
183+
184184
opts.discretization = fnft_nse_discretization_2SPLIT2A;
185-
185+
186186
} else if ( strcmp(str, "discr_2split4A") == 0 ) {
187-
187+
188188
opts.discretization = fnft_nse_discretization_2SPLIT4A; upsampling_factor = 4;
189-
189+
190190
} else if ( strcmp(str, "discr_2split4B") == 0 ) {
191-
191+
192192
opts.discretization = fnft_nse_discretization_2SPLIT4B; upsampling_factor = 2;
193-
193+
194194
} else if ( strcmp(str, "discr_4split4B") == 0 ) {
195-
196-
opts.discretization = fnft_nse_discretization_4SPLIT4B; upsampling_factor = 4;
195+
196+
opts.discretization = fnft_nse_discretization_4SPLIT4B; upsampling_factor = 4;
197197

198198
} else {
199199
snprintf(msg, sizeof msg, "%uth input has invalid value.",

matlab/mex_fnft_nsep.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
% Provides an interface to the C routine fnft_nsep.
99
%
1010
% INPUTS
11-
% q Complex row vector of length D=2n>2. The first sample
12-
% q(1) should correspond to T(1) and the last sample
11+
% q Complex row vector of length D>=2; D should be a power of two.
12+
% The first sample q(1) should correspond to T(1) and the last sample
1313
% q(D) should correspond to T(2)-(T(2)-T(1))/D.
1414
% T Real 1x2 vector with T(2)>T(1).
1515
% kappa +1.0 or -1.0

src/fnft_nsep.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ INT fnft_nsep(const UINT D, COMPLEX const * const q,
9292
COMPLEX *q_preprocessed = NULL;
9393

9494
// Check inputs
95-
if (D < 2 || D%2 == 1)
95+
// D (and Dsub in line 493) only need to be even to ensure that deg in line 279 and 537 are also even for all discretizations.
96+
// deg is required to be even so that its use in lines 321, 355 and 587 make sense.
97+
// Due to the periodic boundary conditions, Dsub has to be an even factor of D. For some choices like D=514, this means Dsub can only be 514 as D=514=2*257.
98+
// This makes the idea of subsampling unintuitive. Hence at this stage D is restricted to powers of two for which subsampling still makes sense.
99+
if (D < 2 || (D & (D-1)) != 0 )
96100
return E_INVALID_ARGUMENT(D);
97101
if (q == NULL)
98102
return E_INVALID_ARGUMENT(q);
@@ -483,19 +487,23 @@ static inline INT subsample_and_refine(const UINT D,
483487
first_last_index, opts_ptr->discretization);
484488
CHECK_RETCODE(ret_code, release_mem);
485489

486-
487490
// Create a subsampled/resampled version of q for computing initial guesses.
488491
Dsub = opts_ptr->Dsub;
489492
if (Dsub == 0) // users wants Dsub to be chosen automatically
490-
Dsub = ROUND(SQRT(D * LOG2(D) * LOG2(D)));
491-
nskip_per_step = ROUND((REAL)D / Dsub);
492-
Dsub = ROUND((REAL)D / nskip_per_step); // actual Dsub
493+
Dsub = POW(2.0, CEIL( 0.5 * LOG2(D * LOG2(D) * LOG2(D)) ));
494+
else
495+
Dsub = POW(2.0, ROUND(LOG2(Dsub)));
493496

494497
ret_code = nse_discretization_preprocess_signal(D, q, eps_t, kappa, &Dsub, &qsub_preprocessed, &rsub_preprocessed,
495498
first_last_index, opts_ptr->discretization);
496499
CHECK_RETCODE(ret_code, release_mem);
500+
501+
nskip_per_step = D/Dsub;
502+
if ( first_last_index[0] != 0 || first_last_index[1]+nskip_per_step != D )
503+
return E_ASSERTION_FAILED; // Correct update of T for general
504+
// downsampling still needs to be
505+
// implemented
497506

498-
499507
if (upsampling_factor == 2) {
500508
nse_discretization = nse_discretization_CF4_2;
501509
} else if (upsampling_factor == 1) {

test/fnft_nsep/fnft_nsep_test_constant_defocusing_2split4B.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ INT main()
2525
{
2626
INT ret_code;
2727
const fnft__nsep_testcases_t tc = nsep_testcases_CONSTANT_DEFOCUSING;
28-
UINT D = 1026;
28+
UINT D = 1024;
2929
REAL error_bounds[3] = {
3030
7.6e-5, // main spectrum
3131
2.5e-8, // aux spectrum

test/fnft_nsep/fnft_nsep_test_constant_defocusing_4split4A.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ INT main()
2626
{
2727
INT ret_code;
2828
const fnft__nsep_testcases_t tc = nsep_testcases_CONSTANT_DEFOCUSING;
29-
UINT D = 68;
29+
UINT D = 64;
3030
REAL error_bounds[3] = {
3131
6.8e-4, // main spectrum
32-
1.2e-6, // aux spectrum
32+
1.3e-6, // aux spectrum
3333
0.0 // sheet indices (zero since not yet implemented)
3434
};
3535
fnft_nsep_opts_t opts;

0 commit comments

Comments
 (0)