MultidimensionalTools.jl Documentation
Adding MultidimensionalTools.jl
julia> using Pkg
julia> Pkg.add("MultidimensionalTools")
Updating registry at `~/.julia/registries/General`
Resolving package versions...
Installed MultidimensionalTools ─ v0.1.0
Updating `~/work/MultidimensionalTools.jl/MultidimensionalTools.jl/docs/Project.toml`
[9aeeebde] ~ MultidimensionalTools v0.1.0 `~/work/MultidimensionalTools.jl/MultidimensionalTools.jl` ⇒ v0.1.0
Updating `~/work/MultidimensionalTools.jl/MultidimensionalTools.jl/docs/Manifest.toml`
[9aeeebde] ~ MultidimensionalTools v0.1.0 `~/work/MultidimensionalTools.jl/MultidimensionalTools.jl` ⇒ v0.1.0
Documentation
Main.MultidimensionalTools.adjacencies
— Methodadjacencies(M::AbstractArray{T, N}, idx::AbstractIndex{N})
adjacencies
will get all adjacent element to an index in a given matrix.
Main.MultidimensionalTools.append_n_times
— MethodRepeats a specified value n many times along the specified dimension. If no fill_elem
is given, and the element type of the matrix is a number, fills with zero.
julia> A = rand(Int8, 2, 2)
2×2 Array{Int8,2}:
28 23
-47 54
julia> append_n_times(A, 2, Int8(3), dims = 1) # repeat the value 3 twice along the first dimension
4×2 Array{Int8,2}:
28 23
-47 54
3 3
3 3
Main.MultidimensionalTools.append_n_times_backwards
— Methodjulia> A = rand(Int8, 2, 2)
2×2 Array{Int8,2}:
28 23
-47 54
julia> append_n_times_backwards(A, 2, Int8(3), dims = 1) # repeat the value 3 twice along the first dimension
4×2 Array{Int8,2}:
3 3
3 3
28 23
-47 54
Main.MultidimensionalTools.expand_as_required
— Methodexpand_as_required(M::AbstractArray{T, N}, expand_by::T, inds::AbstractIndexOrIndices{N})
Given indices, expand_as_required
will fill in a matrix with expand_by
where needed if such indices are not currently accessible. If no expand_by
is given, and the element type of the matrix is a number, fills with zero.
julia> A = rand(Int8, 2, 2)
2×2 Array{Int8,2}:
-96 83
-94 -39
julia> expand_as_required(A, zero(Int8), [(1, 1), (2, 2), (3, 3)])
3×3 Array{Int8,2}:
-96 83 0
-94 -39 0
0 0 0
Main.MultidimensionalTools.expanded_adjacencies
— Methodexpanded_adjacencies(M::Array{T, N}, expand_by::T, idx::AbstractIndex{N})
expanded_adjacencies
will get all adjacencies of an index in the matrix M, given that the matrix is infinitely expanding by a single element beyond the specified M. See also adjacencies
and expand_as_required
. If no expand_by
is given, and the element type of the matrix is a number, fills with zero.
Main.MultidimensionalTools.expanded_n_adjacent_to
— Methodexpanded_n_adjacent_to(M::AbstractArray{T, N}, expand_by::T, idx::AbstractIndex{N}, adj_elem::T)
Given a matrix M, counts the number of adjacent elements to index idx
that are exactly the adj_elem
, expanding the matrix if needed (see expanded_adjacencies
). If no expand_by
is given, and the element type of the matrix is a number, fills with zero.
Main.MultidimensionalTools.extrema_indices
— Methodextrema_indices(I::AbstractIndices{N}) -> NTuple{N, NTuple{N, Integer}}
extrema_indices(i::AbstractIndex{N}...) -> NTuple{N, NTuple{N, Integer}}
extrema_indices(A::AbstractArray{T, N}...) -> NTuple{N, NTuple{N, Integer}}
Given indices or arrays, returns an NTuple
. Each element in the NTuple
represents a (min, max) tuple for each dimension.
julia> T = [(3, 1), (4, 5), (6, 2), (1, 1)]
4-element Array{Tuple{Int64,Int64},1}:
(3, 1)
(4, 5)
(6, 2)
(1, 1)
julia> extrema_indices(T)
1×2 Array{Tuple{Int64,Int64},2}:
(1, 6) (1, 5)
julia> # that is, the (min, max) for dim 2 is (1, 5); etc.
Main.MultidimensionalTools.get_directions
— MethodReturns an array of tuples of directions.
get_directions(dim::Integer; include_zero::Bool = false) -> Array{NTuple{N, Integer}, 1}
julia> get_directions(3)
27-element Array{Tuple{Int64,Int64,Int64},1}:
(-1, -1, -1)
(0, -1, -1)
(1, -1, -1)
(-1, 0, -1)
(0, 0, -1)
(1, 0, -1)
(-1, 1, -1)
(0, 1, -1)
(1, 1, -1)
(-1, -1, 0)
(0, -1, 0)
(1, -1, 0)
(-1, 0, 0)
(0, 0, 0)
(1, 0, 0)
(-1, 1, 0)
(0, 1, 0)
(1, 1, 0)
(-1, -1, 1)
(0, -1, 1)
(1, -1, 1)
(-1, 0, 1)
(0, 0, 1)
(1, 0, 1)
(-1, 1, 1)
(0, 1, 1)
(1, 1, 1)
Main.MultidimensionalTools.global_adjacencies
— Methodglobal_adjacencies(M::AbstractArray{T}, idx::AbstractIndex{N}, ignored_elem::T)
Using global_adjacencies_indices
, returns the elements of each globally adjacent index. This function is mainly used for global_n_adjacent_to
.
Main.MultidimensionalTools.global_adjacencies_indices
— Methodglobal_adjacencies(M::AbstractArray{T, N}, idx::AbstractIndex{N}, ignored_elem::T)
Returns the "globally" adjacent indices in arbitrary positions in the cardinal directions from a specified index in matrix M
, ignoring certain adjacent elements (i.e., skipping over them).
Main.MultidimensionalTools.global_n_adjacent_to
— Methodglobal_n_adjacent_to(M::AbstractArray{T, N},idx::AbstractIndex{N}, adj_elem::T, ignored_elem::T) where {N, T}
Given a matrix M, counts the number of adjacent elements to index idx
that are exactly the adj_elem
, skipping over certain elements if needed (see expanded_adjacencies
).
Main.MultidimensionalTools.is2Dsquare
— MethodCheck whether the 2-dimensional aspect of a given array is a square.
Main.MultidimensionalTools.ishypercube
— MethodCheck whether the given array is a cube (i.e., all its dimensions are the same size). Despite the function name, this will work for dimension < 3
Main.MultidimensionalTools.n_adjacencies
— Methodn_adjacencies(dim::Integer) -> Integer
n_adjacencies(M::AbstractArray{T, N}) -> Integer
n_adjacencies(I::AbstractIndexOrIndices{T, N}) -> Integer
Given a matrix or dimension, returns the number of elements adjacent to any given element in an infinite lattice/matrix (i.e., not including edges). For edges, see adjacencies
).
Main.MultidimensionalTools.n_adjacent_to
— Methodn_adjacent_to(M::AbstractArray{T, N}, idx::AbstractIndex{N}, adj_elem::T)
Given a matrix M, counts the number of adjacent elements to index idx
that are exactly the adj_elem
.
Main.MultidimensionalTools.promote_to_3D
— Methodpromote_to_3D(M::AbstractArray{T, N}, fill_elem::T)
promote_to_3D(M::AbstractArray{T, N}) where T <: Number
A simple, self-evident wrapper for promote_to_nD
. No fill_elem
assumes that the value is zero (if it can be).
Main.MultidimensionalTools.promote_to_nD
— Methodfunction promote_to_nD(M::AbstractArray{T, N}, n::Integer, fill_elem::T)
Assumes the given matrix M is an (n - 1) dimensional slice of an n-dimensional structure, and fills in the array to n dimensions with fill_elem
. If no fill_elem
is given, and the element type of the matrix is a number, fills with zero.
Main.MultidimensionalTools.tryindex
— Methodtryindex(M::AbstractArray{T, N}, inds::AbstractIndex{N}}...)
tryindex(M::AbstractArray{T, N}, inds::AbstractIndices{N}})
For each index specified, gets the index or missing if the index is unavailable.
Main.MultidimensionalTools.𝟘
— Method𝟘(n::Integer) -> NTuple{n, Integer}
\bbzero<tab>(n::Integer) -> NTuple{n, Integer}
Simply returns the zero tuple of a given dimension.
Index
Main.MultidimensionalTools.adjacencies
Main.MultidimensionalTools.append_n_times
Main.MultidimensionalTools.append_n_times_backwards
Main.MultidimensionalTools.expand_as_required
Main.MultidimensionalTools.expanded_adjacencies
Main.MultidimensionalTools.expanded_n_adjacent_to
Main.MultidimensionalTools.extrema_indices
Main.MultidimensionalTools.get_directions
Main.MultidimensionalTools.global_adjacencies
Main.MultidimensionalTools.global_adjacencies_indices
Main.MultidimensionalTools.global_n_adjacent_to
Main.MultidimensionalTools.is2Dsquare
Main.MultidimensionalTools.ishypercube
Main.MultidimensionalTools.n_adjacencies
Main.MultidimensionalTools.n_adjacent_to
Main.MultidimensionalTools.promote_to_3D
Main.MultidimensionalTools.promote_to_nD
Main.MultidimensionalTools.tryindex
Main.MultidimensionalTools.𝟘