text:
function get_boundary_indices(mgrid,::FdtdOld)
	# where to store the boundary values (careful, born scaterrers cannot be inside these!?)
	ibx0=_fd.npml-2; ibx1=length(mgrid[2])+_fd.npml+3
	ibz0=_fd.npml-2; ibz1=length(mgrid[1])+_fd.npml+3
#	ibx0=_fd.npml+1; ibx1=length(mgrid[2])+_fd.npml
#	ibz0=_fd.npml+1; ibz1=length(mgrid[1])+_fd.npml
#	println("**** Boundary Storage Changed **** ")

	# for snaps
	isx0, isz0=_fd.npml, _fd.npml

	return NamedArray([ibx0,ibx1,ibz0,ibz1,isx0,isz0],([:bx0,:bx1,:bz0,:bz1,:sx0,:sz0],))

end

function get_boundary_indices(mgrid,::FdtdElastic)
	return NamedArray([1],[:a]) # some dummy, update later
end

@inbounds @fastmath function boundary_force_snap_p!(issp::Int64,pac,pap)
	ps=pap[1].w1[:t][:p]
	boundary=pap[1].ss[issp].boundary[5]
	bs=view(boundary,:,:,1)
	copyto!(ps,bs)
end
@inbounds @fastmath function boundary_force_snap_vxvz!(issp::Int64,pac,pap)
	# initial conditions from boundary for first propagating field only
	ps=pap[1].w1[:t][:vx]
	boundary=pap[1].ss[issp].boundary[5]
	bs=view(boundary,:,:,2)
	copyto!(ps,bs)
	ps=pap[1].w1[:t][:vz]
	bs=view(boundary,:,:,3)
	copyto!(ps,bs)
end
@fastmath @inbounds function boundary_force!(it::Int64,issp::Int64,pac,pap)
	boundary=pap[1].ss[issp].boundary
	p=pap[1].w1[:t]
	ibx0=pac.bindices[:bx0]; ibz0=pac.bindices[:bz0]; ibx1=pac.bindices[:bx1]; ibz1=pac.bindices[:bz1]
	boundaryf_l!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
	boundaryf_r!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
	boundaryf_t!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
	boundaryf_b!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
end
@fastmath @inbounds function boundaryf_l!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
	pw=p[:p]
	for ix=1:3
		@simd for iz=1:ibz1-ibz0+1
			pw[ibz0+iz-1,ibx0+ix-1] = boundary[4][iz,ix,it]
		end
	end
end
@fastmath @inbounds function boundaryf_r!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
	pw=p[:p]
	for ix=1:3
		@simd for iz=1:ibz1-ibz0+1
			pw[ibz0+iz-1,ibx1-ix+1] = boundary[2][iz,ix,it]
		end
	end
end
@fastmath @inbounds function boundaryf_t!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
	pw=p[:p]
	@simd for ix=1:ibx1-ibx0+1
		for iz=1:3
			pw[ibz0+iz-1,ibx0+ix-1] = boundary[1][iz,ix,it]
		end
	end
end
@fastmath @inbounds function boundaryf_b!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
	pw=p[:p]
	@simd for ix=1:ibx1-ibx0+1
		for iz=1:3
			pw[ibz1-iz+1,ibx0+ix-1] = boundary[3][iz,ix,it]
		end
	end
end

@inbounds @fastmath function boundary_save_snap_p!(issp::Int64,pac,pap)
	ps=pap[1].w1[:t][:p]
	boundary=pap[1].ss[issp].boundary[5]
	bs=view(boundary,:,:,1)
	copyto!(bs, ps)
end
@inbounds @fastmath function boundary_save_snap_vxvz!(issp::Int64,pac,pap)
	boundary=pap[1].ss[issp].boundary[5]
	#vx
	bs=view(boundary,:,:,2)
	ps=pap[1].w1[:t][:vx]
	copyto!(bs, ps)
	rmul!(bs,-1.)
	# vz
	bs=view(boundary,:,:,3)
	ps=pap[1].w1[:t][:vz]
	copyto!(bs, ps)
	rmul!(bs,-1.)
end
@fastmath @inbounds function boundary_save!(it::Int64,issp::Int64,pac,pap)
	boundary=pap[1].ss[issp].boundary
	p=pap[1].w1[:t]
	ibx0=pac.bindices[:bx0]; ibz0=pac.bindices[:bz0]; ibx1=pac.bindices[:bx1]; ibz1=pac.bindices[:bz1]
	boundarys_l!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
	boundarys_r!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
	boundarys_t!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
	boundarys_b!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
end
@fastmath @inbounds function boundarys_l!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
	pw=p[:p]
	for ix=1:3
		@simd for iz=1:ibz1-ibz0+1
			boundary[4][iz,ix,it] = pw[ibz0+iz-1,ibx0+ix-1]
		end
	end
end
@fastmath @inbounds function boundarys_r!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
	pw=p[:p]
	for ix=1:3
		@simd for iz=1:ibz1-ibz0+1
			boundary[2][iz,ix,it] = pw[ibz0+iz-1,ibx1-ix+1]
		end
	end
end
@fastmath @inbounds function boundarys_t!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
	pw=p[:p]
	@simd for ix=1:ibx1-ibx0+1
		for iz=1:3
			boundary[1][iz,ix,it] = pw[ibz0+iz-1,ibx0+ix-1]
		end
	end
end
@fastmath @inbounds function boundarys_b!(it,ibx0,ibx1,ibz0,ibz1,p,boundary)
	pw=p[:p]
	@simd for ix=1:ibx1-ibx0+1
		for iz=1:3
			boundary[3][iz,ix,it] = pw[ibz1-iz+1,ibx0+ix-1]
		end
	end
end


text:
module QuickPOMDPs

using POMDPs
using POMDPModelTools
using BeliefUpdaters
using POMDPTesting
using UUIDs
using NamedTupleTools
using Random

export
    DiscreteExplicitPOMDP,
    DiscreteExplicitMDP,
    QuickMDP,
    QuickPOMDP,
    MissingQuickArgument

include("discrete_explicit.jl")
include("quick.jl")
include("quick_error.jl")

end # module

ext: jl


text:
module Dec6Part2
function string_2_set(x::String)::Set
    return Set(x)
end

function multiple_to_single(x::String)::String
    return join(split(x, '\n'))
end

function extract_chunks(x::String, pattern::Regex)::Array{String,1}
    match_iterator = eachmatch(pattern, x)
    return map(x -> strip(x.match), match_iterator)
end

function get_counts(x::String)::Int64
    multilines = String.(split(x, '\n'))
    multilines_set = string_2_set.(multilines)
    common_questions = intersect(multilines_set...)
    return length(common_questions)
end

function main(file_path::String)::Int64
    groups_string = read(file_path, String)
    group_array = extract_chunks(groups_string, r"(?s)((?:[^\n][\n]?)+)")
    counts = get_counts.(group_array)
    return sum(counts)
end
end


text:
@testset "Discrete identity system" begin
    for sd in 1:3
        s = DiscreteIdentitySystem(sd)
        @test statedim(s) == sd
        @test inputdim(s) == 0
        @test noisedim(s) == 0
        @test islinear(s) && isaffine(s) && !ispolynomial(s)
        @test !isnoisy(s) && !iscontrolled(s) && !isconstrained(s)
    end
end

@testset "Discrete constrained identity system" begin
    for sd in 1:3
        X = Singleton(ones(sd))
        s = ConstrainedDiscreteIdentitySystem(sd, X)
        @test statedim(s) == sd
        @test inputdim(s) == 0
        @test noisedim(s) == 0
        @test stateset(s) == X
        @test islinear(s) && isaffine(s) && !ispolynomial(s)
        @test !isnoisy(s) && !iscontrolled(s) && isconstrained(s)
    end
end

@testset "Discrete linear system" begin
    for sd in 1:3
        s = LinearDiscreteSystem(zeros(sd, sd))
        @test statedim(s) == sd
        @test inputdim(s) == 0
        @test noisedim(s) == 0
        @test islinear(s) && isaffine(s) && !ispolynomial(s)
        @test !isnoisy(s) && !iscontrolled(s) && !isconstrained(s)
    end
end

@testset "Discrete affine system" begin
    for sd in 1:3
        s = AffineDiscreteSystem(zeros(sd, sd), zeros(sd))
        @test statedim(s) == sd
        @test inputdim(s) == 0
        @test noisedim(s) == 0
        @test !islinear(s) && isaffine(s) && !ispolynomial(s)
        @test !isnoisy(s) && !iscontrolled(s) && !isconstrained(s)
    end
end

@testset "Discrete linear control system" begin
    for sd in 1:3
        s = LinearControlDiscreteSystem(zeros(sd, sd), ones(sd, sd))
        @test statedim(s) == sd
        @test inputdim(s) == sd
        @test noisedim(s) == 0
        @test islinear(s) && isaffine(s) && !ispolynomial(s)
        @test !isnoisy(s) && iscontrolled(s) && !isconstrained(s)
    end
end

@testset "Discrete constrained linear system" begin
    A = [1. 1; 1 -1]
    X = Line([1., -1], 0.) # line x = y
    s = ConstrainedLinearDiscreteSystem(A, X)
    @test statedim(s) == 2
    @test inputdim(s) == 0
    @test noisedim(s) == 0
    @test stateset(s) == X
    @test islinear(s) && isaffine(s) && !ispolynomial(s)
    @test !isnoisy(s) && !iscontrolled(s) && isconstrained(s)
end

@testset "Discrete constrained affine system" begin
    A = [1. 1; 1 -1]
    c = [1.; 1.]
    X = Line([1., -1], 0.) # line x = y
    s = ConstrainedAffineDiscreteSystem(A, c, X)
    @test statedim(s) == 2
    @test inputdim(s) == 0
    @test noisedim(s) == 0
    @test stateset(s) == X
    @test !islinear(s) && isaffine(s) && !ispolynomial(s)
    @test !isnoisy(s) && !iscontrolled(s) && isconstrained(s)
end

@testset "Discrete constrained linear control system" begin
    A = [1. 1; 1 -1]
    B = Matrix([0.5 1.5]')
    X = Line([1., -1], 0.)
    U = Interval(0.9, 1.1)
    s = ConstrainedLinearControlDiscreteSystem(A, B, X, U)
    @test statedim(s) == 2
    @test inputdim(s) == 1
    @test noisedim(s) == 0
    @test stateset(s) == X
    @test inputset(s) == U
    @test islinear(s) && isaffine(s) && !ispolynomial(s)
    @test !isnoisy(s) && iscontrolled(s) && isconstrained(s)
end

@testset "Discrete linear algebraic system" begin
    for sd in 1:3
        s = LinearAlgebraicDiscreteSystem(zeros(sd, sd), zeros(sd, sd))
        @test statedim(s) == sd
        @test inputdim(s) == 0
        @test noisedim(s) == 0
        @test islinear(s) && isaffine(s) && !ispolynomial(s)
        @test !isnoisy(s) && !iscontrolled(s) && !isconstrained(s)
    end
end

@testset "Discrete constrained linear algebraic system" begin
    A = [1. 1; 1 -1]
    E = [0. 1; 1 0]
    X = LinearConstraint([0, -1.], 0.) # the set y ≥ 0
    s = ConstrainedLinearAlgebraicDiscreteSystem(A, E, X)
    @test statedim(s) == 2
    @test inputdim(s) == 0
    @test noisedim(s) == 0
    @test stateset(s) == X
    @test islinear(s) && isaffine(s) && !ispolynomial(s)
    @test !isnoisy(s) && !iscontrolled(s) && isconstrained(s)
end

@testset "Polynomial system in discrete time" begin
    @polyvar x y
    p = 2x^2 - 3x + y
    s = PolynomialDiscreteSystem(p)
    @test statedim(s) == 2
    @test inputdim(s) == 0
    @test noisedim(s) == 0
    @test !islinear(s) && !isaffine(s) && ispolynomial(s)
    @test !isnoisy(s) && !iscontrolled(s) && !isconstrained(s)
end

@testset "Polynomial system in discrete time with state constraints" begin
    @polyvar x y
    p = 2x^2 - 3x + y
    X = BallInf(zeros(2), 0.1)
    s = ConstrainedPolynomialDiscreteSystem(p, X)
    @test statedim(s) == 2
    @test inputdim(s) == 0
    @test noisedim(s) == 0
    @test dim(stateset(s)) == dim(X)
    @test !islinear(s) && !isaffine(s) && ispolynomial(s)
    @test !isnoisy(s) && !iscontrolled(s) && isconstrained(s)
end

@testset "Implicit discrete system" begin
    add_one(x) = x + 1
    s = BlackBoxDiscreteSystem(add_one, 1)
    x = 1.0
    @test s.f(x) ≈ 2.0
    @test !islinear(s) && !isaffine(s) && !ispolynomial(s)
    @test !isnoisy(s) && !iscontrolled(s) && !isconstrained(s)
end

@testset "Noisy Discrete constrained linear system" begin
    A = [1. 1; 1 -1]
    D = [1. 2; 0 1]
    X = Line([1., -1], 0.) # line x = y
    W = BallInf(zeros(2), 2.0)
    s = NoisyConstrainedLinearDiscreteSystem(A, D, X, W)
    @test s.A == A
    @test s.D == D
    @test statedim(s) == 2
    @test inputdim(s) == 0
    @test noisedim(s) == 2 == dim(W)
    @test stateset(s) == X
    @test noiseset(s) == W
    @test islinear(s) && isaffine(s) && !ispolynomial(s)
    @test isnoisy(s) && !iscontrolled(s) && isconstrained(s)
end

@testset "Noisy Discrete constrained control linear system" begin
    A = [1. 1; 1 -1]
    B = Matrix([0.5 1.5]')
    D = [1. 2; 0 1]
    X = Line([1., -1], 0.) # line x = y
    U = Hyperrectangle(low=[0.9], high=[1.1])
    W = BallInf(zeros(2), 2.0)
    s = NoisyConstrainedLinearControlDiscreteSystem(A, B, D, X, U, W)
    @test s.A == A
    @test s.B == B
    @test s.D == D
    @test statedim(s) == 2
    @test inputdim(s) == dim(U)
    @test noisedim(s) == 2 == dim(W)
    @test stateset(s) == X
    @test inputset(s) == U
    @test noiseset(s) == W
    @test islinear(s) && isaffine(s) && !ispolynomial(s)
    @test isnoisy(s) && iscontrolled(s) && isconstrained(s)
end

@testset "Noisy Discrete constrained control affine system" begin
    A = [1. 1; 1 -1]
    B = Matrix([0.5 1.5]')
    c = [1.0, 0.5]
    D = [1. 2; 0 1]
    X = Line([1., -1], 0.) # line x = y
    U = Hyperrectangle(low=[0.9], high=[1.1])
    W = BallInf(zeros(2), 2.0)
    s = NoisyConstrainedAffineControlDiscreteSystem(A, B, c, D, X, U, W)
    @test s.A == A
    @test s.B == B
    @test s.c == c
    @test s.D == D
    @test statedim(s) == 2
    @test inputdim(s) == dim(U)
    @test noisedim(s) == 2 == dim(W)
    @test stateset(s) == X
    @test inputset(s) == U
    @test noiseset(s) == W
    @test isaffine(s) && !islinear(s) && !ispolynomial(s)
    @test isnoisy(s) && iscontrolled(s) && isconstrained(s)
end

@testset "Noisy Discrete constrained control blackbox system" begin
    n = 2
    m = 1
    l = 2
    f(x,u,w) = ones(n,n)*x + ones(n,m)*u + ones(n,l)*w
    X = BallInf(zeros(n), 1.0)
    U =  BallInf(zeros(m), 1.0)
    W =  BallInf(zeros(l), 1.0)
    s = NoisyConstrainedBlackBoxControlDiscreteSystem(f, n, m, l, X, U, W)
    @test s.f == f
    @test statedim(s) == n
    @test inputdim(s) == dim(U)
    @test noisedim(s) == l == dim(W)
    @test stateset(s) == X
    @test inputset(s) == U
    @test noiseset(s) == W
    @test !islinear(s) && !isaffine(s) && !ispolynomial(s)
    @test isnoisy(s) && iscontrolled(s) && isconstrained(s)
end

@testset "Constant input in a discrete constrained linear control system" begin
    A = [1. 1; 1 -1]
    B = Matrix([0.5 1.5]')
    X = Line([1., -1], 0.)
    U = ConstantInput(Hyperrectangle(low=[0.9], high=[1.1]))
    s = ConstrainedLinearControlDiscreteSystem(A, B, X, U)
    s = ConstrainedLinearControlDiscreteSystem(A, B, X, U)
    if VERSION < v"0.7-"
        @test next(s.U, 1)[1] isa Hyperrectangle
    else
        @test iterate(s.U)[1] isa Hyperrectangle
    end
end

@testset "Varying input in a discrete constrained linear control system" begin
    A = [1. 1; 1 -1]
    B = Matrix([0.5 1.5]')
    X = Line([1., -1], 0.)
    U = VaryingInput([Hyperrectangle(low=[0.9], high=[1.1]),
                      Hyperrectangle(low=[0.99], high=[1.0])])
    s = ConstrainedLinearControlDiscreteSystem(A, B, X, U)
    @test length(s.U) == 2
    for ui in s.U
        @test ui isa Hyperrectangle
    end
end


text:
using BenchmarkTools
using Profile

include("../src/soalight.jl")
include("../src/allocator.jl")
include("../src/tree_iter.jl")

function testbase5()
    tree = AVLTrees.AVLSet{Int}()
    for j in 1:10000000
        i = rand(1:100000)
        # println("insert ", i, " ", haskey(tree, i))
        push!(tree, i)
        i = rand(1:100000)
        # println("delete ", i, " ", haskey(tree, i))
        delete!(tree, i)
        if j % 1000 == 0
            print(".")
        end
    end
end

function testbase6()
    tree = nil()
    for j in 1:10000000
        i = rand(1:100000)
        # println("insert ", i, " ", haskey(tree, i))
        tree = insert(tree, i, nothing)
        i = rand(1:100000)
        # println("delete ", i, " ", haskey(tree, i))
        tree = delete(tree, i)
        if j % 1000 == 0
            print(".")
        end
    end
end

function testalloc()
    alloc = FreeListAllocator{TreeNode{Int, Int}, Int}(nothing)
    tree = nil(alloc)
    for j in 1:10000000
        i = rand(1:100000)
        # println("insert ", i, " ", haskey(tree, i, alloc))
        tree = insert(tree, i, nothing, alloc)
        i = rand(1:100000)
        # println("delete ", i, " ", haskey(tree, i, alloc))
        tree = delete(tree, i, alloc)
        if j % 1000 == 0
            print(".")
        end
    end
end


text:
export SimpleConvexSet, AxisAlignedBox, Ball, SetComplement
export inflate

abstract type SimpleConvexSet end

struct AxisAlignedBox{N,T} <: SimpleConvexSet
    lo::SVector{N,T}
    hi::SVector{N,T}
end
AxisAlignedBox(lo, hi) = AxisAlignedBox{length(lo),eltype(lo)}(lo, hi)
Base.in(x, B::AxisAlignedBox{N}) where {N} = all(B.lo[i] <= x[i] <= B.hi[i] for i in 1:N)
Base.rand(B::AxisAlignedBox) = B.lo + (B.hi - B.lo).*rand(typeof(B.lo))
inflate(B::AxisAlignedBox, ε) = AxisAlignedBox(B.lo .- ε, B.hi .+ ε)
@recipe function f(B::AxisAlignedBox; dims=(1, 2))
    seriestype :=  :shape
    fillcolor  --> :match
    linecolor  --> :match
    label      --> ""
    x, y = dims
    SVector(B.lo[x], B.hi[x], B.hi[x], B.lo[x]), SVector(B.lo[y], B.lo[y], B.hi[y], B.hi[y])
end

struct Ball{N,T} <: SimpleConvexSet
    c::SVector{N,T}
    r::T
end
Ball(c, r) = Ball{length(c),eltype(c)}(c, r)
Base.in(x, B::Ball{N}) where {N} = norm(x - B.c) <= B.r
Base.rand(B::Ball) = (x = B.c + 2*B.r*(rand(typeof(B.c)) .- 1//2); x in B ? x : rand(B))
inflate(B::Ball, ε) = Ball(B.c, B.r + ε)
@recipe function f(B::Ball; dims=(1, 2), n=64)
    seriestype :=  :shape
    fillcolor  --> :match
    linecolor  --> :match
    label      --> ""
    x, y = dims
    θ = range(-π, stop=π, length=n)
    B.c[x] .+ B.r*cos.(θ), B.c[y] .+ B.r*sin.(θ)
end

struct SetComplement{S}
    set::S
end
SetComplement(S::SetComplement) = S.set
Base.in(x, S::SetComplement) = !(x in S.set)
@recipe f(S::SetComplement; dims=(1,2)) = nothing

max_stars_repo_name: pbpf/clean

max_issues_repo_name: pbpf/clean

max_forks_repo_name: pbpf/clean


text:
# syntax: proto3
using ProtoBuf
import ProtoBuf.meta

mutable struct LogicManager_GetRule_Req <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function LogicManager_GetRule_Req(; kwargs...)
        obj = new(meta(LogicManager_GetRule_Req), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct LogicManager_GetRule_Req
const __meta_LogicManager_GetRule_Req = Ref{ProtoMeta}()
function meta(::Type{LogicManager_GetRule_Req})
    ProtoBuf.metalock() do
        if !isassigned(__meta_LogicManager_GetRule_Req)
            __meta_LogicManager_GetRule_Req[] = target = ProtoMeta(LogicManager_GetRule_Req)
            allflds = Pair{Symbol,Union{Type,String}}[:label => AbstractString]
            meta(target, LogicManager_GetRule_Req, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_LogicManager_GetRule_Req[]
    end
end
function Base.getproperty(obj::LogicManager_GetRule_Req, name::Symbol)
    if name === :label
        return (obj.__protobuf_jl_internal_values[name])::AbstractString
    else
        getfield(obj, name)
    end
end

mutable struct LogicManager_GetRule <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function LogicManager_GetRule(; kwargs...)
        obj = new(meta(LogicManager_GetRule), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct LogicManager_GetRule
const __meta_LogicManager_GetRule = Ref{ProtoMeta}()
function meta(::Type{LogicManager_GetRule})
    ProtoBuf.metalock() do
        if !isassigned(__meta_LogicManager_GetRule)
            __meta_LogicManager_GetRule[] = target = ProtoMeta(LogicManager_GetRule)
            allflds = Pair{Symbol,Union{Type,String}}[]
            meta(target, LogicManager_GetRule, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_LogicManager_GetRule[]
    end
end

mutable struct LogicManager_PutRule_Req <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function LogicManager_PutRule_Req(; kwargs...)
        obj = new(meta(LogicManager_PutRule_Req), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct LogicManager_PutRule_Req
const __meta_LogicManager_PutRule_Req = Ref{ProtoMeta}()
function meta(::Type{LogicManager_PutRule_Req})
    ProtoBuf.metalock() do
        if !isassigned(__meta_LogicManager_PutRule_Req)
            __meta_LogicManager_PutRule_Req[] = target = ProtoMeta(LogicManager_PutRule_Req)
            allflds = Pair{Symbol,Union{Type,String}}[:label => AbstractString, :when => AbstractString, :then => AbstractString]
            meta(target, LogicManager_PutRule_Req, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_LogicManager_PutRule_Req[]
    end
end
function Base.getproperty(obj::LogicManager_PutRule_Req, name::Symbol)
    if name === :label
        return (obj.__protobuf_jl_internal_values[name])::AbstractString
    elseif name === :when
        return (obj.__protobuf_jl_internal_values[name])::AbstractString
    elseif name === :then
        return (obj.__protobuf_jl_internal_values[name])::AbstractString
    else
        getfield(obj, name)
    end
end

mutable struct LogicManager_PutRule <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function LogicManager_PutRule(; kwargs...)
        obj = new(meta(LogicManager_PutRule), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct LogicManager_PutRule
const __meta_LogicManager_PutRule = Ref{ProtoMeta}()
function meta(::Type{LogicManager_PutRule})
    ProtoBuf.metalock() do
        if !isassigned(__meta_LogicManager_PutRule)
            __meta_LogicManager_PutRule[] = target = ProtoMeta(LogicManager_PutRule)
            allflds = Pair{Symbol,Union{Type,String}}[]
            meta(target, LogicManager_PutRule, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_LogicManager_PutRule[]
    end
end

mutable struct LogicManager_GetRules_Req <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function LogicManager_GetRules_Req(; kwargs...)
        obj = new(meta(LogicManager_GetRules_Req), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct LogicManager_GetRules_Req
const __meta_LogicManager_GetRules_Req = Ref{ProtoMeta}()
function meta(::Type{LogicManager_GetRules_Req})
    ProtoBuf.metalock() do
        if !isassigned(__meta_LogicManager_GetRules_Req)
            __meta_LogicManager_GetRules_Req[] = target = ProtoMeta(LogicManager_GetRules_Req)
            allflds = Pair{Symbol,Union{Type,String}}[]
            meta(target, LogicManager_GetRules_Req, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_LogicManager_GetRules_Req[]
    end
end

mutable struct LogicManager_Req <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function LogicManager_Req(; kwargs...)
        obj = new(meta(LogicManager_Req), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct LogicManager_Req
const __meta_LogicManager_Req = Ref{ProtoMeta}()
function meta(::Type{LogicManager_Req})
    ProtoBuf.metalock() do
        if !isassigned(__meta_LogicManager_Req)
            __meta_LogicManager_Req[] = target = ProtoMeta(LogicManager_Req)
            allflds = Pair{Symbol,Union{Type,String}}[:get_rule_req => LogicManager_GetRule_Req, :put_rule_req => LogicManager_PutRule_Req, :get_rules_req => LogicManager_GetRules_Req]
            oneofs = Int[1,1,1]
            oneof_names = Symbol[Symbol("req")]
            meta(target, LogicManager_Req, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, oneofs, oneof_names)
        end
        __meta_LogicManager_Req[]
    end
end
function Base.getproperty(obj::LogicManager_Req, name::Symbol)
    if name === :get_rule_req
        return (obj.__protobuf_jl_internal_values[name])::LogicManager_GetRule_Req
    elseif name === :put_rule_req
        return (obj.__protobuf_jl_internal_values[name])::LogicManager_PutRule_Req
    elseif name === :get_rules_req
        return (obj.__protobuf_jl_internal_values[name])::LogicManager_GetRules_Req
    else
        getfield(obj, name)
    end
end

mutable struct LogicManager_GetRules <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function LogicManager_GetRules(; kwargs...)
        obj = new(meta(LogicManager_GetRules), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct LogicManager_GetRules
const __meta_LogicManager_GetRules = Ref{ProtoMeta}()
function meta(::Type{LogicManager_GetRules})
    ProtoBuf.metalock() do
        if !isassigned(__meta_LogicManager_GetRules)
            __meta_LogicManager_GetRules[] = target = ProtoMeta(LogicManager_GetRules)
            allflds = Pair{Symbol,Union{Type,String}}[]
            meta(target, LogicManager_GetRules, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_LogicManager_GetRules[]
    end
end

mutable struct LogicManager <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function LogicManager(; kwargs...)
        obj = new(meta(LogicManager), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct LogicManager
const __meta_LogicManager = Ref{ProtoMeta}()
function meta(::Type{LogicManager})
    ProtoBuf.metalock() do
        if !isassigned(__meta_LogicManager)
            __meta_LogicManager[] = target = ProtoMeta(LogicManager)
            allflds = Pair{Symbol,Union{Type,String}}[]
            meta(target, LogicManager, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_LogicManager[]
    end
end

mutable struct Rule_Delete_Req <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function Rule_Delete_Req(; kwargs...)
        obj = new(meta(Rule_Delete_Req), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct Rule_Delete_Req
const __meta_Rule_Delete_Req = Ref{ProtoMeta}()
function meta(::Type{Rule_Delete_Req})
    ProtoBuf.metalock() do
        if !isassigned(__meta_Rule_Delete_Req)
            __meta_Rule_Delete_Req[] = target = ProtoMeta(Rule_Delete_Req)
            allflds = Pair{Symbol,Union{Type,String}}[]
            meta(target, Rule_Delete_Req, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_Rule_Delete_Req[]
    end
end

mutable struct Rule_Delete_Res <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function Rule_Delete_Res(; kwargs...)
        obj = new(meta(Rule_Delete_Res), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct Rule_Delete_Res
const __meta_Rule_Delete_Res = Ref{ProtoMeta}()
function meta(::Type{Rule_Delete_Res})
    ProtoBuf.metalock() do
        if !isassigned(__meta_Rule_Delete_Res)
            __meta_Rule_Delete_Res[] = target = ProtoMeta(Rule_Delete_Res)
            allflds = Pair{Symbol,Union{Type,String}}[]
            meta(target, Rule_Delete_Res, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_Rule_Delete_Res[]
    end
end

mutable struct Rule_Delete <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function Rule_Delete(; kwargs...)
        obj = new(meta(Rule_Delete), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct Rule_Delete
const __meta_Rule_Delete = Ref{ProtoMeta}()
function meta(::Type{Rule_Delete})
    ProtoBuf.metalock() do
        if !isassigned(__meta_Rule_Delete)
            __meta_Rule_Delete[] = target = ProtoMeta(Rule_Delete)
            allflds = Pair{Symbol,Union{Type,String}}[]
            meta(target, Rule_Delete, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_Rule_Delete[]
    end
end

mutable struct Rule_SetLabel_Req <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function Rule_SetLabel_Req(; kwargs...)
        obj = new(meta(Rule_SetLabel_Req), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct Rule_SetLabel_Req
const __meta_Rule_SetLabel_Req = Ref{ProtoMeta}()
function meta(::Type{Rule_SetLabel_Req})
    ProtoBuf.metalock() do
        if !isassigned(__meta_Rule_SetLabel_Req)
            __meta_Rule_SetLabel_Req[] = target = ProtoMeta(Rule_SetLabel_Req)
            allflds = Pair{Symbol,Union{Type,String}}[:label => AbstractString]
            meta(target, Rule_SetLabel_Req, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_Rule_SetLabel_Req[]
    end
end
function Base.getproperty(obj::Rule_SetLabel_Req, name::Symbol)
    if name === :label
        return (obj.__protobuf_jl_internal_values[name])::AbstractString
    else
        getfield(obj, name)
    end
end

mutable struct Rule_Req <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function Rule_Req(; kwargs...)
        obj = new(meta(Rule_Req), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct Rule_Req
const __meta_Rule_Req = Ref{ProtoMeta}()
function meta(::Type{Rule_Req})
    ProtoBuf.metalock() do
        if !isassigned(__meta_Rule_Req)
            __meta_Rule_Req[] = target = ProtoMeta(Rule_Req)
            fnum = Int[1,100,101]
            allflds = Pair{Symbol,Union{Type,String}}[:label => AbstractString, :rule_delete_req => Rule_Delete_Req, :rule_set_label_req => Rule_SetLabel_Req]
            oneofs = Int[0,1,1]
            oneof_names = Symbol[Symbol("req")]
            meta(target, Rule_Req, allflds, ProtoBuf.DEF_REQ, fnum, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, oneofs, oneof_names)
        end
        __meta_Rule_Req[]
    end
end
function Base.getproperty(obj::Rule_Req, name::Symbol)
    if name === :label
        return (obj.__protobuf_jl_internal_values[name])::AbstractString
    elseif name === :rule_delete_req
        return (obj.__protobuf_jl_internal_values[name])::Rule_Delete_Req
    elseif name === :rule_set_label_req
        return (obj.__protobuf_jl_internal_values[name])::Rule_SetLabel_Req
    else
        getfield(obj, name)
    end
end

mutable struct Rule_SetLabel_Res <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function Rule_SetLabel_Res(; kwargs...)
        obj = new(meta(Rule_SetLabel_Res), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct Rule_SetLabel_Res
const __meta_Rule_SetLabel_Res = Ref{ProtoMeta}()
function meta(::Type{Rule_SetLabel_Res})
    ProtoBuf.metalock() do
        if !isassigned(__meta_Rule_SetLabel_Res)
            __meta_Rule_SetLabel_Res[] = target = ProtoMeta(Rule_SetLabel_Res)
            allflds = Pair{Symbol,Union{Type,String}}[]
            meta(target, Rule_SetLabel_Res, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_Rule_SetLabel_Res[]
    end
end

mutable struct Rule_Res <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function Rule_Res(; kwargs...)
        obj = new(meta(Rule_Res), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct Rule_Res
const __meta_Rule_Res = Ref{ProtoMeta}()
function meta(::Type{Rule_Res})
    ProtoBuf.metalock() do
        if !isassigned(__meta_Rule_Res)
            __meta_Rule_Res[] = target = ProtoMeta(Rule_Res)
            fnum = Int[100,101]
            allflds = Pair{Symbol,Union{Type,String}}[:rule_delete_res => Rule_Delete_Res, :rule_set_label_res => Rule_SetLabel_Res]
            oneofs = Int[1,1]
            oneof_names = Symbol[Symbol("res")]
            meta(target, Rule_Res, allflds, ProtoBuf.DEF_REQ, fnum, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, oneofs, oneof_names)
        end
        __meta_Rule_Res[]
    end
end
function Base.getproperty(obj::Rule_Res, name::Symbol)
    if name === :rule_delete_res
        return (obj.__protobuf_jl_internal_values[name])::Rule_Delete_Res
    elseif name === :rule_set_label_res
        return (obj.__protobuf_jl_internal_values[name])::Rule_SetLabel_Res
    else
        getfield(obj, name)
    end
end

mutable struct Rule_SetLabel <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function Rule_SetLabel(; kwargs...)
        obj = new(meta(Rule_SetLabel), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct Rule_SetLabel
const __meta_Rule_SetLabel = Ref{ProtoMeta}()
function meta(::Type{Rule_SetLabel})
    ProtoBuf.metalock() do
        if !isassigned(__meta_Rule_SetLabel)
            __meta_Rule_SetLabel[] = target = ProtoMeta(Rule_SetLabel)
            allflds = Pair{Symbol,Union{Type,String}}[]
            meta(target, Rule_SetLabel, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_Rule_SetLabel[]
    end
end

mutable struct Rule <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function Rule(; kwargs...)
        obj = new(meta(Rule), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct Rule
const __meta_Rule = Ref{ProtoMeta}()
function meta(::Type{Rule})
    ProtoBuf.metalock() do
        if !isassigned(__meta_Rule)
            __meta_Rule[] = target = ProtoMeta(Rule)
            allflds = Pair{Symbol,Union{Type,String}}[:label => AbstractString, :when => AbstractString, :then => AbstractString]
            meta(target, Rule, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_Rule[]
    end
end
function Base.getproperty(obj::Rule, name::Symbol)
    if name === :label
        return (obj.__protobuf_jl_internal_values[name])::AbstractString
    elseif name === :when
        return (obj.__protobuf_jl_internal_values[name])::AbstractString
    elseif name === :then
        return (obj.__protobuf_jl_internal_values[name])::AbstractString
    else
        getfield(obj, name)
    end
end

mutable struct LogicManager_GetRule_Res <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function LogicManager_GetRule_Res(; kwargs...)
        obj = new(meta(LogicManager_GetRule_Res), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct LogicManager_GetRule_Res
const __meta_LogicManager_GetRule_Res = Ref{ProtoMeta}()
function meta(::Type{LogicManager_GetRule_Res})
    ProtoBuf.metalock() do
        if !isassigned(__meta_LogicManager_GetRule_Res)
            __meta_LogicManager_GetRule_Res[] = target = ProtoMeta(LogicManager_GetRule_Res)
            allflds = Pair{Symbol,Union{Type,String}}[:rule => Rule]
            oneofs = Int[1]
            oneof_names = Symbol[Symbol("res")]
            meta(target, LogicManager_GetRule_Res, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, oneofs, oneof_names)
        end
        __meta_LogicManager_GetRule_Res[]
    end
end
function Base.getproperty(obj::LogicManager_GetRule_Res, name::Symbol)
    if name === :rule
        return (obj.__protobuf_jl_internal_values[name])::Rule
    else
        getfield(obj, name)
    end
end

mutable struct LogicManager_PutRule_Res <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function LogicManager_PutRule_Res(; kwargs...)
        obj = new(meta(LogicManager_PutRule_Res), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct LogicManager_PutRule_Res
const __meta_LogicManager_PutRule_Res = Ref{ProtoMeta}()
function meta(::Type{LogicManager_PutRule_Res})
    ProtoBuf.metalock() do
        if !isassigned(__meta_LogicManager_PutRule_Res)
            __meta_LogicManager_PutRule_Res[] = target = ProtoMeta(LogicManager_PutRule_Res)
            allflds = Pair{Symbol,Union{Type,String}}[:rule => Rule]
            meta(target, LogicManager_PutRule_Res, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_LogicManager_PutRule_Res[]
    end
end
function Base.getproperty(obj::LogicManager_PutRule_Res, name::Symbol)
    if name === :rule
        return (obj.__protobuf_jl_internal_values[name])::Rule
    else
        getfield(obj, name)
    end
end

mutable struct LogicManager_GetRules_ResPart <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function LogicManager_GetRules_ResPart(; kwargs...)
        obj = new(meta(LogicManager_GetRules_ResPart), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct LogicManager_GetRules_ResPart
const __meta_LogicManager_GetRules_ResPart = Ref{ProtoMeta}()
function meta(::Type{LogicManager_GetRules_ResPart})
    ProtoBuf.metalock() do
        if !isassigned(__meta_LogicManager_GetRules_ResPart)
            __meta_LogicManager_GetRules_ResPart[] = target = ProtoMeta(LogicManager_GetRules_ResPart)
            allflds = Pair{Symbol,Union{Type,String}}[:rules => Base.Vector{Rule}]
            meta(target, LogicManager_GetRules_ResPart, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_LogicManager_GetRules_ResPart[]
    end
end
function Base.getproperty(obj::LogicManager_GetRules_ResPart, name::Symbol)
    if name === :rules
        return (obj.__protobuf_jl_internal_values[name])::Base.Vector{Rule}
    else
        getfield(obj, name)
    end
end

mutable struct LogicManager_Res <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function LogicManager_Res(; kwargs...)
        obj = new(meta(LogicManager_Res), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct LogicManager_Res
const __meta_LogicManager_Res = Ref{ProtoMeta}()
function meta(::Type{LogicManager_Res})
    ProtoBuf.metalock() do
        if !isassigned(__meta_LogicManager_Res)
            __meta_LogicManager_Res[] = target = ProtoMeta(LogicManager_Res)
            allflds = Pair{Symbol,Union{Type,String}}[:get_rule_res => LogicManager_GetRule_Res, :put_rule_res => LogicManager_PutRule_Res]
            oneofs = Int[1,1]
            oneof_names = Symbol[Symbol("res")]
            meta(target, LogicManager_Res, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, oneofs, oneof_names)
        end
        __meta_LogicManager_Res[]
    end
end
function Base.getproperty(obj::LogicManager_Res, name::Symbol)
    if name === :get_rule_res
        return (obj.__protobuf_jl_internal_values[name])::LogicManager_GetRule_Res
    elseif name === :put_rule_res
        return (obj.__protobuf_jl_internal_values[name])::LogicManager_PutRule_Res
    else
        getfield(obj, name)
    end
end

mutable struct LogicManager_ResPart <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function LogicManager_ResPart(; kwargs...)
        obj = new(meta(LogicManager_ResPart), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct LogicManager_ResPart
const __meta_LogicManager_ResPart = Ref{ProtoMeta}()
function meta(::Type{LogicManager_ResPart})
    ProtoBuf.metalock() do
        if !isassigned(__meta_LogicManager_ResPart)
            __meta_LogicManager_ResPart[] = target = ProtoMeta(LogicManager_ResPart)
            allflds = Pair{Symbol,Union{Type,String}}[:get_rules_res_part => LogicManager_GetRules_ResPart]
            meta(target, LogicManager_ResPart, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_LogicManager_ResPart[]
    end
end
function Base.getproperty(obj::LogicManager_ResPart, name::Symbol)
    if name === :get_rules_res_part
        return (obj.__protobuf_jl_internal_values[name])::LogicManager_GetRules_ResPart
    else
        getfield(obj, name)
    end
end

mutable struct Explanation_VarList <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function Explanation_VarList(; kwargs...)
        obj = new(meta(Explanation_VarList), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct Explanation_VarList
const __meta_Explanation_VarList = Ref{ProtoMeta}()
function meta(::Type{Explanation_VarList})
    ProtoBuf.metalock() do
        if !isassigned(__meta_Explanation_VarList)
            __meta_Explanation_VarList[] = target = ProtoMeta(Explanation_VarList)
            allflds = Pair{Symbol,Union{Type,String}}[:vars => Base.Vector{AbstractString}]
            meta(target, Explanation_VarList, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_Explanation_VarList[]
    end
end
function Base.getproperty(obj::Explanation_VarList, name::Symbol)
    if name === :vars
        return (obj.__protobuf_jl_internal_values[name])::Base.Vector{AbstractString}
    else
        getfield(obj, name)
    end
end

mutable struct Explanation_VarMappingEntry <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function Explanation_VarMappingEntry(; kwargs...)
        obj = new(meta(Explanation_VarMappingEntry), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct Explanation_VarMappingEntry (mapentry)
const __meta_Explanation_VarMappingEntry = Ref{ProtoMeta}()
function meta(::Type{Explanation_VarMappingEntry})
    ProtoBuf.metalock() do
        if !isassigned(__meta_Explanation_VarMappingEntry)
            __meta_Explanation_VarMappingEntry[] = target = ProtoMeta(Explanation_VarMappingEntry)
            allflds = Pair{Symbol,Union{Type,String}}[:key => AbstractString, :value => Explanation_VarList]
            meta(target, Explanation_VarMappingEntry, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_Explanation_VarMappingEntry[]
    end
end
function Base.getproperty(obj::Explanation_VarMappingEntry, name::Symbol)
    if name === :key
        return (obj.__protobuf_jl_internal_values[name])::AbstractString
    elseif name === :value
        return (obj.__protobuf_jl_internal_values[name])::Explanation_VarList
    else
        getfield(obj, name)
    end
end

mutable struct Explanation <: ProtoType
    __protobuf_jl_internal_meta::ProtoMeta
    __protobuf_jl_internal_values::Dict{Symbol,Any}
    __protobuf_jl_internal_defaultset::Set{Symbol}

    function Explanation(; kwargs...)
        obj = new(meta(Explanation), Dict{Symbol,Any}(), Set{Symbol}())
        values = obj.__protobuf_jl_internal_values
        symdict = obj.__protobuf_jl_internal_meta.symdict
        for nv in kwargs
            fldname, fldval = nv
            fldtype = symdict[fldname].jtyp
            (fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
            if fldval !== nothing
                values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
            end
        end
        obj
    end
end # mutable struct Explanation
const __meta_Explanation = Ref{ProtoMeta}()
function meta(::Type{Explanation})
    ProtoBuf.metalock() do
        if !isassigned(__meta_Explanation)
            __meta_Explanation[] = target = ProtoMeta(Explanation)
            allflds = Pair{Symbol,Union{Type,String}}[:rule => Rule, :var_mapping => Base.Dict{AbstractString,Explanation_VarList}, :condition => ConceptMap, :conclusion => ConceptMap]
            meta(target, Explanation, allflds, ProtoBuf.DEF_REQ, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
        end
        __meta_Explanation[]
    end
end
function Base.getproperty(obj::Explanation, name::Symbol)
    if name === :rule
        return (obj.__protobuf_jl_internal_values[name])::Rule
    elseif name === :var_mapping
        return (obj.__protobuf_jl_internal_values[name])::Base.Dict{AbstractString,Explanation_VarList}
    elseif name === :condition
        return (obj.__protobuf_jl_internal_values[name])::ConceptMap
    elseif name === :conclusion
        return (obj.__protobuf_jl_internal_values[name])::ConceptMap
    else
        getfield(obj, name)
    end
end

export LogicManager_Req, LogicManager_Res, LogicManager_ResPart, LogicManager_GetRule_Req, LogicManager_GetRule_Res, LogicManager_GetRule, LogicManager_PutRule_Req, LogicManager_PutRule_Res, LogicManager_PutRule, LogicManager_GetRules_Req, LogicManager_GetRules_ResPart, LogicManager_GetRules, LogicManager, Rule_Req, Rule_Res, Rule_Delete_Req, Rule_Delete_Res, Rule_Delete, Rule_SetLabel_Req, Rule_SetLabel_Res, Rule_SetLabel, Rule, Explanation_VarMappingEntry, Explanation_VarList, Explanation
# mapentries: "Explanation_VarMappingEntry" => ("AbstractString", "Explanation_VarList")


text:
using jFEMTools
import Tensors

jF = jFEMTools

k = [Tensors.Vec{2}([1.0, 0.0]), Tensors.Vec{2}([0.0, 0.0]), Tensors.Vec{2}([0.0, 1.0])]

points = [Tensors.Vec{2}([1.0/6.0, 1.0/6.0]),
          Tensors.Vec{2}([1.0/6.0, 2.0/3.0]),
          Tensors.Vec{2}([2.0/3.0, 1.0/6.0])]

ref_verts = jF.reference_coordinates(jF.RefSimplex, Val{2})

pt = jF.mapPointsFromReference(jF.RefSimplex,k,points)

A,b = jF.get_affine_map(ref_verts, k)

x = Tensors.Vec{2}([0.0,1.0])
A*x + b

max_stars_repo_name: Paulms/jFEMToools

max_issues_repo_name: Paulms/jFEMToools

max_forks_repo_name: Paulms/jFEMToools


text:
module TestTesting

using Folds.Testing: mapbottom
using Test

vinc(x::AbstractVector) = x .+ 1

@testset "mapbottom" begin
    @test collect(mapbottom(vinc, (x for x in 1:3))) == 2:4
    @test collect(mapbottom(vinc, (x for x in 1:3 if isodd(x)))) == 3:3
    @test collect(mapbottom(vinc, (y for x in (1:2, 3:4) for y in x))) == 2:5
    @test collect(mapbottom(vinc, (y for x in (1:2, 3:4) for y in x if isodd(y)))) == 3:2:5
end

end  # module


text:
import Base: getindex, setindex!
#===============================================================================
                            SETTING VALUES
===============================================================================#
# Translate indices TS understands into indices Arrays can understand (Int Arrays)
getrows{V,T}(x::TS{V,T}, r::Int)                    = r
getrows{V,T}(x::TS{V,T}, r::T)                      = find(x.index .== r)
getrows{V,T}(x::TS{V,T}, r::AbstractArray{Int,1})   = r
getrows{V,T}(x::TS{V,T}, r::Vector{Bool})           = (@assert size(x,1)==length(r); find(r))
getrows{V,T}(x::TS{V,T}, r::BitArray{1})            = (@assert size(x,1)==length(r); find(r))
getrows{V,T}(x::TS{V,T}, r::Vector{T})              = find(overlaps(x.index, r))

getcols{V,T}(x::TS{V,T}, c::Int)                    = c
getcols{V,T}(x::TS{V,T}, c::Symbol)                 = find(x.fields .== c)
getcols{V,T}(x::TS{V,T}, c::AbstractArray{Int,1})   = c
getcols{V,T}(x::TS{V,T}, c::Vector{Bool})           = (@assert size(x,2)==length(c); find(c))
getcols{V,T}(x::TS{V,T}, c::BitArray{1})            = (@assert size(x,2)==length(c); find(c))
getcols{V,T}(x::TS{V,T}, c::Vector{Symbol})         = find(overlaps(x.fields, c))

# Ensure no bounds are violated before calling `setindex!`
function checkdims(x::TS, v; r=1:size(x,1), c=1:size(x,2))
    @assert size(v,2) == length(c)
    @assert size(v,1) == length(r)
    @assert size(x,1) >= length(r)
    @assert size(x,2) >= length(c)
    if size(x,2)==1
        @assert length(c)==1
    else
        @assert size(x,2)>=length(c)
    end
end

# All rows + all columns
setindex!{V,T}(x::TS{V,T}, v, ::Colon)                                          = (checkdims(x,v); x.values=v)
setindex!{V,T}(x::TS{V,T}, v, ::Colon, ::Colon)                                 = (checkdims(x,v); x.values=v)
# Row subset + all columns
setindex!{V,T}(x::TS{V,T}, v, r::Int, ::Colon)                                  = (checkdims(x,v,r=r); x.values[getrows(x,r),:]=v)
setindex!{V,T}(x::TS{V,T}, v, r::T, ::Colon)                                    = (checkdims(x,v,r=r); x.values[getrows(x,r),:]=v)
setindex!{V,T}(x::TS{V,T}, v, r::AbstractArray{Int,1}, ::Colon)                 = (checkdims(x,v,r=r); x.values[getrows(x,r),:]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Vector{Bool}, ::Colon)                         = (checkdims(x,v,r=r); x.values[getrows(x,r),:]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Vector{T}, ::Colon)                            = (checkdims(x,v,r=r); x.values[getrows(x,r),:]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Int)                                           = (checkdims(x,v,r=r); x.values[getrows(x,r),:]=v)
setindex!{V,T}(x::TS{V,T}, v, r::T)                                             = (checkdims(x,v,r=r); x.values[getrows(x,r),:]=v)
setindex!{V,T}(x::TS{V,T}, v, r::AbstractArray{Int,1})                          = (checkdims(x,v,r=r); x.values[getrows(x,r),:]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Vector{Bool})                                  = (checkdims(x,v,r=r); x.values[getrows(x,r),:]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Vector{T})                                     = (checkdims(x,v,r=r); x.values[getrows(x,r),:]=v)
# Column subset + all rows
setindex!{V,T}(x::TS{V,T}, v, ::Colon, c::Int)                                  = (checkdims(x,v,c=c); x.values[:,getcols(x,c)]=v)
setindex!{V,T}(x::TS{V,T}, v, ::Colon, c::Symbol)                               = (checkdims(x,v,c=c); x.values[:,getcols(x,c)]=v)
setindex!{V,T}(x::TS{V,T}, v, ::Colon, c::AbstractArray{Int,1})                 = (checkdims(x,v,c=c); x.values[:,getcols(x,c)]=v)
setindex!{V,T}(x::TS{V,T}, v, ::Colon, c::Vector{Bool})                         = (checkdims(x,v,c=c); x.values[:,getcols(x,c)]=v)
setindex!{V,T}(x::TS{V,T}, v, ::Colon, c::Vector{Symbol})                       = (checkdims(x,v,c=c); x.values[:,getcols(x,c)]=v)
# Row subset + column subset
setindex!{V,T}(x::TS{V,T}, v, r::Int, c::Int)                                   = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(x,c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Int, c::Symbol)                                = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(x,c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Int, c::AbstractArray{Int,1})                  = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(x,c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Int, c::Vector{Bool})                          = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(x,c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Int, c::Vector{Symbol})                        = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(x,c)]=v)

setindex!{V,T}(x::TS{V,T}, v, r::AbstractArray{Int,1}, c::Int)                  = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::AbstractArray{Int,1}, c::Symbol)               = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::AbstractArray{Int,1}, c::AbstractArray{Int,1}) = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::AbstractArray{Int,1}, c::Vector{Bool})         = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::AbstractArray{Int,1}, c::Vector{Symbol})       = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)

setindex!{V,T}(x::TS{V,T}, v, r::Vector{Bool}, c::Int)                          = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Vector{Bool}, c::Symbol)                       = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Vector{Bool}, c::AbstractArray{Int,1})         = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Vector{Bool}, c::Vector{Bool})                 = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Vector{Bool}, c::Vector{Symbol})               = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)

setindex!{V,T}(x::TS{V,T}, v, r::Vector{T}, c::Int)                             = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Vector{T}, c::Symbol)                          = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Vector{T}, c::AbstractArray{Int,1})            = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Vector{T}, c::Vector{Bool})                    = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::Vector{T}, c::Vector{Symbol})                  = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)

setindex!{V,T}(x::TS{V,T}, v, r::T, c::Int)                                     = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::T, c::Symbol)                                  = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::T, c::AbstractArray{Int,1})                    = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::T, c::Vector{Bool})                            = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)
setindex!{V,T}(x::TS{V,T}, v, r::T, c::Vector{Symbol})                          = (checkdims(x,v,r=r,c=c); x.values[getrows(x,r),getcols(c)]=v)

#===============================================================================
							NUMERICAL INDEXING
===============================================================================#
getindex(x::TS) = x

getindex(x::TS, ::Colon)                            = x
getindex(x::TS, ::Colon, ::Colon)                   = x
getindex(x::TS, ::Colon, c::Int)                    = ts(x.values[:,c], x.index, [x.fields[c]])
getindex(x::TS, ::Colon, c::AbstractArray{Int,1})   = ts(x.values[:,c], x.index, x.fields[c])

getindex(x::TS, r::Int)                             = ts(x.values[r,:]', [x.index[r]], x.fields)
getindex(x::TS, r::Int, ::Colon)                    = ts(x.values[r,:]', [x.index[r]], x.fields)
getindex(x::TS, r::Int, c::Int)                     = ts([x.values[r,c]], [x.index[r]], [x.fields[c]])
getindex(x::TS, r::Int, c::AbstractArray{Int,1})    = ts(x.values[r,c]', [x.index[r]], x.fields[c])

getindex(x::TS, r::AbstractArray{Int,1})                            = ts(x.values[r,:], x.index[r], x.fields)
getindex(x::TS, r::AbstractArray{Int,1}, ::Colon)                   = ts(x.values[r,:], x.index[r], x.fields)
getindex(x::TS, r::AbstractArray{Int,1}, c::Int)                    = ts(x.values[r,c], x.index[r], [x.fields[c]])
getindex(x::TS, r::AbstractArray{Int,1}, c::AbstractArray{Int,1})   = ts(x.values[r, c], x.index[r], x.fields[c])

#===============================================================================
							BOOLEAN INDEXING
===============================================================================#
getindex(x::TS, r::BitArray{1})                             = TS(x.values[r,:], x.index[r], x.fields)
getindex(x::TS, r::BitArray{1}, ::Colon)                    = TS(x.values[r,:], x.index[r], x.fields)
getindex(x::TS, r::BitArray{1}, c::Int)                     = TS(x.values[r,c], x.index[r], x.fields[c])
getindex(x::TS, r::BitArray{1}, c::AbstractArray{Int,1})    = TS(x.values[r,c], x.index[r], x.fields[c])
getindex(x::TS, r::BitArray{1}, c::BitArray{1})             = TS(x.values[r,c], x.index[r], x.fields[c])
getindex(x::TS, r::BitArray{1}, c::Vector{Bool})            = TS(x.values[r,c], x.index[r], x.fields[c])

getindex(x::TS, r::Vector{Bool})                            = TS(x.values[r,:], x.index[r], x.fields)
getindex(x::TS, r::Vector{Bool}, ::Colon)                   = TS(x.values[r,:], x.index[r], x.fields)
getindex(x::TS, r::Vector{Bool}, c::Int)                    = TS(x.values[r,c], x.index[r], x.fields[c])
getindex(x::TS, r::Vector{Bool}, c::AbstractArray{Int,1})   = TS(x.values[r,c], x.index[r], x.fields[c])
getindex(x::TS, r::Vector{Bool}, c::Vector{Bool})           = TS(x.values[r,c], x.index[r], x.fields[c])
getindex(x::TS, r::Vector{Bool}, c::BitArray{1})            = TS(x.values[r,c], x.index[r], x.fields[c])

getindex(x::TS, r::AbstractArray{Int,1}, c::BitArray{1})    = TS(x.values[r,c], x.index[r], x.fields[c])
getindex(x::TS, r::AbstractArray{Int,1}, c::Vector{Bool})   = TS(x.values[r,c], x.index[r], x.fields[c])
getindex(x::TS, r::Int, c::BitArray{1})                     = TS(x.values[r,c], x.index[r], x.fields[c])
getindex(x::TS, r::Int, c::Vector{Bool})                    = TS(x.values[r,c], x.index[r], x.fields[c])
getindex(x::TS, ::Colon, c::BitArray{1})                    = TS(x.values[:,c], x.index[:], x.fields[c])
getindex(x::TS, ::Colon, c::Vector{Bool})                   = TS(x.values[:,c], x.index[:], x.fields[c])

getindex(x::TS, r::TS{Bool})                            = x[r.index[overlaps(r.index,x.index).*r.values]]
getindex(x::TS, r::TS{Bool}, ::Colon)                   = x[r.index[overlaps(r.index,x.index).*r.values]]
getindex(x::TS, r::TS{Bool}, c::Int)                    = x[r.index[overlaps(r.index,x.index).*r.values],c]
getindex(x::TS, r::TS{Bool}, c::AbstractArray{Int,1})   = x[r.index[overlaps(r.index,x.index).*r.values],c]
getindex(x::TS, r::TS{Bool}, c::Vector{Bool})           = x[r.index[overlaps(r.index,x.index).*r.values],c]
getindex(x::TS, r::TS{Bool}, c::BitArray{1})            = x[r.index[overlaps(r.index,x.index).*r.values],c]
getindex(x::TS, r::TS{Bool}, c::Symbol)                 = x[r.index[overlaps(r.index,x.index).*r.values],c]
getindex(x::TS, r::TS{Bool}, c::Vector{Symbol})         = x[r.index[overlaps(r.index,x.index).*r.values],c]

#===============================================================================
							TEMPORAL INDEXING
===============================================================================#
getindex(x::TS, r::TimeType)                            = x[x.index.==r]
getindex(x::TS, r::TimeType, ::Colon)                   = x[x.index.==r,:]
getindex(x::TS, r::TimeType, c::Int)                    = x[x.index.==r,c]
getindex(x::TS, r::TimeType, c::AbstractArray{Int,1})   = x[x.index.==r,c]
getindex(x::TS, r::TimeType, c::BitArray{1})            = x[x.index.==r,c]

getindex(x::TS, r::AbstractArray{Date,1})                           = x[overlaps(x.index, r)]
getindex(x::TS, r::AbstractArray{Date,1}, ::Colon)                  = x[overlaps(x.index, r), :]
getindex(x::TS, r::AbstractArray{Date,1}, c::Int)                   = x[overlaps(x.index, r), c]
getindex(x::TS, r::AbstractArray{Date,1}, c::AbstractArray{Int,1})  = x[overlaps(x.index, r), c]
getindex(x::TS, r::AbstractArray{Date,1}, c::BitArray{1})           = x[overlaps(x.index, r), c]

getindex(x::TS, r::AbstractArray{DateTime,1})                           = x[overlaps(x.index, r)]
getindex(x::TS, r::AbstractArray{DateTime,1}, ::Colon)                  = x[overlaps(x.index, r), :]
getindex(x::TS, r::AbstractArray{DateTime,1}, c::Int)                   = x[overlaps(x.index, r), c]
getindex(x::TS, r::AbstractArray{DateTime,1}, c::AbstractArray{Int,1})  = x[overlaps(x.index, r), c]
getindex(x::TS, r::AbstractArray{DateTime,1}, c::BitArray{1})           = x[overlaps(x.index, r), c]

#===============================================================================
							TEXTUAL INDEXING
===============================================================================#
getindex(x::TS, c::Symbol)          = x[:, x.fields.==c]
getindex(x::TS, c::Vector{Symbol})  = x[:, overlaps(x.fields, c)]

getindex(x::TS, ::Colon, c::Symbol)         = x[:, x.fields.==c]
getindex(x::TS, ::Colon, c::Vector{Symbol}) = x[r, overlaps(x.fields, c)]

getindex(x::TS, r::Int, c::Symbol)          = x[r, x.fields.==c]
getindex(x::TS, r::Int, c::Vector{Symbol})  = x[r, overlaps(x.fields, c)]

getindex(x::TS, r::TimeType, c::Symbol)         = x[r, x.fields.==c]
getindex(x::TS, r::TimeType, c::Vector{Symbol}) = x[r, overlaps(x.fields, c)]

getindex(x::TS, r::BitArray{1}, c::Symbol)          = x[r, x.fields.==c]
getindex(x::TS, r::Vector{Bool}, c::Symbol)         = x[r, x.fields.==c]
getindex(x::TS, r::BitArray{1}, c::Vector{Symbol})  = x[r, overlaps(x.fields, c)]
getindex(x::TS, r::Vector{Bool}, c::Vector{Symbol}) = x[r, overlaps(x.fields, c)]

getindex(x::TS, r::AbstractArray{Int,1}, c::Symbol)         = x[r, x.fields.==c]
getindex(x::TS, r::AbstractArray{Int,1}, c::Vector{Symbol}) = x[r, overlaps(x.fields, c)]

getindex(x::TS, r::AbstractArray{Date,1}, c::Symbol)            = x[r, x.fields.==c]
getindex(x::TS, r::AbstractArray{Date,1}, c::Vector{Symbol})    = x[r, overlaps(x.fields, c)]

getindex(x::TS, r::AbstractArray{DateTime,1}, c::Symbol)            = x[r, x.fields.==c]
getindex(x::TS, r::AbstractArray{DateTime,1}, c::Vector{Symbol})    = x[r, overlaps(x.fields, c)]

function thrudt(s::AbstractString, t::Vector{Date})
    n = length(s)
    if n == 4  # yyyy given
        y = parse(Int, s)
        ymd = Date(y, 12, 31)
    elseif n == 7  # yyyy-mm given
        a = split(s, '-')
        y = parse(Int, a[1])
        m = parse(Int, a[2])
        ymd = lastdayofmonth(Date(y, m, 1))
    elseif n == 10  # yyyy-mm-dd given
        a = split(s, '-')
        y = parse(Int, a[1])
        m = parse(Int, a[2])
        d = parse(Int, a[3])
        ymd = Date(y, m, d)
    else
        error("Unable to parse date string $s.")
    end
    return t .<= ymd
end
function fromdt(s::AbstractString, t::Vector{Date})
    n = length(s)
    if n == 4  # yyyy given
        y = parse(Int, s)
        ymd = Date(y, 1, 1)
    elseif n == 7  # yyyy-mm given
        a = split(s, '-')
        y = parse(Int, a[1])
        m = parse(Int, a[2])
        ymd = Date(y, m, 1)
    elseif n == 10  # yyyy-mm-dd given
        a = split(s, '-')
        y = parse(Int, a[1])
        m = parse(Int, a[2])
        d = parse(Int, a[3])
        ymd = Date(y, m, d)
    else
        error("Unable to parse date string $s.")
    end
    return t .>= ymd
end
function thisdt(s::AbstractString, t::Vector{Date})
    n = length(s)
    if n == 4  # yyyy given
        y = parse(Int, s)
        return year(t) .== y
    elseif n == 7  # yyyy-mm given
        a = split(s, '-')
        y = parse(Int, a[1])
        m = parse(Int, a[2])
        return (year(t) .== y) .* (month(t) .== m)
    elseif n == 10  # yyyy-mm-dd given
        a = split(s, '-')
        y = parse(Int, a[1])
        m = parse(Int, a[2])
        d = parse(Int, a[3])
        return (year(t) .== y) .* (month(t) .== m) .* day(t) .== d
    else
        error("Unable to parse date string $s.")
    end
end
function fromthru(from::AbstractString, thru::AbstractString, t::Vector{Date})
    fromidx = fromdt(from, t)
    thruidx = thrudt(thru, t)
    return fromidx .* thruidx
end
function thrudt(s::AbstractString, t::Vector{DateTime})
    n = length(s)
    if n == 4  # yyyy given
        y = parse(Int, s)
        ymdhms = DateTime(y, 12, 31)
    elseif n == 7  # yyyy-mm given
        a = split(s, '-')
        y = parse(Int, a[1])
        m = parse(Int, a[2])
        ymdhms = lastdayofmonth(DateTime(y, m, 1))
    elseif n == 10  # yyyy-mm-dd given
        a = split(s, '-')
        y = parse(Int, a[1])
        m = parse(Int, a[2])
        d = parse(Int, a[3])
        ymdhms = DateTime(y, m, d)
    elseif n == 13  # yyyy-mm-ddTHH given
        a = split(s, 'T')
        b = split(a[1], '-')
        c = split(a[2], ':')
        y = parse(Int, b[1])
        m = parse(Int, b[2])
        d = parse(Int, b[3])
        hr = parse(Int, c[1])
        min = 59
        sec = 59
        ymdhms = DateTime(y, m, d, hr, min, sec)
    elseif n == 16  # yyyy-mm-ddTHH:MM given
        a = split(s, 'T')
        b = split(a[1], '-')
        c = split(a[2], ':')
        y = parse(Int, b[1])
        m = parse(Int, b[2])
        d = parse(Int, b[3])
        hr = parse(Int, c[1])
        min = parse(Int, c[2])
        sec = 59
        ymdhms = DateTime(y, m, d, hr, min, sec)
    elseif n == 19  # yyyy-mm-ddTHH:MM:SS given
        a = split(s, 'T')
        b = split(a[1], '-')
        c = split(a[2], ':')
        y = parse(Int, b[1])
        m = parse(Int, b[2])
        d = parse(Int, b[3])
        hr = parse(Int, c[1])
        min = parse(Int, c[2])
        sec = parse(Int, c[3])
        ymdhms = DateTime(y, m, d, hr, min, sec)
    else
        error("Unable to parse date string $s.")
    end
    return t .<= ymdhms
end
function fromdt(s::AbstractString, t::Vector{DateTime})
    n = length(s)
    if n == 4  # yyyy given
        y = parse(Int, s)
        ymdhms = DateTime(y)
    elseif n == 7  # yyyy-mm given
        a = split(s, '-')
        y = parse(Int, a[1])
        m = parse(Int, a[2])
        ymdhms = DateTime(y, m)
    elseif n == 10  # yyyy-mm-dd given
        a = split(s, '-')
        y = parse(Int, a[1])
        m = parse(Int, a[2])
        d = parse(Int, a[3])
        ymdhms = DateTime(y, m, d)
    elseif n == 13  # yyyy-mm-ddTHH given
        a = split(s, 'T')
        b = split(a[1], '-')
        c = split(a[2], ':')
        y = parse(Int, b[1])
        m = parse(Int, b[2])
        d = parse(Int, b[3])
        hr = parse(Int, c[1])
        ymdhms = DateTime(y, m, d, hr, min, sec)
    elseif n == 16  # yyyy-mm-ddTHH:MM given
        a = split(s, 'T')
        b = split(a[1], '-')
        c = split(a[2], ':')
        y = parse(Int, b[1])
        m = parse(Int, b[2])
        d = parse(Int, b[3])
        hr = parse(Int, c[1])
        min = parse(Int, c[2])
        ymdhms = DateTime(y, m, d, hr, min, sec)
    elseif n == 19  # yyyy-mm-ddTHH:MM:SS given
        a = split(s, 'T')
        b = split(a[1], '-')
        c = split(a[2], ':')
        y = parse(Int, b[1])
        m = parse(Int, b[2])
        d = parse(Int, b[3])
        hr = parse(Int, c[1])
        min = parse(Int, c[2])
        sec = parse(Int, c[3])
        ymdhms = DateTime(y, m, d, hr, min, sec)
    else
        error("Unable to parse date string $s.")
    end
    return t .>= ymdhms
end
function thisdt(s::AbstractString, t::Vector{DateTime})
    n = length(s)
    if n == 4  # yyyy given
        y = parse(Int, s)
        return year(t) .== y
    elseif n == 7  # yyyy-mm given
        a = split(s, '-')
        y = parse(Int, a[1])
        m = parse(Int, a[2])
        return (year(t) .== y) .* (month(t) .== m)
    elseif n == 10  # yyyy-mm-dd given
        a = split(s, '-')
        y = parse(Int, a[1])
        m = parse(Int, a[2])
        d = parse(Int, a[3])
        return (year(t) .== y) .* (month(t) .== m) .* (day(t) .== d)
    elseif n == 13  # yyyy-mm-ddTHH given
        a = split(s, 'T')
        b = split(a[1], '-')
        c = split(a[2], ':')
        y = parse(Int, b[1])
        m = parse(Int, b[2])
        d = parse(Int, b[3])
        hr = parse(Int, c[1])
        return (year(t) .== y) .* (month(t) .== m) .* (day(t) .== d) .* (hour(t) .== hr)
    elseif n == 16  # yyyy-mm-ddTHH:MM given
        a = split(s, 'T')
        b = split(a[1], '-')
        c = split(a[2], ':')
        y = parse(Int, b[1])
        m = parse(Int, b[2])
        d = parse(Int, b[3])
        hr = parse(Int, c[1])
        min = parse(Int, c[2])
        return (year(t) .== y) .* (month(t) .== m) .* (day(t) .== d) .* (hour(t) .== hr) .* (minute(t) .== min)
    elseif n == 19  # yyyy-mm-ddTHH:MM:SS given
        a = split(s, 'T')
        b = split(a[1], '-')
        c = split(a[2], ':')
        y = parse(Int, b[1])
        m = parse(Int, b[2])
        d = parse(Int, b[3])
        hr = parse(Int, c[1])
        min = parse(Int, c[2])
        sec = parse(Int, c[3])
        return (year(t) .== y) .* (month(t) .== m) .* (day(t) .== d) .* (hour(t) .== hr) .* (minute(t) .== min) .* (second(t) .== sec)
    else
        error("Unable to parse date string $s.")
    end
end
function fromthru(from::AbstractString, thru::AbstractString, t::Vector{DateTime})
    fromidx = fromdt(from, t)
    thruidx = thrudt(thru, t)
    return fromidx .* thruidx
end

const RNG_DLM = '/'

function dtidx(s::AbstractString, t::Vector{Date})
    @assert !in('T', s) "Cannot index Date type with sub-daily frequency."
    bds = split(s, RNG_DLM)
    if length(bds) == 1  # single date
        return thisdt(s, t)
    elseif length(bds) == 2  # date range
        n1 = length(bds[1])
        n2 = length(bds[2])
        if n1 == 0 && n2 != 0  # thru date given
            return thrudt(bds[2], t)
        elseif n1 != 0 && n2 == 0  # from date given
            return fromdt(bds[1], t)
        elseif n1 != 0 && n2 != 0  # from and thru date given
            return fromthru(bds[1], bds[2], t)
        else
            error("Invalid indexing string: Unable to parse $s")
        end
    else
        error("Invalid indexing string: Unable to parse $s")
    end
end
function dtidx(s::AbstractString, t::Vector{DateTime})
    @assert !in('T', s) "Cannot index Date type with sub-daily frequency."
    bds = split(s, RNG_DLM)
    if length(bds) == 1  # single date
        return thisdt(s, t)
    elseif length(bds) == 2  # date range
        n1 = length(bds[1])
        n2 = length(bds[2])
        if n1 == 0 && n2 != 0  # thru date given
            return thrudt(bds[2], t)
        elseif n1 != 0 && n2 == 0  # from date given
            return fromdt(bds[1], t)
        elseif n1 != 0 && n2 != 0  # from and thru date given
            return fromthru(bds[1], bds[2], t)
        else
            error("Invalid indexing string: Unable to parse $s")
        end
    else
        error("Invalid indexing string: Unable to parse $s")
    end
end

getindex(x::TS, r::AbstractString)                          = x[dtidx(r, x.index)]
getindex(x::TS, r::AbstractString, ::Colon)                 = x[dtidx(r, x.index)]
getindex(x::TS, r::AbstractString, c::Int)                  = x[dtidx(r, x.index), c]
getindex(x::TS, r::AbstractString, c::AbstractArray{Int,1}) = x[dtidx(r, x.index), c]
getindex(x::TS, r::AbstractString, c::BitArray{1})          = x[dtidx(r, x.index), c]
getindex(x::TS, r::AbstractString, c::Symbol)               = x[dtidx(r, x.index), c]
getindex(x::TS, r::AbstractString, c::Vector{Symbol})       = x[dtidx(r, x.index), c]


text:
@defcomp welfareNeutral begin

    regions      = Index()                                     # Index for RICE regions.

    eta          = Parameter()                                 # Elasticity of marginal utility of consumption.
    rho          = Parameter()                                 # Pure rate of time preference.
    l            = Parameter(index=[time, regions])            # population levels for each region.
    CPC          = Parameter(index=[time, regions, quintiles]) # Post-damage, post-abatement cost consumption (thousands 2005 USD yr⁻¹).

    welfare      = Variable()                                    # Total economic welfare.

    function run_timestep(p, v, d, t)

        if is_first(t)
            # Calculate period 1 welfare.
            v.welfare = sum((p.CPC[t,:] .^ (1.0 - p.eta)) ./ (1.0 - p.eta) .* p.l[t,:]) / (1.0 + p.rho)^(10*(t.t-1))
        else
            # Calculate cummulative welfare over time.
            v.welfare = v.welfare + sum((p.CPC[t,:,:] .^ (1.0 - p.eta)) ./ (1.0 - p.eta) .* p.l[t,:]) / (1.0 + p.rho)^(10*(t.t-1))
        end
    end
end

max_stars_repo_name: fdennig/RICEupdate

max_issues_repo_name: fdennig/RICEupdate

max_forks_repo_name: fdennig/RICEupdate


text:
module Fn

using MacroTools: @capture, prewalk, postwalk

export @fn

const PLACEHOLDER_PATTERN = r"^_([1-9]?|[1-9][0-9]*)$"

"""
    @fn

Shorthand for defining anonymous functions. Use _ and _1, _2, ... as placeholders for
arguments.

    @fn(cat(_; dims=3))

    @fn(_2^_1)
"""
:@fn

macro fn(expr)
    # Resolve everything in the caller's scope. This is fine because all symbols we
    # introduce are gensyms and locally bound to function arguments anyway.
    esc(fn(expr))
end

struct RecursionBarrier
    expr
end

function fn(expr)
    # Collect placeholders
    placeholders = Set{Symbol}()
    analyzed_expr = prewalk(expr) do ex
        if @capture(ex, @fn _)
            # Do not recurse into nested @fn calls
            return RecursionBarrier(ex)
        end

        if ex isa Symbol && (ex == :_ || occursin(PLACEHOLDER_PATTERN, string(ex)))
            push!(placeholders, ex)
        end

        ex
    end

    if length(placeholders) == 0
        args = []
        replacements = Dict{Symbol, Symbol}()
    elseif :_ in placeholders
        if length(placeholders) > 1
            names = join(placeholders, ", ", " and ")
            error("You cannot mix _ and _n in @fn, found $names")
        end

        args = [gensym("arg")]
        replacements = Dict(:_ => args[1])
    else
        numbers = map(collect(placeholders)) do p; parse(Int, string(p)[2:end]) end
        a, b = extrema(numbers)
        args = map(a:b) do i gensym("arg$i") end
        replacements = Dict(map(enumerate(args)) do (i, arg); (Symbol("_$i"), arg) end)
    end

    with_args = postwalk(analyzed_expr) do ex
        if ex isa RecursionBarrier
            # Unpack nested @fn calls
            return ex.expr
        elseif ex isa Symbol && ex in keys(replacements)
            replacements[ex]
        else
            ex
        end
    end

    quote
        function ($(args...),)
            $(with_args)
        end
    end
end

end


text:
@everywhere using StanSample, Distributed

@everywhere ProjDir = @__DIR__

@everywhere struct Job
  model::AbstractString
  data::Dict
  tmpdir::AbstractString
  name::AbstractString
  nchains::Int
  num_samples::Int
  num_warmup::Int
  save_warmup::Bool
  delta::Float64
  output_format::Symbol
end

@everywhere themodel = "
data {
  int<lower=1> N;
  int<lower=0,upper=1> y[N];
}
parameters {
  real<lower=0,upper=1> theta;
}
model {
  theta ~ beta(1,1);
  y ~ bernoulli(theta);
}
";

@everywhere tmpdir = "$(ProjDir)/tmp"
@everywhere observed_data = Dict(:N => 10, :y => [0, 1, 0, 1, 0, 0, 0, 0, 0, 1])
@everywhere N = 8
@everywhere jobs = Vector{Job}(undef, N)

for i in 1:N
  jobs[i] = Job(
    themodel, observed_data, tmpdir,
    "Bernoulli_$i", 4, 1000, 1000, false, 0.85,
    :particles,
  )
end

@everywhere function runjob(i, jobs)
  sm = SampleModel(jobs[i].name,
    jobs[i].model,
    tmpdir=jobs[i].tmpdir,
    method=StanSample.Sample(
      save_warmup=jobs[i].save_warmup,
      num_warmup=jobs[i].num_warmup,
      num_samples=jobs[i].num_samples,
      adapt=StanSample.Adapt(delta=jobs[i].delta))
  )
  (rc=stan_sample(sm; data=jobs[i].data), model=sm)
end

@time res = pmap(i -> runjob(i, jobs), 1:N);

p = []
for (ind, r) in enumerate(res)
  if success(r.rc)
    push!(p, read_samples(r.model, output_format=:particles))
  else
    println("Job[ind] failed.")
  end
end
display(p)


text:
abstract type Preset end

export Glider, BHeptomino, GosperGun

struct Glider <: Preset
    data::Array{Int,2}
    size::Tuple{Int,Int}
end
Glider() = Glider([
    0 1 0
    0 0 1
    1 1 1
], (3,3))

struct BHeptomino <: Preset
    data::Array{Int,2}
    size::Tuple{Int,Int}
end
BHeptomino() = BHeptomino([
    1 0 1 1
    1 1 1 0
    0 1 0 0
], (3,4))

struct GosperGun <: Preset
    data::Array{Int,2}
    size::Tuple{Int,Int}
end
GosperGun() = GosperGun([
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1
    0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1
    1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    1 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
], (9, 36)
)


text:
# # Variational Quantum Eigen Solver

using Yao, Yao.AD, YaoExtensions

# number of qubits
n = 4

# depth
d = 5
circuit = dispatch!(variational_circuit(n, d),:random)

gatecount(circuit)

nparameters(circuit)

h = heisenberg(n)

# pick the one you like
# either reverse-mode
# or forward mode
# grad = faithful_grad(h, zero_state(n) => circuit; nshots=100)

for i in 1:1000
      _, grad = expect'(h, zero_state(n) => circuit)
      dispatch!(-, circuit, 1e-2 * grad)
      println("Step $i, energy = $(real.(expect(h, zero_state(n)=>circuit)))")
end

using LinearAlgebra
w, _ = eigen(Matrix(mat(h)))

max_stars_repo_name: logankilpatrick/tutorials

max_issues_repo_name: logankilpatrick/tutorials

max_forks_repo_name: logankilpatrick/tutorials


text:
function bundleTMs!(df, nBundles)
    df.x += floor.((df.structMap .- 1) ./ nBundles) .* 2
end


text:
__precompile__(false)
module PDESolver

# defs.jl
export AssembleElementData, AbstractShockSensor

# from registration.jl
export register_physics, retrieve_physics, registerIC, registerBC

# from interface.jl
export evalResidual, evalJacobian, evalHomotopy, evalHomotopyJacobian,
       evalJacobianStrong, createFunctional,
       evalFunctional, evalFunctionalDeriv_q, evalFunctionalDeriv_m,
       updateMetricDependents,
       solvePDE, evalResidual_revm, evalResidual_revq, evaldRdqProduct,
       _getSparsityPattern, getShockSensor, setShockSensor, setShockSensorAlpha,
       createShockSensor, copyParameters, openLoggingFiles, closeLoggingFiles,
       setFluxFunction

# from interface2.jl
export createObjects, createLinearSolver, getSparsityPattern,
       createSBPOperator, createEnrichedObjects

# from startup_func
export run_solver

# from interative.jl
export printICNames, printBCNames

# load paths for all the components of PDESolver
push!(LOAD_PATH, joinpath(Pkg.dir("PumiInterface"), "src"))
push!(LOAD_PATH, joinpath(Pkg.dir("PDESolver"), "src/solver"))
push!(LOAD_PATH, joinpath(Pkg.dir("PDESolver"), "src/NonlinearSolvers"))
push!(LOAD_PATH, joinpath(Pkg.dir("PDESolver"), "src/linearsolvers"))
push!(LOAD_PATH, joinpath(Pkg.dir("PDESolver"), "src/jacobian"))
push!(LOAD_PATH, joinpath(Pkg.dir("PDESolver"), "src/Utils"))
push!(LOAD_PATH, joinpath(Pkg.dir("PDESolver"), "src/Debugging"))
push!(LOAD_PATH, joinpath(Pkg.dir("PDESolver"), "src/input"))

# add physics modules to load path (but don't load them, because that would
# create a circular dependency)
push!(LOAD_PATH, joinpath(Pkg.dir("PDESolver"), "src/solver/advection"))
push!(LOAD_PATH, joinpath(Pkg.dir("PDESolver"), "src/solver/euler"))
push!(LOAD_PATH, joinpath(Pkg.dir("PDESolver"), "src/solver/elliptic"))
push!(LOAD_PATH, joinpath(Pkg.dir("PDESolver"), "src/solver/simpleODE"))
push!(LOAD_PATH, joinpath(Pkg.dir("PDESolver"), "src/solver/elliptic"))
push!(LOAD_PATH, joinpath(Pkg.dir("PDESolver"), "src/solver/navier_stokes"))
push!(LOAD_PATH, joinpath(Pkg.dir("PDESolver"), "src/optimization"))

# load the modules
using MPI
using ODLCommonTools
import ODLCommonTools: evalFunctional, _evalFunctional,
                       evalFunctionalDeriv_m, _evalFunctionalDeriv_m,
                       evalFunctionalDeriv_q, _evalFunctionalDeriv_q

function finalizeMPI()
  if MPI.Initialized()
    MPI.Finalize()
  end
end

if !MPI.Initialized()
  MPI.Init()
  atexit(finalizeMPI)
end

using PETSc2

function finalizePetsc()
  if PetscInitialized()
    PetscFinalize()
  end
end

if !PetscInitialized()
  PetscInitialize()
  atexit(finalizePetsc)
end

using Input
using ODLCommonTools
using PdePumiInterface  # common mesh interface - pumi
using SummationByParts  # SBP operators
#using LinearSolvers
#using NonlinearSolvers   # non-linear solvers
using ArrayViews
import ArrayViews.view
using Utils
import ODLCommonTools.sview
#using Input

include("defs.jl")  # common definitions
include("registration.jl")  # registering physics modules
include("interface.jl")  # functions all physics modules need to implement
include("interface2.jl") # functions physics modules don't have to implement
include("startup_func.jl")  # unified solver invokation
include("interactive.jl")
# package code goes here

end # module


text:
using GroupSlices
using Base.Test

# Tests for groupslices, groupinds, firstinds, lastinds
A = [1 2 3 ; 4 5 6 ; 7 8 9]
B = [11 12 13 ; 14 15 16 ; 17 18 19]
C = [21 22 23 ; 24 25 26 ; 27 28 29]
D = cat(3, A, B, C, C, B, C, A)

ic = [1;2;3;3;2;3;1]
ib = Vector{Int}[]
push!(ib,[1;7])
push!(ib,[2;5])
push!(ib,[3;4;6])
ia = [1;2;3]
ia1 = [1;2;3]
ia2 = [7;5;6]

ic_test = groupslices(D,3)
ib_test = groupinds(ic_test)
ia_test = firstinds(ic_test)
ia1_test = firstinds(ib_test)
ia2_test = lastinds(ib_test)

@test isequal(ic, ic_test)
@test isequal(ib, ib_test)
@test isequal(ia, ia_test)
@test isequal(ia1, ia1_test)
@test isequal(ia2, ia2_test)

E =  [1.0  1.0  2.0  2.0  1.0  1.0  1.0  2.0  2.0  2.0
      1.0  1.0  2.0  2.0  2.0  1.0  2.0  2.0  2.0  1.0
      1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0  2.0]

ib = Vector{Int}[[1,2,6],[3,4,8,9],[5,7],[10]]
ia = [1; 3; 5; 10]
ic = [1; 1; 3; 3; 5; 1; 5; 3; 3; 10]
ia1 = [1; 3; 5; 10]
ia2 = [6; 9; 7; 10]

ic_test = groupslices(E,2)
ib_test = groupinds(ic_test)
ia_test = firstinds(ic_test)
ia1_test = firstinds(ib_test)
ia2_test = lastinds(ib_test)

@test isequal(ic, ic_test)
@test isequal(ib, ib_test)
@test isequal(ia, ia_test)
@test isequal(ia1, ia1_test)
@test isequal(ia2, ia2_test)


text: goals = +

max_stars_repo_name: UlrichBerntien/Codewars-Katas

max_issues_repo_name: UlrichBerntien/Codewars-Katas

max_forks_repo_name: UlrichBerntien/Codewars-Katas


text:
using Documenter
using GrapheneQFT

push!(LOAD_PATH,"../src/")
makedocs(sitename="GrapheneQFT.jl Documentation",
         pages = [
            "Home" => "index.md",
            "Formalism" => "formalism.md",
            "API" => "api.md"

         ],
         format = Documenter.HTML(prettyurls = false)
)
# Documenter can also automatically deploy documentation to gh-pages.
# See "Hosting Documentation" and deploydocs() in the Documenter manual
# for more information.
deploydocs(
    repo = "github.com/rodin-physics/GrapheneQFT.jl.git",
    devbranch = "main"
)


text:
using Test
using SparseArrays

import sbp
using sbp.Operator: read_operator, to_matrix
using sbp.Grid:grid_xp
using sbp.Test:test_first_derivative, test_quadrature, test_first_derivative_sbp
include("operators.jl")

st = sbp.Strand1994

m = 10

B = spzeros(m, m)
B[1,1] = -1
B[end,end] = 1

@test_throws UndefVarError st.load_descrption(order=10)
desc_D21, desc_H21 = st.load_description(order=2)
desc_D42, desc_H42 = st.load_description(order=4)

@testset "D_21, H_21" begin
        x, h, D, H = st.build_operators(desc_D21, desc_H21, m)
        ml = size(desc_D21.left, 1)
        mr = size(desc_D21.right, 1)
        test_first_derivative(D, x, x, 2, 1, ml, mr)
        test_quadrature(H, x, 1)
        test_first_derivative_sbp(H, D, B)
end

@testset "D_42, H_42" begin
        x, h, D, H = st.build_operators(desc_D42, desc_H42, m)
        ml = size(desc_D42.left, 1)
        mr = size(desc_D42.right, 1)
        test_first_derivative(D, x, x, 4, 2, ml, mr)
        test_quadrature(H, x, 3)
        test_first_derivative_sbp(H, D, B)
end

max_stars_repo_name: ooreilly/sbpjl

max_issues_repo_name: ooreilly/sbpjl

max_forks_repo_name: ooreilly/sbpjl