Skip to content

Commit e05a515

Browse files
fixed @report_opt complaint by introducing a recursive type
1 parent ab56491 commit e05a515

File tree

2 files changed

+49
-20
lines changed

2 files changed

+49
-20
lines changed

src/custom_fourier_types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct FourierSplit{T,N, AA<:AbstractArray{T, N}} <: AbstractArray{T,N}
1313
function FourierSplit(parent::AA, D::Int,L1::Int,L2::Int, do_split::Bool) where {T,N, AA<:AbstractArray{T, N}}
1414
return new{T,N, AA}(parent, D, L1, L2, do_split)
1515
end
16-
function FourierSplit(parent::AA, D::Int,L1::Int, do_split::Bool) where {T,N, AA<:AbstractArray{T, N}}
16+
function FourierSplit(parent::AA, D::Int, L1::Int, do_split::Bool) where {T,N, AA<:AbstractArray{T, N}}
1717
mid = fft_center(size(parent)[D])
1818
L2 = mid + (mid-L1)
1919
return FourierSplit(parent, D,L1,L2, do_split)

src/fourier_resizing.jl

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,29 +138,58 @@ function rft_pad(mat, new_size)
138138
return select_region(mat;new_size=new_size, center=c2.+1)
139139
end
140140

141-
function ft_fix_before(mat::AbstractArray{T, N}, size_old, size_new; start_dim=1)::FourierJoin{T,N,AbstractArray{T, N}} where {T,N}
142-
for d = start_dim:ndims(mat)
143-
sn = size_new[d]
144-
so = size_old[d]
141+
"""
142+
ft_fix_before(mat::MT, size_old, size_new, ::Val{N})::FourierJoin{T,N,MT} where {T,N, MT<:AbstractArray{T,N}}
143+
implements the specialized (highest dimension) version of a recursive dimension-specific function that returns an array type which knows
144+
how to access (joins) certain elements.
145+
"""
146+
function ft_fix_before(mat::MT, size_old, size_new, ::Val{N})::FourierJoin{T,N,MT} where {T,N, MT<:AbstractArray{T,N}}
147+
sn = size_new[N]
148+
so = size_old[N]
149+
do_join = (sn < so && iseven(sn))
150+
L1 = (size_old[N] -size_new[N] )÷2 +1
151+
return FourierJoin(mat, N, L1, do_join)
152+
end
153+
154+
"""
155+
ft_fix_before(mat::MT, size_old, size_new, ::Val{D}=Val(1)) where {D, T, N, MT<:AbstractArray{T,N}}
156+
implements the general version of a recursive dimension-specific function that returns an array type which knows
157+
how to access (joins) certain elements.
158+
"""
159+
function ft_fix_before(mat::MT, size_old, size_new, ::Val{D}=Val(1)) where {D, T, N, MT<:AbstractArray{T,N}}
160+
if D <= N
161+
sn = size_new[D]
162+
so = size_old[D]
145163
do_join = (sn < so && iseven(sn))
146-
L1 = (size_old[d] -size_new[d] )÷2 +1
147-
mat = FourierJoin(mat, d, L1, do_join)
164+
L1 = (size_old[D] -size_new[D] )÷2 +1
165+
mat = FourierJoin(mat, D, L1, do_join)
166+
return ft_fix_before(mat, size_old, size_new, Val(D + 1))
167+
else
168+
L1 = (size_old[N] -size_new[N] )÷2 +1
169+
return FourierJoin(mat, N, L1, false)
148170
end
149-
return mat
150171
end
151172

152-
function ft_fix_after(mat::AbstractArray{T, N},size_old,size_new; start_dim=1)::FourierSplit{T,N,AbstractArray{T, N}} where {T,N}
153-
start_dim
154-
ndims(mat)
155-
for d=start_dim:ndims(mat)
156-
sn = size_new[d]
157-
so = size_old[d]
158-
# if equal do nothing
173+
function ft_fix_after(mat::MT, size_old, size_new, ::Val{N})::FourierSplit{T,N,MT} where {T, N, MT<:AbstractArray{T,N}}
174+
sn = size_new[N]
175+
so = size_old[N]
176+
do_split = (sn > so && iseven(so))
177+
L1 = (size_new[N]-size_old[N])÷2+1
178+
return FourierSplit(mat, N, L1, do_split)
179+
end
180+
181+
function ft_fix_after(mat::MT, size_old, size_new, ::Val{D}=Val(1)) where {D, T, N, MT<:AbstractArray{T,N}}
182+
if D <= N
183+
sn = size_new[D]
184+
so = size_old[D]
159185
do_split = (sn > so && iseven(so))
160-
L1 = (size_new[d]-size_old[d])÷2+1
161-
mat = FourierSplit(mat,d,L1, do_split)
186+
L1 = (size_new[D]-size_old[D])÷2+1
187+
mat = FourierSplit(mat, D, L1, do_split)
188+
return ft_fix_after(mat, size_old, size_new, Val(D + 1))
189+
else
190+
L1 = (size_new[N]-size_old[N])÷2+1
191+
return FourierSplit(mat, N, L1, false)
162192
end
163-
return mat
164193
end
165194

166195
function rft_fix_first_dim_before(mat,size_old,size_new;dim=1)
@@ -184,10 +213,10 @@ end
184213

185214
function rft_fix_before(mat,size_old,size_new)
186215
mat=rft_fix_first_dim_before(mat,size_old,size_new;dim=1) # ignore the first dimension
187-
ft_fix_before(mat,size_old,size_new;start_dim=2) # ignore the first dimension
216+
ft_fix_before(mat,size_old,size_new, Val(2)) # ignore the first dimension since it starts at Val(2)
188217
end
189218

190219
function rft_fix_after(mat,size_old,size_new)
191220
mat = rft_fix_first_dim_after(mat,size_old,size_new;dim=1) # ignore the first dimension
192-
ft_fix_after(mat,size_old,size_new;start_dim=2) # ignore the first dimension
221+
ft_fix_after(mat,size_old,size_new, Val(2)) # ignore the first dimension since it starts at Val(2)
193222
end

0 commit comments

Comments
 (0)