Skip to content
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

change 1:ndims(X) to ntuple(identity, ndims(X)) #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ _to1(::Tuple, x) = copy1(eltype(x), x)
for f in (:fft, :bfft, :ifft, :fft!, :bfft!, :ifft!, :rfft)
pf = Symbol("plan_", f)
@eval begin
$f(x::AbstractArray) = $f(x, 1:ndims(x))
$f(x::AbstractArray) = $f(x, ntuple(identity, ndims(x)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just use

Suggested change
$f(x::AbstractArray) = $f(x, ntuple(identity, ndims(x)))
$f(x::AbstractArray) = $f(x, Base.OneTo(ndims(x)))

? Maybe that already fixes constant propagation? It would be less breaking (I think) and should also be more efficient if ndims(x) is large.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this necessarily fixes the issue without the compiler propagating ndims(x) as a constant.

Regarding large ndims, IIUC Tuples are performant till a length of 32, and it's uncommon to have arrays with that many dimensions. In any case, this could be an optimization for ndims(x)<4, which is perhaps the common case.

I fully understand and sympathize with your concern about breakages. I'll see if the direct dependants can be fixed first so that they accept arbitrary regions, before this is considered

$f(x::AbstractArray, region) = (y = to1(x); $pf(y, region) * y)
$pf(x::AbstractArray; kws...) = (y = to1(x); $pf(y, 1:ndims(y); kws...))
end
Expand Down Expand Up @@ -213,7 +213,7 @@ for f in (:fft, :bfft, :ifft)
$pf(x::AbstractArray{<:Complex{<:Union{Integer,Rational}}}, region; kws...) = $pf(complexfloat(x), region; kws...)
end
end
rfft(x::AbstractArray{<:Union{Integer,Rational}}, region=1:ndims(x)) = rfft(realfloat(x), region)
rfft(x::AbstractArray{<:Union{Integer,Rational}}, region=ntuple(identity, ndims(x))) = rfft(realfloat(x), region)
plan_rfft(x::AbstractArray, region; kws...) = plan_rfft(realfloat(x), region; kws...)

# only require implementation to provide *(::Plan{T}, ::Array{T})
Expand Down Expand Up @@ -297,9 +297,9 @@ LinearAlgebra.mul!(y::AbstractArray, p::ScaledPlan, x::AbstractArray) =
for f in (:brfft, :irfft)
pf = Symbol("plan_", f)
@eval begin
$f(x::AbstractArray, d::Integer) = $f(x, d, 1:ndims(x))
$f(x::AbstractArray, d::Integer) = $f(x, d, ntuple(identity, ndims(x)))
$f(x::AbstractArray, d::Integer, region) = $pf(x, d, region) * x
$pf(x::AbstractArray, d::Integer;kws...) = $pf(x, d, 1:ndims(x);kws...)
$pf(x::AbstractArray, d::Integer;kws...) = $pf(x, d, ntuple(identity, ndims(x));kws...)
end
end

Expand Down Expand Up @@ -388,7 +388,7 @@ The output of `fftshift` is allocated. If one desires to store the output in a p
"""
fftshift

fftshift(x, dim = 1:ndims(x)) = fftshift!(similar(x), x, dim)
fftshift(x, dim = ntuple(identity, ndims(x))) = fftshift!(similar(x), x, dim)

"""
ifftshift!(dest, src, [dim])
Expand Down Expand Up @@ -417,7 +417,7 @@ The output of `ifftshift` is allocated. If one desires to store the output in a
"""
ifftshift

ifftshift(x, dim = 1:ndims(x)) = ifftshift!(similar(x), x, dim)
ifftshift(x, dim = ntuple(identity, ndims(x))) = ifftshift!(similar(x), x, dim)

##############################################################################

Expand Down