Bags

Index

API

Mill.AbstractBagsType
AbstractBags{T}

Supertype for structures storing indices of type T of bags' instances in BagNodes.

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.

Mill.AlignedBagsMethod
AlignedBags()

Construct a new AlignedBags struct containing no bags.

Examples

julia> AlignedBags()
AlignedBags{Int64}(UnitRange{Int64}[])
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])
Mill.AlignedBagsMethod
AlignedBags(k::Vector{<:Integer})

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

Examples

julia> AlignedBags([2, 2, 1, 1, 1, 3])
AlignedBags{Int64}(UnitRange{Int64}[1:2, 3:5, 6:6])
Mill.ScatteredBagsMethod
ScatteredBags()

Construct a new ScatteredBags struct containing no bags.

Examples

julia> ScatteredBags()
ScatteredBags{Int64}(Array{Int64,1}[])
Mill.ScatteredBagsMethod
ScatteredBags(k::Vector{<:Integer})

Construct a new ScatteredBags struct from Vectork 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]])
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.

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([2, 2, 3, 1])
AlignedBags{Int64}(UnitRange{Int64}[1:2, 3:3, 4:4])

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}(Array{Int64,1}[])

See also: AlignedBags, ScatteredBags.

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])
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])