text:
import Base: <, ≤

function <(N::T, n::NT) where {T <: QuantitativeNetwork, NT <: Number}
   ReturnType = T <: AbstractBipartiteNetwork ? BipartiteNetwork : UnipartiteNetwork
   return ReturnType(N.A .< n, species_objects(N)...)
end

function <(N::T, n::NT) where {T <: ProbabilisticNetwork, NT <: AbstractFloat}
   ReturnType = T <: AbstractBipartiteNetwork ? BipartiteNetwork : UnipartiteNetwork
   return ReturnType(N.A .< n, species_objects(N)...)
end

function <(n::NT, N::T) where {T <: QuantitativeNetwork, NT <: Number}
   ReturnType = T <: AbstractBipartiteNetwork ? BipartiteNetwork : UnipartiteNetwork
   return ReturnType(n .< N.A, species_objects(N)...)
end

function <(n::NT, N::T) where {T <: ProbabilisticNetwork, NT <: AbstractFloat}
   ReturnType = T <: AbstractBipartiteNetwork ? BipartiteNetwork : UnipartiteNetwork
   return ReturnType(n .< N.A, species_objects(N)...)
end

function ≤(N::T, n::NT) where {T <: QuantitativeNetwork, NT <: Number}
   ReturnType = T <: AbstractBipartiteNetwork ? BipartiteNetwork : UnipartiteNetwork
   return ReturnType(N.A .≤ n, species_objects(N)...)
end

function ≤(N::T, n::NT) where {T <: ProbabilisticNetwork, NT <: AbstractFloat}
   ReturnType = T <: AbstractBipartiteNetwork ? BipartiteNetwork : UnipartiteNetwork
   return ReturnType(N.A .≤ n, species_objects(N)...)
end

function ≤(n::NT, N::T) where {T <: QuantitativeNetwork, NT <: Number}
   ReturnType = T <: AbstractBipartiteNetwork ? BipartiteNetwork : UnipartiteNetwork
   return ReturnType(n .≤ N.A, species_objects(N)...)
end

function ≤(n::NT, N::T) where {T <: ProbabilisticNetwork, NT <: AbstractFloat}
   ReturnType = T <: AbstractBipartiteNetwork ? BipartiteNetwork : UnipartiteNetwork
   return ReturnType(n .≤ N.A, species_objects(N)...)
end


text:
using NamespacedEnums
using Test

@testset "NamespacedEnums.jl" begin
    @eval begin
        @nsenum A a b c
        @test A isa Module
        @test :T in names(A; all=true)
        @test A.T <: Enum
        for v in (:a, :b, :c)
            @test getfield(A, v) isa A.T
        end

        @nsenum T=Name B a=1 b=2 c=3
        @test !(:T in names(B; all=true))
        @test :Name in names(B; all=true)
        @test B.Name <: Enum
        @test Int(B.a) == 1

        @nsenum C::UInt8 begin
            a
            b
            c
        end
        @test C.T <: Enum{UInt8}
        @test :a in names(C; all=true)
    end
end

ext: jl


text:
macro register(dist)
    return quote
        DistributionsAD.eval(getexpr($(esc(dist))))
        DistributionsAD.toflatten(::$(esc(dist))) = true
    end
end
function getexpr(Tdist)
    x = gensym()
    fnames = fieldnames(Tdist)
    flattened_args = Expr(:tuple, [:(dist.$f) for f in fnames]...)
    func = Expr(:->,
                Expr(:tuple, fnames..., x),
                Expr(:block,
                    Expr(:call, :logpdf,
                        Expr(:call, :($Tdist), fnames...),
                        x,
                    )
                )
            )
    return :(flatten(dist::$Tdist) = ($func, $flattened_args))
end
const flattened_dists = [   Bernoulli,
                            BetaBinomial,
                            Binomial,
                            Geometric,
                            NegativeBinomial,
                            Poisson,
                            Skellam,
                            Arcsine,
                            Beta,
                            BetaPrime,
                            Biweight,
                            Cauchy,
                            Chernoff,
                            Chi,
                            Chisq,
                            Cosine,
                            Epanechnikov,
                            Erlang,
                            Exponential,
                            FDist,
                            Frechet,
                            Gamma,
                            GeneralizedExtremeValue,
                            GeneralizedPareto,
                            Gumbel,
                            #InverseGamma,
                            InverseGaussian,
                            Kolmogorov,
                            Laplace,
                            Levy,
                            LocationScale,
                            Logistic,
                            LogitNormal,
                            LogNormal,
                            Normal,
                            #NormalCanon,
                            #NormalInverseGaussian,
                            Pareto,
                            PGeneralizedGaussian,
                            Rayleigh,
                            SymTriangularDist,
                            TDist,
                            TriangularDist,
                            Triweight,
                            TuringUniform,
                            #Truncated,
                            #VonMises,
                        ]
for T in flattened_dists
    @eval toflatten(::$T) = true
end
toflatten(::Distribution) = false
for T in flattened_dists
    eval(getexpr(T))
end


text:
module TestWithSequential

using Adapt
using CUDA
using CUDAKernels

include("../with_sequential.jl")

upload(x) = adapt(CuArray, x)
test_with_sequential(tests, get_executors(CUDADevice()); upload = upload)

end


text:
using Test
using BetweenFlags

@testset "Flag pair" begin
    flag1 = StartFlag("flag1")
    flag2 = StopFlag("flag2")
    flag_set = FlagPair{GreedyType}(
        flag1,
        flag2,
    )
    @test flag_set.start == flag1
    @test flag_set.stop  == flag2
    @test flag_set.ID == "flag1-flag2"
end


text:
using JuMP, EAGO

                     m = Model()

                     EAGO.register_eago_operators!(m)

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

                     @variable(m, -6.103907844236108 <= q <= 8.378675476959124)

                     add_NL_constraint(m, :(log(1 + exp(-0.8297607126794757 + -0.5064858067335005*log(1 + exp(-0.6188655598844357 + -0.38627203797486676*$(x[1]) + 0.4878933200630442*$(x[2]))) + -0.8619658571743893*log(1 + exp(-0.7914291135758744 + 0.8682104207735972*$(x[1]) + 0.3684602934879275*$(x[2]))) + 0.8415580445654567*log(1 + exp(-0.26405078449033637 + -0.6452849815457378*$(x[1]) + 0.9586530591287103*$(x[2]))))) + log(1 + exp(-0.0809505831099564 + 0.6185835236357913*log(1 + exp(-0.6188655598844357 + -0.38627203797486676*$(x[1]) + 0.4878933200630442*$(x[2]))) + -0.5288114683363174*log(1 + exp(-0.7914291135758744 + 0.8682104207735972*$(x[1]) + 0.3684602934879275*$(x[2]))) + -0.42070009030061817*log(1 + exp(-0.26405078449033637 + -0.6452849815457378*$(x[1]) + 0.9586530591287103*$(x[2]))))) + log(1 + exp(0.16011867292674786 + -0.14898607305663658*log(1 + exp(-0.6188655598844357 + -0.38627203797486676*$(x[1]) + 0.4878933200630442*$(x[2]))) + -0.8220978033005912*log(1 + exp(-0.7914291135758744 + 0.8682104207735972*$(x[1]) + 0.3684602934879275*$(x[2]))) + -0.8518875556726564*log(1 + exp(-0.26405078449033637 + -0.6452849815457378*$(x[1]) + 0.9586530591287103*$(x[2]))))) - $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:
using Mjolnir, Test

@testset "Mjolnir" begin

@testset "Trace" begin
  include("trace.jl")
end

end


text:
using HSA
include("helpers.jl")
using FactCheck

facts("A Signal") do
    @use rt = HSA.Runtime() begin

        context("can be created") do
            s = HSA.Signal()
            s2 = HSA.Signal(value = 2)

            @fact s.is_alive --> true
            @fact s.handle --> not(nothing)
            @fact get(s) --> 0
            @fact get(s2) --> 2
        end

        context("are deduplicated in the constructor") do
            s = HSA.Signal()
            s_ame = HSA.Signal(s.handle)

            @fact s --> s_ame
        end

        agents = HSA.all_agents()
        @with_agents context("can be created with specific consumer agents") do
            a = agents[1]

            s3 = HSA.Signal(consumers = [a])

            @fact length(s3.consumers) --> 1
            @fact in(a, s3.consumers) --> true
        end

        context("can be destroyed") do
            s = HSA.Signal()

            finalize(s)

            @fact s.is_alive --> false
        end

        context("can wrap doorbell signals") do
            fake_handle = HSA.hsa_signal_t(10101)
            s = HSA.Signal(fake_handle)

            # does not destroy the signal upon being finalized
            finalize(s)
        end

        context("can be manipulated") do
            s = HSA.Signal(value = 2)

            @fact HSA.load(s) --> 2
            @fact HSA.load(s, Val{Acquire}) --> 2
            @fact HSA.load(s, Val{Relaxed}) --> 2

            HSA.store!(s, 3)
            @fact HSA.load(s) --> 3

            HSA.store!(s, 4, Val{Relaxed})
            @fact HSA.load(s) --> 4
            #TODO s := 5
            @pending HSA.load(s) --> 5

            @fact HSA.exchange!(s, 6) --> 4
            @fact HSA.load(s) --> 6
            @fact HSA.exchange!(s, 7, Val{Relaxed}) --> 6
            @fact HSA.load(s) --> 7
            @fact HSA.exchange!(s, 8, Val{Release}) --> 7
            @fact HSA.load(s) --> 8

            #TODO CAS

            HSA.store!(s, 100)
            HSA.add!(s, 1)
            @fact HSA.load(s) --> 101
            HSA.add!(s, 1, Val{Release})
            @fact HSA.load(s) --> 102
            #TODO s += 1
            @pending HSA.load(s) --> 103
        end

        context("can be waited on") do
        s = HSA.Signal(value = 2)

        @fact wait(s, :(==), 2) --> 2
        @fact wait(s, :<, 3; timeout_hint = 10) --> 2
        @fact wait(s, :(!=), 3) --> 2
        @fact wait(s, :(>=), 2) --> 2
        end

        context("can be waited on with a timeout") do
            s = HSA.Signal(value = 2)

            @fact wait(s, :(==), 3; timeout_hint = 1) --> 2
        end

    end
end


text:
using CUDA
using Printf
using Base.Ryu: writeshortest

#####
##### Convenience functions
#####

Base.length(::Type{Face}, topo, N) = N
Base.length(::Type{Face}, ::Type{Bounded}, N) = N+1
Base.length(::Type{Center}, topo, N) = N
Base.length(::Type{Nothing}, topo, N) = 1

Base.length(::Type{Nothing}, ::Type{Flat}, N) = N
Base.length(::Type{Face},    ::Type{Flat}, N) = N
Base.length(::Type{Center},  ::Type{Flat}, N) = N

"""
    topology(grid)

Return a tuple with the topology of the `grid` for each dimension.
"""
@inline topology(::AbstractGrid{FT, TX, TY, TZ}) where {FT, TX, TY, TZ} = (TX, TY, TZ)

"""
    topology(grid, dim)

Return the topology of the `grid` for the `dim`-th dimension.
"""
@inline topology(grid, dim) = topology(grid)[dim]

"""
    architecture(grid::AbstractGrid)

Return the architecture (CPU or GPU) that the `grid` lives on.
"""
@inline architecture(grid::AbstractGrid) = grid.architecture

"""
    Constant Grid Definitions
"""

Base.eltype(::AbstractGrid{FT}) where FT = FT

function Base.:(==)(grid1::AbstractGrid, grid2::AbstractGrid)
    #check if grids are of the same type
    !isa(grid2, typeof(grid1).name.wrapper) && return false

    topology(grid1) !== topology(grid2) && return false

    x1, y1, z1 = nodes((Face, Face, Face), grid1)
    x2, y2, z2 = nodes((Face, Face, Face), grid2)

    CUDA.@allowscalar return x1 == x2 && y1 == y2 && z1 == z2
end

"""
    size(loc, grid)

Return the size of a `grid` at `loc`, not including halos.
This is a 3-tuple of integers corresponding to the number of interior nodes
along `x, y, z`.
"""
@inline Base.size(loc, grid::AbstractGrid) = (length(loc[1], topology(grid, 1), grid.Nx),
                                              length(loc[2], topology(grid, 2), grid.Ny),
                                              length(loc[3], topology(grid, 3), grid.Nz))

Base.size(grid::AbstractGrid) = size((Center, Center, Center), grid)
Base.size(grid::AbstractGrid, d) = size(grid)[d]
Base.size(loc, grid, d) = size(loc, grid)[d]

total_size(a) = size(a) # fallback

"""
    total_size(loc, grid)

Return the "total" size of a `grid` at `loc`. This is a 3-tuple of integers
corresponding to the number of grid points along `x, y, z`.
"""
@inline total_size(loc, grid) = (total_length(loc[1], topology(grid, 1), grid.Nx, grid.Hx),
                                 total_length(loc[2], topology(grid, 2), grid.Ny, grid.Hy),
                                 total_length(loc[3], topology(grid, 3), grid.Nz, grid.Hz))

"""
    halo_size(grid)

Return a tuple with the size of the halo in each dimension.
"""
halo_size(grid) = (grid.Hx, grid.Hy, grid.Hz)

"""
    total_extent(topology, H, Δ, L)

Return the total extent, including halo regions, of constant-spaced
`Periodic` and `Flat` dimensions with number of halo points `H`,
constant grid spacing `Δ`, and interior extent `L`.
"""
@inline total_extent(topology, H, Δ, L) = L + (2H - 1) * Δ
@inline total_extent(::Type{Bounded}, H, Δ, L) = L + 2H * Δ

"""
    total_length(loc, topo, N, H=0)

Return the total length of a field at `loc`ation along
one dimension of `topo`logy with `N` centered cells and
`H` halo cells.
"""
@inline total_length(loc,             topo,            N, H=0) = N + 2H
@inline total_length(::Type{Face},    ::Type{Bounded}, N, H=0) = N + 1 + 2H
@inline total_length(::Type{Nothing}, topo,            N, H=0) = 1
@inline total_length(::Type{Nothing}, ::Type{Flat},    N, H=0) = N
@inline total_length(::Type{Face},    ::Type{Flat},    N, H=0) = N
@inline total_length(::Type{Center},  ::Type{Flat},    N, H=0) = N

# Grid domains
@inline domain(topo, N, ξ) = CUDA.@allowscalar ξ[1], ξ[N+1]
@inline domain(::Type{Flat}, N, ξ) = CUDA.@allowscalar ξ[1], ξ[1]

@inline x_domain(grid) = domain(topology(grid, 1), grid.Nx, grid.xᶠᵃᵃ)
@inline y_domain(grid) = domain(topology(grid, 2), grid.Ny, grid.yᵃᶠᵃ)
@inline z_domain(grid) = domain(topology(grid, 3), grid.Nz, grid.zᵃᵃᶠ)

regular_dimensions(grid) = ()

#####
##### << Indexing >>
#####

@inline left_halo_indices(loc, topo, N, H) = 1-H:0
@inline left_halo_indices(::Type{Nothing}, topo, N, H) = 1:0 # empty

@inline right_halo_indices(loc, topo, N, H) = N+1:N+H
@inline right_halo_indices(::Type{Face}, ::Type{Bounded}, N, H) = N+2:N+1+H
@inline right_halo_indices(::Type{Nothing}, topo, N, H) = 1:0 # empty

@inline underlying_left_halo_indices(loc, topo, N, H) = 1:H
@inline underlying_left_halo_indices(::Type{Nothing}, topo, N, H) = 1:0 # empty

@inline underlying_right_halo_indices(loc, topo, N, H) = N+1+H:N+2H
@inline underlying_right_halo_indices(::Type{Face}, ::Type{Bounded}, N, H) = N+2+H:N+1+2H
@inline underlying_right_halo_indices(::Type{Nothing}, topo, N, H) = 1:0 # empty

@inline interior_indices(loc,             topo,            N) = 1:N
@inline interior_indices(::Type{Face},    ::Type{Bounded}, N) = 1:N+1
@inline interior_indices(::Type{Nothing}, topo,            N) = 1:1

@inline interior_indices(::Type{Nothing}, topo::Type{Flat}, N) = 1:N
@inline interior_indices(::Type{Face},    topo::Type{Flat}, N) = 1:N
@inline interior_indices(::Type{Center},  topo::Type{Flat}, N) = 1:N

@inline interior_x_indices(loc, grid) = interior_indices(loc, topology(grid, 1), grid.Nx)
@inline interior_y_indices(loc, grid) = interior_indices(loc, topology(grid, 2), grid.Ny)
@inline interior_z_indices(loc, grid) = interior_indices(loc, topology(grid, 3), grid.Nz)

@inline interior_parent_indices(loc,             topo,            N, H) = 1+H:N+H
@inline interior_parent_indices(::Type{Face},    ::Type{Bounded}, N, H) = 1+H:N+1+H
@inline interior_parent_indices(::Type{Nothing}, topo,            N, H) = 1:1

@inline interior_parent_indices(::Type{Nothing}, topo::Type{Flat}, N, H) = 1:N
@inline interior_parent_indices(::Type{Face},    topo::Type{Flat}, N, H) = 1:N
@inline interior_parent_indices(::Type{Center},  topo::Type{Flat}, N, H) = 1:N

# All indices including halos.
@inline all_indices(loc,             topo,            N, H) = 1-H:N+H
@inline all_indices(::Type{Face},    ::Type{Bounded}, N, H) = 1-H:N+1+H
@inline all_indices(::Type{Nothing}, topo,            N, H) = 1:1

@inline all_indices(::Type{Nothing}, ::Type{Flat}, N, H) = 1:N
@inline all_indices(::Type{Face},    ::Type{Flat}, N, H) = 1:N
@inline all_indices(::Type{Center},  ::Type{Flat}, N, H) = 1:N

@inline all_x_indices(loc, grid) = all_indices(loc, topology(grid, 1), grid.Nx, grid.Hx)
@inline all_y_indices(loc, grid) = all_indices(loc, topology(grid, 2), grid.Ny, grid.Hy)
@inline all_z_indices(loc, grid) = all_indices(loc, topology(grid, 3), grid.Nz, grid.Hz)

@inline all_parent_indices(loc,             topo,            N, H) = 1:N+2H
@inline all_parent_indices(::Type{Face},    ::Type{Bounded}, N, H) = 1:N+1+2H
@inline all_parent_indices(::Type{Nothing}, topo,            N, H) = 1:1

@inline all_parent_indices(::Type{Nothing}, ::Type{Flat}, N, H) = 1:N
@inline all_parent_indices(::Type{Face},    ::Type{Flat}, N, H) = 1:N
@inline all_parent_indices(::Type{Center},  ::Type{Flat}, N, H) = 1:N

@inline all_parent_x_indices(loc, grid) = all_parent_indices(loc, topology(grid, 1), grid.Nx, grid.Hx)
@inline all_parent_y_indices(loc, grid) = all_parent_indices(loc, topology(grid, 2), grid.Ny, grid.Hy)
@inline all_parent_z_indices(loc, grid) = all_parent_indices(loc, topology(grid, 3), grid.Nz, grid.Hz)

#####
##### << Nodes >>
#####

# Fallback
@inline xnode(LX, LY, LZ, i, j, k, grid) = xnode(LX, i, grid)
@inline ynode(LX, LY, LZ, i, j, k, grid) = ynode(LY, j, grid)
@inline znode(LX, LY, LZ, i, j, k, grid) = znode(LZ, k, grid)

@inline node(LX, LY, LZ, i, j, k, grid) = (xnode(LX, LY, LZ, i, j, k, grid),
                                           ynode(LX, LY, LZ, i, j, k, grid),
                                           znode(LX, LY, LZ, i, j, k, grid))

@inline node(LX::Nothing, LY, LZ, i, j, k, grid) = (ynode(LX, LY, LZ, i, j, k, grid), znode(LX, LY, LZ, i, j, k, grid))
@inline node(LX, LY::Nothing, LZ, i, j, k, grid) = (xnode(LX, LY, LZ, i, j, k, grid), znode(LX, LY, LZ, i, j, k, grid))
@inline node(LX, LY, LZ::Nothing, i, j, k, grid) = (xnode(LX, LY, LZ, i, j, k, grid), ynode(LX, LY, LZ, i, j, k, grid))

@inline node(LX, LY::Nothing, LZ::Nothing, i, j, k, grid) = tuple(xnode(LX, LY, LZ, i, j, k, grid))
@inline node(LX::Nothing, LY, LZ::Nothing, i, j, k, grid) = tuple(ynode(LX, LY, LZ, i, j, k, grid))
@inline node(LX::Nothing, LY::Nothing, LZ, i, j, k, grid) = tuple(znode(LX, LY, LZ, i, j, k, grid))

@inline cpu_face_constructor_x(grid) = all_x_nodes(Face, adapt(CPU(), grid))[1:grid.Nx+1]
@inline cpu_face_constructor_y(grid) = all_y_nodes(Face, adapt(CPU(), grid))[1:grid.Ny+1]
@inline cpu_face_constructor_z(grid) = all_z_nodes(Face, adapt(CPU(), grid))[1:grid.Nz+1]

all_x_nodes(::Type{Nothing}, grid) = 1:1
all_y_nodes(::Type{Nothing}, grid) = 1:1
all_z_nodes(::Type{Nothing}, grid) = 1:1

"""
    xnodes(loc, grid, reshape=false)

Return a view over the interior `loc=Center` or `loc=Face` nodes
on `grid` in the x-direction. For `Bounded` directions,
`Face` nodes include the boundary points. `reshape=false` will
return a 1D array while `reshape=true` will return a 3D array
with size Nx×1×1.

See `znodes` for examples.
"""
function xnodes(loc, grid; reshape=false)

    x = view(all_x_nodes(loc, grid),
             interior_indices(loc, topology(grid, 1), grid.Nx))

    return reshape ? Base.reshape(x, length(x), 1, 1) : x
end

"""
    ynodes(loc, grid, reshape=false)

Return a view over the interior `loc=Center` or `loc=Face` nodes
on `grid` in the y-direction. For `Bounded` directions,
`Face` nodes include the boundary points. `reshape=false` will
return a 1D array while `reshape=true` will return a 3D array
with size 1×Ny×1.

See [`znodes`](@ref) for examples.
"""
function ynodes(loc, grid; reshape=false)

    y = view(all_y_nodes(loc, grid),
             interior_indices(loc, topology(grid, 2), grid.Ny))

    return reshape ? Base.reshape(y, 1, length(y), 1) : y
end

"""
    znodes(loc, grid, reshape=false)

Return a view over the interior `loc=Center` or `loc=Face` nodes
on `grid` in the z-direction. For `Bounded` directions,
`Face` nodes include the boundary points. `reshape=false` will
return a 1D array while `reshape=true` will return a 3D array
with size 1×1×Nz.

Examples
========

```jldoctest znodes
julia> using Oceananigans

julia> horz_periodic_grid = RectilinearGrid(size=(3, 3, 3), extent=(2π, 2π, 1),
                                                 topology=(Periodic, Periodic, Bounded));

julia> zC = znodes(Center, horz_periodic_grid)
3-element view(OffsetArray(::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, 0:4), 1:3) with eltype Float64:
 -0.8333333333333331
 -0.4999999999999999
 -0.16666666666666652
```

``` jldoctest znodes
julia> zF = znodes(Face, horz_periodic_grid)
4-element view(OffsetArray(::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, 0:5), 1:4) with eltype Float64:
 -1.0
 -0.6666666666666666
 -0.33333333333333337
 -4.44089209850063e-17
```
"""
function znodes(loc, grid; reshape=false)

    z = view(all_z_nodes(loc, grid),
             interior_indices(loc, topology(grid, 3), grid.Nz))

    return reshape ? Base.reshape(z, 1, 1, length(z)) : z
end

"""
    nodes(loc, grid; reshape=false)

Return a 3-tuple of views over the interior nodes
at the locations in `loc` in `x, y, z`.

If `reshape=true`, the views are reshaped to 3D arrays
with non-singleton dimensions 1, 2, 3 for `x, y, z`, respectively.
These reshaped arrays can then be used in broadcast operations with 3D fields
or arrays.

See [`xnodes`](@ref), [`ynodes`](@ref), and [`znodes`](@ref).
"""
function nodes(loc, grid::AbstractGrid; reshape=false)
    if reshape
        x, y, z = nodes(loc, grid; reshape=false)

        N = (length(x), length(y), length(z))

        x = Base.reshape(x, N[1], 1, 1)
        y = Base.reshape(y, 1, N[2], 1)
        z = Base.reshape(z, 1, 1, N[3])

        return (x, y, z)
    else
        return (xnodes(loc[1], grid),
                ynodes(loc[2], grid),
                znodes(loc[3], grid))
    end
end

#####
##### Convenience functions
#####

unpack_grid(grid) = grid.Nx, grid.Ny, grid.Nz, grid.Lx, grid.Ly, grid.Lz

flatten_halo(TX, TY, TZ, halo) = Tuple(T === Flat ? 0 : halo[i] for (i, T) in enumerate((TX, TY, TZ)))
flatten_size(TX, TY, TZ, halo) = Tuple(T === Flat ? 0 : halo[i] for (i, T) in enumerate((TX, TY, TZ)))

"""
    pop_flat_elements(tup, topo)

Return a new tuple that contains the elements of `tup`,
except for those elements corresponding to the `Flat` directions
in `topo`.
"""
function pop_flat_elements(tup, topo)
    new_tup = []
    for i = 1:3
        topo[i] != Flat && push!(new_tup, tup[i])
    end
    return Tuple(new_tup)
end

#####
##### Directions (for tilted domains)
#####

struct ZDirection end

#####
##### Show utils
#####

size_summary(sz) = string(sz[1], "×", sz[2], "×", sz[3])
scalar_summary(σ) = writeshortest(σ, false, false, true, -1, UInt8('e'), false, UInt8('.'), false, true)
dimension_summary(topo::Flat, name, args...) = "Flat $name"

function domain_summary(topo, name, left, right)
    interval = topo isa Periodic ? ")" : "]"
    topo_string = topo isa Periodic ? "Periodic " :
                                      "Bounded  "

    prefix = string(topo_string, name, " ∈ [",
                    scalar_summary(left), ", ",
                    scalar_summary(right), interval)
end

function dimension_summary(topo, name, left, right, spacing, pad_domain=0)
    prefix = domain_summary(topo, name, left, right)
    padding = " "^(pad_domain+1)
    return string(prefix, padding, coordinate_summary(spacing, name))
end

coordinate_summary(Δ::Number, name) = @sprintf("regularly spaced with Δ%s=%s", name, scalar_summary(Δ))
coordinate_summary(Δ::AbstractVector, name) = @sprintf("variably spaced with min(Δ%s)=%s, max(Δ%s)=%s",
                                                       name, scalar_summary(minimum(parent(Δ))),
                                                       name, scalar_summary(maximum(parent(Δ))))


text:
function H!(ˍ₋out, ˍ₋arg1, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4, ˍ₋arg5, ˍ₋arg6, ˍ₋arg7; )
    let c_p = @inbounds(ˍ₋arg1[1]), q_p = @inbounds(ˍ₋arg1[2]), i_p = @inbounds(ˍ₋arg1[3]), c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), c_ss = @inbounds(ˍ₋arg3[1]), q_ss = @inbounds(ˍ₋arg3[2]), i_ss = @inbounds(ˍ₋arg3[3]), k_p = @inbounds(ˍ₋arg4[1]), z_p = @inbounds(ˍ₋arg4[2]), k = @inbounds(ˍ₋arg5[1]), z = @inbounds(ˍ₋arg5[2]), k_ss = @inbounds(ˍ₋arg6[1]), z_ss = @inbounds(ˍ₋arg6[2]), α = @inbounds(ˍ₋arg7[1]), β = @inbounds(ˍ₋arg7[2]), ρ = @inbounds(ˍ₋arg7[3]), δ = @inbounds(ˍ₋arg7[4]), σ = @inbounds(ˍ₋arg7[5]), Ω_1 = @inbounds(ˍ₋arg7[6])
        @inbounds begin
                ˍ₋out[1] = (+)((/)(1, c), (/)((*)(-1, β, (+)(1, (*)(-1, δ), (*)(α, (^)(k_p, (+)(-1, α)), (exp)(z_p)))), c_p))
                ˍ₋out[2] = (+)(c, k_p, (*)(-1, q), (*)(-1, k, (+)(1, (*)(-1, δ))))
                ˍ₋out[3] = (+)(q, (*)(-1, (^)(k, α), (exp)(z)))
                ˍ₋out[4] = (+)(z_p, (*)(-1, z, ρ))
                ˍ₋out[5] = (+)(i, (*)(-1, k_p), (*)(k, (+)(1, (*)(-1, δ))))
                nothing
            end
    end
end

function H_yp!(ˍ₋out, ˍ₋arg1, ˍ₋arg2, ˍ₋arg3; )
    let c = @inbounds(ˍ₋arg1[1]), q = @inbounds(ˍ₋arg1[2]), i = @inbounds(ˍ₋arg1[3]), k = @inbounds(ˍ₋arg2[1]), z = @inbounds(ˍ₋arg2[2]), α = @inbounds(ˍ₋arg3[1]), β = @inbounds(ˍ₋arg3[2]), ρ = @inbounds(ˍ₋arg3[3]), δ = @inbounds(ˍ₋arg3[4]), σ = @inbounds(ˍ₋arg3[5]), Ω_1 = @inbounds(ˍ₋arg3[6])
        @inbounds begin
                ˍ₋out[1] = (*)(-1, (/)((*)(-1, β, (+)(1, (*)(-1, δ), (*)(α, (^)(k, (+)(-1, α)), (exp)(z)))), (^)(c, 2)))
                nothing
            end
    end
end

function H_y!(ˍ₋out, ˍ₋arg1, ˍ₋arg2, ˍ₋arg3; )
    let c = @inbounds(ˍ₋arg1[1]), q = @inbounds(ˍ₋arg1[2]), i = @inbounds(ˍ₋arg1[3]), k = @inbounds(ˍ₋arg2[1]), z = @inbounds(ˍ₋arg2[2]), α = @inbounds(ˍ₋arg3[1]), β = @inbounds(ˍ₋arg3[2]), ρ = @inbounds(ˍ₋arg3[3]), δ = @inbounds(ˍ₋arg3[4]), σ = @inbounds(ˍ₋arg3[5]), Ω_1 = @inbounds(ˍ₋arg3[6])
        @inbounds begin
                ˍ₋out[1] = (*)(-1, (/)(1, (^)(c, 2)))
                ˍ₋out[2] = 1
                ˍ₋out[7] = -1
                ˍ₋out[8] = 1
                ˍ₋out[15] = 1
                nothing
            end
    end
end

function H_xp!(ˍ₋out, ˍ₋arg1, ˍ₋arg2, ˍ₋arg3; )
    let c = @inbounds(ˍ₋arg1[1]), q = @inbounds(ˍ₋arg1[2]), i = @inbounds(ˍ₋arg1[3]), k = @inbounds(ˍ₋arg2[1]), z = @inbounds(ˍ₋arg2[2]), α = @inbounds(ˍ₋arg3[1]), β = @inbounds(ˍ₋arg3[2]), ρ = @inbounds(ˍ₋arg3[3]), δ = @inbounds(ˍ₋arg3[4]), σ = @inbounds(ˍ₋arg3[5]), Ω_1 = @inbounds(ˍ₋arg3[6])
        @inbounds begin
                ˍ₋out[1] = (/)((*)(-1, α, β, (^)(k, (+)(-2, α)), (+)(-1, α), (exp)(z)), c)
                ˍ₋out[2] = 1
                ˍ₋out[5] = -1
                ˍ₋out[6] = (/)((*)(-1, α, β, (^)(k, (+)(-1, α)), (exp)(z)), c)
                ˍ₋out[9] = 1
                nothing
            end
    end
end

function H_x!(ˍ₋out, ˍ₋arg1, ˍ₋arg2, ˍ₋arg3; )
    let c = @inbounds(ˍ₋arg1[1]), q = @inbounds(ˍ₋arg1[2]), i = @inbounds(ˍ₋arg1[3]), k = @inbounds(ˍ₋arg2[1]), z = @inbounds(ˍ₋arg2[2]), α = @inbounds(ˍ₋arg3[1]), β = @inbounds(ˍ₋arg3[2]), ρ = @inbounds(ˍ₋arg3[3]), δ = @inbounds(ˍ₋arg3[4]), σ = @inbounds(ˍ₋arg3[5]), Ω_1 = @inbounds(ˍ₋arg3[6])
        @inbounds begin
                ˍ₋out[2] = (+)(-1, δ)
                ˍ₋out[3] = (*)(-1, α, (^)(k, (+)(-1, α)), (exp)(z))
                ˍ₋out[5] = (+)(1, (*)(-1, δ))
                ˍ₋out[8] = (*)(-1, (^)(k, α), (exp)(z))
                ˍ₋out[9] = (*)(-1, ρ)
                nothing
            end
    end
end

function Ψ!(ˍ₋out, ˍ₋arg1, ˍ₋arg2, ˍ₋arg3; )
    let c = @inbounds(ˍ₋arg1[1]), q = @inbounds(ˍ₋arg1[2]), i = @inbounds(ˍ₋arg1[3]), k = @inbounds(ˍ₋arg2[1]), z = @inbounds(ˍ₋arg2[2]), α = @inbounds(ˍ₋arg3[1]), β = @inbounds(ˍ₋arg3[2]), ρ = @inbounds(ˍ₋arg3[3]), δ = @inbounds(ˍ₋arg3[4]), σ = @inbounds(ˍ₋arg3[5]), Ω_1 = @inbounds(ˍ₋arg3[6])
        @inbounds begin
                nothing
            end
        begin
            @inbounds begin
                    (ˍ₋out[1])[1] = (*)(2, c, (/)((*)(-1, β, (+)(1, (*)(-1, δ), (*)(α, (^)(k, (+)(-1, α)), (exp)(z)))), (^)(c, 4)))
                    (ˍ₋out[1])[7] = (/)((*)(α, β, (^)(k, (+)(-2, α)), (+)(-1, α), (exp)(z)), (^)(c, 2))
                    (ˍ₋out[1])[8] = (/)((*)(α, β, (^)(k, (+)(-1, α)), (exp)(z)), (^)(c, 2))
                    (ˍ₋out[1])[34] = (*)(2, c, (/)(1, (^)(c, 4)))
                    (ˍ₋out[1])[61] = (/)((*)(α, β, (^)(k, (+)(-2, α)), (+)(-1, α), (exp)(z)), (^)(c, 2))
                    (ˍ₋out[1])[67] = (/)((*)(-1, α, β, (^)(k, (+)(-3, α)), (+)(-1, α), (+)(-2, α), (exp)(z)), c)
                    (ˍ₋out[1])[68] = (/)((*)(-1, α, β, (^)(k, (+)(-2, α)), (+)(-1, α), (exp)(z)), c)
                    (ˍ₋out[1])[71] = (/)((*)(α, β, (^)(k, (+)(-1, α)), (exp)(z)), (^)(c, 2))
                    (ˍ₋out[1])[77] = (/)((*)(-1, α, β, (^)(k, (+)(-2, α)), (+)(-1, α), (exp)(z)), c)
                    (ˍ₋out[1])[78] = (/)((*)(-1, α, β, (^)(k, (+)(-1, α)), (exp)(z)), c)
                    nothing
                end
        end
        begin
            @inbounds begin
                    nothing
                end
        end
        begin
            @inbounds begin
                    (ˍ₋out[3])[89] = (*)(-1, α, (^)(k, (+)(-2, α)), (+)(-1, α), (exp)(z))
                    (ˍ₋out[3])[90] = (*)(-1, α, (^)(k, (+)(-1, α)), (exp)(z))
                    (ˍ₋out[3])[99] = (*)(-1, α, (^)(k, (+)(-1, α)), (exp)(z))
                    (ˍ₋out[3])[100] = (*)(-1, (^)(k, α), (exp)(z))
                    nothing
                end
        end
        begin
            @inbounds begin
                    nothing
                end
        end
        begin
            @inbounds begin
                    nothing
                end
        end
    end
end

function H_yp_p!(ˍ₋out, ::Val{:α}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                ˍ₋out[1] = (/)((*)(β, (+)((*)((^)(k, (+)(-1, α)), (exp)(z)), (*)(α, (^)(k, (+)(-1, α)), (log)(k), (exp)(z)))), (^)(c, 2))
                nothing
            end
    end
end

function H_yp_p!(ˍ₋out, ::Val{:ρ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_yp_p!(ˍ₋out, ::Val{:σ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_yp_p!(ˍ₋out, ::Val{:Ω_1}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_yp_p!(ˍ₋out, ::Val{:δ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                ˍ₋out[1] = (/)((*)(-1, β), (^)(c, 2))
                nothing
            end
    end
end

function H_yp_p!(ˍ₋out, ::Val{:β}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                ˍ₋out[1] = (/)((+)(1, (*)(-1, δ), (*)(α, (^)(k, (+)(-1, α)), (exp)(z))), (^)(c, 2))
                nothing
            end
    end
end

function H_y_p!(ˍ₋out, ::Val{:α}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_y_p!(ˍ₋out, ::Val{:ρ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_y_p!(ˍ₋out, ::Val{:σ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_y_p!(ˍ₋out, ::Val{:Ω_1}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_y_p!(ˍ₋out, ::Val{:δ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_y_p!(ˍ₋out, ::Val{:β}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_xp_p!(ˍ₋out, ::Val{:α}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                ˍ₋out[1] = (/)((+)((*)(-1, α, β, (^)(k, (+)(-2, α)), (exp)(z)), (*)(-1, β, (^)(k, (+)(-2, α)), (+)(-1, α), (exp)(z)), (*)(-1, α, β, (^)(k, (+)(-2, α)), (+)(-1, α), (log)(k), (exp)(z))), c)
                ˍ₋out[6] = (/)((+)((*)(-1, β, (^)(k, (+)(-1, α)), (exp)(z)), (*)(-1, α, β, (^)(k, (+)(-1, α)), (log)(k), (exp)(z))), c)
                nothing
            end
    end
end

function H_xp_p!(ˍ₋out, ::Val{:ρ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_xp_p!(ˍ₋out, ::Val{:σ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_xp_p!(ˍ₋out, ::Val{:Ω_1}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_xp_p!(ˍ₋out, ::Val{:δ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_xp_p!(ˍ₋out, ::Val{:β}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                ˍ₋out[1] = (/)((*)(-1, α, (^)(k, (+)(-2, α)), (+)(-1, α), (exp)(z)), c)
                ˍ₋out[6] = (/)((*)(-1, α, (^)(k, (+)(-1, α)), (exp)(z)), c)
                nothing
            end
    end
end

function H_x_p!(ˍ₋out, ::Val{:α}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                ˍ₋out[3] = (+)((*)(-1, (^)(k, (+)(-1, α)), (exp)(z)), (*)(-1, α, (^)(k, (+)(-1, α)), (log)(k), (exp)(z)))
                ˍ₋out[8] = (*)(-1, (^)(k, α), (log)(k), (exp)(z))
                nothing
            end
    end
end

function H_x_p!(ˍ₋out, ::Val{:ρ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                ˍ₋out[9] = -1
                nothing
            end
    end
end

function H_x_p!(ˍ₋out, ::Val{:σ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_x_p!(ˍ₋out, ::Val{:Ω_1}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_x_p!(ˍ₋out, ::Val{:δ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                ˍ₋out[2] = 1
                ˍ₋out[5] = -1
                nothing
            end
    end
end

function H_x_p!(ˍ₋out, ::Val{:β}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_p!(ˍ₋out, ::Val{:α}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                ˍ₋out[1] = (/)((*)(-1, β, (+)((*)((^)(k, (+)(-1, α)), (exp)(z)), (*)(α, (^)(k, (+)(-1, α)), (log)(k), (exp)(z)))), c)
                ˍ₋out[3] = (*)(-1, (^)(k, α), (log)(k), (exp)(z))
                nothing
            end
    end
end

function H_p!(ˍ₋out, ::Val{:ρ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                ˍ₋out[4] = (*)(-1, z)
                nothing
            end
    end
end

function H_p!(ˍ₋out, ::Val{:σ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_p!(ˍ₋out, ::Val{:Ω_1}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                nothing
            end
    end
end

function H_p!(ˍ₋out, ::Val{:δ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                ˍ₋out[1] = (/)(β, c)
                ˍ₋out[2] = k
                ˍ₋out[5] = (*)(-1, k)
                nothing
            end
    end
end

function H_p!(ˍ₋out, ::Val{:β}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )
    let c = @inbounds(ˍ₋arg2[1]), q = @inbounds(ˍ₋arg2[2]), i = @inbounds(ˍ₋arg2[3]), k = @inbounds(ˍ₋arg3[1]), z = @inbounds(ˍ₋arg3[2]), α = @inbounds(ˍ₋arg4[1]), β = @inbounds(ˍ₋arg4[2]), ρ = @inbounds(ˍ₋arg4[3]), δ = @inbounds(ˍ₋arg4[4]), σ = @inbounds(ˍ₋arg4[5]), Ω_1 = @inbounds(ˍ₋arg4[6])
        @inbounds begin
                ˍ₋out[1] = (/)((+)(-1, δ, (*)(-1, α, (^)(k, (+)(-1, α)), (exp)(z))), c)
                nothing
            end
    end
end

max_stars_repo_name: HighDimensionalEconLab/HMCExamples

max_issues_repo_name: HighDimensionalEconLab/HMCExamples

max_forks_repo_name: HighDimensionalEconLab/HMCExamples


text:
@testset "minimal_nums_to_interval_test" begin

    @test interval(-1.0,1.0) === Interval(-1.0,1.0)

    @test interval(-Inf,1.0) === Interval(-Inf,1.0)

    @test interval(-1.0,Inf) === Interval(-1.0,Inf)

    @test interval(-Inf,Inf) === Interval(-Inf,Inf)

    @test interval(NaN,NaN) === emptyinterval()

    @test interval(1.0,-1.0) === emptyinterval()

    @test interval(-Inf,-Inf) === emptyinterval()

    @test interval(Inf,Inf) === emptyinterval()

end

@testset "minimal_nums_to_decorated_interval_test" begin

    @test DecoratedInterval(-1.0,1.0) === DecoratedInterval(Interval(-1.0,1.0), com)

    @test DecoratedInterval(-Inf,1.0) === DecoratedInterval(Interval(-Inf,1.0), dac)

    @test DecoratedInterval(-1.0,Inf) === DecoratedInterval(Interval(-1.0,Inf), dac)

    @test DecoratedInterval(-Inf,Inf) === DecoratedInterval(Interval(-Inf,Inf), dac)

    @test isnai(DecoratedInterval(NaN,NaN))

    @test isnai(DecoratedInterval(1.0,-1.0))

    @test isnai(DecoratedInterval(-Inf,-Inf))

    @test isnai(DecoratedInterval(Inf,Inf))

end

@testset "minimal_text_to_interval_test" begin

    @test @interval("[ Empty  ]") === emptyinterval()

    @test @interval("[ Empty  ]_trv") === emptyinterval()

    @test @interval("[  ]") === emptyinterval()

    @test @interval("[  ]_trv") === emptyinterval()

    @test @interval("[,]") === Interval(-Inf,Inf)

    @test_broken @interval("[,]_trv") === emptyinterval()

    @test @interval("[ entire  ]") === Interval(-Inf,Inf)

    @test_broken @interval("[ ENTIRE ]_dac") === emptyinterval()

    @test_broken @interval("[ ENTIRE ]") === Interval(-Inf,Inf)

    @test_broken @interval("[ -inf , INF  ]") === Interval(-Inf,Inf)

    @test_broken @interval("[ -inf, INF ]_def") === emptyinterval()

    @test @interval("[-1.0,1.0]") === Interval(-1.0,1.0)

    @test @interval("[  -1.0  ,  1.0  ]") === Interval(-1.0,1.0)

    @test @interval("[  -1.0  , 1.0]") === Interval(-1.0,1.0)

    @test @interval("[-1,]") === Interval(-1.0,Inf)

    @test_broken @interval("[-1.0, +inf]") === Interval(-1.0,Inf)

    @test @interval("[-1.0, +infinity]") === Interval(-1.0,Inf)

    @test @interval("[-Inf, 1.000 ]") === Interval(-Inf,1.0)

    @test_broken @interval("[-Infinity, 1.000 ]") === Interval(-Inf,1.0)

    @test_broken @interval("[1.0E+400 ]") === Interval(0x1.fffffffffffffp+1023,Inf)

    @test @interval("[ -4/2, 10/5 ]") === Interval(-2.0,2.0)

    @test @interval("[ -1/10, 1/10 ]") === Interval(-0.1,0.1)

    @test @interval("0.0?") === Interval(-0.05,0.05)

    @test @interval("0.0?u") === Interval(0.0,0.05)

    @test @interval("0.0?d") === Interval(-0.05,0.0)

    @test @interval("2.5?") === Interval(0x1.3999999999999p+1,0x1.4666666666667p+1)

    @test @interval("2.5?u") === Interval(2.5,0x1.4666666666667p+1)

    @test @interval("2.5?d") === Interval(0x1.3999999999999p+1,2.5)

    @test @interval("0.000?5") === Interval(-0.005,0.005)

    @test @interval("0.000?5u") === Interval(0.0,0.005)

    @test @interval("0.000?5d") === Interval(-0.005,0.0)

    @test @interval("2.500?5") === Interval(0x1.3f5c28f5c28f5p+1,0x1.40a3d70a3d70bp+1)

    @test @interval("2.500?5u") === Interval(2.5,0x1.40a3d70a3d70bp+1)

    @test @interval("2.500?5d") === Interval(0x1.3f5c28f5c28f5p+1,2.5)

    @test @interval("0.0??") === Interval(-Inf,Inf)

    @test @interval("0.0??u") === Interval(0.0,Inf)

    @test @interval("0.0??d") === Interval(-Inf,0.0)

    @test @interval("2.5??") === Interval(-Inf,Inf)

    @test @interval("2.5??u") === Interval(2.5,Inf)

    @test @interval("2.5??d") === Interval(-Inf,2.5)

    @test_broken @interval("2.500?5e+27") === Interval(0x1.01fa19a08fe7fp+91,0x1.0302cc4352683p+91)

    @test @interval("2.500?5ue4") === Interval(0x1.86ap+14,0x1.8768p+14)

    @test @interval("2.500?5de-5") === Interval(0x1.a2976f1cee4d5p-16,0x1.a36e2eb1c432dp-16)

    @test @interval("10?3") === Interval(7.0,13.0)

    @test_broken @interval("10?3e380") === Interval(0x1.fffffffffffffp+1023,Inf)

    @test_broken @interval("1.0000000000000001?1") === Interval(1.0,0x1.0000000000001p+0)

    @test_broken @interval("10?1800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") === Interval(-Inf,Inf)

    @test_broken @interval("[ Nai  ]") === emptyinterval()

    @test_broken @interval("[ Nai  ]_ill") === emptyinterval()

    @test_broken @interval("[ Nai  ]_trv") === emptyinterval()

    @test @interval("[ Empty  ]_ill") === emptyinterval()

    @test @interval("[  ]_com") === emptyinterval()

    @test_broken @interval("[,]_com") === emptyinterval()

    @test_broken @interval("[   Entire ]_com") === emptyinterval()

    @test_broken @interval("[ -inf ,  INF ]_com") === emptyinterval()

    @test_broken @interval("[  -1.0  , 1.0]_ill") === emptyinterval()

    @test_broken @interval("[  -1.0  , 1.0]_fooo") === emptyinterval()

    @test_broken @interval("[  -1.0  , 1.0]_da") === emptyinterval()

    @test_broken @interval("[-1.0,]_com") === emptyinterval()

    @test_broken @interval("[-Inf, 1.000 ]_ill") === emptyinterval()

    @test_broken @interval("[-I  nf, 1.000 ]") === emptyinterval()

    @test_broken @interval("[-Inf, 1.0  00 ]") === emptyinterval()

    @test_broken @interval("[-Inf ]") === emptyinterval()

    @test_broken @interval("[Inf , INF]") === emptyinterval()

    @test_broken @interval("[ foo ]") === emptyinterval()

    @test_broken @interval("[1.0000000000000002,1.0000000000000001]") === Interval(1.0,0x1.0000000000001p+0)

    @test @interval("[10000000000000001/10000000000000000,10000000000000002/10000000000000001]") === Interval(1.0,0x1.0000000000001p+0)

    @test_broken @interval("[0x1.00000000000002p0,0x1.00000000000001p0]") === Interval(1.0,0x1.0000000000001p+0)

end

@testset "minimal_text_to_decorated_interval_test" begin

    @test @decorated("[ Empty  ]") === DecoratedInterval(emptyinterval(), trv)

    @test @decorated("[ Empty  ]_trv") === DecoratedInterval(emptyinterval(), trv)

    @test @decorated("[  ]") === DecoratedInterval(emptyinterval(), trv)

    @test @decorated("[  ]_trv") === DecoratedInterval(emptyinterval(), trv)

    @test @decorated("[,]") === DecoratedInterval(entireinterval(), dac)

    @test @decorated("[,]_trv") === DecoratedInterval(entireinterval(), trv)

    @test @decorated("[ entire  ]") === DecoratedInterval(entireinterval(), dac)

    @test_skip @decorated("[ ENTIRE ]_dac") === DecoratedInterval(entireinterval(), dac)

    @test_skip @decorated("[ -inf , INF  ]") === DecoratedInterval(entireinterval(), dac)

    @test_skip @decorated("[ -inf, INF ]_def") === DecoratedInterval(entireinterval(), def)

    @test @decorated("[-1.0,1.0]") === DecoratedInterval(Interval(-1.0,1.0), com)

    @test @decorated("[  -1.0  ,  1.0  ]_com") === DecoratedInterval(Interval(-1.0,1.0), com)

    @test @decorated("[  -1.0  , 1.0]_trv") === DecoratedInterval(Interval(-1.0,1.0), trv)

    @test @decorated("[-1,]") === DecoratedInterval(Interval(-1.0,Inf), dac)

    @test_skip @decorated("[-1.0, +inf]_def") === DecoratedInterval(Interval(-1.0,Inf), def)

    @test @decorated("[-1.0, +infinity]_def") === DecoratedInterval(Interval(-1.0,Inf), def)

    @test @decorated("[-Inf, 1.000 ]") === DecoratedInterval(Interval(-Inf,1.0), dac)

    @test_skip @decorated("[-Infinity, 1.000 ]_trv") === DecoratedInterval(Interval(-Inf,1.0), trv)

    @test_skip @decorated("[1.0E+400 ]_com") === DecoratedInterval(Interval(0x1.fffffffffffffp+1023,Inf), dac)

    @test @decorated("[ -4/2, 10/5 ]_com") === DecoratedInterval(Interval(-2.0,2.0), com)

    @test @decorated("[ -1/10, 1/10 ]_com") === DecoratedInterval(Interval(-0.1,0.1), com)

    @test @decorated("0.0?") === DecoratedInterval(Interval(-0.05,0.05), com)

    @test @decorated("0.0?u_trv") === DecoratedInterval(Interval(0.0,0.05), trv)

    @test @decorated("0.0?d_dac") === DecoratedInterval(Interval(-0.05,0.0), dac)

    @test @decorated("2.5?") === DecoratedInterval(Interval(0x1.3999999999999p+1,0x1.4666666666667p+1), com)

    @test @decorated("2.5?u") === DecoratedInterval(Interval(2.5,0x1.4666666666667p+1), com)

    @test @decorated("2.5?d_trv") === DecoratedInterval(Interval(0x1.3999999999999p+1,2.5), trv)

    @test @decorated("0.000?5") === DecoratedInterval(Interval(-0.005,0.005), com)

    @test @decorated("0.000?5u_def") === DecoratedInterval(Interval(0.0,0.005), def)

    @test @decorated("0.000?5d") === DecoratedInterval(Interval(-0.005,0.0), com)

    @test @decorated("2.500?5") === DecoratedInterval(Interval(0x1.3f5c28f5c28f5p+1,0x1.40a3d70a3d70bp+1), com)

    @test @decorated("2.500?5u") === DecoratedInterval(Interval(2.5,0x1.40a3d70a3d70bp+1), com)

    @test @decorated("2.500?5d") === DecoratedInterval(Interval(0x1.3f5c28f5c28f5p+1,2.5), com)

    @test @decorated("0.0??_dac") === DecoratedInterval(Interval(-Inf,Inf), dac)

    @test @decorated("0.0??u_trv") === DecoratedInterval(Interval(0.0,Inf), trv)

    @test @decorated("0.0??d") === DecoratedInterval(Interval(-Inf,0.0), dac)

    @test @decorated("2.5??") === DecoratedInterval(Interval(-Inf,Inf), dac)

    @test @decorated("2.5??u_def") === DecoratedInterval(Interval(2.5,Inf), def)

    @test @decorated("2.5??d_dac") === DecoratedInterval(Interval(-Inf,2.5), dac)

    @test_skip @decorated("2.500?5e+27") === DecoratedInterval(Interval(0x1.01fa19a08fe7fp+91,0x1.0302cc4352683p+91), com)

    @test @decorated("2.500?5ue4_def") === DecoratedInterval(Interval(0x1.86ap+14,0x1.8768p+14), def)

    @test_skip @decorated("2.500?5de-5") === DecoratedInterval(Interval(0x1.a2976f1cee4d5p-16,0x1.a36e2eb1c432dp-16), com)

    @test_skip isnai(@decorated("[ Nai  ]"))

    @test_skip @decorated("10?1800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000_com") === DecoratedInterval(Interval(-Inf,Inf), dac)

    @test @decorated("10?3_com") === DecoratedInterval(Interval(7.0,13.0), com)

    @test_skip @decorated("10?3e380_com") === DecoratedInterval(Interval(0x1.fffffffffffffp+1023,Inf), dac)

    @test_skip isnai(@decorated("[ Nai  ]_ill"))

    @test_skip isnai(@decorated("[ Nai  ]_trv"))

    @test_skip isnai(@decorated("[ Empty  ]_ill"))

    @test_skip isnai(@decorated("[  ]_com"))

    @test_skip isnai(@decorated("[,]_com"))

    @test_skip isnai(@decorated("[   Entire ]_com"))

    @test_skip isnai(@decorated("[ -inf ,  INF ]_com"))

    @test_skip isnai(@decorated("[  -1.0  , 1.0]_ill"))

    @test_skip isnai(@decorated("[  -1.0  , 1.0]_fooo"))

    @test_skip isnai(@decorated("[  -1.0  , 1.0]_da"))

    @test_skip isnai(@decorated("[-1.0,]_com"))

    @test_skip isnai(@decorated("[-Inf, 1.000 ]_ill"))

    @test_skip isnai(@decorated("[-I  nf, 1.000 ]"))

    @test_skip isnai(@decorated("[-Inf, 1.0  00 ]"))

    @test_skip isnai(@decorated("[-Inf ]"))

    @test_skip isnai(@decorated("[Inf , INF]"))

    @test_skip isnai(@decorated("[ foo ]"))

    @test_skip isnai(@decorated("0.0??_com"))

    @test_skip isnai(@decorated("0.0??u_ill"))

    @test_skip isnai(@decorated("0.0??d_com"))

    @test_skip isnai(@decorated("0.0??_com"))

    @test_skip isnai(@decorated("[1.0,2.0"))

    @test_broken @decorated("[1.0000000000000002,1.0000000000000001]") === DecoratedInterval(Interval(1.0,0x1.0000000000001p+0), com)

    @test @decorated("[10000000000000001/10000000000000000,10000000000000002/10000000000000001]") === DecoratedInterval(Interval(1.0,0x1.0000000000001p+0), com)

    @test_broken @decorated("[0x1.00000000000002p0,0x1.00000000000001p0]") === DecoratedInterval(Interval(1.0,0x1.0000000000001p+0), com)

end

@testset "minimal_interval_part_test" begin

    @test interval(DecoratedInterval(interval(-0x1.99999A842549Ap+4,0x1.9999999999999P-4), trv)) === Interval(-0x1.99999A842549Ap+4,0x1.9999999999999P-4)

    @test interval(DecoratedInterval(interval(-0x1.99999C0000000p+4,0x1.9999999999999P-4), com)) === Interval(-0x1.99999C0000000p+4,0x1.9999999999999P-4)

    @test interval(DecoratedInterval(interval(-0x1.99999A842549Ap+4,0x1.99999A0000000p-4), dac)) === Interval(-0x1.99999A842549Ap+4,0x1.99999A0000000p-4)

    @test interval(DecoratedInterval(interval(-0x1.99999C0000000p+4,0x1.99999A0000000p-4), def)) === Interval(-0x1.99999C0000000p+4,0x1.99999A0000000p-4)

    @test interval(DecoratedInterval(interval(-0x0.0000000000001p-1022,-0x0.0000000000001p-1022), trv)) === Interval(-0x0.0000000000001p-1022,-0x0.0000000000001p-1022)

    @test interval(DecoratedInterval(interval(-0x0.0000000000001p-1022,0x0.0000000000001p-1022), trv)) === Interval(-0x0.0000000000001p-1022,0x0.0000000000001p-1022)

    @test interval(DecoratedInterval(interval(0x0.0000000000001p-1022,0x0.0000000000001p-1022), trv)) === Interval(0x0.0000000000001p-1022,0x0.0000000000001p-1022)

    @test interval(DecoratedInterval(interval(-0x1.fffffffffffffp+1023,-0x1.fffffffffffffp+1023), trv)) === Interval(-0x1.fffffffffffffp+1023,-0x1.fffffffffffffp+1023)

    @test interval(DecoratedInterval(interval(-0x1.fffffffffffffp+1023,0x1.fffffffffffffp+1023), trv)) === Interval(-0x1.fffffffffffffp+1023,0x1.fffffffffffffp+1023)

    @test interval(DecoratedInterval(interval(0x1.fffffffffffffp+1023,0x1.fffffffffffffp+1023), trv)) === Interval(0x1.fffffffffffffp+1023,0x1.fffffffffffffp+1023)

    @test interval(DecoratedInterval(interval(-Inf,Inf), trv)) === Interval(-Inf,Inf)

    @test interval(DecoratedInterval(emptyinterval(), trv)) === emptyinterval()

    @test interval(DecoratedInterval(interval(-0x1.99999C0000000p+4,0x1.9999999999999P-4), com)) === Interval(-0x1.99999C0000000p+4,0x1.9999999999999P-4)

    @test_broken interval(nai()) === emptyinterval()

end

@testset "minimal_new_dec_test" begin

    @test DecoratedInterval(interval(-0x1.99999A842549Ap+4,0x1.9999999999999P-4)) === DecoratedInterval(Interval(-0x1.99999A842549Ap+4,0x1.9999999999999P-4), com)

    @test DecoratedInterval(interval(-0x1.99999C0000000p+4,0x1.9999999999999P-4)) === DecoratedInterval(Interval(-0x1.99999C0000000p+4,0x1.9999999999999P-4), com)

    @test DecoratedInterval(interval(-0x1.99999A842549Ap+4,0x1.99999A0000000p-4)) === DecoratedInterval(Interval(-0x1.99999A842549Ap+4,0x1.99999A0000000p-4), com)

    @test DecoratedInterval(interval(-0x1.99999C0000000p+4,0x1.99999A0000000p-4)) === DecoratedInterval(Interval(-0x1.99999C0000000p+4,0x1.99999A0000000p-4), com)

    @test DecoratedInterval(interval(-0x0.0000000000001p-1022,-0x0.0000000000001p-1022)) === DecoratedInterval(Interval(-0x0.0000000000001p-1022,-0x0.0000000000001p-1022), com)

    @test DecoratedInterval(interval(-0x0.0000000000001p-1022,0x0.0000000000001p-1022)) === DecoratedInterval(Interval(-0x0.0000000000001p-1022,0x0.0000000000001p-1022), com)

    @test DecoratedInterval(interval(0x0.0000000000001p-1022,0x0.0000000000001p-1022)) === DecoratedInterval(Interval(0x0.0000000000001p-1022,0x0.0000000000001p-1022), com)

    @test DecoratedInterval(interval(-0x1.fffffffffffffp+1023,-0x1.fffffffffffffp+1023)) === DecoratedInterval(Interval(-0x1.fffffffffffffp+1023,-0x1.fffffffffffffp+1023), com)

    @test DecoratedInterval(interval(-0x1.fffffffffffffp+1023,0x1.fffffffffffffp+1023)) === DecoratedInterval(Interval(-0x1.fffffffffffffp+1023,0x1.fffffffffffffp+1023), com)

    @test DecoratedInterval(interval(0x1.fffffffffffffp+1023,0x1.fffffffffffffp+1023)) === DecoratedInterval(Interval(0x1.fffffffffffffp+1023,0x1.fffffffffffffp+1023), com)

    @test DecoratedInterval(interval(-Inf,Inf)) === DecoratedInterval(Interval(-Inf,Inf), dac)

    @test DecoratedInterval(emptyinterval()) === DecoratedInterval(emptyinterval(), trv)

    @test DecoratedInterval(interval(-0x1.99999C0000000p+4,0x1.9999999999999P-4)) === DecoratedInterval(Interval(-0x1.99999C0000000p+4,0x1.9999999999999P-4), com)

end

@testset "minimal_set_dec_test" begin

    @test DecoratedInterval(interval(-0x1.99999A842549Ap+4,0x1.9999999999999P-4), trv) === DecoratedInterval(Interval(-0x1.99999A842549Ap+4,0x1.9999999999999P-4), trv)

    @test DecoratedInterval(interval(-0x1.99999C0000000p+4,0x1.9999999999999P-4), com) === DecoratedInterval(Interval(-0x1.99999C0000000p+4,0x1.9999999999999P-4), com)

    @test DecoratedInterval(interval(-0x1.99999A842549Ap+4,0x1.99999A0000000p-4), dac) === DecoratedInterval(Interval(-0x1.99999A842549Ap+4,0x1.99999A0000000p-4), dac)

    @test DecoratedInterval(interval(-0x1.99999C0000000p+4,0x1.99999A0000000p-4), def) === DecoratedInterval(Interval(-0x1.99999C0000000p+4,0x1.99999A0000000p-4), def)

    @test DecoratedInterval(interval(-0x0.0000000000001p-1022,-0x0.0000000000001p-1022), trv) === DecoratedInterval(Interval(-0x0.0000000000001p-1022,-0x0.0000000000001p-1022), trv)

    @test DecoratedInterval(interval(-0x0.0000000000001p-1022,0x0.0000000000001p-1022), def) === DecoratedInterval(Interval(-0x0.0000000000001p-1022,0x0.0000000000001p-1022), def)

    @test DecoratedInterval(interval(0x0.0000000000001p-1022,0x0.0000000000001p-1022), dac) === DecoratedInterval(Interval(0x0.0000000000001p-1022,0x0.0000000000001p-1022), dac)

    @test DecoratedInterval(interval(-0x1.fffffffffffffp+1023,-0x1.fffffffffffffp+1023), com) === DecoratedInterval(Interval(-0x1.fffffffffffffp+1023,-0x1.fffffffffffffp+1023), com)

    @test DecoratedInterval(interval(-0x1.fffffffffffffp+1023,0x1.fffffffffffffp+1023), def) === DecoratedInterval(Interval(-0x1.fffffffffffffp+1023,0x1.fffffffffffffp+1023), def)

    @test DecoratedInterval(interval(0x1.fffffffffffffp+1023,0x1.fffffffffffffp+1023), trv) === DecoratedInterval(Interval(0x1.fffffffffffffp+1023,0x1.fffffffffffffp+1023), trv)

    @test DecoratedInterval(interval(-Inf,Inf), dac) === DecoratedInterval(Interval(-Inf,Inf), dac)

    @test DecoratedInterval(emptyinterval(), trv) === DecoratedInterval(emptyinterval(), trv)

    @test DecoratedInterval(interval(-0x1.99999C0000000p+4,0x1.9999999999999P-4), com) === DecoratedInterval(Interval(-0x1.99999C0000000p+4,0x1.9999999999999P-4), com)

    @test DecoratedInterval(emptyinterval(), def) === DecoratedInterval(emptyinterval(), trv)

    @test DecoratedInterval(emptyinterval(), dac) === DecoratedInterval(emptyinterval(), trv)

    @test DecoratedInterval(emptyinterval(), com) === DecoratedInterval(emptyinterval(), trv)

    @test_broken DecoratedInterval(interval(1.0,Inf), com) === DecoratedInterval(Interval(1.0,Inf), dac)

    @test_broken DecoratedInterval(interval(-Inf,3.0), com) === DecoratedInterval(Interval(-Inf,3.0), dac)

    @test_broken DecoratedInterval(interval(-Inf,Inf), com) === DecoratedInterval(Interval(-Inf,Inf), dac)

    @test_broken isnai(DecoratedInterval(emptyinterval(), ill))

    @test_broken isnai(DecoratedInterval(interval(-Inf,3.0), ill))

    @test_broken isnai(DecoratedInterval(interval(-1.0,3.0), ill))

end

@testset "minimal_decoration_part_test" begin

    @test decoration(nai()) === ill

    @test decoration(DecoratedInterval(emptyinterval(), trv)) === trv

    @test decoration(DecoratedInterval(interval(-1.0,3.0), trv)) === trv

    @test decoration(DecoratedInterval(interval(-1.0,3.0), def)) === def

    @test decoration(DecoratedInterval(interval(-1.0,3.0), dac)) === dac

    @test decoration(DecoratedInterval(interval(-1.0,3.0), com)) === com

end


text:
"""
FunctionBlocks
"""

export SaturationBlock

mutable struct SaturationBlock <: AbstractFunctionBlock
    inport::Vector{InPort}
    outport::Vector{OutPort}
    upperlimit::AbstractSignalLine
    lowerlimit::AbstractSignalLine

    function SaturationBlock(::Type{Tv} = Float64; upperlimit = 0, lowerlimit = 0) where Tv
        @createblock new(Vector{InPort}(), Vector{OutPort}(),
            signal(upperlimit, Tv),
            signal(lowerlimit, Tv)
            ) 1 1
    end
end

"""
IO
"""

function Base.show(io::IO, blk::SaturationBlock)
    println(io, "Saturation()")
end

"""
to expr
"""

function _toexpr(blk::SaturationBlock)
    upperlimit = _toexpr(blk.upperlimit)
    lowerlimit = _toexpr(blk.lowerlimit)

    Expr(:if, Expr(:comparison, lowerlimit, :>=, _toexpr(blk.inport[1])), lowerlimit, Expr(:if, Expr(:comparison, upperlimit, :<=, _toexpr(blk.inport[1])), upperlimit, _toexpr(blk.inport[1])))

    #Expr(:if, Expr(:comparison, upperlimit, :<=, _toexpr(blk.inport[1])), upperlimit, _toexpr(blk.inport[1]))

end


text:
# Fallbacks
@inline diffusivity_mixing_length(m, i) = mixing_length(m, i)
@inline dissipation_length(m, i) = mixing_length(m, i)

#
# A "simple" mixing length
#

Base.@kwdef struct SimpleMixingLength{T} <: AbstractParameters
    Cᴸᵟ :: T = 1.0
    Cᴸʷ :: T = 3.4684
    Cᴸᵇ :: T = 3.9302
end

@inline function mixing_length(m::Model{<:SimpleMixingLength}, i)
    # Two mixing lengths based on stratification and distance from surface:
    @inbounds ℓᶻ = - m.mixing_length.Cᴸʷ * m.grid.zc[i]
    ℓᵇ = nan2inf(m.mixing_length.Cᴸᵇ * sqrt_e(m, i) / oncell(sqrt_∂B∂z, m, i))

    # Take hard minimum:
    ℓ = min(ℓᶻ, ℓᵇ)

    # Finally, limit by some factor of the local cell width
    ℓᵐⁱⁿ = m.mixing_length.Cᴸᵟ * Δf(m.grid, i)
    ℓ = max(ℓ, ℓᵐⁱⁿ)

    return ℓ
end

#
# Mixing length model due to Ignacio Lopez-Gomez + Clima
#

Base.@kwdef struct EquilibriumMixingLength{T} <: AbstractParameters
    Cᴸᵟ :: T = 1.0
    Cᴸʷ :: T = 1.688 # Limits to Von-Karman constant for stress-driven turbulence
    Cᴸᵇ :: T = 1.664
end

@inline function mixing_length(m::Model{<:EquilibriumMixingLength}, i)
    @inbounds e = m.solution.e[i] # TKE at cell i

    # "Smallest" diffusivity limited by grid spacing.
    ℓᵟ = m.mixing_length.Cᴸᵟ * Δf(m.grid, i)

    if e <= 0 # shortcut when TKE is zero (diffusivity is zero in this case regardless).
        return ℓᵟ
    else
        # For notational convenience
        Cᴸᵇ = m.mixing_length.Cᴸᵇ
        Cᴸʷ = m.mixing_length.Cᴸʷ
        Cᴰ  = m.tke_equation.Cᴰ

        # Extract buoyancy frequency and shear squared.
        N² = oncell_∂B∂z(m, i)
        S² = oncell(shear_squared, m, i)

        # Length scale associated with a production-buoyancy flux-dissipation balance
        # in the TKE budget. Valid only for a linear equation of state with a shared diffusivity
        # for salinity and temperature.
        #
        # Note that ω² = Cᴷu * S² - Cᴷc * N² can be negative, in which case this model predicts ℓᵀᴷᴱ=0.
        ω² = Cᴷu(m, i) * S² - Cᴷc(m, i) * N²
        ℓᵀᴷᴱ = maxsqrt(Cᴰ * e / ω²)

        # Length-scale limitation by strong stratification.
        ℓᵇ = N² <= 0 ? Inf : Cᴸᵇ * √(e / N²)

        # Near-wall length scale:
        ℓʷ = @inbounds - Cᴸʷ * m.grid.zc[i] * u★(m) / √e

        # Hard minimum for now
        ℓ = min(ℓᵀᴷᴱ, ℓᵇ, ℓʷ)

        return max(ℓ, ℓᵟ) # limits mixing length to be larger than grid spacing
    end
end

#
# Mixing length model from Tan et al 2018.
#

#=
Base.@kwdef struct TanEtAl2018MixingLength{T} <: AbstractParameters
       Cᴸᵟ :: T = 1.0
       Cᴸʷ :: T = 0.4
    Cᵃunst :: T = -100.0
    Cᵃstab :: T = 2.7
    Cⁿunst :: T = 0.2
    Cⁿstab :: T = -1.0
end

@inline ζ(Ca, Qb, u★, z) = Ca * Qb / u★^3 * z

@inline function mixing_length(m::Model{<:TanEtAl2018MixingLength}, i)
    if isunstable(m)
        Cκ, Ca, Cn = m.mixing_length.Cᴸʷ, m.mixing_length.Cᵃunst, m.mixing_length.Cⁿunst
        ℓᶻ = @inbounds Cκ * m.grid.zc[i] * (1 - ζ(Ca, m.state.Qb, u★(m)^3, m.grid.zc[i]))^Cn
    else
        Cκ, Ca, Cn = m.mixing_length.Cᴸʷ, m.mixing_length.Cᵃstab, m.mixing_length.Cⁿstab
        ℓᶻ = @inbounds Cκ * m.grid.zc[i] * (1 - ζ(Ca, m.state.Qb, u★(m)^3, m.grid.zc[i]))^Cn
    end

    ℓᵟ = m.mixing_length.Cᴸᵟ * Δf(m.grid, i)
    ℓ = max(ℓᶻ, ℓᵟ)

    return ℓ
end
=#


text:
function assembly_dir()
    dir = joinpath(opengene_datadir(), "assembly")
    if !isdir(dir)
        mkpath(dir)
    end
    return dir
end

const human_genomes = Dict(
    "hg38" => Dict(
        "localfile" => joinpath(assembly_dir(), "hg38.chromFa.tar.gz"),
        "source" => "http://hgdownload.cse.ucsc.edu/goldenPath/hg38/bigZips/hg38.chromFa.tar.gz",
        "sha1" => "f459b51d6440f7342f3ddb38c33a1f945ded7cf2",
        "subdir" => "chroms"
    ),
    "hg19" => Dict(
        "localfile" => joinpath(assembly_dir(), "hg19.chromFa.tar.gz"),
        "source" => "http://hgdownload.cse.ucsc.edu/goldenPath/hg19/bigZips/chromFa.tar.gz",
        "sha1" => "eae3720102935210a10c184d68e3024ce05b18a0",
        "subdir" => ""
    ),
)


text:
module RNG

import ..Tagging: hastag, tag
using Random: AbstractRNG

export tagrng, rng

rng(t) = t.tags.rng
hasrng(ω) = hastag(ω, Val{:rng})
tagrng(ω, rng::AbstractRNG) = tag(ω, (rng = rng,))

end

max_stars_repo_name: zenna/expect

max_issues_repo_name: zenna/expect

max_forks_repo_name: zenna/expect


text:
module TestEvalWindow

using Gtk, Gtk.ShortNames, Gtk.GConstants
using ..Ahorn, Maple

evalWindow = nothing

function evalCode(button, textField)
    text = Ahorn.getTextViewText(textField)

    @Ahorn.catchall begin
        expr = Meta.parse("begin;" * strip(text) * "; end")
        res = Base.eval(Ahorn, expr)

        if res !== nothing
            println(res)
        end
    end
end

function spawnWindowIfAbsent!()
    if evalWindow === nothing
        global evalWindow = createWindow()
    end
end

function hideEvalWindow(widget=nothing, event=nothing)
    spawnWindowIfAbsent!()
    visible(evalWindow, false)

    return true
end

function showEvalWindow(widget=nothing, event=nothing)
    spawnWindowIfAbsent!()
    visible(evalWindow, true)
    present(evalWindow)

    return true
end

function createWindow()
    evalWindow = Window("$(Ahorn.baseTitle) - Test Console", 720, 480, true, icon = Ahorn.windowIcon, gravity = GdkGravity.GDK_GRAVITY_CENTER
    ) |> (Frame() |> (evalBox = Box(:v)))

    # Hide window instead of destroying it
    signal_connect(hideEvalWindow, evalWindow, "delete_event")

    evalGrid = Ahorn.Grid()
    evalInputField = TextView(
        vexpand=true,
        hexpand=true,
        monospace=true
    )

    evalButton = Button("Eval", hexpand=true)
    signal_connect(widget -> evalCode(evalButton, evalInputField), evalButton, "clicked")

    scrollableInputField = ScrolledWindow(vexpand=true, hexpand=true)
    push!(scrollableInputField, evalInputField)

    evalGrid[1, 1] = scrollableInputField
    evalGrid[1, 2] = evalButton

    push!(evalBox, evalGrid)
    showall(evalWindow)

    return evalWindow
end

end

max_stars_repo_name: mwhatters/Ahorn

max_issues_repo_name: mwhatters/Ahorn

max_forks_repo_name: mwhatters/Ahorn


text:
## Copyright (c) 2013 Miguel Bazdresch
##
## This file is distributed under the 2-clause BSD License.

# This file contains configuration-related functions and types

# default term file string
const tmpprefix = randstring(8)

# Default font, size and background for each supported terminal
const TerminalDefaults = Dict("wxt" => Dict(:font       => "Sans,10",
                                            :size       => "640,384",
                                            :background => "white"),
                              "qt" => Dict(:font       => "Sans,9",
                                           :size       => "640,480",
                                           :background => ""),
                              "x11" => Dict(:font       => "",
                                            :size       => "640,480",
                                            :background => ""),
                              "aqua" => Dict(:font       => "Times-Roman,14",
                                             :size       => "846,594",
                                             :background => ""),
                              "dumb" => Dict(:font       => "",
                                             :size       => "79,24",
                                             :background => ""),
                              "sixelgd" => Dict(:font       => "Sans,12",
                                                :size       => "640,480",
                                                :background => "white"),
                              "svg" => Dict(:font       => "Arial,12",
                                            :size       => "640,384",
                                            :background => "white"),
                              "gif" => Dict(:font       => "Sans,12",
                                            :size       => "640,480",
                                            :background => "white"),
                              "pngcairo" => Dict(:font       => "Sans,12",
                                                 :size       => "640,480",
                                                 :background => "white"),
                              "pdfcairo" => Dict(:font       => "Sans,12",
                                                 :size       => "5,3",
                                                 :background => "white"),
                              "epscairo" => Dict(:font       => "Sans,12",
                                                 :size       => "5,3",
                                                 :background => "white"),
                              "epslatex" => Dict(:font       => "Sans,12",
                                                 :size       => "5,3",
                                                 :background => "white"),
                              "cairolatex" => Dict(:font       => "Sans,12",
                                                 :size         => "5,3",
                                                 :background   => "white"))

# Dicts to store user-specified configuration
default_config() = Dict(:mode => IsJupyterOrJuno ? "ijulia" : "normal",
                        :timeouts => Dict(:stdout_timeout => Sys.isunix() ? 2 : 20,
                                          :stderr_timeout => Sys.isunix() ? 5 : 20),
                        :debug => false,
                        :term => Dict(:terminal => IsJupyterOrJuno ? "svg" : "qt",
                                      :font => "",
                                      :size => "",
                                      :background => "",
                                      :termopts => ""),
                        :axes => Dict(:axis => "",
                                      :xrange => "",
                                      :yrange => "",
                                      :zrange => "",
                                      :fillstyle => "",
                                      :grid => "",
                                      :boxwidth => "",
                                      :xzeroaxis => "",
                                      :yzeroaxis => "",
                                      :zzeroaxis => "",
                                      :keyoptions => "",
                                      :palette => "",
                                      :onlyimpulses => false,
                                      :output => ""),
                        :curve => Dict(:plotstyle => "",
                                       :linecolor => "",
                                       :linewidth => "",
                                       :linestyle => "",
                                       :pointtype => "",
                                       :pointsize => "",
                                       :fillcolor => "",
                                       :fillstyle => ""),
                        :print => Dict(:print_term => "pdfcairo",
                                       :print_termopts => "",
                                       :print_font => "",
                                       :print_size => "",
                                       :print_linewidth => "",
                                       :print_background => ""))
*
# Set any of Gaston's configuration variables
function set(;reset = false, terminal=config[:term][:terminal],
             mode = config[:mode], kw...)
    global config

    if reset
        config = default_config()
        return nothing
    end

    t = terminal
    mode == "ijulia" && (t = "svg")
    mode == "null" && (t = "dumb")
    if mode == "normal"
        terminal == "pdf" && (t = "pdfcairo")
        terminal == "pnf" && (t = "pnfcairo")
        terminal == "eps" && (t = "epscairo")
    end
    valid_terminal(t)
    config[:term][:terminal] = t
    config[:mode] = mode

    for k in keys(kw)
        if k == :debug
            kw[k] isa Bool && (config[:debug] = kw[k]; continue)
            throw(DomainError("argument to debug must be Bool"))
        end
        k == :plotstyle && valid_plotstyle(kw[k])
        k == :linestyle && valid_linestyle(kw[k])
        k == :pointtype && valid_pointtype(kw[k])
        k == :axis && valid_axis(kw[k])
        k == :xrange && valid_range(kw[k])
        k == :yrange && valid_range(kw[k])
        k == :zrange && valid_range(kw[k])
        flag = true
        for i in [:timeouts, :term, :axes, :curve, :print]
            c = config[i]
            haskey(c, k) && (flag=false; c[k] = string(kw[k]))
        end
        flag && throw(ArgumentError("$k is an invalid setting"))
    end

    return nothing
end

### Encode terminal capabilities
# supports multiple windows
const term_window = ["qt", "wxt", "x11", "aqua"]
# outputs text
const term_text = ["dumb", "sixelgd"]
# outputs to a file
const term_file = ["svg", "gif", "pngcairo", "pdfcairo", "epscairo",
                   "epslatex", "cairolatex"]
# supports size
const term_sup_size = ["qt", "wxt", "x11", "sixelgd", "svg", "gif",
                       "dumb", "pngcairo", "pdfcairo", "epscairo",
                       "epslatex", "cairolatex"]
# supports font
const term_sup_font = ["qt", "wxt", "x11", "aqua", "sixelgd", "svg",
                       "gif","pngcairo", "pdfcairo", "epscairo",
                       "epslatex", "cairolatex"]
# supports background color
const term_sup_bkgnd = ["sixelgd", "svg", "wxt", "gif", "pdfcairo",
                        "pngcairo", "epscairo", "epslatex", "cairolatex"]

# List of valid configuration values
const supported_terminals = ["", "qt", "wxt", "x11", "aqua", "dumb", "sixelgd",
                             "svg", "gif", "pngcairo", "pdfcairo", "epscairo",
                             "epslatex", "cairolatex"]
const supported_2Dplotstyles = ["", "lines", "linespoints", "points",
                                "impulses", "boxes", "errorlines", "errorbars",
                                "dots", "steps", "fsteps", "fillsteps",
                                "financebars"]
const supported_3Dplotstyles = ["", "lines", "linespoints", "points", "labels",
                                "impulses", "pm3d", "image", "rgbimage", "dots"]
const supported_plotstyles = vcat(supported_2Dplotstyles, supported_3Dplotstyles)
const supported_axis = ["", "normal", "semilogx", "semilogy", "semilogz",
                        "loglog"]
const supported_pointtypes = ["", "+", "x", "*", "esquare", "fsquare",
                          "ecircle", "fcircle", "etrianup", "ftrianup",
                          "etriandn", "ftriandn", "edmd", "fdmd"]
# List of plotstyles that support points
const ps_sup_points = ["linespoints", "points"]

#
# Validation functions
#

function valid_file_term(s)
    s ∈ term_file && return true
    throw(DomainError(s,"supported terminals are: $term_file"))
end

function valid_terminal(s)
    s ∈ supported_terminals && return true
    throw(DomainError(s,"supported terminals are: $supported_terminals"))
end
function valid_plotstyle(s)
    s ∈ supported_plotstyles && return true
    throw(DomainError(s,"supported plotstyles are: $supported_plotstyles"))
end
function valid_2Dplotstyle(s)
    s ∈ supported_2Dplotstyles && return true
    throw(DomainError(s,"supported 2-D plotstyles are: $supported_2Dplotstyles"))
end
function valid_3Dplotstyle(s)
    s ∈ supported_3Dplotstyles && return true
    throw(DomainError(s,"supported 3-D plotstyles are: $supported_3Dplotstyles"))
end
function valid_pointtype(s)
    isempty(s) && return true
    length(s) == 1 && return true
    s ∈ supported_pointtypes && return true
    throw(DomainError(s,"supported point types are: $supported_pointtypes or single-character strings"))
end
function valid_numeric(s)
    isempty(s) && return true
    ss = tryparse(Float64,s)
    (ss != nothing && ss >= 0) && return true
    throw(DomainError(s,"not a valid numeric argument"))
end
function valid_axis(s)
    s ∈ supported_axis && return true
    throw(DomainError(s,"supported axis types are: $supported_axis"))
end

function valid_linestyle(s)
    invalid = false
    s == "" && return true # allow empty string
    c = collect(s)
    # make sure only allowed characters are passed
    issubset(c, Set([' ', '-', '_', '.'])) || (invalid = true)
    # but do not allow spaces only
    unique(c) != [' '] || (invalid = true)
    invalid && throw(DomainError(s,"line style pattern accepts: space, dash, underscore and dot"))
    return true
end

# Validate that a given range follows gnuplot's syntax.
function valid_range(s::String)
    s == "" && return true # allow empty strings
    # floating point, starting with a dot
    f1 = "[-+]?\\.\\d+([eE][-+]?\\d+)?"
    # floating point, starting with a digit
    f2 = "[-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?"
    # floating point
    f = "($f1|$f2)"
    # autoscale directive (i.e. `*` surrounded by
    # optional bounds lb < * < ub)
    as = "(($f\\s*<\\s*)?\\*(\\s*<\\s*$f)?)"
    # full range item: a floating point, or an
    # autoscale directive, or nothing
    it = "(\\s*($as|$f)?\\s*)"

    # empty range
    er = "\\[\\s*\\]"
    # full range: two colon-separated items
    fr = "\\[$it:$it\\]"

    # range regex
    rx = Regex("^\\s*($er|$fr)\\s*\$")

    if occursin(rx, s)
        return true
    end

    throw(DomainError(s,"range must have have the form of [x:y]"))
end

# Validate coordinates
function valid_coords(x,y;err=ErrorCoords(),fin=FinancialCoords())
    invalid = false
    length(x) != length(y) && (invalid = true)
    if err != nothing
        length(x) != length(err.ylow) && (invalid = true)
        (!isempty(err.yhigh) && length(x) != length(err.yhigh)) && (invalid = true)
    end
    if fin != nothing
        lx = length(x)
        lx != length(fin.open) && (invalid = true)
        lx != length(fin.low) && (invalid = true)
        lx != length(fin.high) && (invalid = true)
        lx != length(fin.close) && (invalid = true)
    end

    invalid && throw(DimensionMismatch("input vectors must have the same number of elements."))

    return true

end

# Define plot argument synonyms
const ps_syn = [:plotstyle, :ps]
const lc_syn = [:linecolor, :lc]
const lw_syn = [:linewidth, :lw]
const ls_syn = [:linestyle, :ls]
const pt_syn = [:pointtype, :pt, :marker, :mk]
const pz_syn = [:pointsize, :ps, :markersize, :mks]
const fc_syn = [:fillcolor, :fc]
const fs_syn = [:fillstyle, :fs]
const bw_syn = [:boxwidth, :bw]
const ko_syn = [:keyoptions, :ko]
const bg_syn = [:background, :bg]
const of_syn = [:output, :of, :filename]
const zax_syn = [:xzeroaxis, :xza]
const zay_syn = [:yzeroaxis, :yza]
const zaz_syn = [:zzeroaxis, :zza]

const syn = [ps_syn, lc_syn, lw_syn, ls_syn, pt_syn, pz_syn,
             fc_syn, fs_syn, bw_syn, ko_syn, bg_syn, of_syn,
             zax_syn, zay_syn, zaz_syn]


text:
using CatViews

import LinearAlgebra: dot, norm
import RigidBodyTools: view
import CartesianGrids: integrate
import Base: ones, copyto!
export points, normals, areas

"""
    points(b::Body/BodyList)

Return `VectorData` filled with the coordinates of the points
associated with `b`.
"""
@inline points(b::Union{Body,BodyList}) = VectorData(collect(b))

"""
    normals(b::Body/BodyList)

Return `VectorData` filled with the normal vectors (via midpoint rule)
associated with `b`.
"""
function normals(b::Union{Body,BodyList})
  nrm = VectorData(numpts(b))
  nx, ny = normalmid(b)
  nrm.u .= nx
  nrm.v .= ny
  nrm
end

"""
    areas(b::Body/BodyList)

Return `ScalarData` filled with the 1-d areas (via midpoint rule)
associated with `b`.
"""
areas(b::Union{Body,BodyList}) = ScalarData(dlengthmid(b))

## Tools for partitioned operations via body lists

"""
    view(v::VectorData,bl::BodyList,i::Int)

Provide a view of the range of values in `VectorData` `v`, corresponding to the
points of the body with index `i` in a BodyList `bl`.
"""
@inline view(v::VectorData,bl::BodyList,i::Int) = CatView(view(v.u,bl,i),view(v.v,bl,i))

"""
    copyto!(u::PointData,v::PointData,bl::BodyList,i::Int)

Copy the data in the elements of `v` associated with body `i` in body list `bl` to
the corresponding elements in `u`. These data must be of the same type (e.g.,
`ScalarData` or `VectorData`) and have the same length.
""" copyto!(u::PointData,v::PointData,bl::BodyList,i::Int)

for f in [:ScalarData,:VectorData]
  @eval function copyto!(u::$f{N},v::$f{N},bl::BodyList,i::Int) where {N}
    ui = view(u,bl,i)
    vi = view(v,bl,i)
    ui .= vi
    return u
  end
end

"""
    copyto!(u::ScalarData,v::AbstractVector,bl::BodyList,i::Int)

Copy the data in `v` to the elements in `u` associated with body `i` in body list `bl`.
`v` must have the same length as this subarray of `u` associated with `i`.
"""
function copyto!(u::ScalarData{N},v::AbstractVector,bl::BodyList,i::Int) where {N}
    ui = view(u,bl,i)
    @assert length(v) == length(ui) "Lengths are incompatible for copyto!"
    ui .= v
    return u
end

### GRID OPERATIONS

## Dot, norm, integrate

"""
    dot(u1::GridData,u2::GridData,g::PhysicalGrid)

Return the inner product between `u1` and `u2` weighted by the volume (area)
of the cell in grid `g`.
"""
function dot(u1::GridData{NX,NY},u2::GridData{NX,NY},g::PhysicalGrid) where {NX,NY}
    @assert (NX,NY) == size(g)
    dot(u1,u2)*volume(g)
end

"""
    norm(u::GridData,g::PhysicalGrid)

Return the norm of `u`, weighted by the volume (area)
of the cell in grid `g`.
"""
norm(u::GridData,g::PhysicalGrid) = sqrt(dot(u,u,g))

"""
    ones(u::ScalarGridData)

Returns `ScalarGridData` of the same type as `u` filled with ones.
"""
function ones(u::ScalarGridData)
  o = similar(u)
  o .= 1
  o
end

"""
    ones(u::VectorGridData,dim::Int)

Returns `VectorGridData` of the same type as `u`, filled with ones in
component `dim`.
"""
function ones(u::VectorGridData,dim::Integer)
  o = zero(u)
  ocomp = getfield(o,dim+1) # offset
  ocomp .= 1
  o
end

### POINT OPERATIONS

## Inner products

"""
    dot(u1::PointData,u2::PointData,ds::ScalarData)

Return the inner product between `u1` and `u2`, weighted by `ds`.
"""
dot(u1::ScalarData{N},u2::ScalarData{N},ds::ScalarData{N}) where {N} = dot(u1,ds∘u2)

dot(u1::VectorData{N},u2::VectorData{N},ds::ScalarData{N}) where {N} =
    dot(u1.u,u2.u,ds) + dot(u1.v,u2.v,ds)

"""
    dot(u1::PointData,u2::PointData,ds::ScalarData,bl::BodyList,i)

Return the inner product between `u1` and `u2`, weighted by `ds`,
for only the data associated with body `i` in body list `bl`.
"""
dot(u1::ScalarData{N},u2::ScalarData{N},ds::ScalarData{N},bl::BodyList,i::Int) where {N} =
    dot(ScalarData(view(u1,bl,i)),ScalarData(view(u2,bl,i)),ScalarData(view(ds,bl,i)))

dot(u1::VectorData{N},u2::VectorData{N},ds::ScalarData{N},bl::BodyList,i::Int) where {N} =
    dot(ScalarData(view(u1.u,bl,i)),ScalarData(view(u2.u,bl,i)),ScalarData(view(ds,bl,i))) +
    dot(ScalarData(view(u1.v,bl,i)),ScalarData(view(u2.v,bl,i)),ScalarData(view(ds,bl,i)))

# Extend the inner products that do not scale with surface areas.
dot(u1::ScalarData{N},u2::ScalarData{N},bl::BodyList,i::Int) where {N} =
    dot(ScalarData(view(u1,bl,i)),ScalarData(view(u2,bl,i)))

dot(u1::VectorData{N},u2::VectorData{N},bl::BodyList,i::Int) where {N} =
    dot(ScalarData(view(u1.u,bl,i)),ScalarData(view(u2.u,bl,i))) +
    dot(ScalarData(view(u1.v,bl,i)),ScalarData(view(u2.v,bl,i)))

## Norms

"""
    norm(u::PointData,ds::ScalarData)

Return the norm of `u`, weighted by `ds`.
"""
norm(u::PointData{N},ds::ScalarData{N}) where {N} = sqrt(dot(u,u,ds))

"""
    norm(u::PointData,ds::ScalarData,bl::BodyList,i)

Return the norm of `u`, weighted by `ds`, for body `i` in body list `bl`
"""
norm(u::PointData{N},ds::ScalarData{N},bl::BodyList,i::Int) where {N} = sqrt(dot(u,u,ds,bl,i))

# Extend the norm that does not scale with surface areas.
norm(u::PointData{N},bl::BodyList,i::Int) where {N} = sqrt(dot(u,u,bl,i))

## Integrals

"""
    integrate(u::PointData,ds::ScalarData)

Calculate the discrete surface integral of data `u`, using the
surface element areas in `ds`. This uses trapezoidal rule quadrature.
If `u` is `VectorData`, then this returns a vector of the integrals in
each coordinate direction.
"""
integrate(u::ScalarData{N},ds::ScalarData{N}) where {N} = dot(u,ds)

integrate(u::VectorData{N},ds::ScalarData{N}) where {N} = [dot(u.u,ds),dot(u.v,ds)]

"""
    integrate(u::PointData,ds::ScalarData,bl::BodyList,i::Int)

Calculate the discrete surface integral of scalar data `u`, restricting the
integral to body `i` in body list `bl`, using the
surface element areas in `ds`. This uses trapezoidal rule quadrature.
If `u` is `VectorData`, then this returns a vector of the integrals in
each coordinate direction.
"""
integrate(u::ScalarData{N},ds::ScalarData{N},bl::BodyList,i::Int) where {N} = dot(u,ds,bl,i)

integrate(u::VectorData{N},ds::ScalarData{N},bl::BodyList,i::Int) where {N} = [dot(u.u,ds,bl,i); dot(u.v,ds,bl,i)]

"""
    ones(u::ScalarData)

Returns `ScalarData` of the same type as `u` filled with ones.
"""
function ones(u::ScalarData{N}) where {N}
  o = similar(u)
  o .= 1
  o
end

"""
    ones(u::VectorData,dim::Int)

Returns `VectorData` of the same type as `u`, filled with ones in
component `dim`.
"""
function ones(u::VectorData{N},dim::Integer) where {N}
  o = zero(u)
  ocomp = getfield(o,dim+1) # offset
  ocomp .= 1
  o
end


text:
using Plots; gr()
using DifferentialEquations

# Lorenz example from documentation
function g(du,u,p,t)
 du[1] = p[1]*(u[2]-u[1])
 du[2] = u[1]*(p[2]-u[3]) - u[2]
 du[3] = u[1]*u[2] - p[3]*u[3]
end
u0 = [1.0;0.0;0.0]
tspan = (0.0,180.0)
p = [10.0,28.0,8/3]
prob = ODEProblem(g,u0,tspan,p)

sollor = solve(prob,reltol=1e-14,abstol=1e-14)

plot(sollor,title="Lorenz System",label=false, xaxis="Time (x)")

# Get the results
u1 = [s[1] for s in sollor.u];
u2 = [s[2] for s in sollor.u];
u3 = [s[3] for s in sollor.u];
t = sollor.t

plot(t,u1, xaxis=false, yaxis=false, legend=false)
plot!(t,u2, xaxis=false, yaxis=false, legend=false)
plot!(t,u3, xaxis=false, yaxis=false, legend=false)
plot(u1,u2, xaxis=false, yaxis=false, legend=false)
plot(u1,u3, xaxis=false, yaxis=false, legend=false)

# Logistic model as system of 2 ODEs
# Cell = u[1]
# Agar = u[2]

function g(du,u,p,t)
 du[1] = p[1]*u[1]*u[2]
 du[2] = -p[1]*u[1]*u[2]
end
u0 = [0.1;1.0]
tspan = (0.0,10.0)
p = [5.0]
prob = ODEProblem(g,u0,tspan,p)

sollogistic = solve(prob,reltol=1e-8,abstol=1e-8)
plot(sollogistic)

using Plots
using DifferentialEquations

function g(du,u,p,t)
 du[1] = p[1]*(u[2]-u[1])
 du[2] = u[1]*(p[2]-u[3]) - u[2]
 du[3] = u[1]*u[2] - p[3]*u[3]
end
u0 = [1.0;0.0;0.0]
tspan = (0.0,180.0)
p = [10.0,28.0,8/3]
prob = ODEProblem(g,u0,tspan,p)

sollor = solve(prob,reltol=1e-14,abstol=1e-14)

t = sollor.t
u1 = [s[1] for s in sollor.u];
u2 = [s[2] for s in sollor.u];
u3 = [s[3] for s in sollor.u];
# Get the results
plotlzsys=plot(t,u1, xaxis=false, yaxis=false, legend=false)
plot!(t,u2, xaxis=false, yaxis=false, legend=false)
plot!(t,u3, xaxis=false, yaxis=false, legend=false)

plotlz = plot(u1,u2, xaxis=false, yaxis=false, legend=false)
#plot(u1,u3, xaxis=false, yaxis=false, legend=false)

plot(plotlzsys,plotlz,layout=(1,2),legend=false,linewidth=3 )


text:
using RedPitayaDAQServer
using PyPlot

# obtain the URL of the RedPitaya
include("config.jl")

rp = RedPitayaCluster([URLs[1]])

dec = 64
modulus = 4864
base_frequency = 125000000
samples_per_period = div(modulus, dec)
periods_per_frame = 5

clearSequence(rp)
decimation(rp, dec)
samplesPerPeriod(rp, samples_per_period)
periodsPerFrame(rp, periods_per_frame)
passPDMToFastDAC(master(rp), true)

modeDAC(rp, "STANDARD")
ramWriterMode(rp, "TRIGGERED")
triggerMode(rp, "EXTERNAL")

masterTrigger(rp, false)

frequencyDAC(rp, 1, 1, base_frequency / 4864)
signalTypeDAC(rp, 1 , "SINE")
amplitudeDAC(rp, 1, 1, 0.9)
offsetDAC(master(rp), 1, 0)
phaseDAC(rp, 1, 1, 0.0 )

samplesPerSlowDACStep(rp, div(4800, dec))
numSlowDACChan(master(rp), 1)
seq1 = PauseSequence(nothing, periods_per_frame, 1, true)
seq2 = PauseSequence(nothing, periods_per_frame, 1, true)
seq3 = PauseSequence(nothing, periods_per_frame, 1, true)
seq4 = PauseSequence(nothing, periods_per_frame, 1, true)
seq5 = PauseSequence(nothing, periods_per_frame, 1)
appendSequence(master(rp), seq1)
appendSequence(master(rp), seq2)
appendSequence(master(rp), seq3)
appendSequence(master(rp), seq4)
appendSequence(master(rp), seq5)
prepareSequence(master(rp))

startADC(rp)
masterTrigger(rp, true)

samples1 = readPipelinedSamples(rp, 0, 5 * div(4800, dec))
samples2 = readPipelinedSamples(rp, (length(seq1) + start(seq2)) * div(4800, dec), 5 * div(4800, dec))
samples3 = readPipelinedSamples(rp, (length(seq1) + length(seq2) + start(seq3)) * div(4800, dec), 5 * div(4800, dec))
samples4 = readPipelinedSamples(rp, (length(seq1) + length(seq2) + length(seq3) + start(seq4)) * div(4800, dec), 5 * div(4800, dec))
samples5 = readPipelinedSamples(rp, (length(seq1) + length(seq2) + length(seq3) + length(seq4) + start(seq5)) * div(4800, dec), 5 * div(4800, dec))
samplesAll = readPipelinedSamples(rp, 0, (length(seq1) + length(seq2) + length(seq3) + length(seq4) + length(seq5)) * div(4800, dec))
stopADC(rp)
masterTrigger(rp, false)
clearSequence(rp)

fig = figure(1)
clf()
subplot(3, 1, 1)
plot(vec(samples1[1, :]))
plot(vec(samples2[1, :]))
subplot(3, 1, 2)
#plot(vec(samples1[1, :]))
plot(vec(samples2[1, :]))
#subplot(6, 1, 3)
plot(vec(samples3[1, :]))
#subplot(6, 1, 4)
plot(vec(samples4[1, :]))
#subplot(6, 1, 5)
plot(vec(samples5[1, :]))
subplot(3, 1, 3)
plot(vec(samplesAll[1, :]))
fig

max_stars_repo_name: tknopp/RedPitayaDAQServer

max_issues_repo_name: tknopp/RedPitayaDAQServer

max_forks_repo_name: tknopp/RedPitayaDAQServer


text:
function warning_callback(message::String)
    global TEST_CALLBACK = true
    error("checking that error are supported")
end

@testset "Errors" begin
    err = ChemfilesError("oops")
    iobuf = IOBuffer()
    show(iobuf, err)
    @test String(iobuf.data[1:(19 + length(err.message))]) == "\"Chemfiles error: oops\""

    Chemfiles.clear_errors()
    @test Chemfiles.last_error() == ""

    remove_chemfiles_warning() do
        @test_throws ChemfilesError Residue(Topology(), 3)
    end
    @test_throws UndefVarError TEST_CALLBACK == false

    @test Chemfiles.last_error() == "residue index out of bounds in topology: we have 0 residues, but the index is 3"

    Chemfiles.clear_errors()
    @test Chemfiles.last_error() == ""

    Chemfiles.set_warning_callback(warning_callback)
    @test_throws ChemfilesError Residue(Topology(), 3)
    @test TEST_CALLBACK == true

    Chemfiles.set_warning_callback(Chemfiles.__default_warning_callback)
end

@testset "Configuration" begin
    config = joinpath(@__DIR__, "data", "config.toml")
    Chemfiles.add_configuration(config)

    trajectory = joinpath(@__DIR__, "data", "water.xyz")
    frame = read(Trajectory(trajectory))

    @test name(Atom(frame, 9)) == "Oz"
    @test type(Atom(frame, 9)) == "F"
end

@testset "Format list" begin
    for metadata in Chemfiles.format_list()
        if metadata.name == "XYZ"
            @test metadata.description == "XYZ text format"
            @test metadata.extension == ".xyz"
            @test metadata.reference == "https://openbabel.org/wiki/XYZ"

            @test metadata.read == true
            @test metadata.write == true
            @test metadata.memory == true
            @test metadata.positions == true
            @test metadata.velocities == false
            @test metadata.unit_cell == true
            @test metadata.atoms == true
            @test metadata.bonds == false
            @test metadata.residues == false
        end

        if metadata.name == "LAMMPD Data"
            @test metadata.extension === nothing
        end
    end
end

@testset "Guess format" begin
    @test Chemfiles.guess_format("file.xyz.gz") == "XYZ / GZ"
    @test Chemfiles.guess_format("file.nc") == "Amber NetCDF"
end


text:
##########################################################################################
######################### Este archivo contiene las funciones que son ####################
######################### usadas para que los jugadores tiren         ####################
##########################################################################################

# Esta función ejecuta el tiro en una celda libre
function Tiro(J::Jugador, G::Gato, loc::Int64, R::Array{Int8, 1})

    if G.tablero[loc] == 0

        G.tablero[loc] = R[J.num]

        return true
    else
        println("Celda ya ocupada, ¡elige otra!")
        return false
    end
end

# Esta función ejecuta el turno entero de un jugador
function Turno(J::Jugador, Tablero::Gato, tiro::Int64, gane::Bool, R::Array{Int8,1})

    if gane == false  # si no ha ganado...
        num = J.num

        check = false
        while check == false

            loc = Pregunta_tiro(num)    # Se le pregunta donde quiere tirar
            check = Tiro(J, Tablero, loc, R)  # Si tiró en una celda libre
        end                                   # entonces se checa si es un tiro ganador

        if  Ganar(Tablero, J, R) == true      # y si sí lo es... se anunca al ganador!
            println("¡Miau $num ha ganado!")
            return true
        else
            return false
        end
    end
end

####### Estos arreglos son las distintas combinaciones para las cuales se puede ganar

Comb_h = [(1, 2, 3), (4, 5, 6), (7, 8, 9)]  # combinaciones horizontales
Comb_v = [(1, 4, 7), (2, 5, 8), (3, 6, 9)]  # combinaciones verticales
Comb_d = [(1, 5, 9), (3, 5, 7)]             # combinaciones diagonales

Combinaciones = [Comb_h; Comb_v; Comb_d]    # juntamos todas las combinaciones

##### Esta función checa si hay alguna combinación ganadora
function Ganar(G::Gato, J::Jugador, R::Array{Int8, 1})
    for (loc1, loc2, loc3) in Combinaciones
        if G.tablero[loc1] == G.tablero[loc2] == G.tablero[loc3] == R[J.num]
            J.marcador += 1 # si hay un ganador entonces se suma uno a su marcador
            return true
        end
    end
end


text:
# tests
using NearestNeighborDescent
using NearestNeighborDescent.KNNGraphs
using LightGraphs
using DataStructures
using Distances
using Test
using Random
using Statistics

@testset "KNN Graph tests" begin
    include("knn_graph/heap_graph_tests.jl")
    include("knn_graph/edge_tests.jl")
    include("knn_graph/utils_tests.jl")
end
include("utils_tests.jl")
include("descent_tests.jl")
include("search_tests.jl")