text:
abstract type AbstractBC end
struct NeumannBC <: AbstractBC end
struct DirichletBC <: AbstractBC end

struct One end
struct MinusOne end
Base.getindex(::One, args...) = 1
Base.getindex(::MinusOne, args...) = -1
Base.:-(::One) = MinusOne()
Base.:-(::MinusOne) = One()

struct Derivative{O,F,D,S}
    ∂::O
    f::F
    domain::D
    scale::S
end
Base.getindex(d::Derivative, I::CartesianIndex{3}) = d.scale*d.∂(I,d.f,d.domain)
Base.:-(d::Derivative) = Derivative(d.∂, d.f, d.domain, -d.scale)
Base.:*(a, d::Derivative) = Derivative(d.∂, d.f, d.domain, a*d.scale)
Base.:*(d::Derivative, a) = *(a, d)

∂x²f(f,d::Domain) = Derivative(∂x²,f,d,1)
∂y²f(f,d::Domain) = Derivative(∂y²,f,d,1)
∂z²f(f,d::Domain) = Derivative(∂z²,f,d,1)
∂xyf(f,d::Domain) = Derivative(∂xy,f,d,1)
∂xzf(f,d::Domain) = Derivative(∂xz,f,d,1)
∂yzf(f,d::Domain) = Derivative(∂yz,f,d,1)

function new_sparse_matrix(d::Domain)
    N = prod(size(d))
    S = spzeros(N,N)
    l = LinearIndices(d)
    ldx = l[2,1,1] - l[1,1,1]
    ldy = l[1,2,1] - l[1,1,1]
    ldz = l[1,1,2] - l[1,1,1]
    for K = -1:1
        for J = -1:1
            for I = -1:1
                d = I*ldx + J*ldy + K*ldz
                n = N - abs(d)
                S += spdiagm(d => ones(n))
            end
        end
    end
    @. S = 0
    return S
end

function add_f∂a²!(S, f, da, Δa, Na, domain::Domain, Aa)
    Na = Na-1
    Δa² = Δa^2
    c = CartesianIndices(domain)
    l = LinearIndices(domain)
    for I = first(c):last(c)-Na*da
        S[l[I],l[I     ]] += -Aa/Δa² * f[I]
        S[l[I],l[I + da]] +=   1/Δa² * f[I]
    end
    for I = first(c)+da:last(c)-da
        S[l[I],l[I - da]] +=  1/Δa² * f[I]
        S[l[I],l[I     ]] += -2/Δa² * f[I]
        S[l[I],l[I + da]] +=  1/Δa² * f[I]
    end
    for I = first(c)+Na*da:last(c)
        S[l[I],l[I - da]] +=   1/Δa² * f[I]
        S[l[I],l[I     ]] += -Aa/Δa² * f[I]
    end
    return S
end
add_f∂x²!(S, f, domain::Domain) = add_f∂a²!(S, f, dx, domain.Δx, domain.nx, domain, 2)
add_f∂y²!(S, f, domain::Domain) = add_f∂a²!(S, f, dy, domain.Δy, domain.ny, domain, 2)
add_f∂z²!(S, f, domain::Domain) = add_f∂a²!(S, f, dz, domain.Δz, domain.nz, domain, 1)
add_∂x²!(S, domain::Domain) = add_f∂x²!(S, One(), domain)
add_∂y²!(S, domain::Domain) = add_f∂y²!(S, One(), domain)
add_∂z²!(S, domain::Domain) = add_f∂z²!(S, One(), domain)

function add_f∂ab!(S, f, da, db, Δa, Δb, Na, Nb, domain::Domain, Aa, Ab)
    Na = Na-1
    Nb = Nb-1
    c = CartesianIndices(domain)
    l = LinearIndices(domain)
    for I = first(c):last(c)-Na*da-Nb*db # a bottom, b bottom
        S[l[I],l[I + da + db]] +=      1/(4*Δa*Δb) * f[I]
        S[l[I],l[I          ]] +=  Aa*Ab/(4*Δa*Δb) * f[I]
        S[l[I],l[I + da     ]] += -   Ab/(4*Δa*Δb) * f[I]
        S[l[I],l[I      + db]] += -Aa   /(4*Δa*Δb) * f[I]
    end
    for I = first(c)+da:last(c)-da-Nb*db # a interior, b bottom
        S[l[I],l[I + da + db]] +=   1/(4*Δa*Δb) * f[I]
        S[l[I],l[I - da     ]] +=  Ab/(4*Δa*Δb) * f[I]
        S[l[I],l[I + da     ]] += -Ab/(4*Δa*Δb) * f[I]
        S[l[I],l[I - da + db]] += - 1/(4*Δa*Δb) * f[I]
    end
    for I = first(c)+Na*da:last(c)-Nb*db # a top, b bottom
        S[l[I],l[I      + db]] +=  Aa   /(4*Δa*Δb) * f[I]
        S[l[I],l[I - da     ]] +=     Ab/(4*Δa*Δb) * f[I]
        S[l[I],l[I          ]] += -Aa*Ab/(4*Δa*Δb) * f[I]
        S[l[I],l[I - da + db]] += -    1/(4*Δa*Δb) * f[I]
    end
    for I = first(c)+db:last(c)-Na*da-db # a bottom, b interior
        S[l[I],l[I + da + db]] +=   1/(4*Δa*Δb) * f[I]
        S[l[I],l[I      - db]] +=  Aa/(4*Δa*Δb) * f[I]
        S[l[I],l[I + da - db]] += - 1/(4*Δa*Δb) * f[I]
        S[l[I],l[I      + db]] += -Aa/(4*Δa*Δb) * f[I]
    end
    for I = first(c)+da+db:last(c)-da-db # a interior, b interior
        S[l[I],l[I + da + db]] +=  1/(4*Δa*Δb) * f[I]
        S[l[I],l[I - da - db]] +=  1/(4*Δa*Δb) * f[I]
        S[l[I],l[I + da - db]] += -1/(4*Δa*Δb) * f[I]
        S[l[I],l[I - da + db]] += -1/(4*Δa*Δb) * f[I]
    end
    for I = first(c)+Na*da+db:last(c)-db # a top, b interior
        S[l[I],l[I      + db]] +=  Aa/(4*Δa*Δb) * f[I]
        S[l[I],l[I - da - db]] +=   1/(4*Δa*Δb) * f[I]
        S[l[I],l[I      - db]] += -Aa/(4*Δa*Δb) * f[I]
        S[l[I],l[I - da + db]] += - 1/(4*Δa*Δb) * f[I]
    end
    for I = first(c)+Nb*db:last(c)-Na*da # a bottom, b top
        S[l[I],l[I + da     ]] +=     Ab/(4*Δa*Δb) * f[I]
        S[l[I],l[I      - db]] +=  Aa   /(4*Δa*Δb) * f[I]
        S[l[I],l[I + da - db]] += -    1/(4*Δa*Δb) * f[I]
        S[l[I],l[I          ]] += -Aa*Ab/(4*Δa*Δb) * f[I]
    end
    for I = first(c)+da+Nb*db:last(c)-da # a interior, b top
        S[l[I],l[I + da     ]] +=  Ab/(4*Δa*Δb) * f[I]
        S[l[I],l[I - da - db]] +=   1/(4*Δa*Δb) * f[I]
        S[l[I],l[I + da - db]] += - 1/(4*Δa*Δb) * f[I]
        S[l[I],l[I - da     ]] += -Ab/(4*Δa*Δb) * f[I]
    end
    for I = first(c)+Na*da+Nb*db:last(c) # a top, b top
        S[l[I],l[I          ]] +=  Aa*Ab/(4*Δa*Δb) * f[I]
        S[l[I],l[I - da - db]] +=      1/(4*Δa*Δb) * f[I]
        S[l[I],l[I      - db]] += -Aa   /(4*Δa*Δb) * f[I]
        S[l[I],l[I - da     ]] += -   Ab/(4*Δa*Δb) * f[I]
    end
    return S
end
add_f∂xy!(S, f, domain::Domain) = add_f∂ab!(S, f, dx, dy, domain.Δx, domain.Δy, domain.nx, domain.ny, domain, 0, 0)
add_f∂xz!(S, f, domain::Domain) = add_f∂ab!(S, f, dx, dz, domain.Δx, domain.Δz, domain.nx, domain.nz, domain, 0, 1)
add_f∂yz!(S, f, domain::Domain) = add_f∂ab!(S, f, dy, dz, domain.Δy, domain.Δz, domain.ny, domain.nz, domain, 0, 1)
add_∂xy!(S, domain::Domain) = add_f∂xy!(S, One(), domain)
add_∂xz!(S, domain::Domain) = add_f∂xz!(S, One(), domain)
add_∂yz!(S, domain::Domain) = add_f∂yz!(S, One(), domain)

function generate_sparse_linearized_L(ψ0, ϕ0, d::Domain)

    UL = new_sparse_matrix(d)
    add_∂z²!(UL, d)
    add_f∂z²!(UL, ∂x²f(ψ0,d), d)
    add_f∂z²!(UL, ∂y²f(ψ0,d), d)
    add_f∂xz!(UL, -∂xzf(ψ0,d), d)
    add_f∂yz!(UL, -∂yzf(ψ0,d), d)

    UR = new_sparse_matrix(d)
    add_f∂x²!(UR, ∂z²f(ϕ0,d), d)
    add_f∂y²!(UR, ∂z²f(ϕ0,d), d)
    add_f∂xz!(UR, -∂xzf(ϕ0,d), d)
    add_f∂yz!(UR, -∂yzf(ϕ0,d), d)

    BL = new_sparse_matrix(d)
    add_∂x²!(BL, d)
    add_∂y²!(BL, d)

    BR = new_sparse_matrix(d)
    add_f∂x²!(BR, -One(), d)
    add_f∂y²!(BR, -One(), d)
    add_f∂x²!(BR, -2*∂y²f(ψ0,d), d)
    add_f∂y²!(BR, -2*∂x²f(ψ0,d), d)
    add_f∂xy!(BR, 4*∂xyf(ψ0,d), d)

    S = hvcat((2,2), UL, UR, BL, BR)
    return S

end


text:
module TestExpressionsAsExpr

import Test: @testset, @test
import Volcanito: column_names_tuple_expr, ColumnName

test_cases = (
    (
        input = (ColumnName(:a, false), ColumnName(:b, false)),
        output = Expr(:tuple, QuoteNode(:a), QuoteNode(:b)),
    ),
)

@testset "column_names_tuple_expr" begin
    for case in test_cases
        @test sort([eval(column_names_tuple_expr(case.input))...]) == sort([eval(case.output)...])
    end
end

end

ext: jl


text:
# Basing off of NbodyGradient/test/outer_ss/NBG_performance.jl
# Trying to profile to see how much time is spent on allocations
# for moving memory back and forth.

include("../src/ttv.jl")

n=5
xout = zeros(3,n)
# Positions at time September 5, 1994 at 0h00 in days (from Hairer, Lubich & Wanner
# 2006, Geometric Numerical Integration, 2nd Edition, Springer, pp. 13-14):

xout .= transpose([-2.079997415328555E-04  7.127853194812450E-03 -1.352450694676177E-05;
        -3.502576700516146E+00 -4.111754741095586E+00  9.546978009906396E-02;
         9.075323061767737E+00 -3.443060862268533E+00 -3.008002403885198E-01;
         8.309900066449559E+00 -1.782348877489204E+01 -1.738826162402036E-01;
         1.147049510166812E+01 -2.790203169301273E+01  3.102324955757055E-01]) #;
        #-1.553841709421204E+01 -2.440295115792555E+01  7.105854443660053E+00])
vout = zeros(3,n)
vout .= transpose([-6.227982601533108E-06  2.641634501527718E-06  1.564697381040213E-07;
         5.647185656190083E-03 -4.540768041260330E-03 -1.077099720398784E-04;
         1.677252499111402E-03  5.205044577942047E-03 -1.577215030049337E-04;
         3.535508197097127E-03  1.479452678720917E-03 -4.019422185567764E-05;
         2.882592399188369E-03  1.211095412047072E-03 -9.118527716949448E-05]) #;
         #2.754640676017983E-03 -2.105690992946069E-03 -5.607958889969929E-04]);
# Units of velocity are AU/day

# Specify masses, including terrestrial planets in the Sun:
m = [1.00000597682,0.000954786104043,0.000285583733151,
         0.0000437273164546,0.0000517759138449] #,6.58086572e-9];

# Compute the center-of-mass:
vcm = zeros(3);
xcm = zeros(3);
for j=1:n
    vcm .+= m[j]*vout[:,j];
    xcm .+= m[j]*xout[:,j];
end
vcm ./= sum(m);
xcm ./= sum(m);
# Adjust so CoM is stationary
for j=1:n
    vout[:,j] .-= vcm[:];
    xout[:,j] .-= xcm[:];
end

h = 50.0
n = 5
pair = zeros(Bool, n, n)  # Pairwise Keplerians for all bodies
xerror = similar(xout)
verror = similar(vout)
fill!(xerror,0.0)
fill!(verror,0.0)
nstep = 1000000
jac_step = Matrix{Float64}(I,7*n,7*n)
jac_error = zeros(Float64,7*n,7*n)

# Now, time it:
@time for i=1:nstep; ah18!(xout,vout,xerror,verror,h,m,n,jac_step,jac_error,pair); end


text:
@mlj_model mutable struct APIx0 <: Supervised
    f0::Int
end
@mlj_model mutable struct APIx0b <: Supervised
    f0::Int
end

mutable struct APIx1 <: Static end

@testset "fit-x" begin
    m0 = APIx0(f0=1)
    m1 = APIx0b(f0=3)
    # no weight support: fallback
    M.fit(m::APIx0, v::Int, X, y) = (5, nothing, nothing)
    @test fit(m0, 1, randn(2), randn(2), 5) == (5, nothing, nothing)
    # with weight support: use
    M.fit(m::APIx0b, v::Int, X, y, w) = (7, nothing, nothing)
    @test fit(m1, 1, randn(2), randn(2), 5) == (7, nothing, nothing)
    # default fitted params
    @test M.fitted_params(m1, 7) == (fitresult=7,)
    # static
    s1 = APIx1()
    @test fit(s1, 1, 0) == (nothing, nothing, nothing)

    #update fallback = fit
    @test update(m0, 1, 5, nothing, randn(2), 5) == (5, nothing, nothing)
end

struct DummyUnivariateFinite end

mutable struct UnivariateFiniteFitter <: Probabilistic end

@testset "models fitting a distribution to data" begin

    function MLJModelInterface.fit(model::UnivariateFiniteFitter,
                                   verbosity::Int, X, y)

        fitresult = DummyUnivariateFinite()
        report = nothing
        cache = nothing

        verbosity > 0 && @info "Fitted a $fitresult"

        return fitresult, cache, report
    end

    MLJModelInterface.predict(model::UnivariateFiniteFitter,
                          fitresult,
                          X) = fill(fitresult, length(X))

    MLJModelInterface.input_scitype(::Type{<:UnivariateFiniteFitter}) =
        AbstractVector{Nothing}
    MLJModelInterface.target_scitype(::Type{<:UnivariateFiniteFitter}) =
        AbstractVector{<:Finite}

    y =categorical(collect("aabbccaa"))
    X = fill(nothing, length(y))
    model = UnivariateFiniteFitter()
    fitresult, cache, report = MLJModelInterface.fit(model, 1, X, y)

    @test cache == nothing
    @test report == nothing

    ytest = y[1:3]
    yhat = predict(model, fitresult, fill(nothing, 3))
    @test yhat == fill(DummyUnivariateFinite(), 3)

end


text:
abstract type Object end

"""
  Occlusion
  - degrees come from sides of a plane (camera view)
  - check object visible inside list (degree check)
  - if not visible do not set
  - set visible object with its degree sides which occludes everything else
  - 2 Arrays 1-220 (-10°-190°) for X and Y: 220 * 220 = 48400 degrees
  - Z is not needed, it changes X and Y degrees
"""
function occlusion(blocks)
  spectrum = Array{Union{Array{Object,1},Nothing}}(undef, 220, 220)
  fill!(spectrum, nothing)

  #currentBlock.rightTop
  #currentBlock.rightBottom
  #currentBlock.leftTop
  #currentBlock.leftBottom

  #currentBlock.rightTop * z_distance
  #...

  #loop:
  # current object degree sides are inside a objects shadow?
  #if spectrum[Y][X] != nothing continue # skip current object
  #else
  # loop2: set all degrees inside objects shadow (frustum)
  #end

  # search3D_spiral(block_coordinates + player_position)
  # projection_orthographic(-w, w, -h, h, znear, zfar)
  #u = atan(x / z)
  #v = atan(y / z)
  #atan(u/v)
  #a = tan(fovy * pi / 360) * (w/h)
end

occlusion(nothing)

max_stars_repo_name: Gilga/JuliaOpenGL

max_issues_repo_name: Gilga/JuliaOpenGL

max_forks_repo_name: Gilga/JuliaOpenGL


text:
using Documenter, ProperOrthogonalDecomposition

makedocs(
        modules = [ProperOrthogonalDecomposition],
        format = :html,
        sitename = "ProperOrthogonalDecomposition.jl",
        strict = true,
        assets = ["assets/favicon.ico"],
        clean = true,
        checkdocs = :none,
        pages = Any[
                "Home" => "index.md",
                "Manual" => Any[
                        "man/POD.md",
                        "man/weightedPOD.md",
                        "man/convergence.md",
                ]
        ]
)

deploydocs(
    repo = "github.com/MrUrq/ProperOrthogonalDecomposition.jl.git",
    target = "build",
    julia = "1.0",
    deps = nothing,
    make = nothing
)


text:
using JuMP, EAGO

                     m = Model()

                     EAGO.register_eago_operators!(m)

                     @variable(m, -1 <= x[i=1:3] <= 1)

                     @variable(m, -24.652335523355834 <= q <= 21.32472335033785)

                     add_NL_constraint(m, :(sigmoid(-0.6982139593401175 + -0.19504968807074974*sigmoid(0.6793369023557885 + 0.6523875537646115*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + -0.5142038874540145*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.0456439541419269*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + 0.6096854328317232*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3]))) + -0.41803298572193937*sigmoid(-0.7048442383777926 + 0.47781322839334983*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + -0.713369260368808*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.44964139924772173*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + -0.9876898123617992*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3]))) + 0.9542284451941447*sigmoid(0.9969387928417852 + -0.011395717836928387*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + 0.8103499615759371*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.12667586987008894*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + 0.6252342222679741*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3]))) + 0.7916680056214345*sigmoid(-0.5156629799588863 + -0.22745979325095078*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + -0.8222624364306839*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.4937419854366709*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + -0.1046356011041838*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3])))) + sigmoid(-0.4539405071565561 + 0.5320780591355936*sigmoid(0.6793369023557885 + 0.6523875537646115*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + -0.5142038874540145*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.0456439541419269*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + 0.6096854328317232*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3]))) + -0.8489788623944037*sigmoid(-0.7048442383777926 + 0.47781322839334983*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + -0.713369260368808*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.44964139924772173*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + -0.9876898123617992*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3]))) + -0.25620536200506905*sigmoid(0.9969387928417852 + -0.011395717836928387*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + 0.8103499615759371*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.12667586987008894*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + 0.6252342222679741*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3]))) + 0.9264345634068367*sigmoid(-0.5156629799588863 + -0.22745979325095078*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + -0.8222624364306839*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.4937419854366709*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + -0.1046356011041838*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3])))) + sigmoid(-0.4017849565754932 + 0.7092320156791541*sigmoid(0.6793369023557885 + 0.6523875537646115*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + -0.5142038874540145*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.0456439541419269*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + 0.6096854328317232*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3]))) + -0.20657569919094643*sigmoid(-0.7048442383777926 + 0.47781322839334983*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + -0.713369260368808*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.44964139924772173*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + -0.9876898123617992*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3]))) + 0.6260976974386958*sigmoid(0.9969387928417852 + -0.011395717836928387*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + 0.8103499615759371*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.12667586987008894*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + 0.6252342222679741*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3]))) + 0.026773003462286393*sigmoid(-0.5156629799588863 + -0.22745979325095078*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + -0.8222624364306839*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.4937419854366709*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + -0.1046356011041838*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3])))) + sigmoid(0.8541923459688499 + -0.7979821016654509*sigmoid(0.6793369023557885 + 0.6523875537646115*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + -0.5142038874540145*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.0456439541419269*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + 0.6096854328317232*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3]))) + 0.2172669330681649*sigmoid(-0.7048442383777926 + 0.47781322839334983*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + -0.713369260368808*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.44964139924772173*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + -0.9876898123617992*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3]))) + -0.6626207135044284*sigmoid(0.9969387928417852 + -0.011395717836928387*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + 0.8103499615759371*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.12667586987008894*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + 0.6252342222679741*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3]))) + -0.5735396155482761*sigmoid(-0.5156629799588863 + -0.22745979325095078*sigmoid(0.1880507757579264 + -0.8703531991881865*$(x[1]) + 0.8423062039785143*$(x[2]) + 0.27626604928751597*$(x[3])) + -0.8222624364306839*sigmoid(0.8004597365811503 + 0.4093664270553261*$(x[1]) + -0.7983161406747903*$(x[2]) + -0.755209029087681*$(x[3])) + -0.4937419854366709*sigmoid(-0.8428376848805481 + -0.4971126206674761*$(x[1]) + -0.0245959153233013*$(x[2]) + 0.4386350201089879*$(x[3])) + -0.1046356011041838*sigmoid(-0.26516744777719925 + 0.12012704290515952*$(x[1]) + -0.4833932117044406*$(x[2]) + -0.25804110713494666*$(x[3])))) - $q <= 0.0))

                     @objective(m, Min, q)

                     return m

max_stars_repo_name: PSORLab/RSActivationFunctions

max_issues_repo_name: PSORLab/RSActivationFunctions

max_forks_repo_name: PSORLab/RSActivationFunctions


text:
"""
```julia
calculate_tgrad(sys::AbstractSystem)
```

Calculate the time gradient of a system.

Returns a vector of [`Num`](@ref) instances. The result from the first
call will be cached in the system object.
"""
function calculate_tgrad end

"""
```julia
calculate_gradient(sys::AbstractSystem)
```

Calculate the gradient of a scalar system.

Returns a vector of [`Num`](@ref) instances. The result from the first
call will be cached in the system object.
"""
function calculate_gradient end

"""
```julia
calculate_jacobian(sys::AbstractSystem)
```

Calculate the jacobian matrix of a system.

Returns a matrix of [`Num`](@ref) instances. The result from the first
call will be cached in the system object.
"""
function calculate_jacobian end

"""
```julia
calculate_factorized_W(sys::AbstractSystem)
```

Calculate the factorized W-matrix of a system.

Returns a matrix of [`Num`](@ref) instances. The result from the first
call will be cached in the system object.
"""
function calculate_factorized_W end

"""
```julia
calculate_hessian(sys::AbstractSystem)
```

Calculate the hessian matrix of a scalar system.

Returns a matrix of [`Num`](@ref) instances. The result from the first
call will be cached in the system object.
"""
function calculate_hessian end

"""
```julia
generate_tgrad(sys::AbstractSystem, dvs = states(sys), ps = parameters(sys), expression = Val{true}; kwargs...)
```

Generates a function for the time gradient of a system. Extra arguments control
the arguments to the internal [`build_function`](@ref) call.
"""
function generate_tgrad end

"""
```julia
generate_gradient(sys::AbstractSystem, dvs = states(sys), ps = parameters(sys), expression = Val{true}; kwargs...)
```

Generates a function for the gradient of a system. Extra arguments control
the arguments to the internal [`build_function`](@ref) call.
"""
function generate_gradient end

"""
```julia
generate_jacobian(sys::AbstractSystem, dvs = states(sys), ps = parameters(sys), expression = Val{true}; sparse = false, kwargs...)
```

Generates a function for the jacobian matrix matrix of a system. Extra arguments control
the arguments to the internal [`build_function`](@ref) call.
"""
function generate_jacobian end

"""
```julia
generate_factorized_W(sys::AbstractSystem, dvs = states(sys), ps = parameters(sys), expression = Val{true}; sparse = false, kwargs...)
```

Generates a function for the factorized W-matrix matrix of a system. Extra arguments control
the arguments to the internal [`build_function`](@ref) call.
"""
function generate_factorized_W end

"""
```julia
generate_hessian(sys::AbstractSystem, dvs = states(sys), ps = parameters(sys), expression = Val{true}; sparse = false, kwargs...)
```

Generates a function for the hessian matrix matrix of a system. Extra arguments control
the arguments to the internal [`build_function`](@ref) call.
"""
function generate_hessian end

"""
```julia
generate_function(sys::AbstractSystem, dvs = states(sys), ps = parameters(sys), expression = Val{true}; kwargs...)
```

Generate a function to evaluate the system's equations.
"""
function generate_function end

getname(x::Sym) = nameof(x)
getname(t::Term) = t.op isa Sym ? getname(t.op) : error("Cannot get name of $t")

function Base.getproperty(sys::AbstractSystem, name::Symbol)

    if name ∈ fieldnames(typeof(sys))
        return getfield(sys,name)
    elseif !isempty(sys.systems)
        i = findfirst(x->x.name==name,sys.systems)
        if i !== nothing
            return rename(sys.systems[i],renamespace(sys.name,name))
        end
    end

    i = findfirst(x->getname(x) == name, sys.states)

    if i !== nothing
        return rename(sys.states[i],renamespace(sys.name,name))
    end

    if :ps ∈ fieldnames(typeof(sys))
        i = findfirst(x->getname(x) == name,sys.ps)
        if i !== nothing
            return rename(sys.ps[i],renamespace(sys.name,name))
        end
    end

    if :observed ∈ fieldnames(typeof(sys))
        i = findfirst(x->getname(x.lhs)==name,sys.observed)
        if i !== nothing
            return rename(sys.observed[i].lhs,renamespace(sys.name,name))
        end
    end

    throw(error("Variable $name does not exist"))
end

renamespace(namespace,name) = Symbol(namespace,:₊,name)

function renamespace(namespace, x::Sym)
    Sym{symtype(x)}(renamespace(namespace,x.name))
end

function renamespace(namespace, x::Term)
    renamespace(namespace, x.op)(x.args...)
end

function namespace_variables(sys::AbstractSystem)
    [renamespace(sys.name,x) for x in states(sys)]
end

function namespace_parameters(sys::AbstractSystem)
    [toparam(renamespace(sys.name,x)) for x in parameters(sys)]
end

function namespace_pins(sys::AbstractSystem)
    [renamespace(sys.name,x) for x in pins(sys)]
end

namespace_equations(sys::AbstractSystem) = namespace_equation.(equations(sys),sys.name,sys.iv.name)

function namespace_equation(eq::Equation,name,ivname)
    _lhs = namespace_expr(eq.lhs,name,ivname)
    _rhs = namespace_expr(eq.rhs,name,ivname)
    _lhs ~ _rhs
end

function namespace_expr(O::Sym,name,ivname)
    O.name == ivname ? O : rename(O,renamespace(name,O.name))
end

function namespace_expr(O::Term,name,ivname)
    if O.op isa Sym
        Term(rename(O.op,renamespace(name,O.op.name)),namespace_expr.(O.args,name,ivname))
    else
        Term(O.op,namespace_expr.(O.args,name,ivname))
    end
end
namespace_expr(O,name,ivname) = O

independent_variable(sys::AbstractSystem) = sys.iv
function states(sys::AbstractSystem)
    unique(isempty(sys.systems) ?
           setdiff(sys.states, value.(sys.pins)) :
           [sys.states;reduce(vcat,namespace_variables.(sys.systems))])
end
parameters(sys::AbstractSystem) = isempty(sys.systems) ? sys.ps : [sys.ps;reduce(vcat,namespace_parameters.(sys.systems))]
pins(sys::AbstractSystem) = isempty(sys.systems) ? sys.pins : [sys.pins;reduce(vcat,namespace_pins.(sys.systems))]
function observed(sys::AbstractSystem)
    [sys.observed;
     reduce(vcat,
            (namespace_equation.(observed(s), s.name, s.iv.name) for s in sys.systems),
            init=Equation[])]
end

function states(sys::AbstractSystem,name::Symbol)
    x = sys.states[findfirst(x->x.name==name,sys.states)]
    rename(x,renamespace(sys.name,x.name))(sys.iv)
end

function parameters(sys::AbstractSystem,name::Symbol)
    x = sys.ps[findfirst(x->x.name==name,sys.ps)]
    rename(x,renamespace(sys.name,x.name))()
end

function pins(sys::AbstractSystem,name::Symbol)
    x = sys.pins[findfirst(x->x.name==name,sys.ps)]
    rename(x,renamespace(sys.name,x.name))(sys.iv())
end

lhss(xs) = map(x->x.lhs, xs)
rhss(xs) = map(x->x.rhs, xs)

function equations(sys::ModelingToolkit.AbstractSystem)
    if isempty(sys.systems)
        return sys.eqs
    else
        eqs = [sys.eqs;
               reduce(vcat,
                      namespace_equations.(sys.systems);
                      init=Equation[])]

        return eqs
    end
end

function states(sys::AbstractSystem,args...)
    name = last(args)
    extra_names = reduce(Symbol,[Symbol(:₊,x.name) for x in args[1:end-1]])
    newname = renamespace(extra_names,name)
    rename(x,renamespace(sys.name,newname))(sys.iv)
end

function parameters(sys::AbstractSystem,args...)
    name = last(args)
    extra_names = reduce(Symbol,[Symbol(:₊,x.name) for x in args[1:end-1]])
    newname = renamespace(extra_names,name)
    rename(x,renamespace(sys.name,newname))()
end

function islinear(sys::AbstractSystem)
    rhs = [eq.rhs for eq ∈ equations(sys)]

    all(islinear(r, states(sys)) for r in rhs)
end

function pins(sys::AbstractSystem,args...)
    name = last(args)
    extra_names = reduce(Symbol,[Symbol(:₊,x.name) for x in args[1:end-1]])
    newname = renamespace(extra_names,name)
    rename(x,renamespace(sys.name,newname))(sys.iv())
end

struct AbstractSysToExpr
    sys::AbstractSystem
    states::Vector
end
AbstractSysToExpr(sys) = AbstractSysToExpr(sys,states(sys))
function (f::AbstractSysToExpr)(O::Term)
    any(isequal(O), f.states) && return O.op.name  # variables
    if isa(O.op, Sym)
        return build_expr(:call, Any[O.op.name; f.(O.args)])
    end
    return build_expr(:call, Any[O.op; f.(O.args)])
end
(f::AbstractSysToExpr)(x) = toexpr(x)


text:
using MPSKit,MPSKitModels,TensorKit,Plots

let
    #defining the hamiltonian
    th = nonsym_ising_ham(lambda = 0.3)
    (sx,sy,sz) = nonsym_spintensors(1//2);

    #initilizing a random mps
    ts = InfiniteMPS([ℂ^2],[ℂ^12]);

    #Finding the groundstate
    (ts,envs,_) = find_groundstate(ts,th,Vumps(maxiter=400));

    len=20;deltat=0.05;totaltime=3.0
    middle = Int(round(len/2));

    #apply a single spinflip at the middle site
    mpco = MPSComoving(ts,len);
    @tensor mpco.AC[middle][-1 -2;-3] := mpco.AC[middle][-1,1,-3]*sx[-2,1]
    normalize!(mpco);

    envs = environments(mpco,th)

    szdat = [expectation_value(mpco,szt)]

    for i in 1:(totaltime/deltat)
        (mpco,envs) = timestep(mpco,th,deltat,Tdvp2(trscheme = truncdim(20)),envs)
        push!(szdat,expectation_value(mpco,sz))
    end

    display(heatmap(real.(reduce((a,b)->[a b],szdat))))

    println("Enter to continue ...")
    readline();
end


text:
using Peacock
r = 0.1
# mu1 = 1
mu1 = [14 12.4im 0;-12.4im 14 0;0 0 1]
epf(x, y) = x^2 + y^2 <= r^2 ? 15 : 1
muf(x, y) = x^2 + y^2 <= r^2 ? mu1 : 1
a1 = [1, 0]; a2 = [0, 1]
d1 = 0.01; d2 = 0.01
polar = TM
@time Chern_number(epf, muf, a1, a2, d1, d2, polar, bands=1:4)

mu1=[0.8736 -0.6671im 0;0.6671im 0.8736 0;0 0 0.8736]
r1 = 0.2
r2 = 0.2
xc = 1/4; yc = 1/4/sqrt(3)
epf(x,y) = (x-xc)^2 + (y-yc)^2 <r1^2 || (x+xc)^2 + (y+yc)^2 < r2^2 ? 15 : 1
muf(x,y) = (x-xc)^2 + (y-yc)^2 <r1^2 || (x+xc)^2 + (y+yc)^2 < r2^2 ? mu1 : 1
d1, d2 = 0.01, 0.01
a1 = [1, 0]; a2 = [1/2, sqrt(3)/2]
@time Chern_number(epf, muf, a1, a2, d1, d2, polar, Nkx = 4, Nky = 4, bands=1:3)

geometry = Geometry(epf, muf, a1, a2, d1, d2, polar)
solver = Peacock.FDFD.Solver(geometry, 2*[d1, d2])
Chern_number(solver, polar)


text:
using DiffEqProblemLibrary, Sundials, Test
using DiffEqProblemLibrary.DAEProblemLibrary: importdaeproblems; importdaeproblems()
using DiffEqProblemLibrary.DAEProblemLibrary: prob_dae_resrob

# Test DAE
prob = prob_dae_resrob
dt = 1000
saveat = float(collect(0:dt:100000))
sol = solve(prob,IDA())
sol = solve(prob,IDA(),abstol=[1e-9,1e-8,1e-7])
sol2 = solve(prob,IDA(linear_solver=:Band,jac_upper=2,jac_lower=2))
sol3 = solve(prob,IDA(linear_solver=:GMRES))
#sol4 = solve(prob,IDA(linear_solver=:BCG)) # Fails but doesn't throw an error?
sol5 = solve(prob,IDA(linear_solver=:TFQMR))
sol6 = solve(prob,IDA(linear_solver=:FGMRES))
sol7 = solve(prob,IDA(linear_solver=:PCG)) # Requires symmetric linear

# Test identity preconditioner
global prec_used = false
global psetup_used = false
prec = (z,r,p,t,y,fy,resid,gamma,delta,lr)->(global prec_used=true;z.=r)
psetup = (p,t,resid,u,du,gamma) -> (global psetup_used = true)
sol4 = solve(prob,IDA(linear_solver=:GMRES,
             prec_side = 3,
             prec=prec))
@test prec_used
sol4 = solve(prob,IDA(linear_solver=:GMRES,
             prec_side = 3,
             prec=prec,
             psetup=psetup))
@test psetup_used

sol = solve(prob,IDA(),saveat=saveat)

@test sol.t == saveat

sol = solve(prob,IDA(),saveat=saveat,save_everystep=true)

@test sol.t != saveat
@test intersect(sol.t,saveat) == saveat

sol = solve(prob,IDA(),tstops=[0.9])

@test 0.9 ∈ sol.t

prob = deepcopy(prob_dae_resrob)
prob2 = DAEProblem(prob.f,prob.du0,prob.u0,(1.0,0.0))
sol = solve(prob2,IDA())
@test maximum(diff(sol.t)) < 0 # Make sure all go negative

function f!(res, du, u, p ,t)
    res[1] = du[1]-1.01
    return
end

u0 = [0.]
du0 = [1.01]
tspan = (0.0, 10.)

println("With consistent initial conditions:")

dae_prob = DAEProblem(f!,du0,u0,tspan, differential_vars=[true])
sol = solve(dae_prob,IDA())

println("With inconsistent initial conditions:")

du0 = [0.]

dae_prob = DAEProblem(f!,du0, u0,tspan, differential_vars=[true])
sol = solve(dae_prob,IDA())


text:
# BigBed Record
# =============

# type Record is defined in reader.jl.

"""
    BigBed.Record()

Create an unfilled bigBed record.
"""
function Record()
    return Record(
        # chromid, chromstart, chromend
        0, 0, 0,
        # data, filled range, #columns
        UInt8[], 1:0, 0,
        # indexes
        1:0, 1:0, 0,
        1:0, 1:0, 1:0,
        1:0, UnitRange{Int}[], UnitRange{Int}[])
end

function Base.convert(::Type{GenomicFeatures.Interval}, record::Record)
    s = hasstrand(record) ? strand(record) : GenomicFeatures.STRAND_BOTH
    return GenomicFeatures.Interval(chrom(record), chromstart(record), chromend(record), s, record)
end

function Base.convert(::Type{GenomicFeatures.Interval{Record}}, record::Record)
    return convert(GenomicFeatures.Interval, record)
end

function Base.copy(record::Record)
    copy = Record(
        record.chromid,
        record.chromstart,
        record.chromend,
        record.data[record.filled],
        record.filled,
        record.ncols,
        record.name,
        record.score,
        record.strand,
        record.thickstart,
        record.thickend,
        record.itemrgb,
        record.blockcount,
        Base.copy(record.blocksizes),
        Base.copy(record.blockstarts))
    if isdefined(record, :reader)
        copy.reader = record.reader
    end
    return copy
end

function initialize!(record::Record)
    record.chromid = 0
    record.chromstart = 0
    record.chromend = 0
    record.filled = 1:0
    record.ncols = 0
    record.name = 1:0
    record.score = 1:0
    record.strand = 0
    record.thickstart = 1:0
    record.thickend = 1:0
    record.itemrgb = 1:0
    record.blockcount = 1:0
    empty!(record.blocksizes)
    empty!(record.blockstarts)
    return record
end

function BioCore.isfilled(record::Record)
    return !isempty(record.filled)
end

function Base.show(io::IO, record::Record)
    if get(io, :compact, false)
        if isfilled(record)
            # TODO: more fields
            print(io, chrom(record), ':', chromstart(record), '-', chromend(record))
        else
            print(io, "<not filled>")
        end
    else
        print(io, summary(record), ':')
        if isfilled(record)
            println(io)
            println(io, "   chromosome: ", chrom(record))
            println(io, "        start: ", chromstart(record))
              print(io, "          end: ", chromend(record))
            if hasname(record)
                println(io)
                print(io, "         name: ", name(record))
            end
            if hasscore(record)
                println(io)
                print(io, "        score: ", score(record))
            end
            if hasstrand(record)
                println(io)
                print(io, "       strand: ", strand(record))
            end
            if hasthickstart(record)
                println(io)
                print(io, "  thick start: ", thickstart(record))
            end
            if hasthickend(record)
                println(io)
                print(io, "    thick end: ", thickend(record))
            end
            if hasitemrgb(record)
                println(io)
                print(io, "     item RGB: ", itemrgb(record))
            end
            if hasblockcount(record)
                bcount = blockcount(record)
                println(io)
                print(io, "  block count: ", bcount)
                for (i, (bsize, bstart)) in enumerate(zip(blocksizes(record), blockstarts(record)))
                    println(io)
                    print(io, "      [$i]: size=$(bsize), start=$(bstart)")
                end
            end
        else
            print(io, " <not filled>")
        end
    end
end

# Accessor functions
# ------------------

"""
    chromid(record::Record)::UInt32

Get the chromosome ID of `record`.
"""
function chromid(record::Record)::UInt32
    checkfilled(record)
    return record.chromid
end

"""
    chrom(record::Record)::String

Get the chromosome name of `record`.
"""
function chrom(record::Record)::String
    checkfilled(record)
    return record.reader.chrom_names[chromid(record)]
end

function haschrom(record::Record)
    return isfilled(record)
end

function BioCore.seqname(record::Record)
    return chrom(record)
end

function BioCore.hasseqname(record::Record)
    return haschrom(record)
end

"""
    chromstart(record::Record)::Int

Get the start position of `record`.
"""
function chromstart(record::Record)::Int
    checkfilled(record)
    return record.chromstart + 1
end

function haschromstart(record::Record)
    return isfilled(record)
end

function BioCore.leftposition(record::Record)
    return chromstart(record)
end

function BioCore.hasleftposition(record::Record)
    return haschromstart(record)
end

"""
    chromend(record::Record)::Int

Get the end position of `record`.
"""
function chromend(record::Record)::Int
    checkfilled(record)
    return record.chromend % Int
end

function haschromend(record::Record)
    return isfilled(record)
end

function BioCore.rightposition(record::Record)
    return chromend(record)
end

function BioCore.hasrightposition(record::Record)
    return haschromend(record)
end

"""
    name(record::Record)::String

Get the name of `record`.
"""
function name(record::Record)::String
    checkfilled(record)
    if !hasname(record)
        missingerror(:name)
    end
    return String(record.data[record.name])
end

function hasname(record::Record)
    return record.ncols ≥ 4
end

"""
    score(record::Record)::Int

Get the score between 0 and 1000.
"""
function score(record::Record)::Int
    checkfilled(record)
    if !hasscore(record)
        missingerror(:score)
    end
    return BED.unsafe_parse_decimal(Int, record.data, record.score)
end

function hasscore(record::Record)
    return record.ncols ≥ 5
end

"""
    strand(record::Record)::GenomicFeatures.Strand

Get the strand of `record`.
"""
function strand(record::Record)::GenomicFeatures.Strand
    checkfilled(record)
    if !hasstrand(record)
        missingerror(:strand)
    end
    return convert(GenomicFeatures.Strand, Char(record.data[record.strand]))
end

function hasstrand(record::Record)
    return record.ncols ≥ 6
end

function GenomicFeatures.strand(record::Record)
    return strand(record)
end

"""
    thickstart(record::Record)::Int

Get the starting position at which `record` is drawn thickly.

Note that the first base is numbered 1.
"""
function thickstart(record::Record)::Int
    checkfilled(record)
    if !hasthickstart(record)
        missingerror(:thickstart)
    end
    return BED.unsafe_parse_decimal(Int, record.data, record.thickstart) + 1
end

function hasthickstart(record::Record)
    return record.ncols ≥ 7
end

"""
    thickend(record::Record)::Int

Get the end position at which `record` is drawn thickly.
"""
function thickend(record::Record)::Int
    checkfilled(record)
    if !hasthickend(record)
        missingerror(:thickend)
    end
    return BED.unsafe_parse_decimal(Int, record.data, record.thickend)
end

function hasthickend(record::Record)
    return record.ncols ≥ 8
end

"""
    itemrgb(record::Record)::ColorTypes.RGB

Get the RGB value of `record`.

The return type is defined in [ColorTypes.jl](https://github.com/JuliaGraphics/ColorTypes.jl).
"""
function itemrgb(record::Record)::ColorTypes.RGB
    checkfilled(record)
    if !hasitemrgb(record)
        missingerror(:itemrgb)
    end
    return BED.parse_rgbcolor(record.data, record.itemrgb)
end

function hasitemrgb(record::Record)
    return record.ncols ≥ 9
end

"""
    blockcount(record::Record)::Int

Get the number of blocks (exons) in `record`.
"""
function blockcount(record::Record)::Int
    checkfilled(record)
    if !hasblockcount(record)
        missingerror(:blockcount)
    end
    return BED.unsafe_parse_decimal(Int, record.data, record.blockcount)
end

function hasblockcount(record::Record)
    return record.ncols ≥ 10
end

"""
    blocksizes(record::Record)::Vector{Int}

Get the block (exon) sizes of `record`.
"""
function blocksizes(record::Record)::Vector{Int}
    checkfilled(record)
    if !hasblocksizes(record)
        missingerror(:blocksizes)
    end
    return [BED.unsafe_parse_decimal(Int, record.data, r) for r in record.blocksizes]
end

function hasblocksizes(record::Record)
    return record.ncols ≥ 11
end

"""
    blockstarts(record::Record)::Vector{Int}

Get the block (exon) starts of `record`.

Note that the first base is numbered 1.
"""
function blockstarts(record::Record)::Vector{Int}
    checkfilled(record)
    if !hasblockstarts(record)
        missingerror(:blockstarts)
    end
    return [BED.unsafe_parse_decimal(Int, record.data, r) + 1 for r in record.blockstarts]
end

function hasblockstarts(record::Record)
    return record.ncols ≥ 12
end

"""
    optionals(record::Record)::Vector{String}

Get optional fields as strings.
"""
function optionals(record::Record)::Vector{String}
    checkfilled(record)
    ret = String[]
    p = 13
    p_end = last(record.filled)
    while p ≤ p_end
        p_delim = findnext(isequal(UInt8('\t')), record.data, p)

        if p_delim === nothing
            p_delim = p_end + 1
        end
        push!(ret, String(record.data[p:p_delim-1]))
        p = p_delim + 1
    end
    return ret
end

function checkfilled(record::Record)
    if !isfilled(record)
        throw(ArgumentError("unfilled bigBed record"))
    end
end


text:
# Julia wrapper for header: /Volumes/BOOTCAMP/programs/compa_libs/iup/include/iup.h
# Automatically generated using Clang.jl wrap_c, version 0.0.0

@static is_windows()? (const iup = "iup") : (const iup = "libiup")  # Name of IUP shared lib.

function IupVbox(c1::Ptr{Ihandle}, c2=C_NULL, c3=C_NULL, c4=C_NULL, c5=C_NULL, c6=C_NULL, c7=C_NULL, c8=C_NULL, c9=C_NULL,
		c10=C_NULL, c11=C_NULL, c12=C_NULL, c13=C_NULL, c14=C_NULL, c15=C_NULL)
	ccall((:IupVbox, iup), Ptr{Ihandle}, (Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle},
		Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle},
		Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}),
		c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15)
end

function IupHbox(c1::Ptr{Ihandle}, c2=C_NULL, c3=C_NULL, c4=C_NULL, c5=C_NULL, c6=C_NULL, c7=C_NULL, c8=C_NULL, c9=C_NULL,
		c10=C_NULL, c11=C_NULL, c12=C_NULL, c13=C_NULL, c14=C_NULL, c15=C_NULL)
	ccall((:IupHbox, iup), Ptr{Ihandle}, (Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle},
		Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle},
		Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}),
		c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15)
end

function IupCbox(c1=C_NULL, c2=C_NULL, c3=C_NULL, c4=C_NULL, c5=C_NULL, c6=C_NULL, c7=C_NULL, c8=C_NULL, c9=C_NULL,
		c10=C_NULL, c11=C_NULL, c12=C_NULL, c13=C_NULL)
	ccall((:IupCbox, iup), Ptr{Ihandle}, (Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle},
		Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}),
		c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13)
end

function IupMenu(c1::Ptr{Ihandle}, c2=C_NULL, c3=C_NULL, c4=C_NULL, c5=C_NULL, c6=C_NULL, c7=C_NULL, c8=C_NULL, c9=C_NULL,
		c10=C_NULL, c11=C_NULL, c12=C_NULL, c13=C_NULL, c14=C_NULL, c15=C_NULL)
	ccall((:IupMenu, iup), Ptr{Ihandle}, (Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle},
		Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle},
		Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}),
		c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15)
end

function IupGridBox(c1::Ptr{Ihandle}, c2=C_NULL, c3=C_NULL, c4=C_NULL, c5=C_NULL, c6=C_NULL, c7=C_NULL, c8=C_NULL, c9=C_NULL,
		c10=C_NULL, c11=C_NULL, c12=C_NULL, c13=C_NULL)
	ccall((:IupGridBox, iup), Ptr{Ihandle}, (Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle},
		Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}),
		c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13)
end

function IupTabs(c1::Ptr{Ihandle}, c2=C_NULL, c3=C_NULL, c4=C_NULL, c5=C_NULL, c6=C_NULL, c7=C_NULL, c8=C_NULL, c9=C_NULL,
		c10=C_NULL, c11=C_NULL, c12=C_NULL, c13=C_NULL)
	ccall((:IupTabs, iup), Ptr{Ihandle}, (Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle},
		Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}),
		c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13)
end

# I Don't understand the purpose of this function, which true definition includes a varargs, so I implemented
# this one only as a guide for the future problems
#=
function IupSetCallbacks(ih::Ptr{Ihandle}, name::String, func1::Icallback, func2::Icallback)
	ccall((:IupSetCallbacks, iup), Icallback, (Ptr{Ihandle}, Ptr{UInt8}, Icallback, Icallback), ih, name, func1, func2)
end
=#
# Followinfg the advice in https://groups.google.com/forum/?fromgroups=#!topic/julia-users/bBXHSq_KJZM
function IupSetCallbacks(ih::Ptr{Ihandle}, name::String, func1::Icallback)
    ccall((:IupSetCallbacks, iup), Icallback, (Ptr{Ihandle}, Ptr{UInt8}, Icallback, Ptr{Void}...), ih, name, func1, C_NULL)
end

# When I find that these arguments may be used to send in something useful I'll activate them
#function IupOpen(argc::Ptr{Cint}=C_NULL, argv::Ptr{Ptr{Ptr{UInt8}}}=C_NULL)
function IupOpen(argc=C_NULL, argv=C_NULL)
	ccall((:IupOpen, iup), Cint, (Ptr{Cint}, Ptr{Ptr{Ptr{UInt8}}}), argc, argv)
end
function IupClose()
	ccall((:IupClose, iup), Void, (),)
end
function IupImageLibOpen()
  ccall( (:IupImageLibOpen, iup), Void, (), )
end
function IupMainLoop()
	ccall((:IupMainLoop, iup), Cint, (), )
end
function IupLoopStep()
  ccall( (:IupLoopStep, iup), Cint, (), )
end
function IupLoopStepWait()
  ccall( (:IupLoopStepWait, iup), Cint, (), )
end
function IupMainLoopLevel()
  ccall( (:IupMainLoopLevel, iup), Cint, (), )
end
function IupFlush()
  ccall( (:IupFlush, iup), Void, (), )
end
function IupExitLoop()
  ccall( (:IupExitLoop, iup), Void, (), )
end
function IupRecordInput(filename::String, mode::Int)
	ccall((:IupRecordInput, iup), Cint, (Ptr{UInt8}, Cint), filename, mode)
end
function IupPlayInput(filename::String)
  ccall( (:IupPlayInput, iup), Cint, (Ptr{UInt8},), filename)
end
function IupUpdate(ih::Ptr{Ihandle})
  ccall( (:IupUpdate, iup), Void, (Ptr{Ihandle},), ih)
end
function IupUpdateChildren(ih::Ptr{Ihandle})
  ccall( (:IupUpdateChildren, iup), Void, (Ptr{Ihandle},), ih)
end
function IupRedraw(ih::Ptr{Ihandle}, children::Cint)
  ccall( (:IupRedraw, iup), Void, (Ptr{Ihandle}, Cint), ih, children)
end
function IupRefresh(ih::Ptr{Ihandle})
  ccall( (:IupRefresh, iup), Void, (Ptr{Ihandle},), ih)
end
function IupRefreshChildren(ih::Ptr{Ihandle})
  ccall( (:IupRefreshChildren, iup), Void, (Ptr{Ihandle},), ih)
end
function IupHelp(url::String)
  ccall( (:IupHelp, iup), Cint, (Ptr{UInt8},), url)
end
function IupLoad(filename::String)
  ccall( (:IupLoad, iup), Ptr{UInt8}, (Ptr{UInt8},), filename)
end
function IupLoadBuffer(buffer::String)
  ccall( (:IupLoadBuffer, iup), Ptr{UInt8}, (Ptr{UInt8},), buffer)
end
function IupVersion()
  ccall( (:IupVersion, iup), Ptr{UInt8}, (), )
end
function IupVersionDate()
  ccall( (:IupVersionDate, iup), Ptr{UInt8}, (), )
end
function IupVersionNumber()
  ccall( (:IupVersionNumber, iup), Cint, (), )
end
function IupSetLanguage(lng::String)
	ccall((:IupSetLanguage, iup), Void, (Ptr{UInt8},), lng)
end
function IupGetLanguage()
  ccall( (:IupGetLanguage, iup), Ptr{UInt8}, (), )
end
function IupSetLanguageString(name::String, str::String)
	ccall((:IupSetLanguageString, iup), Void, (Ptr{UInt8}, Ptr{UInt8}), name, str)
end
function IupStoreLanguageString(name::String, str::String)
	ccall((:IupStoreLanguageString, iup), Void, (Ptr{UInt8}, Ptr{UInt8}), name, str)
end
function IupGetLanguageString(name::String)
	ccall((:IupGetLanguageString, iup), Ptr{UInt8}, (Ptr{UInt8},), name)
end
function IupSetLanguagePack(ih::Ptr{Ihandle})
  ccall( (:IupSetLanguagePack, iup), Void, (Ptr{Ihandle},), ih)
end
function IupDestroy(ih::Ptr{Ihandle})
	ccall((:IupDestroy, iup), Void, (Ptr{Ihandle},), ih)
end
function IupDetach(child::Ptr{Ihandle})
  ccall( (:IupDetach, iup), Void, (Ptr{Ihandle},), child)
end
function IupAppend(ih::Ptr{Ihandle}, child::Ptr{Ihandle})
  ccall( (:IupAppend, iup), Ptr{Ihandle}, (Ptr{Ihandle}, Ptr{Ihandle}), ih, child)
end
function IupInsert(ih::Ptr{Ihandle}, ref_child::Ptr{Ihandle}, child::Ptr{Ihandle})
  ccall( (:IupInsert, iup), Ptr{Ihandle}, (Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}), ih, ref_child, child)
end
function IupGetChild(ih::Ptr{Ihandle}, pos::Cint)
  ccall( (:IupGetChild, iup), Ptr{Ihandle}, (Ptr{Ihandle}, Cint), ih, pos)
end
function IupGetChildPos(ih::Ptr{Ihandle}, child::Ptr{Ihandle})
  ccall( (:IupGetChildPos, iup), Cint, (Ptr{Ihandle}, Ptr{Ihandle}), ih, child)
end
function IupGetChildCount(ih::Ptr{Ihandle})
  ccall( (:IupGetChildCount, iup), Cint, (Ptr{Ihandle},), ih)
end
function IupGetNextChild(ih::Ptr{Ihandle}, child::Ptr{Ihandle})
  ccall( (:IupGetNextChild, iup), Ptr{Ihandle}, (Ptr{Ihandle}, Ptr{Ihandle}), ih, child)
end
function IupGetBrother(ih::Ptr{Ihandle})
  ccall( (:IupGetBrother, iup), Ptr{Ihandle}, (Ptr{Ihandle},), ih)
end
function IupGetParent(ih::Ptr{Ihandle})
  ccall( (:IupGetParent, iup), Ptr{Ihandle}, (Ptr{Ihandle},), ih)
end
function IupGetDialog(ih::Ptr{Ihandle})
	ccall((:IupGetDialog, iup), Ptr{Ihandle}, (Ptr{Ihandle},), ih)
end
function IupGetDialogChild(ih::Ptr{Ihandle}, name::String)
  ccall( (:IupGetDialogChild, iup), Ptr{Ihandle}, (Ptr{Ihandle}, Ptr{UInt8}), ih, name)
end
function IupReparent(ih::Ptr{Ihandle}, new_parent::Ptr{Ihandle}, ref_child::Ptr{Ihandle})
  ccall( (:IupReparent, iup), Cint, (Ptr{Ihandle}, Ptr{Ihandle}, Ptr{Ihandle}), ih, new_parent, ref_child)
end
function IupPopup(ih::Ptr{Ihandle}, x::Integer, y::Integer)
	ccall((:IupPopup, iup), Cint, (Ptr{Ihandle}, Cint, Cint), ih, x, y)
end
function IupShow(ih::Ptr{Ihandle})
	ccall((:IupShow, iup), Cint, (Ptr{Ihandle},), ih)
end
function IupShowXY(ih::Ptr{Ihandle}, x::Integer, y::Integer)
	ccall((:IupShowXY, iup), Cint, (Ptr{Ihandle}, Cint, Cint), ih, x, y)
end
function IupHide(ih::Ptr{Ihandle})
  ccall( (:IupHide, iup), Cint, (Ptr{Ihandle},), ih)
end
function IupMap(ih::Ptr{Ihandle})
	ccall((:IupMap, iup), Cint, (Ptr{Ihandle},), ih)
end
function IupUnmap(ih::Ptr{Ihandle})
  ccall( (:IupUnmap, iup), Void, (Ptr{Ihandle},), ih)
end
function IupResetAttribute(ih::Ptr{Ihandle}, name::String)
  ccall( (:IupResetAttribute, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}), ih, name)
end
function IupGetAllAttributes(ih::Ptr{Ihandle}, names::Ptr{Ptr{UInt8}}, n::Cint)
  ccall( (:IupGetAllAttributes, iup), Cint, (Ptr{Ihandle}, Ptr{Ptr{UInt8}}, Cint), ih, names, n)
end
function IupSetAttributes(ih::Ptr{Ihandle}, str::String)
	ccall((:IupSetAttributes, iup), Ptr{Ihandle}, (Ptr{Ihandle}, Ptr{UInt8}), ih, str)
end
function IupGetAttributes(ih::Ptr{Ihandle})
  ccall( (:IupGetAttributes, iup), Ptr{UInt8}, (Ptr{Ihandle},), ih)
end
function IupSetAttribute(ih::Ptr{Ihandle}, name::String, value=C_NULL)
	ccall((:IupSetAttribute, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Ptr{UInt8}), ih, name, value)
end
function IupSetStrAttribute(ih::Ptr{Ihandle}, name::String, value::String)
  ccall( (:IupSetStrAttribute, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Ptr{UInt8}), ih, name, value)
end
function IupSetInt(ih::Ptr{Ihandle}, name::String, value::Cint)
  ccall( (:IupSetInt, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint), ih, name, value)
end
function IupSetFloat(ih::Ptr{Ihandle}, name::String, value)
  ccall( (:IupSetFloat, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cfloat), ih, name, value)
end
function IupSetDouble(ih::Ptr{Ihandle}, name::String, value)
  ccall( (:IupSetFloat, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cdouble), ih, name, value)
end
function IupSetRGB(ih::Ptr{Ihandle}, name::String, r::Cuchar, g::Cuchar, b::Cuchar)
  ccall( (:IupSetRGB, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cuchar, Cuchar, Cuchar), ih, name, r, g, b)
end
function IupGetAttribute(ih::Ptr{Ihandle}, name::String)
	ccall((:IupGetAttribute, iup), Ptr{UInt8}, (Ptr{Ihandle}, Ptr{UInt8}), ih, name)
end
function IupGetInt(ih::Ptr{Ihandle}, name::String)
	ccall((:IupGetInt, iup), Cint, (Ptr{Ihandle}, Ptr{UInt8}), ih, name)
end
function IupGetInt2(ih::Ptr{Ihandle}, name::String)
	ccall((:IupGetInt2, iup), Cint, (Ptr{Ihandle}, Ptr{UInt8}), ih, name)
end
function IupGetIntInt(ih::Ptr{Ihandle}, name::String, i1::Ptr{Cint}, i2::Ptr{Cint})
  ccall( (:IupGetIntInt, iup), Cint, (Ptr{Ihandle}, Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}), ih, name, i1, i2)
end
function IupGetFloat(ih::Ptr{Ihandle}, name::String)
	ccall((:IupGetFloat, iup), Cfloat, (Ptr{Ihandle}, Ptr{UInt8}), ih, name)
end
function IupGetDouble(ih::Ptr{Ihandle}, name::String)
    ccall((:IupGetFloat, iup), Cdouble, (Ptr{Ihandle}, Ptr{UInt8}), ih, name)
end
function IupGetRGB(ih::Ptr{Ihandle}, name::String, r::Ptr{Cuchar}, g::Ptr{Cuchar}, b::Ptr{Cuchar})
  ccall( (:IupGetRGB, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}), ih, name, r, g, b)
end
function IupSetAttributeId(ih::Ptr{Ihandle}, name::String, id::Cint, value::String)
  ccall( (:IupSetAttributeId, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Ptr{UInt8}), ih, name, id, value)
end
function IupSetStrAttributeId(ih::Ptr{Ihandle}, name::String, id::Cint, value::String)
  ccall( (:IupSetStrAttributeId, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Ptr{UInt8}), ih, name, id, value)
end
function IupSetIntId(ih::Ptr{Ihandle}, name::String, id::Cint, value::Cint)
  ccall( (:IupSetIntId, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Cint), ih, name, id, value)
end
function IupSetFloatId(ih::Ptr{Ihandle}, name::String, id::Cint, value::Cfloat)
  ccall( (:IupSetFloatId, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Cfloat), ih, name, id, value)
end
function IupSetDoubleId(ih::Ptr{Ihandle}, name::String, id::Cint, value::Cdouble)
  ccall( (:IupSetFloatId, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Cdouble), ih, name, id, value)
end
function IupSetRGBId(ih::Ptr{Ihandle}, name::String, id::Cint, r::Cuchar, g::Cuchar, b::Cuchar)
  ccall( (:IupSetRGBId, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Cuchar, Cuchar, Cuchar), ih, name, id, r, g, b)
end
function IupGetAttributeId(ih::Ptr{Ihandle}, name::String, id::Cint)
  ccall( (:IupGetAttributeId, iup), Ptr{UInt8}, (Ptr{Ihandle}, Ptr{UInt8}, Cint), ih, name, id)
end
function IupGetIntId(ih::Ptr{Ihandle}, name::String, id::Cint)
  ccall( (:IupGetIntId, iup), Cint, (Ptr{Ihandle}, Ptr{UInt8}, Cint), ih, name, id)
end
function IupGetFloatId(ih::Ptr{Ihandle}, name::String, id::Cint)
  ccall( (:IupGetFloatId, iup), Cfloat, (Ptr{Ihandle}, Ptr{UInt8}, Cint), ih, name, id)
end
function IupGetDoubleId(ih::Ptr{Ihandle}, name::String, id::Cint)
  ccall( (:IupGetFloatId, iup), Cdouble, (Ptr{Ihandle}, Ptr{UInt8}, Cint), ih, name, id)
end
function IupGetRGBId(ih::Ptr{Ihandle}, name::String, id::Cint, r::Ptr{Cuchar}, g::Ptr{Cuchar}, b::Ptr{Cuchar})
  ccall( (:IupGetRGBId, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}), ih, name, id, r, g, b)
end
function IupSetAttributeId2(ih::Ptr{Ihandle}, name::String, lin::Cint, col::Cint, value::String)
  ccall( (:IupSetAttributeId2, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Cint, Ptr{UInt8}), ih, name, lin, col, value)
end
function IupSetStrAttributeId2(ih::Ptr{Ihandle}, name::String, lin::Cint, col::Cint, value::String)
  ccall( (:IupSetStrAttributeId2, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Cint, Ptr{UInt8}), ih, name, lin, col, value)
end
function IupSetIntId2(ih::Ptr{Ihandle}, name::String, lin::Cint, col::Cint, value::Cint)
  ccall( (:IupSetIntId2, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Cint, Cint), ih, name, lin, col, value)
end
function IupSetFloatId2(ih::Ptr{Ihandle}, name::String, lin::Cint, col::Cint, value::Cfloat)
  ccall( (:IupSetFloatId2, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Cint, Cfloat), ih, name, lin, col, value)
end
function IupSetRGBId2(ih::Ptr{Ihandle}, name::String, lin::Cint, col::Cint, r::Cuchar, g::Cuchar, b::Cuchar)
  ccall( (:IupSetRGBId2, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Cint, Cuchar, Cuchar, Cuchar), ih, name, lin, col, r, g, b)
end
function IupGetAttributeId2(ih::Ptr{Ihandle}, name::String, lin::Cint, col::Cint)
  ccall( (:IupGetAttributeId2, iup), Ptr{UInt8}, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Cint), ih, name, lin, col)
end
function IupGetIntId2(ih::Ptr{Ihandle}, name::String, lin::Cint, col::Cint)
  ccall( (:IupGetIntId2, iup), Cint, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Cint), ih, name, lin, col)
end
function IupGetFloatId2(ih::Ptr{Ihandle}, name::String, lin::Cint, col::Cint)
  ccall( (:IupGetFloatId2, iup), Cfloat, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Cint), ih, name, lin, col)
end
function IupGetRGBId2(ih::Ptr{Ihandle}, name::String, lin::Cint, col::Cint, r::Ptr{Cuchar}, g::Ptr{Cuchar}, b::Ptr{Cuchar})
  ccall( (:IupGetRGBId2, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Cint, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}), ih, name, lin, col, r, g, b)
end
function IupSetGlobal(name::String, value::String)
	ccall((:IupSetGlobal, iup), Void, (Ptr{UInt8}, Ptr{UInt8}), name, value)
end
function IupSetStrGlobal(name::String, value::String)
  ccall( (:IupSetStrGlobal, iup), Void, (Ptr{UInt8}, Ptr{UInt8}), name, value)
end
function IupGetGlobal(name::String)
	ccall((:IupGetGlobal, iup), Ptr{UInt8}, (Ptr{UInt8},), name)
end
function IupSetFocus(ih::Ptr{Ihandle})
  ccall( (:IupSetFocus, iup), Ptr{Ihandle}, (Ptr{Ihandle},), ih)
end
function IupGetFocus()
  ccall( (:IupGetFocus, iup), Ptr{Ihandle}, (), )
end
function IupPreviousField(ih::Ptr{Ihandle})
  ccall( (:IupPreviousField, iup), Ptr{Ihandle}, (Ptr{Ihandle},), ih)
end
function IupNextField(ih::Ptr{Ihandle})
  ccall( (:IupNextField, iup), Ptr{Ihandle}, (Ptr{Ihandle},), ih)
end
function IupGetCallback(ih::Ptr{Ihandle}, name::String)
  ccall( (:IupGetCallback, iup), Icallback, (Ptr{Ihandle}, Ptr{UInt8}), ih, name)
end
function IupSetCallback(ih::Ptr{Ihandle}, name::String, func::Icallback)
	ccall((:IupSetCallback, iup), Icallback, (Ptr{Ihandle}, Ptr{UInt8}, Icallback), ih, name, func)
end
function IupGetFunction(name::String)
  ccall( (:IupGetFunction, iup), Icallback, (Ptr{UInt8},), name)
end
function IupSetFunction(name::String, func::Icallback)
	ccall((:IupSetFunction, iup), Icallback, (Ptr{UInt8}, Icallback), name, func)
end
function IupGetHandle(name::String)
	ccall((:IupGetHandle, iup), Ptr{Ihandle}, (Ptr{UInt8},), name)
end
function IupGetHandle(name::Ptr{UInt8})
    ccall((:IupGetHandle, iup), Ptr{Ihandle}, (Ptr{UInt8},), name)
end
function IupSetHandle(name::String, ih::Ptr{Ihandle})
	ccall((:IupSetHandle, iup), Ptr{Ihandle}, (Ptr{UInt8}, Ptr{Ihandle}), name, ih)
end
function IupGetAllNames(names::Ptr{Ptr{UInt8}}, n::Cint)
  ccall( (:IupGetAllNames, iup), Cint, (Ptr{Ptr{UInt8}}, Cint), names, n)
end
function IupGetAllDialogs(names::Ptr{Ptr{UInt8}}, n::Cint)
  ccall( (:IupGetAllDialogs, iup), Cint, (Ptr{Ptr{UInt8}}, Cint), names, n)
end
function IupGetName(ih::Ptr{Ihandle})
  ccall( (:IupGetName, iup), Ptr{UInt8}, (Ptr{Ihandle},), ih)
end
function IupSetAttributeHandle(ih::Ptr{Ihandle}, name::String, ih_named::Ptr{Ihandle})
	ccall((:IupSetAttributeHandle, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Ptr{Ihandle}), ih, name, ih_named)
end
function IupGetAttributeHandle(ih::Ptr{Ihandle}, name::String)
	ccall((:IupGetAttributeHandle, iup), Ptr{Ihandle}, (Ptr{Ihandle}, Ptr{UInt8}), ih, name)
end
function IupGetClassName(ih::Ptr{Ihandle})
	ccall((:IupGetClassName, iup), Ptr{UInt8}, (Ptr{Ihandle},), ih)
end
function IupGetClassType(ih::Ptr{Ihandle})
  ccall( (:IupGetClassType, iup), Ptr{UInt8}, (Ptr{Ihandle},), ih)
end
function IupGetAllClasses(names::Ptr{Ptr{UInt8}}, n::Int)
  ccall( (:IupGetAllClasses, iup), Cint, (Ptr{Ptr{UInt8}}, Cint), names, n)
end
function IupGetClassAttributes(classname::String, names::Ptr{Ptr{UInt8}}, n::Int)
	ccall((:IupGetClassAttributes, iup), Cint, (Ptr{UInt8}, Ptr{Ptr{UInt8}}, Cint), classname, names, n)
end
function IupGetClassCallbacks(classname::String, names::Ptr{Ptr{UInt8}}, n::Int)
	ccall((:IupGetClassCallbacks, iup), Cint, (Ptr{UInt8}, Ptr{Ptr{UInt8}}, Cint), classname, names, n)
end
function IupSaveClassAttributes(ih::Ptr{Ihandle})
  ccall( (:IupSaveClassAttributes, iup), Void, (Ptr{Ihandle},), ih)
end
function IupCopyClassAttributes(src_ih::Ptr{Ihandle}, dst_ih::Ptr{Ihandle})
  ccall( (:IupCopyClassAttributes, iup), Void, (Ptr{Ihandle}, Ptr{Ihandle}), src_ih, dst_ih)
end
function IupSetClassDefaultAttribute(classname::String, name::String, value::String)
  ccall( (:IupSetClassDefaultAttribute, iup), Void, (Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}), classname, name, value)
end
function IupClassMatch(ih::Ptr{Ihandle}, classname::String)
  ccall( (:IupClassMatch, iup), Cint, (Ptr{Ihandle}, Ptr{UInt8}), ih, classname)
end
function IupCreate(classname::String)
  ccall( (:IupCreate, iup), Ptr{Ihandle}, (Ptr{UInt8},), classname)
end
function IupCreatev(classname::String, params::Ptr{Ptr{Void}})
  ccall( (:IupCreatev, iup), Ptr{Ihandle}, (Ptr{UInt8}, Ptr{Ptr{Void}}), classname, params)
end
function IupFill()
	ccall((:IupFill, iup), Ptr{Ihandle}, (), )
end
function IupRadio(child::Ptr{Ihandle})
	ccall((:IupRadio, iup), Ptr{Ihandle}, (Ptr{Ihandle},), child)
end
function IupVboxv(children::Ptr{Ptr{Ihandle}})
  ccall( (:IupVboxv, iup), Ptr{Ihandle}, (Ptr{Ptr{Ihandle}},), children)
end
function IupZboxv(children::Ptr{Ptr{Ihandle}})
  ccall( (:IupZboxv, iup), Ptr{Ihandle}, (Ptr{Ptr{Ihandle}},), children)
end
function IupHboxv(children::Ptr{Ptr{Ihandle}})
  ccall( (:IupHboxv, iup), Ptr{Ihandle}, (Ptr{Ptr{Ihandle}},), children)
end
function IupNormalizerv(ih_list::Ptr{Ptr{Ihandle}})
  ccall( (:IupNormalizerv, iup), Ptr{Ihandle}, (Ptr{Ptr{Ihandle}},), ih_list)
end
function IupCboxv(children::Ptr{Ptr{Ihandle}})
  ccall( (:IupCboxv, iup), Ptr{Ihandle}, (Ptr{Ptr{Ihandle}},), children)
end
function IupSbox(child::Ptr{Ihandle})
  ccall( (:IupSbox, iup), Ptr{Ihandle}, (Ptr{Ihandle},), child)
end
function IupSplit(child1::Ptr{Ihandle}, child2::Ptr{Ihandle})
  ccall( (:IupSplit, iup), Ptr{Ihandle}, (Ptr{Ihandle}, Ptr{Ihandle}), child1, child2)
end
function IupScrollBox(child::Ptr{Ihandle})
  ccall( (:IupScrollBox, iup), Ptr{Ihandle}, (Ptr{Ihandle},), child)
end
function IupGridBoxv(children::Ptr{Ptr{Ihandle}})
  ccall( (:IupGridBoxv, iup), Ptr{Ihandle}, (Ptr{Ptr{Ihandle}},), children)
end
function IupExpander(child::Ptr{Ihandle})
  ccall( (:IupExpander, iup), Ptr{Ihandle}, (Ptr{Ihandle},), child)
end
function IupDetachBox(child::Ptr{Ihandle})
  ccall( (:IupDetachBox, iup), Ptr{Ihandle}, (Ptr{Ihandle},), child)
end
function IupBackgroundBox(child::Ptr{Ihandle})
	ccall((:IupBackgroundBox, iup), Ptr{Ihandle}, (Ptr{Ihandle},), child)
end
function IupFrame(child::Ptr{Ihandle})
	ccall((:IupFrame, iup), Ptr{Ihandle}, (Ptr{Ihandle},), child)
end

function IupImage(width::Int, height::Int, pixmap::Ptr{Cuchar})
	ccall((:IupImage, iup), Ptr{Ihandle}, (Cint, Cint, Ptr{Cuchar}), width, height, pixmap)
end
function IupImage(width::Integer, height::Integer, pixmap::Array{UInt8})
	IupImage(width, height, pointer(pixmap))
end

function IupImageRGB(width::Cint, height::Cint, pixmap::Ptr{Cuchar})
  ccall( (:IupImageRGB, iup), Ptr{Ihandle}, (Cint, Cint, Ptr{Cuchar}), width, height, pixmap)
end
function IupImageRGBA(width::Int, height::Int, pixmap::Ptr{Cuchar})
	ccall((:IupImageRGBA, iup), Ptr{Ihandle}, (Cint, Cint, Ptr{Cuchar}), width, height, pixmap)
end
function IupItem(title::String, action::String="")
	ccall((:IupItem, iup), Ptr{Ihandle}, (Ptr{UInt8}, Ptr{UInt8}), title, action)
end
function IupSubmenu(title::String, child::Ptr{Ihandle})
	ccall((:IupSubmenu, iup), Ptr{Ihandle}, (Ptr{UInt8}, Ptr{Ihandle}), title, child)
end
function IupSeparator()
	ccall((:IupSeparator, iup), Ptr{Ihandle}, (), )
end
function IupMenuv(children::Ptr{Ptr{Ihandle}})
  ccall( (:IupMenuv, iup), Ptr{Ihandle}, (Ptr{Ptr{Ihandle}},), children)
end
function IupButton(title::String="", action::String="")
	ccall((:IupButton, iup), Ptr{Ihandle}, (Ptr{UInt8}, Ptr{UInt8}), title, action)
end
function IupCanvas(action::String)
	ccall((:IupCanvas, iup), Ptr{Ihandle}, (Ptr{UInt8},), action)
end
function IupCanvas(action::Ptr{Void}=C_NULL)
	ccall((:IupCanvas, iup), Ptr{Ihandle}, (Ptr{UInt8},), action)
end
function IupDialog(child::Ptr{Ihandle})
	ccall((:IupDialog, iup), Ptr{Ihandle}, (Ptr{Ihandle},), child)
end
function IupUser()
  ccall( (:IupUser, iup), Ptr{Ihandle}, (), )
end
function IupLabel(title::String="")
	ccall((:IupLabel, iup), Ptr{Ihandle}, (Ptr{UInt8},), title)
end
function IupLabel(title::Ptr{Void})
	ccall((:IupLabel, iup), Ptr{Ihandle}, (Ptr{UInt8},), title)
end
function IupList(action::String="")
	ccall((:IupList, iup), Ptr{Ihandle}, (Ptr{UInt8},), action)
end
function IupList(action::Ptr{Void})
	ccall((:IupList, iup), Ptr{Ihandle}, (Ptr{UInt8},), action)
end
function IupText(action::String="")
	ccall((:IupText, iup), Ptr{Ihandle}, (Ptr{UInt8},), action)
end
function IupMultiLine(action::String="")
	ccall((:IupMultiLine, iup), Ptr{Ihandle}, (Ptr{UInt8},), action)
end
function IupMultiLine(action::Ptr{Void})
	ccall((:IupMultiLine, iup), Ptr{Ihandle}, (Ptr{UInt8},), action)
end
function IupToggle(title::String="", action::String="")
	ccall((:IupToggle, iup), Ptr{Ihandle}, (Ptr{UInt8}, Ptr{UInt8}), title, action)
end
function IupTimer()
  ccall( (:IupTimer, iup), Ptr{Ihandle}, (), )
end
function IupClipboard()
  ccall( (:IupClipboard, iup), Ptr{Ihandle}, (), )
end
function IupProgressBar()
	ccall((:IupProgressBar, iup), Ptr{Ihandle}, (), )
end
function IupVal(type_::String="")
	ccall((:IupVal, iup), Ptr{Ihandle}, (Ptr{UInt8},), type_)
end
function IupVal(type_::Ptr{Void})
	ccall((:IupVal, iup), Ptr{Ihandle}, (Ptr{UInt8},), type_)
end
function IupTabsv(children::Ptr{Ptr{Ihandle}})
  ccall( (:IupTabsv, iup), Ptr{Ihandle}, (Ptr{Ptr{Ihandle}},), children)
end
function IupTree()
	ccall((:IupTree, iup), Ptr{Ihandle}, (), )
end
function IupLink(url::String, title::String)
  ccall( (:IupLink, iup), Ptr{Ihandle}, (Ptr{UInt8}, Ptr{UInt8}), url, title)
end
function IupSpin()
  ccall( (:IupSpin, iup), Ptr{Ihandle}, (), )
end
function IupSpinbox(child::Ptr{Ihandle})
  ccall( (:IupSpinbox, iup), Ptr{Ihandle}, (Ptr{Ihandle},), child)
end
function IupSaveImageAsText(ih::Ptr{Ihandle}, file_name::String, format::String, name::String)
  ccall( (:IupSaveImageAsText, iup), Cint, (Ptr{Ihandle}, Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}), ih, file_name, format, name)
end
function IupTextConvertLinColToPos(ih::Ptr{Ihandle}, lin::Cint, col::Cint, pos::Ptr{Cint})
  ccall( (:IupTextConvertLinColToPos, iup), Void, (Ptr{Ihandle}, Cint, Cint, Ptr{Cint}), ih, lin, col, pos)
end
function IupTextConvertPosToLinCol(ih::Ptr{Ihandle}, pos::Cint, lin::Ptr{Cint}, col::Ptr{Cint})
  ccall( (:IupTextConvertPosToLinCol, iup), Void, (Ptr{Ihandle}, Cint, Ptr{Cint}, Ptr{Cint}), ih, pos, lin, col)
end
function IupConvertXYToPos(ih::Ptr{Ihandle}, x::Cint, y::Cint)
  ccall( (:IupConvertXYToPos, iup), Cint, (Ptr{Ihandle}, Cint, Cint), ih, x, y)
end
function IupStoreGlobal(name::String, value::String)
  ccall( (:IupStoreGlobal, iup), Void, (Ptr{UInt8}, Ptr{UInt8}), name, value)
end
function IupStoreAttribute(ih::Ptr{Ihandle}, name::String, value::String)
	ccall((:IupStoreAttribute, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Ptr{UInt8}), ih, name, value)
end
function IupStoreAttribute(ih::Ptr{Ihandle}, name::String, value::Ptr{UInt8})
	ccall((:IupStoreAttribute, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Ptr{UInt8}), ih, name, value)
end
function IupStoreAttributeId(ih::Ptr{Ihandle}, name::String, id::Cint, value::String)
	ccall((:IupStoreAttributeId, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Ptr{UInt8}), ih, name, id, value)
end
function IupStoreAttributeId2(ih::Ptr{Ihandle}, name::String, lin::Cint, col::Cint, value::String)
  ccall( (:IupStoreAttributeId2, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Cint, Ptr{UInt8}), ih, name, lin, col, value)
end
function IupTreeSetUserId(ih::Ptr{Ihandle}, id::Cint, userid::Ptr{Void})
  ccall( (:IupTreeSetUserId, iup), Cint, (Ptr{Ihandle}, Cint, Ptr{Void}), ih, id, userid)
end
function IupTreeGetUserId(ih::Ptr{Ihandle}, id::Cint)
  ccall( (:IupTreeGetUserId, iup), Ptr{Void}, (Ptr{Ihandle}, Cint), ih, id)
end
function IupTreeGetId(ih::Ptr{Ihandle}, userid::Ptr{Void})
  ccall( (:IupTreeGetId, iup), Cint, (Ptr{Ihandle}, Ptr{Void}), ih, userid)
end
function IupTreeSetAttributeHandle(ih::Ptr{Ihandle}, name::String, id::Cint, ih_named::Ptr{Ihandle})
  ccall( (:IupTreeSetAttributeHandle, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Ptr{Ihandle}), ih, name, id, ih_named)
end
function IupTreeSetAttribute(ih::Ptr{Ihandle}, name::String, id::Cint, value::String)
  ccall( (:IupTreeSetAttribute, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Ptr{UInt8}), ih, name, id, value)
end
function IupTreeStoreAttribute(ih::Ptr{Ihandle}, name::String, id::Cint, value::String)
  ccall( (:IupTreeStoreAttribute, iup), Void, (Ptr{Ihandle}, Ptr{UInt8}, Cint, Ptr{UInt8}), ih, name, id, value)
end
function IupTreeGetAttribute(ih::Ptr{Ihandle}, name::String, id::Int)
	ccall((:IupTreeGetAttribute, iup), Ptr{UInt8}, (Ptr{Ihandle}, Ptr{UInt8}, Cint), ih, name, id)
end
function IupTreeGetInt(ih::Ptr{Ihandle}, name::String, id::Int)
	ccall((:IupTreeGetInt, iup), Cint, (Ptr{Ihandle}, Ptr{UInt8}, Cint), ih, name, id)
end
function IupTreeGetFloat(ih::Ptr{Ihandle}, name::String, id::Int)
	ccall((:IupTreeGetFloat, iup), Cfloat, (Ptr{Ihandle}, Ptr{UInt8}, Cint), ih, name, id)
end
function IupGetActionName()
	ccall((:IupGetActionName, iup), Ptr{UInt8}, (), )
end
function IupMapFont(iupfont::String)
	ccall((:IupMapFont, iup), Ptr{UInt8}, (Ptr{UInt8},), iupfont)
end
function IupUnMapFont(driverfont::String)
	ccall((:IupUnMapFont, iup), Ptr{UInt8}, (Ptr{UInt8},), driverfont)
end
function IupFileDlg()
	ccall((:IupFileDlg, iup), Ptr{Ihandle}, (), )
end
function IupMessageDlg()
	ccall((:IupMessageDlg, iup), Ptr{Ihandle}, (), )
end
function IupColorDlg()
	ccall((:IupColorDlg, iup), Ptr{Ihandle}, (), )
end
function IupFontDlg()
	ccall((:IupFontDlg, iup), Ptr{Ihandle}, (), )
end
function IupProgressDlg()
	ccall((:IupProgressDlg, iup), Ptr{Ihandle}, (), )
end
function IupGetFile(arq::String)
	ccall((:IupGetFile, iup), Cint, (Ptr{UInt8},), arq)
end
function IupMessage(title::String, msg::String)
	ccall((:IupMessage, iup), Void, (Ptr{UInt8}, Ptr{UInt8}), title, msg)
end
function IupMessage(title::String, msg::Ptr{UInt8})
	ccall((:IupMessage, iup), Void, (Ptr{UInt8}, Ptr{UInt8}), title, msg)
end

function IupAlarm(title::String, msg::String, b1::String, b2=C_NULL, b3=C_NULL)
	# Should I test that if b2 or b3 are given but are not strings?
	ccall((:IupAlarm, iup), Cint, (Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}), title, msg, b1, b2, b3)
end

function IupListDialog(_type::Int, title::String, size::Int, list::Ptr{Ptr{UInt8}}, op::Int, max_col::Int,
		max_lin::Int, marks::Ptr{Int})
	ccall((:IupListDialog, iup), Cint, (Cint, Ptr{UInt8}, Cint, Ptr{Ptr{UInt8}}, Cint, Cint, Cint, Ptr{Cint}),
		_type, title, size, list, op, max_col, max_lin, marks)
end
function IupGetText(title::String, text::String)
	ccall((:IupGetText, iup), Cint, (Ptr{UInt8}, Ptr{UInt8}), title, text)
end
function IupGetColor(x::Int, y::Int, r::Ptr{Cuchar}, g::Ptr{Cuchar}, b::Ptr{Cuchar})
	ccall((:IupGetColor, iup), Cint, (Cint, Cint, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}), x, y, r, g, b)
end
function IupGetParamv(title::String, action::Iparamcb, user_data::Ptr{Void}, format::String, param_count::Int,
		param_extra::Int, param_data::Ptr{Ptr{Void}})
	ccall((:IupGetParamv, iup), Cint, (Ptr{UInt8}, Iparamcb, Ptr{Void}, Ptr{UInt8}, Cint, Cint, Ptr{Ptr{Void}}),
		title, action, user_data, format, param_count, param_extra, param_data)
end
function IupLayoutDialog(dialog::Ptr{Ihandle})
	ccall((:IupLayoutDialog, iup), Ptr{Ihandle}, (Ptr{Ihandle},), dialog)
end
function IupElementPropertiesDialog(elem::Ptr{Ihandle})
	ccall((:IupElementPropertiesDialog, iup), Ptr{Ihandle}, (Ptr{Ihandle},), elem)
end

#=
const GtkFileChooserDialogDict = Dict{Int, Function}()  # for varargs ccall
type GtkFileChooserDialog <: GtkDialogI
    handle::Ptr{GObject}
    function GtkFileChooserDialog(title::String, parent::Union(GtkWindow,Ptr{Void}), action::Integer, button_text_response...)
        n = length(button_text_response)
        if !iseven(n)
            error("button_text_response must consist of text/response pairs")
        end
        npairs = div(n, 2)
        if !haskey(GtkFileChooserDialogDict, npairs)
            # Build a function expression that makes ccall with explicit args of correct types
            ctypeexpr = Expr(:tuple,Ptr{UInt8},Ptr{Void},Cint,ntuple(n,i->isodd(i) ? Ptr{UInt8} : Cint)...,Ptr{Void})
            argnameexpr = Expr(:tuple,:title,:parent,:action,Expr(:...,:button_text_response))
            argvalexpr = tuple(:title,:(anonp(parent)),:action,ntuple(n,i->:(button_text_response[$i]))...,:C_NULL)
            ex = Expr(:function, argnameexpr, Expr(:ccall,
                                                   :(:gtk_file_chooser_dialog_new,libgtk),
                                                   :(Ptr{GObject}),
                                                   ctypeexpr,
                                                   argvalexpr...))
            GtkFileChooserDialogDict[npairs] = eval(ex)
        end
        hnd = GtkFileChooserDialogDict[npairs](title, parent, action,button_text_response...)
        widget = gc_ref(new(hnd))
        gtk_doevent()
        show(widget)
        widget
    end
end
=#


text:
@doc raw"""
    AdaptiveThreshold <: AbstractImageBinarizationAlgorithm
    AdaptiveThreshold([img]; [window_size,] percentage = 15)

    binarize([T,] img, f::AdaptiveThreshold)
    binarize!([out,] img, f::AdaptiveThreshold)

Binarize `img` using a threshold that varies according to background
illumination.

# Output

Return the binarized image as an `Array{Gray{T}}` of size `size(img)`. If
`T` is not specified, it is inferred from `out` and `img`.

# Details

If the value of a pixel is `t` percent less than the average of an ``s
\times s`` window of pixels centered around the pixel, then the pixel is set
to black, otherwise it is set to white.

A computationally efficient method for computing the average of an ``s
\times s`` neighbourhood is achieved by using an *integral image*
`integral_image`.

This algorithm works particularly well on images that have distinct contrast
between background and foreground. See [1] for more details.

# Arguments

The function argument is described in more detail below.

##  `img::AbstractArray`

The image that need to be binarized. The image is automatically converted
to `Gray` in order to construct the requisite graylevel histogram.

You can also pass `img` to `AdaptiveThreshold` to automatically infer the "best"
`window_size`.

# Options

Various options for the parameters of `AdaptiveThreshold`, `binarize` and
`binarize!` are described in more detail below.

## Choices for `percentage`

You can specify an integer for the `percentage` (denoted by `t` in [1])
which must be between 0 and 100. Default: 15

## Choices for `window_size`

The argument `window_size` (denoted by `s` in [1]) specifies the size of
pixel's square neighbourhood which must be greater than zero.

If `img` is passed to `AdaptiveThreshold` constructor, then `window_size` is infered as
the integer closest to 1/8 of the average of the width and height of `img`.

# Examples

```julia
using TestImages

img = testimage("cameraman")
f = AdaptiveThreshold(window_size = 16)
img₀₁ = binarize(img, f)

f = AdaptiveThreshold(img) # infer the best `window_size` using `img`
img₀₁ = binarize(img, f)
```

See also [`binarize!`](@ref) for in-place operation.

# References

[1] Bradley, D. (2007). Adaptive Thresholding using Integral Image. *Journal of Graphic Tools*, 12(2), pp.13-21. [doi:10.1080/2151237x.2007.10129236](https://doi.org/10.1080/2151237x.2007.10129236)

"""
struct AdaptiveThreshold <: AbstractImageBinarizationAlgorithm
    window_size::Int
    percentage::Float64

    function AdaptiveThreshold(window_size::Integer, percentage::Real)
        window_size < 0 && throw(ArgumentError("window_size should be non-negative."))
        (percentage < 0 || percentage > 100) && throw(ArgumentError("percentage should be ∈ [0, 100]."))
        new(window_size, percentage)
    end
end

function AdaptiveThreshold(img::Union{AbstractArray, Nothing}=nothing;
                           window_size::Union{Integer, Nothing} = nothing,
                           percentage::Real = 15)
    if window_size == nothing
        if img == nothing
            depwarn("deprecated: without img given, window_size will be required in the future.", :AdaptiveThreshold)
            window_size = 32
            # Deprecated in ImageBinarization v0.3
            # throw(ArgumentError("window_size is required without img given"))
        else
            window_size = round(Int, mean(size(img))/8)
        end
    end
    return AdaptiveThreshold(window_size, percentage)
end

function (f::AdaptiveThreshold)(out::GenericGrayImage,
                                img::GenericGrayImage)

    size(out) == size(img) || throw(ArgumentError("out and img should have the same shape, instead they are $(size(out)) and $(size(img))"))

    rₛ = CartesianIndex(Tuple(repeated(f.window_size ÷ 2, ndims(img))))
    R = CartesianIndices(img)
    p_first, p_last = first(R), last(R)

    integral_img = integral_image(img)
    @simd for p in R
        p_tl = max(p_first, p - rₛ)
        p_br = min(p_last, p + rₛ)
        # can we pre-calculate this before the for-loop?
        total = boxdiff(integral_img, p_tl, p_br)
        count = length(_colon(p_tl, p_br))
        if img[p] * count <= total * ((100 - f.percentage) / 100)
            out[p] = 0
        else
            out[p] = 1
        end
    end
    out
end

# first do Color3 to Gray conversion
function (f::AdaptiveThreshold)(out::GenericGrayImage, img::AbstractArray{<:Color3}, args...; kwargs...)
    # map `img` to grayspace while keeping the storage type
    # TODO: this mapping operation can be done lazily to reduce memory allocation
    GT = base_color_type(eltype(out)){eltype(eltype(img))}
    f(out, GT.(img), args...; kwargs...)
end


text:
using ..Helper: init

function simulate!(x, m)
    dim, steps = size(x)
    for t = 2:steps, j = 1:dim
        y = 0.0
        @simd for i = 1:dim
            y += m[i, j] * x[i, t-1]
        end
        x[j, t] = tanh(y)
    end
end

function prepare(name; m=nothing)
    res = init(name)
    if m != nothing
        res[:m] = m
    end
    function run()
        simulate!(res[:x], res[:m])
        res
    end
end

max_stars_repo_name: tkf/comparatist

max_issues_repo_name: tkf/comparatist

max_forks_repo_name: tkf/comparatist


text:
using HyperGraphs

## Boolean queries ##

# hyperedges
e = HyperEdge([1, 2, 3])
@test has_vertex(e, 1)
@test has_vertex(e, [1, 2]) == Vector{Bool}([true, true])
@test has_vertices(e, [1, 2])
che = ChemicalHyperEdge([1], [1, 2, 3])
@test has_vertex(che, 1)
@test has_vertex(che, [1, 2]) == Vector{Bool}([true, true])
@test has_vertices(che, [1, 2])
che = ChemicalHyperEdge(["W", "X"], ["Y", "Z"])
@test in_src("W", che) && in_src(["W"], che)[1]
@test all(in_src(src(che), che))
@test in_tgt("Y", che) && in_tgt(["Y"], che)[1]
@test all(in_tgt(tgt(che), che))

# hypergraphs
vertices_es = [[1, 2, 3], [2, 3, 4]]
es = [HyperEdge(vertices_es[1]), HyperEdge(vertices_es[2])]
x = HyperGraph(es)
@test has_vertex(x, 1)
@test has_vertices(x, vertices(x))
@test has_hyperedge(x, HyperEdge([1, 2, 3]))
@test has_hyperedges(x, hyperedges(x))
@test has_vertex(x, 1)
@test all(has_vertex(x, vertices(x)))
@test has_vertices(x, vertices(x))
@test has_vertex(hyperedges(x)[1], 1)
@test has_vertices(hyperedges(x)[1], [1, 2])
@test has_hyperedge(x, hyperedges(x)[1])
@test has_hyperedges(x, hyperedges(x))
srcs = [[1], [4]]; tgts = [[1, 2, 3], [2, 3, 4]]
ches = [ChemicalHyperEdge(src, tgt) for (src, tgt) in zip(srcs, tgts)]
vertices_chx = [1, 2, 3, 4]
chx = ChemicalHyperGraph(vertices_chx, ches)
@test has_vertex(chx, 1)
@test has_vertices(chx, vertices(chx))
@test !has_hyperedge(HyperGraph(), HyperEdge()) # an emty hypergraph does not have empty hyperedges
@test !has_hyperedge(ChemicalHyperGraph(), ChemicalHyperEdge()) # an emty hypergraph does not have empty hyperedges

# Base.in extension
e1_in = HyperEdge([1, 2, 3])
e2_in = HyperEdge([2, 3, 4])
x_in = HyperGraph([e1_in, e2_in])
@test e1_in in x && e2_in in x_in
che1_in = ChemicalHyperEdge([1, 2], [3])
che2_in = ChemicalHyperEdge([2, 3], [4])
chx_in = ChemicalHyperGraph([che1_in, che2_in])
@test che1_in in chx_in && che2_in in chx_in

# incidences
e1 = HyperEdge([1, 2, 3])
e2 = ChemicalHyperEdge([1], [2, 3])
@test isincident(e1, 1) && isincident(1, e1)
@test isincident(e2, 1) && isincident(1, e2)

# issimple
@test issimple(HyperGraph())
@test issimple(HyperGraph(HyperEdge([1, 2, 3])))
@test !issimple(HyperGraph(HyperEdge([1, 2, 3, 1]))) # loop
@test !issimple(HyperGraph([HyperEdge([1, 2, 3]), HyperEdge([1, 2, 3])])) # multiple hyperedges
@test issimple(ChemicalHyperGraph())
@test issimple(ChemicalHyperGraph(ChemicalHyperEdge([1, 2, 3], [4])))
@test !issimple(ChemicalHyperGraph(ChemicalHyperEdge([1, 2, 3], [4, 1]))) # loop
@test !issimple(ChemicalHyperGraph([ChemicalHyperEdge([1, 2, 3], [4]), ChemicalHyperEdge([1, 2, 3], [4])])) # multiple hyperedges

# isgraph
@test isgraph(HyperGraph([HyperEdge([1, 2]), HyperEdge([1, 2])]))
@test !isgraph(HyperGraph([HyperEdge([1, 2]), HyperEdge([1, 2, 3])]))
@test isgraph(ChemicalHyperGraph([ChemicalHyperEdge([1], [2]), ChemicalHyperEdge([1], [2])]))
@test !isgraph(ChemicalHyperGraph([ChemicalHyperEdge([1], [2]), ChemicalHyperEdge([1, 2], [3])]))

# empty hyperedges and hypergraphs
@test isempty(HyperEdge())
@test isempty(HyperGraph())
@test isempty(HyperGraph[])
@test isempty(HyperEdge[])
@test isempty(ChemicalHyperEdge())
@test isempty(ChemicalHyperGraph())
@test isempty(ChemicalHyperGraph[])
@test isempty(ChemicalHyperEdge[])
@test !isempty(HyperGraph(HyperEdge())) # has one empty hyperedge
@test !isempty(ChemicalHyperGraph(ChemicalHyperEdge())) # has one empty hyperedge

# subhyperedge -- unoriented
e_sub = HyperEdge([1, 2])
e_super = HyperEdge([1, 2, 2, 3])
@test issubhyperedge(e_sub, e_super)
@test !issubhyperedge(e_super, e_sub)

# subhyperedge -- oriented
che_sub = ChemicalHyperEdge([1], [2])
che_super = ChemicalHyperEdge([1, 2], [2, 3, 4])
@test issubhyperedge(che_sub, che_super)
@test !issubhyperedge(che_super, che_sub)

# unique subhyperedge -- unoriented
e_sub = HyperEdge([1, 2])
x1 = HyperGraph([HyperEdge([1, 2, 3]), HyperEdge([2, 3, 4])])
x2 = HyperGraph([HyperEdge([1, 2, 3]), HyperEdge([1, 2, 3, 4])])
@test isuniquesubhyperedge(e_sub, x1)
@test !isuniquesubhyperedge(e_sub, x2)
@test isuniquesubhyperedge(e_sub, HyperGraph(e_sub)) # any hyperedge is a subedge of itself

# unique subhyperedge -- oriented
che_sub = ChemicalHyperEdge([1], [2])
x1 = ChemicalHyperGraph([ChemicalHyperEdge([1], [2, 3]), ChemicalHyperEdge([2], [3, 4])])
x2 = ChemicalHyperGraph([ChemicalHyperEdge([1], [2, 3]), ChemicalHyperEdge([1, 2], [2, 3, 4])])
@test isuniquesubhyperedge(che_sub, x1)
@test !isuniquesubhyperedge(che_sub, x2)
@test isuniquesubhyperedge(che_sub, ChemicalHyperGraph(che_sub)) # any hyperedge is a subedge of itself

# loops
unoriented_loop1 = HyperEdge([1, 1])
unoriented_loop2 = HyperEdge([1, 2, 1, 4])
positive_loop1 = ChemicalHyperEdge([1], [1])
positive_loop2 = ChemicalHyperEdge([1, 2], [2, 5])
negative_loop1 = ChemicalHyperEdge(Int[], [1, 1])
negative_loop2 = ChemicalHyperEdge([1, 2, 3], [4, 5, 4])
@test isloop(unoriented_loop1)
@test isloop(unoriented_loop2)
@test isloop(positive_loop1)
@test isloop(positive_loop2)
@test isloop(negative_loop1)
@test isloop(negative_loop2)
@test is_positive_loop(positive_loop1)
@test is_positive_loop(positive_loop1, 1)
@test is_positive_loop(positive_loop2)
@test is_positive_loop(positive_loop2, 2)
@test !is_positive_loop(positive_loop2, 5)
@test !has_loops(ChemicalHyperGraph())
@test !has_loops(HyperGraph())

# uniformity, regularity
@test iskuniform(x, 3)
@test !iskuniform(x, rand(Int))
@test iskuniform(chx, 4)
@test !iskuniform(chx, rand(Int))
@test iskregular(chx, 2)
@test !iskregular(chx, rand(Int))
@test !iskregular(x, rand(Int))

# chemical hypergraph & hyperedge queries
@test is_netstoich_null(ChemicalHyperEdge([1], [1, 2, 3, 4]), 1)
catalyst_edge = ChemicalHyperEdge([:X], [:X])
@test is_netstoich_null(catalyst_edge, :X)
@test iscatalyst(chx, 1) && iscatalyst(hyperedges(chx)[1], 1)

# parallel and multi-hyperedges

## content queries ##

# incident_hyperedges
x = HyperGraph([HyperEdge([1, 2, 3]), HyperEdge([2, 3, 4])])
srcs = [[1], [4]]; tgts = [[1, 2, 3], [2, 3, 4]]
chx = ChemicalHyperGraph([ChemicalHyperEdge(src, tgt) for (src, tgt) in zip(srcs, tgts)])
@test incident_hyperedges(x, 1) == [hyperedges(x)[1]]
@test incident_hyperedges(chx, 1) == [hyperedges(chx)[1]]

# empty hyperedges and hypergraphs
@test empty_hyperedges(HyperGraph(HyperEdge())) == [HyperEdge()]
@test empty_hyperedges(ChemicalHyperGraph(ChemicalHyperEdge())) == [ChemicalHyperEdge()]
@test num_empty_hyperedges(HyperGraph()) == 0
@test num_empty_hyperedges(HyperGraph(HyperEdge())) == 1
@test num_empty_hyperedges(ChemicalHyperGraph()) == 0
@test num_empty_hyperedges(HyperGraph(HyperEdge())) == 1
@test has_empty_hyperedges(ChemicalHyperGraph(ChemicalHyperEdge()))

# neighbors
@test neighbors(x, 2) == [1, 3, 4]
@test inneighbors(chx, 1) == [1]
@test inneighbors(chx, 2) == [1, 4]
@test inneighbors(chx, 3) == [1, 4]
@test inneighbors(chx, 4) == [4]
@test outneighbors(chx, 1) == [1, 2, 3]
@test outneighbors(chx, 2) == []
@test outneighbors(chx, 3) == []
@test outneighbors(chx, 4) == [2, 3, 4]
@test all_neighbors(x, 1) == neighbors(x, 1) == [2, 3]
@test all_neighbors(x, 2) == neighbors(x, 2) == [1, 3, 4]
@test all_neighbors(chx, 1) == [1, 2, 3]
new_ches = [ChemicalHyperEdge(src, tgt) for (src, tgt) in zip([[1], [4]], [[1, 2, 3, 4], [2, 3, 4, 5]])]
new_chx = ChemicalHyperGraph(new_ches)
@test sort(all_neighbors(new_chx, 4)) == [1, 2, 3, 4, 5]
@test neighbors(HyperGraph(HyperEdge([1, 1])), 1) == [1] # loop
@test all_neighbors(ChemicalHyperGraph(ChemicalHyperEdge([1], [1])), 1) == [1] # loop

# loops
extra_unoriented_e = HyperEdge([1])
extra_oriented_che = ChemicalHyperEdge([1], [2])
@test loops([unoriented_loop1, unoriented_loop2, extra_unoriented_e]) == [unoriented_loop1, unoriented_loop2]
@test loops(HyperGraph([unoriented_loop1, unoriented_loop2, extra_unoriented_e])) == [unoriented_loop1, unoriented_loop2]
@test loops([positive_loop1, negative_loop1, extra_oriented_che]) == [positive_loop1, negative_loop1]
@test loops(ChemicalHyperGraph([positive_loop1, negative_loop1, extra_oriented_che])) == [positive_loop1, negative_loop1]
@test positive_loops([positive_loop1, positive_loop2, extra_oriented_che]) == [positive_loop1, positive_loop2]
@test positive_loops(ChemicalHyperGraph(positive_loop1))[1] == positive_loop1
@test positive_loops(ChemicalHyperGraph([positive_loop1, negative_loop1, negative_loop2]))[1] == positive_loop1
@test num_loops(HyperGraph([unoriented_loop1, unoriented_loop2, extra_unoriented_e])) == 2
@test num_loops(ChemicalHyperGraph([positive_loop1, negative_loop1, extra_oriented_che])) == 2
@test num_loops(HyperGraph()) == num_loops(ChemicalHyperGraph()) == 0

# catalysts (chemical hypergraphs)
@test catalysts(catalyst_edge) == [:X]
@test catalysts(ChemicalHyperEdge([:X, :Y, :Z], [:X])) == [:X]
@test catalysts(ches) == catalysts(chx) == [1, 4]
@test isempty(catalysts(ChemicalHyperEdge(SpeciesSet(:X), SpeciesSet(:X, 2)))) # non-null net stoichiometry

# parallel and multi-hyperedges
parallel_x = HyperGraph([HyperEdge([1, 2, 3]), HyperEdge([1, 2, 3])])
multi_x = HyperGraph([HyperEdge([1, 2, 3]), HyperEdge([1, 2, 3, 4])])
@test parallel_hyperedges(parallel_x) == multi_hyperedges(parallel_x) == hyperedges(parallel_x)
@test isempty(parallel_hyperedges(multi_x))
@test num_parallel_hyperedges(multi_x) == 0
@test multi_hyperedges(multi_x) == [hyperedges(multi_x)[1]]
@test num_parallel_hyperedges(parallel_x) == 2
@test num_multi_hyperedges(multi_x) == 1
@test has_parallel_hyperedges(parallel_x)
@test !has_parallel_hyperedges(multi_x)
@test has_multi_hyperedges(parallel_x)
@test has_multi_hyperedges(multi_x)
parallel_chx = ChemicalHyperGraph([ChemicalHyperEdge(src, tgt) for (src, tgt) in zip([[1], [1]], [[1, 2, 3], [1, 2, 3]])])
multi_chx = ChemicalHyperGraph([ChemicalHyperEdge(src, tgt) for (src, tgt) in zip([[1], [1]], [[1, 2, 3], [1, 2, 3, 4]])])
@test parallel_hyperedges(parallel_chx) == multi_hyperedges(parallel_chx) == hyperedges(parallel_chx)
@test isempty(parallel_hyperedges(multi_chx))
@test num_parallel_hyperedges(multi_chx) == 0
@test multi_hyperedges(multi_chx) == [hyperedges(multi_chx)[1]]
@test num_parallel_hyperedges(parallel_chx) == 2
@test num_multi_hyperedges(multi_chx) == 1
@test has_parallel_hyperedges(parallel_chx)
@test !has_parallel_hyperedges(multi_chx)
@test has_multi_hyperedges(parallel_chx)
@test has_multi_hyperedges(multi_chx)


text:
using ApproxFun, SingularIntegralEquations, Test
import SingularIntegralEquations: stieltjesmoment, stieltjesmoment!, stieltjesjacobimoment

@testset "Stieljes moments" begin
    c = [0.9731840665678853,0.11644664868790366,0.8961305368364185,0.30663942299763747,
         0.4564158422422153,0.7262396331533589,0.6448725310785985,0.05623500638232981,
         0.8452582204677404,0.25385833878392283]

    for z in [1+1.0im,0.1+0.1im]
        o=Fun(one)
        x=Fun(identity)

        @test stieltjes(o)(z) ≈ sum(1/(z-x))
        @test stieltjes(x)(z) ≈ sum(x/(z-x))

        for w in (sqrt(1-x),sqrt(1+x))
            @test stieltjes(w*o)(z) ≈ sum(w/(z-x))
            @test stieltjes(w*x)(z) ≈ sum(w*x/(z-x))
        end

        for a in -0.5:0.5:0.5, b in -0.5:0.5:0.5
            f = Fun(WeightedJacobi(a,b),c)
            @test stieltjes(f)(z) ≈ sum(f/(z-x))
        end

        f = Fun(WeightedJacobi(0.123,0.456),c)
        @test stieltjes(f)(z) ≈ sum(f/(z-x))

        f = Fun(identity, (-1..1) \ 0)
        @test cauchy(sqrt(Fun(one,space(f))-f^2))(z) ≈ cauchy(sqrt(1-Fun()^2),z)
    end

    x = Fun(identity,Segment(im,0) ∪ Segment(0,1))
    w = 2/(sqrt(1-x)*sqrt(1+im*x))

    for x in (0.9im,0.4im,0.4,0.9)
        #@test cauchy(w,x,true)-cauchy(w,x,false) ≈ w(x)
    end

    @testset "High Legendre near interval" begin
        @test stieltjes(Fun(Legendre(),[zeros(256);1]),1.06) == 0
        @test stieltjes(Fun(Legendre(),[zeros(256);1]),1.001) ≈ 7.643611577855717E-6 atol=1E-13
        @test stieltjes(Fun(Legendre(),[zeros(1000);1]),1.001) == 0
    end

    @testset "stieljesmoment!" begin
        z = 1+im
        @test stieltjesmoment!(Vector{ComplexF64}(undef, 10), Legendre(), z)[end] ≈
            stieltjes(Fun(Legendre(),[zeros(9);1]),z)
        sp = JacobiWeight(0.1,0.2,Jacobi(0.1,0.2))
        @test stieltjesmoment!(Vector{ComplexF64}(undef, 10), sp, z)[end] ≈
            stieltjes(Fun(sp,[zeros(9);1]),z)
    end
end


text:
function FRTruncation3d(S::Array{T,4},r::NTuple{3,Int64}) where T
  S_lr = zeros(T,size(S));
  for k=1:size(S,4)
    S_lr[:,:,:,k] .= truncateHOSVD(S[:,:,:,k],r)
  end

  return S_lr
end

function truncateHOSVD(x::Array{T,3},r::NTuple{3,Int64}) where T
  guvw_r = hosvd(real.(x),r)
  guvw_i = hosvd(imag.(x),r)

  return compose(guvw_r)+1im*compose(guvw_i)
end