ManyPencilArraysRFFT!: avoid inefficient view + reshape #75
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
I propose a minor update of
multiarrays_r2c.jl
to fix two issues for the use of the view to the first (real valued)PencilArray
of theManyPencilArraysRFFT!
.Since the input real valued array of a
RFFT
uses less memory than the complex output, the inplaceRFFT!
requires that the view to the real valued array is reshaped from a vector SubArrayvec
of some larger vectordata
. This was previously done usingvec = view(data, Base.OneTo(n))
.However
reshape(vec, dims)
outputs aBase.ReshapedArray{T, N, SubArray{T, 1, Vector{T}, Tuple{UnitRange{Int64}}, true}, Tuple{}}
, for which the compiler may produce inefficient code.The proposed alternative is to use
vec = unsafe_wrap(typeof(data), pointer(data), n)
, after whichreshape(vec, dims)
outputs a simpleArray{T,N}
.This fixes:
PencilArray
view of theManyPencilArraysRFFT!
PencilArray
view usingPencilArrays.PencilIO
The same idea could be used in function
_make_arrays
ofmultiarrays.jl
ofPencilArrays
, line 137:vec = view(data, Base.OneTo(n))
.