text:
using UnrollingAverages
using Statistics
using Test

@testset "UnrollingAverages.jl" begin

    # params
    n₋ = 2
    n₊ = 4

    # test series
    for i in 1:10
        original_time_series        = [rand(0:9) for i in 1:500]
        original_time_series_with_0 = vcat(repeat([0],n₋+n₊),[rand(0:9) for i in 1:500])

        averaged_time_series = [mean(original_time_series[(i-n₋):(i+n₊)]) for i in (1+n₋):(length(original_time_series)-n₊)];
        averaged_time_series_with_0 = [mean(original_time_series_with_0[(i-n₋):(i+n₊)]) for i in (1+n₋):(length(original_time_series_with_0)-n₊)];

        # test unroll_recursive
        @test unroll(averaged_time_series, n₋ + n₊ + 1; initial_conditions =  Tuple(original_time_series[1:(n₋+n₊)])  )[1] == original_time_series
        # test unroll_recursive error when initial values are not of the correct length
        @test unroll(averaged_time_series, n₋ + n₊ + 1; initial_conditions =  Tuple(original_time_series[1:(n₋+n₊)])  )[1] == original_time_series
        ## test that unroll_recursive errors when initial conditions are of wrong length
        @test_throws ErrorException unroll(averaged_time_series, n₋ + n₊ + 1; initial_conditions =  Tuple(original_time_series[2:(n₋+n₊)])  )[1]
        # test that assert_natural has no effects when `initial_conditions` are specified (calls unroll_recursive again)
        @test unroll(averaged_time_series, n₋ + n₊ + 1; initial_conditions =  Tuple(original_time_series[1:(n₋+n₊)]), assert_natural = true  )[1] == original_time_series
        # test unroll_linear_approximation
        @test UnrollingAverages.moving_average(unroll(averaged_time_series, n₋ + n₊ + 1 )[1] , n₋, n₊ ) ≈ averaged_time_series
        # test unroll_iterative
        @test original_time_series ∈ unroll(averaged_time_series, n₋ + n₊ + 1;  assert_natural = true)
        # test unroll_iterative when the movign average has a 0
        @test original_time_series_with_0 ∈ unroll(averaged_time_series_with_0, n₋ + n₊ + 1;  assert_natural = true)
        # test internal `moving_average(time_series::Union{Vector{Float64},Vector{Int64}},window::Int64)`
        @test UnrollingAverages.moving_average(unroll(averaged_time_series, n₋ + n₊ + 1 )[1] , n₋ + n₊ +1 ) ≈ averaged_time_series

        #@time unroll(averaged_time_series, n₋ + n₊ + 1;  assert_natural = true)

    end

end


text:
#module Visualize
#using Bridge, PyPlot, StaticVector
#end

using Bridge, StaticArrays, Bridge.Models
const R = ℝ
Random.seed!(2)

iterations = 25000
rho = 0.005 # 1 - rho is AR(1) coefficient of Brownian motion valued random walk
independent = false # independent proposals
adaptive = false # adaptive proposals
adaptit = 500 # adapt every `it`th step
#adaptmax = 4000
adaptmax = 10000
cheating = false # take a posteriori good value of Pt
showpath = false
partial = true

πH = 2000. # prior

t = 1.0
T = 5.00
n = 50001 # total imputed length
m = 500 # number of segments
M = div(n-1,m)
skiplast = 0
skippoints = 2
dt = (T-t)/(n-1)
tt = t:dt:T
si = 3.
P = Bridge.Models.Lorenz(ℝ{3}(10, 20, 8/3), ℝ{3}(si,0*si,si))
P2 = Psmooth = Bridge.Models.Lorenz(ℝ{3}(10, 28, 8/3), ℝ{3}(0,0,0))

x0 = Models.x0(P)
#x0 =  ℝ{3}(6, 0, 2)

W = sample(tt, Wiener{ℝ{3}}())
X = SamplePath(tt, zeros(ℝ{3}, length(tt)))
Bridge.solve!(Euler(), X, x0, W, P)
W = sample(tt, Wiener{ℝ{3}}())
X2 = SamplePath(tt, zeros(ℝ{3}, length(tt)))
Bridge.solve!(Euler(), X2, x0, W, P2)

Xtrue = copy(X)

# Observation scheme and subsample
_pairs(collection) = Base.Generator(=>, keys(collection), values(collection))
SV = ℝ{3}
SM = typeof(one(Bridge.outer(zero(SV))))

if !partial
    L = I
    Σ = SDiagonal(1., 1., 1.)
    lΣ = chol(Σ)'
    RV = SV
    RM = SM

    V = SamplePath(collect(_pairs(Xtrue))[1:M:end])
    map!(y -> L*y + lΣ*randn(RV), V.yy, V.yy)
else
    L = @SMatrix [0.0 1.0 0.0; 0.0 0.0 1.0]
    Σ = SDiagonal(1., 1.)
    lΣ = chol(Σ)'
    RV = ℝ{2}
    RM = typeof(one(Bridge.outer(zero(RV))))

    V_ = SamplePath(collect(_pairs(Xtrue))[1:M:end])
    V = SamplePath(V_.tt, map(y -> L*y + lΣ*randn(RV), V_.yy))

end
XX = Vector{typeof(X)}(m)
XXmean = Vector{typeof(X)}(m)
XXᵒ = Vector{typeof(X)}(m)
WW = Vector{typeof(W)}(m)
WWᵒ = Vector{typeof(W)}(m)

# Create linear noise approximations

TPt = Bridge.LinearAppr{StaticArrays.SDiagonal{3,Float64},StaticArrays.SArray{Tuple{3,3},Float64,2,9},SVector{3,Float64}}
TPᵒ = Bridge.GuidedBridge{SVector{3,Float64},StaticArrays.SArray{Tuple{3,3},Float64,2,9},TPt,Bridge.Models.Lorenz}

Pt = Vector{TPt}(m)
Pᵒ = Vector{TPᵒ}(m)

H♢, v = Bridge.gpupdate(πH*one(SM), zero(SV), L, Σ, V.yy[end])

for i in m:-1:1
    XX[i] = SamplePath(X.tt[1 + (i-1)*M:1 + i*M], X.yy[1 + (i-1)*M:1 + i*M])
    WW[i] = SamplePath(W.tt[1 + (i-1)*M:1 + i*M], W.yy[1 + (i-1)*M:1 + i*M])

#    Σ_= Bridge.σ(XX[i].tt[end], v, P)

    x_ = Models.foci(P)[1 + ( V.yy[i][1] > 0)]
#    B_ = -Bridge.bderiv(0, x_, P)'
#    β_ = zero(ℝ{3})  #-B_*f
#
    #Pt[i] = Bridge.LinearAppr(XX[i].tt, fill(x_, M+1), fill(B_, M+1), fill(β_, M+1), fill(Σ_, M+1))

    Pt[i] = Bridge.linearappr(SamplePath(XX[i].tt, fill(x_, M+1)), P)

    Pᵒ[i] = Bridge.GuidedBridge(XX[i].tt, P, Pt[i], v, H♢)

    H♢, v = Bridge.gpupdate(Pᵒ[i], L, Σ, V.yy[i])
end

π0 = Bridge.Gaussian(v, Hermitian(H♢))

y = π0.μ
for i in 1:m
    sample!(WW[i], Wiener{ℝ{3}}())
    y = Bridge.bridge!(XX[i], y, WW[i], Pᵒ[i])
end
XXmean = [zero(XX[i]) for i in 1:m]

#X0 = ℝ{3}[]

function smooth(π0, XX, WW, P, Pᵒ, iterations, rho; verbose = true, adaptive = true, adaptmax = iterations, adaptit = 5000, independent = false, hwindow=20)
    m = length(XX)
    rho0 = rho
    # create workspace
    XXᵒ = deepcopy(XX)
    WWᵒ = deepcopy(WW)
    Wnr = Wiener{valtype(WW[1])}()

    # initialize
    mcstate = [mcstart(XX[i].yy) for i in 1:m]
    acc = 0
    y0 = π0.μ

    for it in 1:iterations
        doaccept = false

        if adaptive && it < adaptmax && it % adaptit == 0 # adaptive smoothing
            H♢, v = Bridge.gpupdate(πH*one(SM), zero(SV), L, Σ, V.yy[end])
            for i in m:-1:1
                xx = mcstate[i][1]
                Y = SamplePath(XX[i].tt, [mean(xx[max(1, j-hwindow):min(end, j+hwindow)]) for j in 1:length(xx)])
                Bridge.linearappr!(Pt[i], Y, P)

                Pᵒ[i] = Bridge.GuidedBridge(XX[i].tt, P, Pt[i], v, H♢)
                H♢, v = Bridge.gpupdate(Pᵒ[i], L, Σ, V.yy[i])
            end
            π0 = Bridge.Gaussian(v, Hermitian(H♢))
            #y0ᵒ = rand(π0)
            #doaccept = true
        end

        if !independent
            y0ᵒ = π0.μ + sqrt(rho0)*(rand(π0) - π0.μ) + sqrt(1-rho0)*(y0 - π0.μ)
        else
            y0ᵒ = rand(π0)
        end
        y = y0ᵒ
        for i in 1:m
            sample!(WWᵒ[i], Wnr)
            if !independent
                rho_ = rho * rand()
                WWᵒ[i].yy[:] = sqrt(rho_)*WWᵒ[i].yy + sqrt(1-rho_)*WW[i].yy
            end
            y = Bridge.bridge!(XXᵒ[i], y, WWᵒ[i], Pᵒ[i])
        end

        ll = 0.0
        for i in 1:m
            ll += llikelihood(LeftRule(), XXᵒ[i],  Pᵒ[i]) - llikelihood(LeftRule(), XX[i],  Pᵒ[i])
        end
        verbose && print("$it ll $(round(ll, digits=2)) ")

        #if true
        if doaccept || rand() < exp(ll)
            acc += 1
            verbose && print("\t X")
            y0 = y0ᵒ
            for i in 1:m
                XX[i], XXᵒ[i] = XXᵒ[i], XX[i]
                WW[i], WWᵒ[i] = WWᵒ[i], WW[i]
            end
        else
            verbose && print("\t .")
        end
        verbose && println("\t\t", round.(y0 - x0, 2))
        for i in 1:m
            mcstate[i] = Bridge.mcnext!(mcstate[i],XX[i].yy)
        end
    end
    mcstate, acc
end

if showpath
    using Makie
    scene = Scene(resolution = (400, 400))
    lines((@view Xtrue.yy[1:10:end]), linewidth = 0.2, color = :darkblue)
    center!(scene)

    for i in indices(XX,1)
        lines(XX[i].yy, linewidth = 0.2, color = :darkgreen)
    end
end

mcstates, acc = smooth(π0, XX, WW, P, Pᵒ, iterations, rho;
    adaptive = adaptive,
    adaptit = adaptit,
    adaptmax = adaptmax,
    verbose = true, independent = independent)
@show acc/iterations

include("../extra/makie.jl")

Xmean, Xrot, Xscal = mcsvd3(mcstates)

# Plot result
include("makie.jl")
Xmean, Xstd = mcmarginalstats(mcstates)

if true
    using PyPlot
    clf()
    for i in 1:3; plot(Xtrue.tt, getindex.(Xtrue.yy, i), label = "$i", color = :red); end
    for i in 1:3; plot(Xtrue.tt, getindex.(Xmean, i), label = "$i", color = :blue); end
    for i in 1:3; plot(Xtrue.tt, getindex.(Xmean + Xstd, i), color = :lightblue); end
    for i in 1:3; plot(Xtrue.tt, getindex.(Xmean - Xstd, i),   color = :lightblue); end
    for i in 1:2; plot(V.tt, getindex.(V.yy,i), ".",  color = :black); end
    for i in 1:3; plot(Xtrue.tt[1:end-1], getindex.(Nu, i), color = :palevioletred); end
end

ext: jl


text:
# ---
# title: 1096. Brace Expansion II
# id: problem1096
# author: Tian Jun
# date: 2020-10-31
# difficulty: Hard
# categories: String
# link: <https://leetcode.com/problems/brace-expansion-ii/description/>
# hidden: true
# ---
#
# Under a grammar given below, strings can represent a set of lowercase words.
# Let's use `R(expr)` to denote the **set** of words the expression represents.
#
# Grammar can best be understood through simple examples:
#
#   * Single letters represent a singleton set containing that word.
#     * `R("a") = {"a"}`
#     * `R("w") = {"w"}`
#   * When we take a comma delimited list of 2 or more expressions, we take the union of possibilities.
#     * `R("{a,b,c}") = {"a","b","c"}`
#     * `R("{{a,b},{b,c}}") = {"a","b","c"}` (notice the final set only contains each word at most once)
#   * When we concatenate two expressions, we take the set of possible concatenations between two words where the first word comes from the first expression and the second word comes from the second expression.
#     * `R("{a,b}{c,d}") = {"ac","ad","bc","bd"}`
#     * `R("a{b,c}{d,e}f{g,h}") = {"abdfg", "abdfh", "abefg", "abefh", "acdfg", "acdfh", "acefg", "acefh"}`
#
# Formally, the 3 rules for our grammar:
#
#   * For every lowercase letter `x`, we have `R(x) = {x}`
#   * For expressions `e_1, e_2, ... , e_k` with `k >= 2`, we have `R({e_1,e_2,...}) = R(e_1) ∪ R(e_2) ∪ ...`
#   * For expressions `e_1` and `e_2`, we have `R(e_1 + e_2) = {a + b for (a, b) in R(e_1) × R(e_2)}`, where + denotes concatenation, and × denotes the cartesian product.
#
# Given an `expression` representing a set of words under the given grammar,
# return the sorted list of words that the expression represents.
#
#
#
# **Example 1:**
#
#
#
#     Input: "{a,b}{c,{d,e}}"
#     Output: ["ac","ad","ae","bc","bd","be"]
#
#
# **Example 2:**
#
#
#
#     Input: "{{a,z},a{b,c},{ab,z}}"
#     Output: ["a","ab","ac","z"]
#     Explanation: Each distinct word is written only once in the final answer.
#
#
#
#
# **Constraints:**
#
#   1. `1 <= expression.length <= 60`
#   2. `expression[i]` consists of `'{'`, `'}'`, `','`or lowercase English letters.
#   3. The given `expression` represents a set of words based on the grammar given in the description.
#
#
## @lc code=start
using LeetCode

## add your code here:
## @lc code=end


text:
using LinearAlgebraicRepresentation
Lar = LinearAlgebraicRepresentation

"""
    frag_edge_channel(in_chan, out_chan,
        V::Lar.Points, EV::Lar.ChainOp, bigPI)

Parallel fragmentation of edges in `EV` using the spatial index `bigPI`.
"""
function frag_edge_channel(in_chan, out_chan, V, EV, bigPI)
    run_loop = true
    while run_loop
        edgenum = take!(in_chan)
        if edgenum != -1
            put!(out_chan, (edgenum, frag_edge(V, EV, edgenum, bigPI)))
        else
            run_loop = false
        end
    end
end

"""
    frag_edge(V::Lar.Points, EV::Lar.ChainOp, edge_idx::Int, bigPI::Array)

Fragment the edge of index `edge_idx` using the edges indicized in `bigPI`.
"""
function frag_edge(V, EV::Lar.ChainOp, edge_idx::Int, bigPI)
    alphas = Dict{Float64, Int}()
    edge = EV[edge_idx, :]
    verts = V[edge.nzind, :]
    for i in bigPI[edge_idx]
        if i != edge_idx
            intersection = Lar.Arrangement.intersect_edges(
            	V, edge, EV[i, :])
            for (point, alpha) in intersection
                verts = [verts; point]
                alphas[alpha] = size(verts, 1)
            end
        end
    end
    alphas[0.0], alphas[1.0] = [1, 2]
    alphas_keys = sort(collect(keys(alphas)))
    edge_num = length(alphas_keys)-1
    verts_num = size(verts, 1)
    ev = SparseArrays.spzeros(Int8, edge_num, verts_num)
    for i in 1:edge_num
        ev[i, alphas[alphas_keys[i]]] = 1
        ev[i, alphas[alphas_keys[i+1]]] = 1
    end
    return verts, ev
end

"""
    intersect_edges(V::Lar.Points, edge1::Lar.Cell, edge2::Lar.Cell)

Intersect two 2D edges (`edge1` and `edge2`).
"""
function intersect_edges(V::Lar.Points, edge1::Lar.Cell, edge2::Lar.Cell)
    err = 10e-8

    x1, y1, x2, y2 = vcat(map(c->V[c, :], edge1.nzind)...)
    x3, y3, x4, y4 = vcat(map(c->V[c, :], edge2.nzind)...)
    ret = Array{Tuple{Lar.Points, BigFloat}, 1}()

    v1 = [x2-x1, y2-y1];
    v2 = [x4-x3, y4-y3];
    v3 = [x3-x1, y3-y1];
    ang1 = dot(normalize(v1), normalize(v2))
    ang2 = dot(normalize(v1), normalize(v3))
    parallel = 1-err < abs(ang1) < 1+err
    colinear = parallel && (1-err < abs(ang2) < 1+err || -err < norm(v3) < err)
    if colinear
        o = [x1 y1]
        v = [x2 y2] - o
        alpha = 1/dot(v,v')
        ps = [x3 y3; x4 y4]
        for i in 1:2
            a = alpha*dot(v',(reshape(ps[i, :], 1, 2)-o))
            if 0 < a < 1
                push!(ret, (ps[i:i, :], a))
            end
        end
    elseif !parallel
        denom = (v2[2])*(v1[1]) - (v2[1])*(v1[2])
        a = ((v2[1])*(-v3[2]) - (v2[2])*(-v3[1])) / denom
        b = ((v1[1])*(-v3[2]) - (v1[2])*(-v3[1])) / denom

        if -err < a < 1+err && -err <= b <= 1+err
            p = [(x1 + a*(x2-x1))  (y1 + a*(y2-y1))]
            push!(ret, (p, a))
        end
    end
    return ret
end

"""
    merge_vertices!(V::Lar.Points, EV::Lar.ChainOp, edge_map, err=1e-4)

Merge congruent vertices and edges in `V` and `EV`.
"""
function merge_vertices!(V::Lar.Points, EV::Lar.ChainOp, edge_map, err=1e-4)
    vertsnum = size(V, 1)
    edgenum = size(EV, 1)
    newverts = zeros(Int, vertsnum)
    # KDTree constructor needs an explicit array of Float64
    V = Array{Float64,2}(V)
    kdtree = KDTree(permutedims(V))

    # merge congruent vertices
    todelete = []
    i = 1
    for vi in 1:vertsnum
        if !(vi in todelete)
            nearvs = Lar.inrange(kdtree, V[vi, :], err)
            newverts[nearvs] .= i
            nearvs = setdiff(nearvs, vi)
            todelete = union(todelete, nearvs)
            i = i + 1
        end
    end
    nV = V[setdiff(collect(1:vertsnum), todelete), :]

    # merge congruent edges
    edges = Array{Tuple{Int, Int}, 1}(undef, edgenum)
    oedges = Array{Tuple{Int, Int}, 1}(undef, edgenum)
    for ei in 1:edgenum
        v1, v2 = EV[ei, :].nzind
        edges[ei] = Tuple{Int, Int}(sort([newverts[v1], newverts[v2]]))
        oedges[ei] = Tuple{Int, Int}(sort([v1, v2]))
    end
    nedges = union(edges)
    nedges = filter(t->t[1]!=t[2], nedges)
    nedgenum = length(nedges)
    nEV = spzeros(Int8, nedgenum, size(nV, 1))
    # maps pairs of vertex indices to edge index
    etuple2idx = Dict{Tuple{Int, Int}, Int}()
    # builds `edge_map`
    for ei in 1:nedgenum
        nEV[ei, collect(nedges[ei])] .= 1
        etuple2idx[nedges[ei]] = ei
    end
    for i in 1:length(edge_map)
        row = edge_map[i]
        row = map(x->edges[x], row)
        row = filter(t->t[1]!=t[2], row)
        row = map(x->etuple2idx[x], row)
        edge_map[i] = row
    end
    # return new vertices and new edges
    return Lar.Points(nV), nEV
end

"""
    biconnected_components(EV::Lar.ChainOp)

Compute the biconnected components of the `EV` graph, represented
by edges as pairs of vertices.
"""
function biconnected_components(EV::Lar.ChainOp)

    ps = Array{Tuple{Int, Int, Int}, 1}()
    es = Array{Tuple{Int, Int}, 1}()
    todel = Array{Int, 1}()
    visited = Array{Int, 1}()
    bicon_comps = Array{Array{Int, 1}, 1}()
    hivtx = 1

    function an_edge(point) # TODO: fix bug
        # error? : BoundsError: attempt to access 0×0 SparseMatrix ...
        edges = setdiff(EV[:, point].nzind, todel)
        if length(edges) == 0
            edges = [false]
        end
        edges[1]
    end

    function get_head(edge, tail)
        setdiff(EV[edge, :].nzind, [tail])[1]
    end

    function v_to_vi(v)
        i = findfirst(t->t[1]==v, ps)
        # seems findfirst changed from 0 to Nothing
        if typeof(i) == Nothing
            return false
        elseif i == 0
            return false
        else
            return ps[i][2]
        end
    end

    push!(ps, (1,1,1))
    push!(visited, 1)
    exit = false
    while !exit
        edge = an_edge(ps[end][1])
        if edge != false
            tail = ps[end][2]
            head = get_head(edge, ps[end][1])
            hi = v_to_vi(head)
            if hi == false
                hivtx += 1
                push!(ps, (head, hivtx, ps[end][2]))
                push!(visited, head)
            else
                if hi < ps[end][3]
                    ps[end] = (ps[end][1], ps[end][2], hi)
                end
            end
            push!(es, (edge, tail))
            push!(todel, edge)
        else
            if length(ps) == 1
                found = false
                pop!(ps)
                for i in 1:size(EV,2)
                    if !(i in visited)
                        hivtx = 1
                        push!(ps, (i, hivtx, 1))
                        push!(visited, i)
                        found = true
                        break
                    end
                end
                if !found
                    exit = true
                end

            else
                if ps[end][3] == ps[end-1][2]
                    edges = Array{Int, 1}()
                    while true
                        edge, tail = pop!(es)
                        push!(edges, edge)
                        if tail == ps[end][3]
                            if length(edges) > 1
                                push!(bicon_comps, edges)
                            end
                            break
                        end
                    end

                else
                    if ps[end-1][3] > ps[end][3]
                        ps[end-1] = (ps[end-1][1], ps[end-1][2], ps[end][3])
                    end
                end
                pop!(ps)
            end
        end
    end
    bicon_comps = sort(bicon_comps, lt=(x,y)->length(x)>length(y))
    return bicon_comps
end

function get_external_cycle(V::Lar.Points, EV::Lar.ChainOp, FE::Lar.ChainOp)
    FV = abs.(FE)*EV
    vs = sparsevec(mapslices(sum, abs.(EV), dims=1)').nzind
    minv_x1 = maxv_x1 = minv_x2 = maxv_x2 = pop!(vs)
    for i in vs
        if V[i, 1] > V[maxv_x1, 1]
            maxv_x1 = i
        elseif V[i, 1] < V[minv_x1, 1]
            minv_x1 = i
        end
        if V[i, 2] > V[maxv_x2, 2]
            maxv_x2 = i
        elseif V[i, 2] < V[minv_x2, 2]
            minv_x2 = i
        end
    end
    cells = intersect(
        FV[:, minv_x1].nzind,
        FV[:, maxv_x1].nzind,
        FV[:, minv_x2].nzind,
        FV[:, maxv_x2].nzind
    )
    if length(cells) == 1
        return cells[1]
    else
        for c in cells
            if Lar.face_area(V, EV, FE[c, :]) < 0
                return c
            end
        end
    end
end
function pre_containment_test(bboxes)
    n = length(bboxes)
    containment_graph = spzeros(Int8, n, n)

    for i in 1:n
        for j in 1:n
            if i != j && Lar.bbox_contains(bboxes[j], bboxes[i])
                containment_graph[i, j] = 1
            end
        end
    end

    return containment_graph
end
function prune_containment_graph(n, V, EVs, shells, graph)

    for i in 1:n
        an_edge = shells[i].nzind[1]
        origin_index = EVs[i][an_edge, :].nzind[1]
        origin = V[origin_index, :]

        for j in 1:n
            if i != j
                if graph[i, j] == 1
                    shell_edge_indexes = shells[j].nzind
                    ev = EVs[j][shell_edge_indexes, :]

                    if !Lar.point_in_face(origin, V, ev)
                        graph[i, j] = 0
                    end
                end
             end
         end

     end
     return graph
end
function transitive_reduction!(graph)
    n = size(graph, 1)
    for j in 1:n
        for i in 1:n
            if graph[i, j] > 0
                for k in 1:n
                    if graph[j, k] > 0
                        graph[i, k] = 0
                    end
                end
            end
        end
    end
end
function cell_merging(n, containment_graph, V, EVs, boundaries, shells, shell_bboxes)
    function bboxes(V::Lar.Points, indexes::Lar.ChainOp)
        boxes = Array{Tuple{Any, Any}}(undef, indexes.n)
        for i in 1:indexes.n
            v_inds = indexes[:, i].nzind
            boxes[i] = Lar.bbox(V[v_inds, :])
        end
        boxes
    end
    # initiolization
    sums = Array{Tuple{Int, Int, Int}}(undef, 0);
    # assembling child components with father components
    for father in 1:n
        if sum(containment_graph[:, father]) > 0
            father_bboxes = bboxes(V, abs.(EVs[father]')*abs.(boundaries[father]'))
            for child in 1:n
                if containment_graph[child, father] > 0
                    child_bbox = shell_bboxes[child]
                    for b in 1:length(father_bboxes)
                        if Lar.bbox_contains(father_bboxes[b], child_bbox)
                            push!(sums, (father, b, child))
                            break
                        end
                    end
                end
            end
        end
    end
    # offset assembly initialization
    EV = vcat(EVs...)
    edgenum = size(EV, 1)
    facenum = sum(map(x->size(x,1), boundaries))
    FE = spzeros(Int8, facenum, edgenum)
    shells2 = spzeros(Int8, length(shells), edgenum)
    r_offsets = [1]
    c_offset = 1
    # submatrices construction
    for i in 1:n
        min_row = r_offsets[end]
        max_row = r_offsets[end] + size(boundaries[i], 1) - 1
        min_col = c_offset
        max_col = c_offset + size(boundaries[i], 2) - 1
        FE[min_row:max_row, min_col:max_col] = boundaries[i]
        shells2[i, min_col:max_col] = shells[i]
        push!(r_offsets, max_row + 1)
        c_offset = max_col + 1
    end
    # offsetting assembly of component submatrices
    for (f, r, c) in sums
        FE[r_offsets[f]+r-1, :] += shells2[c, :]
    end
    return EV, FE
end

# function decomposition

function componentgraph(V, copEV, bicon_comps)
    # arrangement of isolated components
	n = size(bicon_comps, 1)
   	shells = Array{Lar.Chain, 1}(undef, n)
	boundaries = Array{Lar.ChainOp, 1}(undef, n)
	EVs = Array{Lar.ChainOp, 1}(undef, n)
    # for each component
	for p in 1:n
		ev = copEV[sort(bicon_comps[p]), :]
        # computation of 2-cells
		fe = Lar.Arrangement.minimal_2cycles(V, ev)
        # exterior cycle
		shell_num = Lar.Arrangement.get_external_cycle(V, ev, fe)
        # decompose each fe (co-boundary local to component)
		EVs[p] = ev
		tokeep = setdiff(1:fe.m, shell_num)
		boundaries[p] = fe[tokeep, :]
		shells[p] = fe[shell_num, :]
    end
    # computation of bounding boxes of isolated components
	shell_bboxes = []
	for i in 1:n
    	vs_indexes = (abs.(EVs[i]')*abs.(shells[i])).nzind
   		push!(shell_bboxes, Lar.bbox(V[vs_indexes, :]))
	end
    # computation and reduction of containment graph
	containment_graph = pre_containment_test(shell_bboxes)
	containment_graph = prune_containment_graph(n, V, EVs, shells, containment_graph)
	transitive_reduction!(containment_graph)
	return n, containment_graph, V, EVs, boundaries, shells, shell_bboxes
end

function cleandecomposition(V, copEV, sigma, edge_map)
    # Deletes edges outside sigma area
    todel = []
    new_edges = []
    map(i->new_edges=union(new_edges, edge_map[i]), sigma.nzind)
    ev = copEV[new_edges, :]
    for e in 1:copEV.m
        if !(e in new_edges)

            vidxs = copEV[e, :].nzind
            v1, v2 = map(i->V[vidxs[i], :], [1,2])
            centroid = .5*(v1 + v2)

            if ! Lar.point_in_face(centroid, V, ev)
                push!(todel, e)
            end
        end
    end

    for i in reverse(todel)
        for row in edge_map

            filter!(x->x!=i, row)

            for j in 1:length(row)
                if row[j] > i
                    row[j] -= 1
                end
            end
        end
    end

    V, copEV = Lar.delete_edges(todel, V, copEV)
	return V,copEV
end

function planar_arrangement_1( V, copEV,
		sigma::Lar.Chain=spzeros(Int8, 0),
		return_edge_map::Bool=false,
		multiproc::Bool=false)
	# data structures initialization
	edgenum = size(copEV, 1)
	edge_map = Array{Array{Int, 1}, 1}(undef,edgenum)
	rV = Lar.Points(zeros(0, 2))
	rEV = SparseArrays.spzeros(Int8, 0, 0)
	finalcells_num = 0

	# spaceindex computation
	model = (convert(Lar.Points,V'),Lar.cop2lar(copEV))
	bigPI = Lar.spaceindex(model::Lar.LAR)

    # multiprocessing of edge fragmentation
    if (multiproc == true)
        in_chan = Distributed.RemoteChannel(()->Channel{Int64}(0))
        out_chan = Distributed.RemoteChannel(()->Channel{Tuple}(0))
        ordered_dict = SortedDict{Int64,Tuple}()
        @async begin
            for i in 1:edgenum
                put!(in_chan,i)
            end
            for p in distributed.workers()
                put!(in_chan,-1)
            end
        end
        for p in distributed.workers()
            @async Base.remote_do(frag_edge_channel, p, in_chan, out_chan, V, copEV, bigPI)
        end
        for i in 1:edgenum
            frag_done_job = take!(out_chan)
            ordered_dict[frag_done_job[1]] = frag_done_job[2]
        end
        for (dkey, dval) in ordered_dict
            i = dkey
            v, ev = dval
            newedges_nums = map(x->x+finalcells_num, collect(1:size(ev, 1)))
            edge_map[i] = newedges_nums
            finalcells_num += size(ev, 1)
            rV, rEV = Lar.skel_merge(rV, rEV, v, ev)
        end
    else
        # sequential (iterative) processing of edge fragmentation
        for i in 1:edgenum
            v, ev = frag_edge(V, copEV, i, bigPI)
            newedges_nums = map(x->x+finalcells_num, collect(1:size(ev, 1)))
            edge_map[i] = newedges_nums
            finalcells_num += size(ev, 1)
            rV = convert(Lar.Points, rV)
            rV, rEV = Lar.skel_merge(rV, rEV, v, ev)
        end
    end
    # merging of close vertices and edges (2D congruence)
    V, copEV = rV, rEV
    V, copEV = merge_vertices!(V, copEV, edge_map)
	return V,copEV,sigma,edge_map
end

function planar_arrangement_2(V, copEV,bicon_comps, edge_map,
		sigma::Lar.Chain=spzeros(Int8, 0))

    edges = sort(union(bicon_comps...))
    todel = sort(setdiff(collect(1:size(copEV,1)), edges))

    for i in reverse(todel)
        for row in edge_map

            filter!(x->x!=i, row)

            for j in 1:length(row)
                if row[j] > i
                    row[j] -= 1
                end
            end
        end
    end

	bicon_comps = Lar.Arrangement.biconnected_components(copEV)

	# component graph
	n, containment_graph, V, EVs, boundaries, shells, shell_bboxes=Lar.Arrangement.componentgraph(V,copEV,bicon_comps)

	copEV, FE = Lar.Arrangement.cell_merging(
	   	n, containment_graph, V, EVs, boundaries, shells, shell_bboxes)

	return V,copEV,FE
end

"""
    planar_arrangement(V::Points, EV::ChainOp, [sigma::Chain], [return_edge_map::Bool], [multiproc::Bool])

Compute the arrangement on the given cellular complex 1-skeleton in 2D.

A cellular complex is arranged when the intersection of every possible pair of cell
of the complex is empty and the union of all the cells is the whole Euclidean space.
The basic method of the function without the `sigma`, `return_edge_map` and `multiproc` arguments
returns the full arranged complex `V`, `EV` and `FE`.

## Additional arguments:
- `sigma::Chain`: if specified, `planar_arrangement` will delete from the output every edge and face outside this cell. Defaults to an empty cell.
- `return_edge_map::Bool`: makes the function return also an `edge_map` which maps the edges of the imput to the one of the output. Defaults to `false`.
- `multiproc::Bool`: Runs the computation in parallel mode. Defaults to `false`.
"""
function planar_arrangement(
        V::Lar.Points,
        copEV::Lar.ChainOp,
        sigma::Lar.Chain=spzeros(Int8, 0),
        return_edge_map::Bool=false,
        multiproc::Bool=false)

    #planar_arrangement_1
	V,copEV,sigma,edge_map=Lar.Arrangement.planar_arrangement_1(V,copEV,sigma,return_edge_map,multiproc)
    # cleandecomposition
	if sigma.n > 0
		V,copEV=Lar.Arrangement.cleandecomposition(V, copEV, sigma, edge_map)
	end

    bicon_comps = Lar.Arrangement.biconnected_components(copEV)
    # EV = Lar.cop2lar(copEV)
    # V,bicon_comps = Lar.biconnectedComponent((V,EV))

	if isempty(bicon_comps)
    	println("No biconnected components found.")
    	if (return_edge_map)
    	    return (nothing, nothing, nothing, nothing)
    	else
    	    return (nothing, nothing, nothing)
    	end
	end
    #Planar_arrangement_2
	V,copEV,FE=Lar.Arrangement.planar_arrangement_2(V,copEV,bicon_comps,edge_map,sigma)
    println("TEST EULERO PLANAR START")
    Lar.test_eulero(V,copEV, FE)
    Lar.test_eulero_face4face(V,copEV, FE)
    println("TEST EULERO PLANAR END")
	if (return_edge_map)
	     return V, copEV, FE, edge_map
	else
	     return V, copEV, FE
	end
end


text:
module SI

    TSSGP = exp(841.2869278)                                # 26 sporadic group Product
    HFP = exp(674.5210288)                                  # Happy Family product
    O_M = 80801742479451287588645990496171075700575436800000000 #2^46 · 3^20 · 5^9 · 7^6 · 11^2 · 13^3 · 17 · 19 · 23 · 29 · 31 · 41 · 47 · 59 · 71
    O_B = 4154781481226426191177580544000000                #2^41 · 3^13 · 5^6 · 7^2 · 11 · 13 · 17 · 19 · 23 · 31 · 47
    ΔνCs = 9192631770e0;                                    #  Δν(133Cs)hfs=9192631770e0 s−1
    λe = 2.4263102367e-12;                                  # Electron Compton wavelength in m
    ƛe = 3.861592046068738e-13;                             # ƛe ≡ ħ/m_ec Reduced Electron Compton wavelength
    ElementaryCharge = 1.602176634e-19;                     #  coulomb (C). or A⋅s
    c = 299792458e0;                                        # m⋅s−1
    SpeedOfLight = 2.99792458e8;                            # m / s 299 792 458 m/s
    GravitationalConstant = 6.67408e-11;                    # m^3 / kg^-1 s^-2 or m^3 kg^-1 s^-2
    SanchezGravitationalConstant = 6.675453818e-11;         # m^3 / kg^-1 s^-2 or m^3 kg^-1 s^-2
    h = 6.62607015e-34;                                     # kg⋅m2⋅s−1
    PlanckConstantH = 6.62607015e-34;                       # J . s
    PlanckConstantHbar = 1.05457162825e-34;                 # J . s
    AstronomicalUnit = 1.49597870691e11;                    # m
    LightYear = 9.46053620707e15;                           # m
    Parsec = 3.08567758135e16;                              # m
    Jansky = 10e-26;                                        # W.m^−2.Hz^−1  \text{ Jansky}=10^{-26}\text{ Watts meters}^{-2}\text{ Hertz}^{-1}
    GravAccel = 9.80665e0;                                  # m / s^2
    ElectronVolt = 1.602176487e-19;                         # kg m^2 / s^2
    MassElectron = 9.10938356e-31;                          # kg
    MassMuon = 1.83615267e-28;                              # kg
    MassProton = 1.672621898e-27;                           # kg
    MassNeutron = 1.674927471e-27;                          # kg
    MassTau = 3.16773502e-27;                               # kg
    MassHydrogen = 1.6737236e-27;                           # kg
    Rydberg = 2.17987196968e-18;                            # kg m^2 / s^2
    k = 1.380649e-23;                                       # kg⋅m2⋅K−1⋅s−2
    Boltzmann = 1.380649e-23;                               # J / K                  [kg cm^2 / K s^2]
    AvogadroNumberNA = 6.02214076e23;                       # mol−1  reciprocal mole (mol−1)
    LuminousEfficacyKcd = 683e0;                            # cd⋅sr⋅s3⋅kg−1⋅m−2
    Minute = 6e1;                                           # s
    Hour = 3.6e3;                                           # s
    Day = 8.64e4;                                           # s
    Week = 6.048e5;                                         # s
    Inch = 2.54e-2;                                         # m
    Foot = 3.048e-1;                                        # m
    Yard = 9.144e-1;                                        # m
    Mile = 1.609344e3;                                      # m
    NauticalMile = 1.852e3;                                 # m
    Fathom = 1.8288e0;                                      # m
    Mil = 2.54e-5;                                          # m
    Point = 3.52777777778e-4;                               # m
    Texpoint = 3.51459803515e-4;                            # m
    Micron = 1e-6;                                          # m
    Angstrom = 1e-10;                                       # m
    Hectare = 1e4;                                          # m^2
    Acre = 4.04685642241e3;                                 # m^2
    Barn = 1e-28;                                           # m^2
    Liter = 1e-3;                                           # m^3
    UsGallon = 3.78541178402e-3;                            # m^3
    Quart = 9.46352946004e-4;                               # m^3
    Pint = 4.73176473002e-4;                                # m^3
    Cup = 2.36588236501e-4;                                 # m^3
    FluidOunce = 2.95735295626e-5;                          # m^3
    Tablespoon = 1.47867647813e-5;                          # m^3
    Teaspoon = 4.92892159375e-6;                            # m^3
    CanadianGallon = 4.54609e-3;                            # m^3
    UkGallon = 4.546092e-3;                                 # m^3
    MilesPerHour = 4.4704e-1;                               # m / s
    KilometersPerHour = 2.77777777778e-1;                   # m / s
    Knot = 5.14444444444e-1;                                # m / s
    PoundMass = 4.5359237e-1;                               # kg
    OunceMass = 2.8349523125e-2;                            # kg
    Ton = 9.0718474e2;                                      # kg
    MetricTon = 1e3;                                        # kg
    UkTon = 1.0160469088e3;                                 # kg
    TroyOunce = 3.1103475e-2;                               # kg
    Carat = 2e-4;                                           # kg
    UnifiedAtomicMass = 1.660539040e-27;                    # kg per u, Da or AMU [See Dalton]
    GramForce = 9.80665e-3;                                 # kg m / s^2
    PoundForce = 4.44822161526e0;                           # kg m / s^2
    KilopoundForce = 4.44822161526e3;                       # kg m / s^2
    Poundal = 1.38255e-1;                                   # kg m / s^2
    Calorie = 4.1868e0;                                     # kg m^2 / s^2
    Btu = 1.05505585262e3;                                  # kg m^2 / s^2
    Therm = 1.05506e8;                                      # kg m^2 / s^2
    Horsepower = 7.457e2;                                   # kg m^2 / s^3
    Bar = 1e5;                                              # kg / m s^2
    StdAtmosphere = 1.01325e5;                              # kg / m s^2
    Torr = 1.33322368421e2;                                 # kg / m s^2
    MeterOfMercury = 1.33322368421e5;                       # kg / m s^2
    InchOfMercury = 3.38638815789e3;                        # kg / m s^2
    InchOfWater = 2.490889e2;                               # kg / m s^2
    Psi = 6.89475729317e3;                                  # kg / m s^2
    Poise = 1e-1;                                           # kg m^-1 s^-1
    Stokes = 1e-4;                                          # m^2 / s
    Stilb = 1e4;                                            # cd / m^2
    Lumen = 1e0;                                            # cd sr
    Lux = 1e0;                                              # cd sr / m^2
    Phot = 1e4;                                             # cd sr / m^2
    Footcandle = 1.076e1;                                   # cd sr / m^2
    Lambert = 1e4;                                          # cd sr / m^2
    Footlambert = 1.07639104e1;                             # cd sr / m^2
    Curie = 3.7e10;                                         # 1 / s
    Roentgen = 2.58e-4;                                     # A s / kg
    Rad = 1e-2;                                             # m^2 / s^2
    SolarMass = 1.98892e30;                                 # kg
    BohrRadius = 5.291772083e-11;                           # m
    Newton = 1e0;                                           # kg m / s^2
    Dyne = 1e-5;                                            # kg m / s^2
    Joule = 1e0;                                            # kg m^2 / s^2
    Erg = 1e-7;                                             # kg m^2 / s^2
    StefanBoltzmannConstant = 5.67040047374e-8;             # kg / K^4 s^3
    ThomsonCrossSection = 6.65245893699e-29;                # m^2
    BohrMagneton = 9.27400899e-24;                          # A m^2
    NuclearMagneton = 5.05078317e-27;                       # A m^2
    ElectronMagneticMoment = 9.28476362e-24;                # A m^2
    ProtonMagneticMoment = 1.410606633e-26;                 # A m^2
    Faraday = 9.64853429775e4;                              # A s / mol
    ElectronCharge = 1.602176487e-19;                       # A s
    VacuumPermittivity = 8.854187817e-12;                   # A^2 s^4 / kg m^3
    VacuumPermeability = 1.25663706144e-6;                  # kg m / a^2 s^2
    Debye = 3.33564095198e-30;                              # A s^2 / m^2
    Gauss = 1e-4;                                           # kg / A s^2
    ThomsonCrossSection = 6.65245893699e-29;                # m^2
    KotovCosmicPeriodicity = 9600.061e0;                    # s
    CmbTemperature = 2.7255;
    SanchezCmbTemperature = 2.725820831e0;                  # K
    UniverseSanchezMass = 8.7936e52;                        # kg
    SanchezElectrConstant = 137.035999139e0;                # dimensionless Sanchez Electric Constant
    α = 7.2973525664e-3;                                    # Fine Structure Constant
    ε0 = 8.854187817e-12;                                   # F m-1 electric constant
    μ0 = 12.566370614e-7;                                   # N A-2     magnetic constant
    γ = 0.5772156649015328606065120900824024310421593359e0; # Euler–Mascheroni constant
    e = 2.7182818284590450907955982984276488423343144531e0; # Euler
    a = 137.035999139e0;                                    # Sanchez Electric Constant
    a_G = 1.32613243113089e-69                              # a_G gravitational coupling constant
    #α^-1 = 137.035999139e0                                 # Inverse fine-structure Constant
end


text:
module COMCall

# Imports

import Base: show, convert, getindex

# Exports

export COM, getindex, BaseIID, QueryInterface, CoInitialize, CoCreateInstance

# Libraries

const l_ole32 = "ole32"
const l_kernel32 = "kernel32"

# Implementation

include("comtypes.jl")
include("comaux.jl")
include("com.jl")

# Module initialization

COM = COMGlobal()
const DefaultLCID = get_default_lcid()

function __init__()
    CoInitialize()
    global COM
    COM.initialized = true
end

end # module COMCall


text:
module OVERT

include("overapprox_nd.jl")
export overapprox, OverApproximation

end


text:
for f in ALL_SQUARES
    for t in ALL_SQUARES
        if t == f
            continue
        end
        m = Move(f, t)
        @test from(m) == f
        @test to(m) == t
        @test !ispromotion(m)
        @test m == movefromstring(tostring(m))
        for prom in [QUEEN, ROOK, BISHOP, KNIGHT]
            m = Move(f, t, prom)
            @test from(m) == f
            @test to(m) == t
            @test ispromotion(m)
            @test promotion(m) == prom
            @test m == movefromstring(tostring(m))
        end
    end
end


text:
using DynamicalSystemsBase
using Test, StaticArrays, LinearAlgebra, OrdinaryDiffEq, SimpleDiffEq
using DynamicalSystemsBase: CDS, DDS
using DynamicalSystemsBase: orthonormal
using DynamicalSystemsBase.Systems: hoop, hoop_jac, hiip, hiip_jac
using DynamicalSystemsBase.Systems: loop, loop_jac, liip, liip_jac

println("\nTesting dynamical systems...")

algs = (Vern9(), Tsit5(), SimpleATsit5())

for alg in algs
u0 = [0, 10.0, 0]
p = [10, 28, 8/3]
u0h = ones(2)
ph = [1.4, 0.3]

FUNCTIONS = [liip, liip_jac, loop, loop_jac, hiip, hiip_jac, hoop, hoop_jac]
INITCOD = [u0, u0h]
PARAMS = [p, ph]

@testset "Dynamical system integrators" begin
for i in 1:8
    @testset "$alg combination $i" begin
        # Here we test the constructors with all possible cases of IIP/Autodiff
        sysindx = i < 5 ? 1 : 2
        if i < 5
            if isodd(i)
                ds = CDS(FUNCTIONS[i], INITCOD[sysindx], PARAMS[sysindx])
            else
                ds = CDS(FUNCTIONS[i-1], INITCOD[sysindx], PARAMS[sysindx], FUNCTIONS[i])
            end
        else
            if isodd(i)
                ds = DDS(FUNCTIONS[i], INITCOD[sysindx], PARAMS[sysindx])
            else
                ds = DDS(FUNCTIONS[i-1], INITCOD[sysindx], PARAMS[sysindx], FUNCTIONS[i])
            end
        end

        isad = DynamicalSystemsBase.isautodiff(ds)
        iip = DynamicalSystemsBase.isinplace(ds)
        @test isodd(i) ? isad : !isad
        @test mod(i-1, 4) < 2 ? iip : !iip
        J = jacobian(ds)
        @test typeof(J) <: (iip ? Matrix : SMatrix)

        tinteg = tangent_integrator(ds, orthonormal(dimension(ds), dimension(ds)); alg = alg)
        tuprev = deepcopy(get_state(tinteg))
        step!(tinteg)
        @test tuprev != get_state(tinteg)

        integ = integrator(ds; alg = alg)
        uprev = deepcopy(get_state(integ))
        step!(integ)
        @test uprev != get_state(integ)

        # Test that progressing tangent integrator gives same state as normal integrator
        if i < 5
            tt = tinteg.t
            while integ.t < tt
                step!(integ)
            end
            @test get_state(tinteg) ≈ integ(tt) atol = 1e-2
        else
            @test get_state(tinteg) == get_state(integ)
        end

        # Test parallel integrators
        pinteg = parallel_integrator(ds, [copy(INITCOD[sysindx]), copy(INITCOD[sysindx])]; alg = alg)
        puprev = deepcopy(get_state(pinteg))
        step!(pinteg)
        @test get_state(pinteg, 1) == get_state(pinteg, 2) == get_state(pinteg)
        @test puprev != get_state(pinteg)
        if i ∈ (1,2)
            # Interpolation does not work for Vector{SVector} so it is tested for matrix
            tt = pinteg.t
            while integ.t < tt
                step!(integ)
            end
            @test get_state(pinteg, 1) ≈ integ(tt) atol = 1e-2
        elseif i > 4
            @test get_state(pinteg) == get_state(integ)
        end
        u2 = 2get_state(pinteg, 2)
        set_state!(pinteg, u2, 2)
        @test get_state(pinteg, 2) == u2
    end
end

end
end


text:
using DelimitedFiles
using PyPlot
using RAFF

datafile = "/tmp/output.txt"

fp = open(datafile, "r")

N = parse(Int, readline(fp))

M = readdlm(fp)

close(fp)

x = M[:, 1]
y = M[:, 2]
c = M[:, 3]

sol = [779.616, 5315.36, 0.174958, 2.52718]

n, model, modelstr = RAFF.model_list["logistic"]

modl1 = (x) -> model(x, sol)
modl2 = (x) -> model(x, θSol)

t = minimum(x):0.01:maximum(x)
PyPlot.plot(t, modl1.(t), "r", label="RAFF")

θSol = [1000.0, 5000.0, 0.2, 3.0]
PyPlot.plot(t, modl2.(t), "b--", label="True")

θLS = [-959.07, 8151.03, 0.0927191, 0.940711]
modl3 = (x) -> model(x, θLS)

PyPlot.plot(t, modl3.(t), "g-.", label="Least Squares")

PyPlot.legend(loc=4)

PyPlot.scatter(x[c .== 0.0], y[c .== 0.0], color=PyPlot.cm."Paired"(0.1), marker="o", s=50.0, linewidths=0.2,
               alpha=1.0)

PyPlot.scatter(x[c .== 1.0], y[c .== 1.0], color=PyPlot.cm."Paired"(0.5), marker="^", s=50.0, linewidths=0.2,
               alpha=1.0)

PyPlot.show()

PyPlot.savefig("/tmp/figure.png", DPI=100)


text:
using LinearAlgebra
A = [1 -2  2; 1 -1  2; -1  1  1];
det(A)

b = [5, 7, 5];
v = A\b

transpose(v)

A1 = A[:, 2:3]

(A1\b)'

A2 = A[1:2,:]; b2 = b[1:2];
(A2\b2)'

Alu = lu(A)

Alu.U # similar for the lower, i.e. Alu.L

Alu.L*Alu.U  # => A (original matrix)

Alu.P

#=
Suppose we have equations:

 x - 2y + 2z = 5
 x -  y + 2z = 3
-x +  y + z  = 6

=#

b = [5; 3; 6];

# Ax = b => LUx = b :  x = inv(U)*inv(L)*b

(x,y,z) = inv(Alu.U)*inv(Alu.L)*b

# Compute the eigenvalues of A
# (These are complex numbers)
U = eigvals(A)

# ... and the eigenvectors
V = eigvecs(A)

#=
The eigenvectors are the columns of the V matrix.
=#

A*V[:,1] - U[1]*V[:,1]

#=
That is, all the real and imaginary parts are of the e-16 order,
so this is in effect a zero matrix of complex numbers.
=#

A = [1 -2  2; 1 -1  2; -1  1  1];
Diagonal(diag(A))

diag(A)

n = 2000;
B = randn(n,n);
B1 = B + B';
B2 = copy(B1);
B2[1,2] += 1eps();
B2[2,1] += 2eps();
issymmetric(B1)'; # => true
issymmetric(B2)'; # => false

@time eigvals(B1);

@time eigvals(B2);

@time eigvals(Symmetric(B2));

# Signal Processing
using PyPlot

fq = 500.0;
N = 512;
T = 6 / fq;
t = collect(range(0, stop=T, length=N));

x1 = sin.(2π * fq * t);
x2 = cos.(8π * fq * t);
x3 = cos.(16π * fq * t);
x = x1 + 0.4*x2 + 0.2*x3;

PyPlot.plot(t,x)

## using Pkg; Pkg.add("FFTW")
using FFTW

X = rfft(x)
sr = N / T

fd = collect(range(0, stop = sr/2, length = div(N,2) + 1))
yy = abs.(X);

plot(fd[1:64], yy[1:64])

using DSP

ns = 0.1*randn(length(x));
xn = x + ns;
M = 16;
xm = ones(Float64, M) / M;
xf = conv(xn, xm)
plot(1:length(xf), xf)

responsetype = Lowpass(0.2)

prototype = Elliptic(4, 0.5, 30)
tf = convert(TFFilter, digitalfilter(responsetype, prototype))

numerator_coefs   = coefb(tf)
denominator_coefs = coefa(tf)

responsetype = Bandpass(10, 40; fs=1000)
prototype = Butterworth(4)

xb = filt(digitalfilter(responsetype, prototype), x)›
plot(1:length(xb), xb)

# Image Processing

img = open("Files/lena.pgm");
magic  = chomp(readline(img));
params = chomp(readline(img));
pm = split(params)

# Remember the GSD

try
  global wd = parse(Int64,pm[1]);
  global ht = parse(Int64,pm[2]);
catch
  error("Can't figure out the image dimensions")
end

# Version 1.0 way of defining a byte array
# readbytes!() will read in place

data = Array{UInt8,2}(undef,wd,ht)
readbytes!(img, data, wd*ht);

data = reshape(data,wd,ht);
close(img);

# Define a convolution mask

Gx = [1 2 1; 0 0 0; -1 -2 -1];
Gy = [1 0 -1; 2 0 -2; 1 0 -1];

dout = copy(data);
for i = 2:wd-1
  for j = 2:ht-1
    temp = data[i-1:i+1, j-1:j+1];
    x = sum(Gx.*temp)
    y = sum(Gy.*temp)
    p = Int64(floor(sqrt(x*x + y*y)))
    dout[i,j] = (p < 256) ? UInt8(p) : 0xff
  end
end

# ... and output the result
out = open("lenaX.pgm","w");
println(out,magic);
println(out,params);
write(out,dout);
close(out);

# This only works if you have Imagemagick (or similar) installed
run(`display lenaX.pgm`);

using Plots; gr()

# http://docs.juliadiffeq.org/latest/

#=
OrdinaryDiffEq.jl is part of the JuliaDiffEq common interface,
but can be used independently of DifferentialEquations.jl.

User passes to OrdinaryDiffEq.jl an algorithm to solve
=#

using OrdinaryDiffEq

function ff(d,u,p,t)
  d[1] =  u[1] - u[1]*u[2]
  d[2] = -u[2] + u[1]*u[2] - u[2]*u[3]
  d[3] = -u[3] + u[2]*u[3]
end

u0 = [0.5; 1.0; 2.0];    # Setup the initial conditions
tspan = (0.0,10.0);       # and the time range

#=
In OrdinaryDiffEq.jl, some good "go-to" choices for ODEs are:

AutoTsit5(Rosenbrock23()) handles both stiff and non-stiff equations. This is a good algorithm to use if you know nothing about the equation.
BS3() for fast low accuracy non-stiff.
Tsit5() for standard non-stiff. This is the first algorithm to try in most cases.
Vern7() for high accuracy non-stiff.
Rodas4() for stiff equations with Julia-defined types, events, etc.
radau() for really high accuracy stiff equations (requires installing ODEInterfaceDiffEq.jl)

=#

prob = ODEProblem(ff,u0,tspan)

u = solve(prob, Tsit5());

# Plot API will plot the array
styles = [:solid; :dash; :dot]
N = length(styles)
styles = reshape(styles, 1, N)  # styles is now a 1xN Vector

Plots.plot(u, line = (2,styles))

using Sundials
function exotherm(t, x, dx; n=1, a=1, b=1)
  p = x[2]^n * exp(x[1])
  dx[1] = p - a*x[1]
  dx[2] = -b*p
  return(dx)
end

t = collect(range(0.0; stop=5.0,length=1001))
fexo(t,x,dx) = exotherm(t, x, dx, a=0.6, b=0.1)
x1 = Sundials.cvode(fexo, [0.0, 1.0], t)

PyPlot.plot(x1[:,1])

using Roots, Printf

f(x,a) = exp(x) - a*x

for p = 2.8:-0.02:2.6
  try
    ff(x) = f(x,p)
    @printf "%.2f : %.5f\n" p find_zero(ff,1.0)
  catch
    error("No convergence for parameter value: $p")
  end
end

# There is no solution for a <= exp(1) => 2.7182 .....

function lorenz(du,u,p,t)
 du[1] = 10.0(u[2]-u[1])
 du[2] = u[1]*(28.0-u[3]) - u[2]
 du[3] = u[1]*u[2] - (8/3)*u[3]
end
u0 = [1.0;0.0;0.0]
tspan = (0.0,100.0)
prob = ODEProblem(lorenz,u0,tspan)
sol = solve(prob,CVODE_Adams())
Plots.plot(sol,vars=(1,2,3))

using DifferentialEquations

f(du,u,p,t) = (du .= u)
g(du,u,p,t) = (du .= u)

u0 = rand(4,2);
W = WienerProcess(0.0,0.0,0.0);

prob = SDEProblem(f,g,u0,(0.0,1.0),noise=W)
sol = solve(prob,SRIW1());

# using Plots
# gr()
Plots.plot(sol)

function f(du,u,p,t)
  du[1] = u[1]
end

prob = ODEProblem(f,[0.2],(0.0,10.0))

rate(u,p,t) = 2
affect!(integrator) = (integrator.u[1] = integrator.u[1]/2)
jump = ConstantRateJump(rate,affect!)
jump_prob = JumpProblem(prob,Direct(),jump)

sol = solve(jump_prob,Tsit5())
Plots.plot(sol)

using Calculus

f(x)=sin(x)*cos(x)
derivative(f,1.0)

# Check since d(f) => cos*cos - sin*sin
cos(1.0)^2 - sin(1.0)^2

# Possible to curry the function
df = derivative(f)
df(1.0)

# Also defined is the 2nd derivative
d2f = second_derivative(f)
d2f(1.0)

# Also can use tick notation forhigher derivatives
# e.g. Value of the 3rd derivative
f'''(1.0)

#
# There are 2D functions, argument is a N-vector
# Be careful of name clashes
#
h(x) = (1+x[1])*exp(x[1])*sin(x[2])*cos(x[2])
gd=Calculus.gradient(h)
gd([1.0,1.0])

hs = Calculus.hessian(h)
hs([1.0,1.0])

# It is possible to output the symbolic version of the derivate
differentiate("sin(x)*cos(x)", :x)

# Not that clear but can be simplfied somewhat
# ... although not entirely perfect.
simplify(differentiate("sin(x)*cos(x)", :x))

# These techniques work more than a single variable too
# We get a 2-D array of partial derivatives
# Clearly the terms with a '0' multiplier can be ignored
#
simplify(differentiate("x*exp(-x)*sin(y)", [:x, :y]))

struct D <: Number
  d1::Float64
  d2::Float64
end

import Base: +, /, convert, promote_rule
+(x::D, y::D) = D(x.d1+y.d1, x.d2+y.d2)
/(x::D, y::D) = D(x.d1/y.d1, (y.d1*x.d2 - x.d1*y.d2)/y.d1^2)
convert(::Type{D}, x::Real) = D(x,zero(x))
promote_rule(::Type{D}, ::Type{<:Number}) = D

da = D(17,1)

function hero(x; k::Integer = 10)
  @assert k > 0
  t = (1+x)/2
  for i = 2:k
    t = (t + x/t)/2
  end
  return t
end

Call the function with the D() structure.
db = hero(da)

db.d1^2   # Confirm the solution

How does this work?
Decode it without the 'dual' number

using Printf
function dhero(x; k = 10)
    t  = (1+x)/2
    dt = 1
    @printf "%3d : %.5f : %.5f\n" 1 t dt
    for i = 2:k;
        t  = (t+x/t)/2;
        dt = (dt + (t - x*dt)/t^2)/2;
        @printf "%3d : %.5f : %.5f\n" i t dt
    end
    (t,dt)
end

dhero(17, k=5)

using SymPy

Display Hero's first 4 terms
Gets a little complex after that, try upping M!

M = 4
x = symbols("x")
for i = 1:M
  display(simplify(hero(x, k = i )))
end

using QuadGK
f(x) = sin(x)*(1.0 + cos(x))
quadgk(f,0.0,1.0)

#=
Addition function gives points and weights over the interval [-1,1]
Pick a sigmodial function : 1 - x exp(-|x|)
=#
g(u) = 1 - u*exp(-abs(u))

using PyPlot
x = collect(-1.0:0.1:1.0)
y = g.(x)
PyPlot.plot(x,y)

# The gauss() function creates a tuple of N array of points and weights
(x,w) = gauss(20)
s = sum([w[i]*g(x[i]) for i = 1:20])

# Alternate package which will do multidimension quadratutes
# Written by Steven Johnson (of PyCall, IJulia, etc. )
# It also does 1-D integration

using HCubature
hquadrature(f,0.0,1.0)

# But the power is the n-D quadratures
# Notice that the function expects an array argument

h(x) = 2.0*x[1]*exp(-x[1])*sin(x[2])*cos(x[2])
hcubature(h, [0,0], [1,1])

# Add JuMP#master to get v0.19

using JuMP, Clp

#=
Maximize the 5x+3y function subject to the constraint that: 3x+5y < 7
=#
m = Model(with_optimizer(Clp.Optimizer))

@variable(m, 0 <= x <= 5 );
@variable(m, 0 <= y <= 10 );

@objective(m, Max, 5x + 3y );
@constraint(m, 2x + 5y <= 7.0 );

JuMP.optimize!(m)

println("x = ", JuMP.value(x), " y = ", JuMP.value(y))

JuMP.objective_value(m)

using JuMP, LinearAlgebra, Printf

N = 6;
m = Model()
@variable(m, x[1:N], Bin);      # Define array variable to hold results
profit = [ 5, 3, 2, 7, 4, 4 ];  # Profit vector of size N
weight = [ 2, 8, 4, 2, 5, 6 ];  # Weights vector of size

maxcap = 15;

@objective(m, Max, dot(profit, x));
@constraint(m, dot(weight, x) <= maxcap);

using GLPK
JuMP.optimize!(m, with_optimizer(GLPK.Optimizer))

println("Objective is : ", JuMP.objective_value(m))
println("\nSolution is :")

for i = 1:N
    print("\tx[$i] = ", JuMP.value(x[i]))
    println(", p[$i]/w[$i] = ", profit[i]/weight[i])
end

using Optim

rosenbrock(x) =  (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2
result = Optim.optimize(rosenbrock, zeros(2), BFGS())

# Look at some values across a diagonal (x[1] == x[2]) cut
#
using Printf
for x in 0.0:0.1:1.3
  @printf "%3.1f : %f\n" x rosenbrock([x,x])
end

using SimJulia, ResumableFunctions
using Distributions
using Printf, Random

NUM_CUSTOMERS = 16     # total number of customers generated
NUM_TELLERS   = 2      # number of servers
QUEUE_MAX     = 2      # Maximum size of queue

μ = 0.4                # service rate
λ = 0.9                # arrival rate

arrival_dist = Exponential(1/λ)  # interarrival time distriubtion
service_dist = Exponential(1/μ)  # service time distribution

seed = ccall((:clock,"libc"),Int32,())
Random.seed!(seed);

queue_length = 0;
queue_stack  = Array{Integer,1}(undef,0);

@resumable function visit(env::Environment,
                        teller::Resource,
                        id::Integer,
                        time_arrvl::Float64,
                        dist_serve::Distribution)

# customer arrives
# recall the crazy scoping rules, we can see the array but not the scalar
#
    global queue_length
    @yield timeout(env, time_arrvl)
    @printf "Customer %2d %15s : %.3f\n" id "arrives" now(env)
    if queue_length > 0
        push!(queue_stack,id)
        println("CHECK: Length of the queue is $queue_length")
    end
    queue_length += 1
# customer starts to be served
    @yield request(teller)
    queue_length -= 1
    @printf "Customer %2d %15s : %.3f\n" id "being served" now(env)
#  teller is busy
    @yield timeout(env, rand(dist_serve))
# customer leaves
    @yield release(teller)
    @printf "Customer %2d %15s : %.3f\n" id "leaves" now(env)
end

# initialize simulation <: environment
sim     = Simulation()

# initialize service resources
service = Resource(sim, NUM_TELLERS)

# initialize customers and set arrival time
# customers arrive randomly baed on Poisson distribution
arrival_time = 0.0
for i = 1:NUM_CUSTOMERS
    arrival_time += rand(arrival_dist)
    @process visit(sim, service, i, arrival_time, service_dist)
end

# run the simulation
run(sim)

# Check on which customers had to wait
queue_stack


text:
using Test, DataAPI

@testset "DataAPI" begin

@testset "defaultarray" begin

    @test DataAPI.defaultarray(Int64, 1) == Vector{Int64}
    @test DataAPI.defaultarray(Vector{Int64}, 1) == Vector{Vector{Int64}}
    @test DataAPI.defaultarray(String, 2) == Matrix{String}

end

@testset "refarray" begin

    A = Int64[]
    @test DataAPI.refarray(A) === A
    A = String[]
    @test DataAPI.refarray(A) === A

end

@testset "refvalue" begin

    A = Int64[1, 2, 3]
    R = DataAPI.refarray(A)
    @test DataAPI.refvalue(A, R[1]) === R[1]

end

@testset "levels" begin

    @test DataAPI.levels(1:1) ==
        DataAPI.levels([1]) ==
        DataAPI.levels([1, missing]) ==
        DataAPI.levels([missing, 1]) ==
        [1]
    @test DataAPI.levels(2:-1:1) ==
        DataAPI.levels([2, 1]) ==
        DataAPI.levels(Any[2, 1]) ==
        DataAPI.levels([2, missing, 1]) ==
        [1, 2]
    @test DataAPI.levels([missing, "a", "c", missing, "b"]) == ["a", "b", "c"]
    @test DataAPI.levels([Complex(0, 1), Complex(1, 0), missing]) ==
        [Complex(0, 1), Complex(1, 0)]
    @test typeof(DataAPI.levels([1])) ===
        typeof(DataAPI.levels([1, missing])) ===
        Vector{Int}
    @test typeof(DataAPI.levels(["a"])) ===
        typeof(DataAPI.levels(["a", missing])) ===
        Vector{String}
    @test typeof(DataAPI.levels(Real[1])) ===
        typeof(DataAPI.levels(Union{Real,Missing}[1, missing])) ===
        Vector{Real}
    @test typeof(DataAPI.levels(trues(1))) === Vector{Bool}
    @test isempty(DataAPI.levels([missing]))
    @test isempty(DataAPI.levels([]))

end

@testset "Between" begin

    for x in (1, :a, "a"), y in (1, :a, "a")
        b = DataAPI.Between(x, y)
        @test b.first == (x isa Int ? x : Symbol(x))
        @test b.last == (y isa Int ? y : Symbol(y))
    end

    @test_throws MethodError DataAPI.Between(true, 1)
    @test_throws MethodError DataAPI.Between(:a, 0x01)

end

@testset "All" begin

    @test DataAPI.All().cols == ()
    @test DataAPI.All(1).cols == (1,)
    @test DataAPI.All([1,2,3], :a).cols == ([1, 2, 3], :a)

    a = DataAPI.All(DataAPI.All())
    @test length(a.cols) == 1
    @test a.cols[1] isa DataAPI.All
    @test a.cols[1].cols == ()

end

end # @testset "DataAPI"


text:
using Documenter, Heterogeneous

makedocs(
    modules = [Heterogeneous],
    format = :html,
    sitename = "Heterogeneous.jl",
    pages = [
        "Home"    => "index.md",
    ],
    doctest = true
)

deploydocs(
    repo = "github.com/vchuravy/Heterogeneous.jl.git",
    julia = "",
    osname = "",
    # no need to build anything here, re-use output of `makedocs`
    target = "build",
    deps = nothing,
    make = nothing
)


text:
module UnicodeExtras

using ICU

export
    UnicodeText,
    decode,
    encode,
    foldcase,
    set_locale, # from ICU
    titlecase

import Base: cmp,
    convert,
    endof,
    getindex,
    isequal,
    isless,
    length,
    lowercase,
    show,
    uppercase

## lowercase, uppercase, foldcase, titlecase ##
#
# Example:
#
#   using UnicodeExtras
#   uppercase("testingß")  # "TESTINGSS"
#   set_locale("tr")       # set locale to Turkish
#   uppercase("testingß")  # "TESTİNGSS"
#
# Note that "ß" gets converted to "SS" in the first call to uppercase,
# and "i" gets converted to "İ" (dotted capital I) in the second call
# after the locale is set to Turkish.
#

 foldcase(s::ASCIIString) = foldcase(utf8(s))
titlecase(s::ASCIIString) = titlecase(utf8(s))

 foldcase(s::UTF8String)  = ucasemap_utf8FoldCase(s)
lowercase(s::UTF8String)  = ucasemap_utf8ToLower(s)
uppercase(s::UTF8String)  = ucasemap_utf8ToUpper(s)
titlecase(s::UTF8String)  = ucasemap_utf8ToTitle(s)

 foldcase(s::UTF16String) = u_strFoldCase(s)
lowercase(s::UTF16String) = u_strToLower(s)
uppercase(s::UTF16String) = u_strToUpper(s)
titlecase(s::UTF16String) = u_strToTitle(s)

## UnicodeText ##

immutable UnicodeText
    data::Array{Uint16,1}
end

UnicodeText(s::ByteString) = UnicodeText(utf16(s).data)
UnicodeText(s::UTF16String) = UnicodeText(s.data)

convert(::Type{UTF8String},  t::UnicodeText) = utf8(utf16(t.data))
convert(::Type{UTF16String}, t::UnicodeText) = UTF16String(t.data)

cmp(a::UnicodeText, b::UnicodeText) = ucol_strcoll(ICU.collator, a.data, b.data)
# is this right?
cmp(t::UnicodeText, s::String) = cmp(UTF16String(t.data), s)
cmp(s::String, t::UnicodeText) = cmp(t, s)

endof(t::UnicodeText) = length(t)

isequal(a::UnicodeText, b::UnicodeText) = cmp(a,b) == 0
isequal(a::UnicodeText, b::String)      = cmp(a,b) == 0
isequal(a::String, b::UnicodeText)      = cmp(a,b) == 0

isless(a::UnicodeText, b::UnicodeText)  = cmp(a,b) < 0
isless(a::UnicodeText, b::String)       = cmp(a,b) < 0
isless(a::String, b::UnicodeText)       = cmp(a,b) < 0

function length(t::UnicodeText)
    bi = ubrk_open(UBRK_CHARACTER, ICU.locale, t.data)
    n = 0
    while ubrk_next(bi) > 0
        n += 1
    end
    ubrk_close(bi)
    n
end

getindex(t::UnicodeText, i::Int) = getindex(t, i:i)
function getindex(t::UnicodeText, r::Range1{Int})
    bi = ubrk_open(UBRK_CHARACTER, ICU.locale, t.data)
    offset = 0
    for i = 1:first(r)-1
        offset = ubrk_next(bi)
        offset > 0 || break
    end
    a = offset + 1
    for i = 1:last(r)-first(r)+1
        offset = ubrk_next(bi)
        offset > 0 || break
    end
    b = offset
    ubrk_close(bi)
    SubString(UTF16String(t.data), a, b)
end

for f in (:foldcase,:lowercase,:titlecase,:uppercase)
    @eval ($f)(t::UnicodeText) = UnicodeText(($f)(utf16(t)))
end

show(io::IO, t::UnicodeText) = show(io, UTF16String(t.data))

## encodings ##

function transcode(src::Array{Uint8,1}, from::ASCIIString, to::ASCIIString)
    src_cnv = ucnv_open(from)
    dst_cnv = ucnv_open(to)
    src_buf = IOBuffer(src)
    dst_buf = IOBuffer()
    Base.ensureroom(dst_buf, length(src))
    pivot = ICU.UConverterPivot(16)
    while ucnv_convertEx(dst_cnv, src_cnv, dst_buf, src_buf, pivot)
        Base.ensureroom(dst_buf, dst_buf.size + length(src))
    end
    ucnv_close(src_cnv)
    ucnv_close(dst_cnv)
    takebuf_array(dst_buf)
end

function decode(b::Array{Uint8,1}, encoding::ASCIIString)
    bytestring(transcode(b, encoding, "utf8"))
end

function encode(s::ByteString, encoding::ASCIIString)
    transcode(s.data, "utf8", encoding)
end

end # module


text:
export BrickletSegmentDisplay4x7Segments
struct BrickletSegmentDisplay4x7Segments
    segments::Vector{Integer}
    brightness::Integer
    colon::Bool
end

export BrickletSegmentDisplay4x7Identity
struct BrickletSegmentDisplay4x7Identity
    uid::String
    connected_uid::String
    position::Char
    hardware_version::Vector{Integer}
    firmware_version::Vector{Integer}
    device_identifier::Integer
end

export BrickletSegmentDisplay4x7
"""
Four 7-segment displays with switchable colon
"""
mutable struct BrickletSegmentDisplay4x7 <: TinkerforgeDevice
    ipcon::IPConnection
    deviceInternal::PyObject

    """
    Creates an object with the unique device ID *uid* and adds it to
    the IP Connection *ipcon*.
    """
    function BrickletSegmentDisplay4x7(uid::String, ipcon::IPConnection)
        package = pyimport("tinkerforge.bricklet_segment_display_4x7")
        deviceInternal = package.BrickletSegmentDisplay4x7(uid, ipcon.ipconInternal)

        return new(ipcon, deviceInternal)
    end
end

export set_segments
"""
    $(SIGNATURES)

The 7-segment display can be set with bitmaps. Every bit controls one
segment:

.. image:: /Images/Bricklets/bricklet_segment_display_4x7_bit_order.png
   :scale: 100 %
   :alt: Bit order of one segment
   :align: center

For example to set a "5" you would want to activate segments 0, 2, 3, 5 and 6.
This is represented by the number 0b01101101 = 0x6d = 109.

The brightness can be set between 0 (dark) and 7 (bright). The colon
parameter turns the colon of the display on or off.
"""
function set_segments(device::BrickletSegmentDisplay4x7, segments, brightness, colon)
    device.deviceInternal.set_segments(segments, brightness, colon)
end

export get_segments
"""
    $(SIGNATURES)

Returns the segment, brightness and color data as set by
:func:`Set Segments`.
"""
function get_segments(device::BrickletSegmentDisplay4x7)
    return device.deviceInternal.get_segments()
end

export start_counter
"""
    $(SIGNATURES)

Starts a counter with the *from* value that counts to the *to*
value with the each step incremented by *increment*.
*length* is the pause between each increment.

Example: If you set *from* to 0, *to* to 100, *increment* to 1 and
*length* to 1000, a counter that goes from 0 to 100 with one second
pause between each increment will be started.

Using a negative increment allows to count backwards.

You can stop the counter at every time by calling :func:`Set Segments`.
"""
function start_counter(device::BrickletSegmentDisplay4x7, value_from, value_to, increment, length)
    device.deviceInternal.start_counter(value_from, value_to, increment, length)
end

export get_counter_value
"""
    $(SIGNATURES)

Returns the counter value that is currently shown on the display.

If there is no counter running a 0 will be returned.
"""
function get_counter_value(device::BrickletSegmentDisplay4x7)
    return device.deviceInternal.get_counter_value()
end

export get_identity
"""
    $(SIGNATURES)

Returns the UID, the UID where the Bricklet is connected to,
the position, the hardware and firmware version as well as the
device identifier.

The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at
position 'z'.

The device identifier numbers can be found :ref:`here <device_identifier>`.
|device_identifier_constant|
"""
function get_identity(device::BrickletSegmentDisplay4x7)
    return device.deviceInternal.get_identity()
end

export register_callback
"""
Registers the given *function* with the given *callback_id*.
"""
function register_callback(device::BrickletSegmentDisplay4x7, callback_id, function_)
    if isnothing(function_)
        device.registered_callbacks.pop(callback_id, None)
    else
        device.registered_callbacks[callback_id] = function_
    end
end


text:
precompile(Tuple{typeof(Base.__precompile__)})
precompile(Tuple{Printf.var"#@printf", LineNumberNode, Module, Vararg{Any, N} where N})
precompile(Tuple{typeof(Printf._printf), String, Symbol, String, Tuple{Symbol}})
precompile(Tuple{typeof(Base.tail), Tuple{String, Symbol, Symbol}})
precompile(Tuple{typeof(Printf._printf), String, Symbol, String, Tuple{Symbol, Symbol}})
precompile(Tuple{typeof(Base.tail), Tuple{String, Symbol, Symbol, Symbol}})
precompile(Tuple{typeof(Printf._printf), String, Symbol, String, Tuple{Symbol, Symbol, Symbol}})
precompile(Tuple{typeof(Base.tail), Tuple{String, Expr, Expr}})
precompile(Tuple{typeof(Printf._printf), String, Symbol, String, Tuple{Expr, Expr}})
precompile(Tuple{Test.var"#@test", LineNumberNode, Module, Any, Vararg{Any, N} where N})
precompile(Tuple{typeof(Test.test_expr!), Any, Any})
precompile(Tuple{typeof(Test.get_test_result), Any, Any})
precompile(Tuple{typeof(Base.first), String})
precompile(Tuple{typeof(Base.collect), Base.Generator{Array{Any, 1}, typeof(Base.esc)}})
precompile(Tuple{Type{Base.Generator{I, F} where F where I}, Type{QuoteNode}, Array{Any, 1}})
precompile(Tuple{typeof(Base.collect), Base.Generator{Array{Any, 1}, Type{QuoteNode}}})
precompile(Tuple{typeof(Base.tail), Tuple{String, Symbol, Expr, Expr}})
precompile(Tuple{typeof(Printf._printf), String, Symbol, String, Tuple{Symbol, Expr, Expr}})
precompile(Tuple{typeof(Base.tail), Tuple{Symbol, String, Symbol, Expr, Expr}})
precompile(Tuple{typeof(Printf._printf), String, Expr, String, Tuple{Symbol, Expr, Expr}})
precompile(Tuple{typeof(Base.allocatedinline), Type{DocOpt.Option}})
precompile(Tuple{typeof(Base.allocatedinline), Type{DocOpt.Pattern}})
precompile(Tuple{typeof(Base.allocatedinline), Type{Array{T, N} where N where T}})
precompile(Tuple{typeof(Base.allocatedinline), Type{DocOpt.Required}})
precompile(Tuple{typeof(Base.allocatedinline), Type{DocOpt.Either}})
precompile(Tuple{typeof(Base.allocatedinline), Type{DocOpt.Argument}})
precompile(Tuple{typeof(Base._compute_eltype), Type{Tuple{Float64, Int64, Bool}}})
precompile(Tuple{Base.var"##s91#155", Any, Any, Any, Any, Any})
precompile(Tuple{typeof(Base.merge_names), Tuple{Symbol}, Tuple{Symbol, Symbol, Symbol}})
precompile(Tuple{typeof(Base.merge_types), Tuple{Symbol, Symbol, Symbol, Symbol}, Type{NamedTuple{(:initially_zero,), Tuple{Bool}}}, Type{NamedTuple{(:abstol, :maxiter, :log), Tuple{Float64, Int64, Bool}}}})
precompile(Tuple{typeof(Base.sym_in), Symbol, Tuple{Symbol, Symbol, Symbol}})
precompile(Tuple{typeof(Base.diff_names), Tuple{Symbol, Symbol, Symbol, Symbol}, Tuple{Symbol, Symbol, Symbol, Symbol, Symbol, Symbol, Symbol}})
precompile(Tuple{typeof(Base.merge_names), Tuple{Symbol, Symbol, Symbol, Symbol}, Tuple{Symbol}})
precompile(Tuple{typeof(Base.merge_types), Tuple{Symbol, Symbol, Symbol, Symbol, Symbol}, Type{NamedTuple{(:abstol, :reltol, :maxiter, :statevars), Tuple{Float64, Float64, Int64, IterativeSolvers.CGStateVariables{Float64, SparseArrays.SparseVector{Float64, Int64}}}}}, Type{NamedTuple{(:initially_zero,), Tuple{Bool}}}})
precompile(Tuple{Type{Base.Broadcast.BroadcastStyle}, Base.Broadcast.DefaultArrayStyle{0}, SparseArrays.HigherOrderFns.SparseVecStyle})
precompile(Tuple{typeof(Base.typename), DataType})
precompile(Tuple{typeof(Base.allocatedinline), Type{Ptr{SuiteSparse.CHOLMOD.C_Sparse{Float64}}}})
precompile(Tuple{typeof(Base.allocatedinline), Type{Ptr{SuiteSparse.CHOLMOD.C_Factor{Float64}}}})
precompile(Tuple{typeof(Base.allocatedinline), Type{Base.Complex{Float64}}})
precompile(Tuple{typeof(Base.allocatedinline), Type{Ptr{Int64}}})
precompile(Tuple{typeof(Base.allocatedinline), Type{Ptr{SuiteSparse.CHOLMOD.C_Dense{Float64}}}})
precompile(Tuple{typeof(Base.allocatedinline), Type{Union{Ptr{Nothing}, Base.InterpreterIP}}})
precompile(Tuple{typeof(Base.allocatedinline), Type{Tuple{UInt64, Main.Pos}}})
precompile(Tuple{typeof(Base.split), Base.SubString{String}, String})
precompile(Tuple{typeof(DocOpt.formal_usage), Base.SubString{String}})
precompile(Tuple{typeof(Base.findnext), typeof(Base.Unicode.isspace), Base.SubString{String}, Int64})
precompile(Tuple{Base.var"##sprint#355", Nothing, Int64, typeof(Base.sprint), Function, Array{AbstractString, 1}, Vararg{Any, N} where N})
precompile(Tuple{typeof(Base.join), Base.GenericIOBuffer{Array{UInt8, 1}}, Array{AbstractString, 1}, Char})
precompile(Tuple{Type{DocOpt.Tokens}, String, Type{T} where T})
precompile(Tuple{typeof(Base.vect), Nothing, Vararg{Any, N} where N})
precompile(Tuple{typeof(Base.promote_typeof), String, String, Vararg{String, N} where N})
precompile(Tuple{Type{Array{Union{Nothing, String}, 1}}, UndefInitializer, Int64})
precompile(Tuple{typeof(Base.copyto!), Array{Union{Nothing, String}, 1}, Tuple{Nothing, String, String, String}})
precompile(Tuple{typeof(Base.append!), Array{DocOpt.Pattern, 1}, Array{DocOpt.Option, 1}})
precompile(Tuple{Type{DocOpt.Required}, Array{DocOpt.Either, 1}})
precompile(Tuple{typeof(Base.vect), DocOpt.Required})
precompile(Tuple{typeof(Base.append!), Array{DocOpt.Pattern, 1}, Array{DocOpt.Required, 1}})
precompile(Tuple{Type{DocOpt.Optional}, Array{DocOpt.Either, 1}})
precompile(Tuple{typeof(Base.vect), DocOpt.Optional})
precompile(Tuple{typeof(Base.allocatedinline), Type{DocOpt.Optional}})
precompile(Tuple{typeof(Base.append!), Array{DocOpt.Pattern, 1}, Array{DocOpt.Optional, 1}})
precompile(Tuple{Type{DocOpt.Optional}, Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(Base.append!), Array{DocOpt.Pattern, 1}, Array{DocOpt.Argument, 1}})
precompile(Tuple{Type{DocOpt.Required}, Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(DocOpt.flat), DocOpt.Required, Array{DataType, 1}})
precompile(Tuple{typeof(Base.collect), Base.Generator{Array{DocOpt.Pattern, 1}, DocOpt.var"#7#8"{Array{DataType, 1}}}})
precompile(Tuple{DocOpt.var"#7#8"{Array{DataType, 1}}, DocOpt.Either})
precompile(Tuple{DocOpt.var"#7#8"{Array{DataType, 1}}, DocOpt.Required})
precompile(Tuple{DocOpt.var"#7#8"{Array{DataType, 1}}, DocOpt.Option})
precompile(Tuple{typeof(Base._array_for), Type{Array{DocOpt.Option, 1}}, Array{DocOpt.Pattern, 1}, Base.HasShape{1}})
precompile(Tuple{typeof(Base.collect_to_with_first!), Array{Array{DocOpt.Option, 1}, 1}, Array{DocOpt.Option, 1}, Base.Generator{Array{DocOpt.Pattern, 1}, DocOpt.var"#7#8"{Array{DataType, 1}}}, Int64})
precompile(Tuple{Base.var"#reduce##kw", NamedTuple{(:init,), Tuple{Array{DocOpt.Pattern, 1}}}, typeof(Base.reduce), Function, Array{Array{DocOpt.Option, 1}, 1}})
precompile(Tuple{Base.var"##mapfoldl#204", Base.Iterators.Pairs{Symbol, Array{DocOpt.Pattern, 1}, Tuple{Symbol}, NamedTuple{(:init,), Tuple{Array{DocOpt.Pattern, 1}}}}, typeof(Base.mapfoldl), Function, Function, Array{Array{DocOpt.Option, 1}, 1}})
precompile(Tuple{typeof(Base.mapfoldl_impl), typeof(Base.identity), typeof(Base.vcat), NamedTuple{(:init,), Tuple{Array{DocOpt.Pattern, 1}}}, Array{Array{DocOpt.Option, 1}, 1}})
precompile(Tuple{typeof(Base._array_for), Type{Array{DocOpt.Pattern, 1}}, Array{DocOpt.Pattern, 1}, Base.HasShape{1}})
precompile(Tuple{typeof(Base.collect_to_with_first!), Array{Array{DocOpt.Pattern, 1}, 1}, Array{DocOpt.Pattern, 1}, Base.Generator{Array{DocOpt.Pattern, 1}, DocOpt.var"#7#8"{Array{DataType, 1}}}, Int64})
precompile(Tuple{Base.var"#reduce##kw", NamedTuple{(:init,), Tuple{Array{DocOpt.Pattern, 1}}}, typeof(Base.reduce), Function, Array{Array{DocOpt.Pattern, 1}, 1}})
precompile(Tuple{Base.var"##mapfoldl#204", Base.Iterators.Pairs{Symbol, Array{DocOpt.Pattern, 1}, Tuple{Symbol}, NamedTuple{(:init,), Tuple{Array{DocOpt.Pattern, 1}}}}, typeof(Base.mapfoldl), Function, Function, Array{Array{DocOpt.Pattern, 1}, 1}})
precompile(Tuple{typeof(Base.mapfoldl_impl), typeof(Base.identity), typeof(Base.vcat), NamedTuple{(:init,), Tuple{Array{DocOpt.Pattern, 1}}}, Array{Array{DocOpt.Pattern, 1}, 1}})
precompile(Tuple{DocOpt.var"#7#8"{Array{DataType, 1}}, DocOpt.Optional})
precompile(Tuple{DocOpt.var"#7#8"{Array{DataType, 1}}, DocOpt.Argument})
precompile(Tuple{Type{Base.Set{T} where T}, Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(Base.push!), Base.Set{DocOpt.Pattern}, DocOpt.Option})
precompile(Tuple{typeof(Base.show), Base.IOContext{Base.GenericIOBuffer{Array{UInt8, 1}}}, String})
precompile(Tuple{typeof(Base.show), Base.IOContext{Base.GenericIOBuffer{Array{UInt8, 1}}}, Base.SubString{String}})
precompile(Tuple{typeof(Base.show), Base.IOContext{Base.GenericIOBuffer{Array{UInt8, 1}}}, Bool})
precompile(Tuple{typeof(Base.isequal), DocOpt.Option, DocOpt.Option})
precompile(Tuple{typeof(Base.:(==)), Base.SubString{String}, Base.SubString{String}})
precompile(Tuple{typeof(Base.:(==)), Bool, Bool})
precompile(Tuple{typeof(Base.show), Base.IOContext{Base.GenericIOBuffer{Array{UInt8, 1}}}, Nothing})
precompile(Tuple{typeof(Base.iterate), Array{DocOpt.Pattern, 1}})
precompile(Tuple{DocOpt.var"#35#37", DocOpt.Argument})
precompile(Tuple{typeof(Base.in), Nothing, Array{String, 1}})
precompile(Tuple{typeof(DocOpt.flat), DocOpt.Required, Array{Any, 1}})
precompile(Tuple{typeof(Base.in), Type{T} where T, Array{Any, 1}})
precompile(Tuple{typeof(Base.collect), Base.Generator{Array{DocOpt.Pattern, 1}, DocOpt.var"#7#8"{Array{Any, 1}}}})
precompile(Tuple{DocOpt.var"#7#8"{Array{Any, 1}}, DocOpt.Either})
precompile(Tuple{DocOpt.var"#7#8"{Array{Any, 1}}, DocOpt.Required})
precompile(Tuple{DocOpt.var"#7#8"{Array{Any, 1}}, DocOpt.Option})
precompile(Tuple{typeof(Base.collect_to_with_first!), Array{Array{DocOpt.Option, 1}, 1}, Array{DocOpt.Option, 1}, Base.Generator{Array{DocOpt.Pattern, 1}, DocOpt.var"#7#8"{Array{Any, 1}}}, Int64})
precompile(Tuple{typeof(Base.collect_to_with_first!), Array{Array{DocOpt.Pattern, 1}, 1}, Array{DocOpt.Pattern, 1}, Base.Generator{Array{DocOpt.Pattern, 1}, DocOpt.var"#7#8"{Array{Any, 1}}}, Int64})
precompile(Tuple{DocOpt.var"#7#8"{Array{Any, 1}}, DocOpt.Optional})
precompile(Tuple{DocOpt.var"#7#8"{Array{Any, 1}}, DocOpt.Argument})
precompile(Tuple{typeof(Base.allocatedinline), Type{Array{T, 1} where T}})
precompile(Tuple{typeof(Base.allocatedinline), Type{Array{DocOpt.Pattern, 1}}})
precompile(Tuple{typeof(Base.setindex_widen_up_to), Array{Array{DocOpt.Pattern, 1}, 1}, Array{DocOpt.Argument, 1}, Int64})
precompile(Tuple{typeof(Base.collect_to!), Array{Array{T, 1} where T, 1}, Base.Generator{Array{DocOpt.Pattern, 1}, DocOpt.var"#7#8"{Array{Any, 1}}}, Int64, Int64})
precompile(Tuple{typeof(Base._array_for), Type{Array{DocOpt.Argument, 1}}, Array{DocOpt.Pattern, 1}, Base.HasShape{1}})
precompile(Tuple{typeof(Base.collect_to_with_first!), Array{Array{DocOpt.Argument, 1}, 1}, Array{DocOpt.Argument, 1}, Base.Generator{Array{DocOpt.Pattern, 1}, DocOpt.var"#7#8"{Array{Any, 1}}}, Int64})
precompile(Tuple{Base.var"#reduce##kw", NamedTuple{(:init,), Tuple{Array{DocOpt.Pattern, 1}}}, typeof(Base.reduce), Function, Array{Array{DocOpt.Argument, 1}, 1}})
precompile(Tuple{Base.var"##mapfoldl#204", Base.Iterators.Pairs{Symbol, Array{DocOpt.Pattern, 1}, Tuple{Symbol}, NamedTuple{(:init,), Tuple{Array{DocOpt.Pattern, 1}}}}, typeof(Base.mapfoldl), Function, Function, Array{Array{DocOpt.Argument, 1}, 1}})
precompile(Tuple{typeof(Base.mapfoldl_impl), typeof(Base.identity), typeof(Base.vcat), NamedTuple{(:init,), Tuple{Array{DocOpt.Pattern, 1}}}, Array{Array{DocOpt.Argument, 1}, 1}})
precompile(Tuple{Base.var"#reduce##kw", NamedTuple{(:init,), Tuple{Array{DocOpt.Pattern, 1}}}, typeof(Base.reduce), Function, Array{Array{T, 1} where T, 1}})
precompile(Tuple{Base.var"##mapfoldl#204", Base.Iterators.Pairs{Symbol, Array{DocOpt.Pattern, 1}, Tuple{Symbol}, NamedTuple{(:init,), Tuple{Array{DocOpt.Pattern, 1}}}}, typeof(Base.mapfoldl), Function, Function, Array{Array{T, 1} where T, 1}})
precompile(Tuple{typeof(Base.mapfoldl_impl), typeof(Base.identity), typeof(Base.vcat), NamedTuple{(:init,), Tuple{Array{DocOpt.Pattern, 1}}}, Array{Array{T, 1} where T, 1}})
precompile(Tuple{typeof(Base.vcat), Array{DocOpt.Pattern, 1}, Array{DocOpt.Argument, 1}})
precompile(Tuple{typeof(Base.unique), Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(Base.in), DocOpt.Option, Base.Set{DocOpt.Pattern}})
precompile(Tuple{typeof(Base.in), DocOpt.Argument, Base.Set{DocOpt.Pattern}})
precompile(Tuple{typeof(Base.isequal), DocOpt.Argument, DocOpt.Option})
precompile(Tuple{typeof(Base.push!), Base.Set{DocOpt.Pattern}, DocOpt.Argument})
precompile(Tuple{typeof(DocOpt.fix_identities), DocOpt.Either, Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(DocOpt.fix_identities), DocOpt.Required, Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(Base.isequal), DocOpt.Option})
precompile(Tuple{typeof(Base.findfirst), Function, Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(Base.findnext), Base.Fix2{typeof(Base.isequal), DocOpt.Option}, Array{DocOpt.Pattern, 1}, Int64})
precompile(Tuple{Base.Fix2{typeof(Base.isequal), DocOpt.Option}, DocOpt.Option})
precompile(Tuple{typeof(Base.:(==)), String, Base.SubString{String}})
precompile(Tuple{typeof(DocOpt.fix_identities), DocOpt.Optional, Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(Base.isequal), DocOpt.Argument})
precompile(Tuple{typeof(Base.findnext), Base.Fix2{typeof(Base.isequal), DocOpt.Argument}, Array{DocOpt.Pattern, 1}, Int64})
precompile(Tuple{Base.Fix2{typeof(Base.isequal), DocOpt.Argument}, DocOpt.Option})
precompile(Tuple{Base.Fix2{typeof(Base.isequal), DocOpt.Argument}, DocOpt.Argument})
precompile(Tuple{typeof(Base.map), Function, Array{DataType, 1}})
precompile(Tuple{Type{Base.Generator{I, F} where F where I}, DocOpt.var"#15#17"{Array{DocOpt.Pattern, 1}}, Array{DataType, 1}})
precompile(Tuple{typeof(Base.allocatedinline), Type{Base.Missing}})
precompile(Tuple{typeof(Base.allocatedinline), Type{Union{Base.Missing, Bool}}})
precompile(Tuple{typeof(Base.collect_similar), Array{DataType, 1}, Base.Generator{Array{DataType, 1}, DocOpt.var"#15#17"{Array{DocOpt.Pattern, 1}}}})
precompile(Tuple{DocOpt.var"#15#17"{Array{DocOpt.Pattern, 1}}, Type{T} where T})
precompile(Tuple{typeof(Base._similar_for), Array{DocOpt.Pattern, 1}, Type{DataType}, Base.Generator{Array{DocOpt.Pattern, 1}, typeof(typeof)}, Base.HasShape{1}})
precompile(Tuple{typeof(Base.collect_to_with_first!), Array{DataType, 1}, Type{T} where T, Base.Generator{Array{DocOpt.Pattern, 1}, typeof(typeof)}, Int64})
precompile(Tuple{typeof(Base.in), Type{T} where T, Array{DataType, 1}})
precompile(Tuple{typeof(Base._similar_for), Array{DataType, 1}, Type{Bool}, Base.Generator{Array{DataType, 1}, DocOpt.var"#15#17"{Array{DocOpt.Pattern, 1}}}, Base.HasShape{1}})
precompile(Tuple{typeof(Base.collect_to!), Array{Bool, 1}, Base.Generator{Array{DataType, 1}, DocOpt.var"#15#17"{Array{DocOpt.Pattern, 1}}}, Int64, Int64})
precompile(Tuple{typeof(Base.any), Array{Bool, 1}})
precompile(Tuple{typeof(Base.filter), DocOpt.var"#16#18"{Array{DataType, 1}}, Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(Base.first), Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(Base.isequal), DocOpt.Required})
precompile(Tuple{typeof(Base.findnext), Base.Fix2{typeof(Base.isequal), DocOpt.Required}, Array{DocOpt.Pattern, 1}, Int64})
precompile(Tuple{Base.Fix2{typeof(Base.isequal), DocOpt.Required}, DocOpt.Required})
precompile(Tuple{typeof(Base.:(==)), DocOpt.Either, DocOpt.Either})
precompile(Tuple{typeof(Base.:(==)), DocOpt.Required, DocOpt.Required})
precompile(Tuple{typeof(Base.:(==)), DocOpt.Optional, DocOpt.Optional})
precompile(Tuple{typeof(Base.splice!), Array{DocOpt.Pattern, 1}, Int64})
precompile(Tuple{typeof(Base.getproperty), DocOpt.Required, Symbol})
precompile(Tuple{typeof(Base.isequal), DocOpt.Either})
precompile(Tuple{typeof(Base.findnext), Base.Fix2{typeof(Base.isequal), DocOpt.Either}, Array{DocOpt.Pattern, 1}, Int64})
precompile(Tuple{Base.Fix2{typeof(Base.isequal), DocOpt.Either}, DocOpt.Either})
precompile(Tuple{typeof(Base.vcat), Array{DocOpt.Required, 1}, Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(Base.vect), DocOpt.Option})
precompile(Tuple{typeof(Base.vcat), Array{DocOpt.Option, 1}, Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(Base.isequal), DocOpt.Optional})
precompile(Tuple{typeof(Base.findnext), Base.Fix2{typeof(Base.isequal), DocOpt.Optional}, Array{DocOpt.Pattern, 1}, Int64})
precompile(Tuple{Base.Fix2{typeof(Base.isequal), DocOpt.Optional}, DocOpt.Optional})
precompile(Tuple{typeof(Base.getproperty), DocOpt.Optional, Symbol})
precompile(Tuple{Base.Fix2{typeof(Base.isequal), DocOpt.Optional}, DocOpt.Option})
precompile(Tuple{Base.Fix2{typeof(Base.isequal), DocOpt.Optional}, DocOpt.Argument})
precompile(Tuple{typeof(Base.collect_to_with_first!), Array{Array{DocOpt.Pattern, 1}, 1}, Array{DocOpt.Pattern, 1}, Base.Generator{Array{DocOpt.Pattern, 1}, DocOpt.var"#9#12"}, Int64})
precompile(Tuple{typeof(Base.getindex), Array{Array{DocOpt.Pattern, 1}, 1}, Int64})
precompile(Tuple{typeof(Base.filter), DocOpt.var"#10#13"{Array{DocOpt.Pattern, 1}}, Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(Base._count), Function, Array{DocOpt.Pattern, 1}, Base.Colon})
precompile(Tuple{typeof(Base._simple_count), DocOpt.var"#11#14"{DocOpt.Option}, Array{DocOpt.Pattern, 1}})
precompile(Tuple{DocOpt.var"#11#14"{DocOpt.Option}, DocOpt.Option})
precompile(Tuple{typeof(Base._simple_count), DocOpt.var"#11#14"{DocOpt.Argument}, Array{DocOpt.Pattern, 1}})
precompile(Tuple{DocOpt.var"#11#14"{DocOpt.Argument}, DocOpt.Argument})
precompile(Tuple{DocOpt.var"#11#14"{DocOpt.Argument}, DocOpt.Option})
precompile(Tuple{DocOpt.var"#11#14"{DocOpt.Option}, DocOpt.Argument})
precompile(Tuple{typeof(DocOpt.patternmatch), DocOpt.Either, Array{DocOpt.Pattern, 1}, Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(DocOpt.patternmatch), DocOpt.Option, Array{DocOpt.Pattern, 1}, Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(DocOpt.name), DocOpt.Argument})
precompile(Tuple{typeof(Base.indexed_iterate), Tuple{Bool, Array{DocOpt.Pattern, 1}, Array{DocOpt.Pattern, 1}}, Int64})
precompile(Tuple{typeof(Base.indexed_iterate), Tuple{Bool, Array{DocOpt.Pattern, 1}, Array{DocOpt.Pattern, 1}}, Int64, Int64})
precompile(Tuple{typeof(DocOpt.patternmatch), DocOpt.Optional, Array{DocOpt.Pattern, 1}, Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(DocOpt.patternmatch), DocOpt.Argument, Array{DocOpt.Pattern, 1}, Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(Base.vect), DocOpt.Argument})
precompile(Tuple{DocOpt.var"#5#6"{DocOpt.Argument}, DocOpt.Argument})
precompile(Tuple{typeof(Base.length), Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(Base.isempty), Array{DocOpt.Pattern, 1}})
precompile(Tuple{typeof(Base.getproperty), DocOpt.Option, Symbol})
precompile(Tuple{typeof(Base.setindex!), Base.Dict{String, Any}, Bool, Base.SubString{String}})
precompile(Tuple{typeof(Base.iterate), Array{DocOpt.Pattern, 1}, Int64})
precompile(Tuple{typeof(Base.setindex!), Base.Dict{String, Any}, Nothing, Base.SubString{String}})
precompile(Tuple{typeof(Base.getproperty), DocOpt.Argument, Symbol})
precompile(Tuple{typeof(Main.read_input), String})
precompile(Tuple{typeof(Base.parse), Type{UInt64}, Base.SubString{String}})
precompile(Tuple{typeof(Base.print), Base.GenericIOBuffer{Array{UInt8, 1}}, UInt64})
precompile(Tuple{typeof(Base.getindex), Array{Base.SubString{String}, 1}, UInt64})
precompile(Tuple{typeof(Base.parse), Type{Float64}, Base.SubString{String}})
precompile(Tuple{typeof(Base.:(*)), Float64, Float64})
precompile(Tuple{typeof(Base.setindex!), SparseArrays.SparseVector{Float64, Int64}, Float64, UInt64})
precompile(Tuple{Type{IterativeSolvers.ConvergenceHistory{true, Nothing}}, Int64, Int64, Int64, Nothing, Bool, Base.Dict{Symbol, Any}})
precompile(Tuple{typeof(IterativeSolvers.reserve!), IterativeSolvers.ConvergenceHistory{true, Nothing}, Symbol, Int64})
precompile(Tuple{typeof(Base.push!), IterativeSolvers.ConvergenceHistory{true, Nothing}, Symbol, Float64})
precompile(Tuple{typeof(Base.setindex!), Array{Float64, 1}, Float64, Int64})
precompile(Tuple{typeof(Base.indexed_iterate), Tuple{SparseArrays.SparseVector{Float64, Int64}, IterativeSolvers.ConvergenceHistory{true, Nothing}}, Int64})
precompile(Tuple{typeof(Base.indexed_iterate), Tuple{SparseArrays.SparseVector{Float64, Int64}, IterativeSolvers.ConvergenceHistory{true, Nothing}}, Int64, Int64})
precompile(Tuple{typeof(SparseArrays.ftranspose), SparseArrays.SparseMatrixCSC{Float64, Int64}, Function, Type{Float64}})
precompile(Tuple{typeof(SparseArrays._distributevals_halfperm!), SparseArrays.SparseMatrixCSC{Float64, Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Base.UnitRange{Int64}, SparseArrays.var"#5#6"})
precompile(Tuple{typeof(Base.:(\)), SuiteSparse.CHOLMOD.Factor{Float64}, Array{Float64, 2}})
precompile(Tuple{typeof(Base.getindex), Array{Float64, 2}, Base.UnitRange{Int64}, Int64})
precompile(Tuple{typeof(Base.:(>)), Float64, Float64})
precompile(Tuple{typeof(Base.getindex), Array{Float64, 2}, Int64, Int64})
precompile(Tuple{typeof(Base.:(==)), Float64, Int64})
precompile(Tuple{typeof(Base.sign), Float64})
precompile(Tuple{typeof(Base.convert), Type{Int64}, Float64})
precompile(Tuple{typeof(Base.adjoint), SuiteSparse.CHOLMOD.Factor{Float64}})
precompile(Tuple{typeof(Base.:(\)), LinearAlgebra.Adjoint{Float64, SuiteSparse.CHOLMOD.Factor{Float64}}, Array{Int64, 2}})
precompile(Tuple{typeof(Base.zeros), Type{Float64}, Int64})
precompile(Tuple{typeof(Base.getindex), Array{Float64, 2}, Int64, Base.UnitRange{Int64}})
precompile(Tuple{typeof(SuiteSparse.CHOLMOD.free!), SuiteSparse.CHOLMOD.Dense{Float64}})
precompile(Tuple{typeof(SuiteSparse.CHOLMOD.free!), SuiteSparse.CHOLMOD.Sparse{Float64}})
precompile(Tuple{typeof(LinearAlgebra.norm), Array{Float64, 1}, Float64})
precompile(Tuple{typeof(Base.getindex), Array{Float64, 1}, Int64})
precompile(Tuple{Base.var"#sortperm##kw", NamedTuple{(:rev,), Tuple{Bool}}, typeof(Base.sortperm), Array{Float64, 1}})
precompile(Tuple{Base.Sort.var"##sortperm#11", Base.Sort.QuickSortAlg, Function, Function, Bool, Base.Order.ForwardOrdering, typeof(Base.sortperm), Array{Float64, 1}})
precompile(Tuple{Type{Base.Order.Perm{O, V} where V<:(AbstractArray{T, 1} where T) where O<:Base.Order.Ordering}, Base.Order.ReverseOrdering{Base.Order.ForwardOrdering}, Array{Float64, 1}})
precompile(Tuple{typeof(Base.sort!), Array{Int64, 1}, Base.Sort.QuickSortAlg, Base.Order.Perm{Base.Order.ReverseOrdering{Base.Order.ForwardOrdering}, Array{Float64, 1}}})
precompile(Tuple{typeof(Base.getindex), Array{Float64, 1}, Array{Int64, 1}})
precompile(Tuple{typeof(Base.:(<=)), Float64, Float64})
precompile(Tuple{typeof(Base.:(*)), SparseArrays.SparseMatrixCSC{Float64, Int64}, SparseArrays.SparseVector{Float64, Int64}})
precompile(Tuple{typeof(Base.:(-)), SparseArrays.SparseVector{Float64, Int64}, SparseArrays.SparseVector{Float64, Int64}})
precompile(Tuple{typeof(LinearAlgebra.norm), SparseArrays.SparseVector{Float64, Int64}})
precompile(Tuple{typeof(Test.do_test), Test.ExecutionResult, Any})
precompile(Tuple{typeof(Base.isempty), Array{Test.AbstractTestSet, 1}})
precompile(Tuple{typeof(Base.getproperty), IterativeSolvers.ConvergenceHistory{true, Nothing}, Symbol})
precompile(Tuple{typeof(Base.string), String, IterativeSolvers.ConvergenceHistory{true, Nothing}})
precompile(Tuple{typeof(Base.print), Base.GenericIOBuffer{Array{UInt8, 1}}, IterativeSolvers.ConvergenceHistory{true, Nothing}})
precompile(Tuple{typeof(Base.getindex), SparseArrays.SparseVector{Float64, Int64}, UInt64})
precompile(Tuple{typeof(Base.deepcopy_internal), Any, Base.IdDict{Any, Any}})
precompile(Tuple{typeof(Base.deepcopy_internal), Array{UInt64, 1}, Base.IdDict{Any, Any}})
precompile(Tuple{typeof(Base.similar), Array{Main.Pad, 1}})
precompile(Tuple{typeof(Base.length), Array{Main.Pad, 1}})
precompile(Tuple{typeof(Base.convert), Type{AbstractString}, String})
precompile(Tuple{typeof(Base.print), String, String, String, Vararg{String, N} where N})
precompile(Tuple{typeof(Base.print), Base.TTY, String, String, Vararg{String, N} where N})
precompile(Tuple{typeof(SuiteSparse.CHOLMOD.free!), SuiteSparse.CHOLMOD.Factor{Float64}})
precompile(Tuple{typeof(Main.read_input), String})

max_stars_repo_name: alsam/julia-samples

max_issues_repo_name: alsam/julia-samples

max_forks_repo_name: alsam/julia-samples