Bags

Index

API

Mill.AlignedBagsType
AlignedBags{T <: Integer} <: AbstractBags{T}

AlignedBags struct stores indices of bags' instances in one or more UnitRange{T}s. This is only possible if instances of every bag are stored in one contiguous block.

See also: ScatteredBags.

source
Mill.AlignedBagsMethod
AlignedBags()

Construct a new AlignedBags struct containing no bags.

Examples

julia> AlignedBags()
AlignedBags{Int64}(UnitRange{Int64}[])
source
Mill.AlignedBagsMethod
AlignedBags(bags::UnitRange{<:Integer}...)

Construct a new AlignedBags struct from bags in arguments.

Examples

julia> AlignedBags(1:3, 4:8)
AlignedBags{Int64}(UnitRange{Int64}[1:3, 4:8])
source
Mill.AlignedBagsMethod
AlignedBags(k::Vector{<:Integer})

Construct a new AlignedBags struct from Vector k specifying the index of the bag each instance belongs to. Throws ArgumentError if this is not possible.

Examples

julia> AlignedBags([1, 1, 2, 2, 2, 4])
AlignedBags{Int64}(UnitRange{Int64}[1:2, 3:5, 0:-1, 6:6])
source
Mill.ScatteredBagsMethod
ScatteredBags(k::Vector{<:Integer})

Construct a new ScatteredBags struct from Vector k specifying the index of the bag each instance belongs to.

Examples

julia> ScatteredBags([2, 2, 1, 1, 1, 3])
ScatteredBags{Int64}([[3, 4, 5], [1, 2], [6]])
source
Mill.length2bagsFunction
length2bags(ls::Vector{<:Integer})

Convert lengths of bags given in ls to AlignedBags with contiguous blocks.

Examples

julia> length2bags([1, 3, 2])
AlignedBags{Int64}(UnitRange{Int64}[1:1, 2:4, 5:6])

See also: AlignedBags.

source
Mill.bagsFunction
bags(k::Vector{<:Integer})
bags(k::Vector{T}) where T <: UnitRange{<:Integer}
bags(b::AbstractBags)

Construct an AbstractBags structure that is most suitable for the input (AlignedBags if possible, ScatteredBags otherwise).

Examples

julia> bags([1, 1, 3])
AlignedBags{Int64}(UnitRange{Int64}[1:2, 0:-1, 3:3])

julia> bags([2, 3, 1, 2])
ScatteredBags{Int64}([[3], [1, 4], [2]])

julia> bags([1:3, 4:5])
AlignedBags{Int64}(UnitRange{Int64}[1:3, 4:5])

julia> bags(ScatteredBags())
ScatteredBags{Int64}(Vector{Int64}[])

See also: AlignedBags, ScatteredBags.

source
Mill.remapbagsFunction
remapbags(b::AbstractBags, idcs::VecOrRange{<:Integer}) -> (rb, I)

Select a subset of bags in b corresponding to indices idcs and remap instance indices appropriately. Return new bags rb as well as a Vector of remapped instances I.

Examples

julia> remapbags(AlignedBags([1:1, 2:3, 4:5]), [1, 3])
(AlignedBags{Int64}(UnitRange{Int64}[1:1, 2:3]), [1, 4, 5])

julia> remapbags(ScatteredBags([[1,3], [2], Int[]]), [2])
(ScatteredBags{Int64}([[1]]), [2])
source
Mill.adjustbagsFunction
adjustbags(b::AlignedBags, mask::AbstractVector{Bool})

Remove indices of instances brom bags b and remap the remaining instances accordingly.

Examples

julia> adjustbags(AlignedBags([1:2, 0:-1, 3:4]), [false, false, true, true])
AlignedBags{Int64}(UnitRange{Int64}[0:-1, 0:-1, 1:2])
source