-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
RecursiveSet
and DuplicateVector
, better benchmarking of Brus…
…selator (#50) * Add `RecursiveSet` * Put set types in subfolders * Add `DuplicateVector` * Make Brusselator into callable struct
- Loading branch information
Showing
29 changed files
with
330 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
HessianTracer{BitSet}( | ||
2 => (), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
HessianTracer{DuplicateVector{UInt64}}( | ||
2 => (), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
HessianTracer{RecursiveSet{UInt64}}( | ||
2 => (), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
HessianTracer{Set{UInt64}}( | ||
2 => (), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
HessianTracer{SortedVector{UInt64}}( | ||
2 => (), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
DuplicateVector | ||
Vector that can have duplicate values, for which union is just concatenation. | ||
""" | ||
struct DuplicateVector{T<:Number} | ||
data::Vector{T} | ||
|
||
DuplicateVector{T}(data::AbstractVector{T}) where {T} = new{T}(convert(Vector{T}, data)) | ||
DuplicateVector{T}(x::Number) where {T} = new{T}([convert(T, x)]) | ||
DuplicateVector{T}() where {T} = new{T}(T[]) | ||
end | ||
|
||
Base.eltype(::Type{DuplicateVector{T}}) where {T} = T | ||
|
||
function Base.union(dv1::DuplicateVector{T}, dv2::DuplicateVector{T}) where {T} | ||
return DuplicateVector{T}(vcat(dv1.data, dv2.data)) | ||
end | ||
|
||
Base.collect(dv::DuplicateVector) = collect(Set(dv.data)) | ||
|
||
## SCT tricks | ||
|
||
function keys2set(::Type{S}, d::Dict{I}) where {I<:Integer,S<:DuplicateVector{I}} | ||
return S(collect(keys(d))) | ||
end | ||
|
||
const EMPTY_CONNECTIVITY_TRACER_DV_U16 = ConnectivityTracer(DuplicateVector{UInt16}()) | ||
const EMPTY_CONNECTIVITY_TRACER_DV_U32 = ConnectivityTracer(DuplicateVector{UInt32}()) | ||
const EMPTY_CONNECTIVITY_TRACER_DV_U64 = ConnectivityTracer(DuplicateVector{UInt64}()) | ||
|
||
const EMPTY_JACOBIAN_TRACER_DV_U16 = JacobianTracer(DuplicateVector{UInt16}()) | ||
const EMPTY_JACOBIAN_TRACER_DV_U32 = JacobianTracer(DuplicateVector{UInt32}()) | ||
const EMPTY_JACOBIAN_TRACER_DV_U64 = JacobianTracer(DuplicateVector{UInt64}()) | ||
|
||
const EMPTY_HESSIAN_TRACER_DV_U16 = HessianTracer(Dict{UInt16,DuplicateVector{UInt16}}()) | ||
const EMPTY_HESSIAN_TRACER_DV_U32 = HessianTracer(Dict{UInt32,DuplicateVector{UInt32}}()) | ||
const EMPTY_HESSIAN_TRACER_DV_U64 = HessianTracer(Dict{UInt64,DuplicateVector{UInt64}}()) | ||
|
||
function empty(::Type{ConnectivityTracer{DuplicateVector{UInt16}}}) | ||
return EMPTY_CONNECTIVITY_TRACER_DV_U16 | ||
end | ||
function empty(::Type{ConnectivityTracer{DuplicateVector{UInt32}}}) | ||
return EMPTY_CONNECTIVITY_TRACER_DV_U32 | ||
end | ||
function empty(::Type{ConnectivityTracer{DuplicateVector{UInt64}}}) | ||
return EMPTY_CONNECTIVITY_TRACER_DV_U64 | ||
end | ||
|
||
empty(::Type{JacobianTracer{DuplicateVector{UInt16}}}) = EMPTY_JACOBIAN_TRACER_DV_U16 | ||
empty(::Type{JacobianTracer{DuplicateVector{UInt32}}}) = EMPTY_JACOBIAN_TRACER_DV_U32 | ||
empty(::Type{JacobianTracer{DuplicateVector{UInt64}}}) = EMPTY_JACOBIAN_TRACER_DV_U64 | ||
|
||
empty(::Type{HessianTracer{DuplicateVector{UInt16},UInt16}}) = EMPTY_HESSIAN_TRACER_DV_U16 | ||
empty(::Type{HessianTracer{DuplicateVector{UInt32},UInt32}}) = EMPTY_HESSIAN_TRACER_DV_U32 | ||
empty(::Type{HessianTracer{DuplicateVector{UInt64},UInt64}}) = EMPTY_HESSIAN_TRACER_DV_U64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
""" | ||
RecursiveSet | ||
Lazy union of sets. | ||
""" | ||
struct RecursiveSet{T<:Number} | ||
s::Union{Nothing,Set{T}} | ||
child1::Union{Nothing,RecursiveSet{T}} | ||
child2::Union{Nothing,RecursiveSet{T}} | ||
|
||
function RecursiveSet{T}(s) where {T} | ||
return new{T}(Set{T}(s), nothing, nothing) | ||
end | ||
|
||
function RecursiveSet{T}(x::Number) where {T} | ||
return new{T}(Set{T}(convert(T, x)), nothing, nothing) | ||
end | ||
|
||
function RecursiveSet{T}() where {T} | ||
return new{T}(Set{T}(), nothing, nothing) | ||
end | ||
|
||
function RecursiveSet{T}(rs1::RecursiveSet{T}, rs2::RecursiveSet{T}) where {T} | ||
return new{T}(nothing, rs1, rs2) | ||
end | ||
end | ||
|
||
function print_recursiveset(io::IO, rs::RecursiveSet{T}; offset) where {T} | ||
if !isnothing(rs.s) | ||
print(io, "RecursiveSet{$T} containing $(rs.s)") | ||
else | ||
print(io, "RecursiveSet{$T} with two children:") | ||
print(io, "\n ", " "^offset, "1: ") | ||
print_recursiveset(io, rs.child1; offset=offset + 2) | ||
print(io, "\n ", " "^offset, "2: ") | ||
print_recursiveset(io, rs.child2; offset=offset + 2) | ||
end | ||
end | ||
|
||
function Base.show(io::IO, rs::RecursiveSet{T}) where {T} | ||
return print_recursiveset(io, rs; offset=0) | ||
end | ||
|
||
Base.eltype(::Type{RecursiveSet{T}}) where {T} = T | ||
|
||
function Base.union(rs1::RecursiveSet{T}, rs2::RecursiveSet{T}) where {T} | ||
return RecursiveSet{T}(rs1, rs2) | ||
end | ||
|
||
function Base.collect(rs::RecursiveSet{T}) where {T} | ||
accumulator = Set{T}() | ||
collect_aux!(accumulator, rs) | ||
return collect(accumulator) | ||
end | ||
|
||
function collect_aux!(accumulator::Set{T}, rs::RecursiveSet{T})::Nothing where {T} | ||
if !isnothing(rs.s) | ||
union!(accumulator, rs.s::Set{T}) | ||
else | ||
collect_aux!(accumulator, rs.child1::RecursiveSet{T}) | ||
collect_aux!(accumulator, rs.child2::RecursiveSet{T}) | ||
end | ||
return nothing | ||
end | ||
|
||
## SCT tricks | ||
|
||
function keys2set(::Type{S}, d::Dict{I}) where {I<:Integer,S<:RecursiveSet{I}} | ||
return S(keys(d)) | ||
end | ||
|
||
const EMPTY_CONNECTIVITY_TRACER_RS_U16 = ConnectivityTracer(RecursiveSet{UInt16}()) | ||
const EMPTY_CONNECTIVITY_TRACER_RS_U32 = ConnectivityTracer(RecursiveSet{UInt32}()) | ||
const EMPTY_CONNECTIVITY_TRACER_RS_U64 = ConnectivityTracer(RecursiveSet{UInt64}()) | ||
|
||
const EMPTY_JACOBIAN_TRACER_RS_U16 = JacobianTracer(RecursiveSet{UInt16}()) | ||
const EMPTY_JACOBIAN_TRACER_RS_U32 = JacobianTracer(RecursiveSet{UInt32}()) | ||
const EMPTY_JACOBIAN_TRACER_RS_U64 = JacobianTracer(RecursiveSet{UInt64}()) | ||
|
||
const EMPTY_HESSIAN_TRACER_RS_U16 = HessianTracer(Dict{UInt16,RecursiveSet{UInt16}}()) | ||
const EMPTY_HESSIAN_TRACER_RS_U32 = HessianTracer(Dict{UInt32,RecursiveSet{UInt32}}()) | ||
const EMPTY_HESSIAN_TRACER_RS_U64 = HessianTracer(Dict{UInt64,RecursiveSet{UInt64}}()) | ||
|
||
empty(::Type{ConnectivityTracer{RecursiveSet{UInt16}}}) = EMPTY_CONNECTIVITY_TRACER_RS_U16 | ||
empty(::Type{ConnectivityTracer{RecursiveSet{UInt32}}}) = EMPTY_CONNECTIVITY_TRACER_RS_U32 | ||
empty(::Type{ConnectivityTracer{RecursiveSet{UInt64}}}) = EMPTY_CONNECTIVITY_TRACER_RS_U64 | ||
|
||
empty(::Type{JacobianTracer{RecursiveSet{UInt16}}}) = EMPTY_JACOBIAN_TRACER_RS_U16 | ||
empty(::Type{JacobianTracer{RecursiveSet{UInt32}}}) = EMPTY_JACOBIAN_TRACER_RS_U32 | ||
empty(::Type{JacobianTracer{RecursiveSet{UInt64}}}) = EMPTY_JACOBIAN_TRACER_RS_U64 | ||
|
||
empty(::Type{HessianTracer{RecursiveSet{UInt16},UInt16}}) = EMPTY_HESSIAN_TRACER_RS_U16 | ||
empty(::Type{HessianTracer{RecursiveSet{UInt32},UInt32}}) = EMPTY_HESSIAN_TRACER_RS_U32 | ||
empty(::Type{HessianTracer{RecursiveSet{UInt64},UInt64}}) = EMPTY_HESSIAN_TRACER_RS_U64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.