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

baremodule Base

using Core.Intrinsics, Core.IR

const is_primary_base_module = ccall(:jl_module_parent, Ref{Module}, (Any,), Base) === Core.Main
ccall(:jl_set_istopmod, Cvoid, (Any, Bool), Base, is_primary_base_module)

# Try to help prevent users from shooting them-selves in the foot
# with ambiguities by defining a few common and critical operations
# (and these don't need the extra convert code)
getproperty(x::Module, f::Symbol) = getfield(x, f)
setproperty!(x::Module, f::Symbol, v) = setfield!(x, f, v)
getproperty(x::Type, f::Symbol) = getfield(x, f)
setproperty!(x::Type, f::Symbol, v) = setfield!(x, f, v)

getproperty(Core.@nospecialize(x), f::Symbol) = getfield(x, f)
setproperty!(x, f::Symbol, v) = setfield!(x, f, convert(fieldtype(typeof(x), f), v))

function include_relative end
function include(mod::Module, path::AbstractString)
    local result
    if INCLUDE_STATE === 1
        result = _include1(mod, path)
    elseif INCLUDE_STATE === 2
        result = _include(mod, path)
    elseif INCLUDE_STATE === 3
        result = include_relative(mod, path)
    end
    result
end
function include(path::AbstractString)
    local result
    if INCLUDE_STATE === 1
        result = _include1(Base, path)
    elseif INCLUDE_STATE === 2
        result = _include(Base, path)
    else
        # to help users avoid error (accidentally evaluating into Base), this is not allowed
        error("Base.include(string) is discontinued, use `include(fname)` or `Base.include(@__MODULE__, fname)` instead.")
    end
    result
end
const _included_files = Array{Tuple{Module,String},1}()
function _include1(mod::Module, path)
    Core.Compiler.push!(_included_files, (mod, ccall(:jl_prepend_cwd, Any, (Any,), path)))
    Core.include(mod, path)
end
let SOURCE_PATH = ""
    # simple, race-y TLS, relative include
    global _include
    function _include(mod::Module, path)
        prev = SOURCE_PATH
        path = normpath(joinpath(dirname(prev), path))
        push!(_included_files, (mod, abspath(path)))
        SOURCE_PATH = path
        result = Core.include(mod, path)
        SOURCE_PATH = prev
        result
    end
end
INCLUDE_STATE = 1 # include = Core.include

include("coreio.jl")

eval(x) = Core.eval(Base, x)
eval(m::Module, x) = Core.eval(m, x)

VecElement{T}(arg) where {T} = VecElement{T}(convert(T, arg))
convert(::Type{T}, arg)  where {T<:VecElement} = T(arg)
convert(::Type{T}, arg::T) where {T<:VecElement} = arg

# init core docsystem
import Core: @doc, @__doc__, WrappedException, @int128_str, @uint128_str, @big_str, @cmd
if isdefined(Core, :Compiler)
    import Core.Compiler.CoreDocs
    Core.atdoc!(CoreDocs.docm)
end

include("exports.jl")

if false
    # simple print definitions for debugging. enable these if something
    # goes wrong during bootstrap before printing code is available.
    # otherwise, they just just eventually get (noisily) overwritten later
    global show, print, println
    show(io::IO, x) = Core.show(io, x)
    print(io::IO, a...) = Core.print(io, a...)
    println(io::IO, x...) = Core.println(io, x...)
end

"""
    time_ns()

Get the time in nanoseconds. The time corresponding to 0 is undefined, and wraps every 5.8 years.
"""
time_ns() = ccall(:jl_hrtime, UInt64, ())

start_base_include = time_ns()

## Load essential files and libraries
include("essentials.jl")
include("ctypes.jl")
include("gcutils.jl")
include("generator.jl")
include("reflection.jl")
include("options.jl")

# core operations & types
include("promotion.jl")
include("tuple.jl")
include("pair.jl")
include("traits.jl")
include("range.jl")
include("expr.jl")
include("error.jl")

# core numeric operations & types
include("bool.jl")
include("number.jl")
include("int.jl")
include("operators.jl")
include("pointer.jl")
include("refvalue.jl")
include("refpointer.jl")
include("checked.jl")
using .Checked

# vararg Symbol constructor
Symbol(x...) = Symbol(string(x...))

# array structures
include("indices.jl")
include("array.jl")
include("abstractarray.jl")
include("subarray.jl")
include("views.jl")

# ## dims-type-converting Array constructors for convenience
# type and dimensionality specified, accepting dims as series of Integers
Vector{T}(::UndefInitializer, m::Integer) where {T} = Vector{T}(undef, Int(m))
Matrix{T}(::UndefInitializer, m::Integer, n::Integer) where {T} = Matrix{T}(undef, Int(m), Int(n))
Array{T,N}(::UndefInitializer, d::Vararg{Integer,N}) where {T,N} = Array{T,N}(undef, convert(Tuple{Vararg{Int}}, d))
# type but not dimensionality specified, accepting dims as series of Integers
Array{T}(::UndefInitializer, m::Integer) where {T} = Array{T,1}(undef, Int(m))
Array{T}(::UndefInitializer, m::Integer, n::Integer) where {T} = Array{T,2}(undef, Int(m), Int(n))
Array{T}(::UndefInitializer, m::Integer, n::Integer, o::Integer) where {T} = Array{T,3}(undef, Int(m), Int(n), Int(o))
Array{T}(::UndefInitializer, d::Integer...) where {T} = Array{T}(undef, convert(Tuple{Vararg{Int}}, d))
# dimensionality but not type specified, accepting dims as series of Integers
Vector(::UndefInitializer, m::Integer) = Vector{Any}(undef, Int(m))
Matrix(::UndefInitializer, m::Integer, n::Integer) = Matrix{Any}(undef, Int(m), Int(n))
# Dimensions as a single tuple
Array{T}(::UndefInitializer, d::NTuple{N,Integer}) where {T,N} = Array{T,N}(undef, convert(Tuple{Vararg{Int}}, d))
Array{T,N}(::UndefInitializer, d::NTuple{N,Integer}) where {T,N} = Array{T,N}(undef, convert(Tuple{Vararg{Int}}, d))
# empty vector constructor
Vector() = Vector{Any}(undef, 0)

# Array constructors for nothing and missing
# type and dimensionality specified
Array{T,N}(::Nothing, d...) where {T,N} = fill!(Array{T,N}(undef, d...), nothing)
Array{T,N}(::Missing, d...) where {T,N} = fill!(Array{T,N}(undef, d...), missing)
# type but not dimensionality specified
Array{T}(::Nothing, d...) where {T} = fill!(Array{T}(undef, d...), nothing)
Array{T}(::Missing, d...) where {T} = fill!(Array{T}(undef, d...), missing)

include("abstractdict.jl")

include("iterators.jl")
using .Iterators: zip, enumerate
using .Iterators: Flatten, Filter, product  # for generators

include("namedtuple.jl")

# numeric operations
include("hashing.jl")
include("rounding.jl")
using .Rounding
include("float.jl")
include("twiceprecision.jl")
include("complex.jl")
include("rational.jl")
include("multinverses.jl")
using .MultiplicativeInverses
include("abstractarraymath.jl")
include("arraymath.jl")

# define MIME"foo/bar" early so that we can overload 3-arg show
"""
    MIME

A type representing a standard internet data format. "MIME" stands for
"Multipurpose Internet Mail Extensions", since the standard was originally
used to describe multimedia attachments to email messages.

A `MIME` object can be passed as the second argument to [`show`](@ref) to
request output in that format.

# Examples
```jldoctest
julia> show(stdout, MIME("text/plain"), "hi")
"hi"
```
"""
struct MIME{mime} end

"""
    @MIME_str

A convenience macro for writing [`MIME`](@ref) types, typically used when
adding methods to `show`.
For example the syntax `show(io::IO, ::MIME"text/html", x::MyType) = ...`
could be used to define how to write an HTML representation of `MyType`.
"""
macro MIME_str(s)
    :(MIME{$(Expr(:quote, Symbol(s)))})
end
# fallback text/plain representation of any type:
show(io::IO, ::MIME"text/plain", x) = show(io, x)

# SIMD loops
include("simdloop.jl")
using .SimdLoop

# map-reduce operators
include("reduce.jl")

## core structures
include("reshapedarray.jl")
include("reinterpretarray.jl")
include("bitarray.jl")
include("bitset.jl")

if !isdefined(Core, :Compiler)
    include("docs/core.jl")
    Core.atdoc!(CoreDocs.docm)
end

# Some type
include("some.jl")

include("dict.jl")
include("abstractset.jl")
include("set.jl")

include("char.jl")
include("strings/basic.jl")
include("strings/string.jl")
include("strings/substring.jl")

# Definition of StridedArray
StridedFastContiguousSubArray{T,N,A<:DenseArray} = FastContiguousSubArray{T,N,A}
StridedReinterpretArray{T,N,A<:Union{DenseArray,StridedFastContiguousSubArray}} = ReinterpretArray{T,N,S,A} where S
StridedReshapedArray{T,N,A<:Union{DenseArray,StridedFastContiguousSubArray,StridedReinterpretArray}} = ReshapedArray{T,N,A}
StridedSubArray{T,N,A<:Union{DenseArray,StridedReshapedArray,StridedReinterpretArray},
    I<:Tuple{Vararg{Union{RangeIndex, AbstractCartesianIndex}}}} = SubArray{T,N,A,I}
StridedArray{T,N} = Union{DenseArray{T,N}, StridedSubArray{T,N}, StridedReshapedArray{T,N}, StridedReinterpretArray{T,N}}
StridedVector{T} = Union{DenseArray{T,1}, StridedSubArray{T,1}, StridedReshapedArray{T,1}, StridedReinterpretArray{T,1}}
StridedMatrix{T} = Union{DenseArray{T,2}, StridedSubArray{T,2}, StridedReshapedArray{T,2}, StridedReinterpretArray{T,2}}
StridedVecOrMat{T} = Union{StridedVector{T}, StridedMatrix{T}}

# For OS specific stuff
include(string((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "build_h.jl"))     # include($BUILDROOT/base/build_h.jl)
include(string((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "version_git.jl")) # include($BUILDROOT/base/version_git.jl)

include("osutils.jl")
include("c.jl")

# Core I/O
include("io.jl")
include("iostream.jl")
include("iobuffer.jl")

# strings & printing
include("intfuncs.jl")
include("strings/strings.jl")
include("parse.jl")
include("shell.jl")
include("regex.jl")
include("show.jl")
include("arrayshow.jl")

# multidimensional arrays
include("cartesian.jl")
using .Cartesian
include("multidimensional.jl")
include("permuteddimsarray.jl")
using .PermutedDimsArrays

include("broadcast.jl")
using .Broadcast
using .Broadcast: broadcasted, broadcasted_kwsyntax, materialize, materialize!

# define the real ntuple functions
@inline function ntuple(f::F, ::Val{N}) where {F,N}
    N::Int
    (N >= 0) || throw(ArgumentError(string("tuple length should be ≥0, got ", N)))
    if @generated
        quote
            @nexprs $N i -> t_i = f(i)
            @ncall $N tuple t
        end
    else
        Tuple(f(i) for i = 1:N)
    end
end
@inline function fill_to_length(t::Tuple, val, ::Val{N}) where {N}
    M = length(t)
    M > N && throw(ArgumentError("input tuple of length $M, requested $N"))
    if @generated
        quote
            (t..., $(fill(:val, N-length(t.parameters))...))
        end
    else
        (t..., fill(val, N-M)...)
    end
end

# missing values
include("missing.jl")

# version
include("version.jl")

# system & environment
include("sysinfo.jl")
include("libc.jl")
using .Libc: getpid, gethostname, time

const DL_LOAD_PATH = String[]
if Sys.isapple()
    push!(DL_LOAD_PATH, "@loader_path/julia")
    push!(DL_LOAD_PATH, "@loader_path")
end

include("env.jl")

# Scheduling
include("libuv.jl")
include("event.jl")
include("task.jl")
include("threads.jl")
include("lock.jl")
include("weakkeydict.jl")

# Logging
include("logging.jl")
using .CoreLogging

# functions defined in Random
function rand end
function randn end

# I/O
include("stream.jl")
include("filesystem.jl")
using .Filesystem
include("process.jl")
include("grisu/grisu.jl")
include("methodshow.jl")
include("secretbuffer.jl")

# core math functions
include("floatfuncs.jl")
include("math.jl")
using .Math
const (√)=sqrt
const (∛)=cbrt

INCLUDE_STATE = 2 # include = _include (from lines above)

# reduction along dims
include("reducedim.jl")  # macros in this file relies on string.jl
include("accumulate.jl")

# basic data structures
include("ordering.jl")
using .Order

# Combinatorics
include("sort.jl")
using .Sort

# Fast math
include("fastmath.jl")
using .FastMath

function deepcopy_internal end

# enums
include("Enums.jl")
using .Enums

# BigInts and BigFloats
include("gmp.jl")
using .GMP

for T in [Signed, Integer, BigInt, Float32, Float64, Real, Complex, Rational]
    @eval flipsign(x::$T, ::Unsigned) = +x
    @eval copysign(x::$T, ::Unsigned) = +x
end

include("mpfr.jl")
using .MPFR
big(n::Integer) = convert(BigInt,n)
big(x::AbstractFloat) = convert(BigFloat,x)
big(q::Rational) = big(numerator(q))//big(denominator(q))

include("combinatorics.jl")

# more hashing definitions
include("hashing2.jl")

# irrational mathematical constants
include("irrationals.jl")
include("mathconstants.jl")
using .MathConstants: ℯ, π, pi

# (s)printf macros
include("printf.jl")
# import .Printf

# metaprogramming
include("meta.jl")

# concurrency and parallelism
include("channels.jl")

# utilities
include("deepcopy.jl")
include("download.jl")
include("summarysize.jl")
include("errorshow.jl")

# Stack frames and traces
include("stacktraces.jl")
using .StackTraces

include("initdefs.jl")

# worker threads
include("threadcall.jl")

# code loading
include("uuid.jl")
include("loading.jl")

# misc useful functions & macros
include("util.jl")

include("asyncmap.jl")

include("multimedia.jl")
using .Multimedia

# deprecated functions
include("deprecated.jl")

# Some basic documentation
include("docs/basedocs.jl")

include("client.jl")

# Documentation -- should always be included last in sysimg.
include("docs/Docs.jl")
using .Docs
if isdefined(Core, :Compiler) && is_primary_base_module
    Docs.loaddocs(Core.Compiler.CoreDocs.DOCS)
end

end_base_include = time_ns()

if is_primary_base_module
function __init__()
    # try to ensuremake sure OpenBLAS does not set CPU affinity (#1070, #9639)
    if !haskey(ENV, "OPENBLAS_MAIN_FREE") && !haskey(ENV, "GOTOBLAS_MAIN_FREE")
        ENV["OPENBLAS_MAIN_FREE"] = "1"
    end
    # And try to prevent openblas from starting too many threads, unless/until specifically requested
    if !haskey(ENV, "OPENBLAS_NUM_THREADS") && !haskey(ENV, "OMP_NUM_THREADS")
        cpu_threads = Sys.CPU_THREADS::Int
        if cpu_threads > 8 # always at most 8
            ENV["OPENBLAS_NUM_THREADS"] = "8"
        elseif haskey(ENV, "JULIA_CPU_THREADS") # or exactly as specified
            ENV["OPENBLAS_NUM_THREADS"] = cpu_threads
        end # otherwise, trust that openblas will pick CPU_THREADS anyways, without any intervention
    end
    # for the few uses of Libc.rand in Base:
    Libc.srand()
    # Base library init
    reinit_stdio()
    Multimedia.reinit_displays() # since Multimedia.displays uses stdout as fallback
    # initialize loading
    init_depot_path()
    init_load_path()
    nothing
end

INCLUDE_STATE = 3 # include = include_relative
end

const tot_time_stdlib = RefValue(0.0)

end # baremodule Base

using .Base

# Ensure this file is also tracked
pushfirst!(Base._included_files, (@__MODULE__, joinpath(@__DIR__, "sysimg.jl")))

# set up depot & load paths to be able to find stdlib packages
@eval Base creating_sysimg = true
Base.init_depot_path()
Base.init_load_path()

if Base.is_primary_base_module
# load some stdlib packages but don't put their names in Main
let
    # Stdlibs manually sorted in top down order
    stdlibs = [
            # No deps
            :Base64,
            :CRC32c,
            :SHA,
            :FileWatching,
            :Unicode,
            :Mmap,
            :Serialization,
            :Libdl,
            :Markdown,
            :LibGit2,
            :Logging,
            :Sockets,
            :Printf,
            :Profile,
            :Dates,
            :DelimitedFiles,
            :Random,
            :UUIDs,
            :Future,
            :LinearAlgebra,
            :SparseArrays,
            :SuiteSparse,
            :Distributed,
            :SharedArrays,
            :Pkg,
            :Test,
            :REPL,
            :Statistics,
        ]

    maxlen = maximum(textwidth.(string.(stdlibs)))

    print_time = (mod, t) -> (print(rpad(string(mod) * "  ", maxlen + 3, "─")); Base.time_print(t * 10^9); println())
    print_time(Base, (Base.end_base_include - Base.start_base_include) * 10^(-9))

    Base._track_dependencies[] = true
    Base.tot_time_stdlib[] = @elapsed for stdlib in stdlibs
        tt = @elapsed Base.require(Base, stdlib)
        print_time(stdlib, tt)
    end
    for dep in Base._require_dependencies
        dep[3] == 0.0 && continue
        push!(Base._included_files, dep[1:2])
    end
    empty!(Base._require_dependencies)
    Base._track_dependencies[] = false

    print_time("Stdlibs total", Base.tot_time_stdlib[])
end
end

# Clear global state
empty!(Core.ARGS)
empty!(Base.ARGS)
empty!(LOAD_PATH)
@eval Base creating_sysimg = false
Base.init_load_path() # want to be able to find external packages in userimg.jl

let
tot_time_userimg = @elapsed (Base.isfile("userimg.jl") && Base.include(Main, "userimg.jl"))

tot_time_base = (Base.end_base_include - Base.start_base_include) * 10.0^(-9)
tot_time = tot_time_base + Base.tot_time_stdlib[] + tot_time_userimg

println("Sysimage built. Summary:")
print("Total ─────── "); Base.time_print(tot_time               * 10^9); print(" \n");
print("Base: ─────── "); Base.time_print(tot_time_base          * 10^9); print(" "); show(IOContext(stdout, :compact=>true), (tot_time_base          / tot_time) * 100); println("%")
print("Stdlibs: ──── "); Base.time_print(Base.tot_time_stdlib[] * 10^9); print(" "); show(IOContext(stdout, :compact=>true), (Base.tot_time_stdlib[] / tot_time) * 100); println("%")
if isfile("userimg.jl")
print("Userimg: ──── "); Base.time_print(tot_time_userimg       * 10^9); print(" "); show(IOContext(stdout, :compact=>true), (tot_time_userimg       / tot_time) * 100); println("%")
end
end

empty!(LOAD_PATH)
empty!(DEPOT_PATH)

max_stars_repo_name: marekkukan-tw/julia

max_issues_repo_name: marekkukan-tw/julia

max_forks_repo_name: marekkukan-tw/julia


text:
export Cycle, advance!, nextitem!

mutable struct Cycle{T} <: AbstractVector{T}
    data::Vector{T}
    pos::Int
end

function Cycle(x::Vector{T}) where T
    Cycle(x, 1)
end

function advance!(x::Cycle{T}, n::Int = 1) where T
    x.pos += n
    l = length(x.data)
    x.pos %= l
    if x.pos == 0
        x.pos = l
    end
    x
end

Base.IndexStyle(::Type{<:Cycle{T}}) where T = IndexLinear()
Base.size(x::Cycle{T}) where T = size(x.data)

function nextitem!(x::Cycle{T}) where T
    advance!(x)
    x.data[x.pos]
end

function nextitem!(x::Vector{T}) where T
    pop!(x)
end

function Base.:getindex(x::Cycle{T}, i) where T
    getindex(x.data, i)
end

Base.setindex!(A::Cycle{T}, v, i::Int) where T = setindex!(A.data, v, i)

ext: jl

max_stars_repo_name: asieev/ArenaSim

max_issues_repo_name: asieev/ArenaSim

max_forks_repo_name: asieev/ArenaSim


text:
# This file is auto-generated by AWSMetadata.jl
using AWS
using AWS.AWSServices: voice_id
using AWS.Compat
using AWS.UUIDs

"""
    create_domain(name, server_side_encryption_configuration)
    create_domain(name, server_side_encryption_configuration, params::Dict{String,<:Any})

Creates a domain that contains all Amazon Connect Voice ID data, such as speakers,
fraudsters, customer audio, and voiceprints.

# Arguments
- `name`: The name of the domain.
- `server_side_encryption_configuration`: The configuration, containing the KMS Key
  Identifier, to be used by Voice ID for the server-side encryption of your data. Refer to
  Amazon Connect VoiceID encryption at rest for more details on how the KMS Key is used.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"ClientToken"`: The idempotency token for creating a new domain. If not provided, Amazon
  Web Services SDK populates this field.
- `"Description"`: A brief description of this domain.
- `"Tags"`: A list of tags you want added to the domain.
"""
function create_domain(
    Name,
    ServerSideEncryptionConfiguration;
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "CreateDomain",
        Dict{String,Any}(
            "Name" => Name,
            "ServerSideEncryptionConfiguration" => ServerSideEncryptionConfiguration,
            "ClientToken" => string(uuid4()),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function create_domain(
    Name,
    ServerSideEncryptionConfiguration,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "CreateDomain",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}(
                    "Name" => Name,
                    "ServerSideEncryptionConfiguration" =>
                        ServerSideEncryptionConfiguration,
                    "ClientToken" => string(uuid4()),
                ),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    delete_domain(domain_id)
    delete_domain(domain_id, params::Dict{String,<:Any})

Deletes the specified domain from the Amazon Connect Voice ID system.

# Arguments
- `domain_id`: The identifier of the domain you want to delete.

"""
function delete_domain(DomainId; aws_config::AbstractAWSConfig=global_aws_config())
    return voice_id(
        "DeleteDomain",
        Dict{String,Any}("DomainId" => DomainId);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function delete_domain(
    DomainId,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "DeleteDomain",
        Dict{String,Any}(
            mergewith(_merge, Dict{String,Any}("DomainId" => DomainId), params)
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    delete_fraudster(domain_id, fraudster_id)
    delete_fraudster(domain_id, fraudster_id, params::Dict{String,<:Any})

Deletes the specified fraudster from the Amazon Connect Voice ID system.

# Arguments
- `domain_id`: The identifier of the domain containing the fraudster.
- `fraudster_id`: The identifier of the fraudster you want to delete.

"""
function delete_fraudster(
    DomainId, FraudsterId; aws_config::AbstractAWSConfig=global_aws_config()
)
    return voice_id(
        "DeleteFraudster",
        Dict{String,Any}("DomainId" => DomainId, "FraudsterId" => FraudsterId);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function delete_fraudster(
    DomainId,
    FraudsterId,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "DeleteFraudster",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}("DomainId" => DomainId, "FraudsterId" => FraudsterId),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    delete_speaker(domain_id, speaker_id)
    delete_speaker(domain_id, speaker_id, params::Dict{String,<:Any})

Deletes the specified speaker from the Amazon Connect Voice ID system.

# Arguments
- `domain_id`: The identifier of the domain containing the speaker.
- `speaker_id`: The identifier of the speaker you want to delete.

"""
function delete_speaker(
    DomainId, SpeakerId; aws_config::AbstractAWSConfig=global_aws_config()
)
    return voice_id(
        "DeleteSpeaker",
        Dict{String,Any}("DomainId" => DomainId, "SpeakerId" => SpeakerId);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function delete_speaker(
    DomainId,
    SpeakerId,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "DeleteSpeaker",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}("DomainId" => DomainId, "SpeakerId" => SpeakerId),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    describe_domain(domain_id)
    describe_domain(domain_id, params::Dict{String,<:Any})

Describes the specified domain.

# Arguments
- `domain_id`: The identifier of the domain you are describing.

"""
function describe_domain(DomainId; aws_config::AbstractAWSConfig=global_aws_config())
    return voice_id(
        "DescribeDomain",
        Dict{String,Any}("DomainId" => DomainId);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function describe_domain(
    DomainId,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "DescribeDomain",
        Dict{String,Any}(
            mergewith(_merge, Dict{String,Any}("DomainId" => DomainId), params)
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    describe_fraudster(domain_id, fraudster_id)
    describe_fraudster(domain_id, fraudster_id, params::Dict{String,<:Any})

Describes the specified fraudster.

# Arguments
- `domain_id`: The identifier of the domain containing the fraudster.
- `fraudster_id`: The identifier of the fraudster you are describing.

"""
function describe_fraudster(
    DomainId, FraudsterId; aws_config::AbstractAWSConfig=global_aws_config()
)
    return voice_id(
        "DescribeFraudster",
        Dict{String,Any}("DomainId" => DomainId, "FraudsterId" => FraudsterId);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function describe_fraudster(
    DomainId,
    FraudsterId,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "DescribeFraudster",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}("DomainId" => DomainId, "FraudsterId" => FraudsterId),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    describe_fraudster_registration_job(domain_id, job_id)
    describe_fraudster_registration_job(domain_id, job_id, params::Dict{String,<:Any})

Describes the specified fraudster registration job.

# Arguments
- `domain_id`: The identifier for the domain containing the fraudster registration job.
- `job_id`: The identifier for the fraudster registration job you are describing.

"""
function describe_fraudster_registration_job(
    DomainId, JobId; aws_config::AbstractAWSConfig=global_aws_config()
)
    return voice_id(
        "DescribeFraudsterRegistrationJob",
        Dict{String,Any}("DomainId" => DomainId, "JobId" => JobId);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function describe_fraudster_registration_job(
    DomainId,
    JobId,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "DescribeFraudsterRegistrationJob",
        Dict{String,Any}(
            mergewith(
                _merge, Dict{String,Any}("DomainId" => DomainId, "JobId" => JobId), params
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    describe_speaker(domain_id, speaker_id)
    describe_speaker(domain_id, speaker_id, params::Dict{String,<:Any})

Describes the specified speaker.

# Arguments
- `domain_id`: The identifier of the domain that contains the speaker.
- `speaker_id`: The identifier of the speaker you are describing.

"""
function describe_speaker(
    DomainId, SpeakerId; aws_config::AbstractAWSConfig=global_aws_config()
)
    return voice_id(
        "DescribeSpeaker",
        Dict{String,Any}("DomainId" => DomainId, "SpeakerId" => SpeakerId);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function describe_speaker(
    DomainId,
    SpeakerId,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "DescribeSpeaker",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}("DomainId" => DomainId, "SpeakerId" => SpeakerId),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    describe_speaker_enrollment_job(domain_id, job_id)
    describe_speaker_enrollment_job(domain_id, job_id, params::Dict{String,<:Any})

Describes the specified speaker enrollment job.

# Arguments
- `domain_id`: The identifier of the domain containing the speaker enrollment job.
- `job_id`: The identifier of the speaker enrollment job you are describing.

"""
function describe_speaker_enrollment_job(
    DomainId, JobId; aws_config::AbstractAWSConfig=global_aws_config()
)
    return voice_id(
        "DescribeSpeakerEnrollmentJob",
        Dict{String,Any}("DomainId" => DomainId, "JobId" => JobId);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function describe_speaker_enrollment_job(
    DomainId,
    JobId,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "DescribeSpeakerEnrollmentJob",
        Dict{String,Any}(
            mergewith(
                _merge, Dict{String,Any}("DomainId" => DomainId, "JobId" => JobId), params
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    evaluate_session(domain_id, session_name_or_id)
    evaluate_session(domain_id, session_name_or_id, params::Dict{String,<:Any})

Evaluates a specified session based on audio data accumulated during a streaming Amazon
Connect Voice ID call.

# Arguments
- `domain_id`: The identifier of the domain where the session started.
- `session_name_or_id`: The session identifier, or name of the session, that you want to
  evaluate. In Voice ID integration, this is the Contact-Id.

"""
function evaluate_session(
    DomainId, SessionNameOrId; aws_config::AbstractAWSConfig=global_aws_config()
)
    return voice_id(
        "EvaluateSession",
        Dict{String,Any}("DomainId" => DomainId, "SessionNameOrId" => SessionNameOrId);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function evaluate_session(
    DomainId,
    SessionNameOrId,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "EvaluateSession",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}(
                    "DomainId" => DomainId, "SessionNameOrId" => SessionNameOrId
                ),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    list_domains()
    list_domains(params::Dict{String,<:Any})

Lists all the domains in the Amazon Web Services account.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"MaxResults"`: The maximum number of results that are returned per call. You can use
  NextToken to obtain further pages of results. The default is 100; the maximum allowed page
  size is also 100.
- `"NextToken"`: If NextToken is returned, there are more results available. The value of
  NextToken is a unique pagination token for each page. Make the call again using the
  returned token to retrieve the next page. Keep all other arguments unchanged. Each
  pagination token expires after 24 hours.
"""
function list_domains(; aws_config::AbstractAWSConfig=global_aws_config())
    return voice_id("ListDomains"; aws_config=aws_config, feature_set=SERVICE_FEATURE_SET)
end
function list_domains(
    params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()
)
    return voice_id(
        "ListDomains", params; aws_config=aws_config, feature_set=SERVICE_FEATURE_SET
    )
end

"""
    list_fraudster_registration_jobs(domain_id)
    list_fraudster_registration_jobs(domain_id, params::Dict{String,<:Any})

Lists all the fraudster registration jobs in the domain with the given JobStatus. If
JobStatus is not provided, this lists all fraudster registration jobs in the given domain.

# Arguments
- `domain_id`: The identifier of the domain containing the fraudster registration Jobs.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"JobStatus"`: Provides the status of your fraudster registration job.
- `"MaxResults"`: The maximum number of results that are returned per call. You can use
  NextToken to obtain further pages of results. The default is 100; the maximum allowed page
  size is also 100.
- `"NextToken"`: If NextToken is returned, there are more results available. The value of
  NextToken is a unique pagination token for each page. Make the call again using the
  returned token to retrieve the next page. Keep all other arguments unchanged. Each
  pagination token expires after 24 hours.
"""
function list_fraudster_registration_jobs(
    DomainId; aws_config::AbstractAWSConfig=global_aws_config()
)
    return voice_id(
        "ListFraudsterRegistrationJobs",
        Dict{String,Any}("DomainId" => DomainId);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function list_fraudster_registration_jobs(
    DomainId,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "ListFraudsterRegistrationJobs",
        Dict{String,Any}(
            mergewith(_merge, Dict{String,Any}("DomainId" => DomainId), params)
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    list_speaker_enrollment_jobs(domain_id)
    list_speaker_enrollment_jobs(domain_id, params::Dict{String,<:Any})

Lists all the speaker enrollment jobs in the domain with the specified JobStatus. If
JobStatus is not provided, this lists all jobs with all possible speaker enrollment job
statuses.

# Arguments
- `domain_id`: The identifier of the domain containing the speaker enrollment jobs.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"JobStatus"`: Provides the status of your speaker enrollment Job.
- `"MaxResults"`: The maximum number of results that are returned per call. You can use
  NextToken to obtain further pages of results. The default is 100; the maximum allowed page
  size is also 100.
- `"NextToken"`: If NextToken is returned, there are more results available. The value of
  NextToken is a unique pagination token for each page. Make the call again using the
  returned token to retrieve the next page. Keep all other arguments unchanged. Each
  pagination token expires after 24 hours.
"""
function list_speaker_enrollment_jobs(
    DomainId; aws_config::AbstractAWSConfig=global_aws_config()
)
    return voice_id(
        "ListSpeakerEnrollmentJobs",
        Dict{String,Any}("DomainId" => DomainId);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function list_speaker_enrollment_jobs(
    DomainId,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "ListSpeakerEnrollmentJobs",
        Dict{String,Any}(
            mergewith(_merge, Dict{String,Any}("DomainId" => DomainId), params)
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    list_speakers(domain_id)
    list_speakers(domain_id, params::Dict{String,<:Any})

Lists all speakers in a specified domain.

# Arguments
- `domain_id`: The identifier of the domain.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"MaxResults"`: The maximum number of results that are returned per call. You can use
  NextToken to obtain further pages of results. The default is 100; the maximum allowed page
  size is also 100.
- `"NextToken"`: If NextToken is returned, there are more results available. The value of
  NextToken is a unique pagination token for each page. Make the call again using the
  returned token to retrieve the next page. Keep all other arguments unchanged. Each
  pagination token expires after 24 hours.
"""
function list_speakers(DomainId; aws_config::AbstractAWSConfig=global_aws_config())
    return voice_id(
        "ListSpeakers",
        Dict{String,Any}("DomainId" => DomainId);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function list_speakers(
    DomainId,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "ListSpeakers",
        Dict{String,Any}(
            mergewith(_merge, Dict{String,Any}("DomainId" => DomainId), params)
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    list_tags_for_resource(resource_arn)
    list_tags_for_resource(resource_arn, params::Dict{String,<:Any})

Lists all tags associated with a specified Voice ID resource.

# Arguments
- `resource_arn`: The Amazon Resource Name (ARN) of the Voice ID resource for which you
  want to list the tags.

"""
function list_tags_for_resource(
    ResourceArn; aws_config::AbstractAWSConfig=global_aws_config()
)
    return voice_id(
        "ListTagsForResource",
        Dict{String,Any}("ResourceArn" => ResourceArn);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function list_tags_for_resource(
    ResourceArn,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "ListTagsForResource",
        Dict{String,Any}(
            mergewith(_merge, Dict{String,Any}("ResourceArn" => ResourceArn), params)
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    opt_out_speaker(domain_id, speaker_id)
    opt_out_speaker(domain_id, speaker_id, params::Dict{String,<:Any})

Opts out a speaker from Voice ID system. A speaker can be opted out regardless of whether
or not they already exist in the system. If they don't yet exist, a new speaker is created
in an opted out state. If they already exist, their existing status is overridden and they
are opted out. Enrollment and evaluation authentication requests are rejected for opted out
speakers, and opted out speakers have no voice embeddings stored in the system.

# Arguments
- `domain_id`: The identifier of the domain containing the speaker.
- `speaker_id`: The identifier of the speaker you want opted-out.

"""
function opt_out_speaker(
    DomainId, SpeakerId; aws_config::AbstractAWSConfig=global_aws_config()
)
    return voice_id(
        "OptOutSpeaker",
        Dict{String,Any}("DomainId" => DomainId, "SpeakerId" => SpeakerId);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function opt_out_speaker(
    DomainId,
    SpeakerId,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "OptOutSpeaker",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}("DomainId" => DomainId, "SpeakerId" => SpeakerId),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    start_fraudster_registration_job(data_access_role_arn, domain_id, input_data_config, output_data_config)
    start_fraudster_registration_job(data_access_role_arn, domain_id, input_data_config, output_data_config, params::Dict{String,<:Any})

Starts a new batch fraudster registration job using provided details.

# Arguments
- `data_access_role_arn`: The IAM role Amazon Resource Name (ARN) that grants Voice ID
  permissions to access customer's buckets to read the input manifest file and write the Job
  output file. Refer to the Create and edit a fraudster watchlist documentation for the
  permissions needed in this role.
- `domain_id`: The identifier of the domain containing the fraudster registration job and
  in which the fraudsters are registered.
- `input_data_config`: The input data config containing an S3 URI for the input manifest
  file that contains the list of fraudster registration requests.
- `output_data_config`: The output data config containing the S3 location where Voice ID
  writes the job output file; you must also include a KMS Key ID to encrypt the file.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"ClientToken"`: The idempotency token for starting a new fraudster registration job. If
  not provided, Amazon Web Services SDK populates this field.
- `"JobName"`: The name of the new fraudster registration job.
- `"RegistrationConfig"`: The registration config containing details such as the action to
  take when a duplicate fraudster is detected, and the similarity threshold to use for
  detecting a duplicate fraudster.
"""
function start_fraudster_registration_job(
    DataAccessRoleArn,
    DomainId,
    InputDataConfig,
    OutputDataConfig;
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "StartFraudsterRegistrationJob",
        Dict{String,Any}(
            "DataAccessRoleArn" => DataAccessRoleArn,
            "DomainId" => DomainId,
            "InputDataConfig" => InputDataConfig,
            "OutputDataConfig" => OutputDataConfig,
            "ClientToken" => string(uuid4()),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function start_fraudster_registration_job(
    DataAccessRoleArn,
    DomainId,
    InputDataConfig,
    OutputDataConfig,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "StartFraudsterRegistrationJob",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}(
                    "DataAccessRoleArn" => DataAccessRoleArn,
                    "DomainId" => DomainId,
                    "InputDataConfig" => InputDataConfig,
                    "OutputDataConfig" => OutputDataConfig,
                    "ClientToken" => string(uuid4()),
                ),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    start_speaker_enrollment_job(data_access_role_arn, domain_id, input_data_config, output_data_config)
    start_speaker_enrollment_job(data_access_role_arn, domain_id, input_data_config, output_data_config, params::Dict{String,<:Any})

Starts a new batch speaker enrollment job using specified details.

# Arguments
- `data_access_role_arn`: The IAM role Amazon Resource Name (ARN) that grants Voice ID
  permissions to access customer's buckets to read the input manifest file and write the job
  output file. Refer to Batch enrollment using audio data from prior calls documentation for
  the permissions needed in this role.
- `domain_id`: The identifier of the domain that contains the speaker enrollment job and in
  which the speakers are enrolled.
- `input_data_config`: The input data config containing the S3 location for the input
  manifest file that contains the list of speaker enrollment requests.
- `output_data_config`: The output data config containing the S3 location where Voice ID
  writes the job output file; you must also include a KMS Key ID to encrypt the file.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"ClientToken"`: The idempotency token for starting a new speaker enrollment Job. If not
  provided, Amazon Web Services SDK populates this field.
- `"EnrollmentConfig"`: The enrollment config that contains details such as the action to
  take when a speaker is already enrolled in the Voice ID system or when a speaker is
  identified as a fraudster.
- `"JobName"`: A name for your speaker enrollment job.
"""
function start_speaker_enrollment_job(
    DataAccessRoleArn,
    DomainId,
    InputDataConfig,
    OutputDataConfig;
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "StartSpeakerEnrollmentJob",
        Dict{String,Any}(
            "DataAccessRoleArn" => DataAccessRoleArn,
            "DomainId" => DomainId,
            "InputDataConfig" => InputDataConfig,
            "OutputDataConfig" => OutputDataConfig,
            "ClientToken" => string(uuid4()),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function start_speaker_enrollment_job(
    DataAccessRoleArn,
    DomainId,
    InputDataConfig,
    OutputDataConfig,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "StartSpeakerEnrollmentJob",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}(
                    "DataAccessRoleArn" => DataAccessRoleArn,
                    "DomainId" => DomainId,
                    "InputDataConfig" => InputDataConfig,
                    "OutputDataConfig" => OutputDataConfig,
                    "ClientToken" => string(uuid4()),
                ),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    tag_resource(resource_arn, tags)
    tag_resource(resource_arn, tags, params::Dict{String,<:Any})

Tags an Amazon Connect Voice ID resource with the provided list of tags.

# Arguments
- `resource_arn`: The Amazon Resource Name (ARN) of the Voice ID resource you want to tag.
- `tags`: The list of tags to assign to the specified resource.

"""
function tag_resource(ResourceArn, Tags; aws_config::AbstractAWSConfig=global_aws_config())
    return voice_id(
        "TagResource",
        Dict{String,Any}("ResourceArn" => ResourceArn, "Tags" => Tags);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function tag_resource(
    ResourceArn,
    Tags,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "TagResource",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}("ResourceArn" => ResourceArn, "Tags" => Tags),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    untag_resource(resource_arn, tag_keys)
    untag_resource(resource_arn, tag_keys, params::Dict{String,<:Any})

Removes specified tags from a specified Amazon Connect Voice ID resource.

# Arguments
- `resource_arn`: The Amazon Resource Name (ARN) of the Voice ID resource you want to
  remove tags from.
- `tag_keys`: The list of tag keys you want to remove from the specified resource.

"""
function untag_resource(
    ResourceArn, TagKeys; aws_config::AbstractAWSConfig=global_aws_config()
)
    return voice_id(
        "UntagResource",
        Dict{String,Any}("ResourceArn" => ResourceArn, "TagKeys" => TagKeys);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function untag_resource(
    ResourceArn,
    TagKeys,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "UntagResource",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}("ResourceArn" => ResourceArn, "TagKeys" => TagKeys),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    update_domain(domain_id, name, server_side_encryption_configuration)
    update_domain(domain_id, name, server_side_encryption_configuration, params::Dict{String,<:Any})

Updates the specified domain. This API has clobber behavior, and clears and replaces all
attributes. If an optional field, such as 'Description' is not provided, it is removed from
the domain.

# Arguments
- `domain_id`: The identifier of the domain to be updated.
- `name`: The name of the domain.
- `server_side_encryption_configuration`: The configuration, containing the KMS Key
  Identifier, to be used by Voice ID for the server-side encryption of your data. Note that
  all the existing data in the domain are still encrypted using the existing key, only the
  data added to domain after updating the key is encrypted using the new key.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"Description"`: A brief description about this domain.
"""
function update_domain(
    DomainId,
    Name,
    ServerSideEncryptionConfiguration;
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "UpdateDomain",
        Dict{String,Any}(
            "DomainId" => DomainId,
            "Name" => Name,
            "ServerSideEncryptionConfiguration" => ServerSideEncryptionConfiguration,
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function update_domain(
    DomainId,
    Name,
    ServerSideEncryptionConfiguration,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return voice_id(
        "UpdateDomain",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}(
                    "DomainId" => DomainId,
                    "Name" => Name,
                    "ServerSideEncryptionConfiguration" =>
                        ServerSideEncryptionConfiguration,
                ),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end


text:
@testset "Multi" begin
  outer = P2[(0,0),(1,0),(1,1),(0,1),(0,0)]
  hole1 = P2[(0.2,0.2),(0.4,0.2),(0.4,0.4),(0.2,0.4),(0.2,0.2)]
  hole2 = P2[(0.6,0.2),(0.8,0.2),(0.8,0.4),(0.6,0.4),(0.6,0.2)]
  poly  = PolyArea(outer, [hole1, hole2])
  multi = Multi([poly, poly])
  @test multi == multi
  @test vertices(multi) == [vertices(poly); vertices(poly)]
  @test chains(multi) == [chains(poly); chains(poly)]

  poly1 = PolyArea(P2[(0,0),(1,0),(1,1),(0,1),(0,0)])
  poly2 = PolyArea(P2[(1,1),(2,1),(2,2),(1,2),(1,1)])
  multi = Multi([poly1, poly2])
  @test vertices(multi) == [vertices(poly1); vertices(poly2)]
  @test area(multi) == area(poly1) + area(poly2)
  @test P2(0.5,0.5) ∈ multi
  @test P2(1.5,1.5) ∈ multi
  @test P2(1.5,0.5) ∉ multi
  @test P2(0.5,1.5) ∉ multi
end


text:
include("../aimajulia.jl");

using Test;

using Main.aimajulia;

using Main.aimajulia.utils;

#The following nlp tests are from the aima-python doctests

# Test the Grammar DataType methods
check = Dict([Pair("A", [["B", "C"], ["D", "E"]]),
            Pair("B", [["E"], ["a"], ["b", "c"]])]);

@test (Rules(["A"=>"B C | D E", "B"=>"E | a | b c"]) == check);

check = Dict([Pair("Article", ["the", "a", "an"]),
            Pair("Pronoun", ["i", "you", "he"])]);

@test (Lexicon(["Article"=>"the | a | an", "Pronoun"=>"i | you | he"]) == check);

rules = Rules(["A"=>"B C | D E", "B"=>"E | a | b c"]);
lexicon = Lexicon(["Article"=>"the | a | an", "Pronoun"=>"i | you | he"]);
grammar = Grammar("Simplegram", rules, lexicon);

@test (rewrites_for(grammar, "A") == [["B", "C"], ["D", "E"]]);

@test (is_category(grammar, "the", "Article") == true);

grammar = aimajulia.nlp.epsilon_chomsky;

@test (all((function(rule::Tuple)
                return (length(rule) == 3);
            end), cnf_rules(grammar)));

lexicon = Lexicon(["Article"=>"the | a | an", "Pronoun"=>"i | you | he"]);
rules = Rules(["S"=>"Article | More | Pronoun", "More"=>"Article Pronoun | Pronoun Pronoun"]);
grammar = Grammar("Simplegram", rules, lexicon);
sentence = generate_random_sentence(grammar, "S");

@test (all((function(token::String)
                return any((function(terminals::AbstractVector)
                                return (token in terminals);
                            end), values(grammar.lexicon));
            end), map(String, split(sentence))));

# Test the ProbabilityGrammar DataType methods
check = Dict([Pair("A", [(["B", "C"], 0.3), (["D", "E"], 0.7)]),
            Pair("B", [(["E"], 0.1), (["a"], 0.2), (["b", "c"], 0.7)])]);

@test (ProbabilityRules(["A"=>"B C [0.3] | D E [0.7]", "B"=>"E [0.1] | a [0.2] | b c [0.7]"]) == check);

check = Dict([Pair("Article", [("the", 0.5), ("a", 0.25), ("an", 0.25)]),
            Pair("Pronoun", [("i", 0.4), ("you", 0.3), ("he", 0.3)])]);

@test (ProbabilityLexicon(["Article"=>"the [0.5] | a [0.25] | an [0.25]", "Pronoun"=>"i [0.4] | you [0.3] | he [0.3]"]) == check);

rules = ProbabilityRules(["A"=>"B C [0.3] | D E [0.7]", "B"=>"E [0.1] | a [0.2] | b c [0.7]"]);
lexicon = ProbabilityLexicon(["Article"=>"the [0.5] | a [0.25] | an [0.25]", "Pronoun"=>"i [0.4] | you [0.3] | he [0.3]"]);
grammar = ProbabilityGrammar("Simplegram", rules, lexicon);

@test (rewrites_for(grammar, "A") == [(["B", "C"], 0.3), (["D", "E"], 0.7)]);

@test (is_category(grammar, "the", "Article") == true);

grammar = aimajulia.nlp.epsilon_probability_chomsky;

@test (all((function(rule::Tuple)
                return (length(rule) == 4);
            end), cnf_rules(grammar)));

lexicon = ProbabilityLexicon(["Verb"=>"am [0.5] | are [0.25] | is [0.25]",
                            "Pronoun"=>"i [0.4] | you [0.3] | he [0.3]"]);
rules = ProbabilityRules(["S"=>"Verb [0.5] | More [0.3] | Pronoun [0.1] | nobody is here [0.1]",
                        "More"=>"Pronoun Verb [0.7] | Pronoun Pronoun [0.3]"]);
grammar = ProbabilityGrammar("Simplegram", rules, lexicon);
sentence = generate_random_sentence(grammar, "S");

@test (length(sentence) == 2);

# Test the Chart DataType
chart = Chart(aimajulia.nlp.epsilon_0);

@test (length(parse_sentence(chart, "the stench is in 2 2")) == 1);

# Test the CYK parsing
grammar = aimajulia.nlp.epsilon_probability_chomsky;
words = ["the", "robot", "is", "good"];

@test (length(cyk_parse(words, grammar)) == 52);

# Test the HTML parsing functions
address = "https://en.wikipedia.org/wiki/Ethics";

page = load_page_html([address]);

page_html = page[address];

@test ((!occursin("", page_html)) && (!occursin("", page_html)));

test_html_1 = ("Keyword String 1: A man is a male human."
                *"Keyword String 2: Like most other male mammals, a man inherits an"
                *"X from his mom and a Y from his dad."
                *"Links:"
                *"href=\"https://google.com.au\""
                *"<href=\"/wiki/TestThing\"> href=\"/wiki/TestBoy\""
                *"href=\"/wiki/TestLiving\" href=\"/wiki/TestMan\">");
test_html_2 = "a mom and a dad";
test_html_3 = "<!DOCTYPE html><title>Page Title</title>
AIMA book
";
no_head_test_html_3 = replace(test_html_3, @r_str("(.*)", "s")=>"");

@test ((!occursin("", no_head_test_html_3)) && (!occursin("", no_head_test_html_3)));

@test ((occursin("AIMA book", test_html_3)) && (occursin("AIMA book", no_head_test_html_3)));

page_A = Page("A", inlinks=["B", "C", "E"], outlinks=["D"], hub=1, authority=6);
page_B = Page("B", inlinks=["E"], outlinks=["A", "C", "D"], hub=2, authority=5);
page_C = Page("C", inlinks=["B", "E"], outlinks=["A", "D"], hub=3, authority=4);
page_D = Page("D", inlinks=["A", "B", "C", "E"], outlinks=[], hub=4, authority=3);
page_E = Page("E", inlinks=[], outlinks=["A", "B", "C", "D", "F"], hub=5, authority=2);
page_F = Page("F", inlinks=["E"], outlinks=[], hub=6, authority=1);

page_dict = Dict([Pair(page_A.address, page_A),
                    Pair(page_B.address, page_B),
                    Pair(page_C.address, page_C),
                    Pair(page_D.address, page_D),
                    Pair(page_E.address, page_E),
                    Pair(page_F.address, page_F)]);

pages_index = page_dict;

pages_content = Dict([Pair(page_A.address, test_html_1),
                        Pair(page_B.address, test_html_2),
                        Pair(page_C.address, test_html_1),
                        Pair(page_D.address, test_html_2),
                        Pair(page_E.address, test_html_1),
                        Pair(page_F.address, test_html_2)]);

@test (Set(determine_inlinks(page_A, pages_index)) == Set(["B", "C", "E"]));

@test (Set(determine_inlinks(page_E, pages_index)) == Set([]));

@test (Set(determine_inlinks(page_F, pages_index)) == Set(["E"]));

test_page_A = page_dict[page_A.address];
test_outlinks = find_outlinks(test_page_A, pages_content, only_wikipedia_urls);

@test ("https://en.wikipedia.org/wiki/TestThing" in test_outlinks);

@test (!("https://google.com.au" in test_outlinks));

pages = Dict(collect((k, page_dict[k]) for k in ("F",)));
pages_two = Dict(collect((k, page_dict[k]) for k in ("A", "E")));
expanded_pages = expand_pages(pages, pages_index);

@test (all(x in keys(expanded_pages) for x in ("F", "E")));

@test (all(!(x in keys(expanded_pages)) for x in ("A", "B", "C", "D")));

expanded_pages = expand_pages(pages_two, pages_index);

@test (all(x in keys(expanded_pages) for x in ("A", "B", "C", "D", "E", "F")));

pages = relevant_pages("his dad", pages_index, pages_content);

@test (all((x in keys(pages)) for x in ("A", "C", "E")));

@test (all((!(x in keys(pages))) for x in ("B", "D", "F")));

pages = relevant_pages("mom and dad", pages_index, pages_content);

@test (all((x in keys(pages)) for x in ("A", "B", "C", "D", "E", "F")));

pages = relevant_pages("philosophy", pages_index, pages_content);

@test (all((!(x in keys(pages))) for x in ("A", "B", "C", "D", "E", "F")));

normalize_pages(page_dict);
println("pages_index hubs: ", collect(page.hub for page in values(pages_index)));

expected_hubs = [(1 / sqrt(91)), (2 / sqrt(91)), (3 / sqrt(91)), (4 / sqrt(91)), (5 / sqrt(91)), (6 / sqrt(91))];
expected_authorities = collect(reverse(expected_hubs));

@test (length(expected_hubs) == length(expected_authorities) == length(pages_index));

sorted_pages = sort(collect(pages_index),
                    lt=(function(p1::Pair, p2::Pair)
                            if (p1.first < p2.first)
                                return true;
                            else
                                return false;
                            end
                        end));

@test (expected_hubs == collect(page.hub for (address, page) in sorted_pages));

@test (expected_authorities == collect(page.authority for (address, page) in sorted_pages));

convergence = ConvergenceDetector();
detect_convergence(convergence, pages_index);

@test (detect_convergence(convergence, pages_index));

new_pages_index = deepcopy(pages_index);

for (address, page) in new_pages_index
    page.hub = page.hub + 0.0003;
    page.authority = page.authority + 0.0004;
end

@test (detect_convergence(convergence, new_pages_index));

for (address, page) in new_pages_index
    page.hub = page.hub + 3000000;
    page.authority = page.authority + 3000000;
end

@test (!detect_convergence(convergence, new_pages_index));

@test (sort(get_inlinks(page_dict["A"], pages_index)) == page_dict["A"].inlinks);

@test (sort(get_outlinks(page_dict["A"], pages_index, pages_content)) == page_dict["A"].outlinks);

HITS("inherit", pages_index, pages_content);

authorities = [page_A.authority, page_B.authority, page_C.authority, page_D.authority, page_E.authority, page_F.authority];
hubs = [page_A.hub, page_B.hub, page_C.hub, page_D.hub, page_E.hub, page_F.hub];

@test (reduce(max, authorities) == page_D.authority);

@test (reduce(max, hubs) == page_E.hub);

max_stars_repo_name: mikhail-j/aima-julia-aimacode-fork

max_issues_repo_name: mikhail-j/aima-julia-aimacode-fork

max_forks_repo_name: mikhail-j/aima-julia-aimacode-fork


text:
module Example1

include("Example.jl")
# import Example: MyType, foo, +

export  MyType, foo, mysqure
mysqure(x :: Example.MyType) = Example.foo(x)^2

end

max_stars_repo_name: YinpuLi/SparsityBoosting

max_issues_repo_name: YinpuLi/SparsityBoosting

max_forks_repo_name: YinpuLi/SparsityBoosting


text:
module Contexts

# some cuda related utilities
include("cuda.jl")
# data structures for iterating over slices
include("slices.jl")
# context interface and QXContext implementation
include("base.jl")
# MPI context implementation
include("mpi_context.jl")
# Context using Distributed.jl implementation
# include("dist_context.jl")

end


text:
for n in [3, 4, 5, 6]
    M = matrixdepot("magic", n)
    @test sum(M,1) == sum(M,2)'
    k = rand(1:n)
    @test sum(M,1)[k] == sum(M,2)'[k]
    # diagnoal == antidiagnoal
    p = [n:-1:1;]
    @test sum(diag(M)) == sum(diag(M[:,p]))
end

println("'magic' passed test...")


text:
"""
    hasnulls(itr)

Return `true` if any element in `itr` is null; otherwise return `false`.
"""
@inline function hasnulls(itr::Any)::Bool
    res = false
    for el in itr
        if isa(el, Nullable)
            res |= isnull(el)
        end
    end
    return res
end


text:
#######################
# recursive fibonacci #
#######################

perf_micro_fib(n) = n < 2 ? n : perf_micro_fib(n-1) + perf_micro_fib(n-2)

############
# parseint #
############

if VERSION >= v"0.7.0-DEV.3526"
    _parse16(s) = parse(Int64, s, base=16)
else
    _parse16(s) = parse(Int64, s, 16)
end

if VERSION >= v"0.7.0-DEV.4446"
    _hex(s) = string(s, base=16)
else
    _hex(s) = hex(s)
end

function perf_micro_parseint(t)
    local n, m
    for i=1:t
        n = rand(UInt32)
        s = _hex(n)
        m = UInt32(_parse16(s))
    end
    @assert m == n
    return n
end

##############
# mandelbrot #
##############

function mandel(z)
    c = z
    maxiter = 80
    for n = 1:maxiter
        if abs(z) > 2
            return n-1
        end
        z = z^2 + c
    end
    return maxiter
end

perf_micro_mandel() = [mandel(complex(r,i)) for i=-1.:.1:1., r=-2.0:.1:0.5]

#############
# quicksort #
#############

function quicksort!(a, lo, hi)
    i, j = lo, hi
    while i < hi
        pivot = a[(lo+hi)>>>1]
        while i <= j
            while a[i] < pivot; i += 1; end
            while a[j] > pivot; j -= 1; end
            if i <= j
                a[i], a[j] = a[j], a[i]
                i, j = i+1, j-1
            end
        end
        if lo < j; quicksort!(a,lo,j); end
        lo, j = i, hi
    end
    return a
end

perf_micro_quicksort(n) = quicksort!(rand(n), 1, n)

########
# πsum #
########

function perf_micro_pisum()
    sum = 0.0
    for j = 1:500
        sum = 0.0
        for k = 1:10000
            sum += 1.0/(k*k)
        end
    end
    return sum
end

###############
# randmatstat #
###############

if VERSION >= v"0.7.0-DEV.3204"
    _at_mul_b(A, B) = transpose(A)*B
else
    _at_mul_b(A, B) = At_mul_B(A, B)
end

if VERSION >= v"0.7.0-DEV.5238"
    # std in StatsBase instead of in Base
    function stdmean(x)
        n = length(x)
        m = mean(x)
        sqrt(sum(xi->abs2(xi - m), x) / (n - 1)) / m
    end
else
    stdmean(x) = std(x) / mean(x)
end

if VERSION < v"0.7.0-DEV.4591"
    _tr(x) = trace(x)
else
    _tr(x) = tr(x)
end
function perf_micro_randmatstat(t)
    n = 5
    v = zeros(t)
    w = zeros(t)
    for i=1:t
        a = randn(n,n)
        b = randn(n,n)
        c = randn(n,n)
        d = randn(n,n)
        P = [a b c d]
        Q = [a b; c d]
        v[i] = _tr(_at_mul_b(P,P)^4)
        w[i] = _tr(_at_mul_b(Q,Q)^4)
    end
    return (stdmean(v), stdmean(w))
end

##############
# randmatmul #
##############

perf_micro_randmatmul(t) = rand(t,t)*rand(t,t)

#################
# print_to_file #
#################

if VERSION > v"0.7.0-DEV.3026"
    using Printf
end

function perf_printfd(n)
    open("/dev/null", "w") do io
        for i = 1:n
            @printf(io, "%d %d\n", i, i + 1)
        end
    end
end


text:
############################################################################################
"""
$(SIGNATURES)
Callable struct to make initializing ParticleFilter sampler easier in sampling library.

# Examples
```julia
```

"""
struct ParticleFilterConstructor{
    S<:Union{Symbol,NTuple{k,Symbol} where k},D<:ParticleFilterDefault
} <: AbstractConstructor
    "Parameter to be tracked in filter."
    sym::S
    "PF Default Arguments."
    default::D
    function ParticleFilterConstructor(
        sym::S, default::D
    ) where {S<:Union{Symbol,NTuple{k,Symbol} where k},D<:ParticleFilterDefault}
        tup = BaytesCore.to_Tuple(sym)
        return new{typeof(tup),D}(tup, default)
    end
end
function (constructor::ParticleFilterConstructor)(
    _rng::Random.AbstractRNG,
    model::ModelWrapper,
    data::D,
    temperature::F,
    info::BaytesCore.SampleDefault
) where {D, F<:AbstractFloat}
    return ParticleFilter(
        _rng,
        Objective(model, data, Tagged(model, constructor.sym), temperature),
        constructor.default,
        info
    )
end
function ParticleFilter(sym::S; kwargs...) where {S<:Union{Symbol,NTuple{k,Symbol} where k}}
    return ParticleFilterConstructor(sym, ParticleFilterDefault(; kwargs...))
end

############################################################################################
"""
$(SIGNATURES)
Infer ParticleFilter diagnostics type.

# Examples
```julia
```

"""
function infer(
    _rng::Random.AbstractRNG,
    diagnostics::Type{AbstractDiagnostics},
    pf::ParticleFilter,
    model::ModelWrapper,
    data::D,
) where {D}
    #TTemperature = model.info.flattendefault.output
    TPrediction = infer(_rng, pf, model, data)
    TGenerated = infer_generated(_rng, pf, model, data)
    return ParticleFilterDiagnostics{TPrediction, TGenerated}
end

"""
$(SIGNATURES)
Infer type of predictions of kernel.

# Examples
```julia
```

"""
function infer(_rng::Random.AbstractRNG,
    tune::ParticleFilterTune,
    kernel::ParticleKernel,
    model::ModelWrapper,
    data::D
) where {D}
    reference = get_reference(tune.referencing, model, data, tune.tagged)
    trajectory = propagate(_rng, kernel, tune.memory, reference)
    ## Chose first available iterations where we can predict
    iter = max(tune.memory) + 1
    return typeof(predict(_rng, trajectory, kernel, reference, iter))
end
function infer(
    _rng::Random.AbstractRNG, pf::ParticleFilter, model::ModelWrapper, data::D
) where {D}
    return infer(_rng, pf.tune, pf.particles.kernel, model, data)
end

"""
$(SIGNATURES)
Infer type of generated quantities of PF sampler.

# Examples
```julia
```

"""
function infer_generated(
    _rng::Random.AbstractRNG, pf::ParticleFilter, model::ModelWrapper, data::D
) where {D}
    objective = Objective(model, data, pf.tune.tagged)
    return typeof(generate(_rng, objective, pf.tune.generated))
end

"""
$(SIGNATURES)
Return summary statistics for PF diagnostics.

# Examples
```julia
```

"""
function results(
    diagnosticsᵛ::AbstractVector{P},
    pf::ParticleFilter,
    Ndigits::Integer,
    quantiles::Vector{T},
) where {T<:Real,P<:ParticleFilterDiagnostics}
    ## Print Trace
    println(
        "### ",
        Base.nameof(typeof(pf)),
        " parameter target: ",
        keys(pf.tune.tagged.parameter),
    )
    println(
        "Initial ℓlikelihood: ",
        round(mean(diagnosticsᵛ[begin].base.ℓobjective); digits=Ndigits),
        ", final ℓlikelihood: ",
        round(mean(diagnosticsᵛ[end].base.ℓobjective); digits=Ndigits),
        ".",
    )
    println(
        "Avg. number of used particles: ",
        round(
            mean(diagnosticsᵛ[iter].Nparticles for iter in eachindex(diagnosticsᵛ));
            digits=0,
        ),
        ".",
    )
    return println(
        "Avg. resampling steps: ",
        round(
            mean(diagnosticsᵛ[iter].resampled for iter in eachindex(diagnosticsᵛ)) * 100;
            digits=Ndigits,
        ),
        "%.",
    )
end

############################################################################################
function result!(pf::ParticleFilter, result::L) where {L<:ℓObjectiveResult}
    return error("Not implemented for ParticleFilter.")
end
function get_result(pf::ParticleFilter)
    return error("Not implemented for ParticleFilter.")
end
function predict(_rng::Random.AbstractRNG, pf::ParticleFilter, objective::Objective)
    #return pf.particles.buffer.prediction[1]
    path = BaytesCore.draw!(_rng, pf.particles.weights)
    reference = get_reference(pf.tune.referencing,
        Objective(objective.model, objective.data, pf.tune.tagged, objective.temperature)
    ) #objective)
    return predict(_rng, pf.particles, pf.tune, reference, path)
end

############################################################################################
#export
export ParticleFilterConstructor, infer


text:
module Varthaka

test_me() = "Varthaka"

end # module


text:
module Exercise1

export rowmatmul!, colmatmul!, rowmatmuldot!, colmatmuldot!, turbomul!

using LoopVectorization
import LinearAlgebra: dot

"""
   rowmatmul!(C, A, B)

Set C = A*B, looping over rows first
"""
function rowmatmul!(C,A,B)
  for i in 1:size(C,1)
    for j in 1:size(C,2)
      C[i,j] = zero(eltype(C))
      for k in 1:size(A,2)
        C[i,j] += A[i,k]*B[k,j]
      end
    end
  end
end

function colmatmul!(C,A,B)
  for j in 1:size(C,1)
    for i in 1:size(C,2)
      C[i,j] = zero(eltype(C))
      for k in 1:size(A,2)
        C[i,j] += A[i,k]*B[k,j]
      end
    end
  end
end

function rowmatmuldot!(C,A,B)
  error("not implemented")
end

function colmatmuldot!(C,A,B)
  error("not implemented")
end

function turbomul!(C, A, B)
  @turbo for n ∈ indices((C,B), 2), m ∈ indices((C,A), 1)
      Cmn = zero(eltype(C))
      for k ∈ indices((A,B), (2,1))
          Cmn += A[m,k] * B[k,n]
      end
      C[m,n] = Cmn
  end
end

end


text:
module BenchDictHasKey

using BenchmarkTools
using ConcurrentCollections

function generate(;
    datasize = 2^13,  # `Base.Dict` is better on smaller size
    keysize = 50,  # expensive isequal; favors ConcurrentDict
    nkeys = 100,
)
    vs = UInt64.(1:datasize)
    ks = string.(vs; pad = keysize)
    # ks = vs
    # ks = UInt32.(vs)
    cdict = ConcurrentDict{eltype(ks),eltype(vs)}(zip(ks, vs))
    ks_100 = ks[1:nkeys]
    ks_000 = string.(.-vs[1:nkeys])
    ks_050 = ifelse.(isodd.(vs[1:nkeys]), ks_100, ks_000)
    return (; cdict, ks_100, ks_000, ks_050)
end

const CACHE = Ref{Any}()

function setup(; cases = [:ks_050, :ks_000], kwargs...)
    data = generate(; kwargs...)
    (; cdict) = data
    dict = Dict(cdict)
    CACHE[] = (; dict, data...)

    labelmap = Dict(
        :ks_100 => "100% existing",
        :ks_050 => "50% existing",  # `Base.Dict` is better with 50% hit
        :ks_000 => "0% existing",
    )

    suite = BenchmarkGroup()
    for ksprop in cases
        s1 = suite[labelmap[ksprop]] = BenchmarkGroup()
        ks = getproperty(data, ksprop)
        s1["base-seq"] = @benchmarkable(
            count(k -> haskey(dict, k), ks),
            setup = begin
                dict = CACHE[].dict::$(typeof(dict))
                ks = CACHE[].$ksprop::$(typeof(ks))
            end,
            evals = 1,
        )
        s1["cdict-seq"] = @benchmarkable(
            count(k -> haskey(dict, k), ks),
            setup = begin
                dict = CACHE[].cdict::$(typeof(cdict))
                ks = CACHE[].$ksprop::$(typeof(ks))
            end,
            evals = 1,
        )
    end
    return suite
end

function clear()
    CACHE[] = nothing
end

end  # module


text:
module LockPatternComplexity

include("functions.jl")
export Grid, LineTypes, Symmetries, Bounds, line_type
export data, extract_solutions, create_instance

include("plots.jl")
export canvas, color_map, plot_grid!, plot_lines!, plot_lock_pattern!, create_plots

end


text:
module CellFieldsOperationsTests

using Test
using Gridap
using ..CellFieldsMocks
using ..CellValuesMocks

import Gridap: ∇

l = 10
cf = IterCellFieldMock(2,Int,l)

p1 = Point(1,2)
p2 = Point(0,3)
p3 = Point(7,4)
p4 = Point(8,1)
p = [p1,p2,p3,p4]
cp = TestIterCellValue(p,l)

f,_ = iterate(cf)
fg = gradient(f)
r = evaluate(f,p)
rg = evaluate(fg,p)

cf2 = -cf
v = [-r for i in 1:l]
g = [-rg for i in 1:l]
test_iter_cell_field(cf2,cp,v,g)

cf = IndexCellFieldMock(2,Int,l)
cp = TestIndexCellValue(p,l)
cf2 = -cf
test_index_cell_field(cf2,cp,v,g)

cf = IterCellFieldMock(2,Int,l)
cf2 = cf+cf
v = [r+r for i in 1:l]
g = [rg+rg for i in 1:l]
test_iter_cell_field(cf2,cp,v,g)

cf = IndexCellFieldMock(2,Int,l)
cp = TestIndexCellValue(p,l)
cf2 = cf+cf
test_index_cell_field(cf2,cp,v,g)

cf = IterCellBasisMock(2,Int,l)
cp = TestIterCellValue(p,l)

f,_ = iterate(cf)
fg = gradient(f)
r = evaluate(f,p)
rg = evaluate(fg,p)
v = [r+r for i in 1:l]
g = [rg+rg for i in 1:l]
cf2 = cf+cf
test_iter_cell_basis(cf2,cp,v,g)

# varinner

cf = IterCellFieldMock(2,Int,l)
cb = IterCellBasisMock(2,Int,l)

f,_ = iterate(cf)
r = evaluate(f,p)
b,_ = iterate(cb)
rb = evaluate(b,p)

v = [ r.*r for i in 1:l ]
cs = varinner(cf,cf)
test_iter_cell_map(cs,cp,v)

ndofs, npoins = size(rb)
rv = zeros(eltype(r),ndofs,npoins)
for j in 1:npoins
  for i in 1:ndofs
    rv[i,j] = rb[i,j]*r[j]
  end
end
v = [ rv for i in 1:l ]

cs = varinner(cb,cf)
test_iter_cell_map(cs,cp,v)

rv = zeros(eltype(r),ndofs,ndofs,npoins)
for k in 1:npoins
  for j in 1:ndofs
    for i in 1:ndofs
      rv[i,j,k] = rb[i,k]*rb[j,k]
    end
  end
end
v = [ rv for i in 1:l ]

cs = varinner(cb,cb)
test_iter_cell_map(cs,cp,v)

# lincomb

cf = IterCellFieldMock(2,Float64,l)
cb = IterCellBasisMock(2,Float64,l)

f,_ = iterate(cf)
r = evaluate(f,p)
b,_ = iterate(cb)
rb = evaluate(b,p)

u = rand(eltype(r),ndofs)
cu = TestIterCellValue(u,l)

ndofs, npoins = size(rb)
rv = zeros(eltype(r),npoins)
for j in 1:npoins
  for i in 1:ndofs
    rv[j] += rb[i,j]*u[i]
  end
end
v = [ rv for i in 1:l ]

rbg = evaluate(∇(b),p)
rv = zeros(eltype(rbg),npoins)
for j in 1:npoins
  for i in 1:ndofs
    rv[j] += rbg[i,j]*u[i]
  end
end
g = [ rv for i in 1:l ]

cs = lincomb(cb,cu)
test_iter_cell_field(cs,cp,v,g)

# compose

cf = IterCellFieldMock(2,Int,l)
ufun(x) = 2*x[1]

f,_ = iterate(cf)
r = evaluate(f,p)
v = [ ufun.(r) for i in 1:l ]

cr = compose(ufun,cf)
test_iter_cell_field_without_grad(cr,cp,v)

ufungrad(x) = VectorValue(2,0)
∇(::typeof(ufun)) = ufungrad

vg = [ ufungrad.(r) for i in 1:l ]

cr = compose(ufun,cf)
test_iter_cell_field(cr,cp,v,vg)

# attachgeomap

cf = IterCellGeomapMock(2,Float64,l)
cb = IterCellBasisMock(2,Float64,l)

b,_ = iterate(cb)
rb = evaluate(b,p)
rbg = evaluate(∇(b),p)

f,_ = iterate(cf)
r = evaluate(∇(f),p)

ndofs, npoins = size(rb)
v = [ rb for i in 1:l ]
g = [ reshape(inv.(r),1,npoins) .* rbg for i in 1:l ]

cb2 = attachgeomap(cb,cf)

test_iter_cell_basis(cb2,cp,v,g)

l = 10
cf = IterCellGeomapMock(2,Float64,l)

p1 = Point(1,2)
p2 = Point(0,3)
p3 = Point(7,4)
p4 = Point(8,1)
p = [p1,p2,p3,p4]
cp = TestIterCellValue(p,l)

sg = ε(cf)

ri = TensorValue{2,Float64,4}[
  (3.0, 0.0, 0.0, 3.0), (3.0, 0.0, 0.0, 3.0),
  (3.0, 0.0, 0.0, 3.0), (3.0, 0.0, 0.0, 3.0)]
r = fill(ri,l)

test_iter_cell_field_without_grad(sg,cp,r)

@test ε == symmetric_gradient

gr = ∇(cf)
sg = trace(gr)

ri = fill(6.0,4)
r = fill(ri,l)

test_iter_cell_field_without_grad(sg,cp,r)

sg = div(cf)

test_iter_cell_field_without_grad(sg,cp,r)

sg = curl(cf)

ri = fill(0.0,4)
r = fill(ri,l)
test_iter_cell_field_without_grad(sg,cp,r)

end # module


text:
###############################################################################
# BUILD TMLE FROM .TOML

function buildmodels(config)
    models = Dict()
    for (modelname, hyperparams) in config
        if !(modelname in ("resampling", "outcome"))
            modeltype = eval(Symbol(modelname))
            paramnames = Tuple(Symbol(x[1]) for x in hyperparams)
            counter = 1
            for paramvals in Base.Iterators.product(values(hyperparams)...)
                model = modeltype(;NamedTuple{paramnames}(paramvals)...)
                models[Symbol(modelname*"_$counter")] = model
                counter += 1
            end
        end
    end
    return models
end

function stack_from_config(config::Dict, metalearner)
    # Define the resampling strategy
    resampling = config["resampling"]
    resampling = eval(Symbol(resampling["type"]))(nfolds=resampling["nfolds"])

    # Define the models library
    models = buildmodels(config)

    # Define the Stack
    Stack(;metalearner=metalearner, resampling=resampling, models...)
end

function estimators_from_toml(config::Dict, queries, run_fn::typeof(PhenotypeTMLEEpistasis))
    tmles = Dict()
    queryvals = [x[2] for x in queries]
    isinteraction = length(queryvals[1]) > 1
    # Parse estimator for the propensity score
    metalearner = LogisticClassifier(fit_intercept=false)
    if isinteraction
        G = FullCategoricalJoint(stack_from_config(config["G"], metalearner))
    else
        G = stack_from_config(config["G"], metalearner)
    end

    # Parse estimator for the outcome regression
    if haskey(config, "Qcont")
        metalearner =  LinearRegressor(fit_intercept=false)
        Q̅ = stack_from_config(config["Qcont"], metalearner)
        tmles["continuous"] = TMLEstimator(Q̅, G, queryvals...)
    end

    if haskey(config, "Qcat")
        metalearner = LogisticClassifier(fit_intercept=false)
        Q̅ = stack_from_config(config["Qcat"], metalearner)
        tmles["binary"] = TMLEstimator(Q̅, G, queryvals...)
    end

    length(tmles) == 0 && throw(ArgumentError("At least one of (Qcat, Qcont) "*
                                               "should be specified in the TMLE"*
                                               " configuration file"))

    return tmles

end

function estimators_from_toml(config::Dict, queries, run_fn::typeof(PhenotypeCrossValidation))

    libraries = Dict()
    for key in ["G", "Qcont", "Qcat"]
        key_config = config[key]
        models = buildmodels(key_config)
        resampling = eval(Symbol(key_config["resampling"]["type"]))(nfolds=key_config["resampling"]["nfolds"])
        libraries[key] = (resampling, models)
    end

    return libraries

end


text:
"""
Provides functionality to resolve citations. A citation is indicated using `@citation`
for the `url` in a markdown link.
"""
module Citations

import Documenter:
    Documenter,
    Documents,
    Utilities,
    Builder,
    Expanders,
    Writers,
    Anchors

import .Utilities: Selectors
import .Utilities.DOM: @tags
import .Writers.HTMLWriter: domify
import Markdown

using PyCall
const btp = PyNULL()
function __init__()
    copy!(btp, pyimport_conda("bibtexparser", "bibtexparser"))
end

include("walk_and_replace.jl")

# Nodes for citations and bibliographies
include("nodes.jl")

include("CitationStyle.jl")

struct CitationPlugin <: Documenter.Plugin
    bibnodes::Vector{BibliographyNode}
    style::Symbol

    function CitationPlugin(style::Symbol=:default)
        new(Vector{BibliographyNode}(), style)
    end

end

# Extra build steps to register and resolve citations
include("RegisterCitations.jl")
include("GenerateBibliography.jl")
include("ResolveCitations.jl")

# Extend Documenter's Expander step to support bibliographies
include("BibliographyBlocks.jl")

# Extentions to the builtin HTMLWriter
# include("HTMLWriter.jl")

# Parse .bib files and format citations
include("citations.jl")

end # module


text:
"""
  NEqProblem(residuals)
  NEqProblem(residuals, options)

An NEqProblem (Non-linear system of Equations Problem), is used to represent the
mathematical problem of finding zeros in the residual function of square systems
of equations. The problem is defined by `residuals` which is an appropriate objective
type (for example `NonDiffed`, `OnceDiffed`, ...) for the types of algorithm to be used.

Options are stored in `options` and are of the `NEqOptions` type. See more information
about options using `?NEqOptions`.

The package NLSolversAD.jl adds automatic conversion of problems to match algorithms
that require higher order derivates than provided by the user. It also adds AD
constructors for a target number of derivatives.
"""
struct NEqProblem{TR,Tb,Tm<:Manifold,I}
    R::TR
    bounds::Tb
    manifold::Tm
    mstyle::I
end
function NEqProblem(residuals; inplace = true)
    mstyle = inplace === true ? InPlace() : OutOfPlace()
    NEqProblem(residuals, nothing, Euclidean(0), mstyle)
end
mstyle(problem::NEqProblem) = problem.mstyle
_manifold(prob::NEqProblem) = prob.manifold
is_inplace(problem::NEqProblem) = mstyle(problem) === InPlace()

#function value(nleq::NEqProblem, x)
#    nleq.R(x)
#end
function value(nleq::NEqProblem, x, F)
    value(nleq.R, x, F)
end
struct VectorObjective{TF,TJ,TFJ,TJv}
    F::TF
    J::TJ
    FJ::TFJ
    Jv::TJv
end
function value(nleq::VectorObjective, F, x)
    nleq.F(F, x)
end
function value_jacobian!(nleq::NEqProblem{<:VectorObjective,<:Any,<:Any}, F, J, x)
    nleq.FJ(F, J, x)
end

"""
  NEqOptions(; ...)

NEqOptions are used to control the behavior of solvers for non-linear systems of
equations. Current options are:

  - `maxiter` [= 10000]: number of major iterations where appropriate
"""
struct NEqOptions{T,Tmi,Call}
    f_limit::T
    f_abstol::T
    f_reltol::T
    maxiter::Tmi
    callback::Call
end
NEqOptions(;
    f_limit = 0.0,
    f_abstol = 1e-8,
    f_reltol = 1e-12,
    maxiter = 10^4,
    callback = nothing,
) = NEqOptions(f_limit, f_abstol, f_reltol, maxiter, callback)
function Base.show(io::IO, ci::ConvergenceInfo{<:Any,<:Any,<:NEqOptions})
    opt = ci.options
    info = ci.info

    println(io, "Results of solving non-linear equations\n")
    println(io, "* Algorithm:")
    println(io, "  $(summary(ci.solver))")
    println(io)
    println(io, "* Candidate solution:")
    println(
        io,
        "  Final residual 2-norm:      $(@sprintf("%.2e", norm(ci.info.best_residual, 2)))",
    )
    println(
        io,
        "  Final residual Inf-norm:    $(@sprintf("%.2e", norm(ci.info.best_residual, Inf)))",
    )
    if haskey(info, :temperature)
        println(io, "  Final temperature:        $(@sprintf("%.2e", ci.info.temperature))")
    end
    println(io)
    println(io, "  Initial residual 2-norm:    $(@sprintf("%.2e", info.ρ2F0))")
    println(io, "  Initial residual Inf-norm:  $(@sprintf("%.2e", info.ρF0))")
    println(io)
    println(io, "* Convergence measures")
    if true
        #    println(io, "  |x - x'|              = $(@sprintf("%.2e", info.ρs)) <= $(@sprintf("%.2e", opt.x_abstol)) ($(info.ρs<=opt.x_abstol))")
        #    println(io, "  |x - x'|/|x|          = $(@sprintf("%.2e", info.ρs/info.ρx)) <= $(@sprintf("%.2e", opt.x_reltol)) ($(info.ρs/info.ρx <= opt.x_reltol))")
        if isfinite(opt.f_limit)
            ρF = norm(info.best_residual, Inf)
            println(
                io,
                "  |F(x')|               = $(@sprintf("%.2e", ρF)) <= $(@sprintf("%.2e", opt.f_limit)) ($(ρF<=opt.f_limit))",
            )
        end
        if haskey(info, :fx)
            Δf = abs(info.fx - info.minimum)
            println(
                io,
                "  |f(x) - f(x')|        = $(@sprintf("%.2e", Δf)) <= $(@sprintf("%.2e", opt.f_abstol)) ($(Δf<=opt.f_abstol))",
            )
            println(
                io,
                "  |f(x) - f(x')|/|f(x)| = $(@sprintf("%.2e", Δf/abs(info.fx))) <= $(@sprintf("%.2e", opt.f_reltol)) ($(Δf/abs(info.fx)<=opt.f_reltol))",
            )
        end
        if haskey(info, :∇fz)
            ρ∇f = opt.g_norm(info.∇fz)
            println(
                io,
                "  |g(x)|                = $(@sprintf("%.2e", ρ∇f)) <= $(@sprintf("%.2e", opt.g_abstol)) ($(ρ∇f<=opt.g_abstol))",
            )
            println(
                io,
                "  |g(x)|/|g(x₀)|        = $(@sprintf("%.2e", ρ∇f/info.∇f0)) <= $(@sprintf("%.2e", opt.g_reltol)) ($(ρ∇f/info.∇f0<=opt.g_reltol))",
            )
        end
    end
    println(io)
    println(io, "* Work counters")
    println(io, "  Seconds run:   $(@sprintf("%.2e", info.time))")
    println(io, "  Iterations:    $(info.iter)")
end

max_stars_repo_name: JuliaNLSolvers/NLSolvers

max_issues_repo_name: JuliaNLSolvers/NLSolvers

max_forks_repo_name: JuliaNLSolvers/NLSolvers


text:
module TestComposeWiringDiagrams

using Test
import Compose

using Catlab.Doctrines, Catlab.WiringDiagrams
using Catlab: Graphics

to_composejl(f; kw...) = Graphics.to_composejl(f; outer_ports_layout=:fixed, kw...)

function tagged(ctx::Compose.Context, tag::Symbol)
  vcat(ctx.tag == tag ? [ctx] : [],
       mapreduce(c -> tagged(c, tag), vcat, ctx.container_children; init=[]))
end
tagged(pic::Graphics.ComposePicture, tag::Symbol) = tagged(pic.context, tag)

A, B = Ob(FreeSymmetricMonoidalCategory, :A, :B)
f, g = Hom(:f, A, B), Hom(:g, B, A)

pic = to_composejl(f)
@test length(tagged(pic, :box)) == 1
@test length(tagged(pic, :wire)) == 2

pic = to_composejl(id(A))
@test length(tagged(pic, :box)) == 0
@test length(tagged(pic, :wire)) == 1

pic = to_composejl(compose(f,g))
@test length(tagged(pic, :box)) == 2
@test length(tagged(pic, :wire)) == 3

pic = to_composejl(otimes(f,g))
@test length(tagged(pic, :box)) == 2
@test length(tagged(pic, :wire)) == 4

pic = to_composejl(braid(A,B))
@test length(tagged(pic, :box)) == 0
@test length(tagged(pic, :wire)) == 2

A, B = Ob(FreeBiproductCategory, :A, :B)

for expr in (mcopy(A), delete(A), mmerge(A), create(A))
  pic = to_composejl(expr)
  @test length(tagged(pic, :box)) == 1
end

end


text:
# Examples of handling a race condition.
# From https://github.com/JuliaGizmos/Reactive.jl/issues/115

module Example

using ReactiveBasics

# Here's the naive case from the issue.
# The update to `w` is faster, so we get a -41 as an intermediate answer before the final update to -60.
# For some applications, this may be fine, but for others, we might want a different order of operation.
# Results:
#  -11
#  -41
#  -60
function test1()
    x = Signal(1)
    y = map(a -> (sleep(2); -a), x)
    w = Signal(10)
    map(println, map(-, y, w))
    # suddenly two events appear in this order:
    @async push!(x, 20) # the @async just represents updates coming from a different task
    @async push!(w, 40)
    sleep(2.5); # wait till previous update goes through
end

# Here's another approach where we don't want the long operation to be bypassed.
# So, we use `flatmap` to create a Signal to make it wait for the value from the long calc.
# Note that ultimately, this only responds to changes in `x`.
# Results:
#  -11
#  -60
function test2()
    x = Signal(1)
    y = map(a -> (sleep(2); -a), x)
    w = Signal(10)
    map(println, flatmap(u -> map(-, Signal(u), w), y))
    # suddenly two events appear in this order:
    @async push!(x, 20) # the @async just represents updates coming from a different task
    @async push!(w, 40)
    sleep(2.5); # wait till previous update goes through
end

# Here's another try that responds to both x and w. It takes the inputs
# and puts them in an input queue to process one at a time.
# Results:
#  -11
#  -30
#  -60
function test3()
    queue = Any[]
    function queued(u::Signal)
        signal = Signal(u.value)
        subscribe!(u) do x
            unshift!(queue, (signal, x))  # add the signal to the queue
        end
        signal
    end
    function nextqueued()
        if !isempty(queue)
            signal, x = pop!(queue)
            push!(signal, x)
        end
    end
    xi = Signal(1)
    x = queued(xi)
    wi = Signal(10)
    w = queued(wi)
    y = map(a -> (sleep(2); -a), x)
    z = map(-, y, w)
    map(println, z)
    # suddenly two events appear in this order:
    @async push!(xi, 20) # the @async just represents updates coming from a different task
    @async push!(wi, 40)
    sleep(2.5); # wait till previous update goes through
    nextqueued()
    nextqueued()
end

println("Naive")
test1()
println("Better")
test2()
println("Input queue")
test3()

end # module


text:
function extend_from_vk(spec::SpecStruct)
    p = Dict(
        :category => :function,
        :name => :from_vk,
        :args => [:(T::Type{$(remove_vk_prefix(spec.name))}), :(x::$(spec.name))],
        :short => true,
    )
    p[:body] = :(T($(filter(!isnothing, from_vk_call.(spec.members))...)))
    p
end


text:
module BugReportingUnitTests

using BugReporting:
    check_perf_event_paranoid, get_record_flags, InvalidPerfEventParanoidError
using Test

@testset "get_record_flags" begin
    @test withenv(get_record_flags, "JULIA_RR_RECORD_ARGS" => "") == String[]
    @test withenv(get_record_flags, "JULIA_RR_RECORD_ARGS" => " ") == String[]
    @test withenv(get_record_flags, "JULIA_RR_RECORD_ARGS" => "-n") == ["-n"]
    @test withenv(get_record_flags, "JULIA_RR_RECORD_ARGS" => " -n ") == ["-n"]
end

@testset "check_perf_event_paranoid" begin
    function check(value, flags = "")
        mktemp() do path, io
            write(io, value)
            close(io)
            withenv("JULIA_RR_RECORD_ARGS" => flags) do
                check_perf_event_paranoid(path)
            end
        end
        return true
    end
    @test check("0")
    @test check("1")
    @test_throws InvalidPerfEventParanoidError check("2")
    @test_throws InvalidPerfEventParanoidError check("3")
    @test check("2", "-n")
    @test check("2", "--no-syscall-buffer")

    # Let `rr` handle these?
    @test check("non integer")
    withenv("JULIA_RR_RECORD_ARGS" => "") do
        @test check_perf_event_paranoid("/hopefully/non/existing/path") === nothing
    end

    err = try
        check("2")
    catch err
        err
    end
    @test err isa InvalidPerfEventParanoidError
    msg = sprint(showerror, err)
    @test contains(msg, "rr needs /proc/sys/kernel/perf_event_paranoid <= 1, but it is 2")
end

end  # module


text:
using ClimateTools,NCDatasets,NCTiles
# ClimateTools requires that lat,lon,time requires specific field names
# latitude: lat, latitude, rlat, y, yc
# longitude: lon, longitude, rlon, x, xc
# time: time
examplesdir = joinpath("data","ex5")
fldname = "Chl050"
indir = joinpath(examplesdir,"infiles")
savedir = joinpath(examplesdir,"outfiles")
if ~ispath(savedir); mkpath(savedir); end

"""
        climgridtoncvar(C::ClimGrid)

Creates an NCvar struct from a ClimGrid object. NCvar struct can then be written
to a NetCDF file using write().

Ex: C = load(fname,fldname)
writefld = climgridtoncvar(C)
write(writefld,"myfile.nc")
"""
function climgridtoncvar(C::ClimGrid)
        x, y, timevec = ClimateTools.getdims(C) # may need to check number of dims first
        timevec = NCDatasets.timeencode(timevec, C.timeattrib["units"], get(C.timeattrib,"calendar","standard"))

        dims = [NCvar(C.dimension_dict["lon"],C.lonunits,size(C.data)[1],x,Dict("long_name" => "longitude"),NCDatasets),
                NCvar(C.dimension_dict["lat"],C.latunits,size(C.data)[2],y,Dict("long_name" => "latitude"),NCDatasets),
                NCvar("time",C.timeattrib["units"],Inf,timevec,Dict(("long_name" => "tim","standard_name" => "time")),NCDatasets)
                ]

        return NCvar(fldname,C.dataunits,dims,C.data.data,C.varattribs,NCDatasets)
end

# First test one of our files
fname = joinpath(indir,"Chl050.nc")
README = readlines(joinpath(examplesdir,"README"))
savename = joinpath(savedir,"ex5.nc")

C = load(fname,fldname)
writefld = climgridtoncvar(C)
write(writefld,savename)

# Files from ClimateTools Example
gcmfiles =["tasmax_day_MIROC5_historical_r1i1p1_19800101-19891231.nc",
"tasmax_day_MIROC5_historical_r1i1p1_19900101-19991231.nc",
"tasmax_day_MIROC5_historical_r1i1p1_20000101-20091231.nc"]
fldname = "tasmax"
savename = joinpath(savedir,gcmfiles[1])
C = load(joinpath(indir,gcmfiles[1]),fldname)
writefld = climgridtoncvar(C)
write(writefld,savename)

# Following ClimateTools Example
# Extraction
poly_reg = [[NaN -65 -80 -80 -65 -65];[NaN 42 42 52 52 42]]
model = load(joinpath.(Ref(indir),gcmfiles), "tasmax", poly=poly_reg)
writefld = climgridtoncvar(model)
write(writefld,joinpath(savedir,"ex5_extraction.nc"),globalattribs=model.globalattribs)


text:
# multiDimAdditiveSDEExample()
using DiffEqProblemLibrary.SDEProblemLibrary: importsdeproblems; importsdeproblems()
import DiffEqProblemLibrary.SDEProblemLibrary: prob_sde_lorenz, oval2ModelExample

oval2ModelExample()

oval2ModelExample(useBigs=true,largeFluctuations=true)

true


text:
export irmid, irfirstbig

# ---- IR PEAK DETECTION ---------------------------------------------

irmid(x) = round(Int, length(x) / 2, RoundNearestTiesAway) # the first peak is in the middle

function irfirstbig(x::AbstractVector, threshold=0.5) # the first peak is the first one having size greater than threshold (normalized absoulute IR)
    x2 = abs.(x)
    x2 ./= maximum(x2)
    for i in 1:length(x2)
        if x2[i] > threshold
            return i
        end
    end
    @warn "irfirstbig: not found, returning first index!"
    return 1
end

function irfirstbig(a::SampleArray, threshold=0.5)
    nchannels(a) != 1 && throw(ArgumentError("number of channels != 1 ($(nchannels(a)))"))
    irfirstbig(data(a)[:, 1], threshold)
end

# Base.getindex(x::SampleBuf{T, 1} where T, pidx::Int, pre::Int, post::Int) = x[pidx-pre:pidx+post]
# Base.getindex(x::SampleBuf{T, 1} where T, pidx::Int, pre, post) = x[pidx, _convtime(x, pre), _convtime(x, post)]
# Base.getindex(x::SampleBuf{T, 1} where T, peakf::Function, pre, post) = x[peakf(x), _convtime(x, pre), _convtime(x, post)]


text:
# f(x)=abs(x)

function Fabs(x)
    return (abs(x),nothing)
end

function Fabs_inplace(value::Array,auxvalue,x) # inplace
    copy!(value,abs(x))
end

function Dabs(derivativeIDX,f_c,faux_c,grad_c,grad_n,x)
    axpy!(1.0,sign(x).*grad_c,grad_n)
end

if PROC=="GPU"
    function Fabs_inplace(value::CudaArray,auxvalue,x::CudaArray) # inplace
        fill!(value,0.0)
        abs!(x,value)
    end

    function Dabs(derivativeIDX,f_c,faux_c,grad_c,grad_n,x::CudaArray)
        xsigny_update!(grad_c,x,grad_n)
    end
end

Derivative[Fabs]=Dabs # Define dictionary lookup
Inplace[Fabs]=Fabs_inplace

import Base.abs

abs(n::ADnode)=ADnode(Fabs,n)

###abs(A::ADtrans)=transpose(abs(node[A.parent])) # abs(A')=(abs(A))' TODO:check

export abs

max_stars_repo_name: davidbarber/AutoDiff

max_issues_repo_name: davidbarber/AutoDiff

max_forks_repo_name: davidbarber/AutoDiff


text:
import Random: GLOBAL_RNG

"""Random number generator for Float32 in [0,1) that samples from
42*2^23 float32s in [0,1) compared to 2^23 for rand(Float32)."""
function randfloat(rng::Random.AbstractRNG,::Type{Float32})
    # create exponent bits in 0000_0000 to 0111_1110
    # at following chances
    # e=01111110 at 50.0% for [0.5,1.0)
    # e=01111101 at 25.0% for [0.25,0.5)
    # e=01111100 at 12.5% for [0.125,0.25)
    # ...
    ui = rand(rng,UInt64)

    # count leading zeros of random UInt64
    # 0 leading zeros at 50% chance
    # 1 leading zero at 25% chance
    # 2 leading zeros at 12.5% chance etc.
    # then convert leading zeros to exponent bits of Float32
    lz = leading_zeros(ui)
    e = ((126 - lz) % UInt32) << 23

    # for 64 leading zeros the smallest float32 that can be created is 2.7105054f-20
    # use last 23 bits for signficand, only when they are not part of the leading zeros
    # to sample from all floats in 2.7105054f-20 to prevfloat(1f0)
    ui = lz > 40 ? rand(rng,UInt64) : ui

    # combine exponent and signficand
    return reinterpret(Float32,e | ((ui % UInt32) & 0x007f_ffff))
end

"""Random number generator for Float64 in [0,1) that samples from
64*2^52 floats compared to 2^52 for rand(Float64)."""
function randfloat(rng::Random.AbstractRNG,::Type{Float64})
    # create exponent bits in 000_0000_0000 to 011_1111_1110
    # at following chances
    # e=01111111110 at 50.0% for [0.5,1.0)
    # e=01111111101 at 25.0% for [0.25,0.5)
    # e=01111111100 at 12.5% for [0.125,0.25)
    # ...
    ui = rand(rng,UInt64)

    # count leading zeros of random UInt64 in several steps
    # 0 leading zeros at 50% chance
    # 1 leading zero at 25% chance
    # 2 leading zeros at 12.5% chance etc.
    # then convert leading zeros to exponent bits of Float64
    lz = leading_zeros(ui)
    e = ((1022 - lz) % UInt64) << 52

    # for 64 leading zeros the smallest float64 that
    # can be created is 2.710505431213761e-20

    # draw another UInt64 for significant bits in case the leading
    # zeros reach into the bits that would be used for the significand
    # (in which case the first signifcant bits would always be zero)
    ui = lz > 11 ? rand(rng,UInt64) : ui

    # combine exponent and significand (sign always 0)
    return reinterpret(Float64,e | (ui & 0x000f_ffff_ffff_ffff))
end

"""Random number generator for Float16 in [0,1) that samples from
all 15360 float16s in that range."""
function randfloat(rng::Random.AbstractRNG,::Type{Float16})
    # create exponent bits in 00000 to 01110
    # at following chances
    # e=01110 at 50.0% for [0.5,1.0)
    # e=01101 at 25.0% for [0.25,0.5)
    # e=01100 at 12.5% for [0.125,0.25)
    # ...
    ui = rand(rng,UInt32) | 0x0002_0000
    # set 15th bit to 1 to have at most 14 leading zeros.

    # count leading zeros of random UInt64 in several steps
    # 0 leading zeros at 50% chance
    # 1 leading zero at 25% chance
    # 2 leading zeros at 12.5% chance etc.
    # then convert leading zeros to exponent bits of Float16
    lz = leading_zeros(ui)
    e = ((14 - lz) % UInt32) << 10

    # combine exponent and significand (sign always 0)
    return reinterpret(Float16,(e | (ui & 0x0000_03ff)) % UInt16)
end

# use stdlib default RNG as a default here too
randfloat(::Type{T}=Float64) where {T<:Base.IEEEFloat} = randfloat(GLOBAL_RNG,T)
randfloat(rng::Random.AbstractRNG) = randfloat(rng,Float64)

# randfloat for arrays - in-place
function randfloat!(rng::Random.AbstractRNG, A::AbstractArray{T}) where T
    for i in eachindex(A)
        @inbounds A[i] = randfloat(rng, T)
    end
    A
end

# randfloat for arrays with memory allocation
randfloat(rng::Random.AbstractRNG, ::Type{T}, dims::Integer...) where {T<:Base.IEEEFloat} = randfloat!(rng, Array{T}(undef,dims))
randfloat(rng::Random.AbstractRNG,            dims::Integer...)                           = randfloat!(rng, Array{Float64}(undef,dims))
randfloat(::Type{T}, dims::Integer...) where {T<:Base.IEEEFloat} = randfloat!(GLOBAL_RNG, Array{T}(undef,dims))
randfloat(           dims::Integer...)                           = randfloat!(GLOBAL_RNG, Array{Float64}(undef,dims))


text:
module Serde

# --------------------------------
# Include
# --------------------------------

# tools
include("packing.jl")
include("quantizer.jl")
include("delta_compressor.jl")

# payload serde
include("payloads/payload.jl")
include("payloads/vanilla_payload.jl")
include("payloads/quantized_payload.jl")
include("payloads/qdiff_payload.jl")
include("payloads/qdiff_static_payload.jl")
include("payloads/gd_payload.jl")
include("payloads/gd_static_payload.jl")

# --------------------------------
# Export
# --------------------------------
export pack, unpack, Quantizer, quantize, dequantize, Patch, diff, patch,
    PayloadSerde, serialize_payload, deserialize_payload, VanillaPayloadSerde,
    QuantizedPayloadSerde, QDiffPayloadSerde, QDiffStaticPayloadSerde,
    GDPayloadSerde

end # module