@@ -138,29 +138,58 @@ function rft_pad(mat, new_size)
138138 return select_region (mat;new_size= new_size, center= c2.+ 1 )
139139end
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
150171end
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
164193end
165194
166195function rft_fix_first_dim_before (mat,size_old,size_new;dim= 1 )
@@ -184,10 +213,10 @@ end
184213
185214function 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)
188217end
189218
190219function 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)
193222end
0 commit comments