Skip to content

Commit

Permalink
NULL -> nullptr, more vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
mreineck committed Sep 26, 2024
1 parent 79b9080 commit ff8da04
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 63 deletions.
10 changes: 5 additions & 5 deletions include/finufft/finufft_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ template<typename TF> 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<TC> prephase; // pre-phase, for all input NU pts
std::vector<TC> deconv; // reciprocal of kernel FT, phase, all output NU pts
std::vector<TC> CpBatch; // working array of prephased strengths
TF *Sp = nullptr, *Tp = nullptr, *Up = nullptr; // internal primed targs (s'_k, etc),
// allocated
type3params<TF> t3P; // groups together type 3 shift, scale, phase, parameters
std::vector<TC> deconv; // reciprocal of kernel FT, phase, all output NU pts
std::vector<TC> CpBatch; // working array of prephased strengths
std::vector<TF> Sp, Tp, Up; // internal primed targs (s'_k, etc),
// allocated
type3params<TF> t3P; // groups together type 3 shift, scale, phase, parameters
FINUFFT_PLAN_T<TF> *innerT2plan = nullptr; // ptr used for type 2 in step 2 of type 3

// other internal structs
Expand Down
4 changes: 2 additions & 2 deletions src/finufft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FINUFFT_PLAN_T<FLT> *>(p);
Expand Down
46 changes: 19 additions & 27 deletions src/finufft_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ static void onedim_fseries_kernel(BIGINT nf, std::vector<T> &fwkerhalf,
}

template<typename T>
static void onedim_nuft_kernel(BIGINT nk, T *k, std::vector<T> &phihat,
static void onedim_nuft_kernel(BIGINT nk, const std::vector<T> &k, std::vector<T> &phihat,
finufft_spread_opts opts)
/*
Approximates exact 1D Fourier transform of cnufftspread's real symmetric
Expand Down Expand Up @@ -543,7 +543,7 @@ template<typename TF>
int finufft_makeplan_t(int type, int dim, const BIGINT *n_modes, int iflag, int ntrans,
TF tol, FINUFFT_PLAN_T<TF> **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
Expand All @@ -552,7 +552,7 @@ int finufft_makeplan_t(int type, int dim, const BIGINT *n_modes, int iflag, int
p = new FINUFFT_PLAN_T<TF>; // 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!
}
Expand Down Expand Up @@ -884,20 +881,17 @@ int finufft_setpts_t(FINUFFT_PLAN_T<TF> *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)...
Expand Down Expand Up @@ -1005,8 +999,9 @@ int finufft_setpts_t(FINUFFT_PLAN_T<TF> *p, BIGINT nj, TF *xj, TF *yj, TF *zj, B
__func__, ier);
return ier;
}
ier = finufft_setpts_t<TF>(p->innerT2plan, nk, p->Sp, p->Tp, p->Up, 0, NULL, NULL,
NULL); // note nk = # output points (not nj)
ier = finufft_setpts_t<TF>(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;
Expand Down Expand Up @@ -1177,16 +1172,13 @@ template int finufft_execute_t<double>(
template<typename TF> FINUFFT_PLAN_T<TF>::~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);
Expand Down
62 changes: 33 additions & 29 deletions src/simpleinterfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ int finufftf_execute(finufftf_plan p, std::complex<float> *cj, std::complex<floa
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 ptr, so not a ptr to a plan, report error
return 1;

delete reinterpret_cast<FINUFFT_PLAN_T<double> *>(p);
Expand All @@ -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<FINUFFT_PLAN_T<float> *>(p);
Expand All @@ -95,7 +95,7 @@ static int invokeGuruInterface(int n_dims, int type, int n_transf, BIGINT nj, T
FINUFFT_PLAN_T<T> *plan = nullptr;
int ier =
finufft_makeplan_t<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;
Expand Down Expand Up @@ -164,16 +164,18 @@ int finufft1d2many(int n_transf, BIGINT nj, double *xj, std::complex<double> *cj
finufft_opts *opts)
// Type-2 1D complex nonuniform FFT, many vectors. See ../docs/usage.rst
{
return invokeGuruInterface<double>(1, 2, n_transf, nj, xj, NULL, NULL, cj, iflag, eps,
{ms, 1, 1}, 0, NULL, NULL, NULL, fk, opts);
return invokeGuruInterface<double>(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<float> *cj,
int iflag, float eps, BIGINT ms, std::complex<float> *fk,
finufft_opts *opts)
// Type-2 1D complex nonuniform FFT, many vectors. See ../docs/usage.rst
{
return invokeGuruInterface<float>(1, 2, n_transf, nj, xj, NULL, NULL, cj, iflag, eps,
{ms, 1, 1}, 0, NULL, NULL, NULL, fk, opts);
return invokeGuruInterface<float>(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<double> *cj, int iflag, double eps,
Expand All @@ -194,16 +196,16 @@ int finufft1d3many(int n_transf, BIGINT nj, double *xj, std::complex<double> *cj
finufft_opts *opts)
// Type-3 1D complex nonuniform FFT, many vectors. See ../docs/usage.rst
{
return invokeGuruInterface<double>(1, 3, n_transf, nj, xj, NULL, NULL, cj, iflag, eps,
{0, 0, 0}, nk, s, NULL, NULL, fk, opts);
return invokeGuruInterface<double>(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<float> *cj,
int iflag, float eps, BIGINT nk, float *s, std::complex<float> *fk,
finufft_opts *opts)
// Type-3 1D complex nonuniform FFT, many vectors. See ../docs/usage.rst
{
return invokeGuruInterface<float>(1, 3, n_transf, nj, xj, NULL, NULL, cj, iflag, eps,
{0, 0, 0}, nk, s, NULL, NULL, fk, opts);
return invokeGuruInterface<float>(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<double> *cj, int iflag, double eps,
BIGINT nk, double *s, std::complex<double> *fk, finufft_opts *opts)
Expand All @@ -225,16 +227,16 @@ int finufft2d1many(int n_transf, BIGINT nj, double *xj, double *yj,
std::complex<double> *fk, finufft_opts *opts)
// Type-1 2D complex nonuniform FFT, many vectors. See ../docs/usage.rst
{
return invokeGuruInterface<double>(2, 1, n_transf, nj, xj, yj, NULL, c, iflag, eps,
{ms, mt, 1}, 0, NULL, NULL, NULL, fk, opts);
return invokeGuruInterface<double>(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<float> *c,
int iflag, float eps, BIGINT ms, BIGINT mt, std::complex<float> *fk,
finufft_opts *opts)
// Type-1 2D complex nonuniform FFT, many vectors. See ../docs/usage.rst
{
return invokeGuruInterface<float>(2, 1, n_transf, nj, xj, yj, NULL, c, iflag, eps,
{ms, mt, 1}, 0, NULL, NULL, NULL, fk, opts);
return invokeGuruInterface<float>(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<double> *cj, int iflag,
double eps, BIGINT ms, BIGINT mt, std::complex<double> *fk,
Expand All @@ -256,16 +258,16 @@ int finufft2d2many(int n_transf, BIGINT nj, double *xj, double *yj,
std::complex<double> *fk, finufft_opts *opts)
// Type-2 2D complex nonuniform FFT, many vectors. See ../docs/usage.rst
{
return invokeGuruInterface<double>(2, 2, n_transf, nj, xj, yj, NULL, c, iflag, eps,
{ms, mt, 1}, 0, NULL, NULL, NULL, fk, opts);
return invokeGuruInterface<double>(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<float> *c,
int iflag, float eps, BIGINT ms, BIGINT mt, std::complex<float> *fk,
finufft_opts *opts)
// Type-2 2D complex nonuniform FFT, many vectors. See ../docs/usage.rst
{
return invokeGuruInterface<float>(2, 2, n_transf, nj, xj, yj, NULL, c, iflag, eps,
{ms, mt, 1}, 0, NULL, NULL, NULL, fk, opts);
return invokeGuruInterface<float>(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<double> *cj, int iflag,
double eps, BIGINT ms, BIGINT mt, std::complex<double> *fk,
Expand All @@ -287,16 +289,16 @@ int finufft2d3many(int n_transf, BIGINT nj, double *xj, double *yj,
double *t, std::complex<double> *fk, finufft_opts *opts)
// Type-3 2D complex nonuniform FFT, many vectors. See ../docs/usage.rst
{
return invokeGuruInterface<double>(2, 3, n_transf, nj, xj, yj, NULL, cj, iflag, eps,
{0, 0, 0}, nk, s, t, NULL, fk, opts);
return invokeGuruInterface<double>(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<float> *cj, int iflag, float eps, BIGINT nk, float *s,
float *t, std::complex<float> *fk, finufft_opts *opts)
// Type-3 2D complex nonuniform FFT, many vectors. See ../docs/usage.rst
{
return invokeGuruInterface<float>(2, 3, n_transf, nj, xj, yj, NULL, cj, iflag, eps,
{0, 0, 0}, nk, s, t, NULL, fk, opts);
return invokeGuruInterface<float>(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<double> *cj, int iflag,
double eps, BIGINT nk, double *s, double *t, std::complex<double> *fk,
Expand All @@ -321,15 +323,16 @@ 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<double>(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<float> *cj, int iflag, float eps, BIGINT ms, BIGINT mt,
BIGINT mu, std::complex<float> *fk, finufft_opts *opts)
// Type-1 3D complex nonuniform FFT, many vectors. See ../docs/usage.rst
{
return invokeGuruInterface<float>(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<double> *cj,
int iflag, double eps, BIGINT ms, BIGINT mt, BIGINT mu,
Expand All @@ -352,15 +355,16 @@ 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<double>(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<float> *cj, int iflag, float eps, BIGINT ms, BIGINT mt,
BIGINT mu, std::complex<float> *fk, finufft_opts *opts)
// Type-2 3D complex nonuniform FFT, many vectors. See ../docs/usage.rst
{
return invokeGuruInterface<float>(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<double> *cj,
int iflag, double eps, BIGINT ms, BIGINT mt, BIGINT mu,
Expand Down

0 comments on commit ff8da04

Please sign in to comment.