Conversation
devmotion
left a comment
There was a problem hiding this comment.
I'm in favor of this change. I think this is a better approach than #117 since users and downstream dependencies such as plotting packages would not have to choose an FFT backend, so this PR would not affect their workflow/implementation.
I'm using KernelDensity mostly indirectly in plotting packages, and there the performance regression for small arrays is not relevant. I wonder if there are applications/downstream packages for which it could matter?
Since FFTA is not as mature as eg. FFTW yet - can we expect any further performance improvements in the future?
There are several improvements in the pipeline. The real FFT can be made faster, see JuliaMath/FFTA.jl#98, which I have now updated the PR with. See the timings for the 1D case which are now faster than FFTW. Once there is a new release of FFTA, I'll suggest that we move forward with this one. Then I'll promise to have the (less common) 2D case ready before too long. |
c5929e3 to
6a48e74
Compare
src/bivariate.jl
Outdated
| # Transform to Fourier basis | ||
| Kx, Ky = size(k.density) | ||
| ft = rfft(k.density) | ||
| ft::Matrix{Complex{Float64}} = rfft(k.density) |
There was a problem hiding this comment.
Is the conversion needed? Does it fix a type inference problem?
There was a problem hiding this comment.
See JuliaMath/FFTA.jl#78. It is caused by AbstractFFTs.
There was a problem hiding this comment.
I see now that k.density is hardcoded to Matrix{Float64} (and similarly to Vector{Float64} in the univariate case below). Initially, I was worried that this change could lead to different return types and additional allocations.
Could we avoid the need for the explicit Matrix conversion by specifying the region explicitly or using an in-place method?
Alternatively, I think we should change the conversion to a type assertion to make it clear that there are no additional allocations or type changes here and to avoid silently introducing those in case we generalize the type of k.density at some point.
There was a problem hiding this comment.
Could we avoid the need for the explicit Matrix conversion by specifying the region explicitly or using an in-place method?
Possibly, but with the current hard-coding of k.density, I think a type assert is the simplest solution (I've updated the PR). I hope that the inference issue will be fixed upstream, at which point the type assertion can just be removed.
This change adds support for more element types and drops a binary GPL dependency. For small problems, there is a minor slowdown, but it goes away for slightly larger problems where the processing between the ffts start dominating.
This drops a binary GPL dependency while potentially adds support for more element types as FFTA is a generic, but still quite fast, FFT implementation in Julia. For small problems, there is a minor slowdown, but it goes away for slightly larger problems where the processing between the ffts starts dominating.
Closes #123
Timings