Skip to content

Commit 7f36347

Browse files
committed
cleanup
1 parent c1b91d0 commit 7f36347

17 files changed

+70
-54
lines changed

examples/guru1d1.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ int main(int argc, char *argv[])
7070
// rest is math checking and reporting...
7171
int n = 142519; // check the answer just for this mode
7272
assert(n >= -(double)N / 2 && n < (double)N / 2); // ensure meaningful test
73-
std::complex<double> Ftest = std::complex<double>(0, 0);
74-
const std::complex<double> I(0.0, 1.0);
73+
std::complex<double> Ftest(0, 0);
7574
for (int j = 0; j < M; ++j) Ftest += c[j] * std::exp(I * (double)n * x[j]);
7675
int nout = n + N / 2; // index in output array for freq mode n
7776
double Fmax = 0.0; // compute inf norm of F

src/cuda/spreadinterp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ int setup_spreader(finufft_spread_opts &opts, T eps, T upsampfac,
5555
}
5656

5757
// Set kernel width w (aka ns) and ES kernel beta parameter, in opts...
58-
int ns = std::ceil(-log10(eps / (T)10.0)); // 1 digit per power of ten
58+
int ns = std::ceil(-std::log10(eps / (T)10.0)); // 1 digit per power of ten
5959
if (upsampfac != 2.0) // override ns for custom sigma
6060
ns = std::ceil(
61-
-log(eps) / (T(PI) * sqrt(1 - 1 / upsampfac))); // formula,
61+
-std::log(eps) / (T(PI) * std::sqrt(1 - 1 / upsampfac))); // formula,
6262
// gamma=1
6363
ns = std::max(2, ns); // we don't have ns=1 version yet
6464
if (ns > MAX_NSPREAD) { // clip to match allocated arrays

test/adjointness.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int main() {
6464
BIGINT Nmax = Ns[0] * Ns[1] * Ns[2];
6565
std::vector<CPX> f(Nmax);
6666
for (int i = 0; i < Nmax; i++) f[i] = crandm11();
67-
std::cout << " done" << endl;
67+
std::cout << " done" << std::endl;
6868

6969
// generate random freq targs for type 3 only (t3 always uses Nmax targs)
7070
std::vector<FLT> s(Nmax), t(Nmax), u(Nmax);
@@ -83,7 +83,7 @@ int main() {
8383
for (int dim = 1; dim <= 3; ++dim) { // ....... loop over dims
8484
BIGINT N = 1; // compute actual num modes in this dim
8585
for (int d = 0; d < dim; ++d) N *= Ns[d];
86-
std::cout << " dim=" << dim << ", M=" << M << " pts, N=" << N << " modes:" << endl;
86+
std::cout << " dim=" << dim << ", M=" << M << " pts, N=" << N << " modes:" << std::endl;
8787

8888
for (int type = 1; type <= 3; ++type) { // .......... loop over types
8989
std::cout << "\ttype " << type << ": ";
@@ -99,8 +99,9 @@ int main() {
9999
ier = FINUFFT_EXECUTE(plan, C.data(), f.data()); // f->C
100100
ieradj = FINUFFT_EXECUTE_ADJOINT(plan, c.data(), F.data()); // c->F
101101
}
102-
if (ier > 0) std::cout << "\texecute failure: ier=" << ier << endl;
103-
if (ieradj > 0) std::cout << "\texecute_adjoint failure: ier=" << ieradj << endl;
102+
if (ier > 0) std::cout << "\texecute failure: ier=" << ier << std::endl;
103+
if (ieradj > 0) std::cout << "\texecute_adjoint failure: ier=" << ieradj
104+
<< std::endl;
104105
iermax = std::max(std::max(ier, ieradj), iermax); // track if something failed
105106
FINUFFT_DESTROY(plan);
106107

@@ -115,18 +116,18 @@ int main() {
115116
FLT denom =
116117
twonorm(Nused, F.data()) * twonorm(Nused, f.data()) / std::sqrt(Nused);
117118
FLT err = std::abs(ipc - ipf) / denom; // scale rel to norms of vectors in ipc
118-
std::cout << " adj rel err " << err << endl; // "\t denom=" << denom << endl;
119+
std::cout << " adj rel err " << err << std::endl; // "\t denom=" << denom << endl;
119120
errmax = std::max(err, errmax);
120121
}
121122
}
122123

123124
// report and exit code
124125
if (errmax > allowederr || iermax > 0) {
125-
std::cout << name << " failed! (allowederr=" << allowederr << ", iermax=" << iermax << ")"
126-
<< endl;
126+
std::cout << name << " failed! (allowederr=" << allowederr << ", iermax=" << iermax
127+
<< ")" << std::endl;
127128
return 1;
128129
} else {
129-
std::cout << name << " passed" << endl;
130+
std::cout << name << " passed" << std::endl;
130131
return 0;
131132
}
132133
}

test/basicpassfail.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <cmath>
2+
13
#include <finufft/test_defs.h>
24

35
// Basic pass-fail test of one routine in library w/ default opts.
@@ -32,7 +34,8 @@ int main() {
3234
// Check correct math for a single mode...................
3335
BIGINT n = (BIGINT)(0.37 * N); // choose some mode near the top (N/2)
3436
CPX Ftest = CPX(0.0, 0.0); // crude exact answer & error check...
35-
for (BIGINT j = 0; j < M; ++j) Ftest += c[j] * exp((FLT)isign * I * (FLT)n * x[j]);
37+
for (BIGINT j = 0; j < M; ++j)
38+
Ftest += c[j] * std::exp((FLT)isign * I * (FLT)n * x[j]);
3639
BIGINT nout = n + N / 2; // index in output array for freq mode n
3740
FLT Finfnrm = 0.0; // compute inf norm of F...
3841
for (int m = 0; m < N; ++m) {

test/cuda/cufinufft1d_test.cu

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,10 @@ int run_test(int method, int type, int N1, int M, T tol, T checktol, int iflag,
187187
if (type == 1) {
188188
int nt1 = 0.37 * N1; // choose some mode index to check
189189
thrust::complex<T> Ftp = thrust::complex<T>(0, 0), J = thrust::complex<T>(0.0, iflag);
190-
for (int j = 0; j < M; ++j) Ftp += c[j] * exp(J * (nt1 * x[j])); // crude direct
191-
int it = N1 / 2 + nt1; // index in complex F as 1d array
192-
rel_error = std::abs(Ftp - fk[it]) / infnorm(N1, fk);
190+
for (int j = 0; j < M; ++j)
191+
Ftp += c[j] * thrust::exp(J * (nt1 * x[j])); // crude direct
192+
int it = N1 / 2 + nt1; // index in complex F as 1d array
193+
rel_error = thrust::abs(Ftp - fk[it]) / infnorm(N1, fk);
193194
printf("[gpu ] one mode: rel err in F[%d] is %.3g\n", nt1, rel_error);
194195
if (static_cast<double>(M) * N1 <= TEST_BIGPROB) {
195196
// also full direct eval
@@ -205,8 +206,8 @@ int run_test(int method, int type, int N1, int M, T tol, T checktol, int iflag,
205206
thrust::complex<T> ctp = thrust::complex<T>(0, 0);
206207
int m = 0;
207208
for (int m1 = -(N1 / 2); m1 <= (N1 - 1) / 2; ++m1)
208-
ctp += fk[m++] * exp(J * (m1 * x[jt])); // crude direct
209-
rel_error = std::abs(c[jt] - ctp) / infnorm(M, (std::complex<T> *)c.data());
209+
ctp += fk[m++] * thrust::exp(J * (m1 * x[jt])); // crude direct
210+
rel_error = thrust::abs(c[jt] - ctp) / infnorm(M, (std::complex<T> *)c.data());
210211
printf("[gpu ] one targ: rel err in c[%d] is %.3g\n", jt, rel_error);
211212
if (static_cast<double>(M) * N1 <= TEST_BIGPROB) {
212213
std::vector<thrust::complex<T>> ct(M);
@@ -222,9 +223,9 @@ int run_test(int method, int type, int N1, int M, T tol, T checktol, int iflag,
222223
thrust::complex<T> Ftp = thrust::complex<T>(0, 0);
223224

224225
for (int j = 0; j < M; ++j) {
225-
Ftp += c[j] * exp(J * (x[j] * s[jt]));
226+
Ftp += c[j] * thrust::exp(J * (x[j] * s[jt]));
226227
}
227-
rel_error = std::abs(Ftp - fk[jt]) / infnorm(N1, (std::complex<T> *)fk.data());
228+
rel_error = thrust::abs(Ftp - fk[jt]) / infnorm(N1, (std::complex<T> *)fk.data());
228229
printf("[gpu ] one mode: rel err in F[%d] is %.3g\n", jt, rel_error);
229230
if (static_cast<double>(M) * N1 <= TEST_BIGPROB) {
230231
std::vector<thrust::complex<T>> Ft(N1);

test/cuda/cufinufft1dspreadinterponly_test.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ int run_test(int N1, int M, T tol, T checktol, int iflag, double upsampfac) {
185185

186186
csum = std::accumulate(c.begin(), c.end(), thrust::complex<T>(T(0), T(0)));
187187
auto sup_err = T(0.0);
188-
for (auto cj : c) sup_err = std::max(sup_err, std::abs(cj - kersum));
188+
for (auto cj : c) sup_err = std::max(sup_err, thrust::abs(cj - kersum));
189189
const auto rel_sup_err = sup_err / thrust::abs(kersum);
190190
printf("\trel sup err %.3g\n", rel_sup_err);
191191

test/cuda/cufinufft2d1nupts_test.cu

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,16 @@ template<typename T> int run_test(int method) {
194194
int nt1 = (int)(0.37 * N1), nt2 = (int)(0.26 * N2); // choose some mode index to check
195195
thrust::complex<T> Ft(0, 0), J(0, iflag);
196196
for (int j = 0; j < M1; ++j)
197-
Ft += c1[j] * exp(J * (nt1 * x1[j] + nt2 * y1[j])); // crude direct
198-
int it = N1 / 2 + nt1 + N1 * (N2 / 2 + nt2); // index in complex F as 1d array
197+
Ft += c1[j] * thrust::exp(J * (nt1 * x1[j] + nt2 * y1[j])); // crude direct
198+
int it = N1 / 2 + nt1 + N1 * (N2 / 2 + nt2); // index in complex F as 1d array
199199

200200
printf("[gpu ] one mode: rel err in F[%d,%d] is %.3g (set 1)\n", (int)nt1, (int)nt2,
201-
std::abs(Ft - fk1[it]) / infnorm(N, (std::complex<T> *)fk1.data()));
201+
thrust::abs(Ft - fk1[it]) / infnorm(N, (std::complex<T> *)fk1.data()));
202202
Ft = thrust::complex<T>(0, 0);
203203
for (int j = 0; j < M2; ++j)
204-
Ft += c2[j] * exp(J * (nt1 * x2[j] + nt2 * y2[j])); // crude direct
204+
Ft += c2[j] * thrust::exp(J * (nt1 * x2[j] + nt2 * y2[j])); // crude direct
205205
printf("[gpu ] one mode: rel err in F[%d,%d] is %.3g (set 2)\n", (int)nt1, (int)nt2,
206-
std::abs(Ft - fk2[it]) / infnorm(N, (std::complex<T> *)fk2.data()));
206+
thrust::abs(Ft - fk2[it]) / infnorm(N, (std::complex<T> *)fk2.data()));
207207

208208
return 0;
209209
}

test/cuda/cufinufft2d_test.cu

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ int run_test(int method, int type, int N1, int N2, int M, T tol, T checktol, int
181181
const int nt2 = 0.26 * N2; // choose some mode index to check
182182
thrust::complex<T> Ft = thrust::complex<T>(0, 0), J = thrust::complex<T>(0.0, iflag);
183183
for (int j = 0; j < M; ++j)
184-
Ft += c[j] * exp(J * (nt1 * x[j] + nt2 * y[j])); // crude direct
185-
const int it = N1 / 2 + nt1 + N1 * (N2 / 2 + nt2); // index in complex F as 1d
186-
// array
187-
rel_error = std::abs(Ft - fk[it]) / infnorm(N1, (std::complex<T> *)fk.data());
184+
Ft += c[j] * thrust::exp(J * (nt1 * x[j] + nt2 * y[j])); // crude direct
185+
const int it = N1 / 2 + nt1 + N1 * (N2 / 2 + nt2); // index in complex F as 1d
186+
// array
187+
rel_error = thrust::abs(Ft - fk[it]) / infnorm(N1, (std::complex<T> *)fk.data());
188188
printf("[gpu ] one mode: rel err in F[%d,%d] is %.3g\n", nt1, nt2, rel_error);
189189
if (type == 1 && static_cast<int64_t>(M) * N1 * N2 <= TEST_BIGPROB) {
190190
std::vector<thrust::complex<T>> Ft(N1 * N2);
@@ -201,9 +201,9 @@ int run_test(int method, int type, int N1, int N2, int M, T tol, T checktol, int
201201
int m = 0;
202202
for (int m2 = -(N2 / 2); m2 <= (N2 - 1) / 2; ++m2) // loop in correct order over F
203203
for (int m1 = -(N1 / 2); m1 <= (N1 - 1) / 2; ++m1)
204-
ct += fk[m++] * exp(J * (m1 * x[jt] + m2 * y[jt])); // crude direct
204+
ct += fk[m++] * thrust::exp(J * (m1 * x[jt] + m2 * y[jt])); // crude direct
205205

206-
rel_error = std::abs(c[jt] - ct) / infnorm(M, (std::complex<T> *)c.data());
206+
rel_error = thrust::abs(c[jt] - ct) / infnorm(M, (std::complex<T> *)c.data());
207207
printf("[gpu ] one targ: rel err in c[%d] is %.3g\n", jt, rel_error);
208208
if (type == 2 && static_cast<int64_t>(M) * N1 * N2 <= TEST_BIGPROB) {
209209
std::vector<thrust::complex<T>> ct(M);
@@ -219,9 +219,9 @@ int run_test(int method, int type, int N1, int N2, int M, T tol, T checktol, int
219219
thrust::complex<T> Ft = thrust::complex<T>(0, 0);
220220

221221
for (int j = 0; j < M; ++j) {
222-
Ft += c[j] * exp(J * (x[j] * s[jt] + y[j] * t[jt]));
222+
Ft += c[j] * thrust::exp(J * (x[j] * s[jt] + y[j] * t[jt]));
223223
}
224-
rel_error = std::abs(Ft - fk[jt]) / infnorm(N1 * N2, (std::complex<T> *)fk.data());
224+
rel_error = thrust::abs(Ft - fk[jt]) / infnorm(N1 * N2, (std::complex<T> *)fk.data());
225225
printf("[gpu ] one mode: rel err in F[%d] is %.3g\n", jt, rel_error);
226226
if (type == 3 && static_cast<int64_t>(M) * N1 * N2 <= TEST_BIGPROB) {
227227
std::vector<thrust::complex<T>> Ft(N1 * N2);

test/cuda/cufinufft2dmany_test.cu

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ int run_test(int method, int type, int N1, int N2, int ntransf, int maxbatchsize
179179
// check
180180
thrust::complex<T> Ft = thrust::complex<T>(0, 0), J = thrust::complex<T>(0.0, iflag);
181181
for (int j = 0; j < M; ++j)
182-
Ft += c[j + i * M] * exp(J * (nt1 * x[j] + nt2 * y[j])); // crude direct
183-
int it = N1 / 2 + nt1 + N1 * (N2 / 2 + nt2); // index in complex F as 1d array
184-
rel_error =
185-
std::abs(Ft - fk[it + i * N]) / infnorm(N1, (std::complex<T> *)fk.data() + i * N);
182+
Ft += c[j + i * M] * thrust::exp(J * (nt1 * x[j] + nt2 * y[j])); // crude direct
183+
int it = N1 / 2 + nt1 + N1 * (N2 / 2 + nt2); // index in complex F as 1d array
184+
rel_error = thrust::abs(Ft - fk[it + i * N]) /
185+
infnorm(N1, (std::complex<T> *)fk.data() + i * N);
186186
printf("[gpu ] %dth data one mode: rel err in F[%d,%d] is %.3g\n", i, nt1, nt2,
187187
rel_error);
188188
} else if (type == 2) {
@@ -195,9 +195,9 @@ int run_test(int method, int type, int N1, int N2, int ntransf, int maxbatchsize
195195
int m = 0;
196196
for (int m2 = -(N2 / 2); m2 <= (N2 - 1) / 2; ++m2) // loop in correct order over F
197197
for (int m1 = -(N1 / 2); m1 <= (N1 - 1) / 2; ++m1)
198-
ct += fkstart[m++] * exp(J * (m1 * x[jt] + m2 * y[jt])); // crude direct
198+
ct += fkstart[m++] * thrust::exp(J * (m1 * x[jt] + m2 * y[jt])); // crude direct
199199

200-
rel_error = std::abs(cstart[jt] - ct) / infnorm(M, (std::complex<T> *)c.data());
200+
rel_error = thrust::abs(cstart[jt] - ct) / infnorm(M, (std::complex<T> *)c.data());
201201
printf("[gpu ] %dth data one targ: rel err in c[%d] is %.3g\n", t, jt, rel_error);
202202
} else if (type == 3) {
203203
int jt = (N1 * N2) / 2; // check arbitrary choice of one targ pt
@@ -207,10 +207,10 @@ int run_test(int method, int type, int N1, int N2, int ntransf, int maxbatchsize
207207
const thrust::complex<T> *cstart = c.data() + (ntransf - 1) * M;
208208

209209
for (int j = 0; j < M; ++j) {
210-
Ft += cstart[j] * exp(J * (x[j] * s[jt] + y[j] * t[jt]));
210+
Ft += cstart[j] * thrust::exp(J * (x[j] * s[jt] + y[j] * t[jt]));
211211
}
212212
rel_error =
213-
std::abs(Ft - fkstart[jt]) / infnorm(N1 * N2, (std::complex<T> *)fk.data());
213+
thrust::abs(Ft - fkstart[jt]) / infnorm(N1 * N2, (std::complex<T> *)fk.data());
214214
printf("[gpu ] one mode: rel err in F[%d] is %.3g\n", jt, rel_error);
215215
}
216216

test/cuda/cufinufft3d_test.cu

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,15 @@ int run_test(int method, int type, int N1, int N2, int N3, int M, T tol, T check
189189
nt3 = (int)(0.13 * N3); // choose some mode index to check
190190
thrust::complex<T> Ft = thrust::complex<T>(0, 0), J = thrust::complex<T>(0.0, iflag);
191191
for (int j = 0; j < M; ++j)
192-
Ft += c[j] * exp(J * (nt1 * x[j] + nt2 * y[j] + nt3 * z[j])); // crude direct
192+
Ft += c[j] * thrust::exp(J * (nt1 * x[j] + nt2 * y[j] + nt3 * z[j])); // crude
193+
// direct
193194

194195
int it = N1 / 2 + nt1 + N1 * (N2 / 2 + nt2) + N1 * N2 * (N3 / 2 + nt3); // index
195196
// in
196197
// complex
197198
// F as 1d
198199
// array
199-
rel_error = std::abs(Ft - fk[it]) / infnorm(N1, (std::complex<T> *)fk.data());
200+
rel_error = thrust::abs(Ft - fk[it]) / infnorm(N1, (std::complex<T> *)fk.data());
200201
printf("[gpu ] one mode: rel err in F[%d,%d,%d] is %.3g\n", nt1, nt2, nt3,
201202
rel_error);
202203
if (static_cast<int64_t>(M) * N1 * N2 * N3 <= TEST_BIGPROB) {
@@ -216,9 +217,11 @@ int run_test(int method, int type, int N1, int N2, int N3, int M, T tol, T check
216217
for (int m2 = -(N2 / 2); m2 <= (N2 - 1) / 2; ++m2) // loop in correct order
217218
// over F
218219
for (int m1 = -(N1 / 2); m1 <= (N1 - 1) / 2; ++m1)
219-
ct += fk[m++] * exp(J * (m1 * x[jt] + m2 * y[jt] + m3 * z[jt])); // crude direct
220+
ct +=
221+
fk[m++] * thrust::exp(J * (m1 * x[jt] + m2 * y[jt] + m3 * z[jt])); // crude
222+
// direct
220223

221-
rel_error = std::abs(c[jt] - ct) / infnorm(M, (std::complex<T> *)c.data());
224+
rel_error = thrust::abs(c[jt] - ct) / infnorm(M, (std::complex<T> *)c.data());
222225
printf("[gpu ] one targ: rel err in c[%ld] is %.3g\n", (int64_t)jt, rel_error);
223226
if (static_cast<int64_t>(M) * N1 * N2 * N3 <= TEST_BIGPROB) {
224227
std::vector<thrust::complex<T>> ct(M);
@@ -234,10 +237,10 @@ int run_test(int method, int type, int N1, int N2, int N3, int M, T tol, T check
234237
thrust::complex<T> Ft = thrust::complex<T>(0, 0);
235238

236239
for (int j = 0; j < M; ++j) {
237-
Ft += c[j] * exp(J * (x[j] * s[jt] + y[j] * t[jt] + z[j] * u[jt]));
240+
Ft += c[j] * thrust::exp(J * (x[j] * s[jt] + y[j] * t[jt] + z[j] * u[jt]));
238241
}
239242
rel_error =
240-
std::abs(Ft - fk[jt]) / infnorm(N1 * N2 * N3, (std::complex<T> *)fk.data());
243+
thrust::abs(Ft - fk[jt]) / infnorm(N1 * N2 * N3, (std::complex<T> *)fk.data());
241244
printf("[gpu ] one mode: rel err in F[%d] is %.3g\n", jt, rel_error);
242245
if (static_cast<int64_t>(M) * N1 * N2 * N3 <= TEST_BIGPROB) {
243246
std::vector<thrust::complex<T>> Ft(N1 * N2 * N3);

0 commit comments

Comments
 (0)