LabeledArrays
Vector
s for fast Int index retrieval, NamedMatrix
with names as keys of arbitrary type and sparse index vectors.
TODO:
- generalized
NamedArray
implementation. - examples
Public Documentation
Documentation for LabeledArrays.jl
's public interface.
LabeledArrays.LabeledMatrix
— TypeA matrix, AbstractArray{T,2}
, with a layer labeled rows and cols.
LabeledArrays.NBijection
— TypeNBijection(x::Vector{T})
KEY <-> Int, bijection map. Synonym to possibly better name EnumerationDict
, or VectorDict
.
Store inverse indices in a Dict{T,I}
as well as original Vector{T}
.
copy
: set to false to storex
without copying. (make sure that Vector will be mutated only throughNBijection
API.
Base.get!
— MethodBase.get!(f::Function,b::NBijection, key)
Calls f(length(b),key)
hook function if key !in b
, push key
to b.enumeration
and store key=>index
. Similar to get!(f,b::Dict, key)
.
TODO: remove f(n,key)
julia> x = NBijection(['a','b','c'])
julia> get!(x,'b')
2
julia> get!((i,k)->println("neu"), x, 'd')
neu
4
julia> get!((i,k)->println("neu"), x, 'd')
4
Base.get!
— MethodBase.get!(b::NBijection, key)
When key !in b.index
, push nothing
to b.enumeration
and store key=>index
.
julia> x = NBijection(['a','b','c'])
julia> get!(x,'b')
2
julia> get!(x,'d')
4
julia> get!(x,'d')
4
Base.getindex
— MethodBase.getindex(b::NBijection,i::Integer)
b.enumeration[i]
.
Base.keys
— Methodkeys(b::NBijection)
terms are keys in sequence that share position index with some other data structure, like a count matrix in Count.
Base.push!
— MethodBase.push!(b::NBijection, key)
Push key
to b.enumeration
and store key=>index
. Return last index.
@asserts that key is not in index, fails otherwise. Consider get!
.
SparseArrays.nnz
— Methodnnz(x::LinearAlgebra.Adjoint)
Call SparseArrays.nnz
of transpose for performance.
SparseArrays.sparsevec
— Methodsparse_vector(x::NBijection,sel)
Create a sparse vector representation of sel
ected values in x::
NBijection
.