-
Notifications
You must be signed in to change notification settings - Fork 94
Fix 740 #742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix 740 #742
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,17 +4,13 @@ | |
|
|
||
| // specific to this example... | ||
| #include <cassert> | ||
| #include <math.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <cmath> | ||
| #include <cstdint> | ||
| #include <cstdio> | ||
| #include <cstdlib> | ||
| #include <vector> | ||
|
|
||
| // only good for small projects... | ||
| using namespace std; | ||
|
|
||
| static const double PI = 3.141592653589793238462643383279502884; | ||
| // allows 1i to be the imaginary unit... (C++14 onwards) | ||
| using namespace std::complex_literals; | ||
|
|
||
| int main(int argc, char *argv[]) | ||
| /* Example calling guru C++ interface to FINUFFT library, passing | ||
|
|
@@ -42,43 +38,47 @@ int main(int argc, char *argv[]) | |
| } else // or, NULL here means use default opts... | ||
| finufft_makeplan(type, dim, Ns, +1, ntransf, tol, &plan, NULL); | ||
|
|
||
| const std::complex<double> I(0.0, 1.0); | ||
|
|
||
| // generate some random nonuniform points | ||
| vector<double> x(M); | ||
| std::vector<double> x(M); | ||
| for (int j = 0; j < M; ++j) | ||
| x[j] = PI * (2 * ((double)rand() / RAND_MAX) - 1); // uniform random in [-pi,pi) | ||
| x[j] = PI * (2 * ((double)std::rand() / RAND_MAX) - 1); // uniform random in [-pi,pi) | ||
| // note FINUFFT doesn't use std::vector types, so we need to make a pointer... | ||
| finufft_setpts(plan, M, x.data(), NULL, NULL, 0, NULL, NULL, NULL); | ||
|
|
||
| // generate some complex strengths | ||
| vector<complex<double>> c(M); | ||
| std::vector<std::complex<double>> c(M); | ||
| for (int j = 0; j < M; ++j) | ||
| c[j] = | ||
| 2 * ((double)rand() / RAND_MAX) - 1 + 1i * (2 * ((double)rand() / RAND_MAX) - 1); | ||
| c[j] = 2 * ((double)std::rand() / RAND_MAX) - 1 + | ||
| std::complex<double>(0.0, 1.0) * | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use |
||
| (2 * ((double)std::rand() / RAND_MAX) - 1); | ||
|
|
||
| // alloc output array for the Fourier modes, then do the transform | ||
| vector<complex<double>> F(N); | ||
| std::vector<std::complex<double>> F(N); | ||
| int ier = finufft_execute(plan, c.data(), F.data()); | ||
|
|
||
| // for fun, do another with same NU pts (no re-sorting), but new strengths... | ||
| for (int j = 0; j < M; ++j) | ||
| c[j] = | ||
| 2 * ((double)rand() / RAND_MAX) - 1 + 1i * (2 * ((double)rand() / RAND_MAX) - 1); | ||
| c[j] = 2 * ((double)std::rand() / RAND_MAX) - 1 + | ||
| std::complex<double>(0.0, 1.0) * | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| (2 * ((double)std::rand() / RAND_MAX) - 1); | ||
| ier = finufft_execute(plan, c.data(), F.data()); | ||
|
|
||
| finufft_destroy(plan); // don't forget! done with transforms of this size | ||
|
|
||
| // rest is math checking and reporting... | ||
| int n = 142519; // check the answer just for this mode | ||
| assert(n >= -(double)N / 2 && n < (double)N / 2); // ensure meaningful test | ||
| complex<double> Ftest = complex<double>(0, 0); | ||
| for (int j = 0; j < M; ++j) Ftest += c[j] * exp(1i * (double)n * x[j]); | ||
| std::complex<double> Ftest(0, 0); | ||
| for (int j = 0; j < M; ++j) Ftest += c[j] * std::exp(I * (double)n * x[j]); | ||
| int nout = n + N / 2; // index in output array for freq mode n | ||
| double Fmax = 0.0; // compute inf norm of F | ||
| for (int m = 0; m < N; ++m) { | ||
| double aF = abs(F[m]); | ||
| double aF = std::abs(F[m]); | ||
| if (aF > Fmax) Fmax = aF; | ||
| } | ||
| double err = abs(F[nout] - Ftest) / Fmax; | ||
| double err = std::abs(F[nout] - Ftest) / Fmax; | ||
| printf("guru 1D type-1 double-prec NUFFT done. ier=%d, rel err in F[%d] is %.3g\n", ier, | ||
| n, err); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nullptr ? Surely it doesn't matter since setpts ignores them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed it. I'll fix it.