From ff8da04fb1cbf9dea429048b0e82bdf10e7821cb Mon Sep 17 00:00:00 2001 From: Martin Reinecke Date: Thu, 26 Sep 2024 08:38:35 +0200 Subject: [PATCH] NULL -> nullptr, more vectors --- include/finufft/finufft_core.h | 10 +++--- src/finufft.cpp | 4 +-- src/finufft_core.cpp | 46 +++++++++++-------------- src/simpleinterfaces.cpp | 62 ++++++++++++++++++---------------- 4 files changed, 59 insertions(+), 63 deletions(-) diff --git a/include/finufft/finufft_core.h b/include/finufft/finufft_core.h index 4f81728d..038d079a 100644 --- a/include/finufft/finufft_core.h +++ b/include/finufft/finufft_core.h @@ -184,11 +184,11 @@ template struct FINUFFT_PLAN_T { // the main plan object, fully C++ TF *S = nullptr, *T = nullptr, *U = nullptr; // pointers to user's target NU pts arrays // (no new allocs) std::vector prephase; // pre-phase, for all input NU pts - std::vector deconv; // reciprocal of kernel FT, phase, all output NU pts - std::vector CpBatch; // working array of prephased strengths - TF *Sp = nullptr, *Tp = nullptr, *Up = nullptr; // internal primed targs (s'_k, etc), - // allocated - type3params t3P; // groups together type 3 shift, scale, phase, parameters + std::vector deconv; // reciprocal of kernel FT, phase, all output NU pts + std::vector CpBatch; // working array of prephased strengths + std::vector Sp, Tp, Up; // internal primed targs (s'_k, etc), + // allocated + type3params t3P; // groups together type 3 shift, scale, phase, parameters FINUFFT_PLAN_T *innerT2plan = nullptr; // ptr used for type 2 in step 2 of type 3 // other internal structs diff --git a/src/finufft.cpp b/src/finufft.cpp index fddb3fb6..758fcb72 100644 --- a/src/finufft.cpp +++ b/src/finufft.cpp @@ -26,10 +26,10 @@ int FINUFFT_EXECUTE(FINUFFT_PLAN p, CPX *cj, CPX *fk) { int FINUFFT_DESTROY(FINUFFT_PLAN p) // Free everything we allocated inside of finufft_plan pointed to by p. // Also must not crash if called immediately after finufft_makeplan. -// Thus either each thing free'd here is guaranteed to be NULL or correctly +// Thus either each thing free'd here is guaranteed to be nullptr or correctly // allocated. { - if (!p) // NULL ptr, so not a ptr to a plan, report error + if (!p) // nullptr, so not a ptr to a plan, report error return 1; delete reinterpret_cast *>(p); diff --git a/src/finufft_core.cpp b/src/finufft_core.cpp index 8987a37a..e7e36858 100644 --- a/src/finufft_core.cpp +++ b/src/finufft_core.cpp @@ -232,7 +232,7 @@ static void onedim_fseries_kernel(BIGINT nf, std::vector &fwkerhalf, } template -static void onedim_nuft_kernel(BIGINT nk, T *k, std::vector &phihat, +static void onedim_nuft_kernel(BIGINT nk, const std::vector &k, std::vector &phihat, finufft_spread_opts opts) /* Approximates exact 1D Fourier transform of cnufftspread's real symmetric @@ -543,7 +543,7 @@ template int finufft_makeplan_t(int type, int dim, const BIGINT *n_modes, int iflag, int ntrans, TF tol, FINUFFT_PLAN_T **pp, finufft_opts *opts) // Populates the fields of finufft_plan which is pointed to by "pp". -// opts is ptr to a finufft_opts to set options, or NULL to use defaults. +// opts is ptr to a finufft_opts to set options, or nullptr to use defaults. // For some of the fields (if "auto" selected) here choose the actual setting. // For types 1,2 allocates memory for internal working arrays, // evaluates spreading kernel coefficients, and instantiates the fftw_plan @@ -552,7 +552,7 @@ int finufft_makeplan_t(int type, int dim, const BIGINT *n_modes, int iflag, int p = new FINUFFT_PLAN_T; // allocate fresh plan struct *pp = p; // pass out plan as ptr to plan struct - if (opts == NULL) // use default opts + if (!opts) // use default opts finufft_default_opts_t(&(p->opts)); else // or read from what's passed in p->opts = *opts; // keep a deep copy; changing *opts now has no effect @@ -654,9 +654,9 @@ int finufft_makeplan_t(int type, int dim, const BIGINT *n_modes, int iflag, int return ier; // set others as defaults (or unallocated for arrays)... - p->X = NULL; - p->Y = NULL; - p->Z = NULL; + p->X = nullptr; + p->Y = nullptr; + p->Z = nullptr; p->nf1 = 1; p->nf2 = 1; p->nf3 = 1; // crucial to leave as 1 for unused dims @@ -752,11 +752,8 @@ int finufft_makeplan_t(int type, int dim, const BIGINT *n_modes, int iflag, int if (p->opts.debug) printf("[%s] %dd%d: ntrans=%d\n", __func__, dim, type, ntrans); // in case destroy occurs before setpts, need safe dummy ptrs/plans... - p->fwBatch = NULL; - p->Sp = NULL; - p->Tp = NULL; - p->Up = NULL; - p->innerT2plan = NULL; + p->fwBatch = nullptr; + p->innerT2plan = nullptr; // Type 3 will call finufft_makeplan for type 2; no need to init FFTW // Note we don't even know nj or nk yet, so can't do anything else! } @@ -884,20 +881,17 @@ int finufft_setpts_t(FINUFFT_PLAN_T *p, BIGINT nj, TF *xj, TF *yj, TF *zj, B // alloc rescaled NU src pts x'_j (in X etc), rescaled NU targ pts s'_k ... // FIXME: should use realloc if (p->X) free(p->X); - if (p->Sp) free(p->Sp); - p->X = (TF *)malloc(sizeof(TF) * nj); - p->Sp = (TF *)malloc(sizeof(TF) * nk); + p->X = (TF *)malloc(sizeof(TF) * nj); + p->Sp.resize(nk); if (d > 1) { if (p->Y) free(p->Y); - if (p->Tp) free(p->Tp); - p->Y = (TF *)malloc(sizeof(TF) * nj); - p->Tp = (TF *)malloc(sizeof(TF) * nk); + p->Y = (TF *)malloc(sizeof(TF) * nj); + p->Tp.resize(nk); } if (d > 2) { if (p->Z) free(p->Z); - if (p->Up) free(p->Up); - p->Z = (TF *)malloc(sizeof(TF) * nj); - p->Up = (TF *)malloc(sizeof(TF) * nk); + p->Z = (TF *)malloc(sizeof(TF) * nj); + p->Up.resize(nk); } // always shift as use gam to rescale x_j to x'_j, etc (twist iii)... @@ -1005,8 +999,9 @@ int finufft_setpts_t(FINUFFT_PLAN_T *p, BIGINT nj, TF *xj, TF *yj, TF *zj, B __func__, ier); return ier; } - ier = finufft_setpts_t(p->innerT2plan, nk, p->Sp, p->Tp, p->Up, 0, NULL, NULL, - NULL); // note nk = # output points (not nj) + ier = finufft_setpts_t(p->innerT2plan, nk, p->Sp.data(), p->Tp.data(), + p->Up.data(), 0, nullptr, nullptr, + nullptr); // note nk = # output points (not nj) if (ier > 1) { fprintf(stderr, "[%s t3]: inner type 2 setpts failed, ier=%d!\n", __func__, ier); return ier; @@ -1177,16 +1172,13 @@ template int finufft_execute_t( template FINUFFT_PLAN_T::~FINUFFT_PLAN_T() { // Free everything we allocated inside of finufft_plan pointed to by p. // Also must not crash if called immediately after finufft_makeplan. - // Thus either each thing free'd here is guaranteed to be NULL or correctly + // Thus either each thing free'd here is guaranteed to be nullptr or correctly // allocated. if (fftPlan) fftPlan->free(fwBatch); // free the big FFTW (or t3 spread) working array if (type == 1 || type == 2) { } else { // free the stuff alloc for type 3 only delete innerT2plan; - innerT2plan = nullptr; // if NULL, ignore its error code - free(Sp); - free(Tp); - free(Up); + innerT2plan = nullptr; free(X); free(Y); free(Z); diff --git a/src/simpleinterfaces.cpp b/src/simpleinterfaces.cpp index 43d9806a..4b3630d9 100644 --- a/src/simpleinterfaces.cpp +++ b/src/simpleinterfaces.cpp @@ -56,10 +56,10 @@ int finufftf_execute(finufftf_plan p, std::complex *cj, std::complex *>(p); @@ -69,10 +69,10 @@ int finufft_destroy(finufft_plan p) int finufftf_destroy(finufftf_plan p) // Free everything we allocated inside of finufft_plan pointed to by p. // Also must not crash if called immediately after finufft_makeplan. -// Thus either each thing free'd here is guaranteed to be NULL or correctly +// Thus either each thing free'd here is guaranteed to be nullptr or correctly // allocated. { - if (!p) // NULL ptr, so not a ptr to a plan, report error + if (!p) // nullptr ptr, so not a ptr to a plan, report error return 1; delete reinterpret_cast *>(p); @@ -95,7 +95,7 @@ static int invokeGuruInterface(int n_dims, int type, int n_transf, BIGINT nj, T FINUFFT_PLAN_T *plan = nullptr; int ier = finufft_makeplan_t(type, n_dims, n_modes.data(), iflag, n_transf, eps, &plan, - popts); // popts (ptr to opts) can be NULL + popts); // popts (ptr to opts) can be nullptr if (ier > 1) { // since 1 (a warning) still allows proceeding... fprintf(stderr, "FINUFFT invokeGuru: plan error (ier=%d)!\n", ier); delete plan; @@ -164,16 +164,18 @@ int finufft1d2many(int n_transf, BIGINT nj, double *xj, std::complex *cj finufft_opts *opts) // Type-2 1D complex nonuniform FFT, many vectors. See ../docs/usage.rst { - return invokeGuruInterface(1, 2, n_transf, nj, xj, NULL, NULL, cj, iflag, eps, - {ms, 1, 1}, 0, NULL, NULL, NULL, fk, opts); + return invokeGuruInterface(1, 2, n_transf, nj, xj, nullptr, nullptr, cj, iflag, + eps, {ms, 1, 1}, 0, nullptr, nullptr, nullptr, fk, + opts); } int finufftf1d2many(int n_transf, BIGINT nj, float *xj, std::complex *cj, int iflag, float eps, BIGINT ms, std::complex *fk, finufft_opts *opts) // Type-2 1D complex nonuniform FFT, many vectors. See ../docs/usage.rst { - return invokeGuruInterface(1, 2, n_transf, nj, xj, NULL, NULL, cj, iflag, eps, - {ms, 1, 1}, 0, NULL, NULL, NULL, fk, opts); + return invokeGuruInterface(1, 2, n_transf, nj, xj, nullptr, nullptr, cj, iflag, + eps, {ms, 1, 1}, 0, nullptr, nullptr, nullptr, fk, + opts); } int finufft1d2(BIGINT nj, double *xj, std::complex *cj, int iflag, double eps, @@ -194,16 +196,16 @@ int finufft1d3many(int n_transf, BIGINT nj, double *xj, std::complex *cj finufft_opts *opts) // Type-3 1D complex nonuniform FFT, many vectors. See ../docs/usage.rst { - return invokeGuruInterface(1, 3, n_transf, nj, xj, NULL, NULL, cj, iflag, eps, - {0, 0, 0}, nk, s, NULL, NULL, fk, opts); + return invokeGuruInterface(1, 3, n_transf, nj, xj, nullptr, nullptr, cj, iflag, + eps, {0, 0, 0}, nk, s, nullptr, nullptr, fk, opts); } int finufftf1d3many(int n_transf, BIGINT nj, float *xj, std::complex *cj, int iflag, float eps, BIGINT nk, float *s, std::complex *fk, finufft_opts *opts) // Type-3 1D complex nonuniform FFT, many vectors. See ../docs/usage.rst { - return invokeGuruInterface(1, 3, n_transf, nj, xj, NULL, NULL, cj, iflag, eps, - {0, 0, 0}, nk, s, NULL, NULL, fk, opts); + return invokeGuruInterface(1, 3, n_transf, nj, xj, nullptr, nullptr, cj, iflag, + eps, {0, 0, 0}, nk, s, nullptr, nullptr, fk, opts); } int finufft1d3(BIGINT nj, double *xj, std::complex *cj, int iflag, double eps, BIGINT nk, double *s, std::complex *fk, finufft_opts *opts) @@ -225,16 +227,16 @@ int finufft2d1many(int n_transf, BIGINT nj, double *xj, double *yj, std::complex *fk, finufft_opts *opts) // Type-1 2D complex nonuniform FFT, many vectors. See ../docs/usage.rst { - return invokeGuruInterface(2, 1, n_transf, nj, xj, yj, NULL, c, iflag, eps, - {ms, mt, 1}, 0, NULL, NULL, NULL, fk, opts); + return invokeGuruInterface(2, 1, n_transf, nj, xj, yj, nullptr, c, iflag, eps, + {ms, mt, 1}, 0, nullptr, nullptr, nullptr, fk, opts); } int finufftf2d1many(int n_transf, BIGINT nj, float *xj, float *yj, std::complex *c, int iflag, float eps, BIGINT ms, BIGINT mt, std::complex *fk, finufft_opts *opts) // Type-1 2D complex nonuniform FFT, many vectors. See ../docs/usage.rst { - return invokeGuruInterface(2, 1, n_transf, nj, xj, yj, NULL, c, iflag, eps, - {ms, mt, 1}, 0, NULL, NULL, NULL, fk, opts); + return invokeGuruInterface(2, 1, n_transf, nj, xj, yj, nullptr, c, iflag, eps, + {ms, mt, 1}, 0, nullptr, nullptr, nullptr, fk, opts); } int finufft2d1(BIGINT nj, double *xj, double *yj, std::complex *cj, int iflag, double eps, BIGINT ms, BIGINT mt, std::complex *fk, @@ -256,16 +258,16 @@ int finufft2d2many(int n_transf, BIGINT nj, double *xj, double *yj, std::complex *fk, finufft_opts *opts) // Type-2 2D complex nonuniform FFT, many vectors. See ../docs/usage.rst { - return invokeGuruInterface(2, 2, n_transf, nj, xj, yj, NULL, c, iflag, eps, - {ms, mt, 1}, 0, NULL, NULL, NULL, fk, opts); + return invokeGuruInterface(2, 2, n_transf, nj, xj, yj, nullptr, c, iflag, eps, + {ms, mt, 1}, 0, nullptr, nullptr, nullptr, fk, opts); } int finufftf2d2many(int n_transf, BIGINT nj, float *xj, float *yj, std::complex *c, int iflag, float eps, BIGINT ms, BIGINT mt, std::complex *fk, finufft_opts *opts) // Type-2 2D complex nonuniform FFT, many vectors. See ../docs/usage.rst { - return invokeGuruInterface(2, 2, n_transf, nj, xj, yj, NULL, c, iflag, eps, - {ms, mt, 1}, 0, NULL, NULL, NULL, fk, opts); + return invokeGuruInterface(2, 2, n_transf, nj, xj, yj, nullptr, c, iflag, eps, + {ms, mt, 1}, 0, nullptr, nullptr, nullptr, fk, opts); } int finufft2d2(BIGINT nj, double *xj, double *yj, std::complex *cj, int iflag, double eps, BIGINT ms, BIGINT mt, std::complex *fk, @@ -287,16 +289,16 @@ int finufft2d3many(int n_transf, BIGINT nj, double *xj, double *yj, double *t, std::complex *fk, finufft_opts *opts) // Type-3 2D complex nonuniform FFT, many vectors. See ../docs/usage.rst { - return invokeGuruInterface(2, 3, n_transf, nj, xj, yj, NULL, cj, iflag, eps, - {0, 0, 0}, nk, s, t, NULL, fk, opts); + return invokeGuruInterface(2, 3, n_transf, nj, xj, yj, nullptr, cj, iflag, eps, + {0, 0, 0}, nk, s, t, nullptr, fk, opts); } int finufftf2d3many(int n_transf, BIGINT nj, float *xj, float *yj, std::complex *cj, int iflag, float eps, BIGINT nk, float *s, float *t, std::complex *fk, finufft_opts *opts) // Type-3 2D complex nonuniform FFT, many vectors. See ../docs/usage.rst { - return invokeGuruInterface(2, 3, n_transf, nj, xj, yj, NULL, cj, iflag, eps, - {0, 0, 0}, nk, s, t, NULL, fk, opts); + return invokeGuruInterface(2, 3, n_transf, nj, xj, yj, nullptr, cj, iflag, eps, + {0, 0, 0}, nk, s, t, nullptr, fk, opts); } int finufft2d3(BIGINT nj, double *xj, double *yj, std::complex *cj, int iflag, double eps, BIGINT nk, double *s, double *t, std::complex *fk, @@ -321,7 +323,8 @@ int finufft3d1many(int n_transf, BIGINT nj, double *xj, double *yj, double *zj, // Type-1 3D complex nonuniform FFT, many vectors. See ../docs/usage.rst { return invokeGuruInterface(3, 1, n_transf, nj, xj, yj, zj, cj, iflag, eps, - {ms, mt, mu}, 0, NULL, NULL, NULL, fk, opts); + {ms, mt, mu}, 0, nullptr, nullptr, nullptr, fk, + opts); } int finufftf3d1many(int n_transf, BIGINT nj, float *xj, float *yj, float *zj, std::complex *cj, int iflag, float eps, BIGINT ms, BIGINT mt, @@ -329,7 +332,7 @@ int finufftf3d1many(int n_transf, BIGINT nj, float *xj, float *yj, float *zj, // Type-1 3D complex nonuniform FFT, many vectors. See ../docs/usage.rst { return invokeGuruInterface(3, 1, n_transf, nj, xj, yj, zj, cj, iflag, eps, - {ms, mt, mu}, 0, NULL, NULL, NULL, fk, opts); + {ms, mt, mu}, 0, nullptr, nullptr, nullptr, fk, opts); } int finufft3d1(BIGINT nj, double *xj, double *yj, double *zj, std::complex *cj, int iflag, double eps, BIGINT ms, BIGINT mt, BIGINT mu, @@ -352,7 +355,8 @@ int finufft3d2many(int n_transf, BIGINT nj, double *xj, double *yj, double *zj, // Type-2 3D complex nonuniform FFT, many vectors. See ../docs/usage.rst { return invokeGuruInterface(3, 2, n_transf, nj, xj, yj, zj, cj, iflag, eps, - {ms, mt, mu}, 0, NULL, NULL, NULL, fk, opts); + {ms, mt, mu}, 0, nullptr, nullptr, nullptr, fk, + opts); } int finufftf3d2many(int n_transf, BIGINT nj, float *xj, float *yj, float *zj, std::complex *cj, int iflag, float eps, BIGINT ms, BIGINT mt, @@ -360,7 +364,7 @@ int finufftf3d2many(int n_transf, BIGINT nj, float *xj, float *yj, float *zj, // Type-2 3D complex nonuniform FFT, many vectors. See ../docs/usage.rst { return invokeGuruInterface(3, 2, n_transf, nj, xj, yj, zj, cj, iflag, eps, - {ms, mt, mu}, 0, NULL, NULL, NULL, fk, opts); + {ms, mt, mu}, 0, nullptr, nullptr, nullptr, fk, opts); } int finufft3d2(BIGINT nj, double *xj, double *yj, double *zj, std::complex *cj, int iflag, double eps, BIGINT ms, BIGINT mt, BIGINT mu,