@@ -16,16 +16,17 @@ There is also `shear!` available.
1616+ `fix_nyquist`: apply a fix to the highest frequency during the Fourier-space application of the exponential factor
1717+ `adapt_size`: if true, pad the data prior to the shear. The result array will be larger
1818+ `pad_value`: the value to pad with (only applies if `adapt_size=true`)
19+ + `assign_wrap=assign_wrap`: replaces wrap-around areas by `pad_value` (only of `adapt_size` is `false`)
1920
2021For complex arrays we use `fft`, for real array we use `rfft`.
2122"""
22- function shear (arr:: AbstractArray , Δ, shear_dir_dim= 1 , shear_dim= 2 ; fix_nyquist= false , adapt_size= false :: Bool , pad_value= zero (eltype (arr)))
23+ function shear (arr:: AbstractArray , Δ, shear_dir_dim= 1 , shear_dim= 2 ; fix_nyquist= false , assign_wrap = false , adapt_size= false :: Bool , pad_value= zero (eltype (arr)))
2324 if adapt_size
2425 ns = Tuple (d == shear_dir_dim ? size (arr,d)+ ceil (Int,abs .(Δ)) : size (arr,d) for d in 1 : ndims (arr))
2526 arr2 = collect (select_region (arr, new_size= ns, pad_value= pad_value))
2627 return shear! (arr2, Δ, shear_dir_dim, shear_dim, fix_nyquist= fix_nyquist)
2728 else
28- return shear! (copy (arr), Δ, shear_dir_dim, shear_dim, fix_nyquist= fix_nyquist)
29+ return shear! (copy (arr), Δ, shear_dir_dim, shear_dim, fix_nyquist= fix_nyquist, assign_wrap = assign_wrap, pad_value = pad_value )
2930 end
3031end
3132
@@ -40,11 +41,14 @@ For more details see `shear.`
4041For complex arrays we can completely avoid large memory allocations.
4142For real arrays, we need at least allocate on array in the fourier space.
4243"""
43- function shear! (arr:: AbstractArray{<:Complex, N} , Δ, shear_dir_dim= 1 , shear_dim= 2 ; fix_nyquist= false , assign_wrap= false , pad_value= zero (eltype (arr))) where N
44+ function shear! (arr:: TA , Δ, shear_dir_dim= 1 , shear_dim= 2 ; fix_nyquist= false , assign_wrap= false , pad_value= zero (eltype (arr))) where {N, TA <: AbstractArray{<:Complex, N} }
4445 fft! (arr, shear_dir_dim)
4546
4647 # stores the maximum amount of shift
47- shift = reshape (fftfreq (size (arr, shear_dir_dim)), NDTools. select_sizes (arr, shear_dir_dim))
48+ # TR = real_arr_type(TA)
49+ shift = similar (arr, real (eltype (arr)), select_sizes (arr, shear_dir_dim))
50+ shift .= reshape (fftfreq (size (arr, shear_dir_dim)), NDTools. select_sizes (arr, shear_dir_dim))
51+ # shift = TR(reorient(fftfreq(size(arr, shear_dir_dim)), shear_dir_dim, Val(N)))
4852
4953 apply_shift_strength! (arr, arr, shift, shear_dir_dim, shear_dim, Δ, fix_nyquist)
5054
@@ -56,16 +60,19 @@ function shear!(arr::AbstractArray{<:Complex, N}, Δ, shear_dir_dim=1, shear_dim
5660 return arr
5761end
5862
59- function shear! (arr:: AbstractArray{<:Real, N} , Δ, shear_dir_dim= 1 , shear_dim= 2 ; fix_nyquist= false , assign_wrap= false , pad_value= zero (eltype (arr))) where N
63+ function shear! (arr:: TA , Δ, shear_dir_dim= 1 , shear_dim= 2 ; fix_nyquist= false , assign_wrap= false , pad_value= zero (eltype (arr))) where {N, TA <: AbstractArray{<:Real, N} }
6064 p = plan_rfft (arr, shear_dir_dim)
6165 arr_ft = p * arr
6266
6367 # stores the maximum amount of shift
64- shift = reshape (rfftfreq (size (arr, shear_dir_dim)), NDTools. select_sizes (arr_ft, shear_dir_dim))
68+ # TR = real_arr_type(TA)
69+ shift = similar (arr, real (eltype (arr_ft)), select_sizes (arr_ft, shear_dir_dim))
70+ shift .= reshape (rfftfreq (size (arr, shear_dir_dim)), NDTools. select_sizes (arr_ft, shear_dir_dim))
71+ # shift = TR(reorient(rfftfreq(size(arr, shear_dir_dim)),shear_dir_dim, Val(N)))
6572
6673 apply_shift_strength! (arr_ft, arr, shift, shear_dir_dim, shear_dim, Δ, fix_nyquist)
6774 # go back to real space
68-
75+
6976 # overwrites arr in-place
7077 ldiv! (arr, p, arr_ft)
7178 if assign_wrap
@@ -103,10 +110,12 @@ function assign_shear_wrap!(arr, Δ, shear_dir_dim=1, shear_dim=2, pad_value=zer
103110 end
104111end
105112
106- function apply_shift_strength! (arr, arr_orig, shift, shear_dir_dim, shear_dim, Δ, fix_nyquist= false )
113+ function apply_shift_strength! (arr:: TA , arr_orig, shift, shear_dir_dim, shear_dim, Δ, fix_nyquist= false ) where {T, N, TA <: AbstractArray{T, N} }
107114 # applies the strength to each slice
108- shift_strength = reshape (fftpos (1 , size (arr, shear_dim), CenterFT), NDTools. select_sizes (arr, shear_dim))
109-
115+ # The TR trick does not seem to work for the code below due to a call with a PaddedArray.
116+ shift_strength = similar (arr, real (eltype (arr)), select_sizes (arr, shear_dim))
117+ shift_strength .= (real (eltype (TA))). (reorient (fftpos (1 , size (arr, shear_dim), CenterFT), shear_dim, Val (N)))
118+
110119 # do the exp multiplication in place
111120 e = cispi .(2 .* Δ .* shift .* shift_strength)
112121 # for even arrays we need to fix real property of highest frequency
0 commit comments