API
Array types
MutableShiftedArrays.MutableShiftedArray — Type
MutableShiftedArray(parent::AbstractArray, shifts = (), viewsize=size(v); default = zero(eltype(parent)))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). As opposed to ShiftedArray of the ShiftedArrays.jl toolbox, this object is mutable and mutation operations in the padded ranges are ignored. Furthermore it also supports size changes in the view.
For s::MutableShiftedArray, 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 MutableShiftedArray into a normal Array. The recommended constructor is MutableShiftedArray(parent, shifts; default = missing).
If parent is itself a MutableShiftedArray with a compatible default value, the constructor does not nest MutableShiftedArray objects but rather combines the shifts additively.
Arguments
parent::AbstractArray: the array to be shiftedshifts::Tuple{Int}: the amount by whichparentis shifted in each dimension. The default, an empty Tuple will result in no shifts.viewsize::Tuple{Int}: the size of the view. By default the size of the parent array is used.default::M: the default value to return when out of bounds in the original array. By default zero of the correspondingeltypeis used. Note that usingmissingas default value will cause single index accesses in CUDA due to the Union type.
Examples
julia> v = [1, 3, 5, 4];
julia> s = MutableShiftedArray(v, (1,))
4-element MutableShiftedVector{Int64, Int64, Vector{Int64}}:
0
1
3
5
julia> copy(s)
4-element Vector{Int64}:
0
1
3
5
julia> v = reshape(1:16, 4, 4);
julia> s = MutableShiftedArray(v, (0, 2), default=missing)
4×4 MutableShiftedArray{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)MutableShiftedArrays.MutableShiftedVector — Type
MutableShiftedVector{T, S<:AbstractArray}Shorthand for MutableShiftedArray{T, 1, S}.
MutableShiftedArrays.CircShiftedArray — Type
CircShiftedArray(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
5MutableShiftedArrays.CircShiftedVector — Type
CircShiftedVector{T, S<:AbstractArray}Shorthand for CircShiftedArray{T, 1, S}.
Shifting operations
MutableShiftedArrays.lag — Function
lag(v::AbstractArray, n = 1, viewsize=size(v); default=zero(eltype(v)))Return a MutableShiftedArray 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> MutableShiftedArrays.lag(v, default=missing)
4-element MutableShiftedVector{Int64, Missing, Vector{Int64}}:
missing
1
3
5
julia> w = 1:2:9
1:2:9
julia> s = MutableShiftedArrays.lag(w, 2, default=missing)
5-element MutableShiftedVector{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 = MutableShiftedArrays.lag(v, (0, 2), default=missing)
4×4 MutableShiftedArray{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 8MutableShiftedArrays.lead — Function
lead(v::AbstractArray, n = 1, viewsize=size(v); default=zero(eltype(v)))Return a MutableShiftedArray 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> MutableShiftedArrays.lead(v, default=missing)
4-element MutableShiftedVector{Int64, Missing, Vector{Int64}}:
3
5
4
missing
julia> w = 1:2:9
1:2:9
julia> s = MutableShiftedArrays.lead(w, 2, default=missing)
5-element MutableShiftedVector{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 = MutableShiftedArrays.lead(v, (0, 2), default=missing)
4×4 MutableShiftedArray{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 missingMutableShiftedArrays.fftshift — Function
fftshift(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> MutableShiftedArrays.fftshift([1 0 0 0])
1×4 CircShiftedArray{Int64, 2, Matrix{Int64}}:
0 0 1 0
julia> MutableShiftedArrays.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> MutableShiftedArrays.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 0MutableShiftedArrays.ifftshift — Function
ifftshift(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> MutableShiftedArrays.ifftshift([0 0 1 0])
1×4 CircShiftedArray{Int64, 2, Matrix{Int64}}:
1 0 0 0
julia> MutableShiftedArrays.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> MutableShiftedArrays.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 0MutableShiftedArrays.circshift — Function
circshift(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> MutableShiftedArrays.circshift(v, 1)
4-element CircShiftedVector{Int64, Vector{Int64}}:
4
1
3
5
julia> w = reshape(1:16, 4, 4);
julia> MutableShiftedArrays.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 3Accessor functions
MutableShiftedArrays.shifts — Function
shifts(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).
MutableShiftedArrays.default — Function
default(s::MutableShiftedArray)Return default value.
MutableShiftedArrays.ft_center_diff — Function
ft_center_diff(s [, dims])Return the shifts required to center dimensions dims at the respective Fourier centers. This function is internally used by MutableShiftedArrays.fftshift and MutableShiftedArrays.ifftshift.
Examples
julia> MutableShiftedArrays.ft_center_diff((4, 5, 6), (1, 2)) # Fourier center is at (2, 3, 0)
(2, 2, 0)
julia> MutableShiftedArrays.ft_center_diff((4, 5, 6), (1, 2, 3)) # Fourier center is at (2, 3, 4)
(2, 2, 3)Internals
MutableShiftedArrays.padded_tuple — Function
padded_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> MutableShiftedArrays.padded_tuple(rand(10, 10), 3)
(3, 0)
julia> MutableShiftedArrays.padded_tuple(rand(10, 10), (4,))
(4, 0)
julia> MutableShiftedArrays.padded_tuple(rand(10, 10), (1, 5))
(1, 5)