Skip to content

Commit 468844f

Browse files
committed
using const ref when possible
1 parent 16973b5 commit 468844f

File tree

2 files changed

+35
-38
lines changed

2 files changed

+35
-38
lines changed

include/finufft/spreadinterp.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,25 @@ namespace spreadinterp {
3131
// things external (spreadinterp) interface needs...
3232
FINUFFT_EXPORT int FINUFFT_CDECL spreadinterp(
3333
BIGINT N1, BIGINT N2, BIGINT N3, FLT *data_uniform, BIGINT M, FLT *kx, FLT *ky,
34-
FLT *kz, FLT *data_nonuniform, finufft_spread_opts opts);
34+
FLT *kz, FLT *data_nonuniform, const finufft_spread_opts &opts);
3535
FINUFFT_EXPORT int FINUFFT_CDECL spreadcheck(BIGINT N1, BIGINT N2, BIGINT N3, BIGINT M,
3636
FLT *kx, FLT *ky, FLT *kz,
37-
finufft_spread_opts opts);
37+
const finufft_spread_opts &opts);
3838
FINUFFT_EXPORT int FINUFFT_CDECL indexSort(BIGINT *sort_indices, BIGINT N1, BIGINT N2,
3939
BIGINT N3, BIGINT M, FLT *kx, FLT *ky, FLT *kz,
40-
finufft_spread_opts opts);
40+
const finufft_spread_opts &opts);
4141
FINUFFT_EXPORT int FINUFFT_CDECL interpSorted(
4242
BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT N3, FLT *data_uniform, BIGINT M,
43-
FLT *kx, FLT *ky, FLT *kz, FLT *data_nonuniform, finufft_spread_opts opts,
44-
int did_sort);
43+
FLT *kx, FLT *ky, FLT *kz, FLT *data_nonuniform, const finufft_spread_opts &opts);
4544
FINUFFT_EXPORT int FINUFFT_CDECL spreadSorted(
46-
BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT N3, FLT *data_uniform, BIGINT M,
47-
FLT *kx, FLT *ky, FLT *kz, FLT *data_nonuniform, finufft_spread_opts opts,
48-
int did_sort);
45+
const BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT N3, FLT *data_uniform,
46+
BIGINT M, FLT *kx, FLT *ky, FLT *kz, const FLT *data_nonuniform,
47+
const finufft_spread_opts &opts, int did_sort);
4948
FINUFFT_EXPORT int FINUFFT_CDECL spreadinterpSorted(
5049
BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT N3, FLT *data_uniform, BIGINT M,
51-
FLT *kx, FLT *ky, FLT *kz, FLT *data_nonuniform, finufft_spread_opts opts,
50+
FLT *kx, FLT *ky, FLT *kz, FLT *data_nonuniform, const finufft_spread_opts &opts,
5251
int did_sort);
5352
FINUFFT_EXPORT FLT FINUFFT_CDECL evaluate_kernel(FLT x, const finufft_spread_opts &opts);
54-
FINUFFT_EXPORT FLT FINUFFT_CDECL evaluate_kernel_noexp(FLT x,
55-
const finufft_spread_opts &opts);
5653
FINUFFT_EXPORT int FINUFFT_CDECL setup_spreader(finufft_spread_opts &opts, FLT eps,
5754
double upsampfac, int kerevalmeth,
5855
int debug, int showwarn, int dim);

src/spreadinterp.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static void get_subgrid(BIGINT &offset1, BIGINT &offset2, BIGINT &offset3,
104104

105105
// ==========================================================================
106106
int spreadinterp(BIGINT N1, BIGINT N2, BIGINT N3, FLT *data_uniform, BIGINT M, FLT *kx,
107-
FLT *ky, FLT *kz, FLT *data_nonuniform, finufft_spread_opts opts)
107+
FLT *ky, FLT *kz, FLT *data_nonuniform, const finufft_spread_opts &opts)
108108
/* ------------Spreader/interpolator for 1, 2, or 3 dimensions --------------
109109
If opts.spread_direction=1, evaluate, in the 1D case,
110110
@@ -196,7 +196,7 @@ static int ndims_from_Ns(BIGINT N1, BIGINT N2, BIGINT N3)
196196
}
197197

198198
int spreadcheck(BIGINT N1, BIGINT N2, BIGINT N3, BIGINT M, FLT *kx, FLT *ky, FLT *kz,
199-
finufft_spread_opts opts)
199+
const finufft_spread_opts &opts)
200200
/* This does just the input checking and reporting for the spreader.
201201
See spreadinterp() for input arguments and meaning of returned value.
202202
Split out by Melody Shih, Jun 2018. Finiteness chk Barnett 7/30/18.
@@ -220,7 +220,7 @@ int spreadcheck(BIGINT N1, BIGINT N2, BIGINT N3, BIGINT M, FLT *kx, FLT *ky, FLT
220220
}
221221

222222
int indexSort(BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT N3, BIGINT M, FLT *kx,
223-
FLT *ky, FLT *kz, finufft_spread_opts opts)
223+
FLT *ky, FLT *kz, const finufft_spread_opts &opts)
224224
/* This makes a decision whether or not to sort the NU pts (influenced by
225225
opts.sort), and if yes, calls either single- or multi-threaded bin sort,
226226
writing reordered index list to sort_indices. If decided not to sort, the
@@ -298,7 +298,8 @@ int indexSort(BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT N3, BIGINT M, F
298298

299299
int spreadinterpSorted(BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT N3,
300300
FLT *data_uniform, BIGINT M, FLT *kx, FLT *ky, FLT *kz,
301-
FLT *data_nonuniform, finufft_spread_opts opts, int did_sort)
301+
FLT *data_nonuniform, const finufft_spread_opts &opts,
302+
int did_sort)
302303
/* Logic to select the main spreading (dir=1) vs interpolation (dir=2) routine.
303304
See spreadinterp() above for inputs arguments and definitions.
304305
Return value should always be 0 (no error reporting).
@@ -311,15 +312,16 @@ int spreadinterpSorted(BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT N3,
311312

312313
else // ================= direction 2 (interpolation) ===========
313314
interpSorted(sort_indices, N1, N2, N3, data_uniform, M, kx, ky, kz, data_nonuniform,
314-
opts, did_sort);
315+
opts);
315316

316317
return 0;
317318
}
318319

319320
// --------------------------------------------------------------------------
320-
int spreadSorted(BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT N3, FLT *data_uniform,
321-
BIGINT M, FLT *kx, FLT *ky, FLT *kz, FLT *data_nonuniform,
322-
finufft_spread_opts opts, int did_sort)
321+
int spreadSorted(const BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT N3,
322+
FLT *data_uniform, BIGINT M, FLT *kx, FLT *ky, FLT *kz,
323+
const FLT *data_nonuniform, const finufft_spread_opts &opts,
324+
int did_sort)
323325
// Spread NU pts in sorted order to a uniform grid. See spreadinterp() for doc.
324326
{
325327
CNTime timer;
@@ -441,9 +443,10 @@ int spreadSorted(BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT N3, FLT *dat
441443

442444
// --------------------------------------------------------------------------
443445
template<uint16_t ns, uint16_t kerevalmeth>
444-
int interpSorted_kernel(const BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT N3,
445-
FLT *data_uniform, BIGINT M, FLT *kx, FLT *ky, FLT *kz,
446-
FLT *data_nonuniform, finufft_spread_opts opts, int did_sort)
446+
static int interpSorted_kernel(const BIGINT *sort_indices, const BIGINT N1,
447+
const BIGINT N2, const BIGINT N3, const FLT *data_uniform,
448+
const BIGINT M, FLT *kx, FLT *ky, FLT *kz,
449+
FLT *data_nonuniform, const finufft_spread_opts &opts)
447450
// Interpolate to NU pts in sorted order from a uniform grid.
448451
// See spreadinterp() for doc.
449452
{
@@ -546,43 +549,40 @@ int interpSorted_kernel(const BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT
546549
}
547550

548551
template<uint16_t NS>
549-
int interpSorted_dispatch(BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT N3,
550-
FLT *data_uniform, BIGINT M, FLT *kx, FLT *ky, FLT *kz,
551-
FLT *data_nonuniform, finufft_spread_opts opts, int did_sort) {
552+
static int interpSorted_dispatch(BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT N3,
553+
FLT *data_uniform, BIGINT M, FLT *kx, FLT *ky, FLT *kz,
554+
FLT *data_nonuniform, const finufft_spread_opts &opts) {
552555
static_assert(MIN_NSPREAD <= NS <= MAX_NSPREAD,
553556
"NS must be in the range (MIN_NSPREAD, MAX_NSPREAD)");
554557
if constexpr (NS == MIN_NSPREAD) { // Base case
555558
if (opts.kerevalmeth)
556-
return interpSorted_kernel<MIN_NSPREAD, true>(sort_indices, N1, N2, N3,
557-
data_uniform, M, kx, ky, kz,
558-
data_nonuniform, opts, did_sort);
559+
return interpSorted_kernel<MIN_NSPREAD, true>(
560+
sort_indices, N1, N2, N3, data_uniform, M, kx, ky, kz, data_nonuniform, opts);
559561
else {
560-
return interpSorted_kernel<MIN_NSPREAD, false>(sort_indices, N1, N2, N3,
561-
data_uniform, M, kx, ky, kz,
562-
data_nonuniform, opts, did_sort);
562+
return interpSorted_kernel<MIN_NSPREAD, false>(
563+
sort_indices, N1, N2, N3, data_uniform, M, kx, ky, kz, data_nonuniform, opts);
563564
}
564565
} else {
565566
if (opts.nspread == NS) {
566567
if (opts.kerevalmeth) {
567568
return interpSorted_kernel<NS, true>(sort_indices, N1, N2, N3, data_uniform, M,
568-
kx, ky, kz, data_nonuniform, opts, did_sort);
569+
kx, ky, kz, data_nonuniform, opts);
569570
} else {
570571
return interpSorted_kernel<NS, false>(sort_indices, N1, N2, N3, data_uniform, M,
571-
kx, ky, kz, data_nonuniform, opts,
572-
did_sort);
572+
kx, ky, kz, data_nonuniform, opts);
573573
}
574574
} else {
575575
return interpSorted_dispatch<NS - 1>(sort_indices, N1, N2, N3, data_uniform, M, kx,
576-
ky, kz, data_nonuniform, opts, did_sort);
576+
ky, kz, data_nonuniform, opts);
577577
}
578578
}
579579
}
580580

581581
int interpSorted(BIGINT *sort_indices, BIGINT N1, BIGINT N2, BIGINT N3, FLT *data_uniform,
582582
BIGINT M, FLT *kx, FLT *ky, FLT *kz, FLT *data_nonuniform,
583-
finufft_spread_opts opts, int did_sort) {
583+
const finufft_spread_opts &opts) {
584584
return interpSorted_dispatch<MAX_NSPREAD>(sort_indices, N1, N2, N3, data_uniform, M, kx,
585-
ky, kz, data_nonuniform, opts, did_sort);
585+
ky, kz, data_nonuniform, opts);
586586
}
587587

588588
///////////////////////////////////////////////////////////////////////////
@@ -760,7 +760,7 @@ Two upsampfacs implemented. Params must match ref formula. Barnett 4/24/18 */
760760
alignas(alignment) static constexpr auto padded_coeffs =
761761
pad_2D_array_with_zeros<FLT, nc, w, padded_ns>(horner_coeffs);
762762

763-
const auto zv = simd_type(z);
763+
const simd_type zv(z);
764764

765765
for (uint8_t i = 0; i < w; i += simd_size) {
766766
auto k = simd_type::load_aligned(padded_coeffs[0].data() + i);

0 commit comments

Comments
 (0)