11# # This View checks for the index to be L1 or the mirrored version (L2)
22# and then replaces the value by half of the parent at L1
3+ # do_split is a Bool that indicates whether this mechanism is active. It is needed for type stability reasons of functions returnting this type
34struct FourierSplit{T,N, AA<: AbstractArray{T, N} } <: AbstractArray{T,N}
45 parent:: AA # holds the data (or is another view)
56 D:: Int # dimension along which to apply to copy
67 L1:: Int # low index position to copy from (and half)
78 L2:: Int # high index positon to copy to (and half)
9+ do_split:: Bool
810
911 # This version below is needed to avoid a split for the firs rft dimension but still return half the value
1012 # FFTs and other RFT dimension should use the version without L2
11- function FourierSplit (parent:: AA , D:: Int ,L1:: Int ,L2:: Int ) where {T,N, AA<: AbstractArray{T, N} }
12- return new {T,N, AA} (parent, D, L1, L2)
13+ function FourierSplit (parent:: AA , D:: Int ,L1:: Int ,L2:: Int , do_split :: Bool ) where {T,N, AA<: AbstractArray{T, N} }
14+ return new {T,N, AA} (parent, D, L1, L2, do_split )
1315 end
14- function FourierSplit (parent:: AA , D:: Int ,L1:: Int ) 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} }
1517 mid = fft_center (size (parent)[D])
1618 L2 = mid + (mid- L1)
17- return FourierSplit (parent, D,L1,L2)
19+ return FourierSplit (parent, D,L1,L2, do_split )
1820 end
1921end
2022
@@ -25,7 +27,7 @@ Base.parent(A::FourierSplit) = A.parent
2527Base. size (A:: FourierSplit ) = size (parent (A))
2628
2729@inline function Base. getindex (A:: FourierSplit{T,N, <:AbstractArray{T, N}} , i:: Vararg{Int,N} ) where {T,N}
28- if i[A. D]== A. L2 || i[A. D]== A. L1 # index along this dimension A.D corrsponds to slice L2
30+ if ( i[A. D]== A. L2 || i[A. D]== A. L1) && A . do_split # index along this dimension A.D corrsponds to slice L2
2931 # not that "setindex" in the line below modifies only the index, not the array
3032 @inbounds return parent (A)[Base. setindex (i,A. L1, A. D)... ] / 2
3133 else i[A. D]== A. L2
3638
3739# # This View checks for the index to be L1
3840# and then replaces the value by add the value at the mirrored position L2
41+ # do_join is a Bool that indicates whether this mechanism is active. It is needed for type stability reasons of functions returnting this type
3942struct FourierJoin{T,N, AA<: AbstractArray{T, N} } <: AbstractArray{T, N}
4043 parent:: AA
4144 D:: Int # dimension along which to apply to copy
4245 L1:: Int # low index position to copy from (and half)
4346 L2:: Int # high index positon to copy to (and half)
47+ do_join:: Bool
4448
4549 # This version below is needed to avoid a split for the firs rft dimension but still return half the value
4650 # FFTs and other RFT dimension should use the version without L2
47- function FourierJoin (parent:: AA , D:: Int , L1:: Int , L2:: Int ) where {T, N, AA<: AbstractArray{T, N} }
48- return new {T, N, AA} (parent, D, L1, L2)
51+ function FourierJoin (parent:: AA , D:: Int , L1:: Int , L2:: Int , do_join :: Bool ) where {T, N, AA<: AbstractArray{T, N} }
52+ return new {T, N, AA} (parent, D, L1, L2, do_join )
4953 end
5054
51- function FourierJoin (parent:: AA , D:: Int ,L1:: Int ) where {T, N, AA<: AbstractArray{T, N} }
55+ function FourierJoin (parent:: AA , D:: Int ,L1:: Int , do_join :: Bool ) where {T, N, AA<: AbstractArray{T, N} }
5256 mid = fft_center (size (parent)[D])
5357 L2 = mid + (mid- L1)
54- return FourierJoin (parent, D, L1, L2)
58+ return FourierJoin (parent, D, L1, L2, do_join )
5559 end
5660end
5761Base. IndexStyle (:: Type{FS} ) where {FS<: FourierJoin } = IndexStyle (parenttype (FS))
@@ -61,7 +65,7 @@ Base.parent(A::FourierJoin) = A.parent
6165Base. size (A:: FourierJoin ) = size (parent (A))
6266
6367@inline function Base. getindex (A:: FourierJoin{T,N, <:AbstractArray{T, N}} , i:: Vararg{Int,N} ) where {T,N}
64- if i[A. D]== A. L1
68+ if i[A. D]== A. L1 && A . do_join
6569 @inbounds return (parent (A)[i... ] + parent (A)[Base. setindex (i, A. L2, A. D)... ])
6670 else
6771 @inbounds return (parent (A)[i... ])
0 commit comments