-
-
Notifications
You must be signed in to change notification settings - Fork 739
Fix dlang#10798 — Reimplement FFT solver to support @nogc nothrow pure @safe
#10799
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?
Conversation
Unlike `Fft`, this can be used in `@nogc` code.
Thanks for your pull request and interest in making D better, @Ogi-kun! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#10799" |
The type and the size of a lookup table is an implementation detail.
@nogc nothrow pure @safe
@jmdavis I kindly ask for a review. |
Honestly, this is not code or an algorithm that I'm particularly familiar with. So, I'm not necessarily well-suited to review it (and I don't know who would be out of those contributors who are currently active). However, at a glance, I can say that this design is somewhat questionable:
Also, as a general rule, I don't think that it's a great idea to be altering existing Phobos code to work with Regardless, this will need to be approved by @atilaneves, because it adds a new symbol. |
We have run into endless trouble every time we add attribute restrictions to Phobos. And this implementation seems brittle at best. This is a no vote for me. It's the kind of thing that would best be handled in a library with specific @nogc intentions. |
Thank you for your time! The algorithm was left untouched (almost), so the reviewer doesn’t need to know anything about signal processing. The only thing that changed about the algorithm is the way the lookup table is stored (2D array vs that dense triangular array thingy). This was done to avoid extra allocation.
Not being able to copy the object is a valid concern. Actually, I intended to use If you don’t care about auto fft = new FFT(1024); // `fft` is a copyable pointer Or, you can use recently introduced auto _fft = FFT(1024);
ref fft = _fft; // `fft` is a copyable reference
I have no idea what immutable members you’re talking about. struct FFT
{
immutable(lookup_t)* pStorage;
immutable(lookup_t)[] table;
} Mind the parentheses! The members themselves are mutable, so the struct mutable as well. No issues with assignment.
I see some issues the existing names:
The struct is not an alternative to the class, it’s a replacement. The class remains just for compatibility with existing code. Introduction of the new API presents an opportunity to fix naming. Or maybe it should be called |
This is absolutely not true. "Square root" and "absolute value" are not verbs, for example, but it would be ridiculous to name the functions that return them |
My design doesn’t impose any restrictions on the user. You’re want to use GC? By all means: unittest
{
enum size = 1024;
auto fft = new FFT(size);
auto data = new float[](size);
auto result = fft.compute(data);
} I can see where your concern is coming from but this is not the case where attributes are problematic.
Please elaborate.
The only downside of this implementation is that the solver is not copyable, and this is trivially solved. The upsides are better support for language features and a (slightly) better performance. This is not a different design with its own set of strengths and weaknesses, it’s an improvement over the original design. |
This is not a hard rule for functions in general but its more important for member functions. Noun makes it look like a property function, because that’s what the D Style guide recommends for properties. |
Does existing code in Phobos actually follow this rule? My impression is that |
Having both |
Property is any function that is intended to be used as if it was a variable or a field. It doesn’t have to be marked as
Farther documentation refers to functions with this attribute as “ |
I can mark its constructor as |
The fact that
Sure there is:
|
I believe that at some point in the feature (maybe in Phobos v3?) we will remove the old version and rename If the class was actually called
This requires DIP1000 to not be a potential disaster. Without
The same thing but with a struct will not compile, with or without
|
Yes.
Is that good name? No. Is it better than |
How about |
Fix #10798
FFT
. It either allocates a buffer for a lookup table usingmalloc
, or uses a preallocated buffer. In the former case, the buffer is freed upon destruction.FFT
is non-copyable.Fft
class now is just a wrapper aroundFFT
.FFT
instead ofFft
. In effect,fft(R, Ret)
andinverseFft(R, Ret)
can be used in@nogc
,nothrow
,pure
and@safe
code.Though the optimization of the algorithm itself was not the goal of this change, the new version performs slightly better on the larger FFT sizes. Using LDC2 with
-O -release
flags, on size=64FFT.compute
works about as fast as the oldFft.fft
, and on size=32768 it works 6-7 % faster. DMD shows similar results.