Some Utility Functions
FourierTools.δ — Functionδ([T,] sz, pos=FourierTools.fft_center.(sz))Return an array which has 1 at pos in the array of size sz.
Examples
julia> δ((3, 3))
3×3 Matrix{Int64}:
0 0 0
0 1 0
0 0 0
julia> δ(Float32, (4, 3))
4×3 Matrix{Float32}:
0.0 0.0 0.0
0.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 0.0
julia> δ(Float32, (3, 3), (1,1))
3×3 Matrix{Float32}:
1.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0FourierTools.center_set! — Functioncenter_set!(arr_large, arr_small)Puts the arr_small central into arr_large. The convention, where the center is, is the same as the definition as for FFT based centered. Function works both for even and uneven arrays.
Examples
julia> FourierTools.center_set!([1, 1, 1, 1, 1, 1], [5, 5, 5])
6-element Array{Int64,1}:
1
1
5
5
5
1FourierTools.get_indices_around_center — Functionget_indices_around_center(i_in, i_out)A function which provides two output indices i1 and i2 where i2 - i1 = i_out The indices are chosen in a way that the set i1:i2 cuts the interval 1:i_in in a way that the center frequency stays at the center position. Works for both odd and even indices
FourierTools.center_extract — Functioncenter_extract(arr, new_size_array)Extracts a center of an array. new_size_array must be list of sizes indicating the output size of each dimension. Centered means that a center frequency stays at the center position. Works for even and uneven. If length(new_size_array) < length(ndims(arr)) the remaining dimensions are untouched and copied.
Examples
julia> FourierTools.center_extract([1 2; 3 4], [1])
1×2 view(::Matrix{Int64}, 2:2, 1:2) with eltype Int64:
3 4
julia> FourierTools.center_extract([1 2; 3 4], [1, 1])
1×1 view(::Matrix{Int64}, 2:2, 2:2) with eltype Int64:
4
julia> FourierTools.center_extract([1 2 3; 3 4 5; 6 7 8], [2 2])
2×2 view(::Matrix{Int64}, 1:2, 1:2) with eltype Int64:
1 2
3 4FourierTools.selectsizes — Functionselectsizes(x, dism; keep_dims=true)Select the sizes of x for all dims If keep_dims=true the non-selected dimensions are returned as 1.
Examples
julia> FourierTools.selectsizes(randn((4,3,2)), (2,3))
(1, 3, 2)
julia> FourierTools.selectsizes(randn((4,3,2)), (2,3), keep_dims=false)
(3, 2)FourierTools.expanddims — Functionexpanddims(x, ::Val{N})expands the dimensions of an array to a given number of dimensions:
Examples
The result is a 5D array with singleton dimensions at the end
julia> expanddims(ones((1,2,3)), 5)
1×2×3×1×1 Array{Float64, 5}:
[:, :, 1, 1, 1] =
1.0 1.0
[:, :, 2, 1, 1] =
1.0 1.0
[:, :, 3, 1, 1] =
1.0 1.0FourierTools.slice — Functionslice(arr, dim, index)Return a N dimensional slice (where one dimensions has size 1) of the N-dimensional arr at the index position index in the dim dimension of the array. It holds size(out)[dim] == 1.
Examples
julia> x = [1 2 3; 4 5 6; 7 8 9]
3×3 Matrix{Int64}:
1 2 3
4 5 6
7 8 9
julia> FourierTools.slice(x, 1, 1)
1×3 view(::Matrix{Int64}, 1:1, 1:3) with eltype Int64:
1 2 3FourierTools.slice_indices — Functionslice_indices(a, dim, index)a should be the axes obtained by axes(arr) of an array. dim is the dimension to be selected and index the index of it.
Examples
julia> FourierTools.slice_indices((1:10, 1:20, 1:12, 1:33), 1, 3)
(3:3, 1:20, 1:12, 1:33)