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
/* start of usignal */ | |
/* usignal license: https://github.com/WebReflection/usignal/blob/18920ecf613d31b4a8f20f1acc4bcb111a3ab987/LICENSE */ | |
/*! (c) Andrea Giammarchi */ | |
const {is} = Object; | |
let batches; |
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
# | |
# Loosely based on the paper at https://core.ac.uk/download/pdf/82729885.pdf but with some significant deviation. | |
# | |
# This implementation should be robust even for bad inputs with large condition numbers. The reduced basis of a lattice L with basis | |
# vectors as columns of a matrix M is given by M*lll_unimod(M) . | |
# | |
# | |
# Acceptably optimized. Spends just under 50% of its time in the call to LinearAlgebra.qr for 2000 x 2000 matrices. | |
# Benchmarks fairly well compared to existing libraries in multiple languages. |
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
using FunctionalCollections | |
using MacroTools | |
using DataFrames | |
# Data structures designed for this problem | |
include("persistent_unionfind.jl") | |
include("pairingheap.jl") | |
# | |
# (For datalog-like subset) |
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
# | |
# Mutable Pairing heap. This version only allocates new nodes when you | |
# create a heap or add elements to it, so number of allocations == number of nodes. Has O(1) merges. | |
# Performance is not yet optimized and is much slower than an immutable persistent version I wrote, | |
# Performance difference may possibly be due to the generational GC making allocation cheaper & more cache friendly, | |
# and mutating pointers from old to new nodes more expensive than in C or Rust. | |
# | |
struct EmptyHeap{T} end | |
mutable struct PairingTree{T} |
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
struct EmptyHeap{T} end | |
struct PairingTree{T} | |
top::T | |
length::Int | |
subheaps::Union{PairingTree{T},Nothing} | |
tail::Union{PairingTree{T},Nothing} # Intrusive linked list. | |
end | |
const PairingHeap{T} = Union{EmptyHeap{T},PairingTree{T}} | |
Base.show(io::IO,pt::PairingTree{T}) where {T} = show(io,"PairingTree{$(T)}($(pt.top),$(pt.length),$(isnothing(pt.subheaps) ? "empty" : "..." ))") |
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
abstract type GlobalScope end | |
abstract type _LifeTime{S<:GlobalScope} end | |
const LifeTime{S<:GlobalScope} = _LifeTime{>:S} | |
struct LivesExactly{L<:LifeTime,T} | |
val::T | |
LivesExactly(lt::Type{L},val::T) where {T,L<:LifeTime} = new{L,T}(val) | |
end | |
const LivesAtLeast{L,T} = LivesExactly{<:L,T} |
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
using LightGraphs | |
using SimpleTraits | |
using BenchmarkTools | |
using GraphPlot | |
@traitfn function strongly_connected_components_2(g::AG::IsDirected) where {T <: Integer, AG <: AbstractGraph{T}} | |
if iszero(nv(g)) return Vector{Vector{T}}() end | |
strongly_connected_components_tarjan(g,infer_nb_iterstate_type(g)) | |
end |
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
using MLStyle | |
import MacroTools | |
import Printf | |
@data internal MExpr begin | |
MInt(Int) | |
Var(Symbol) | |
Add(MExpr,MExpr) | |
Mul(MExpr,MExpr) | |
Pow(MExpr,MExpr) |