text:
###############################################################################
#
# Simulate short wave radiation
#
###############################################################################
"""
    short_wave!(can::Canopy4RT{FT},
                can_opt::CanopyOpticals{FT},
                can_rad::CanopyRads{FT},
                in_rad::IncomingRadiation{FT},
                soil::SoilOpticals{FT},
                rt_con::RTCache{FT}
    ) where {FT<:AbstractFloat}

Simulate the short wave radiation through the canopy, given
- `can` [`Canopy4RT`](@ref) type struct
- `can_opt` [`CanopyOpticals`](@ref) type struct
- `can_rad` [`CanopyRads`](@ref) type struct
- `in_rad` [`IncomingRadiation`](@ref) type struct
- `soil` [`SoilOpticals`](@ref) type struct
- `rt_con` [`RTCache`](@ref) type cache
"""
function short_wave!(
            can::Canopy4RT{FT},
            can_opt::CanopyOpticals{FT},
            can_rad::CanopyRads{FT},
            in_rad::IncomingRadiation{FT},
            soil::SoilOpticals{FT},
            rt_con::RTCache{FT}
) where {FT<:AbstractFloat}
    # unpack values from can and soil
    @unpack LAI, nLayer, Ω = can;
    @unpack ks, sb, sf, sigb = can_opt;
    @unpack ρ_SW = soil;
    sw_con = rt_con.sw_con;

    # 1. define some useful parameters
    iLAI = LAI * Ω / nLayer;

    # 2. scattering and extinction coefficients to
    #    thin layer reflectances and transmittances
    # Eq. 17 in mSCOPE paper (changed here to compute real transmission)
    # this is the original equation: τ_ss = 1 - ks * iLAI;
    τ_ss = exp(-ks * iLAI);
    sw_con.τ_dd .= 1 .- can_opt.a .* iLAI;
    sw_con.τ_sd .= sf   .* iLAI;
    sw_con.ρ_dd .= sigb .* iLAI;
    sw_con.ρ_sd .= sb   .* iLAI;
    @unpack ρ_dd, ρ_sd, τ_dd, τ_sd = sw_con;

    # 3. reflectance calculation
    # 3.1 Eq. 18 in mSCOPE paper
    Xss = τ_ss;

    # 3.2 Soil reflectance boundary condition (same for diffuse and direct)
    can_opt.R_sd[:,end] .= ρ_SW;
    can_opt.R_dd[:,end] .= ρ_SW;

    # 3.3 reflectance for each layer from bottom to top
    @inbounds for j in nLayer:-1:1
        sw_con.dnorm      .= 1 .-
                             view(ρ_dd, :, j) .*
                             view(can_opt.R_dd, :, j+1);
        can_opt.Xsd[:,j]  .= ( view(τ_sd, :, j) .+
                               Xss .* view(can_opt.R_sd, :, j+1) .*
                                      view(ρ_dd, :, j) ) ./
                             sw_con.dnorm;
        can_opt.Xdd[:,j]  .= view(τ_dd, :, j) ./ sw_con.dnorm;
        can_opt.R_sd[:,j] .= view(ρ_sd, :, j) .+
                             view(τ_dd, :, j) .*
                                ( view(can_opt.R_sd, :, j+1) .*
                                  Xss .+
                                  view(can_opt.R_dd, :, j+1) .*
                                  view(can_opt.Xsd , :, j  ) );
        can_opt.R_dd[:,j] .= view(ρ_dd        , :, j  ) .+
                             view(τ_dd        , :, j  ) .*
                             view(can_opt.R_dd, :, j+1) .*
                             view(can_opt.Xdd , :, j  );
    end

    # 4. flux profile calculation
    # Eq. 19 in mSCOPE paper
    # 4.1 Boundary condition at top: Incoming solar radiation
    can_opt.Es_[:,1]    .= in_rad.E_direct;
    can_rad.E_down[:,1] .= in_rad.E_diffuse;

    # 4.2 from top to bottom
    @inbounds for j=1:nLayer
        can_rad.netSW_sunlit[:,j] .= view(can_opt.Es_   , :, j) .*
                                     ( 1 .- (τ_ss .+ view(τ_sd, :, j) .+
                                     view(ρ_sd          , :, j)) );
        can_opt.Es_[:,j+1]        .= Xss .*
                                     view(can_opt.Es_   , :, j);
        can_rad.E_down[:,j+1]     .= view(can_opt.Xsd   , :, j) .*
                                     view(can_opt.Es_   , :, j) .+
                                     view(can_opt.Xdd   , :, j) .*
                                     view(can_rad.E_down, :, j);
        can_rad.E_up[:,j]         .= view(can_opt.R_sd  , :, j) .*
                                     view(can_opt.Es_   , :, j) .+
                                     view(can_opt.R_dd  , :, j) .*
                                     view(can_rad.E_down, :, j);
    end

    # 4.3 Boundary condition at the bottom, soil reflectance (Lambertian here)
    last_ind_co = lastindex(can_opt.R_sd, 2);
    can_rad.E_up[:,end] .= view(can_opt.R_sd  , :, last_ind_co) .*
                           view(can_opt.Es_   , :, last_ind_co) .+
                           view(can_opt.R_dd  , :, last_ind_co) .*
                           view(can_rad.E_down, :, last_ind_co);

    # 4.4 Hemispheric total outgoing
    can_rad.Eout .= view(can_rad.E_up, :, 1);

    # 4.5 compute net diffuse radiation per layer:
    @inbounds for j in 1:nLayer
        can_rad.netSW_shade[:,j] .= ( view(can_rad.E_down, :, j) .+
                                      view(can_rad.E_up, :, j+1) ) .*
                                    ( 1 .- ( view(τ_dd, :, j) .+
                                             view(ρ_dd, :, j) ) );
        # Add diffuse radiation to direct radiation as well:
        #can_rad.netSW_sunlit[:,j] += can_rad.netSW_shade[:,j]
    end

    # 4.6 outgoing in viewing direction
    # From Canopy
    sw_con.piLoc2 .= can_opt.vb .* view(can_opt.Po       , 1:nLayer)' .*
                                   view(can_rad.E_down, :, 1:nLayer)  .+
                     can_opt.vf .* view(can_opt.Po       , 1:nLayer)' .*
                                   view(can_rad.E_up  , :, 1:nLayer)  .+
                     can_opt.w  .* view(can_opt.Pso      , 1:nLayer)' .*
                                   in_rad.E_direct;
    #sw_con.piLoc  .= iLAI .* view(sum(sw_con.piLoc2, dims=2), :, 1);
    @inbounds for j in eachindex(sw_con.piLoc)
        sw_con.piLoc[j] = iLAI * sum( view(sw_con.piLoc2, j, :) );
    end

    # 4.7 From Soil
    sw_con.piLos .= view(can_rad.E_up, :, last_ind_co) .*
                    can_opt.Po[end];
    sw_con.piLo  .= sw_con.piLoc .+ sw_con.piLos;
    can_rad.Lo   .= sw_con.piLo ./ pi;

    # 4.8 Save albedos (hemispheric direct and diffuse and directional (obs))
    # rso and rdo are not computed separately
    can_rad.alb_obs     .= sw_con.piLo ./ ( in_rad.E_direct .+
                                            in_rad.E_diffuse );
    can_rad.alb_direct  .= view(can_opt.R_sd, :, 1);
    can_rad.alb_diffuse .= view(can_opt.R_dd, :, 1);

    return nothing
end

max_stars_repo_name: climate-machine/Land


text:
export EMNIST
module EMNIST
    using DataDeps
    using BinDeps
    using FixedPointNumbers
    using MAT: matopen, matread
    using ..MLDatasets: bytes_to_type, datafile, download_dep, download_docstring
    using ..MNIST: convert2image

        const DEPNAME = "EMNIST"

        """
            download([dir]; [i_accept_the_terms_of_use])

        Trigger the (interactive) download of the full dataset into
        "`dir`". If no `dir` is provided the dataset will be
        downloaded into "~/.julia/datadeps/$DEPNAME".

        This function will display an interactive dialog unless
        either the keyword parameter `i_accept_the_terms_of_use` or
        the environment variable `DATADEPS_ALWAY_ACCEPT` is set to
        `true`. Note that using the data responsibly and respecting
        copyright/terms-of-use remains your responsibility.
        """
        download(args...; kw...) = download_dep(DEPNAME, args...; kw...)

        function __init__()
            register(DataDep(
                DEPNAME,
                """
                Dataset: The EMNIST Dataset
                Authors: Gregory Cohen, Saeed Afshar, Jonathan Tapson, and Andre van Schaik
                Website: https://www.nist.gov/itl/products-and-services/emnist-dataset

                [Cohen et al., 2017]
                    Cohen, G., Afshar, S., Tapson, J., & van Schaik, A. (2017).
                    EMNIST: an extension of MNIST to handwritten letters.
                    Retrieved from http://arxiv.org/abs/1702.05373

                The EMNIST dataset is a set of handwritten character digits derived from the
                NIST Special Database 19 (https://www.nist.gov/srd/nist-special-database-19)
                and converted to a 28x28 pixel image format and dataset structure that directly
                matches the MNIST dataset (http://yann.lecun.com/exdb/mnist/). Further information
                on the dataset contents and conversion process can be found in the paper available
                at https://arxiv.org/abs/1702.05373v1.

                The files are available for download at the official
                website linked above. Note that using the data
                responsibly and respecting copyright remains your
                responsibility. For example the website mentions that
                the data is for non-commercial use only. Please read
                the website to make sure you want to download the
                dataset.
                """,
                "http://www.itl.nist.gov/iaui/vip/cs_links/EMNIST/matlab.zip",
                "e1fa805cdeae699a52da0b77c2db17f6feb77eed125f9b45c022e7990444df95",
                post_fetch_method = file -> (run(BinDeps.unpack_cmd(file,dirname(file),".zip","")); rm(file))
            ))
        end

        module Balanced
            using DataDeps
            using BinDeps
            using FixedPointNumbers
            using MAT: matopen, matread
            using ...MLDatasets: bytes_to_type, datafile, download_dep, download_docstring
            using ...MNIST: convert2image

            const DEPNAME = "EMNIST"
            const FILENAME = "matlab/emnist-balanced.mat"

            function traindata(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return reshape(vars["dataset"]["train"]["images"],:,28,28)
            end

            function testdata(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return reshape(vars["dataset"]["test"]["images"],:,28,28)
            end

            function trainlabels(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return vars["dataset"]["train"]["labels"]
            end

            function testlabels(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return vars["dataset"]["test"]["labels"]
            end
        end

        module ByClass
            using DataDeps
            using BinDeps
            using FixedPointNumbers
            using MAT: matopen, matread
            using ...MLDatasets: bytes_to_type, datafile, download_dep, download_docstring
            using ...MNIST: convert2image

            const DEPNAME = "EMNIST"
            const FILENAME = "matlab/emnist-byclass.mat"

            function traindata(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return reshape(vars["dataset"]["train"]["images"],:,28,28)
            end

            function testdata(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return reshape(vars["dataset"]["test"]["images"],:,28,28)
            end

            function trainlabels(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return vars["dataset"]["train"]["labels"]
            end

            function testlabels(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return vars["dataset"]["test"]["labels"]
            end
        end

        module ByMerge
            using DataDeps
            using BinDeps
            using FixedPointNumbers
            using MAT: matopen, matread
            using ...MLDatasets: bytes_to_type, datafile, download_dep, download_docstring
            using ...MNIST: convert2image

            const DEPNAME = "EMNIST"
            const FILENAME = "matlab/emnist-bymerge.mat"

            function traindata(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return reshape(vars["dataset"]["train"]["images"],:,28,28)
            end

            function testdata(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return reshape(vars["dataset"]["test"]["images"],:,28,28)
            end

            function trainlabels(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return vars["dataset"]["train"]["labels"]
            end

            function testlabels(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return vars["dataset"]["test"]["labels"]
            end
        end

        module Digits
            using DataDeps
            using BinDeps
            using FixedPointNumbers
            using MAT: matopen, matread
            using ...MLDatasets: bytes_to_type, datafile, download_dep, download_docstring
            using ...MNIST: convert2image

            const DEPNAME = "EMNIST"
            const FILENAME = "matlab/emnist-digits.mat"

            function traindata(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return reshape(vars["dataset"]["train"]["images"],:,28,28)
            end

            function testdata(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return reshape(vars["dataset"]["test"]["images"],:,28,28)
            end

            function trainlabels(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return vars["dataset"]["train"]["labels"]
            end

            function testlabels(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return vars["dataset"]["test"]["labels"]
            end
        end

        module Letters
            using DataDeps
            using BinDeps
            using FixedPointNumbers
            using MAT: matopen, matread
            using ...MLDatasets: bytes_to_type, datafile, download_dep, download_docstring
            using ...MNIST: convert2image

            const DEPNAME = "EMNIST"
            const FILENAME = "matlab/emnist-letters.mat"

            function traindata(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return reshape(vars["dataset"]["train"]["images"],:,28,28)
            end

            function testdata(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return reshape(vars["dataset"]["test"]["images"],:,28,28)
            end

            function trainlabels(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return vars["dataset"]["train"]["labels"]
            end

            function testlabels(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return vars["dataset"]["test"]["labels"]
            end
        end

        module MNIST
            using DataDeps
            using BinDeps
            using FixedPointNumbers
            using MAT: matopen, matread
            using ...MLDatasets: bytes_to_type, datafile, download_dep, download_docstring
            using ...MNIST: convert2image

            const DEPNAME = "EMNIST"
            const FILENAME = "matlab/emnist-mnist.mat"

            function traindata(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return reshape(vars["dataset"]["train"]["images"],:,28,28)
            end

            function testdata(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return reshape(vars["dataset"]["test"]["images"],:,28,28)
            end

            function trainlabels(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return vars["dataset"]["train"]["labels"]
            end

            function testlabels(; dir = nothing)
                path = datafile(DEPNAME, FILENAME, dir)
                vars = matread(path)
                return vars["dataset"]["test"]["labels"]
            end
        end
end

ext: jl


text:
using Gadfly
using DelimitedFiles
using DataFrames
using ColorTypes

cores = readdlm("../data/cores.dat", Float64, comment_char='#')
frequency = readdlm("../data/frequency.dat", Float64, comment_char='#')
specint = readdlm("../data/specint.dat", Float64, comment_char='#')
transistors = readdlm("../data/transistors.dat", Float64, comment_char='#')
watts = readdlm("../data/watts.dat", Float64, comment_char='#')

df = vcat(
    DataFrame(Year=transistors[:,1], y=transistors[:,2], label="#Transistors\n (thousands)"),
    DataFrame(Year=specint[:,1], y=specint[:,2], label="Single Thread\n Performance\n (SpecINT x 10³)"),
    DataFrame(Year=frequency[:,1], y=frequency[:,2], label="Frequency \n(MHz)"),
    DataFrame(Year=watts[:,1], y=watts[:,2], label="Power (Watts)"),
    DataFrame(Year=cores[:,1], y=cores[:,2], label="#Cores"),
)

p = Gadfly.plot(df,
    x = :Year,
    y = :y,
    size = [0.5mm],
    color = :label,
    #shape = :label,
    Scale.y_log10,
    Guide.title("Microprocessors metrics"),
    Guide.ylabel(nothing),
    Guide.colorkey(title=""),
    Coord.cartesian(ymin = -1, ymax=8),
    Geom.point,
    Geom.smooth,
    Theme(
        minor_label_color = colorant"white",
        major_label_color = colorant"white",
        key_label_color = colorant"white",
        highlight_width = 0.5pt
    )
)

p |> SVG("../images/microprocessors.svg", 15cm, 9cm)
p |> PNG("../images/microprocessors.png", 15cm, 9cm)

max_stars_repo_name: csimal/Julia-Unamur

max_issues_repo_name: csimal/Julia-Unamur

max_forks_repo_name: csimal/Julia-Unamur


text:
import AbstractTrees: print_tree, printnode

"""
decurse recursive patterns
"""
struct MemoTreeChildren{P}
    visited::Dict
    child::P
    descend::Bool
end

children(x::MemoTreeChildren) =
    if x.descend
        [ MemoTreeChildren(x.visited, c, x.descend ) for c in children(x.child) ]
    else
        tuple()
    end

function printnode(io::IO, x::MemoTreeChildren{<:Union{Char,AbstractString}})
    printstyled(io, regex_string(x.child), bold=true, color=:cyan)
end

function printnode(io::IO, x::MemoTreeChildren)
    printnode(io, x.child)
    x.descend || isempty(children(x.child)) || printstyled(io, " # branches hidden", color=:light_black)
end

children(x::Union{Regex,AbstractString}) = ()

Base.show(io::IO, x::MemoTreeChildren) =
    show(io,x.child)

function Base.show(io::IO, x::Union{ConstantParser,NIndexParser})
    print(io, "re\"",regex_string(x),"\"") ##!!
end
function Base.show(io::IO, x::CombinedParser)
    if get(io,:compact,false)
        print(io, regex_string(x)) ##!!
    else
        print_tree(io, MemoTreeChildren(Dict(),x, true), indicate_truncation=false)
        println(io,"::",result_type(x))
    end
end

printnode(io::IO,x::Bytes) =
    print(io, "$(x.N) Bytes::$(result_type(x))")

printnode(io::IO, x::CombinedParser) =
    printnode_(io, x)

function printnode_(io::IO, x::CombinedParser)
    printstyled(io, regex_prefix(x), bold=true, color=:cyan)
    if isempty(children(x))
        printstyled(io, regex_inner(x), bold=true, color=:cyan)
        ##printnode(io, x.parser)
    else
        printstyled(io, children_char,bold=true)
    end
    printstyled(io, regex_suffix(x), bold=true, color=:cyan)
    printstyled(io, " ")
    print_constructor(io,x) # , color=:yellow)
end

function MemoTreeChildren(children::Union{Vector, Tuple}, visited::Dict=Dict())
    children_ = [ MemoTreeChildren(visited, x, !haskey(visited, x)) for x in children ]
    for c in children
        visited[c] = true
    end
    children_
end


text:
function acos(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "acos", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function acos(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "acos", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function acosh(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "acosh", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function acosh(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "acosh", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function add(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint, arg4::Vector{RealFieldElement}, arg5::jint)
    return jcall(obj, "add", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function add(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint, arg4::Vector{jdouble}, arg5::jint)
    return jcall(obj, "add", void, (Vector{jdouble}, jint, Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function asin(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "asin", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function asin(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "asin", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function asinh(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "asinh", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function asinh(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "asinh", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function atan(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "atan", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function atan(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "atan", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function atan2(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint, arg4::Vector{RealFieldElement}, arg5::jint)
    return jcall(obj, "atan2", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function atan2(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint, arg4::Vector{jdouble}, arg5::jint)
    return jcall(obj, "atan2", void, (Vector{jdouble}, jint, Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function atanh(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "atanh", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function atanh(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "atanh", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function check_compatibility(obj::DSCompiler, arg0::DSCompiler)
    return jcall(obj, "checkCompatibility", void, (DSCompiler,), arg0)
end

function compose(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::Vector{RealFieldElement}, arg4::jint)
    return jcall(obj, "compose", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4)
end

function compose(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{jdouble}, arg3::Vector{RealFieldElement}, arg4::jint)
    return jcall(obj, "compose", void, (Vector{RealFieldElement}, jint, Vector{jdouble}, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4)
end

function compose(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::Vector{jdouble}, arg4::jint)
    return jcall(obj, "compose", void, (Vector{jdouble}, jint, Vector{jdouble}, Vector{jdouble}, jint), arg0, arg1, arg2, arg3, arg4)
end

function cos(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "cos", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function cos(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "cos", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function cosh(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "cosh", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function cosh(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "cosh", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function divide(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint, arg4::Vector{RealFieldElement}, arg5::jint)
    return jcall(obj, "divide", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function divide(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint, arg4::Vector{jdouble}, arg5::jint)
    return jcall(obj, "divide", void, (Vector{jdouble}, jint, Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function equals(obj::Object, arg0::Object)
    return jcall(obj, "equals", jboolean, (Object,), arg0)
end

function exp(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "exp", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function exp(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "exp", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function expm1(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "expm1", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function expm1(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "expm1", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function get_class(obj::Object)
    return jcall(obj, "getClass", Class, ())
end

function get_compiler(::Type{DSCompiler}, arg0::jint, arg1::jint)
    return jcall(DSCompiler, "getCompiler", DSCompiler, (jint, jint), arg0, arg1)
end

function get_free_parameters(obj::DSCompiler)
    return jcall(obj, "getFreeParameters", jint, ())
end

function get_order(obj::DSCompiler)
    return jcall(obj, "getOrder", jint, ())
end

function get_partial_derivative_index(obj::DSCompiler, arg0::Vector{jint})
    return jcall(obj, "getPartialDerivativeIndex", jint, (Vector{jint},), arg0)
end

function get_partial_derivative_orders(obj::DSCompiler, arg0::jint)
    return jcall(obj, "getPartialDerivativeOrders", Vector{jint}, (jint,), arg0)
end

function get_size(obj::DSCompiler)
    return jcall(obj, "getSize", jint, ())
end

function hash_code(obj::Object)
    return jcall(obj, "hashCode", jint, ())
end

function linear_combination(obj::DSCompiler, arg0::RealFieldElement, arg1::Vector{RealFieldElement}, arg10::Vector{RealFieldElement}, arg11::jint, arg12::Vector{RealFieldElement}, arg13::jint, arg2::jint, arg3::RealFieldElement, arg4::Vector{RealFieldElement}, arg5::jint, arg6::RealFieldElement, arg7::Vector{RealFieldElement}, arg8::jint, arg9::RealFieldElement)
    return jcall(obj, "linearCombination", void, (RealFieldElement, Vector{RealFieldElement}, Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint, jint, RealFieldElement, Vector{RealFieldElement}, jint, RealFieldElement, Vector{RealFieldElement}, jint, RealFieldElement), arg0, arg1, arg10, arg11, arg12, arg13, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
end

function linear_combination(obj::DSCompiler, arg0::RealFieldElement, arg1::Vector{RealFieldElement}, arg10::jint, arg2::jint, arg3::RealFieldElement, arg4::Vector{RealFieldElement}, arg5::jint, arg6::RealFieldElement, arg7::Vector{RealFieldElement}, arg8::jint, arg9::Vector{RealFieldElement})
    return jcall(obj, "linearCombination", void, (RealFieldElement, Vector{RealFieldElement}, jint, jint, RealFieldElement, Vector{RealFieldElement}, jint, RealFieldElement, Vector{RealFieldElement}, jint, Vector{RealFieldElement}), arg0, arg1, arg10, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
end

function linear_combination(obj::DSCompiler, arg0::RealFieldElement, arg1::Vector{RealFieldElement}, arg2::jint, arg3::RealFieldElement, arg4::Vector{RealFieldElement}, arg5::jint, arg6::Vector{RealFieldElement}, arg7::jint)
    return jcall(obj, "linearCombination", void, (RealFieldElement, Vector{RealFieldElement}, jint, RealFieldElement, Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
end

function linear_combination(obj::DSCompiler, arg0::jdouble, arg1::Vector{RealFieldElement}, arg10::Vector{RealFieldElement}, arg11::jint, arg12::Vector{RealFieldElement}, arg13::jint, arg2::jint, arg3::jdouble, arg4::Vector{RealFieldElement}, arg5::jint, arg6::jdouble, arg7::Vector{RealFieldElement}, arg8::jint, arg9::jdouble)
    return jcall(obj, "linearCombination", void, (jdouble, Vector{RealFieldElement}, Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint, jint, jdouble, Vector{RealFieldElement}, jint, jdouble, Vector{RealFieldElement}, jint, jdouble), arg0, arg1, arg10, arg11, arg12, arg13, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
end

function linear_combination(obj::DSCompiler, arg0::jdouble, arg1::Vector{RealFieldElement}, arg10::jint, arg2::jint, arg3::jdouble, arg4::Vector{RealFieldElement}, arg5::jint, arg6::jdouble, arg7::Vector{RealFieldElement}, arg8::jint, arg9::Vector{RealFieldElement})
    return jcall(obj, "linearCombination", void, (jdouble, Vector{RealFieldElement}, jint, jint, jdouble, Vector{RealFieldElement}, jint, jdouble, Vector{RealFieldElement}, jint, Vector{RealFieldElement}), arg0, arg1, arg10, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
end

function linear_combination(obj::DSCompiler, arg0::jdouble, arg1::Vector{RealFieldElement}, arg2::jint, arg3::jdouble, arg4::Vector{RealFieldElement}, arg5::jint, arg6::Vector{RealFieldElement}, arg7::jint)
    return jcall(obj, "linearCombination", void, (jdouble, Vector{RealFieldElement}, jint, jdouble, Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
end

function linear_combination(obj::DSCompiler, arg0::jdouble, arg1::Vector{jdouble}, arg10::Vector{jdouble}, arg11::jint, arg12::Vector{jdouble}, arg13::jint, arg2::jint, arg3::jdouble, arg4::Vector{jdouble}, arg5::jint, arg6::jdouble, arg7::Vector{jdouble}, arg8::jint, arg9::jdouble)
    return jcall(obj, "linearCombination", void, (jdouble, Vector{jdouble}, Vector{jdouble}, jint, Vector{jdouble}, jint, jint, jdouble, Vector{jdouble}, jint, jdouble, Vector{jdouble}, jint, jdouble), arg0, arg1, arg10, arg11, arg12, arg13, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
end

function linear_combination(obj::DSCompiler, arg0::jdouble, arg1::Vector{jdouble}, arg10::jint, arg2::jint, arg3::jdouble, arg4::Vector{jdouble}, arg5::jint, arg6::jdouble, arg7::Vector{jdouble}, arg8::jint, arg9::Vector{jdouble})
    return jcall(obj, "linearCombination", void, (jdouble, Vector{jdouble}, jint, jint, jdouble, Vector{jdouble}, jint, jdouble, Vector{jdouble}, jint, Vector{jdouble}), arg0, arg1, arg10, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
end

function linear_combination(obj::DSCompiler, arg0::jdouble, arg1::Vector{jdouble}, arg2::jint, arg3::jdouble, arg4::Vector{jdouble}, arg5::jint, arg6::Vector{jdouble}, arg7::jint)
    return jcall(obj, "linearCombination", void, (jdouble, Vector{jdouble}, jint, jdouble, Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
end

function log(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "log", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function log(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "log", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function log10(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "log10", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function log10(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "log10", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function log1p(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "log1p", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function log1p(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "log1p", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function multiply(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint, arg4::Vector{RealFieldElement}, arg5::jint)
    return jcall(obj, "multiply", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function multiply(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint, arg4::Vector{jdouble}, arg5::jint)
    return jcall(obj, "multiply", void, (Vector{jdouble}, jint, Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function notify(obj::Object)
    return jcall(obj, "notify", void, ())
end

function notify_all(obj::Object)
    return jcall(obj, "notifyAll", void, ())
end

function pow(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint, arg4::Vector{RealFieldElement}, arg5::jint)
    return jcall(obj, "pow", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function pow(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::jdouble, arg3::Vector{RealFieldElement}, arg4::jint)
    return jcall(obj, "pow", void, (Vector{RealFieldElement}, jint, jdouble, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4)
end

function pow(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::jint, arg3::Vector{RealFieldElement}, arg4::jint)
    return jcall(obj, "pow", void, (Vector{RealFieldElement}, jint, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4)
end

function pow(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint, arg4::Vector{jdouble}, arg5::jint)
    return jcall(obj, "pow", void, (Vector{jdouble}, jint, Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function pow(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::jdouble, arg3::Vector{jdouble}, arg4::jint)
    return jcall(obj, "pow", void, (Vector{jdouble}, jint, jdouble, Vector{jdouble}, jint), arg0, arg1, arg2, arg3, arg4)
end

function pow(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::jint, arg3::Vector{jdouble}, arg4::jint)
    return jcall(obj, "pow", void, (Vector{jdouble}, jint, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3, arg4)
end

function pow(obj::DSCompiler, arg0::jdouble, arg1::Vector{RealFieldElement}, arg2::jint, arg3::Vector{RealFieldElement}, arg4::jint)
    return jcall(obj, "pow", void, (jdouble, Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4)
end

function pow(obj::DSCompiler, arg0::jdouble, arg1::Vector{jdouble}, arg2::jint, arg3::Vector{jdouble}, arg4::jint)
    return jcall(obj, "pow", void, (jdouble, Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3, arg4)
end

function remainder(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint, arg4::Vector{RealFieldElement}, arg5::jint)
    return jcall(obj, "remainder", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function remainder(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint, arg4::Vector{jdouble}, arg5::jint)
    return jcall(obj, "remainder", void, (Vector{jdouble}, jint, Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function root_n(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::jint, arg3::Vector{RealFieldElement}, arg4::jint)
    return jcall(obj, "rootN", void, (Vector{RealFieldElement}, jint, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4)
end

function root_n(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::jint, arg3::Vector{jdouble}, arg4::jint)
    return jcall(obj, "rootN", void, (Vector{jdouble}, jint, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3, arg4)
end

function sin(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "sin", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function sin(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "sin", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function sin_cos(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint, arg4::Vector{RealFieldElement}, arg5::jint)
    return jcall(obj, "sinCos", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function sin_cos(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint, arg4::Vector{jdouble}, arg5::jint)
    return jcall(obj, "sinCos", void, (Vector{jdouble}, jint, Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function sinh(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "sinh", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function sinh(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "sinh", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function subtract(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint, arg4::Vector{RealFieldElement}, arg5::jint)
    return jcall(obj, "subtract", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function subtract(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint, arg4::Vector{jdouble}, arg5::jint)
    return jcall(obj, "subtract", void, (Vector{jdouble}, jint, Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3, arg4, arg5)
end

function tan(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "tan", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function tan(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "tan", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function tanh(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement}, arg3::jint)
    return jcall(obj, "tanh", void, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}, jint), arg0, arg1, arg2, arg3)
end

function tanh(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble}, arg3::jint)
    return jcall(obj, "tanh", void, (Vector{jdouble}, jint, Vector{jdouble}, jint), arg0, arg1, arg2, arg3)
end

function taylor(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{RealFieldElement})
    return jcall(obj, "taylor", RealFieldElement, (Vector{RealFieldElement}, jint, Vector{RealFieldElement}), arg0, arg1, arg2)
end

function taylor(obj::DSCompiler, arg0::Vector{RealFieldElement}, arg1::jint, arg2::Vector{jdouble})
    return jcall(obj, "taylor", RealFieldElement, (Vector{RealFieldElement}, jint, Vector{jdouble}), arg0, arg1, arg2)
end

function taylor(obj::DSCompiler, arg0::Vector{jdouble}, arg1::jint, arg2::Vector{jdouble})
    return jcall(obj, "taylor", jdouble, (Vector{jdouble}, jint, Vector{jdouble}), arg0, arg1, arg2)
end

function to_string(obj::Object)
    return jcall(obj, "toString", JString, ())
end

function wait(obj::Object)
    return jcall(obj, "wait", void, ())
end

function wait(obj::Object, arg0::jlong)
    return jcall(obj, "wait", void, (jlong,), arg0)
end

function wait(obj::Object, arg0::jlong, arg1::jint)
    return jcall(obj, "wait", void, (jlong, jint), arg0, arg1)
end


text:
"""
    reinfer_schema!(table::CleanTable; max_types::Int=3)

Tries to minimize the amount of element types for each column without making the column type
`Any`.

For this, will try to make the column of type `Union` with up to `max_types` and
internally use `Base.promote_typejoin` on all numeric types.
If not possible, leaves the column as-is.
"""
function reinfer_schema!(table::CleanTable; max_types::Int=3)
    columns = cols(table)
    if Threads.nthreads() > 1 && length(columns) > 1 && length(columns[1]) >= 1_000_000
        Threads.@threads for i in 1:length(columns)
            col = columns[i]
            type = eltype(col)
            if type == Any
                types = Vector{DataType}()
                number_types = Vector{DataType}()

                for T in unique(typeof.(col))
                    if T <: Number
                        push!(number_types, T)
                    else
                        push!(types, T)
                    end
                end

                if !isempty(number_types)
                    push!(types, reduce(Base.promote_typejoin, number_types))
                end

                if length(types) <= max_types
                    columns[i] = convert(AbstractVector{Union{types...}}, col)
                end
            end
        end
    else
        for i in 1:length(columns)
            col = columns[i]
            type = eltype(col)
            if type == Any
                types = Vector{DataType}()
                number_types = Vector{DataType}()

                for T in unique(typeof.(col))
                    if T <: Number
                        push!(number_types, T)
                    else
                        push!(types, T)
                    end
                end

                if !isempty(number_types)
                    push!(types, reduce(Base.promote_typejoin, number_types))
                end

                if length(types) <= max_types
                    columns[i] = convert(AbstractVector{Union{types...}}, col)
                end
            end
        end
    end

    return table
end

"""
    reinfer_schema(table; max_types::Int=3)

Creates a `CleanTable` with copied columns and tries to minimize the amount of element types
for each column without making the column type `Any`.

For this, will try to make the column of type `Union` with up to max_types and
internally use `Base.promote_typejoin` on all numeric types.
If not possible, leaves the column as-is.
"""
function reinfer_schema(table; max_types::Int=3)
    return reinfer_schema!(CleanTable(table); max_types=max_types)
end

max_stars_repo_name: TheRoniOne/Cleaner

max_issues_repo_name: TheRoniOne/Cleaner

max_forks_repo_name: TheRoniOne/Cleaner


text:
"""This module implements reading and initializing functions."""
# Author: Henri Gérard <hgerard.proy@gmail.com>
# License: MIT

function read_data_libsvm(path, nbfeatures)
    """
    Aggregator of projection

    Parameters
    ----------
    i::Int

    robustModel::RobustModel

    Returns
    -------

    """
    m = readdlm(path)
    data = zeros(size(m)[1], nbfeatures+1)
    for i in 1:size(m)[1]
        for j in 2:size(m)[2]
            if m[i,j] != ""
                a,b = split(m[i,j],":")
                ai = parse(Int, a)
                bi = parse(Float64, b)
                data[i,ai] = bi
            end
        end
    end
    data[:,end] = m[:,1]
    return data
end

function create_data(name, nbfeatures, train_size, train_test_split)
    """
    Aggregator of projection

    Parameters
    ----------
    i::Int

    robustModel::RobustModel

    Returns
    -------

    """
    path_train = string("datasets/",name)
    data = read_data_libsvm(path_train, nbfeatures)
    xtr, xte, ytr, yte = train_test_split(data[:,1:end-1], data[:,end], train_size = train_size)
    df_train = hcat(xtr, ytr)
    df_test = hcat(xte, yte);

    return df_train, df_test
end

function initialize(Z, robustModel, constraint::GeneralConstraint)
    """
    Aggregator of projection

    Parameters
    ----------
    i::Int

    robustModel::RobustModel

    Returns
    -------

    """
    error("'error_loss' not defined for $(typedof(s))")
end

function initialize(Z, robustModel, constraint::KLConstraint)
    """
    Aggregator of projection

    Parameters
    ----------
    i::Int

    robustModel::RobustModel

    Returns
    -------

    """
    N = size(Z)[1]
    lt = size(Z)[2]-1

    x0 = rand(length(robustModel.descent_direction))
    x1 = rand(length(robustModel.descent_direction))
    x2 = ones(length(robustModel.descent_direction))
    x3 = ones(length(robustModel.descent_direction))

    x1[2] = maximum([error_loss(x1[3:3+lt-1], Z[i,:], robustModel.regressionModel) for i in 1:size(Z)[1]])
    x3[2] = maximum([error_loss(x3[3:3+lt-1], Z[i,:], robustModel.regressionModel) for i in 1:size(Z)[1]])
    for k in robustModel.I0
        aux0 = fconstraint(x0, Z, robustModel.regressionModel, k, constraint)
        aux2 = fconstraint(x2, Z, robustModel.regressionModel, k, constraint)
        if aux0 > 0
            x0[3+lt-1+k] = x0[3+lt-1+k] + aux0
        end

        if aux2 > 0
            x2[3+lt-1+k] = x2[3+lt-1+k] + aux2
        end
    end

    array_aux = [robustModel.descent_direction'*x0, robustModel.descent_direction'*x1, robustModel.descent_direction'*x2, robustModel.descent_direction'*x3]
    index = argmin(array_aux)
    if index == 1
        return x0
    elseif index == 2
        return x1
    elseif index == 3
        return x2
    elseif index == 4
        return x3
    end
end

function initialize(Z, robustModel, constraint::EntropicConstraint)
    """
    Aggregator of projection

    Parameters
    ----------
    i::Int

    robustModel::RobustModel

    Returns
    -------

    """
    N = size(Z)[1]
    lt = size(Z)[2]-1

    x0 = rand(length(robustModel.descent_direction))
    x1 = rand(length(robustModel.descent_direction))
    x2 = ones(length(robustModel.descent_direction))
    x3 = ones(length(robustModel.descent_direction))

    x1[1] = maximum([error_loss(x1[3:3+lt-1], Z[i,:], robustModel.regressionModel) for i in 1:size(Z)[1]])
    x3[1] = maximum([error_loss(x3[3:3+lt-1], Z[i,:], robustModel.regressionModel) for i in 1:size(Z)[1]])
    for k in robustModel.I0
        aux0 = fconstraint(x0, Z, robustModel.regressionModel, k, constraint)
        aux2 = fconstraint(x2, Z, robustModel.regressionModel, k, constraint)
        if aux0 > 0
            x0[2+lt-1+k] = x0[2+lt-1+k] + aux0
        end

        if aux2 > 0
            x2[2+lt-1+k] = x2[2+lt-1+k] + aux2
        end
    end

    array_aux = [robustModel.descent_direction'*x0, robustModel.descent_direction'*x1, robustModel.descent_direction'*x2, robustModel.descent_direction'*x3]
    index = argmin(array_aux)
    if index == 1
        return x0
    elseif index == 2
        return x1
    elseif index == 3
        return x2
    elseif index == 4
        return x3
    end
end

function initialize(Z, robustModel, constraint::DROConstraint)
    """
    Aggregator of projection

    Parameters
    ----------
    i::Int

    robustModel::RobustModel

    Returns
    -------

    """
    N = size(Z)[1]
    lt = size(Z)[2]-1
    x0 = rand(length(robustModel.descent_direction))
    x1 = rand(length(robustModel.descent_direction))
    x2 = rand(length(robustModel.descent_direction))
    x3 = rand(length(robustModel.descent_direction))

    for k in robustModel.I0
        aux0 = fconstraint(x0, Z, robustModel.regressionModel, k, constraint)
        aux2 = fconstraint(x2, Z, robustModel.regressionModel, k, constraint)
        if aux0 > 0
            l = div(k-1,N)+1
            x0[2+lt-1+l] = x0[2+lt-1+l] + aux0
        end
        if aux2 > 0
            l = div(k-1,N)+1
            x2[2+lt-1+l] = x2[2+lt-1+l] + aux2
        end
    end

    aux1 = maximum([error_loss(x1[2:2+lt-1], Z[i,:], robustModel.regressionModel) for i in 1:size(Z)[1]])
    for k in 2+lt:N
        x1[k] = aux1
    end

    aux3 = maximum([error_loss(x3[2:2+lt-1], Z[i,:], robustModel.regressionModel) for i in 1:size(Z)[1]])
    for k in 2+lt:N
        x3[k] = aux3
    end

    array_aux = [robustModel.descent_direction'*x0, robustModel.descent_direction'*x1, robustModel.descent_direction'*x2, robustModel.descent_direction'*x3]
    index = argmin(array_aux)
    if index == 1
        return x0
    elseif index == 2
        return x1
    elseif index == 3
        return x2
    elseif index == 4
        return x3
    end
end

function init_proj(data, robustModel, projParams)
    """
    Aggregator of projection

    Parameters
    ----------
    i::Int

    robustModel::RobustModel

    Returns
    -------

    """
    x0 = rand(length(robustModel.descent_direction))
    x1 = ones(length(robustModel.descent_direction))
    x0, dm, it = algo_proj(x0, data, robustModel, projParams)
    x1, dm, it = algo_proj(x1, data, robustModel, projParams)
    if robustModel.descent_direction'*x0 < robustModel.descent_direction'*x1
        return x0
    else
        return x1
    end
end

max_stars_repo_name: Henri-Gerard/robox

max_issues_repo_name: Henri-Gerard/robox

max_forks_repo_name: Henri-Gerard/robox


text:
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Distributed, Sockets

# Run various networking tests checking to see how we perform under large loads
addprocs(1)

function test_connect_disconnect(exp)
    print("Testing 10^$exp connect/disconnects:\n")

    (port, server) = listenany(8000)
    server_started = RemoteChannel()
    server_exited = RemoteChannel()
    client_exited = RemoteChannel()

    @async begin
        clients_served = 0
        print("\t\t\t[SERVER] Started on port $(port), with PID $(getpid())\n")
        put!(server_started, false)
        while (clients_served < 10^exp)
            close(accept(server))
            clients_served += 1
        end
        put!(server_exited, true)
        print("\t\t\t[SERVER] Finished serving $(clients_served) clients\n")
    end

    # Wait for the server
    @spawnat(2, begin
        take!(server_started)
        print("[CLIENT] Connecting repeatedly to port $(port)\n")
        for i in 1:10^exp
            close(connect("localhost", port))
        end
        print("[CLIENT] Finished with 10^$exp connections\n")
        put!(client_exited,true)
    end)

    fetch(client_exited)
    close(server)
    fetch(server_exited)
    print("OK\n")
end

# Perform first test
test_connect_disconnect(5)

function test_send(exp)
    (port, server) = listenany(8000)

    @assert exp > 4
    size = 10^exp
    block = 10^(exp - 4)

    print("Testing open, send of 10^$exp bytes and closing:\n")

    server_started = RemoteChannel()
    server_exited = RemoteChannel()
    client_exited = RemoteChannel()

    @async begin
        print("\t\t\t[SERVER] Started on port $(port)\n")
        put!(server_started, false)
        serv_sock = accept(server)
        bread = 0
        while bread < size
            serv_data = read(serv_sock, UInt8, block)
            @assert length(serv_data) == block
            bread += block
        end
        close(serv_sock)
        print("\t\t\t[SERVER] Received 10^$(log10(bread))B of 10^$(exp)B\n")
        put!(server_exited, bread)
    end

    @spawnat(2, begin
        # wait for the server
        take!(server_started)
        print("[CLIENT] Connecting to port $(port)\n")
        cli_sock = connect("localhost", port)
        data = fill!(zeros(UInt8, block), Int8(65))
        cli_bsent = 0
        while cli_bsent < size
            write(cli_sock, data)
            cli_bsent += block
        end
        close(cli_sock)
        print("[CLIENT] Transmitted 10^$(log10(cli_bsent))B of 10^$(exp)B\n")
        put!(client_exited, cli_bsent)
    end)

    brcvd = take!(server_exited)
    bsent = take!(client_exited)
    close(server)

    if brcvd != bsent
        print("\t[ERROR] Received bytes ($(brcvd)) != sent bytes ($(bsent))\n")
    else
        print("OK\n")
    end
end

# Run second test on a gigabyte of data
test_send(9)

# Utility function for test_bidirectional() that simultaneously transmits and
# receives 10^exp bits of data over s
@everywhere function xfer(s, exp)
    @assert exp > 4
    xfer_size = 10^exp
    xfer_block = 10^(exp - 4)

    bsent = 0
    bread = 0

    @sync begin
        # Create an asynchronous task that can modify bread properly
        recv_task = @task begin
            while bread < xfer_size
                data = read(s, UInt8, xfer_block)
                @assert length(data) == xfer_block
                bread += xfer_block
            end
        end
        Base.sync_add(recv_task)
        Base.enq_work(recv_task)

        send_task = @task begin
            # write in chunks of xfer_block
            data = fill!(zeros(UInt8, xfer_block), Int8(65))
            while bsent < xfer_size
                write(s, data)
                bsent += xfer_block
            end
        end
        Base.sync_add(send_task)
        Base.enq_work(send_task)
    end

    return (bsent, bread)
end

function test_bidirectional(exp)
    print("Testing 10^$exp bytes of concurrent bidirectional transfers:\n")
    (port, server) = listenany(8000)

    # For both the server and the client, we will transfer/receive 10^exp bytes
    server_started = RemoteChannel()
    server_exited = RemoteChannel()
    client_exited = RemoteChannel()

    @async begin
        print("\t\t\t[SERVER] Started on port $(port)\n")
        put!(server_started, true)
        server_sock = accept(server)
        (bsent, bread) = xfer(server_sock, exp)
        close(server_sock)
        print("\t\t\t[SERVER] Transmitted 10^$(log10(bsent))B and received 10^$(log10(bread))B\n")
        put!(server_exited, (bsent, bread))
    end

    @spawnat(2, begin
        # Wait for the server
        take!(server_started)
        print("[CLIENT] Connecting to port $(port)\n")
        client_sock = connect("localhost", port)
        (bsent, bread) = xfer(client_sock, exp)
        close(client_sock)
        print("[CLIENT] Transmitted 10^$(log10(bsent))B and received 10^$(log10(bread))B\n")
        put!(client_exited, (bsent,bread))
    end)

    (serv_bsent, serv_bread) = take!(server_exited)
    (cli_bsent, cli_bread) = take!(client_exited)
    close(server)

    if serv_bsent != cli_bread || serv_bread != cli_bsent
        print("\t[ERROR] Data was not faithfully transmitted!")
    else
        print("OK\n")
    end
end

# Test 1GB of bidirectional data
test_bidirectional(9)

max_stars_repo_name: djsegal/julia-fork

max_issues_repo_name: djsegal/julia-fork

max_forks_repo_name: djsegal/julia-fork


text:
function count_nucleotides(strand::String)
	strand_copy = uppercase(strand) #Set the strand to upper
	alphabet = Set('A':'Z')
	nucleotides = Set(['A', 'C', 'T', 'G'])
	invalid_letters = setdiff(alphabet, nucleotides)
	strand_letters = Set(strand_copy)
	for letter in strand_letters
		if letter in invalid_letters
			return DomainError(letter)
		end

	end
	a_count = count("A", strand_copy)
	c_count = count("C",strand_copy)
	g_count = count("G",strand_copy)
	t_count = count("T",strand_copy)
	n_count =  Dict("A" => a_count, "C" => c_count, "G" => g_count, "T" => t_count)
	return n_count
end

max_stars_repo_name: tamireinhorn/exercism

max_issues_repo_name: tamireinhorn/exercism

max_forks_repo_name: tamireinhorn/Exercism


text:
function checkpoint_deprecation(tags...)
    kwargs = join(["$(first(tag))=\"$(last(tag))\"" for tag in tags], ", ")
    pairs = join([":$(first(tag)) => \"$(last(tag))\"" for tag in tags], ", ")

    isempty(tags) || Base.depwarn(
        "checkpoint(args...; $(kwargs)) is deprecated, use\n" *
        "with_checkpoint_tags($(pairs)) do\n" *
        "    checkpoint(args...)\n" *
        "end\n" *
        "instead. Note the use of `Pair`s instead of keyword arguments.",
        :checkpoint
    )
end


text:
@export function createvaos(n::Int = 1)
   @assert n > 0 "Number of Vertex Arrays to create must be greater than 0"
   ids = Vector{Cuint}(undef, n)
   @c glCreateVertexArrays(1, ids)
   return ids
end

@export function genvaos(n::Int = 1)
   @assert n > 0 "Number of Vertex Arrays to generate must be greater than 0"
   ids = Vector{Cuint}(undef, n)
   @c glGenVertexArrays(1, ids)
   return ids
end

@export createvao() = bindvao!(createvaos() |> first)
@export genvao() = bindvao!(genvaos() |> first)
@export bindvao!(vao::Cuint) = (glBindVertexArray(vao); vao)
@export deletevaos!(ids::Cuint...) = glDeleteVertexArrays(length(ids), collect(ids))

@export function genbuffers(n::Int = 1)
   @assert n > 0 "Number of buffers to generate must be greater than 0"
   ids = Vector{Cuint}(undef, n)
   @c glGenBuffers(1, ids)
   return ids
end

@export function createbuffers(n::Int = 1)
   @assert n > 0 "Number of buffers to create must be greater than 0"
   ids = Vector{Cuint}(undef, n)
   @c glCreateBuffers(n, ids)
   return ids
end

@export genbuffer() = genbuffers() |> first
@export createbuffer() = createbuffers() |> first
@export deletebuffers!(ids::Cuint...) = glDeleteBuffers(length(ids), collect(ids))

"""
      bindbuffer!(buffer, type)

Binds a `buffer` with the respective `type`.

`type` can be one of the following:

```julia
:array              -> GL_ARRAY_BUFFER
:atomic_counter     -> GL_ATOMIC_COUNTER_BUFFER
:copy_read          -> GL_COPY_READ_BUFFER
:copy_write         -> GL_COPY_WRITE_BUFFER
:dispatch_indirect  -> GL_DISPATCH_INDIRECT_BUFFER
:draw_indirect      -> GL_DRAW_INDIRECT_BUFFER
:element_array      -> GL_ELEMENT_ARRAY_BUFFER
:pixel_pack         -> GL_PIXEL_PACK_BUFFER
:pixel_unpack       -> GL_PIXEL_UNPACK_BUFFER
:query              -> GL_QUERY_BUFFER
:shader_storage     -> GL_SHADER_STORAGE_BUFFER
:texture            -> GL_TEXTURE_BUFFER
:transform_feedback -> GL_TRANSFORM_FEEDBACK_BUFFER
:uniform            -> GL_UNIFORM_BUFFER
```
"""
@export function bindbuffer!(buffer::Cuint, type::Symbol)
   sym = Symbol(uppercase("GL_$(type)_BUFFER"))
   @assert isdefined(ModernGL, sym) "Unrecognized buffer type: $sym"
   type = getfield(ModernGL, sym)
   glBindBuffer(type, buffer)
end

@export function bufferdata!(buffer::Cuint, size::Integer, data::T, usage::Symbol) where {T}
   @assert usage in keys(BufferUsageMap) "Unrecognized buffer usage: $usage"
   glNamedBufferData(buffer, size, data, BufferUsageMap[usage])
end

function bufferdata!(buffer::Cuint, data::AbstractArray{T}, usage::Symbol) where {T}
   size = length(data) * sizeof(T)
   bufferdata!(buffer, size, data, usage)
end

function bufferdata!(size::Integer, data::T, usage::Symbol; target::Symbol) where {T}
   @assert usage in keys(BufferUsageMap) "Unrecognized buffer usage: $usage"
   glBufferData(target, size, data, BufferUsageMap[usage])
end

function bufferdata!(data::AbstractArray{T}, usage::Symbol; target::Symbol) where {T}
   size = length(data) * sizeof(T)
   bufferdata!(size, data, usage; target)
end

@export function attrformat!(
   vao::Cuint,
   index::Integer,
   size::Integer,
   type::DataType,
   normalized::Bool,
   offset::Integer
)
   glVertexArrayAttribFormat(vao, index, size, gtype(type), gbool(normalized), offset)
end

function attrformat!(vao::Cuint, binding::Integer, ::Type{T}) where {T}
   for i in 1:fieldcount(T)
      type = fieldtype(T, i)
      offset = fieldoffset(T, i)
      size = type <: SVector{N} where {N} ? length(type) : 1
      attrformat!(vao, i - 1, size, type, false, offset)
      glVertexArrayAttribBinding(vao, i - 1, binding)
      glEnableVertexArrayAttrib(vao, i - 1)
   end
end

@export function draw_elements(mode::GLenum, count::Integer, type::DataType, indices::Ptr = Ptr{Cvoid}(0))
   glDrawElements(mode, count, gtype(type), indices)
end

function draw_elements(count::Integer, type::DataType, indices::Ptr = Ptr{Cvoid}(0))
   glDrawElements(GL_TRIANGLES, count, gtype(type), indices)
end

max_stars_repo_name: jorge-brito/Glutils

max_issues_repo_name: jorge-brito/Glutils

max_forks_repo_name: jorge-brito/Glutils


text:
immutable SequencePair <: Cut{3}; groups; end
export SequencePair
SequencePair() = SequencePair(CutCount{3}())

function getcut{B<:BinaryGray}(prob::Problem, vars::Variables{B}, ::SequencePair, i, j, k)
    N = prob.N
    z⁺, z⁻ = vars.v
    return @LinearConstraints(begin
        z⁺[i,j] + z⁺[j,k] + z⁺[k,i] ≥ 1.0
        z⁺[i,j] + z⁺[j,k] + z⁺[k,i] ≤ 2.0
    end)
end

function addcuts{B<:BinaryBlack}(model::Model, prob::Problem, vars::Variables{B}, cut::SequencePair, ranged=false)
    groups = get_groups(prob, cut, cut.groups)
    N = prob.N
    z⁺, z⁻ = vars.v
    for (i,j,k) in groups
        cuttingplanes = (if ranged
            [LinearConstraint(z⁺[i,j] + z⁺[j,k] + z⁺[k,i], 1.0, 2.0)
             LinearConstraint(z⁻[i,j] + z⁻[j,k] + z⁻[k,i], 1.0, 2.0)]
        else
            @LinearConstraints(begin
                z⁺[i,k] ≥ z⁺[i,j] + z⁺[j,k] - 1
                z⁺[k,i] ≥ z⁺[j,i] + z⁺[k,j] - 1
                z⁻[i,k] ≥ z⁻[i,j] + z⁻[j,k] - 1
                z⁻[k,i] ≥ z⁻[j,i] + z⁻[k,j] - 1
            end)
        end)
        for c in cuttingplanes
            addConstraint(model, c)
        end
    end
end


text:
@testset "initialization" begin

# the API shouldn't have been initialized
@test CuCurrentContext() == nothing

context_cb = Union{Nothing, CuContext}[nothing for tid in 1:Threads.nthreads()]
CUDAnative.atcontextswitch() do tid, ctx
    context_cb[tid] = ctx
end

task_cb = Union{Nothing, Task}[nothing for tid in 1:Threads.nthreads()]
CUDAnative.attaskswitch() do tid, task
    task_cb[tid] = task
end

# now cause initialization
ctx = context()
@test CuCurrentContext() == ctx
@test device() == CuDevice(0)
@test context_cb[1] == ctx
@test task_cb[1] == current_task()

fill!(context_cb, nothing)
fill!(task_cb, nothing)

# ... on a different task
task = @async begin
    context()
end
@test ctx == fetch(task)
@test context_cb[1] == nothing
@test task_cb[1] == task

device!(CuDevice(0))
device!(CuDevice(0)) do
    nothing
end

context!(ctx)
context!(ctx) do
    nothing
end

@test_throws AssertionError device!(0, CUDAdrv.CU_CTX_SCHED_YIELD)

device_reset!()

device!(0, CUDAdrv.CU_CTX_SCHED_YIELD)

# test the device selection functionality
if length(devices()) > 1
    device!(0)
    device!(1) do
        @test device() == CuDevice(1)
    end
    @test device() == CuDevice(0)

    device!(1)
    @test device() == CuDevice(1)
end

# test that each task can work with devices independently from other tasks
if length(devices()) > 1
    device!(0)
    @test device() == CuDevice(0)

    task = @async begin
        device!(1)
        @test device() == CuDevice(1)
    end
    fetch(task)

    @test device() == CuDevice(0)

    # reset on a task
    task = @async begin
        device!(1)
        device_reset!()
    end
    fetch(task)
    @test device() == CuDevice(0)

    # tasks on multiple threads
    Threads.@threads for d in 0:1
        for x in 1:100  # give threads a chance to trample over each other
            device!(d)
            yield()
            @test device() == CuDevice(d)
            yield()

            sleep(rand(0.001:0.001:0.01))

            device!(1-d)
            yield()
            @test device() == CuDevice(1-d)
            yield()
        end
    end
    @test device() == CuDevice(0)
end

# pick a suiteable device
candidates = [(device!(dev);
                (dev=dev,
                cap=capability(dev),
                mem=CUDAdrv.available_memory()))
                for dev in devices()]
## pick a device that is fully supported by our CUDA installation, or tools can fail
## NOTE: we don't reuse target_support which is also bounded by LLVM support,
#        and is used to pick a codegen target regardless of the actual device.
cuda_support = CUDAnative.cuda_compat()
filter!(x->x.cap in cuda_support.cap, candidates)
isempty(candidates) && error("Could not find any suitable device for this configuration")
## order by available memory, but also by capability if testing needs to be thorough
thorough = parse(Bool, get(ENV, "CI_THOROUGH", "false"))
if thorough
    sort!(candidates, by=x->(x.cap, x.mem))
else
    sort!(candidates, by=x->x.mem)
end
pick = last(candidates)
@info("Testing using device $(name(pick.dev)) (compute capability $(pick.cap), $(Base.format_bytes(pick.mem)) available memory) on CUDA driver $(CUDAdrv.version()) and toolkit $(CUDAnative.version())")
device!(pick.dev)

end


text:
# LibTOAST.jl: interface to the TOAST++ library
# Copyright (C) 2019 Samuel Powell

@testset "Raster" begin

  @testset "PixelMap" begin

    nx, ny = 20, 20
    pixelmap = PixelMap(mesh2D, (nx,ny))
    @test nlen(pixelmap) == nodecount(mesh2D)
    @test blen(pixelmap) == nx*ny
    @test glen(pixelmap) == nx*ny*2*2
    @test slen(pixelmap) == 352
    @test all(bdim(pixelmap) .== [nx,ny])
    @test bsize(pixelmap) == 6.25

    gscale = 4
    pixelmap = PixelMap(mesh2D, (nx,ny), gscale=gscale)
    @test nlen(pixelmap) == nodecount(mesh2D)
    @test blen(pixelmap) == nx*ny
    @test glen(pixelmap) == nx*ny*gscale*gscale
    @test slen(pixelmap) == 352

  end

end


text:
in(p::Point, obj::NormedPrimitive) = obj(p) ≤ 0
in(p::Point, tr::Transformed) = tr(p) ≤ 0
in(p::Point{N}, proj::Projection{N}) where {N} = p in proj.obj

function in(p::Point{Dim,T}, proj::Projection{N}) where {Dim,T,N}
    if Dim < N
        Point{N,T}(i <= Dim ? p[i] : zero(T) for i in 1:N) in proj
    else # Dim > N
        all(iszero, @view(p[N+1:Dim])) && Point{N,T}(@view(p[1:N])) in proj
    end
end


text:
"""
`invariants(r::SVector{M,T}) -> SVector` : computes the invariant descriptors as a function of the
lengths in a simplex. The order is lexicographical, i.e.,

* 2-body: `r::SVector{1}`
* 3-body: `r::SVector{3}`, order is irrelevant, but `r = [r12, r13, r23]`
* 4-body: `r::SVector{6}`, order is `r = [r12, r13, r14, r23, r24, r34]`
* n-body: `r::SVector{n*(n-1)/2}`, ...

The first `n*(n-1)/2` invariants are the primary invariants; the remainind
ones are the secondary invariants.
"""
module BLInvariants

using StaticArrays

using NBodyIPs.FastPolys

using LinearAlgebra: dot

"""
need documentation here
"""
function corners end

"""
`tdegrees(::Val{N})` where `N` is the body-order returns a
tuple of polynomial <total degrees> corresponding to the degrees of the
individual invariants.  E.g. for 3-body, the invariants are
r1 + r2 + r3, r1 r2 + r1 r3 + r2 r3, r1 r2 r3, and the corresponding
degrees are `(1, 2, 3)`.
"""
function tdegrees end

# ------------------------------------------------------------------------
#             2-BODY Invariants
# ------------------------------------------------------------------------

# r = (r12,)

invariants(r::SVector{1, T}) where {T} =
      copy(r),
      SVector{1, T}(1.0)

invariants_d(r::SVector{1, T}) where {T} =
      (@SVector [ SVector(one(T))  ]),
      (@SVector [ SVector(zero(T)) ])

invariants_ed(r::SVector{1,T}) where {T} =
      copy(r),
      SVector{1, T}(1.0),
      (@SVector [ SVector(one(T))  ]),
      (@SVector [ SVector(zero(T)) ])

tdegrees(::Val{2}) = (1,), (0,)

corners(::Val{2}) = ( SVector(1,2), )

# ------------------------------------------------------------------------
#             3-BODY Invariants
# ------------------------------------------------------------------------

# r = (r12, r13, r23)

# the 1.0 is a "secondary invariant"
invariants(r::SVector{3, T}) where {T} =
      (@SVector T[ r[1]+r[2]+r[3],
                   r[1]*r[2] + r[1]*r[3] + r[2]*r[3],
                   r[1]*r[2]*r[3] ]),
      (@SVector T[ 1.0 ])

invariants_d(  r::SVector{3, T}) where {T} =
      (@SVector [ (@SVector [1.0, 1.0, 1.0]),
                  (@SVector [r[2]+r[3], r[1]+r[3], r[1]+r[2]]),
                  (@SVector [r[2] * r[3], r[1] * r[3], r[1] * r[2]]) ]),
      (@SVector [ (@SVector [0.0, 0.0, 0.0]) ])

invariants_ed(r::SVector{3, T}) where {T} =
      (@SVector T[ r[1]+r[2]+r[3],
                   r[1]*r[2] + r[1]*r[3] + r[2]*r[3],
                   r[1]*r[2]*r[3] ]),
      (@SVector T[ 1.0 ]),
      (@SVector [ (@SVector [1.0, 1.0, 1.0]),
                  (@SVector [r[2]+r[3], r[1]+r[3], r[1]+r[2]]),
                  (@SVector [r[2] * r[3], r[1] * r[3], r[1] * r[2]]) ]),
      (@SVector [ (@SVector [0.0, 0.0, 0.0]) ])

tdegrees(::Val{3}) = (1, 2, 3), (0,)

corners(::Val{3}) = ( SVector(1,2), SVector(1,3), SVector(2,3) )

# ------------------------------------------------------------------------
#             4-BODY Invariants
# ------------------------------------------------------------------------

const A = @SMatrix [0 1 1 1 1 0
                    1 0 1 1 0 1
                    1 1 0 0 1 1
                    1 1 0 0 1 1
                    1 0 1 1 0 1
                    0 1 1 1 1 0]

const P42 = Val(( (1,2,3), (6,5,4) ))

function invariants(x::SVector{6, T}) where {T}
   x2 = x .*x
   x3 = x2.*x
   x4 = x3.*x

   I1 = sum(x)
   I2 = fpoly( (x,x), P42 )  # x[1]*x[6] + x[2]*x[5] + x[3]*x[4]
   I3 = sum(x2)
   I4 = x[1]*x[2]*x[3] + x[1]*x[4]*x[5] + x[2]*x[4]*x[6] + x[3]*x[5]*x[6]
   I5 = sum(x3)
   I6 = sum(x4)

   Ax = A*x
   PV1 = dot(x2, Ax)
   PV2 = dot(x3, Ax)
   PV3 = dot(x4, x)
   I11 = PV1 * PV1
   I12 = PV2 * PV3

   return SVector(I1, I2, I3, I4, I5, I6),
          SVector(one(T), PV1, PV2, PV3, I11, I12)
end

function invariants_d(x::SVector{6, T}) where {T}
   x2 = x.*x
   x3 = x2.*x
   x4 = x3.*x
   o = @SVector ones(T, 6)
   z = @SVector zeros(T, 6)
   # ∇I2 = @SVector [x[6], x[5], x[4], x[3], x[2], x[1]]
   ∇I2 = fpoly_d( (x, x), (o, o), P42 )
   ∇I4 = @SVector [ x[2]*x[3]+x[4]*x[5],
                    x[1]*x[3]+x[4]*x[6],
                    x[1]*x[2]+x[5]*x[6],
                    x[1]*x[5]+x[2]*x[6],
                    x[1]*x[4]+x[3]*x[6],
                    x[2]*x[4]+x[3]*x[5] ]
   Ax = A*x
   PV1 = dot(x2, Ax)
   PV2 = dot(x3, Ax)
   PV3 = dot(x4, x)
   ∇PV1 = A * x2 + 2 * (x .* Ax)
   ∇PV2 = A * x3 + 3 * (x2 .* Ax)
   ∇PV3 = 5 * x4

   return SVector(o, ∇I2, 2*x, ∇I4, 3*x2, 4*x3),
          SVector(z, ∇PV1, ∇PV2, ∇PV3, 2*PV1*∇PV1, PV3*∇PV2 + PV2*∇PV3)
end

function invariants_ed(x::SVector{6, T}) where {T}
   x2 = x.*x
   x3 = x2.*x
   x4 = x3.*x
   o = @SVector ones(T, 6)
   z = @SVector zeros(T, 6)

   # primary invariants
   I1 = sum(x)
   I2 = x[1]*x[6] + x[2]*x[5] + x[3]*x[4]
   I3 = sum(x2)
   x23 = x[2]*x[3]
   x45 = x[4]*x[5]
   x24 = x[2]*x[4]
   x35 = x[3]*x[5]
   I4 = x[1]*(x23 + x45) + (x24+x35)*x[6]
   I5 = sum(x3)
   I6 = sum(x4)

   # secondary invariants
   Ax = A*x
   PV1 = dot(x2, Ax)
   PV2 = dot(x3, Ax)
   PV3 = dot(x4, x)
   I11 = PV1 * PV1
   I12 = PV2 * PV3

   # gradient precomputations
   ∇I2 = @SVector [x[6], x[5], x[4], x[3], x[2], x[1]]
   ∇I4 = @SVector [ x23+x45,
                    x[1]*x[3]+x[4]*x[6],
                    x[1]*x[2]+x[5]*x[6],
                    x[1]*x[5]+x[2]*x[6],
                    x[1]*x[4]+x[3]*x[6],
                    x24+x35 ]
   ∇PV1 = A * x2 + 2 * (x .* Ax)
   ∇PV2 = A * x3 + 3 * (x2 .* Ax)
   ∇PV3 = 5 * x4

   return SVector(I1, I2, I3, I4, I5, I6),
         SVector(one(T), PV1, PV2, PV3, I11, I12),
         SVector(o, ∇I2, 2*x, ∇I4, 3*x2, 4*x3),
         SVector(z, ∇PV1, ∇PV2, ∇PV3, 2*PV1*∇PV1, PV3*∇PV2 + PV2*∇PV3)
end

tdegrees(::Val{4}) = (1, 2, 2, 3, 3, 4), (0, 3, 4, 5, 6, 9)

corners(::Val{4}) = ( SVector(1,2), SVector(1,3), SVector(1,4), SVector(2,3), SVector(2,4), SVector(3,4) )

# ------------------------------------------------------------------------
#             5-BODY Invariants
# ------------------------------------------------------------------------

# Invariants up to degree 7 only.

# tdegrees(::Val{5}) =
#       (@SVector [ 1, 2, 2, 3, 3, 4, 4, 5, 5, 6 ]),
#       (@SVector [ 0,
#                   3, 3,
#                   4, 4, 4, 4, 4,
#                   5, 5, 5, 5, 5, 5, 5, 5,
#                   6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
#                   7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 ])

tdegrees(::Val{5}) =
          (@SVector [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, ]),
    (@SVector [0,
               3, 3,
               4, 4, 4, 4, 4,
               5, 5, 5, 5, 5, 5, 5, 5,
               6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
               7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
               8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
               8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
               9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
               9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
               9, 9,
               10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
               10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
               10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
               10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
               11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
               11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
               11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
               11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
               11, 11, 11, 11, 11, 11, 11, 11, ])

include("generated/NB_5_deg_12/NB_5_deg_12_invariants.jl")
@inline invariants(x::SVector{10}) = NB5I.invariants_gen(x)
@inline invariants_d(x::SVector{10}) = NB5I.invariants_d_gen(x)
@inline invariants_ed(x::SVector{10}) = NB5I.invariants_ed_gen(x)

end

max_stars_repo_name: cortner/ManyBodyIPs

max_issues_repo_name: cortner/ManyBodyIPs

max_forks_repo_name: cortner/ManyBodyIPs


text:
# include("../src/plotSol.jl")
using LinearAlgebra
using DifferentialEquations
using Revise
# clearconsole()
function PendulumMinReal(m,l,theta,tInt,tEnd)
    function thdot(th)
        thDot = zeros(size(th));
        thDot[1] = th[2]
        thDot[2]  = -3*9.806/2/l*sin(th[1])
        return thDot
    end

    function mainDynMinReal(x,p,t)
        dx = thdot(x);
        return dx
    end

    x0 = [theta; 0.0];
    prob = ODEProblem(mainDynMinReal,x0,(0.0,tEnd))
    sol = solve(prob,Tsit5(),saveat = tInt,reltol=1e-10,abstol=1e-10);
    tSim = sol.t;
    thSol = sol[1,:];
    thDotSol = sol[2,:];
    xSol = zeros(length(tSim))
    zSol = zeros(length(tSim))
    ySol = zeros(length(tSim))
    vSol = zeros(length(tSim),3)
    for i=1:length(tSim)
        xSol[i] = l/2*sin(thSol[i])
        zSol[i] = -l/2*cos(thSol[i])
        vSol[i,:] = [l/2*cos(thSol[i])*thDotSol[i] 0.0 l/2*sin(thSol[i])*thDotSol[i]]
    end
    rSol = [xSol ySol zSol];
    ωSol = [ySol -thDotSol ySol];
    return rSol, vSol, ωSol
end

max_stars_repo_name: isrlab/Multibody-Dynamics

max_issues_repo_name: isrlab/Multibody-Dynamics

max_forks_repo_name: isrlab/Multibody-Dynamics


text:
"""

```
viewmol(i::Int, x::Vector{T}, n::Int) where T
```

Returns a view of a coordinate vector corresponding to the atoms
of a molecule with index i. n is the number of atoms of the molecule.

"""
function viewmol(i::Int, x::Vector{T}, n::Int) where {T}
    first = (i - 1) * n + 1
    last = first + n - 1
    return @view(x[first:last])
end

# From the structure of the solute or solvent
viewmol(i::Int, x::Vector{T}, s::Selection) where {T} = viewmol(i, x, s.natomspermol)


text:
using GeoJSON, GeoMakie, Makie, GeometryTypes, EarCut

goa = download("https://raw.githubusercontent.com/datameet/indian_village_boundaries/master/ga/ga.geojson")

gageo = GeoJSON.parse(read(goa, String))

polys = AbstractPlotting.convert_arguments(Poly, gageo)[1]

meshes = GLNormalMesh[]

sizehint!(meshes, length(polys))

@time for polygon in polys

    triangle_faces = triangulate([polygon])

    v = map(x-> Point3f0(x[1], x[2], 0), polygon)

    push!(meshes, GLNormalMesh(vertices=v, faces=triangle_faces))

end

sc = Scene()
for range in (1:length(meshes)÷4, length(meshes)÷4:2length(meshes)÷4, 2length(meshes)÷4:3length(meshes)÷4, 3length(meshes)÷4:length(meshes))
    mesh!(sc, meshes[range], color=rand(RGBAf0))
end
sc
mesh(meshes; color = 1:length(meshes), colormap = :viridis, scale_plot = false)

poly(rand(Point2f0, 3)) # warm up Makie

@time poly(gageo)


text:
# This file is a part of Julia. License is MIT: https://julialang.org/license

function _parse(stream::IO; greedy::Bool = true, raise::Bool = true)
    pos = position(stream)
    ex, Δ = Meta.parse(read(stream, String), 1, greedy = greedy, raise = raise)
    seek(stream, pos + Δ - 1)
    return ex
end

function interpinner(stream::IO, greedy = false)
    startswith(stream, '$') || return
    (eof(stream) || Char(peek(stream)) in whitespace) && return
    try
        return _parse(stream::IOBuffer, greedy = greedy)
    catch e
        return
    end
end

@trigger '$' ->
function interp(stream::IO, md::MD)
    withstream(stream) do
        ex = interpinner(stream)
        return ex
    end
end

function blockinterp(stream::IO, md::MD)
    withstream(stream) do
        ex = interpinner(stream)
        if ex ≡ nothing
            return false
        else
            push!(md, ex)
            return true
        end
    end
end

toexpr(x) = x

toexpr(xs::Vector{Any}) = Expr(:call, GlobalRef(Base,:vector_any), map(toexpr, xs)...)

for T in Any[MD, Paragraph, Header, Link, Bold, Italic]
    @eval function toexpr(md::$T)
        Expr(:call, typeof(md), $(map(x->:(toexpr(md.$x)), fieldnames(Base.unwrap_unionall(T)))...))
    end
end

max_stars_repo_name: YingboMa/julia

max_issues_repo_name: JuliaLangEs/julieta

max_forks_repo_name: JuliaLangEs/julieta