API
Array types
ShiftedArrays.ShiftedArray — TypeShiftedArray(parent::AbstractArray, shifts, default)Custom AbstractArray object to store an AbstractArray parent shifted by shifts steps (where shifts is a Tuple with one shift value per dimension of parent). For s::ShiftedArray, s[i...] == s.parent[map(-, i, s.shifts)...] if map(-, i, s.shifts) is a valid index for s.parent, and s.v[i, ...] == default otherwise. Use copy to collect the values of a ShiftedArray into a normal Array. The recommended constructor is ShiftedArray(parent, shifts; default = missing).
If parent is itself a ShiftedArray with a compatible default value, the constructor does not nest ShiftedArray objects but rather combines the shifts additively.
Examples
julia> v = [1, 3, 5, 4];
julia> s = ShiftedArray(v, (1,))
4-element ShiftedVector{Int64, Missing, Vector{Int64}}:
missing
1
3
5
julia> v = [1, 3, 5, 4];
julia> s = ShiftedArray(v, (1,))
4-element ShiftedVector{Int64, Missing, Vector{Int64}}:
missing
1
3
5
julia> copy(s)
4-element Vector{Union{Missing, Int64}}:
missing
1
3
5
julia> v = reshape(1:16, 4, 4);
julia> s = ShiftedArray(v, (0, 2))
4×4 ShiftedArray{Int64, Missing, 2, Base.ReshapedArray{Int64, 2, UnitRange{Int64}, Tuple{}}}:
missing missing 1 5
missing missing 2 6
missing missing 3 7
missing missing 4 8
julia> shifts(s)
(0, 2)ShiftedArrays.ShiftedVector — TypeShiftedVector{T, S<:AbstractArray}Shorthand for ShiftedArray{T, 1, S}.
ShiftedArrays.CircShiftedArray — TypeCircShiftedArray(parent::AbstractArray, shifts)Custom AbstractArray object to store an AbstractArray parent circularly shifted by shifts steps (where shifts is a Tuple with one shift value per dimension of parent). Use copy to collect the values of a CircShiftedArray into a normal Array.
shift is modified with a modulo operation and does not store the passed value but instead a nonnegative number which leads to an equivalent shift.
If parent is itself a CircShiftedArray, the constructor does not nest CircShiftedArray objects but rather combines the shifts additively.
Examples
julia> v = [1, 3, 5, 4];
julia> s = CircShiftedArray(v, (1,))
4-element CircShiftedVector{Int64, Vector{Int64}}:
4
1
3
5
julia> copy(s)
4-element Vector{Int64}:
4
1
3
5ShiftedArrays.CircShiftedVector — TypeCircShiftedVector{T, S<:AbstractArray}Shorthand for CircShiftedArray{T, 1, S}.
Shifting operations
ShiftedArrays.lag — Functionlag(v::AbstractArray, n = 1; default = missing)Return a ShiftedArray object which lazily represents the array v shifted by n (an Integer or a Tuple of Integers). If the number of dimensions of v exceeds the length of n, the shift in the remaining dimensions is assumed to be 0. default specifies a default value to return when out of bounds in the original array.
Examples
julia> v = [1, 3, 5, 4];
julia> ShiftedArrays.lag(v)
4-element ShiftedVector{Int64, Missing, Vector{Int64}}:
missing
1
3
5
julia> w = 1:2:9
1:2:9
julia> s = ShiftedArrays.lag(w, 2)
5-element ShiftedVector{Int64, Missing, StepRange{Int64, Int64}}:
missing
missing
1
3
5
julia> copy(s)
5-element Vector{Union{Missing, Int64}}:
missing
missing
1
3
5
julia> v = reshape(1:16, 4, 4);
julia> s = ShiftedArrays.lag(v, (0, 2))
4×4 ShiftedArray{Int64, Missing, 2, Base.ReshapedArray{Int64, 2, UnitRange{Int64}, Tuple{}}}:
missing missing 1 5
missing missing 2 6
missing missing 3 7
missing missing 4 8ShiftedArrays.lead — Functionlead(v::AbstractArray, n = 1; default = missing)Return a ShiftedArray object which lazily represents the array v shifted negatively by n (an Integer or a Tuple of Integers). If the number of dimensions of v exceeds the length of n, the shift in the remaining dimensions is assumed to be 0. default specifies a default value to return when out of bounds in the original array.
Examples
julia> v = [1, 3, 5, 4];
julia> ShiftedArrays.lead(v)
4-element ShiftedVector{Int64, Missing, Vector{Int64}}:
3
5
4
missing
julia> w = 1:2:9
1:2:9
julia> s = ShiftedArrays.lead(w, 2)
5-element ShiftedVector{Int64, Missing, StepRange{Int64, Int64}}:
5
7
9
missing
missing
julia> copy(s)
5-element Vector{Union{Missing, Int64}}:
5
7
9
missing
missing
julia> v = reshape(1:16, 4, 4);
julia> s = ShiftedArrays.lead(v, (0, 2))
4×4 ShiftedArray{Int64, Missing, 2, Base.ReshapedArray{Int64, 2, UnitRange{Int64}, Tuple{}}}:
9 13 missing missing
10 14 missing missing
11 15 missing missing
12 16 missing missingShiftedArrays.circshift — Functioncircshift(v::AbstractArray, n)Return a CircShiftedArray object which lazily represents the array v shifted circularly by n (an Integer or a Tuple of Integers). If the number of dimensions of v exceeds the length of n, the shift in the remaining dimensions is assumed to be 0.
Examples
julia> v = [1, 3, 5, 4];
julia> ShiftedArrays.circshift(v, 1)
4-element CircShiftedVector{Int64, Vector{Int64}}:
4
1
3
5
julia> w = reshape(1:16, 4, 4);
julia> ShiftedArrays.circshift(w, (1, -1))
4×4 CircShiftedArray{Int64, 2, Base.ReshapedArray{Int64, 2, UnitRange{Int64}, Tuple{}}}:
8 12 16 4
5 9 13 1
6 10 14 2
7 11 15 3FFT shifts
ShiftedArrays.fftshift — Functionfftshift(x [, dims])Lazy version of AbstractFFTs.fftshift(x, dims). Return a CircShiftedArray where each given dimension is shifted by N÷2, where N is the size of that dimension.
Examples
julia> ShiftedArrays.fftshift([1 0 0 0])
1×4 CircShiftedArray{Int64, 2, Matrix{Int64}}:
0 0 1 0
julia> ShiftedArrays.fftshift([1 0 0; 0 0 0; 0 0 0])
3×3 CircShiftedArray{Int64, 2, Matrix{Int64}}:
0 0 0
0 1 0
0 0 0
julia> ShiftedArrays.fftshift([1 0 0; 0 0 0; 0 0 0], (1,))
3×3 CircShiftedArray{Int64, 2, Matrix{Int64}}:
0 0 0
1 0 0
0 0 0ShiftedArrays.ifftshift — Functionifftshift(x [, dims])Lazy version of AbstractFFTs.ifftshift(x, dims). Return a CircShiftedArray where each given dimension is shifted by -N÷2, where N is the size of that dimension.
Examples
julia> ShiftedArrays.ifftshift([0 0 1 0])
1×4 CircShiftedArray{Int64, 2, Matrix{Int64}}:
1 0 0 0
julia> ShiftedArrays.ifftshift([0 0 0; 0 1 0; 0 0 0])
3×3 CircShiftedArray{Int64, 2, Matrix{Int64}}:
1 0 0
0 0 0
0 0 0
julia> ShiftedArrays.ifftshift([0 1 0; 0 0 0; 0 0 0], (2,))
3×3 CircShiftedArray{Int64, 2, Matrix{Int64}}:
1 0 0
0 0 0
0 0 0Accessor functions
ShiftedArrays.shifts — Functionshifts(s::ShiftedArray)Return amount by which s is shifted compared to parent(s).
shifts(s::CircShiftedArray)Return amount by which s is shifted compared to parent(s).
ShiftedArrays.default — Functiondefault(s::ShiftedArray)Return default value.
Internals
ShiftedArrays.padded_tuple — Functionpadded_tuple(v::AbstractVector, s)Internal function used to compute shifts. Return a Tuple with as many element as the dimensions of v. The first length(s) entries are filled with values from s, the remaining entries are 0. s should be an integer, in which case length(s) == 1, or a container of integers with keys 1:length(s).
Examples
julia> ShiftedArrays.padded_tuple(rand(10, 10), 3)
(3, 0)
julia> ShiftedArrays.padded_tuple(rand(10, 10), (4,))
(4, 0)
julia> ShiftedArrays.padded_tuple(rand(10, 10), (1, 5))
(1, 5)ShiftedArrays.ft_center_diff — Functionft_center_diff(s [, dims])Return the shifts required to center dimensions dims at the respective Fourier centers. This function is internally used by ShiftedArrays.fftshift and ShiftedArrays.ifftshift.
Examples
julia> ShiftedArrays.ft_center_diff((4, 5, 6), (1, 2)) # Fourier center is at (2, 3, 0)
(2, 2, 0)
julia> ShiftedArrays.ft_center_diff((4, 5, 6), (1, 2, 3)) # Fourier center is at (2, 3, 4)
(2, 2, 3)