text:
julia> [RpcApi.SimpleOrganism(0x0000000000022086,:(function (o::Creature.Organism,)
        function func_273(var_272::Int8=-40)
            Creature.eatLeft(o,Int(var_272))
            var_272 = var_272 + var_272
            var_272 = var_272 * var_272
            var_272 = var_272 + var_272
            Creature.eatRight(o,Int(var_272))
            return var_272
        end
        function func_264(var_263::Int8=-125)
            for i::Int8 = 1:div(var_263,_LOOP_STEPS_DIVIDER)
            end
            return var_263
        end
        local var_243::Bool = false
        function func_232(var_230::Bool=false,var_231::Int16=-29748)
            Creature.stepLeft(o)
            return var_230
        end
        function func_189(var_188::Int16=2883)
            Creature.stepDown(o)
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            Creature.stepDown(o)
            return var_141
        end
        local var_124::Int64 = -1961703428302216313
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_156::Int16 = 19308
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepUp(o)
        Creature.stepUp(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_117 = var_117 + var_117
        o.mem[var_156] = var_156
        var_124 = var_124 + var_124
        Creature.stepUp(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        Creature.eatUp(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        var_124 = var_124 / var_124
        var_124 = var_124 * var_124
        var_243 = var_123 | var_123
        if var_123 != var_123
            Creature.stepLeft(o)
        end
        Creature.eatLeft(o,Int(var_117))
        Creature.stepUp(o)
        Creature.stepRight(o)
        var_156 = if haskey(o.mem,var_156)
                o.mem[var_156]
            else
                var_156
            end
        Creature.stepUp(o)
        Creature.stepRight(o)
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        if var_123 !== var_123
            Creature.stepDown(o)
        end
        Creature.eatRight(o,Int(var_117))
        var_120 = if haskey(o.mem,var_156)
                o.mem[var_156]
            else
                var_120
            end
        if var_124 <= var_124
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.stepRight(o)
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.stepLeft(o)
        end
        Creature.stepLeft(o)
        Creature.eatLeft(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        if var_123 <= var_123
            Creature.stepUp(o)
        end
        Creature.stepDown(o)
        Creature.stepLeft(o)
        return true
    end),[110,300,95,0,1,1,1],4,9571,49,118365,0x00000228,Dict(0=>0,10070=>10070,-4015=>19308,23323=>23323,19308=>19308,-1631=>-1631,1=>1),[1894,4],72),RpcApi.SimpleOrganism(0x0000000000021f07,:(function (o::Creature.Organism,)
        local var_243::Int8 = 83
        local var_242::Int16 = -28511
        function func_189(var_188::Int16=2883)
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            return var_141
        end
        local var_124::Int64 = -1961703428302216313
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_156::Int16 = 19308
        Creature.stepDown(o)
        Creature.stepDown(o)
        Creature.stepRight(o)
        Creature.stepRight(o)
        Creature.eatLeft(o,Int(var_117))
        o.mem[var_120] = var_120
        var_156 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_156
            end
        Creature.eatUp(o,Int(var_117))
        Creature.stepRight(o)
        Creature.eatUp(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        if var_120 > var_156
            local var_251::Int8 = 87
            Creature.stepRight(o)
            Creature.stepRight(o)
        end
        var_117 = var_117 + var_117
        Creature.eatRight(o,Int(var_117))
        Creature.stepDown(o)
        Creature.stepRight(o)
        Creature.stepRight(o)
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_124 = var_124 - var_124
        Creature.stepRight(o)
        var_124 = func_142(var_124)
        Creature.eatRight(o,Int(var_117))
        if var_124 <= var_124
            local var_230::Int16 = 27608
            var_230 = var_230 * var_230
            Creature.stepDown(o)
            var_230 = if haskey(o.mem,var_230)
                    o.mem[var_230]
                else
                    var_230
                end
        end
        Creature.stepRight(o)
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepDown(o)
        var_123 = var_123 | var_123
        Creature.eatUp(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_156)))
        Creature.stepRight(o)
        Creature.eatLeft(o,Int(var_117))
        Creature.stepDown(o)
        var_120 = func_189(var_156)
        Creature.eatDown(o,Int(var_243))
        Creature.eatDown(o,Int(var_117))
        Creature.stepLeft(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_120 = var_120 + var_120
        o.mem[var_120] = var_156
        Creature.eatLeft(o,Int(var_117))
        var_120 = var_120 - var_120
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        var_123 = var_123 | var_123
        Creature.eatLeft(o,Int(var_117))
        Creature.stepUp(o)
        Creature.eatDown(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepUp(o)
        if var_120 >= var_120
            local var_238::Int64 = -5358840696455759399
        end
        Creature.stepUp(o)
        if var_123 <= var_123
            local var_244::ASCIIString = "G36GCJ4z"
            Creature.stepLeft(o)
            Creature.stepUp(o)
            var_244 = var_244 * var_244
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepLeft(o)
        end
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        Creature.eatLeft(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        return true
    end),[110,300,95,0,1,1,1],3,9344,0,108844,0x00000089,Dict(-8030=>-4015,0=>-4015,-4015=>-4015,-3262=>-1631,23323=>23323,19308=>23323,-1631=>-4015,27608=>27608,1=>-4015),[1898,17],90),RpcApi.SimpleOrganism(0x0000000000021a28,:(function
 (o::Creature.Organism,)
        local var_243::Int8 = 83
        local var_242::Int16 = -28511
        function func_189(var_188::Int16=2883)
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            return var_141
        end
        local var_124::Int64 = -1961703428302216313
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        Creature.stepDown(o)
        Creature.stepDown(o)
        Creature.stepRight(o)
        Creature.stepDown(o)
        Creature.eatLeft(o,Int(var_117))
        o.mem[var_120] = var_120
        var_156 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_156
            end
        Creature.eatUp(o,Int(var_117))
        Creature.eatDown(o,Int(var_243))
        Creature.stepRight(o)
        Creature.eatUp(o,Int(var_117))
        var_120 = var_120 - var_120
        Creature.stepLeft(o)
        if var_120 > var_156
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepUp(o)
        end
        var_117 = var_117 + var_117
        Creature.eatRight(o,Int(var_117))
        Creature.stepDown(o)
        Creature.stepRight(o)
        Creature.stepRight(o)
        Creature.eatDown(o,Int(var_117))
        var_242 = var_120 / var_242
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_124 = var_124 - var_124
        Creature.stepRight(o)
        var_242 = var_120 - var_120
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        Creature.stepUp(o)
        Creature.stepRight(o)
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_123 = var_123 & var_123
        var_123 = var_123 | var_123
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_156)))
        Creature.stepRight(o)
        Creature.eatLeft(o,Int(var_117))
        Creature.stepDown(o)
        var_120 = func_189(var_156)
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepLeft(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_120 = var_120 + var_120
        Creature.stepLeft(o)
        Creature.stepUp(o)
        var_120 = var_120 - var_120
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        var_123 = var_123 | var_123
        Creature.eatLeft(o,Int(var_117))
        Creature.stepUp(o)
        Creature.eatRight(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepUp(o)
        if var_120 >= var_120
            local var_238::Int64 = -5358840696455759399
            var_238 = var_238 * var_238
        end
        var_120 = func_189(var_120)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        if var_123 <= var_123
            Creature.stepLeft(o)
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepUp(o)
            Creature.stepLeft(o)
            Creature.stepLeft(o)
        end
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        Creature.eatLeft(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        return true
    end),[110,300,95,0,1,1,1],3,2407,10,101121,0x000000e4,Dict(-8030=>-4015,0=>0,-4015=>-4015,-3262=>-1631,23323=>23323,19308=>23323,-1631=>-4015,27608=>27608,1=>1),[1,1],88),RpcApi.SimpleOrganism(0x00000000000220ac,:(function (o::Creatu
re.Organism,)
        function func_279(var_278::ASCIIString="Hjxigv88")
            Creature.stepUp(o)
            Creature.stepDown(o)
            return var_278
        end
        function func_273(var_272::Int8=-40)
            for i::Int8 = 1:div(var_272,_LOOP_STEPS_DIVIDER)
            end
            return var_272
        end
        function func_264(var_263::Int8=-125)
            Creature.stepUp(o)
            Creature.stepRight(o)
            Creature.eatLeft(o,Int(var_263))
            Creature.stepRight(o)
            Creature.eatUp(o,Int(var_263))
            var_263 = var_263 / var_263
            return var_263
        end
        local var_243::Bool = false
        function func_232(var_230::Bool=false,var_231::Int16=-29748)
            local var_282::Bool = true
            return var_230
        end
        function func_189(var_188::Int16=2883)
            if var_188 === var_188
            end
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            Creature.stepUp(o)
            return var_141
        end
        local var_124::Int64 = -1961703428302216313
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_156::Int16 = 19308
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepUp(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_117 = var_117 + var_117
        o.mem[var_156] = var_156
        var_124 = var_124 + var_124
        Creature.stepUp(o)
        var_243 = Bool(abs(var_123 - var_123))
        Creature.eatUp(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_124 = var_124 * var_124
        var_243 = var_123 | var_123
        if var_123 != var_123
            Creature.stepUp(o)
            Creature.stepDown(o)
            Creature.stepLeft(o)
            Creature.stepUp(o)
        end
        Creature.stepUp(o)
        Creature.stepRight(o)
        var_156 = if haskey(o.mem,var_156)
                o.mem[var_156]
            else
                var_156
            end
        Creature.stepUp(o)
        Creature.stepRight(o)
        Creature.stepUp(o)
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_120 = var_156 / var_120
        Creature.eatRight(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        if var_123 !== var_123
            Creature.stepUp(o)
            Creature.stepLeft(o)
            Creature.stepDown(o)
        end
        Creature.eatRight(o,Int(var_117))
        var_156 = if haskey(o.mem,var_156)
                o.mem[var_156]
            else
                var_156
            end
        if var_124 <= var_124
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.stepRight(o)
            Creature.stepDown(o)
            Creature.stepLeft(o)
        end
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        var_123 = var_123 * var_123
        Creature.eatLeft(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_243 = var_243 | var_243
        Creature.eatUp(o,Int(var_117))
        if var_123 <= var_123
            Creature.stepUp(o)
        end
        Creature.stepDown(o)
        Creature.stepLeft(o)
        return true
    end),[110,300,95,0,1,1,1],6,4602,53,100021,0x0000022b,Dict(0=>0,10070=>10070,-4015=>19308,23323=>23323,19308=>19308,-1631=>-1631,1=>1),[1816,9],80),RpcApi.SimpleOrganism(0x0000000000021e69,:(function (o::Creature.Organism,)
        function func_257(var_255::Int8=113,var_256::Int8=7)
            Creature.eatDown(o,Int(var_256))
            return var_255
        end
        local var_243::Int8 = 83
        local var_242::Int16 = -28511
        function func_189(var_188::Int16=2883)
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            local var_250::Bool = true
            Creature.stepRight(o)
            Creature.stepUp(o)
            if var_250 === var_250
                Creature.stepUp(o)
            end
            Creature.stepDown(o)
            Creature.stepDown(o)
            return var_141
        end
        local var_124::Int64 = -1961703428302216313
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        Creature.stepDown(o)
        Creature.stepDown(o)
        var_120 = var_120 / var_120
        Creature.stepDown(o)
        Creature.eatLeft(o,Int(var_117))
        o.mem[var_120] = var_120
        var_156 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_156
            end
        Creature.eatUp(o,Int(var_117))
        Creature.stepRight(o)
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_243))
        if var_120 > var_156
            Creature.stepRight(o)
        end
        var_117 = var_117 + var_117
        Creature.eatRight(o,Int(var_117))
        Creature.stepDown(o)
        Creature.stepRight(o)
        Creature.stepRight(o)
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepRight(o)
        Creature.stepRight(o)
        var_124 = func_142(var_124)
        Creature.eatRight(o,Int(var_117))
        if var_124 <= var_124
            local var_230::Int16 = 27608
            var_230 = func_189(var_230)
            var_230 = var_230 / var_230
            Creature.stepDown(o)
            Creature.stepDown(o)
            var_230 = if haskey(o.mem,var_230)
                    o.mem[var_230]
                else
                    var_230
                end
            var_230 = func_189(var_230)
        end
        Creature.stepRight(o)
        Creature.eatRight(o,Int(var_117))
        o.mem[var_242] = var_120
        Creature.stepDown(o)
        var_123 = var_123 | var_123
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_156)))
        Creature.stepRight(o)
        Creature.eatLeft(o,Int(var_117))
        Creature.stepDown(o)
        var_120 = func_189(var_156)
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepLeft(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_120 = var_120 + var_120
        o.mem[var_120] = var_156
        Creature.stepUp(o)
        var_120 = var_120 - var_120
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        var_123 = var_123 | var_123
        Creature.eatLeft(o,Int(var_117))
        Creature.stepUp(o)
        Creature.eatDown(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepUp(o)
        if var_120 >= var_120
            local var_238::Int64 = -5358840696455759399
        end
        Creature.stepUp(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        if var_123 <= var_123
            local var_244::ASCIIString = "G36GCJ4z"
            local var_258::ASCIIString = "zRLZiPFN"
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepUp(o)
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepLeft(o)
        end
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        return true
    end),[110,300,95,0,1,1,1],5,9344,51,99438,0x000000c2,Dict(2=>1,-3262=>-1631,-28511=>1,-1631=>-4015,0=>-4015,-8030=>-4015,-4015=>-4015,23323=>23323,19308=>23323,27608=>27608,1=>1),[1913,929],99),RpcApi.SimpleOrganism(0x00000000000220a
8,:(function (o::Creature.Organism,)
        function func_273(var_272::Int8=-40)
            Creature.stepRight(o)
            Creature.eatLeft(o,Int(var_272))
            var_272 = var_272 + var_272
            Creature.eatLeft(o,Int(var_272))
            Creature.eatDown(o,Int(var_272))
            return var_272
        end
        function func_264(var_263::Int8=-125)
            Creature.stepUp(o)
            var_263 = var_263 * var_263
            return var_263
        end
        local var_243::Bool = false
        function func_232(var_230::Bool=false,var_231::Int16=-29748)
            return var_230
        end
        function func_189(var_188::Int16=2883)
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            return var_141
        end
        local var_124::Int64 = -1961703428302216313
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_156::Int16 = 19308
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepUp(o)
        Creature.stepUp(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_117 = var_117 + var_117
        o.mem[var_156] = var_156
        Creature.eatDown(o,Int(var_117))
        Creature.stepUp(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        Creature.eatUp(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        var_124 = var_124 / var_124
        var_124 = var_124 * var_124
        var_243 = var_123 | var_123
        if var_123 != var_123
            Creature.stepLeft(o)
            Creature.stepRight(o)
        end
        Creature.eatLeft(o,Int(var_117))
        Creature.stepUp(o)
        Creature.eatLeft(o,Int(var_117))
        var_156 = if haskey(o.mem,var_156)
                o.mem[var_156]
            else
                var_156
            end
        Creature.stepUp(o)
        var_123 = var_123 | var_243
        Creature.stepRight(o)
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        if var_123 !== var_123
            Creature.stepRight(o)
            Creature.stepDown(o)
        end
        Creature.stepRight(o)
        Creature.eatRight(o,Int(var_117))
        var_120 = if haskey(o.mem,var_156)
                o.mem[var_156]
            else
                var_120
            end
        if var_124 <= var_124
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.stepRight(o)
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.stepLeft(o)
        end
        Creature.stepLeft(o)
        Creature.eatLeft(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        var_243 = var_243 | var_243
        Creature.eatUp(o,Int(var_117))
        if var_123 <= var_123
            Creature.stepUp(o)
        end
        Creature.stepDown(o)
        Creature.stepLeft(o)
        return true
    end),[110,300,95,0,1,1,1],4,9571,49,97013,0x00000226,Dict(0=>0,10070=>10070,-4015=>19308,23323=>23323,19308=>19308,-1631=>-1631,1=>1),[1907,10],74),RpcApi.SimpleOrganism(0x0000000000021f62,:(function (o::Creature.Organism,)
        local var_243::Int8 = 83
        local var_242::Int16 = -28511
        function func_189(var_188::Int16=2883)
            local var_256::Bool = false
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            Creature.stepDown(o)
            return var_141
        end
        local var_124::Int64 = -1961703428302216313
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        Creature.stepDown(o)
        Creature.stepDown(o)
        Creature.stepRight(o)
        Creature.stepDown(o)
        Creature.eatLeft(o,Int(var_117))
        o.mem[var_120] = var_120
        var_156 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_156
            end
        Creature.eatUp(o,Int(var_117))
        Creature.eatDown(o,Int(var_243))
        Creature.stepRight(o)
        Creature.eatUp(o,Int(var_117))
        var_120 = var_120 - var_120
        Creature.stepLeft(o)
        if var_120 > var_156
            Creature.stepUp(o)
            Creature.stepUp(o)
        end
        var_117 = var_117 + var_117
        Creature.eatRight(o,Int(var_117))
        Creature.stepDown(o)
        Creature.stepRight(o)
        Creature.stepRight(o)
        Creature.eatDown(o,Int(var_117))
        var_242 = var_120 / var_242
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_124 = var_124 - var_124
        Creature.stepRight(o)
        var_242 = var_120 - var_120
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        Creature.stepUp(o)
        Creature.stepRight(o)
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_123 = var_123 & var_123
        var_123 = var_123 | var_123
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        Creature.stepRight(o)
        Creature.eatLeft(o,Int(var_117))
        var_120 = func_189(var_156)
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepLeft(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_120 = var_120 + var_120
        Creature.stepLeft(o)
        Creature.stepUp(o)
        var_120 = var_120 - var_120
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        var_123 = var_123 | var_123
        Creature.eatLeft(o,Int(var_117))
        Creature.stepUp(o)
        Creature.stepLeft(o)
        Creature.eatLeft(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepUp(o)
        if var_120 >= var_120
            local var_238::Int64 = -5358840696455759399
            var_238 = var_238 * var_238
        end
        var_120 = func_189(var_120)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        if var_123 <= var_123
            Creature.stepLeft(o)
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepLeft(o)
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepLeft(o)
            Creature.stepLeft(o)
        end
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        Creature.eatLeft(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        return true
    end),[110,300,95,0,1,1,1],3,2407,10,96050,0x000000e7,Dict(-8030=>-4015,0=>0,-4015=>-4015,-3262=>-1631,23323=>23323,19308=>23323,-1631=>-4015,27608=>27608,1=>1),[1874,1],88),RpcApi.SimpleOrganism(0x0000000000021fc4,:(function (o::Crea
ture.Organism,)
        function func_273(var_272::Int8=-40)
            Creature.stepRight(o)
            Creature.eatUp(o,Int(var_272))
            return var_272
        end
        function func_264(var_263::Int8=-125)
            Creature.stepUp(o)
            return var_263
        end
        local var_243::Bool = false
        function func_232(var_230::Bool=false,var_231::Int16=-29748)
            return var_230
        end
        function func_189(var_188::Int16=2883)
            local var_278::Int16 = 12060
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            return var_141
        end
        local var_124::Int64 = -1961703428302216313
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_156::Int16 = 19308
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepUp(o)
        Creature.stepUp(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_117 = var_117 + var_117
        o.mem[var_156] = var_156
        var_124 = var_124 + var_124
        Creature.stepUp(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        Creature.eatUp(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        var_124 = var_124 / var_124
        var_124 = var_124 * var_124
        var_243 = var_123 | var_123
        if var_123 != var_123
            Creature.stepLeft(o)
        end
        Creature.eatLeft(o,Int(var_117))
        Creature.stepUp(o)
        Creature.stepRight(o)
        var_156 = if haskey(o.mem,var_156)
                o.mem[var_156]
            else
                var_156
            end
        Creature.stepUp(o)
        Creature.stepRight(o)
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        if var_123 !== var_123
            Creature.stepRight(o)
            Creature.stepDown(o)
        end
        Creature.eatRight(o,Int(var_117))
        var_120 = if haskey(o.mem,var_156)
                o.mem[var_156]
            else
                var_120
            end
        if var_124 <= var_124
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.stepRight(o)
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.stepLeft(o)
        end
        Creature.stepLeft(o)
        Creature.eatLeft(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        var_243 = var_243 | var_243
        Creature.eatUp(o,Int(var_117))
        if var_123 <= var_123
            Creature.stepUp(o)
        end
        Creature.stepDown(o)
        Creature.stepLeft(o)
        return true
    end),[110,300,95,0,1,1,1],4,9571,27,94525,0x0000021e,Dict(0=>0,10070=>10070,-4015=>19308,23323=>23323,19308=>19308,-1631=>-1631,1=>1),[1907,2],68),RpcApi.SimpleOrganism(0x0000000000021f74,:(function (o::Creature.Organism,)
        function func_273(var_272::Int8=-40)
            Creature.stepRight(o)
            Creature.eatLeft(o,Int(var_272))
            var_272 = var_272 + var_272
            var_272 = var_272 * var_272
            var_272 = var_272 + var_272
            return var_272
        end
        function func_264(var_263::Int8=-125)
            return var_263
        end
        local var_243::Bool = false
        function func_232(var_230::Bool=false,var_231::Int16=-29748)
            Creature.stepLeft(o)
            return var_230
        end
        function func_189(var_188::Int16=2883)
            local var_278::Int16 = 18957
            Creature.stepDown(o)
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            Creature.stepDown(o)
            return var_141
        end
        local var_124::Int64 = -1961703428302216313
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_156::Int16 = 19308
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepUp(o)
        Creature.stepUp(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_117 = var_117 + var_117
        o.mem[var_156] = var_156
        var_124 = var_124 + var_124
        Creature.stepUp(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        Creature.eatUp(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        var_124 = var_124 / var_124
        var_124 = var_124 * var_124
        var_243 = var_123 | var_123
        if var_123 != var_123
            Creature.stepLeft(o)
        end
        Creature.eatLeft(o,Int(var_117))
        Creature.stepUp(o)
        Creature.stepRight(o)
        var_156 = if haskey(o.mem,var_156)
                o.mem[var_156]
            else
                var_156
            end
        Creature.stepUp(o)
        Creature.stepRight(o)
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        if var_123 !== var_123
            Creature.stepDown(o)
        end
        Creature.eatRight(o,Int(var_117))
        var_120 = if haskey(o.mem,var_156)
                o.mem[var_156]
            else
                var_120
            end
        if var_124 <= var_124
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.stepRight(o)
            Creature.stepDown(o)
            Creature.stepDown(o)
            Creature.stepLeft(o)
        end
        Creature.stepLeft(o)
        Creature.eatLeft(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        if var_123 <= var_123
            Creature.stepUp(o)
        end
        Creature.stepDown(o)
        Creature.stepLeft(o)
        return true
    end),[110,300,95,0,1,1,1],4,9571,49,81028,0x00000228,Dict(0=>0,10070=>10070,-4015=>19308,23323=>23323,19308=>19308,-1631=>-1631,1=>1),[1905,6],72),RpcApi.SimpleOrganism(0x0000000000021d87,:(function (o::Creature.Organism,)
        function func_257(var_255::Int8=113,var_256::Int8=7)
            local var_259::Int64 = 8472002642027034382
            local var_260::Int16 = -23495
            return var_255
        end
        local var_243::Int8 = 83
        local var_242::Int16 = -28511
        function func_189(var_188::Int16=2883)
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            local var_250::Bool = true
            Creature.stepRight(o)
            Creature.stepUp(o)
            if var_250 === var_250
                Creature.stepRight(o)
                Creature.stepLeft(o)
            end
            var_141 = var_141 + var_141
            Creature.stepDown(o)
            return var_141
        end
        local var_124::Int64 = -1961703428302216313
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        Creature.stepDown(o)
        Creature.stepDown(o)
        var_120 = var_120 / var_120
        Creature.stepDown(o)
        Creature.eatLeft(o,Int(var_117))
        o.mem[var_120] = var_120
        var_156 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_156
            end
        Creature.eatUp(o,Int(var_117))
        Creature.stepRight(o)
        var_120 = var_120 - var_120
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_243))
        if var_120 > var_156
            Creature.stepRight(o)
        end
        var_117 = var_117 + var_117
        Creature.eatRight(o,Int(var_117))
        Creature.stepDown(o)
        Creature.stepRight(o)
        Creature.stepRight(o)
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepRight(o)
        Creature.stepRight(o)
        var_124 = func_142(var_124)
        Creature.eatRight(o,Int(var_117))
        if var_124 <= var_124
            local var_230::Int16 = 27608
            var_230 = func_189(var_230)
            var_230 = var_230 / var_230
            Creature.stepDown(o)
            Creature.stepDown(o)
            var_230 = if haskey(o.mem,var_230)
                    o.mem[var_230]
                else
                    var_230
                end
            var_230 = func_189(var_230)
        end
        Creature.stepRight(o)
        Creature.eatRight(o,Int(var_117))
        o.mem[var_242] = var_120
        Creature.stepDown(o)
        var_123 = var_123 | var_123
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_156)))
        Creature.stepRight(o)
        Creature.eatLeft(o,Int(var_117))
        Creature.stepDown(o)
        var_120 = func_189(var_156)
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.stepLeft(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_120 = var_120 + var_120
        o.mem[var_120] = var_156
        Creature.stepUp(o)
        var_120 = var_120 - var_120
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        var_123 = var_123 | var_123
        Creature.eatLeft(o,Int(var_117))
        Creature.stepUp(o)
        Creature.stepDown(o)
        Creature.eatLeft(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        if var_120 >= var_120
            local var_238::Int64 = -5358840696455759399
        end
        Creature.stepUp(o)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        if var_123 <= var_123
            local var_244::ASCIIString = "G36GCJ4z"
            Creature.stepUp(o)
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepUp(o)
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepLeft(o)
            Creature.stepUp(o)
        end
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        Creature.eatLeft(o,Int(var_117))
        Creature.stepLeft(o)
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        return true
    end),[110,300,95,0,1,1,1],5,9344,51,75588,0x000000c5,Dict(2=>1,-3262=>-1631,-28511=>0,-1631=>-4015,0=>-4015,-8030=>-4015,-4015=>-4015,23323=>23323,19308=>23323,27608=>27608,1=>1),[1913,891],102)]

max_stars_repo_name: tmptrash/jevo

max_issues_repo_name: tmptrash/jevo

max_forks_repo_name: tmptrash/jevo


text:
"""
Module ImplicitGlobalGrid

Renders the distributed parallelization of stencil-based GPU and CPU applications on a regular staggered grid almost trivial and enables close to ideal weak scaling of real-world applications on thousands of GPUs.

# General overview and examples
https://github.com/eth-cscs/ImplicitGlobalGrid.jl

# Functions
- [`init_global_grid`](@ref)
- [`finalize_global_grid`](@ref)
- [`update_halo!`](@ref)
- [`gather!`](@ref)
- [`select_device`](@ref)
- [`nx_g`](@ref)
- [`ny_g`](@ref)
- [`nz_g`](@ref)
- [`x_g`](@ref)
- [`y_g`](@ref)
- [`z_g`](@ref)
- [`tic`](@ref)
- [`toc`](@ref)

To see a description of a function type `?<functionname>`.

!!! note "Performance note"
    If the system supports CUDA-aware MPI, it may be activated for ImplicitGlobalGrid by setting the following environment variable (at latest before the call to `init_global_grid`):
    ```shell
    shell> export IGG_CUDAAWARE_MPI=1
    ```
"""
module ImplicitGlobalGrid

## Include of shared constant parameters, types and syntax sugar
include("shared.jl")

## Alphabetical include of files
include("finalize_global_grid.jl")
include("gather.jl")
include("init_global_grid.jl")
include("select_device.jl")
include("tools.jl")
include("update_halo.jl")

end

ext: jl


text:
using Random, Distributions
Random.seed!(0)

alpha = 0.05
L(obs) = obs - (1-sqrt(alpha))
U(obs) = obs + (1-sqrt(alpha))

mu = 5.57
observation = rand(TriangularDist(mu-1,mu+1,mu))
println("Lower bound L: ", L(observation))
println("Upper bound U: ", U(observation))

max_stars_repo_name: Yoshinobu-Ishizaki/StatsWithJuliaBook

max_issues_repo_name: Yoshinobu-Ishizaki/StatsWithJuliaBook

max_forks_repo_name: Yoshinobu-Ishizaki/StatsWithJuliaBook


text:
using FractionalDiffEq, Plots, SpecialFunctions

phi(x)=0
α=0.9; τ = 0.1
f(t, y, ϕ)=2/gamma(3-α)*t^(2-α)-1/gamma(2-α)*t^(1-α)+2*τ*t-τ^2-τ-y+ϕ
h = 1e-2
realfun(t) = t^2-t

prob = FDDEProblem(f, phi, α, τ, (0, 5))
sol1 = solve(prob, h, DelayPI())
sol2 = solve(prob, h, DelayABM())
sol3 = sove(prob, h, DelayPECE())


text: palindrome(s) = s == reverse(s)

max_stars_repo_name: ethansaxenian/RosettaDecode

max_issues_repo_name: ethansaxenian/RosettaDecode

max_forks_repo_name: ethansaxenian/RosettaDecode


text:
using ITensors,
      Test

@testset "diagITensor (DiagBlockSparse)" begin

  @testset "diagITensor get and set elements" begin
    i = Index(QN(0)=>2,QN(1)=>3; tags="i")

    D = diagITensor(QN(),i,dag(i'))

    for b in eachnzblock(D)
      @test flux(D,b) == QN()
    end

    D[i(1),i'(1)] = 1
    D[i(2),i'(2)] = 2
    D[i(3),i'(3)] = 3
    D[i(4),i'(4)] = 4
    D[i(5),i'(5)] = 5

    @test_throws ErrorException D[i(1),i'(2)] = 2.0

    @test D[i(1),i'(1)] == 1
    @test D[i(2),i'(2)] == 2
    @test D[i(3),i'(3)] == 3
    @test D[i(4),i'(4)] == 4
    @test D[i(5),i'(5)] == 5
  end

  @testset "diagITensor Tuple constructor" begin
    i = Index(QN(0)=>2, QN(1)=>3; tags="i")

    D = diagITensor((i, dag(i')))

    for b in eachnzblock(D)
      @test flux(D, b) == QN()
    end
  end

  @testset "delta" begin
    i = Index(QN(0)=>2,QN(1)=>3; tags="i")
    ĩ = sim(i; tags="i_sim")
    j = Index(QN(0)=>2,QN(1)=>3,QN(2)=>4; tags="j")

    A = randomITensor(QN(), i, dag(j))

    δiĩ = δ(dag(i), ĩ)

    @test store(δiĩ) isa NDTensors.DiagBlockSparse{ElT,
                                                   ElT} where {ElT<:Number}

    B = A * δiĩ

    A = permute(A, i, j)
    B = permute(B, ĩ, j)

    @test norm(dense(NDTensors.tensor(A)) -
               dense(NDTensors.tensor(B))) ≈ 0
  end

  @testset "delta Tuple constructor" begin
    i = Index(QN(0)=>2, QN(1)=>3; tags="i")
    ĩ = sim(i; tags="i_sim")

    δiĩ = δ((dag(i), ĩ))

    for b in eachnzblock(δiĩ)
      @test flux(δiĩ, b) == QN()
    end
  end

end

nothing


text:
using Compat

struct PincusResult{N,T}
    EX::NTuple{N,T}
    VX::NTuple{N,T}
    converged::Bool
    iterations::Int
end

sum_tup(x::NTuple{N,T}, y::NTuple{N,T}) where {N,T} = ntuple(i -> x[i] + y[i], Val{N}())
function sum_tups(x::Tuple{T,NTuple{N,T},NTuple{N,T}}, y::Tuple{T,NTuple{N,T},NTuple{N,T}}) where {N,T}
    x[1]+y[1], sum_tup(x[2], y[2]), sum_tup(x[3], y[3])
end
@generated zero_tuple(::Type{T}, ::Val{N}) where {N,T} = ntuple(i -> zero(T), Val{N}())
@generated function init_reduce(::Type{T}, ::Val{N}) where {N,T}
    ( zero(T), zero_tuple(T,Val{N}()), zero_tuple(T,Val{N}()) )
end
function reduction_op(x::Tuple{T,NTuple{N,T},NTuple{N,T}}, y::Tuple{T,NTuple{N,T},NTuple{N,T}}) where {N,T}
    (x[1] + y[1], x[2] .+ y[2], x[3] .+ y[3])
end

function maximize(f, grid::AbstractVector{Tuple{T,NTuple{N,T}}}, ::Val{verbose} = Val{true}(), λ = T(0.1), max_iter::Integer = 30, ϵ = 1e-3, step = naive_step) where {N,T, verbose}
    iterations = 0
    converged = false
    EX::NTuple{N,T} = zero_tuple(T, Val{N}())
    VX::NTuple{N,T} = ntuple(i -> T(0.5), Val{N}())
    fx::T = one(T)
    logfx = zero(T)
    function g(zw, logfx, f, λ, EX)
        w, n = zw
        x = EX .+ n ./ √λ
        px = λ^T(1.5)*exp( w + λ*f( x ) - logfx )
        xpx = x .* px
        px, xpx, x .* xpx
    end
#    init_reduce = init_reduce(T, Val{N}())
    while !converged
        let a1 = logfx, a2 = EX, a3 = λ
            fx, EX, VX = mapreduce(x -> g(x, a1, f, a3, a2), reduction_op, grid)::Tuple{T,NTuple{N,T},NTuple{N,T}}
        end#, init_reduce
        EX = EX ./ fx
        VX = @. sqrt( VX / fx - abs2(EX) )
        iterations += 1
        if maximum(VX) < ϵ
            converged = true
        elseif iterations == max_iter
            break
        end
        λ = step(λ, VX)
        logfx += log(fx)
        if verbose == true
            println("Iteration: $iterations\nEX: $EX, VX: $VX, λ: $λ.\n")
        end

    end
    PincusResult(EX, VX, converged, iterations)
end

function maximize(f, grid::CLArray{Tuple{T,NTuple{N,T}},1}, ::Val{verbose} = Val{true}(), λ = T(0.1), max_iter::Integer = 30, ϵ = 1e-3, step = naive_step) where {N,T, verbose}
    iterations = 0
    converged = false
    EX::NTuple{N,T} = zero_tuple(T, Val{N}())
    VX::NTuple{N,T} = ntuple(i -> T(0.5), Val{N}())
    fx::T = one(T)
    logfx = zero(T)
    function g(zw, logfx, f, λ, EX)
        w, n = zw
        x = EX .+ n ./ √λ
        px = λ^T(1.5)*exp( w + λ*f( x ) - logfx )
        xpx = x .* px
        px, xpx, x .* xpx
    end
    init = init_reduce(T, Val{N}())
    while !converged
        let a1 = logfx, a2 = EX, a3 = λ
            fx, EX, VX = mapreduce(x -> g(x, a1, f, a3, a2), reduction_op, init, grid)::Tuple{T,NTuple{N,T},NTuple{N,T}}
        end#, init_reduce
        EX = EX ./ fx
        VX = @. sqrt( VX / fx - abs2(EX) )
        iterations += 1
        if maximum(VX) < ϵ
            converged = true
        elseif iterations == max_iter
            break
        end
        λ = step(λ, VX)
        logfx += log(fx)
        if verbose == true
            println("Iteration: $iterations\nEX: $EX, VX: $VX, λ: $λ.\n")
        end

    end
    PincusResult(EX, VX, converged, iterations)
end
function threaded_maximize(f, grid::AbstractVector{Tuple{T,NTuple{N,T}}}, ::Val{verbose} = Val{true}(), λ = T(0.1), max_iter::Integer = 30, ϵ = 1e-3, step = naive_step) where {N,T, verbose}
    iterations = 0
    converged = false
    EX::NTuple{N,T} = zero_tuple(T, Val{N}())
    VX::NTuple{N,T} = ntuple(i -> T(0.5), Val{N}())
    fx::T = one(T)
    logfx = zero(T)
    function g(zw, logfx, f, λ, EX)
        w, n = zw
        x = EX .+ n ./ √λ
        px = λ^T(1.5)*exp( w + λ*f( x ) - logfx )
        xpx = x .* px
        px, xpx, x .* xpx
    end
    nthread = Threads.nthreads()
    grid_partition = partition(grid, nthread)
    buffer = Vector{Tuple{T,NTuple{N,T},NTuple{N,T}}}(nthread)
    while !converged
        let a1 = logfx, a2 = EX, a3 = λ
            fx, EX, VX = threaded_mapreduce!(buffer, x -> g(x, a1, f, a3, a2), reduction_op, grid_partition)::Tuple{T,NTuple{N,T},NTuple{N,T}}
        end
        EX = EX ./ fx
        VX = @. sqrt( VX / fx - abs2(EX) )
        iterations += 1
        if maximum(VX) < ϵ
            converged = true
        elseif iterations == max_iter
            break
        end
        λ = step(λ, VX)
        logfx += log(fx)
        if verbose == true
            println("Iteration: $iterations\nEX: $EX, VX: $VX, λ: $λ.\n")
        end

    end
    PincusResult(EX, VX, converged, iterations)
end

logit(x) = log( x/(one(x)-x) )
inv_logit(x) = one(x) / (one(x) + exp(-x))
function uniboxmaximize(f, grid::AbstractVector{NTuple{2,T}}, verbose::Val{v} = Val{false}(), EX::T = T(0.5), λ::T = T(0.1), max_iter::Int = 50, ϵ = 1e-6, step = naive_step) where {T,v}
    iterations = 0
    converged = false
    EX = logit(EX)
    VX = one(T)
    fx = one(T)
    logfx = zero(T)
    function g(zw, logfx, f, λ, EX)
        n, w = zw
        x = EX + n/√λ
        px = λ^T(1.5)*exp( w + λ*f(inv_logit(x)) - logfx )
        xpx = x * px
        px, xpx, x*xpx
    end
    func = f
    while !converged
        let a1 = logfx, a2 = λ, a3 = EX
            fx, EX, VX = mapreduce(x -> g(x, a1, f, a2, a3), sum_tup, grid )
        end
        EX = EX / fx
        VX = VX / fx - abs2(EX)
        iterations += 1
        if VX < ϵ
            converged = true
        elseif iterations == max_iter
            break
        end
        if v == true
            println("Iteration: $iterations\nEX: $(inv_logit(EX))\nVX: $VX\nλ: $λ.\n")
        end
        λ = step(λ, VX)
        logfx += log(fx)
    end
    PincusResult((inv_logit(EX),), (VX,), converged, iterations)
end

function gauss_hermite_tup(N::Int, ::Type{T} = Float64) where T
    n, w = gausshermite(N)
    [((√T(2)*T(n[i])), log( T(w[i])/T(√π) ) + abs2(T(n[i]))/2 ) for i ∈ 1:N]
end
function gauss_hermite_tup2(N::Int, ::Type{T} = Float64) where T
    n, w = gausshermite(N)
    [((√T(2)*n[i]), T(w[i])/√π) for i ∈ 1:N]
end
function partition(x, n)
    N = length(x)
    [x[1+N*(i-1)÷n:N*i÷n] for i ∈ 1:n]
end
function partition(x::A, ::Val{n}) where {A,n}
    N = length(x)
    ntuple(i -> x[1+N*(i-1)÷n:N*i÷n], Val{n}())
end

function threaded_mapreduce!(buffer, f, op, vec)
#    tid = Vector{Int}(length(vec))
    Threads.@threads for i in eachindex(vec)
        buffer[i] = mapreduce(f, op, vec[i])
#        tid[i] = Threads.threadid()
    end
#    println("Thread ids:", tid)
    reduce(op, buffer)
end
function threaded_uniboxmaximize(f, grid::AbstractVector{NTuple{2,T}}, verbose::Val{v} = Val{false}(), EX::T = T(0.5), λ::T = T(0.1), max_iter::Integer = 30, ϵ = 1e-6, step = naive_step) where {T,v}
    iterations = 0
    converged = false
    scale = T(0.5)
    EX = logit(EX)
    VX = one(T)
    fx = one(T)
    logfx = zero(T)
    function g(zw, logfx, f, λ, EX, scale)
        n, w = zw
        x = n*scale + EX
        px = w*exp( λ*f( inv_logit(x) )+abs2(n/Cuint(2)) - logfx )
        xpx = x * px
        px, xpx, x * xpx
    end
    init_reduce = (zero(T),zero(T),zero(T))
    #nthread = Threads.nthreads()
    grid_partition = partition(grid, Val{16}())::NTuple{16,Vector{Tuple{BigFloat,BigFloat}}}
    buffer = Vector{typeof(init_reduce)}(16)
    while !converged
        let a1 = logfx, a2 = λ, a3 = EX, a4 = scale
            fx, EX, VX = threaded_mapreduce!(buffer, x -> g(x, a1, f, a2, a3, a4), sum_tup, init_reduce, grid_partition )
        end
        EX = EX / fx
        VX = VX / fx - abs2(EX)
        scale = √VX
        iterations += 1
        if VX < ϵ
            converged = true
        elseif iterations == max_iter
            break
        end
        λ = step(λ, VX)
        if v == true
            println("Iteration: $iterations\nEX: $inv_logit(EX), VX: $VX, λ: $λ.\n")
        end
        logfx += log(fx)
    end
    PincusResult((inv_logit(EX),), (VX,), converged, iterations)
end

function unimaximize(f, grid::AbstractVector{NTuple{2,T}}, λ = T(0.1), max_iter::Integer = 100, ϵ = 1e-3, step = naive_step, ::Val{verbose} = Val{false}()) where {T,verbose}
    iterations = 0
    converged = false
    EX = zero(T)
    VX = one(T)
    logfx = zero(T)
    function g(nw, logfx, EX, VX, f, λ)
        n, w = nw
        fx = w*exp(λ * f( VX * n + EX ) - logfx )
        nfx = n * fx
        fx, nfx, n * nfx
    end
    while !converged
        fx, EX, VX = mapreduce(x -> g(x, EX, VX, f, λ), sum_tup, (zero(T),zero(T),zero(T)), grid )
        EX = EX / fx
        VX = √( VX / fx - abs2(EX) )
        iterations += 1
        if VX < ϵ
            converged = true
        elseif iterations == max_iter
            break
        end
        λ = step(λ, VX)
        logfx += log(fx)
        if verbose == true
            println("Iteration: $iterations\nEX: $EX, VX: $VX, λ: $λ.\n")
        end
    end
    PincusResult((EX,), (VX,), converged, iterations)
end

naive_step(λ::T, VX) where T = λ*T(1.5)
cautious_naive_step(λ::T, VX) where T = λ*T(1.1)


text:
struct PFCombinatorTrace
    args::Tuple
    gen_fn::Any
    emission_choices::DynamicChoiceMap
    log_ml_est::Float64
end

Gen.get_args(tr::PFCombinatorTrace) = tr.args
Gen.get_retval(tr::PFCombinatorTrace) = nothing
Gen.get_gen_fn(tr::PFCombinatorTrace) = tr.gen_fn
Gen.get_score(tr::PFCombinatorTrace) = tr.log_ml_est
Gen.get_choices(tr::PFCombinatorTrace) = tr.emission_choices

struct ParticleFilterCombinator <: GenerativeFunction{Any,PFCombinatorTrace}
    combined::GenerativeFunction
    num_particles::Int
end

function ParticleFilterCombinator(init, dynamics, emission, num_particles::Int)

    @gen function kernel(t::Int, prev_state,
            dynamics_args::Tuple, emission_args::Tuple)
        state = @trace(dynamics(t+1, prev_state, dynamics_args...), :dynamics)
        @trace(emission(t+1, state, emission_args...), :emission)
        return state
    end

    chain = Unfold(kernel)

    @gen function combined(T::Int, init_args::Tuple, dynamics_args::Tuple, emission_args::Tuple)
        init_state = @trace(init(init_args...), :init)
        @trace(emission(1, init_state, emission_args...), :init_emission)
        @trace(chain(T, init_state, dynamics_args, emission_args...), :chain, @argdiff())
    end

    ParticleFilterCombinator(combined, num_particles)
end

function run_particle_filter(gen_fn::ParticleFilterCombinator, args::Tuple, choices::ChoiceMap, num_particles::Int)
    (T::Int, initial_args, dynamics_args, emission_args) = args
    init_obs = choicemap()
    set_submap!(init_obs, :init_emission, get_submap(choices, 1))
    init_args = (0, initial_args, dynamics_args, emission_args)
    state = initialize_particle_filter(gen_fn.combined,
        init_args, init_obs, num_particles)
    argdiff = UnfoldCustomArgDiff(false, false)
    for t=2:T
        new_args = (t-1, initial_args, dynamics_args, emission_args)
        maybe_resample!(state)
        obs = choicemap()
        set_submap!(obs, :chain => t-1 => :emission, get_submap(choices, t))
        particle_filter_step!(state, new_args, argdiff, obs)
    end
    log_ml_estimate(state)
end

function Gen.generate(gen_fn::ParticleFilterCombinator, args::Tuple, choices::ChoiceMap)
    log_ml_est = run_particle_filter(gen_fn, args, choices, gen_fn.num_particles)
    trace = PFCombinatorTrace(args, gen_fn, choices, log_ml_est)
    (trace, log_ml_est)
end

function Gen.update(trace::PFCombinatorTrace, args::Tuple, argdiff, choices::ChoiceMap)
    if !isempty(choices)
        error("Not implemented")
    end
    gen_fn = get_gen_fn(trace)
    new_log_ml_est = run_particle_filter(gen_fn, args, trace.emission_choices, gen_fn.num_particles)
    new_trace = PFCombinatorTrace(args, gen_fn, trace.emission_choices, new_log_ml_est)
    weight = new_log_ml_est - trace.log_ml_est
    (new_trace, weight, DefaultRetDiff(), EmptyChoiceMap())
end

function Gen.regenerate(trace::PFCombinatorTrace, args::Tuple, argdiff, selection::Selection)
    if !isempty(selection)
        error("Not implemented")
    end
    gen_fn = get_gen_fn(trace)
    new_log_ml_est = run_particle_filter(gen_fn, args, trace.emission_choices, gen_fn.num_particles)
    new_trace = PFCombinatorTrace(args, gen_fn, trace.emission_choices, new_log_ml_est)
    weight = new_log_ml_est - trace.log_ml_est
    (new_trace, weight, DefaultRetDiff(), EmptyChoiceMap())
end

function Gen.extend(::PFCombinatorTrace, ::Tuple, argdiff, ::ChoiceMap)
    error("Not implemented")
end

function Gen.choice_gradients(::PFCombinatorTrace, ::Selection)
    error("Not implemented")
end

function Gen.accumulate_param_gradients!(::PFCombinatorTrace,
    retgrad, scale_factor)
    error("Not implemented")
end

function Gen.propose(::ParticleFilterCombinator, args::Tuple)
    error("Not implemented")
end

function Gen.assess(::ParticleFilterCombinator, args::Tuple, choices::ChoiceMap)
    error("Not implemented")
end

function Gen.project(tr::PFCombinatorTrace, ::EmptySelection)
    # q(t; u=empty, x) = simulate forward from model
    # q(r; x, t) = run sMC
    # therefore, the result is SMC-ML-est / forward probability
    #tr.log_ml_est - tr.model_project
    0.
end


text:
using DynamicHMC
using LogDensityProblems
using TransformVariables: as𝕀, as
import TransformVariables
using ForwardDiff
using Omega.Space: flat

"No U-Turn Sampler"
struct NUTSAlg <: SamplingAlgorithm end

isapproximate(::NUTSAlg) = true

"No U-Turn Sampler"
const NUTS = NUTSAlg()
defcb(::NUTSAlg) = default_cbs()
defΩ(::NUTSAlg) = Omega.LinearΩ{Vector{Int64}, UnitRange{Int64}, Vector{ForwardDiff.Dual}}

"""Dynamic Hamiltonian Monte Carlo

$(SIGNATURES)

Sample `n` `ω::ΩT`

# Arguments
- `rng`: Random number generator
- `logdensity`: Real valued `RandVar` defining log-density
- `n`: Number of samples
- `ωinit`: starting position
- `ϵ`: Initial step size

# Returns
- `ωs::Vector{ΩT}`: Samples from `logdensity`

"""
function Base.rand(rng,
                   ΩT::Type{OT},
                   logdensity::RandVar,
                   n::Integer,
                   alg::NUTSAlg;
                   ωinit = ΩT(),
                   ϵ = 0.0001,
                   offset = 0) where {OT <: Ω}
  ω = ωinit
  # init
  logdensity(ω)

  # Ω is unit hypercube.  Do inference on infinite hypercube and transform
  t = as(Array, as𝕀, Omega.Space.nelem(ω))

  flatlogdensity = flat(logdensity, ω)
  P = TransformedLogDensity(t, flatlogdensity)
  ∇P = ADgradient(:ForwardDiff, P)
  chain, NUTS_tuned = NUTS_init_tune_mcmc(rng, ∇P, n, ϵ = ϵ)
  vecuntransformed = get_position.(chain)
  vecsamples = t.(vecuntransformed)
  [unlinearize(floatvec, ω) for floatvec in vecsamples]
end


text:
using Test
import DandelionWebSockets: handle
using DandelionWebSockets: AbstractClientProtocol, SendTextFrame, FinalFrameAlreadySentException
using DandelionWebSockets: TextFrameSender, sendframe, BinaryFrameSender, SendBinaryFrame

struct FakeClientProtocol <: AbstractClientProtocol
    text_frame::Vector{SendTextFrame}
    binary_frame::Vector{SendBinaryFrame}

    FakeClientProtocol() = new([], [])
end

handle(f::FakeClientProtocol, s::SendTextFrame) = push!(f.text_frame, s)
handle(f::FakeClientProtocol, b::SendBinaryFrame) = push!(f.binary_frame, b)

@testset "Multi-frame message    " begin
    # These are tests for sending multi-frame message.
    #
    # Requirement
    # @5_4-2 Fragmented messages
    # @5_4-5 Fragment order
    # @5_4-8 Fragment size for non control messages
    # @5_4-9 Fragmented and unfragmented messages.
    # @6_1-4 Encapsulating data in multi-frame messages.
    # @6_1-6 FIN bit must be set in the last frame.
    # @6_1-8 Transmitting frames.
    #
    # These tests collectively test requirement @5_4-2.
    #
    # Fragments are sent in the order in which the user requests they are sent, by design.
    # The receiving part of fragmentation order is also done by design in client_logic.jl.
    #
    # Fragment size is not constrained in any way. The payload is taken as is by the client.
    @testset "Text frames" begin
        @testset "First frame; Opcode is OPCODE_TEXT" begin
            # Arrange
            logic = FakeClientProtocol()
            sender = TextFrameSender(logic)

            # Act
            sendframe(sender, "Hello")

            # Assert
            @test logic.text_frame[1].opcode == OPCODE_TEXT
        end

        @testset "Second frame; Opcode is OPCODE_CONTINUATION" begin
            # Arrange
            logic = FakeClientProtocol()
            sender = TextFrameSender(logic)

            # Act
            sendframe(sender, "Hello")
            sendframe(sender, "world")

            # Assert
            @test logic.text_frame[2].opcode == OPCODE_CONTINUATION
        end

        @testset "First frame; frame isn't the final" begin
            # Arrange
            logic = FakeClientProtocol()
            sender = TextFrameSender(logic)

            # Act
            sendframe(sender, "Hello")

            # Assert
            @test logic.text_frame[1].isfinal == false
        end

        @testset "Second frame that isn't last; frame isn't final" begin
            # Arrange
            logic = FakeClientProtocol()
            sender = TextFrameSender(logic)

            # Act
            sendframe(sender, "Hello")
            sendframe(sender, "world")

            # Assert
            @test logic.text_frame[2].isfinal == false
        end

        @testset "Last frame; frame is final" begin
            # Arrange
            logic = FakeClientProtocol()
            sender = TextFrameSender(logic)

            # Act
            sendframe(sender, "Hello")
            sendframe(sender, "world")
            sendframe(sender, "lastframe"; isfinal=true)

            # Assert
            @test logic.text_frame[3].isfinal == true
        end

        @testset "Send frame after the final; Exception is thrown" begin
            # Arrange
            logic = FakeClientProtocol()
            sender = TextFrameSender(logic)

            # Act
            sendframe(sender, "lastframe"; isfinal=true)

            # Assert
            @test_throws FinalFrameAlreadySentException sendframe(sender, "another frame")
        end

        @testset "User can send invalid UTF-8 as a byte vector; Frame is sent" begin
            logic = FakeClientProtocol()
            sender = TextFrameSender(logic)

            text = "\u2000"
            # The first byte of the above UTF-8 is invalid as a UTF-8 string.
            text_as_binary = unsafe_wrap(Vector{UInt8}, text)
            payload = text_as_binary[1:1]

            sendframe(sender, payload)

            @test logic.text_frame[1].data == payload
        end
    end

    @testset "Binary frames" begin
        @testset "First frame; Opcode is OPCODE_TEXT" begin
            # Arrange
            logic = FakeClientProtocol()
            sender = BinaryFrameSender(logic)

            # Act
            sendframe(sender, b"Hello")

            # Assert
            @test logic.binary_frame[1].opcode == OPCODE_BINARY
        end

        @testset "Second frame; Opcode is OPCODE_CONTINUATION" begin
            # Arrange
            logic = FakeClientProtocol()
            sender = BinaryFrameSender(logic)

            # Act
            sendframe(sender, b"Hello")
            sendframe(sender, b"world")

            # Assert
            @test logic.binary_frame[2].opcode == OPCODE_CONTINUATION
        end

        @testset "First frame; frame isn't the final" begin
            # Arrange
            logic = FakeClientProtocol()
            sender = BinaryFrameSender(logic)

            # Act
            sendframe(sender, b"Hello")

            # Assert
            @test logic.binary_frame[1].isfinal == false
        end

        @testset "Second frame that isn't last; frame isn't final" begin
            # Arrange
            logic = FakeClientProtocol()
            sender = BinaryFrameSender(logic)

            # Act
            sendframe(sender, b"Hello")
            sendframe(sender, b"world")

            # Assert
            @test logic.binary_frame[2].isfinal == false
        end

        @testset "Last frame; frame is final" begin
            # Arrange
            logic = FakeClientProtocol()
            sender = BinaryFrameSender(logic)

            # Act
            sendframe(sender, b"Hello")
            sendframe(sender, b"world")
            sendframe(sender, b"lastframe"; isfinal=true)

            # Assert
            @test logic.binary_frame[3].isfinal == true
        end

        @testset "Send frame after the final; Exception is thrown" begin
            # Arrange
            logic = FakeClientProtocol()
            sender = BinaryFrameSender(logic)

            # Act
            sendframe(sender, b"lastframe"; isfinal=true)

            # Assert
            @test_throws FinalFrameAlreadySentException sendframe(sender, b"another frame")
        end

    end
end


text:
# Gradient tests for adjoint extended modeling
# Author: Ziyi Yin, ziyi.yin@gatech.edu
# Date: Mar 2021
#
using JUDI4Flux
using JUDI, SegyIO, JOLI, Flux
using Test, ImageFiltering, LinearAlgebra, Random

Random.seed!(11)

# Set up model structure
n = (120, 100)   # (x,y,z) or (x,z)
d = (10., 10.)
o = (0., 0.)

# Velocity [km/s]
v = ones(Float32,n) .+ 0.4f0
v[:, Int(round(end/2)):end] .= 4f0

# Slowness squared [s^2/km^2]
m = (1f0 ./ v).^2
m0 = imfilter(m, Float32.(Kernel.gaussian(10)))

# Setup info and model structure
nsrc = 4	# number of sources
model = Model(n, d, o, m)
model0 = Model(n, d, o, m0)
m = reshape(m,n[1],n[2],1,1)
m0 = reshape(m0,n[1],n[2],1,1)

# Set up receiver geometry
nxrec = 120

xsrc = convertToCell(range(50f0, stop=1150f0,length=nsrc))
ysrc = convertToCell(range(0f0,stop=0f0,length=nsrc))
zsrc = convertToCell(range(20f0, stop=20f0,length=nsrc))

xrec = range(50f0, stop=1150f0, length=nxrec)
yrec = 0f0
zrec = range(50f0, stop=50f0, length=nxrec)

# receiver sampling and recording time
time = 1000f0   # receiver recording time [ms]
dt = 1f0    # receiver sampling interval [ms]
nt = Int(time/dt)+1
# Set up receiver structure
srcGeometry = Geometry(xsrc, ysrc, zsrc; dt=dt, t=time)
recGeometry = Geometry(xrec, yrec, zrec; dt=dt, t=time, nsrc=nsrc)

# setup wavelet
f0 = 0.01f0     # MHz
wavelet = ricker_wavelet(time, dt, f0)

q = judiVector(srcGeometry, wavelet)

# Set up info structure for linear operators
ntComp = get_computational_nt(srcGeometry, recGeometry, model)
info = Info(prod(n), nsrc, ntComp)

# return linearized data as Julia array
opt = Options(return_array=true, sum_padding=true)

# Linear operators
Pr = judiProjection(info, recGeometry)
A_inv = judiModeling(info, model; options=opt)
A_inv0 = judiModeling(info, model0; options=opt)
Ps = judiProjection(info, srcGeometry)
F = Pr*A_inv*adjoint(Ps)
F0 = Pr*A_inv0*adjoint(Ps)

#####################################################################################

G = Forward(F,q)

function misfit_objective(d_obs, m0, G)

	# Data residual and source residual
  	r_data   = G(m0) - d_obs

	# Function value
	fval = .5f0 *sum(r_data.^2)

	print("Function value: ", fval, "\n")
	return fval
end

d_obs = G(m)

J = judiJacobian(F0,q)

gradient_m = adjoint(J)*vec(G(m0)-d_obs)

gs_inv = gradient(x -> misfit_objective(d_obs, x, G), m0)

g1 = vec(gradient_m)
g2 = vec(gs_inv[1])

@test isapprox(norm(g1-g2) / norm(g1), 0f0; atol=1f-1)
@test isapprox(dot(g1,g2)/norm(g1)/norm(g2),1f0;rtol=1f-1)


text:
function secret_handshake(code)
    handshakes = []
    code & 1 == 1 && push!(handshakes, "wink")
    code & 2 == 2 && push!(handshakes, "double blink")
    code & 4 == 4 && push!(handshakes, "close your eyes")
    code & 8 == 8 && push!(handshakes, "jump")
    code & 16 == 16 && reverse!(handshakes)

    return handshakes
end

max_stars_repo_name: koladilip/julia-exercism

max_issues_repo_name: koladilip/julia-exercism

max_forks_repo_name: koladilip/julia-exercism


text:
using Test
using FluidSynth

@time @testset "Without an audio driver Test" begin include("without_audiodriver_test.jl") end
@time @testset "Midi file rendering Test" begin include("midifile_rendering_test.jl") end
# below test is need sound output.
# @time @testset "Audio driver Test" begin include("audiodriver_test.jl") end
# @time @testset "Midi file audio driver Test" begin include("midifile_play_test.jl") end


text:
# phase_vocoder.jl

using Sound: phase_vocoder
using Test: @testset, @test, @inferred

@testset "vocoder" begin
    S = 8192
    N = S
    x = cos.(2π*400*(1:N)/S)
    y = @inferred phase_vocoder(x, S)
    @test length(y) == 2N
    y2 = @inferred phase_vocoder([x 2x], S)
    @test y2 ≈ [y 2y]
end


text:
module Shapes

using Formatting,
RecipesBase

export Circle,
Ellipse,
Square,
Rectangle,
Parallelogram,
DeformedDisk,
Universe

export AbstractShape,
AbstractCircle,
AbstractEllipse,
AbstractSquare,
AbstractRectangle,
AbstractParallelogram

abstract type AbstractShape end
abstract type AbstractParallelogram <: AbstractShape end
abstract type AbstractRectangle <: AbstractParallelogram end
abstract type AbstractSquare <: AbstractRectangle end
abstract type AbstractEllipse <: AbstractShape end
abstract type AbstractCircle <: AbstractEllipse end

"""
    Circle(R, x0, y0)
"""
struct Circle <: AbstractCircle
    R::Float64
    x0::Float64
    y0::Float64

    Circle(R::Number,x0::Number,y0::Number) = new(R,x0,y0)
    (c::Circle)(x,y) = hypot((x-c.x0), (y-c.y0)) ≤ c.R

    Base.show(io::IO, circle::Circle) = print(io, "Circle(R=$(fmt("2.2f",circle.R)), x0=$(fmt("2.2f",circle.x0)), y0=$(fmt("2.2f",circle.y0)))")

    @recipe function f(cr::Circle)
        θ = LinRange(0,2π,101)
        x = @. cr.x0 + cr.R*cos(θ)
        y = @. cr.x0 + cr.R*sin(θ)
        seriestype --> :path
        fillcolor --> :red
        fillrange --> 0
        fillalpha --> .15
        aspect_ratio --> 1
        legend-->false
        (x,y)
    end
end

"""
    Ellipse(a, b, x0, y0, θ)
"""
struct Ellipse <: AbstractEllipse
    a::Float64
    b::Float64
    x0::Float64
    y0::Float64
    θ::Float64
    cosθ::Float64
    sinθ::Float64

    Ellipse(a::Number,b::Number,x0::Number,y0::Number,θ::Number) = new(float(a),float(b),float(x0),float(y0),float(θ),cos(θ),sin(θ))
    function (e::Ellipse)(x,y)
        xrot, yrot = rotate(x-e.x0, y-e.y0, e.cosθ, e.sinθ)
        return hypot(xrot/e.a, yrot/e.b) ≤ 1
    end

    Base.show(io::IO, ellipse::Ellipse) = print(io, "Ellipse(a=$(fmt("2.2f",ellipse.a)), b=$(fmt("2.2f",ellipse.b)), x0=$(fmt("2.2f",ellipse.x0)), y0=$(fmt("2.2f",ellipse.y0)), θ=$(fmt("2.2f",ellipse.θ)))")

    @recipe function f(el::Ellipse)
        θ = LinRange(0,2π,101)
        x = @. el.a*cos(θ)
        y = @. el.b*sin(θ)
        seriestype --> :path
        fillcolor --> :red
        fillrange --> 0
        fillalpha --> .15
        aspect_ratio --> 1
        legend-->false
        xrot, yrot = rotate(x,y,el.cosθ,el.sinθ)
        el.x0 .+ xrot, el.y0 .+ yrot
    end
end

"""
    Square(a,x0,y0,θ)
"""
struct Square <: AbstractSquare
    a::Float64
    x0::Float64
    y0::Float64
    θ::Float64
    cosθ::Float64
    sinθ::Float64

    function Square(a::Number,x0::Number,y0::Number,θ::Number)
        new(float(a),float(x0),float(y0),float(θ),cos(θ),sin(θ))
    end
    function (s::Square)(x,y)
        xrot, yrot = rotate(x-s.x0, y-s.y0, s.cosθ, s.sinθ)
        return 0 ≤ xrot ≤ s.a  &&  0 ≤ yrot ≤ s.a
    end

    Base.show(io::IO, square::Square) = print(io, "Square(a=$(fmt("2.2f",square.a)), x0=$(fmt("2.2f",square.x0)), y0=$(fmt("2.2f",square.y0)), θ=$(fmt("2.2f",square.θ)))")

    @recipe function f(sq::Square)
        x = sq.a*cumsum([0, +1,  0, -1,  0])
        y = sq.a*cumsum([0,  0, +1,  0, -1])
        seriestype --> :path
        fillcolor --> :red
        fillrange --> 0
        fillalpha --> .15
        aspect_ratio --> 1
        legend --> false
        xrot, yrot = rotate(x,y,sq.cosθ,sq.sinθ)
        sq.x0 .+ xrot, sq.y0 .+ yrot
    end
end

"""
    Rectangle(a, b, x0, y0, θ)
"""
struct Rectangle <: AbstractRectangle
    a::Float64
    b::Float64
    x0::Float64
    y0::Float64
    θ::Float64
    cosθ::Float64
    sinθ::Float64

    function Rectangle(a::Number,b::Number,x0::Number,y0::Number,θ::Number)
        new(float(a),float(b),float(x0),float(y0),float(θ),cos(θ),sin(θ))
    end

    function (r::Rectangle)(x,y)
        xrot, yrot = rotate(x-r.x0, y-r.y0, r.cosθ, r.sinθ)
        return 0 ≤ xrot ≤ r.a  &&  0 ≤ yrot ≤ r.b
    end

    Base.show(io::IO, rect::Rectangle) = print(io, "Rectangle(a=$(fmt("2.2f",rect.a)), b=$(fmt("2.2f",rect.b)), x0=$(fmt("2.2f",rect.x0)), y0=$(fmt("2.2f",rect.y0)), θ=$(fmt("2.2f",rect.θ)))")

    @recipe function f(rc::Rectangle)
        x = cumsum([0, rc.a,      0, -rc.a, 0])
        y = cumsum([0,     0, +rc.b,     0, -rc.b])
        seriestype --> :path
        fillcolor --> :red
        fillrange --> 0
        fillalpha --> .15
        aspect_ratio --> 1
        legend --> false
        xrot, yrot = rotate(x,y,rc.cosθ,rc.sinθ)
        rc.x0 .+ xrot, rc.y0 .+ yrot
    end
end

"""
    Parallelogram(a, b, α, x0, y0, θ)
"""
struct Parallelogram <: AbstractParallelogram
    a::Float64
    b::Float64
    α::Float64
    x0::Float64
    y0::Float64
    θ::Float64
    cosθ::Float64
    sinθ::Float64
    tanα::Float64
    cosα::Float64

    function Parallelogram(a::Number, b::Number, α::Number, x0::Number, y0::Number, θ::Number)
        new(float(a),float(b),float(α),float(x0),float(y0),float(θ),cos(θ),sin(θ),tan(α),cos(α))
    end

    function (p::Parallelogram)(x,y)
        xrot, yrot = rotate(x-p.x0, y-p.y0, p.cosθ, p.sinθ)
        return p.tanα*(xrot-p.a) ≤ yrot ≤ p.tanα*xrot  &&  0 ≤ yrot ≤ p.cosα*p.b
    end

    Base.show(io::IO, par::Parallelogram) = print(io, "Parallelogram(a=$(fmt("2.2f",par.a)), b=$(fmt("2.2f",par.b)), α=$(fmt("2.2f",par.α)), x0=$(fmt("2.2f",par.x0)), y0=$(fmt("2.2f",par.y0)), θ=$(fmt("2.2f",par.θ)))")

    @recipe function f(pg::Parallelogram)
        x = cumsum([0, pg.a, +pg.b*cos(pg.α), -pg.a, -pg.b*cos(pg.α)])
        y = cumsum([0, 0, +pg.b*sin(pg.α), 0, -pg.b*sin(pg.α)])
        seriestype --> :path
        fillcolor --> :red
        fillrange --> 0
        fillalpha --> .15
        aspect_ratio --> 1
        legend --> false
        xrot, yrot = rotate(x,y,pg.cosθ,pg.sinθ)
        pg.x0 .+ xrot, pg.y0 .+ yrot
    end
end

"""
    DeformedDisk(R, x0, y0, M, a, φ)
`R` is radius, `x0` and `y0` are origin, `M`
is array of multipole integers, `a` is array of
amplitudes, `φ` is array of angles
"""
struct DeformedDisk{N} <: AbstractShape
    R::Float64
    M::Vector{Int}
    a::Vector{Float64}
    φ::Vector{Float64}
    x0::Float64
    y0::Float64

    function DeformedDisk(R::Number,x0::Number,y0::Number,M::AbstractArray,a,φ)
        new{length(M)}(float(R),M,a,φ,float(x0),float(y0))
    end
    function (d::DeformedDisk)(x,y)
        θ = atan(y-d.y0,x-d.x0)
        return hypot(x,y) ≤ d.R + sum(d.a.*(map((x,y)->cos(x*(θ-y)),d.M,d.φ)))
    end

    Base.show(io::IO, d::DeformedDisk) = print(io,"DeformedDisk")#(a=$(fmt("2.2f",ellipse.a)), b=$(fmt("2.2f",ellipse.b)), x0=$(fmt("2.2f",ellipse.x0)), y0=$(fmt("2.2f",ellipse.y0)), θ=$(fmt("2.2f",ellipse.θ)))")

    @recipe function f(d::DeformedDisk)
        θ = LinRange(0,2π,101)
        r = d.R .+ sum(d.a.*(map((x,y)->cos.(x*(θ.-y)),d.M,d.φ)))
        x = @. r*cos(θ)
        y = @. r*sin(θ)
        seriestype --> :path
        fillcolor --> :red
        fillrange --> 0
        fillalpha --> .15
        aspect_ratio --> 1
        legend-->false
        d.x0 .+ x, d.y0 .+ y
    end
end

"""
    Universe()
"""
struct Universe <: AbstractShape
    Universe() = new()
    (::Universe)(x,y) = true

    Base.show(io::IO, ::Universe) = print(io, "Universe()")
end

"""
    rotate(x,y,cosθ,sinθ)
"""
function rotate(x::Real,y::Real,cosθ::Real,sinθ::Real)
    (xrot,yrot) = iszero(sinθ) ? (x,y) : (cosθ*x-sinθ*y, sinθ*x+cosθ*y)
    return xrot, yrot
end

function rotate(x::AbstractArray,y::AbstractArray,cosθ::Real,sinθ::Real)
    xyrot = rotate.(x,y,cosθ,sinθ)
    xrot = Array{Float64}(undef,size(xyrot))
    yrot = Array{Float64}(undef,size(xyrot))
    for i ∈ eachindex(xyrot)
        xrot[i] = xyrot[i][1]
        yrot[i] = xyrot[i][2]
    end
    return xrot, yrot
end

end #module


text:
"""
    (lon_f, lat_f) = lon_lat_fine(lon, lat, nf)

Interpolate longitude and latitude arrays (2d or 1d) `lon` and `lat` to higher resolution by a factor `nf`.
"""
function lon_lat_fine(lon_mat, lat_mat, nf)

    ns = size(lon_mat)

    if (length(ns)==2)
        nlon = ns[1]; nlat = ns[2]

        xc = 1:nlon
        yc = 1:nlat
        xf = (0.5+1/(2*nf)):1/nf:(nlon+0.5-1/(2*nf))
        yf = (0.5+1/(2*nf)):1/nf:(nlat+0.5-1/(2*nf))
        knots = (collect(yc),collect(xc))

        itplon = extrapolate(interpolate(knots, lon_mat, Gridded(Linear())), Line())
        itplat = extrapolate(interpolate(knots, lat_mat, Gridded(Linear())), Line())

        lon_f = itplon(collect(yf),collect(xf))
        lat_f = itplat(collect(yf),collect(xf))
    else
        (nlat,) = size(lat_mat)
        (nlon,) = size(lon_mat)

        xc = 1:nlon
        yc = 1:nlat

        xf = (0.5+1/(2*nf)):1/nf:(nlon+0.5-1/(2*nf))
        yf = (0.5+1/(2*nf)):1/nf:(nlat+0.5-1/(2*nf))
        knotsx = collect(xc)
        knotsy = collect(yc)

        itplon = extrapolate(interpolate((knotsx,), lon_mat, Gridded(Linear())), Line())
        itplat = extrapolate(interpolate((knotsy,), lat_mat, Gridded(Linear())), Line())

        lon_f = itplon(collect(xf))
        lat_f = itplat(collect(yf))
    end

    return lon_f, lat_f
end


text:
using .Octavian

export backend_octavian

function backend_octavian()
  return gemm_backend[] = :Octavian
end

function _gemm!(
  ::GemmBackend{:Octavian},
  tA,
  tB,
  alpha,
  A::AbstractVecOrMat,
  B::AbstractVecOrMat,
  beta,
  C::AbstractVecOrMat,
)
  return Octavian.matmul!(
    C, tA == 'T' ? transpose(A) : A, tB == 'T' ? transpose(B) : B, alpha, beta
  )
end


text:
using Plots

a = collect(1:20)

f(x)=x^1

b=f.(a)

c=a+b*2

# plot(a,b)


text:
export path_to_edge_list, get_aggregate_graph

function path_to_edge_list(x::Vector{T}) where {T}
    out = Tuple{T,T}[]
    for i in 1:(length(x)-1)
        push!(out, (x[i], x[i+1]))
    end
    return out
end
function path_to_edge_list(x::Vector{String}; relabel=true)
    if relabel
        x_int, rev_map = string_to_int(x)
        return path_to_edge_list(x_int), rev_map
    else
        out = Tuple{String,String}[]
        for i in 1:(length(x)-1)
            push!(out, (x[i], x[i+1]))
        end
        return out
    end
end

function get_aggregate_graph(S::InteractionSequence{Int})
    V = length(unique(vcat(S...)))
    A = zeros(Int, V, V)
    for path in S
        for i in 1:(length(path)-1)
            src, dest = (path[i],path[i+1])
            A[src,dest] += 1
        end
    end
    return A
end

function get_aggregate_graph(S::InteractionSequence{Int}, V::Int)
    A = zeros(Int, V, V)
    for path in S
        for i in 1:(length(path)-1)
            src, dest = (path[i],path[i+1])
            A[src,dest] += 1
        end
    end
    return A
end

function get_aggregate_graph(S::InteractionSequence{String})
    S_int, rev_map = string_to_int(S)
    return get_aggregate_graph(S_int), rev_map
end

max_stars_repo_path: src/Data Processing/aggregate_graph.jl

max_issues_repo_path: src/Data Processing/aggregate_graph.jl

max_forks_repo_path: src/Data Processing/aggregate_graph.jl


text:
"""
    is_same(cursor1, cursor2) -> Bool
Return true if the source codes are exactly the same.
"""
function is_same(cursor1, cursor2)
    tu1 = getTranslationUnit(cursor1)
    tu2 = getTranslationUnit(cursor2)
    if tu1 == tu2
        # if both cursors are in the same TU
        cursor1 == cursor2 && return true
    else
        # if not, compare code locations
        file1, line1, col1 = get_file_line_column(cursor1)
        file2, line2, col2 = get_file_line_column(cursor2)
        return normpath(file1) == normpath(file2) && line1 == line2 && col1 == col2
    end
    # FIXME: in other cases, the code might be just compatible with each other, where we
    # need to compare the tokens.
end

# global counter for generating deterministic symbols
const __JL_COUNTER = Threads.Atomic{Int}(0)

reset_counter() = Threads.atomic_sub!(__JL_COUNTER,  __JL_COUNTER[])
add_counter() = Threads.atomic_add!(__JL_COUNTER, 1)
get_counter() = __JL_COUNTER[]

function gensym_deterministic(x::AbstractString)
    add_counter()
    str = "__JL_" * x * "_" * string(get_counter())
    return Symbol(str)
end


text:
using Gadfly

n = 10
plot(x=rand(n), y=rand(n), color=1000.^rand(n),
     Scale.color_log10(minvalue=1, maxvalue=1e3))


text:
# Use baremodule to shave off a few KB from the serialized `.ji` file
baremodule IntelOpenMP_jll
using Base
using Base: UUID
import JLLWrappers

JLLWrappers.@generate_main_file_header("IntelOpenMP")
JLLWrappers.@generate_main_file("IntelOpenMP", UUID("1d5cc7b8-4909-519e-a0f8-d0f5ad9712d0"))
end  # module IntelOpenMP_jll


text:
"""
SequentialRaytrace is a package for sequential ray tracing of
optical systems.
"""
module SequentialRaytrace

include("Dispersion.jl")
export Air, Silica
export ConstantIndex, Sellmeier_1
export refractive_index

include("Ray.jl")
export Ray
export ray_from_NA

include("Errors.jl")
export error_type

include("Aperture.jl")
export ClearDiameter

include("Surfaces.jl")
export sag

include("Sphere.jl")
export Plano, Sphere

include("EvenAsphere.jl")
export EvenAsphere

include("Paraxial.jl")
export Paraxial

include("Component.jl")
export OpticalComponent
export track_length

include("Lens.jl")
export Lens, Object

include("Trace.jl")
export gen_result, trace!

end # module


text:
using StatsBase
using Test
using Statistics

@testset "Ambiguities" begin
    # Ambiguities with Base, Core, and stdlib Statistics introduced by this package
    @test_broken isempty(detect_ambiguities(StatsBase, Base, Core, Statistics))
end


text:
using Revise, OffsetArrays, ProgressMeter, Plots
import KitBase

begin
    cd(@__DIR__)
    D = KitBase.read_dict("config.txt")
    for key in keys(D)
        s = Symbol(key)
        @eval $s = $(D[key])
    end

    γ = KitBase.heat_capacity_ratio(inK, 1)
    set = KitBase.Setup(
        matter,
        case,
        space,
        flux,
        collision,
        nSpecies,
        interpOrder,
        limiter,
        boundary,
        cfl,
        maxTime,
    )
    pSpace = KitBase.PSpace1D(x0, x1, nx, nxg)
    vSpace = KitBase.VSpace1D(umin, umax, nu, vMeshType, nug)
    μᵣ = KitBase.ref_vhs_vis(knudsen, alphaRef, omegaRef)
    gas =
        KitBase.Gas(knudsen, mach, prandtl, inK, γ, omega, alphaRef, omegaRef, μᵣ, mass, 0)
    wL, primL, hL, bL, bcL, wR, primR, hR, bR, bcR =
        KitBase.ib_rh(gas.Ma, gas.γ, gas.K, vSpace.u)
    ib = KitBase.IB(wL, primL, bcL, wR, primR, bcR)
    ks = KitBase.SolverSet(set, pSpace, vSpace, gas, ib, pwd())

    ctr = OffsetArray{KitBase.ControlVolumeParticle1D}(undef, eachindex(ks.pSpace.x))
    face = Array{KitBase.Interface1D}(undef, ks.pSpace.nx + 1)

    for i in eachindex(ctr)
        if i <= ks.pSpace.nx ÷ 2
            ctr[i] = KitBase.ControlVolumeParticle1D(
                ks.pSpace.x[i],
                ks.pSpace.dx[i],
                ks.ib.wL,
                ks.ib.primL,
                #KitBase.prim_conserve([1.0, 0.0, 0.5], ks.gas.γ),
                #[1.0, 0.0, 0.5],
                KitBase.vhs_collision_time(ks.ib.primL, ks.gas.μᵣ, ks.gas.ω),
            )
        else
            ctr[i] = KitBase.ControlVolumeParticle1D(
                ks.pSpace.x[i],
                ks.pSpace.dx[i],
                ks.ib.wR,
                ks.ib.primR,
                #ks.ib.wL,
                #ks.ib.primL,
                #KitBase.prim_conserve([0.8, 0.0, 0.8], ks.gas.γ),
                #[0.8, 0.0, 0.8],
                KitBase.vhs_collision_time(ks.ib.primR, ks.gas.μᵣ, ks.gas.ω),
            )
        end
    end

    for i = 1:ks.pSpace.nx+1
        face[i] = KitBase.Interface1D(ks.ib.wL)
    end

    t = 0.0
    dt = KitBase.timestep(ks, ctr, t)
    res = zeros(3)
end

ptc = KitBase.init_ptc!(ks, ctr; mode = :soa, factor = 2)
ptc_new = deepcopy(ptc)

KitBase.bgk_transport!(ks, ctr, ptc, ptc_new, dt)
KitBase.bgk_collision!(ks, ctr, ptc_new, face, res)
KitBase.boundary!(ks, ctr, ptc_new, face, dt, :fix)
KitBase.duplicate!(ptc, ptc_new, ks.gas.np)

@showprogress for iter = 1:100#nt

    @inbounds Threads.@threads for i = 1:ks.pSpace.nx+1
        KitBase.flux_equilibrium!(
            face[i].fw,
            ctr[i-1].w,
            ctr[i].w,
            ks.gas.K,
            ks.gas.γ,
            ks.gas.μᵣ,
            ks.gas.ω,
            ks.gas.Pr,
            dt,
            0.5 * ctr[i-1].dx,
            0.5 * ctr[i].dx,
        )
    end

    #KitBase.update!(ks, ctr, ptc, ptc_new, face, dt, res; coll = :bgk, bc = :fix)

    KitBase.bgk_transport!(ks, ctr, ptc, ptc_new, dt)
    KitBase.bgk_collision!(ks, ctr, ptc_new, face, res)
    KitBase.boundary!(ks, ctr, ptc_new, face, dt, :fix)
    KitBase.duplicate!(ptc, ptc_new, ks.gas.np)

    t += dt
end

KitBase.plot_line(ks, ctr)


text:
using DiffEqJump, DiffEqBase
using Test, LinearAlgebra
using StableRNGs
rng = StableRNG(12345)

Nsims = 1e4

# ABC model A + B <--> C
reactstoch = [
    [1 => 1, 2 => 1],
    [3 => 1],
]
netstoch = [
    [1 => -1, 2 => -1, 3 => 1],
    [1 => 1, 2 => 1, 3 => -1]
]
rates = [0.1, 1.]
u0 = [500,500,0]
tspan = (0.0,5.0)
prob = DiscreteProblem(u0, tspan, rates)
majumps = MassActionJump(rates, reactstoch, netstoch)

function getmean(jprob,Nsims)
    Amean = 0
    for i = 1:Nsims
        sol = solve(jprob,SSAStepper())
        Amean += sol[1,end]
    end
    Amean /= Nsims
    Amean
end

function mastereqmean(u, rates)
    α = u[1]; β = u[2]; γ = u[3]
    d₊ = [rates[1]*(a+1)*(β-α+a+1) for a in 0:(α-1)]
    d₋ = [rates[2]*(γ+α-a+1) for a in 1:α]
    d  = [-rates[1]*a*(β-α+a) - rates[2]*(γ+α-a) for a in 0:α]
    L  = diagm(-1=>d₋,0=>d,1=>d₊)
    P_a = nullspace(L)
    P_a ./= sum(P_a)
    P_a .= abs.(P_a)
    sum((a-1)*p for (a,p) in enumerate(P_a))
end
mastereq_mean = mastereqmean(u0, rates)

algs = DiffEqJump.JUMP_AGGREGATORS
relative_tolerance = 0.01
for alg in algs
    local jprob = JumpProblem(prob,alg,majumps,save_positions=(false,false), rng=rng)
    local Amean = getmean(jprob, Nsims)
    @test abs(Amean - mastereq_mean)/mastereq_mean < relative_tolerance
end


text:
degree_size(currDegree, spatialDim) =
    factorial(currDegree + spatialDim - 1) ÷
    (factorial(currDegree) * factorial(spatialDim - 1))

function basis_size(LMaxDegree, spatialDim)
    basisLen = 0
    for idx_degree = 0:LMaxDegree
        basisLen += degree_size(idx_degree, spatialDim)
    end
    return basisLen
end

function power(basis, exponent)
    if exponent == 0
        return 1.0
    end
    result = basis
    for i = 2:exponent
        result *= basis
    end
    return result
end

function monomial_basis(pointX, pointY, pointZ, polyDegree::T) where {T<:Integer}
    idx_vector = 1
    spatialDim = 3
    basisLen = basis_size(polyDegree, spatialDim)
    basisAtPt = ones(1, basisLen)
    for idx_degree = 0:polyDegree
        for a = 0:idx_degree
            for b = 0:(idx_degree-a)
                c = idx_degree - a - b
                basisAtPt[idx_vector] =
                    power(pointX, a) * power(pointY, b) * power(pointZ, c)
                idx_vector = idx_vector + 1
            end
        end
    end

    return basisAtPt
end

function monomial_basis(pointX, polyDegree::T) where {T<:Integer}
    idx_vector = 1
    spatialDim = 1
    basisLen = basis_size(polyDegree, spatialDim)
    basisAtPt = ones(1, basisLen)
    for a = 0:polyDegree
        basisAtPt[idx_vector] = power(pointX, a)
        idx_vector = idx_vector + 1
    end

    return basisAtPt
end

function eval_sphermonomial(quadpts::AV, polyDegree::Integer)
    monomialBasis = zeros(basis_size(polyDegree, 1), size(quadpts, 1))

    for idx_quad = 1:length(quadpts)
        monomialBasis[:, idx_quad] = monomial_basis(quadpts[idx_quad, 1], polyDegree)
    end

    return monomialBasis
end

function eval_sphermonomial(quadpts::Matrix, polyDegree::Integer)
    monomialBasis = zeros(basis_size(polyDegree, 3), size(quadpts, 1))

    for idx_quad = 1:(size(quadpts)[1])
        monomialBasis[:, idx_quad] = monomial_basis(
            quadpts[idx_quad, 1],
            quadpts[idx_quad, 2],
            quadpts[idx_quad, 3],
            polyDegree,
        )
    end

    return monomialBasis
end


text:
@polly function kernel_jacobi_1d(tsteps, A, B)
    n = size(A,1)

    for t = 1:tsteps
        for i = 2:(n-1)
            B[i] = 0.33333 * (A[i-1] + A[i] + A[i + 1])
        end
        for i = 2:(n-1)
            A[i] = 0.33333 * (B[i-1] + B[i] + B[i + 1])
        end
    end
end

let
    tsteps = 500
    n = 2000

    A = zeros(Float32, n)
    B = zeros(Float32, n)

    for i = 1:n
        A[i] = (i+ 2) / n
        B[i] = (i+ 3) / n
    end

    SUITE["jacobi-1d"] = @benchmarkable kernel_jacobi_1d($tsteps, A, B) setup = (A = copy($A); B = copy($B))
end


text:
# -*- encoding: utf-8 -*-
#
# The MIT License (MIT)
#
# Copyright © 2021 Matteo Foglieni and Riccardo Gervasoni
#

@test 1+1==2
@test Raytracing.are_close(1.00000000001, 1)

a = RGB{Float64}(0.1, 0.2, 0.3)
b = RGB{Float64}(0.5, 0.6, 0.7)
err = 1e-11

# Controllo della inizializzazione
@test a ≈ RGB{Float64}(0.1 + err, 0.2, 0.3 - 2*err)
@test b ≈ RGB{Float64}(0.5, 0.6 + err, 0.7 + 2*err)

# Controllo nuove operazioni
@test a+b ≈ RGB(0.6, 0.8+err, 1.0)
@test b-a ≈ RGB(0.4, 0.4-2err, 0.4)
@test 2.0*a ≈ RGB(0.2 + err, 0.4, 0.6)
@test b*0.5 ≈ RGB(0.25 + err, 0.3, 0.35)
@test a/2. ≈ RGB(0.05, 0.1, 0.15 + 3*err)


text:
module WordleSolver

using CSV, DataFrames
using StatsBase
using ProgressMeter

export  wordle

wordle() = solve_wordle(words, freqs, depth_score)

include("data_setup.jl")
include("interactive_solver.jl")
include("analysis.jl")

end


text:
__precompile__()

"""
A package for exporting highlights (and related data) from PDF files and saving them to
a CSV.

Links:
- Repo: https://github.com/paveloom-j/PDFHighlights.jl
- Docs: https://paveloom-j.github.io/PDFHighlights.jl
"""
baremodule PDFHighlights

"This module contains all inner parts of this package."
module Internal

# Include source code
include("Exceptions/Exceptions.jl")
include("Constants.jl")
include("PDF/PDF.jl")
include("CSV/CSV.jl")
include("Both/Both.jl")

# Export contents of the modules into `Internal`
using .Exceptions
using .Constants
using .PDF
using .CSV
using .Both

end

# Export the second-level functions
using .Internal.PDF
using .Internal.CSV
using .Internal.Both

# Export the first-level functions
export #= PDF =#
       get_author_title,
       get_author,
       get_authors_titles,
       get_comments_pages,
       get_comments,
       get_highlights_comments_pages,
       get_highlights_comments,
       get_highlights_pages,
       get_pages,
       get_title,
       #= CSV =#
       get_all,
       get_locations,
       get_notes,
       import_highlights,
       initialize,
       #= Both =#
       get_authors,
       get_highlights,
       get_titles

end


text:
module CompilerHints

include("../src/Jaynes.jl")
using .Jaynes
using Gen

naive_model = @jaynes function baz(x::Int)
    y = 0.0
    for i in 1 : x
        y += {:y => i} ~ Normal(0.0, 1.0)
    end
end (DefaultPipeline)

ker_model = @jaynes function ker(i::Int, y::Float64)
    y += {:y} ~ Normal(0.0, 1.0)
    y
end
comb = Unfold(ker_model)

model3 = @jaynes function baz(x::Int)
    y = 0.0
    y ~ comb(x, y)
end (DefaultPipeline)

tr = simulate(model3, (5, ))

end # module


text:
export exportData, makeTarGzip, createArtifact

function exportData(e::Experiment, mdf::MDFDatasetStore, study::Union{Nothing,Study}=nothing; logging=false,
                    storeForwardRef=false, keepExpNum=false, kargs...)
  # pretend to be a measurement to enforce loading data from time domain in case post processed data is not available
  # in case of compression isCalib=false right now does not work, thus we disable it.

  isCalib = (haskey(kargs, :SNRThresh) || haskey(kargs, :sparsityTrafoRedFactor)) ? true : false

  exportpath = MPIFile(path(e), isCalib=isCalib) do f

    if !isConvertibleToMDF(f)
      return ""
    end

    if iscalib(e)
      exportpath = getNewCalibPath(mdf)
      saveasMDF(exportpath, f; applyCalibPostprocessing=true, kargs...)
      @info "Calibration data from $(path(e)) successfully exported to $exportpath."
    else
      if study == nothing
        name = studyName(f)
        subject = experimentSubject(f)
        date = studyTime(f)
        s = Study(mdf, name; date=date, subject=subject)
      else
        s = study
      end
      if keepExpNum
        expNum = experimentNumber(f) # or e.num
        exportpath = joinpath(path(s),string(expNum)*".mdf")
      else
        expNum = getNewExperimentNum(s)
        exportpath = getNewExperimentPath(s)
      end
      saveasMDF(exportpath, f; experimentNumber = expNum, kargs...)
      @info "Measurement data from $(path(e)) successfully exported to $exportpath."
    end

    if isdir(path(e)) && storeForwardRef # only if input data is a BrukerFile
      # Store export path in Bruker directory
      open(joinpath(path(e),"mdf"),write=true) do io
        write(io, exportpath)
      end
    end

    if logging
      # log action
      open("/opt/DataArchiveOptmpidata/convertBrukerToMDF/log.csv", append=true) do io
        write(io,"$(path(e)), $exportpath\n")
      end
    end
    exportpath
  end

  return exportpath
end

function exportData(s::Study, mdf::MDFDatasetStore, args...;
                    nums::Vector{Int}=zeros(Int,0),
                    kargs...)
  exps = getExperiments(s)
  for e in exps
    # nums indicates which experiments are exported
    (length(nums) == 0 || e.num in nums) && exportData(e, mdf, args...; kargs...)
  end

  return nothing
end

function exportData(store::D, mdf::MDFDatasetStore; kargs...) where D<:DatasetStore
  for s in getStudies(store)
    addStudy(mdf, s)
    exportData(s, mdf; kargs...)
  end

  if D == MDFDatasetStore
    exportData(getCalibStudy(store), mdf; kargs...)
  end
end

#########

# generate tar balls and Julia Artifacts.
function makeTarGzip(dir, filename)
  tar_gz = open(filename, write=true)
  tar = GzipCompressorStream(tar_gz)
  Tar.create(dir, tar)
  close(tar)
end

function makeTarGzip(d::DatasetStore, filename)
  makeTarGzip(d.path, filename)
end

function makeTarGzip(d::DatasetStore)
  filename = joinpath(splitpath(d.path)...)*".tar.gz" # this ensures that a trailing / is removed
  makeTarGzip(d.path, filename)
end

function makeTarGzip(path::String)
  filename = joinpath(splitpath(path)...)*".tar.gz" # this ensures that a trailing / is removed
  makeTarGzip(path, filename)
end

function sha256sum(tarball_path)
  return open(tarball_path, "r") do io
      return bytes2hex(sha256(io))
  end
end

function createArtifact(d::DatasetStore, url="https://")
  makeTarGzip(d)
  tarball = joinpath(splitpath(d.path)...)*".tar.gz"

  artifact_toml = joinpath(d.path, "..", "Artifacts.toml")
  tarball_hash = sha256sum(tarball)
  name = splitpath(d.path)[end]

  hash = create_artifact() do artifact_dir
    unpack(tarball, artifact_dir)
  end

  bind_artifact!(artifact_toml, name, hash;
                 download_info=[(url, tarball_hash)],lazy=true, force=true)
  remove_artifact(hash)
end

function createArtifact(path::String, url="https://")
  makeTarGzip(path)
  tarball = joinpath(splitpath(path)...)*".tar.gz"

  artifact_toml = joinpath(path, "..", "Artifacts.toml")
  tarball_hash = sha256sum(tarball)
  name = splitpath(path)[end]

  hash = create_artifact() do artifact_dir
    unpack(tarball, artifact_dir)
  end

  bind_artifact!(artifact_toml, name, hash;
                 download_info=[(url, tarball_hash)],lazy=true, force=true)
  remove_artifact(hash)
end

function validate(d::DatasetStore)
  return all([validate(s) for s in getStudies(d)])
end