text:
function compare_to(obj::Enum, arg0::Enum)
    return jcall(obj, "compareTo", jint, (Enum,), arg0)
end

function describe_constable(obj::Enum)
    return jcall(obj, "describeConstable", Optional, ())
end

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

function get_declaring_class(obj::Enum)
    return jcall(obj, "getDeclaringClass", Class, ())
end

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

function measurement_is_feasible(obj::SignSemantic, arg0::jdouble)
    return jcall(obj, "measurementIsFeasible", jboolean, (jdouble,), arg0)
end

function name(obj::Enum)
    return jcall(obj, "name", JString, ())
end

function ordinal(obj::Enum)
    return jcall(obj, "ordinal", jint, ())
end

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

function value_of(::Type{Enum}, arg0::Class, arg1::JString)
    return jcall(Enum, "valueOf", Enum, (Class, JString), arg0, arg1)
end

function value_of(::Type{SignSemantic}, arg0::JString)
    return jcall(SignSemantic, "valueOf", SignSemantic, (JString,), arg0)
end

function values(::Type{SignSemantic})
    return jcall(SignSemantic, "values", Vector{SignSemantic}, ())
end


text:
#
# Functional interface to MacroTools' dict-based expression creation functions
# TBD: suggest adding these (without requiring dict) to MacroTools
#
function emit_struct(name::Symbol, supertype::Symbol, mutable::Bool, params::Vector, fields::Vector, ctors::Vector)
    fieldtups = [(tup[1], tup[2]) for tup in map(splitarg, fields)]
    d = Dict(:name=>name, :supertype=>supertype, :mutable=>mutable, :params=>params, :fields=>fieldtups, :constructors=>ctors)
    combinestructdef(d)
end

function emit_function(name::Symbol, body; args::Vector=[], kwargs::Vector=[], rtype=nothing, params::Vector=[], wparams::Vector=[])
    d = Dict(:name=>name, :args=>args, :kwargs=>kwargs, :body=>body, :params=>params, :whereparams=>wparams)
    if rtype !== nothing
        d[:rtype] = rtype
    end
    combinedef(d)
end

abs_symbol(cls::Symbol) = Symbol("Abstract", cls)

# Since nameof() doesn't cover all the cases we need, we define our own
typename(t) = t
typename(t::TypeVar) = t.name

# fieldnames(DataType)
# (:name, :super, :parameters, :types, :names, :instance, :layout, :size, :ninitialized, :uid, :abstract, :mutable, :hasfreetypevars,
# :isconcretetype, :isdispatchtuple, :isbitstype, :zeroinit, :isinlinealloc, Symbol("llvm::StructType"), Symbol("llvm::DIType"))
#
# if dtype.hasfreetypevars, dtype.types is like svec(XYZ<:ABC,...)

function _translate_ivar(d::Dict, ivar)
    if ! @capture(ivar, vname_::vtype_ | vname_)
        error("Expected field definition, got $ivar")
    end

    if vtype === nothing
        return ivar    # no type, nothing to translate
    end

    vtype = get(d, vtype, vtype)    # translate parameterized types
    return :($vname::$vtype)
end

function _translate_where(d::Dict, wparam::TypeVar)
    # supname = :Any
    supname = wparam.ub          # TBD: not sure this suffices
    name = wparam.name
    name = get(d, name, name)    # translate, if a type parameter, else pass through

    return :($name <: $supname)
end

# If a symbol is already a gensym, extract the symbol and re-gensym with it
regensym(s) = MacroTools.isgensym(s) ? gensym(Symbol(MacroTools.gensymname(s))) : gensym(s)

ext: jl


text:
"""
    setup_halofit(pk)

This function returns three parameters, [kσ, neff, C],  which are needed for computation of the halofit non-linear power spectrum.

*Reference*: Appendix C of Smith et al., MNRAS, 341, 1311 (2003)

# Arguments
- `pk`(k): a function which returns a linear matter power spectrum with the argument k being the comoving wavenumber.
    - **pk times k^3 must be dimensionless**. For example, if k is in units of h/Mpc, `pk` must be in units of Mpc^3/h^3.

This function is based on [Cosmology Routine Library (CRL)](https://wwwmpa.mpa-garching.mpg.de/~komatsu/crl/).
"""
function setup_halofit(pk)
    f(x) = √sigma2gaus(pk, x) - 1
    R = find_zero(f, (1e-2, 1e2), Bisection())
    σ2 = sigma2gaus(pk, R)
    dlnσ2dlnR = R * dsigma2gausdR(pk, R) / σ2
    d2lnσ2dlnR2 = dlnσ2dlnR - dlnσ2dlnR^2 + (R^2 / σ2) * d2sigma2gausdR2(pk, R)
    kσ = 1 / R
    neff = -3 - dlnσ2dlnR
    C = -d2lnσ2dlnR2
    return [kσ, neff, C]
end

"""
    halofit(pk, p, Ωmz, k)

This function returns a value of the non-linear power spectrum at a specified value of the comoving wavenumber.

*Reference*: Appendix of Takahashi et al., ApJ, 761, 152 (2012)
- This reference updates parameters given in Appendix C of Smith et al., MNRAS, 341, 1311 (2003)
- The terms proportional to (1+w) in Equation (A6, A7) of Takahashi et al. are not included in this function

# Arguments
- `pk`(k): a function which returns a linear matter power spectrum with the argument k being the comoving wavenumber.
- `p::Array{T,1} where T <: Real`: an array containing three variables [kσ, neff, C], which are obtained from `p = setup_halofit(pk)`.
- `Ωmz::Real`: the matter density parameter at a given redshift z, e.g., ``Ωmz = Ωm(1+z)^3 / [Ωm(1+z)^3 + Ωk(1+z)^2 + ΩΛ]``.
- `k::Real`: comoving wavenumber.
    - **pk times k^3 must be dimensionless**. For example, if `k` is in units of h/Mpc, `pk` must be in units of Mpc^3/h^3.

This function is based on [Cosmology Routine Library (CRL)](https://wwwmpa.mpa-garching.mpg.de/~komatsu/crl/).
"""
function halofit(pk, p::Array{T,1}, Ωmz::Real, k::Real) where {T<:Real}
    kσ, neff, C = p
    an =
        10^(
            1.5222 +
            2.8553neff +
            2.3706 * neff^2 +
            0.9903 * neff^3 +
            0.2250 * neff^4 - 0.6038C
        )
    bn = 10^(-0.5642 + 0.5864neff + 0.5716 * neff^2 - 1.5474C)
    cn = 10^(0.3698 + 2.0404neff + 0.8161 * neff^2 + 0.5869C)
    γn = 0.1971 - 0.0843neff + 0.8460C
    αn = abs(6.0835 + 1.3373neff - 0.1959 * neff^2 - 5.5274C)
    βn =
        2.0379 - 0.7354neff +
        0.3157 * neff^2 +
        1.2490 * neff^3 +
        0.3980 * neff^4 - 0.1682C
    μn = 0
    νn = 10^(5.2105 + 3.6902neff)
    f1 = Ωmz^-0.0307
    f2 = Ωmz^-0.0585
    f3 = Ωmz^0.0743
    y = k / kσ
    Δ2H = an * y^(3 * f1) / (1 + bn * y^f2 + (cn * f3 * y)^(3 - γn))
    Δ2H /= 1 + μn / y + νn / y^2
    Δ2L = k^3 * pk(k) / 2 / π^2
    Δ2Q = Δ2L * (1 + Δ2L)^βn / (1 + αn * Δ2L) * exp(-y / 4 - y^2 / 8)
    pk_nl = (Δ2Q + Δ2H) * 2 * π^2 / k^3
end


text:
include("iPredict.jl/src/iPredict.jl")
using .iPredict
using DataFrames
using Plots
using DelimitedFiles
using Plots.Measures
using StatsBase

#Initialise variables
GeneIsoformRelationships = "data/gencode_human_gene_isoform_relationships.txt"
NumSimulations = 100
NumIsoformsToSimulate = 4
filteringThreshold = 4
alpha = nothing
beta = nothing
scnorm_counts = ["H1_24_scnorm_counts.txt",
"H1_96_scnorm_counts.txt",
"H9_24_scnorm_counts.txt",
"H9_96_scnorm_counts.txt"]
pFP = 0.01
pFN = 0.04
isoChoiceModels = ["Weibull", "Random", "UniformObserved", "CellVariable"]

for countsMatrix in scnorm_counts

    output = "figures/figure4/" * countsMatrix

    for model in 1:length(isoChoiceModels)

        output = "figures/figure4/" * isoChoiceModels[model] * "_" * countsMatrix

        out = globalPredict("data/" * countsMatrix, GeneIsoformRelationships,
        NumSimulations, output, NumIsoformsToSimulate, filteringThreshold,
        false, alpha, beta, pFN, pFP, "none", isoChoiceModels[model],
        "figures/figure5_data/" * isoChoiceModels[model] * "_" * countsMatrix)
    end
end

################################################################################
# Make figure 4 + supplementary figs
################################################################################

function make_hist(path, titleArg)
    Arr = readdlm(path)

    if titleArg == "3 Isoforms" && path == "figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_3_isoforms_array.txt"
        #Untransformed plot
        p1 = histogram(Arr,
        title = titleArg,
        xlims = (0, 4),
        ylims = (0, 5),
        ylabel = "Probability Density",
        normalize=:pdf,
        bins = 100,
        axis = (font(150)), titlefontsize=150, yticks = 0:5:5,
        margin = 35mm,
        left_margin = 50mm,
        right_margin = 50mm)

    elseif titleArg == "Real"
        p1 = histogram(Arr,
        title = titleArg,
        xlims = (0, 4),
        ylims = (0, 5),
        normalize=:pdf,
        xlabel = "Mean No. Isoforms\nper Gene per Cell",
        bins = 100,
        axis = (font(150)), titlefontsize=150, yticks = 0:5:5,
        margin = 35mm,
        left_margin = 50mm,
        right_margin = 50mm)

    else
        #Untransformed plot
        p1 = histogram(Arr,
        title = titleArg,
        xlims = (0, 4),
        ylims = (0, 5),
        normalize=:pdf,
        bins = 100,
        axis = (font(150)), titlefontsize=150, yticks = 0:5:5,
        margin = 35mm,left_margin = 50mm,
        right_margin = 50mm)
    end
    #vline!([mean(Arr)], color = :black, linewidth = 8)
    return p1
end

#for countsMatrix in scnorm_counts
# "Weibull", "Random", "UniformObserved", "CellVariable"
Weibull_1 = make_hist("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_1_isoforms_array.txt", "1 Isoform")
Weibull_2 = make_hist("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_2_isoforms_array.txt", "2 Isoforms")
Weibull_3 = make_hist("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_3_isoforms_array.txt", "3 Isoforms")
Weibull_4 = make_hist("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_4_isoforms_array.txt", "4 Isoforms")
Weibull_real = make_hist("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_real_isoforms_array.txt", "Real")

Random_1 = make_hist("figures/figure5_data/Random_H1_24_scnorm_counts.txt_1_isoforms_array.txt", "1 Isoform")
Random_2 = make_hist("figures/figure5_data/Random_H1_24_scnorm_counts.txt_2_isoforms_array.txt", "2 Isoforms")
Random_3 = make_hist("figures/figure5_data/Random_H1_24_scnorm_counts.txt_3_isoforms_array.txt", "3 Isoforms")
Random_4 = make_hist("figures/figure5_data/Random_H1_24_scnorm_counts.txt_4_isoforms_array.txt", "4 Isoforms")
Random_real = make_hist("figures/figure5_data/Random_H1_24_scnorm_counts.txt_real_isoforms_array.txt", "Real")

UniformObserved_1 = make_hist("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_1_isoforms_array.txt", "1 Isoform")
UniformObserved_2 = make_hist("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_2_isoforms_array.txt", "2 Isoforms")
UniformObserved_3 = make_hist("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_3_isoforms_array.txt", "3 Isoforms")
UniformObserved_4 = make_hist("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_4_isoforms_array.txt", "4 Isoforms")
UniformObserved_real = make_hist("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_real_isoforms_array.txt", "Real")

CellVariable_1 = make_hist("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_1_isoforms_array.txt", "1 Isoform")
CellVariable_2 = make_hist("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_2_isoforms_array.txt", "2 Isoforms")
CellVariable_3 = make_hist("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_3_isoforms_array.txt", "3 Isoforms")
CellVariable_4 = make_hist("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_4_isoforms_array.txt", "4 Isoforms")
CellVariable_real = make_hist("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_real_isoforms_array.txt", "Real")

p3 = plot( Weibull_1, Random_1, UniformObserved_1, CellVariable_1,
       Weibull_2, Random_2,UniformObserved_2, CellVariable_2,
       Weibull_3, Random_3,UniformObserved_3, CellVariable_3,
       Weibull_4, Random_4,UniformObserved_4, CellVariable_4,
       Weibull_real, Random_real,UniformObserved_real, CellVariable_real,
       layout = (5,4), legend = false, size = (750 *8, 900*8), axis = (font(90)), titlefontsize=90,)

savefig(p3, "figures/figure4/figure4.png")

###############################################################
using JLD2
using DelimitedFiles
using HypothesisTests
using DataFrames

Weibull_1 = readdlm("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_1_isoforms_array.txt")
Weibull_2 = readdlm("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_2_isoforms_array.txt")
Weibull_3 = readdlm("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_3_isoforms_array.txt")
Weibull_4 = readdlm("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_4_isoforms_array.txt")
Weibull_real = readdlm("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_real_isoforms_array.txt")

Random_1 = readdlm("figures/figure5_data/Random_H1_24_scnorm_counts.txt_1_isoforms_array.txt")
Random_2 = readdlm("figures/figure5_data/Random_H1_24_scnorm_counts.txt_2_isoforms_array.txt")
Random_3 = readdlm("figures/figure5_data/Random_H1_24_scnorm_counts.txt_3_isoforms_array.txt")
Random_4 = readdlm("figures/figure5_data/Random_H1_24_scnorm_counts.txt_4_isoforms_array.txt")
Random_real = readdlm("figures/figure5_data/Random_H1_24_scnorm_counts.txt_real_isoforms_array.txt")

UniformObserved_1 = readdlm("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_1_isoforms_array.txt")
UniformObserved_2 = readdlm("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_2_isoforms_array.txt")
UniformObserved_3 = readdlm("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_3_isoforms_array.txt")
UniformObserved_4 = readdlm("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_4_isoforms_array.txt")
UniformObserved_real = readdlm("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_real_isoforms_array.txt")

CellVariable_1 = readdlm("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_1_isoforms_array.txt")
CellVariable_2 = readdlm("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_2_isoforms_array.txt")
CellVariable_3 = readdlm("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_3_isoforms_array.txt")
CellVariable_4 = readdlm("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_4_isoforms_array.txt")
CellVariable_real = readdlm("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_real_isoforms_array.txt")

df = DataFrame(IsoformsSimulated=Int64[], Comparison = String[], pValue = Float64[])

append!(df, DataFrame(IsoformsSimulated = [1], Comparison = ["All"], pValue=[pvalue(KSampleADTest(vec(Weibull_1), vec(Random_1), vec(UniformObserved_1), vec(CellVariable_1)))]))
append!(df, DataFrame(IsoformsSimulated = [2], Comparison = "All", pValue=[pvalue(KSampleADTest(vec(Weibull_2), vec(Random_2), vec(UniformObserved_2), vec(CellVariable_2)))]))
append!(df, DataFrame(IsoformsSimulated = [3], Comparison = "All", pValue=[pvalue(KSampleADTest(vec(Weibull_3), vec(Random_3), vec(UniformObserved_3), vec(CellVariable_3)))]))
append!(df, DataFrame(IsoformsSimulated = [4], Comparison = "All", pValue=[pvalue(KSampleADTest(vec(Weibull_4), vec(Random_4), vec(UniformObserved_4), vec(CellVariable_4)))]))

append!(df, DataFrame(IsoformsSimulated = [1], Comparison = "CellVarUnif", pValue=[pvalue(KSampleADTest(vec(UniformObserved_1), vec(CellVariable_1)))]))
append!(df, DataFrame(IsoformsSimulated = [2], Comparison = "CellVarUnif", pValue=[pvalue(KSampleADTest( vec(UniformObserved_2), vec(CellVariable_2)))]))
append!(df, DataFrame(IsoformsSimulated = [3], Comparison = "CellVarUnif", pValue=[pvalue(KSampleADTest(vec(UniformObserved_3), vec(CellVariable_3)))]))
append!(df, DataFrame(IsoformsSimulated = [4], Comparison = "CellVarUnif", pValue=[pvalue(KSampleADTest(vec(UniformObserved_4), vec(CellVariable_4)))]))

jldopen("figures/figure4_data/AD_test_results.jld2", "w") do file
    file["df"] = df
end

####################################################################
# Overlap plots
####################################################################

function make_overlap_hist(path, titleArg)

     Arr = readdlm(path)
     p1 = histogram(Arr, title = titleArg, normalize=:pdf, bins = 100,
     ylims = (0,4), color = palette(:default)[2],
     axis = (font(150)), titlefontsize=150, yticks = 0:2:4,
     xticks = 0:0.5:1,
     margin = 35mm,left_margin = 50mm,
     right_margin = 50mm)
     return p1

end

#For H1_24 dataset

#Weibull
Weibull_1 = make_overlap_hist("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_1_isoforms_overlap_array.txt", "1 Isoform")
Weibull_2 = make_overlap_hist("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_2_isoforms_overlap_array.txt", "2 Isoforms")
Weibull_3 = make_overlap_hist("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_3_isoforms_overlap_array.txt", "3 Isoforms")
Weibull_4 = make_overlap_hist("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_4_isoforms_overlap_array.txt", "4 Isoforms")
outplot = plot(Weibull_1, Weibull_2, Weibull_3, Weibull_4, legend = false)
savefig(outplot, "figures/figure4/Weibull_overlap_H1_24.png")

#Random
Random_1 = make_overlap_hist("figures/figure5_data/Random_H1_24_scnorm_counts.txt_1_isoforms_overlap_array.txt", "1 Isoform")
Random_2 = make_overlap_hist("figures/figure5_data/Random_H1_24_scnorm_counts.txt_2_isoforms_overlap_array.txt", "2 Isoforms")
Random_3 = make_overlap_hist("figures/figure5_data/Random_H1_24_scnorm_counts.txt_3_isoforms_overlap_array.txt", "3 Isoforms")
Random_4 = make_overlap_hist("figures/figure5_data/Random_H1_24_scnorm_counts.txt_4_isoforms_overlap_array.txt", "4 Isoforms")
outplot = plot(Random_1, Random_2, Random_3, Random_4, legend = false)
savefig(outplot, "figures/figure4/Random_overlap_H1_24.png")

UniformObserved_1 = make_overlap_hist("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_1_isoforms_overlap_array.txt", "1 Isoform")
UniformObserved_2 = make_overlap_hist("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_2_isoforms_overlap_array.txt", "2 Isoforms")
UniformObserved_3 = make_overlap_hist("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_3_isoforms_overlap_array.txt", "3 Isoforms")
UniformObserved_4 = make_overlap_hist("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_4_isoforms_overlap_array.txt", "4 Isoforms")
outplot = plot(UniformObserved_1, UniformObserved_2, UniformObserved_3, UniformObserved_4 , legend = false)
savefig(outplot, "figures/figure4/UniformObserved_overlap_H1_24.png")

CellVariable_1 = make_overlap_hist("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_1_isoforms_overlap_array.txt", "1 Isoform")
CellVariable_2 = make_overlap_hist("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_2_isoforms_overlap_array.txt", "2 Isoforms")
CellVariable_3 = make_overlap_hist("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_3_isoforms_overlap_array.txt", "3 Isoforms")
CellVariable_4 = make_overlap_hist("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_4_isoforms_overlap_array.txt", "4 Isoforms")
outplot = plot(CellVariable_1, CellVariable_2, CellVariable_3, CellVariable_4, legend = false)
savefig(outplot, "figures/figure4/CellVariable_overlap_H1_24.png")

p3 = plot( Weibull_1, Random_1, UniformObserved_1, CellVariable_1,
       Weibull_2, Random_2,UniformObserved_2, CellVariable_2,
       Weibull_3, Random_3,UniformObserved_3, CellVariable_3,
       Weibull_4, Random_4,UniformObserved_4, CellVariable_4,
       layout = (4,4), legend = false, size = (750 *8, 750*8), axis = (font(90)), titlefontsize=90,)

savefig(p3, "figures/figure4/figure4_overlap.png")

##############################################################################
# Dropouts
##############################################################################

function make_drop_hist(path, titleArg)

     Arr = readdlm(path)

     if titleArg=="1 Isoform"
         p1 = histogram(rand(Arr, 100000) , title = titleArg, normalize=:pdf,
         bins = 100, ylims = (0,10), ylabel="Probability Density",
         margin = 5mm)
         return p1

    elseif titleArg == "3 Isoforms"
        p1 =histogram(rand(Arr, 100000) , title = titleArg, normalize=:pdf,
        bins = 100, ylims = (0,10), ylabel="Probability Density",
        xlabel = "p(Dropout)",
        margin = 5mm)
        return p1

    elseif titleArg == "4 Isoforms"
        p1 = histogram(rand(Arr, 100000) , title = titleArg, normalize=:pdf,
        bins = 100, xlabel="p(Dropout)", ylims = (0,10),
        margin = 5mm)
        return p1

    else
        p1 = histogram(rand(Arr, 100000) , title = titleArg, normalize=:pdf,
        bins = 100, margin = 5mm,  ylims = (0,10))
        return p1
    end

end

#For H1_24 dataset

#Weibull
Weibull_1 = make_drop_hist("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_1_isoforms_pdrop_array.txt", "1 Isoform")
Weibull_2 = make_drop_hist("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_2_isoforms_pdrop_array.txt", "2 Isoforms")
Weibull_3 = make_drop_hist("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_3_isoforms_pdrop_array.txt", "3 Isoforms")
Weibull_4 = make_drop_hist("figures/figure5_data/Weibull_H1_24_scnorm_counts.txt_4_isoforms_pdrop_array.txt", "4 Isoforms")
outplot = plot(Weibull_1, Weibull_2, Weibull_3, Weibull_4, legend = false)
savefig(outplot, "figures/figure4/Weibull_pdrop_H1_24.png")

#Random
Random_1 = make_drop_hist("figures/figure5_data/Random_H1_24_scnorm_counts.txt_1_isoforms_pdrop_array.txt", "1 Isoform")
Random_2 = make_drop_hist("figures/figure5_data/Random_H1_24_scnorm_counts.txt_2_isoforms_pdrop_array.txt", "2 Isoforms")
Random_3 = make_drop_hist("figures/figure5_data/Random_H1_24_scnorm_counts.txt_3_isoforms_pdrop_array.txt", "3 Isoforms")
Random_4 = make_drop_hist("figures/figure5_data/Random_H1_24_scnorm_counts.txt_4_isoforms_pdrop_array.txt", "4 Isoforms")
outplot = plot(Random_1, Random_2, Random_3, Random_4, legend = false)
savefig(outplot, "figures/figure4/Random_pdrop_H1_24.png")

UniformObserved_1 = make_drop_hist("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_1_isoforms_pdrop_array.txt", "1 Isoform")
UniformObserved_2 = make_drop_hist("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_2_isoforms_pdrop_array.txt", "2 Isoforms")
UniformObserved_3 = make_drop_hist("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_3_isoforms_pdrop_array.txt", "3 Isoforms")
UniformObserved_4 = make_drop_hist("figures/figure5_data/UniformObserved_H1_24_scnorm_counts.txt_4_isoforms_pdrop_array.txt", "4 Isoforms")
outplot = plot(UniformObserved_1, UniformObserved_2, UniformObserved_3, UniformObserved_4, legend = false)
savefig(outplot, "figures/figure4/UniformObserved_pdrop_H1_24.png")

CellVariable_1 = make_drop_hist("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_1_isoforms_pdrop_array.txt", "1 Isoform")
CellVariable_2 = make_drop_hist("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_2_isoforms_pdrop_array.txt", "2 Isoforms")
CellVariable_3 = make_drop_hist("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_3_isoforms_pdrop_array.txt", "3 Isoforms")
CellVariable_4 = make_drop_hist("figures/figure5_data/CellVariable_H1_24_scnorm_counts.txt_4_isoforms_pdrop_array.txt", "4 Isoforms")
outplot = plot(CellVariable_1, CellVariable_2, CellVariable_3, CellVariable_4, legend = false)
savefig(outplot, "figures/figure4/CellVariable_pdrop_H1_24.png")

#Weibull

max_stars_repo_name: jenni-westoby/Obstacles

max_issues_repo_name: jenni-westoby/Obstacles

max_forks_repo_name: jenni-westoby/Obstacles


text:
# Automatically generated using Clang.jl

const CUTENSORNET_MAJOR = 0
const CUTENSORNET_MINOR = 0
const CUTENSORNET_PATCH = 1
const CUTENSORNET_VERSION = CUTENSORNET_MAJOR * 10000 + CUTENSORNET_MINOR * 100 + CUTENSORNET_PATCH

@cenum cutensornetStatus_t::UInt32 begin
    CUTENSORNET_STATUS_SUCCESS = 0
    CUTENSORNET_STATUS_NOT_INITIALIZED = 1
    CUTENSORNET_STATUS_ALLOC_FAILED = 3
    CUTENSORNET_STATUS_INVALID_VALUE = 7
    CUTENSORNET_STATUS_ARCH_MISMATCH = 8
    CUTENSORNET_STATUS_MAPPING_ERROR = 11
    CUTENSORNET_STATUS_EXECUTION_FAILED = 13
    CUTENSORNET_STATUS_INTERNAL_ERROR = 14
    CUTENSORNET_STATUS_NOT_SUPPORTED = 15
    CUTENSORNET_STATUS_LICENSE_ERROR = 16
    CUTENSORNET_STATUS_CUBLAS_ERROR = 17
    CUTENSORNET_STATUS_CUDA_ERROR = 18
    CUTENSORNET_STATUS_INSUFFICIENT_WORKSPACE = 19
    CUTENSORNET_STATUS_INSUFFICIENT_DRIVER = 20
    CUTENSORNET_STATUS_IO_ERROR = 21
    CUTENSORNET_STATUS_CUTENSOR_VERSION_MISMATCH = 22
end

@cenum cutensornetComputeType_t::UInt32 begin
    CUTENSORNET_COMPUTE_16F = 1
    CUTENSORNET_COMPUTE_16BF = 1024
    CUTENSORNET_COMPUTE_TF32 = 4096
    CUTENSORNET_COMPUTE_32F = 4
    CUTENSORNET_COMPUTE_64F = 16
    CUTENSORNET_COMPUTE_8U = 64
    CUTENSORNET_COMPUTE_8I = 256
    CUTENSORNET_COMPUTE_32U = 128
    CUTENSORNET_COMPUTE_32I = 512
end

@cenum cutensornetGraphAlgo_t::UInt32 begin
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_GRAPH_ALGORITHM_RB = 0
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_GRAPH_ALGORITHM_KWAY = 1
end

@cenum cutensornetMemoryModel_t::UInt32 begin
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_SLICER_MEMORY_MODEL_HEURISTIC = 0
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_SLICER_MEMORY_MODEL_CUTENSOR = 1
end

@cenum cutensornetContractionOptimizerConfigAttributes_t::UInt32 begin
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_GRAPH_NUM_PARTITIONS = 0
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_GRAPH_CUTOFF_SIZE = 1
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_GRAPH_ALGORITHM = 2
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_GRAPH_IMBALANCE_FACTOR = 3
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_GRAPH_NUM_ITERATIONS = 4
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_GRAPH_NUM_CUTS = 5
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_RECONFIG_NUM_ITERATIONS = 6
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_RECONFIG_NUM_LEAVES = 7
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_SLICER_DISABLE_SLICING = 8
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_SLICER_MEMORY_MODEL = 9
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_SLICER_MEMORY_FACTOR = 10
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_SLICER_MIN_SLICES = 11
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_SLICER_SLICE_FACTOR = 12
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_HYPER_NUM_SAMPLES = 13
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_SIMPLIFICATION_DISABLE_DR = 14
    CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_SEED = 15
end

@cenum cutensornetContractionOptimizerInfoAttributes_t::UInt32 begin
    CUTENSORNET_CONTRACTION_OPTIMIZER_INFO_NUM_SLICES = 0
    CUTENSORNET_CONTRACTION_OPTIMIZER_INFO_NUM_SLICED_MODES = 1
    CUTENSORNET_CONTRACTION_OPTIMIZER_INFO_SLICED_MODE = 2
    CUTENSORNET_CONTRACTION_OPTIMIZER_INFO_SLICED_EXTENT = 3
    CUTENSORNET_CONTRACTION_OPTIMIZER_INFO_PATH = 4
    CUTENSORNET_CONTRACTION_OPTIMIZER_INFO_PHASE1_FLOP_COUNT = 5
    CUTENSORNET_CONTRACTION_OPTIMIZER_INFO_FLOP_COUNT = 6
    CUTENSORNET_CONTRACTION_OPTIMIZER_INFO_LARGEST_TENSOR = 7
    CUTENSORNET_CONTRACTION_OPTIMIZER_INFO_SLICING_OVERHEAD = 8
end

@cenum cutensornetContractionAutotunePreferenceAttributes_t::UInt32 begin
    CUTENSORNET_CONTRACTION_AUTOTUNE_MAX_ITERATIONS = 0
end

const cutensornetNetworkDescriptor_t = Ptr{Cvoid}
const cutensornetContractionPlan_t = Ptr{Cvoid}
const cutensornetHandle_t = Ptr{Cvoid}
const cutensornetNodePair_t = cutensornetNodePair

struct cutensornetContractionPath
    numContractions::Int32
    data::Ptr{cutensornetNodePair_t}
end

const cutensornetContractionPath_t = cutensornetContractionPath
const cutensornetContractionOptimizerConfig_t = Ptr{Cvoid}
const cutensornetContractionOptimizerInfo_t = Ptr{Cvoid}
const cutensornetContractionAutotunePreference_t = Ptr{Cvoid}
const cutensornetLoggerCallback_t = Ptr{Cvoid}
const CUSTATEVEC_VER_MAJOR = 0
const CUSTATEVEC_VER_MINOR = 1
const CUSTATEVEC_VER_PATCH = 0
const CUSTATEVEC_VERSION = CUSTATEVEC_VER_MAJOR * 1000 + CUSTATEVEC_VER_MINOR * 100 + CUSTATEVEC_VER_PATCH
const custatevecIndex_t = Int64
const custatevecContext = Cvoid
const custatevecHandle_t = Ptr{custatevecContext}

struct custatevecSamplerDescriptor
    data::NTuple{256, UInt8}
end

const custatevecSamplerDescriptor_t = custatevecSamplerDescriptor

struct custatevecAccessorDescriptor
    data::NTuple{1024, UInt8}
end

const custatevecAccessorDescriptor_t = custatevecAccessorDescriptor
const custatevecLoggerCallback_t = Ptr{Cvoid}

@cenum custatevecStatus_t::UInt32 begin
    CUSTATEVEC_STATUS_SUCCESS = 0
    CUSTATEVEC_STATUS_NOT_INITIALIZED = 1
    CUSTATEVEC_STATUS_ALLOC_FAILED = 2
    CUSTATEVEC_STATUS_INVALID_VALUE = 3
    CUSTATEVEC_STATUS_ARCH_MISMATCH = 4
    CUSTATEVEC_STATUS_EXECUTION_FAILED = 5
    CUSTATEVEC_STATUS_INTERNAL_ERROR = 6
    CUSTATEVEC_STATUS_NOT_SUPPORTED = 7
    CUSTATEVEC_STATUS_INSUFFICIENT_WORKSPACE = 8
    CUSTATEVEC_STATUS_SAMPLER_NOT_PREPROCESSED = 9
end

@cenum custatevecPauli_t::UInt32 begin
    CUSTATEVEC_PAULI_I = 0
    CUSTATEVEC_PAULI_X = 1
    CUSTATEVEC_PAULI_Y = 2
    CUSTATEVEC_PAULI_Z = 3
end

@cenum custatevecMatrixLayout_t::UInt32 begin
    CUSTATEVEC_MATRIX_LAYOUT_COL = 0
    CUSTATEVEC_MATRIX_LAYOUT_ROW = 1
end

@cenum custatevecMatrixType_t::UInt32 begin
    CUSTATEVEC_MATRIX_TYPE_GENERAL = 0
    CUSTATEVEC_MATRIX_TYPE_UNITARY = 1
    CUSTATEVEC_MATRIX_TYPE_HERMITIAN = 2
end

@cenum custatevecCollapseOp_t::UInt32 begin
    CUSTATEVEC_COLLAPSE_NONE = 0
    CUSTATEVEC_COLLAPSE_NORMALIZE_AND_ZERO = 1
end

@cenum custatevecComputeType_t::UInt32 begin
    CUSTATEVEC_COMPUTE_DEFAULT = 0
    CUSTATEVEC_COMPUTE_32F = 4
    CUSTATEVEC_COMPUTE_64F = 16
    CUSTATEVEC_COMPUTE_TF32 = 4096
end

@cenum custatevecSamplerOutput_t::UInt32 begin
    CUSTATEVEC_SAMPLER_OUTPUT_RANDNUM_ORDER = 0
    CUSTATEVEC_SAMPLER_OUTPUT_ASCENDING_ORDER = 1
end


text:
# Records spikes from a population.

struct RecordedSpikes{T,R,TT,TI}
    instance::T # the object we're recording from
    steps::R # the timesteps to record
    ts::Vector{TT} # timesteps of recorded spikes
    id::Vector{TI} # indices of recorded spikes
end

function choose_uint_type(max_val)
    for N in (UInt8, UInt16, UInt32, UInt64, UInt128)
        if typemax(N) >= max_val
            return N
        end
    end
    throw(OverflowError())
end

function RecordedSpikes(instance, steps)
    # Choose a compact representation for the data we'll have to store:
    # if issubtype(eltype(steps), Int)
    #     TT = choose_uint_type(maximum(steps))
    # else
    #     TT = eltype(steps)
    # end
    # TI = choose_uint_type(length(instance))

    TT = eltype(steps)
    TI = Int32

    ts = Vector{TT}()
    id = Vector{TI}()

    # Let's pre-allocate a sensible chunk of memory, assuming
    # a 1/1000 spike probability per timestep:
    expected_spikes = clamp((length(steps)*length(instance)) ÷ 1000,
                            1000, 10000000)
    sizehint!(ts, expected_spikes)
    sizehint!(id, expected_spikes)

    RecordedSpikes{typeof(instance), typeof(steps), TT, TI}(
                   instance, steps, ts, id)
end

timestamps(r::RecordedSpikes, dt) = r.ts * dt

function reset!(r::RecordedSpikes)
    empty!(r.ts)
    empty!(r.id)
end

@inline record!(data::Void, step, has_spike) = nothing

@inline function record!{T}(data::RecordedSpikes{T}, step, has_spike)
    if step in data.steps
        group = data.instance
        ts = data.ts
        id = data.id
        for i in eachindex(group)
            @inbounds if has_spike(Elem(group,i))
                push!(ts, step)
                push!(id, i)
            end
        end
    end
    nothing
end


text:
using JuMP, EAGO

                     m = Model()

                     EAGO.register_eago_operators!(m)

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

                     @variable(m, -58.37772561872491 <= q <= 51.748312049639644)

                     add_NL_constraint(m, :(gelu(-0.3976822916974827 + -0.11888104611683081*gelu(-0.09559544092481564 + 0.23201220435158865*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + -0.9126138494455787*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + 0.24324641666113456*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + 0.1690500900766101*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + 0.20833731206579253*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + -0.8277675607937618*gelu(-0.41653739657549194 + 0.7547021537813423*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + 0.5787262183714494*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + -0.11492508246438904*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + 0.30062983013792843*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + -0.1276250114011983*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + 0.37430250255255215*gelu(0.9557400948867283 + -0.3128610884258398*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + 0.29518845150992634*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + -0.18188148649835556*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + 0.8330182900675651*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + -0.8804319372999063*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + 0.9159784725268092*gelu(-0.32868009819829513 + 0.7041500634234112*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + -0.44147758504740464*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + -0.5937281428689025*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + -0.3198554528784734*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + -0.047330375221362964*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + -0.21239133839693736*gelu(-0.6560670298284208 + 0.11579976545709414*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + 0.7227941593613254*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + 0.5041216754022764*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + -0.9501104307252297*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + 0.7033943599032555*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5])))) + gelu(-0.962366690533889 + 0.21288820713294498*gelu(-0.09559544092481564 + 0.23201220435158865*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + -0.9126138494455787*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + 0.24324641666113456*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + 0.1690500900766101*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + 0.20833731206579253*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + 0.04621026197884115*gelu(-0.41653739657549194 + 0.7547021537813423*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + 0.5787262183714494*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + -0.11492508246438904*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + 0.30062983013792843*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + -0.1276250114011983*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + 0.3579305330052933*gelu(0.9557400948867283 + -0.3128610884258398*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + 0.29518845150992634*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + -0.18188148649835556*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + 0.8330182900675651*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + -0.8804319372999063*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + -0.40247732796428703*gelu(-0.32868009819829513 + 0.7041500634234112*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + -0.44147758504740464*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + -0.5937281428689025*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + -0.3198554528784734*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + -0.047330375221362964*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + -0.3937461182921762*gelu(-0.6560670298284208 + 0.11579976545709414*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + 0.7227941593613254*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + 0.5041216754022764*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + -0.9501104307252297*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + 0.7033943599032555*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5])))) + gelu(-0.9189915189234159 + -0.5125130010222394*gelu(-0.09559544092481564 + 0.23201220435158865*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + -0.9126138494455787*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + 0.24324641666113456*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + 0.1690500900766101*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + 0.20833731206579253*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + -0.3502499398907637*gelu(-0.41653739657549194 + 0.7547021537813423*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + 0.5787262183714494*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + -0.11492508246438904*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + 0.30062983013792843*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + -0.1276250114011983*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + -0.8274375080497247*gelu(0.9557400948867283 + -0.3128610884258398*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + 0.29518845150992634*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + -0.18188148649835556*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + 0.8330182900675651*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + -0.8804319372999063*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + -0.7757421130805153*gelu(-0.32868009819829513 + 0.7041500634234112*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + -0.44147758504740464*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + -0.5937281428689025*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + -0.3198554528784734*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + -0.047330375221362964*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + 0.6602598595684599*gelu(-0.6560670298284208 + 0.11579976545709414*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + 0.7227941593613254*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + 0.5041216754022764*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + -0.9501104307252297*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + 0.7033943599032555*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5])))) + gelu(-0.760456357412739 + 0.8974231726544617*gelu(-0.09559544092481564 + 0.23201220435158865*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + -0.9126138494455787*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + 0.24324641666113456*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + 0.1690500900766101*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + 0.20833731206579253*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + -0.7589867374120325*gelu(-0.41653739657549194 + 0.7547021537813423*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + 0.5787262183714494*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + -0.11492508246438904*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + 0.30062983013792843*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + -0.1276250114011983*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + -0.3014899851721653*gelu(0.9557400948867283 + -0.3128610884258398*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + 0.29518845150992634*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + -0.18188148649835556*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + 0.8330182900675651*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + -0.8804319372999063*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + 0.03263132145111802*gelu(-0.32868009819829513 + 0.7041500634234112*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + -0.44147758504740464*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + -0.5937281428689025*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + -0.3198554528784734*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + -0.047330375221362964*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + 0.8460059521417822*gelu(-0.6560670298284208 + 0.11579976545709414*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + 0.7227941593613254*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + 0.5041216754022764*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + -0.9501104307252297*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + 0.7033943599032555*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5])))) + gelu(-0.1364886291423204 + -0.7689732133011344*gelu(-0.09559544092481564 + 0.23201220435158865*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + -0.9126138494455787*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + 0.24324641666113456*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + 0.1690500900766101*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + 0.20833731206579253*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + 0.9275671307049969*gelu(-0.41653739657549194 + 0.7547021537813423*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + 0.5787262183714494*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + -0.11492508246438904*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + 0.30062983013792843*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + -0.1276250114011983*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + -0.311285022430249*gelu(0.9557400948867283 + -0.3128610884258398*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + 0.29518845150992634*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + -0.18188148649835556*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + 0.8330182900675651*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + -0.8804319372999063*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + -0.2373305013184268*gelu(-0.32868009819829513 + 0.7041500634234112*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + -0.44147758504740464*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + -0.5937281428689025*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + -0.3198554528784734*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + -0.047330375221362964*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5]))) + 0.7676258102518863*gelu(-0.6560670298284208 + 0.11579976545709414*gelu(0.22080335056838862 + -0.11207096478827117*$(x[1]) + 0.9802919969431398*$(x[2]) + -0.17783835331857878*$(x[3]) + 0.5553411614422452*$(x[4]) + 0.8384080073044262*$(x[5])) + 0.7227941593613254*gelu(-0.03619259662306584 + -0.3774088093292831*$(x[1]) + 0.859114754276578*$(x[2]) + -0.4844223734792257*$(x[3]) + 0.08654340008535533*$(x[4]) + -0.46594229223618644*$(x[5])) + 0.5041216754022764*gelu(-0.05960623749041094 + -0.4311407494411239*$(x[1]) + -0.025139997052890273*$(x[2]) + 0.060401892548068936*$(x[3]) + 0.5875386419954256*$(x[4]) + 0.5553096462934759*$(x[5])) + -0.9501104307252297*gelu(0.12047524138880839 + -0.4988789730921872*$(x[1]) + -0.41177595995379823*$(x[2]) + -0.6913890776083331*$(x[3]) + 0.032955544793602076*$(x[4]) + -0.5657303188428733*$(x[5])) + 0.7033943599032555*gelu(-0.14422850857319736 + 0.5362813944125526*$(x[1]) + 0.29620144485119626*$(x[2]) + -0.18264867223264059*$(x[3]) + 0.5265937438977235*$(x[4]) + 0.6008528580664168*$(x[5])))) - $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:
module PWscf

using Compat: eachrow
using Crystallography: ReciprocalPoint, MonkhorstPackGrid
using Formatting: sprintf1
using QuantumESPRESSOBase.Inputs.PWscf:
    AtomicSpecies,
    AtomicPosition,
    ReciprocalPoint,
    AtomicSpeciesCard,
    AtomicPositionsCard,
    CellParametersCard,
    AtomicForce,
    SpecialPointsCard,
    GammaPointCard,
    KMeshCard,
    PWInput,
    optionof

import AbInitioSoftwareBase.Inputs: FormatConfig, asstring

export format_file, format_text

FormatConfig(
    ::Union{
        AtomicSpecies,
        AtomicPosition,
        ReciprocalPoint,
        AtomicSpeciesCard,
        AtomicPositionsCard,
        CellParametersCard,
        MonkhorstPackGrid,
        AtomicForce,
        SpecialPointsCard,
        GammaPointCard,
        KMeshCard,
    },
) = FormatConfig(;
    delimiter = " ",
    newline = "\n",
    indent = ' '^4,
    float = "%14.9f",
    int = "%5d",
    bool = ".%.",
)

"""
    asstring(data::AtomicSpecies)

Return a `String` representing a `AtomicSpecies`, valid for Quantum ESPRESSO's input.
"""
function asstring(data::AtomicSpecies)
    config = FormatConfig(data)
    return join(
        (
            config.indent,
            sprintf1("%3s", data.atom),
            sprintf1(config.float, data.mass),
            data.pseudopot,
        ),
        config.delimiter,
    )
end
"""
    asstring(card::AtomicSpeciesCard)

Return a `String` representing a `AtomicSpeciesCard`, valid for Quantum ESPRESSO's input.
"""
function asstring(card::AtomicSpeciesCard)
    config = FormatConfig(card)
    data = union(card.data)
    return join(("ATOMIC_SPECIES", map(asstring, data)...), config.newline)
end
"""
    asstring(data::AtomicPosition)

Return a `String` representing a `AtomicPosition`, valid for Quantum ESPRESSO's input.
"""
function asstring(data::AtomicPosition)
    config = FormatConfig(data)
    content = join(
        (
            config.indent,
            sprintf1("%3s", data.atom),
            map(x -> sprintf1(config.float, x), data.pos)...,
        ),
        config.delimiter,
    )
    if !all(data.if_pos)
        return join((content, map(Int, data.if_pos)...), config.delimiter)
    else
        return content
    end
end
"""
    asstring(card::AtomicPositionsCard)

Return a `String` representing a `AtomicPositionsCard`, valid for Quantum ESPRESSO's input.
"""
function asstring(card::AtomicPositionsCard)
    config = FormatConfig(card)
    join(
        ("ATOMIC_POSITIONS { $(optionof(card)) }", map(asstring, card.data)...),
        config.newline,
    )
end
"""
    asstring(card::CellParametersCard)

Return a `String` representing a `CellParametersCard`, valid for Quantum ESPRESSO's input.
"""
function asstring(card::CellParametersCard)
    config = FormatConfig(card)
    return join(
        (
            "CELL_PARAMETERS { $(optionof(card)) }",
            map(eachrow(card.data)) do row
                join((sprintf1(config.float, x) for x in row))
            end...,
        ),
        config.newline,
    )
end
"""
    asstring(data::MonkhorstPackGrid)

Return a `String` representing a `MonkhorstPackGrid`, valid for Quantum ESPRESSO's input.
"""
function asstring(data::MonkhorstPackGrid)
    config = FormatConfig(data)
    return config.indent * join(map([data.mesh; data.is_shift]) do x
        sprintf1(config.int, x)
    end, config.delimiter)
end
"""
    asstring(data::SpecialKPoint)

Return a `String` representing a `SpecialKPoint`, valid for Quantum ESPRESSO's input.
"""
function asstring(data::ReciprocalPoint)
    config = FormatConfig(data)
    return config.indent * join(
        map(x -> sprintf1(config.float, x), [data.coord..., data.weight]),
        config.delimiter,
    )
end
"""
    asstring(card::KPointsCard)

Return a `String` representing a `KPointsCard`, valid for Quantum ESPRESSO's input.
"""
function asstring(card::SpecialPointsCard)
    config = FormatConfig(card)
    content = "K_POINTS { $(optionof(card)) }" * config.newline
    return join((content, length(card.data), map(asstring, card.data)...), config.newline)
end
function asstring(card::GammaPointCard)
    config = FormatConfig(card)
    return "K_POINTS { $(optionof(card)) }" * config.newline
end
function asstring(card::KMeshCard)
    config = FormatConfig(card)
    content = "K_POINTS { $(optionof(card)) }" * config.newline
    return content * asstring(card.data)
end

function format_file(filename::AbstractString; overwrite::Bool = true, kwargs...)
    text = read(filename, String)
    formatted_text = format_text(text; kwargs...)
    if overwrite
        open(filename, "w") do io
            write(io, formatted_text)
        end
    else
        println(formatted_text)
    end
end

format_text(text::AbstractString) = asstring(parse(PWInput, text))

end


text:
include("../src/TSne.jl")
using MNIST
using Gadfly
using TSne

lables = ()

println("Using MNIST dataset.")
X, labels = traindata()
random_idxs = map(int, shuffle(linspace(1, size(X)[2], size(X)[2])))[1:6000]
X = X[:, random_idxs]'
labels = labels[random_idxs]
plotname = "mnist"
initial_dims = 50
iterations = 10000
perplexity = 30

println("X dimensions are: " * string(size(X)))
Y = tsne(X, 2, initial_dims, iterations, perplexity)
println("Y dimensions are: " * string(size(Y)))

theplot = plot(x=Y[:,1], y=Y[:,2], color=labels)

draw(PDF(plotname*".pdf", 4inch, 3inch), theplot)
draw(SVG(plotname*".svg", 4inch, 3inch), theplot)


text:
IMGUI_DEMO_CHECKBOX_STATES =
    Dict("basic_checkbox" => Checkboxes.State("checkbox"))


text:
# This file was generated by the Julia Swagger Code Generator
# Do not modify this file directly. Modify the swagger specification instead.

@doc raw"""NonResourceRule holds information that describes a rule for the non-resource

    IoK8sApiAuthorizationV1beta1NonResourceRule(;
        nonResourceURLs=nothing,
        verbs=nothing,
    )

    - nonResourceURLs::Vector{String} : NonResourceURLs is a set of partial urls that a user should have access to.  *s are allowed, but only as the full, final step in the path.  \"*\" means all.
    - verbs::Vector{String} : Verb is a list of kubernetes non-resource API verbs, like: get, post, put, delete, patch, head, options.  \"*\" means all.
"""
mutable struct IoK8sApiAuthorizationV1beta1NonResourceRule <: SwaggerModel
    nonResourceURLs::Any # spec type: Union{ Nothing, Vector{String} } # spec name: nonResourceURLs
    verbs::Any # spec type: Union{ Nothing, Vector{String} } # spec name: verbs

    function IoK8sApiAuthorizationV1beta1NonResourceRule(;nonResourceURLs=nothing, verbs=nothing)
        o = new()
        validate_property(IoK8sApiAuthorizationV1beta1NonResourceRule, Symbol("nonResourceURLs"), nonResourceURLs)
        setfield!(o, Symbol("nonResourceURLs"), nonResourceURLs)
        validate_property(IoK8sApiAuthorizationV1beta1NonResourceRule, Symbol("verbs"), verbs)
        setfield!(o, Symbol("verbs"), verbs)
        o
    end
end # type IoK8sApiAuthorizationV1beta1NonResourceRule

const _property_map_IoK8sApiAuthorizationV1beta1NonResourceRule = Dict{Symbol,Symbol}(Symbol("nonResourceURLs")=>Symbol("nonResourceURLs"), Symbol("verbs")=>Symbol("verbs"))
const _property_types_IoK8sApiAuthorizationV1beta1NonResourceRule = Dict{Symbol,String}(Symbol("nonResourceURLs")=>"Vector{String}", Symbol("verbs")=>"Vector{String}")
Base.propertynames(::Type{ IoK8sApiAuthorizationV1beta1NonResourceRule }) = collect(keys(_property_map_IoK8sApiAuthorizationV1beta1NonResourceRule))
Swagger.property_type(::Type{ IoK8sApiAuthorizationV1beta1NonResourceRule }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_IoK8sApiAuthorizationV1beta1NonResourceRule[name]))}
Swagger.field_name(::Type{ IoK8sApiAuthorizationV1beta1NonResourceRule }, property_name::Symbol) =  _property_map_IoK8sApiAuthorizationV1beta1NonResourceRule[property_name]

function check_required(o::IoK8sApiAuthorizationV1beta1NonResourceRule)
    (getproperty(o, Symbol("verbs")) === nothing) && (return false)
    true
end

function validate_property(::Type{ IoK8sApiAuthorizationV1beta1NonResourceRule }, name::Symbol, val)
end


text:
"""

    constructMolAlpha!(myMolData::OneMol_WithPhonons{FT},
                       myPeriodicData::PeriodicData{FT},
                       freq::Union{FT, Complex{FT}},
                       k::Array{FT, 1}=zeros(FT, 3)) where FT<:AbstractFloat

Construct the vector of atomic polarizabilities `myMolData.alpha0` based on the
susceptibility of the molecule in isolation. `myMolData.Ye0ee` will incorporate the
electronic contributions to the response, and `myMolData.Ye0II` will incorporate most
aspects of the nuclear contributions to the response, mainly of use as preconditioners when
computing vdW interactions.

"""
function constructMolAlpha!(myMolData::OneMol_WithPhonons{FT},
                            myPeriodicData::PeriodicData{FT},
                            freq::Union{FT, Complex{FT}},
                            k::Array{FT, 1}=zeros(FT, 3)) where FT<:AbstractFloat

    alphainv = zeros(Complex{FT}, 3*myMolData.numatoms, 3*myMolData.numatoms);
    Ke3N = vecNto3N(myMolData.Ke);
    Qeinv3N = vecNto3N(1 ./ myMolData.Qe);

    KIk!(myMolData, myPeriodicData, k);

    setindex!(alphainv, myMolData.KIBloch,
              1:3*myMolData.numatoms, 1:3*myMolData.numatoms);
    addtodiag!(alphainv,
               Ke3N .- vecNto3N(1im.*freq.*myMolData.BI .+ freq^2 .* myMolData.MI));
    setindex!(alphainv, inv(alphainv),
              1:3*myMolData.numatoms, 1:3*myMolData.numatoms);
    mulMatDiagright!(alphainv, Ke3N);
    mulMatDiagleft!(alphainv, Ke3N);
    subtractfromdiag!(alphainv,
                      Ke3N .- vecNto3N(1im.*freq.*myMolData.Be .+ freq^2 .* myMolData.Me));
    mulMatDiagright!(alphainv, Qeinv3N);
    mulMatDiagleft!(alphainv, Qeinv3N);
    alpha = inv(alphainv);
    alphacarttr = Array{eltype(alpha), 2}(undef, myMolData.numatoms, myMolData.numatoms);
    @inbounds for qq=1:myMolData.numatoms
        @inbounds for pp=1:myMolData.numatoms
            alphacarttr[pp, qq] = tr(alpha[3*pp-2:3*pp, 3*qq-2:3*qq]);
        end
    end

    setindex!(myMolData.alpha0, abs.(vec(sum(alphacarttr, dims=2))), 1:myMolData.numatoms);
    lmul!(1/3, myMolData.alpha0);
    setindex!(myMolData.Ye0ee,
              1 ./ (myMolData.Ke .-
                    (1im .* freq .* myMolData.Be .+ freq^2 .* myMolData.Me)),
              1:myMolData.numatoms);
    setindex!(myMolData.Ye0II,
              1 ./ (myMolData.Ke .-
                    (1im .* freq .* myMolData.BI .+ freq^2 .* myMolData.MI)),
              1:myMolData.numatoms);

end

## TO DELETE: constructMolAlpha!(myMolData::OneMol_NoPhonons{FT}, ...)
## because it no longer makes sense for phonon conduction (if phonons
## are to be ignored, use the usual RMB code)
"""

    constructMolAlpha!(myMolData::OneMol_NoPhonons{FT},
                       myPeriodicData::PeriodicData{FT},
                       freq::Union{FT, Complex{FT}},
                       k::Array{FT, 1}=zeros(FT, 3)) where FT<:AbstractFloat

Construct the inverse molecular susceptibility `myMolData.alphainv` in-place at frequency
`freq` and wavevector `k`, the latter of which must be a 3-element real vector. Without
phonons, `myMolData.alphainv` will be a vector, and the vectors `myMolData.alpha0` and
`myMolData.alphae` will be simply related to `myMolData.alphainv`.

"""
function constructMolAlpha!(myMolData::OneMol_NoPhonons{FT},
                            myPeriodicData::PeriodicData{FT},
                            freq::Union{FT, Complex{FT}},
                            k::Array{FT, 1}=zeros(FT, 3)) where FT<:AbstractFloat

    setindex!(myMolData.alphainv,
              (myMolData.Ke .- (1im.*freq.*myMolData.Be .+
                                freq^2 .* myMolData.Me))./(myMolData.Qe.^2),
              1:myMolData.numatoms);
    setindex!(myMolData.alphae, 1 ./ myMolData.alphainv, 1:myMolData.numatoms);
    setindex!(myMolData.alpha0, abs.(myMolData.alphae), 1:myMolData.numatoms);
    ## constructMolAlphaNoPhonons!(myMolData, myPeriodicData, freq, k)

end

"""

    KIk(myMolData::OneMol_WithPhonons{FT}, myPeriodicData::PeriodicData{FT},
        k::Array{FT, 1}=zeros(FT, 3)) where FT<:AbstractFloat

Construct the `k`-dependence of the internuclear spring constant matrix for the molecule in
isolation, and return the result. Return `myMolData.KI` if the geometry has no periodic
dimensions.

See also: [`constructMolAlpha!`](@ref).

"""
function KIk(myMolData::OneMol_WithPhonons{FT}, myPeriodicData::PeriodicData{FT},
             k::Array{FT, 1}=zeros(FT, 3)) where FT<:AbstractFloat

    if (myPeriodicData.numdims < 1)
        return complex(myMolData.KI);
    end
    if (length(k) != 3)
        error("KIk(): k must have length 3");
    end
    currKIk = zeros(Complex{FT}, 3*myMolData.numatoms, 3*myMolData.numatoms);
    currKIblock = zeros(Complex{FT}, 3*myMolData.numatoms, 3*myMolData.numatoms);
    for nn2=1:myMolData.numblocks2
        for nn1=1:myMolData.numblocks1
            currKIblock[:, :] .= myMolData.KI[3*(nn1-1)*myMolData.numatoms+1:3*nn1*myMolData.numatoms,
                      3*(nn2-1)*myMolData.numatoms+1:3*nn2*myMolData.numatoms];
            lmul!(exp(-1im*dot(k,
                               myMolData.blocklist1[nn1] .*
                               myPeriodicData.latticevecs[:, 1] .+
                               myMolData.blocklist2[nn2] .*
                               myPeriodicData.latticevecs[:, 2])),
                  currKIblock);
            hermpart!(currKIblock);
            currKIk[:, :] .+= currKIblock[:, :];
        end
    end
    hermpart!(currKIk);
    return currKIk;

end

"""

    KIk!(myMolData::OneMol_WithPhonons{FT}, myPeriodicData::PeriodicData{FT},
         k::Array{FT, 1}=zeros(FT, 3)) where FT<:AbstractFloat

Construct the `k`-dependence of the internuclear spring constant matrix for the molecule in
isolation from its real-space representation `myMolData.KI`, and store the result in
`myMolData.KIBloch`. The result will be the same as `myMolData.KI` if the molecule has no
periodic dimensions or couplings across unit cells.

See also: [`constructMolAlpha!`](@ref).

"""
function KIk!(myMolData::OneMol_WithPhonons{FT}, myPeriodicData::PeriodicData{FT},
              k::Array{FT, 1}=zeros(FT, 3)) where FT<:AbstractFloat

    fill!(myMolData.KIBloch, zero(eltype(myMolData.KIBloch)));
    if (myPeriodicData.numdims < 1)
        myMolData.KIBloch .= complex(myMolData.KI);
    else
        if (length(k) != 3)
            error("KIk(): k must have length 3");
        end
        currKIblock = zeros(Complex{FT}, 3*myMolData.numatoms, 3*myMolData.numatoms);
        for nn2=1:myMolData.numblocks2
            for nn1=1:myMolData.numblocks1
                currKIblock[:, :] .= myMolData.KI[3*(nn1-1)*myMolData.numatoms+1:3*nn1*myMolData.numatoms,
                                                  3*(nn2-1)*myMolData.numatoms+1:3*nn2*myMolData.numatoms];
                lmul!(exp(-1im*dot(k,
                                   myMolData.blocklist1[nn1] .*
                                   myPeriodicData.latticevecs[:, 1] .+
                                   myMolData.blocklist2[nn2] .*
                                   myPeriodicData.latticevecs[:, 2])),
                      currKIblock);
                hermpart!(currKIblock);
                myMolData.KIBloch[:, :] .+= currKIblock[:, :];
            end
        end
    end
    hermpart!(myMolData.KIBloch);
end


text:
using Zygote
using ForwardDiff
using DiffRules
using SpecialFunctions
using NaNMath
using Zygote: @adjoint

ForwardDiff.can_dual(::Type{XRTArray{T,(),0}} where T) = true
Zygote.isscalar(::XRTArray{<:Any,(),0}) = true

Zygote.fill_similar_array(x::XRTArray{T, dims, N}, v::XRTScalar) where {T, dims, N} =
    HloBroadcast((), dims)(v)
Zygote.fill_similar_array(x::XRTArray{T, dims, N}, v::XLAScalar) where {T, dims, N} =
    Zygote.fill_similar_array(x, convert(XRTArray{T, (), 0}, v))

sum_adjoint(xs::XRTArray, dims::Colon) = sum(xs), Δ->(Zygote.fill_similar_array(xs, Δ),)
@Base.pure function compute_sum_adj_dims(sz, dim)
    a = Int[]
    b = Int[]
    for i = 0:length(sz)-1
        if i + 1 == dim
            # omit it from both
        else
            push!(a, sz[i + 1])
            push!(b, i)
        end
    end
    tuple(a...), tuple(b...)
end
function sum_adjoint(xs::XRTArray{<:Any, rt_dims}, dim::Int) where rt_dims
    sum(xs, dims=dim), let vdim=Val(dim)
        Δ -> begin
            dims_dropped, all_but_dim = compute_sum_adj_dims(size(Δ), unval(vdim))
            (HloBroadcast(all_but_dim, rt_dims)(HloReshape(dims_dropped)(Δ)),)
        end
    end
end

@adjoint function sum(xs::XRTArray; dims = :)
  sum_adjoint(xs, dims)
end

using Base.Broadcast
using Base.Broadcast: Broadcasted, materialize
function Zygote.broadcast_gradient(bc::Broadcasted{S}, ::Type{T}) where {S <: XLA.XLA.XRTArrayStyle, T}
    # XLA doesn't currently have multi-output kMap
    dest = let f = bc.f
        materialize(Broadcasted{S}((args...)->f(args...).value, bc.args, bc.axes))
    end
    grads = ntuple(length(bc.args)) do i
        let f = bc.f
            materialize(Broadcasted{S}((args...)->f(args...).partials.values[i], bc.args, bc.axes))
        end
    end
    dest, grads
end

for (M, f, arity) in DiffRules.diffrules()
  arity == 1 || continue
  @eval begin
    @adjoint $M.$f(x::XRTScalar) = $M.$f(x),
      Δ -> (Δ * $(DiffRules.diffrule(M, f, :x)),)
  end
end

for (M, f, arity) in DiffRules.diffrules()
  arity == 2 || continue
  da, db = DiffRules.diffrule(M, f, :a, :b)
  @eval begin
    @adjoint $M.$f(a::XRTScalar, b::XRTScalar) = $M.$f(a, b),
      Δ -> (Δ * $da, Δ * $db)
    @adjoint $M.$f(a::Number, b::XRTScalar) = $M.$f(a, b),
      Δ -> (Δ * $da, Δ * $db)
    @adjoint $M.$f(a::XRTScalar, b::Number) = $M.$f(a, b),
      Δ -> (Δ * $da, Δ * $db)
  end
end

@adjoint XRTArray(a::Real) = XRTArray(a), Δ -> (Δ,)

# This is necessary, because even XRT scalars are AbstractArrays
Zygote.accum(a::XRTArray, b::XRTArray) = a+b

@adjoint function execute(args...)
    error("Zygote should not reach the HLO layer. Please define gradients for functions higher up.")
end

struct getindex_back{T, Ti}
    i::Ti
end

function (gb::getindex_back{T, Ti})(Δ) where {T, Ti}
    Δ′ = zero(T)
    Δ′ = Base.setindex(Δ′, Δ, gb.i...)
    (Δ′, ntuple(_->nothing, Val(length(Ti.parameters)))...)
end

@adjoint function getindex(xs::XRTArray, i...)
    xs[i...], getindex_back{typeof(xs), typeof(i)}(i)
end

@Base.pure function make_repeat_adjoint_window(folded_sz, dims_mapping)
    window = ntuple(length(folded_sz)) do i
        if (i - 1) in dims_mapping
            WindowDims(1, 1, 0, 0, 1, 1, false)
        else
            WindowDims(folded_sz[i], 1, 0, 0, 1, 1, false)
        end
    end
end

unval(v::Val{x}) where {x} = x

@adjoint function Base.repeat(A::XRTArray, dims::Integer...)
    repeat(A, dims...), let Asz=Val(size(A)), vdims=Val(dims)
        function (Δ)
            sz_A = unval(Asz)
            ddims = unval(vdims)
            dims_mapping, result_szs, final_sz = make_repeat_dims(sz_A, ddims)
            folded_back = XLA.HloReshape(result_szs)(Δ)
            summed = HloReduceWindow{typeof(+)}(
                make_repeat_adjoint_window(result_szs, dims_mapping)
            )(+, folded_back, XRTArray(zero(eltype(Δ))))
            (HloReshape(sz_A)(summed), ntuple(_->nothing, length(ddims))...)
        end
    end
end

@Zygote.nograd count_summands