@@ -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,13 @@ 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 = TR(reshape(fftfreq(size(arr, shear_dir_dim)), NDTools.select_sizes(arr, shear_dir_dim)))
50+ shift = TR (reorient (fftfreq (size (arr, shear_dir_dim)),shear_dir_dim, Val (N)))
4851
4952 apply_shift_strength! (arr, arr, shift, shear_dir_dim, shear_dim, Δ, fix_nyquist)
5053
@@ -56,12 +59,14 @@ function shear!(arr::AbstractArray{<:Complex, N}, Δ, shear_dir_dim=1, shear_dim
5659 return arr
5760end
5861
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
62+ 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} }
6063 p = plan_rfft (arr, shear_dir_dim)
6164 arr_ft = p * arr
6265
6366 # stores the maximum amount of shift
64- shift = reshape (rfftfreq (size (arr, shear_dir_dim)), NDTools. select_sizes (arr_ft, shear_dir_dim))
67+ TR = real_arr_type (TA)
68+ # shift = TR(reshape(rfftfreq(size(arr, shear_dir_dim)), NDTools.select_sizes(arr_ft, shear_dir_dim)))
69+ shift = TR (reorient (rfftfreq (size (arr, shear_dir_dim)),shear_dir_dim, Val (N)))
6570
6671 apply_shift_strength! (arr_ft, arr, shift, shear_dir_dim, shear_dim, Δ, fix_nyquist)
6772 # go back to real space
@@ -103,10 +108,12 @@ function assign_shear_wrap!(arr, Δ, shear_dir_dim=1, shear_dim=2, pad_value=zer
103108 end
104109end
105110
106- function apply_shift_strength! (arr, arr_orig, shift, shear_dir_dim, shear_dim, Δ, fix_nyquist= false )
111+ function apply_shift_strength! (arr:: TA , arr_orig, shift, shear_dir_dim, shear_dim, Δ, fix_nyquist= false ) where {T, N, TA <: AbstractArray{T, N} }
107112 # applies the strength to each slice
108- shift_strength = reshape (fftpos (1 , size (arr, shear_dim), CenterFT), NDTools. select_sizes (arr, shear_dim))
109-
113+ # shift_strength = reshape(fftpos(1, size(arr, shear_dim), CenterFT), NDTools.select_sizes(arr, shear_dim))
114+ # TR = real_arr_type(typeof(collect(arr[1:1]))) # There is a problem with circshifted arrays and this way of finding the type.
115+ shift_strength = reorient (fftpos (1 , size (arr, shear_dim), CenterFT), shear_dim, Val (N))
116+
110117 # do the exp multiplication in place
111118 e = cispi .(2 .* Δ .* shift .* shift_strength)
112119 # for even arrays we need to fix real property of highest frequency
0 commit comments