text:
struct Normal{T} end
struct Exponential{T} end

# sampler => Dict(seed => rand(LehmerRNG(seed), n))
# if key (sampler) isa Integer, it represents 1:key
const STREAMS = Dict{Any,Dict{Int64,Vector}}(
    UInt64 => Dict(
        0 => [0x45a31efc5a35d971, 0xc6106997913e7a3b, 0x949e7d1a64224226,
              0x233c600f92647349, 0x275e265b37c53f51, 0x7eb1431760d5e0d9,
              0x75a91e49d501684d, 0x2eb2f990c5bd12e0, 0xdf459aadbb8c0b08,
              0xcb81434944438ad0, 0x5385088560aef3b0, 0x0702607d43845765],
        1 => [0xd0e95cf50ea18c53, 0x52313cc6b3bb6eb2, 0xbddb774f2c66c674,
              0x69b5202eb72d59db, 0x761a7311a74fbdf5, 0x7c13c9462281a28d,
              0x60fb5add7f0438e8, 0x8c18ecb2513738a0, 0x9dd0d00932a42118,
              0x6283c9dbcccaa072, 0xfa8f1990220cdb11, 0x15072177ca8d0630],
        Int64(2)^32 =>
        [0xfa0ed1dea67579f2, 0xe88d5e0e5b8b40fe, 0x5ce30167dd0c0c22,
         0x480546a1a865a818, 0x96e8a4ff013c8a92, 0x405d04cb572b978f,
         0x1fabeee4affbf0c3, 0xba2d1f50e67a63d0, 0x565db0bdf8d96d6b,
         0x540858ead6088e6d, 0x14e2efe6ac5775fa, 0x8e0b0f48316d364b],
        typemax(Int64) =>
        [0xe07cb1442060b16b, 0x9f15f9ca1910888d, 0x27d667e3a5597f5e,
         0xe7c43a5819b14e87, 0xbd5d7f453bf3bc1b, 0x7c7998438141ee3f,
         0xf7d425f171d5da47, 0xe1abaee77149b9c0, 0x3f6116840ff765f4,
         0xfd613e850d5b6198, 0x524f389f5079bcf4, 0x6ff20ef5be83190b]),
    123 => Dict(
        0 => [0x72, 0x3c, 0x27, 0x4a, 0x52, 0x5a, 0x4e, 0x61,
              0x09, 0x51, 0x31, 0x66, 0x6d, 0x68, 0x65, 0x1b,
              0x5e, 0x07, 0x28, 0x3a, 0x33, 0x70, 0x6e, 0x35],
        1 => [0x54, 0x33, 0x75, 0x5c, 0x76, 0x0e, 0x69, 0x21,
              0x19, 0x73, 0x12, 0x31, 0x46, 0x38, 0x2d, 0x51,
              0x18, 0x15, 0x76, 0x2d, 0x17, 0x50, 0x4a, 0x1d],
        Int64(2)^32 => [0x73, 0x23, 0x19, 0x13, 0x10, 0x44, 0x51, 0x6c,
                        0x6e, 0x7b, 0x4c, 0x12, 0x19, 0x3e, 0x16, 0x6e,
                        0x06, 0x26, 0x05, 0x7a, 0x13, 0x6d, 0x6e, 0x18],
        typemax(Int64) => [0x6c, 0x0e, 0x5f, 0x08, 0x1c, 0x40, 0x48, 0x41,
                           0x75, 0x19, 0x75, 0x0c, 0x21, 0x52, 0x51, 0x43,
                           0x03, 0x2c, 0x3f, 0x6a, 0x74, 0x27, 0x66, 0x74],
    ),
    # can't have 1:UInt128(2)^100 as a key, it's too big, cf. #35603
    UInt128(2)^100 => Dict(
        0 => [0x007913e7a3b45a31efc5a35d972, 0x00f92647349949e7d1a64224227,
              0x00760d5e0d9275e265b37c53f52, 0x000c5bd12e075a91e49d501684e,
              0x00944438ad0df459aadbb8c0b09, 0x00d438457655385088560aef3b1,
              0x002292725e7bf0412ad4e6167ed, 0x0065e6e00fe22801cd76310dc65,
              0x00329916fdd3b9df5bfe8ce461b, 0x00951b9612719a9585e619de307,
              0x009f94fa7326c9f3ed5bdcadeba, 0x0046c73306dba795fe8c75a9770],
        1 => [0x006b3bb6eb2d0e95cf50ea18c54, 0x00eb72d59dbbddb774f2c66c675,
              0x0062281a28d761a7311a74fbdf6, 0x002513738a060fb5add7f0438e9,
              0x00bcccaa0729dd0d00932a42119, 0x007ca8d0630fa8f1990220cdb12,
              0x0067b7571b73d0c3807eb2437c6, 0x0031b4a02fc678056862932952d,
              0x0097cb44f97b2d9e13fba6ad251, 0x00bf52c23754cfc091b24d9a915,
              0x00debeef59645ddbc8139609c2d, 0x00d455991492f6c1fba560fc650],
        Int64(2)^32 =>
        [0x00e5b8b40fefa0ed1dea67579f3, 0x001a865a8185ce30167dd0c0c23,
         0x00b572b978f96e8a4ff013c8a93, 0x000e67a63d01fabeee4affbf0c4,
         0x00ad6088e6d565db0bdf8d96d6c, 0x008316d364b14e2efe6ac5775fb,
         0x002248fb2185bc6e28653152312, 0x00448742715e8a1d59fe134f43e,
         0x00d6a7b16ed0d3a81f5bdfa84fd, 0x0078499dfa5dce51e6be76c4206,
         0x00e6f5d2d79e834fc489240f705, 0x00fffad736c492e8ec852c85213],
        typemax(Int64) =>
        [0x00a1910888de07cb1442060b16c, 0x00819b14e8727d667e3a5597f5f,
         0x0038141ee3fbd5d7f453bf3bc1c, 0x0077149b9c0f7d425f171d5da48,
         0x0050d5b61983f6116840ff765f5, 0x005be83190b524f389f5079bcf5,
         0x0063a7004d1c355cae530dd93a1, 0x0050aaefc421c91ef1545dcbf51,
         0x004e93aea2baef829b0d3d36503, 0x005cc3461e9a93dd7210c9ab0bf,
         0x009de23a326fd9bcd4fa993b0f4, 0x00aaf1de1730b3d7d6857669166],
    ),
    true => Dict(
        0 => [1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
              0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1],
        1 => [1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0,
              1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1],
        Int64(2)^32 => [0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1,
                        1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0],
        typemax(Int64) => [1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
                           0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1],
    ),
    Float64 => Dict(
        0 =>
        [0.1950648807374728566, 0.0257793115230373626, 0.9055427466847816298,
         0.7734523504688743944, 0.8843643358740858051, 0.0788797171244850492,
         0.5698946304824119568, 0.1859290813601361946, 0.3502633405739192795,
         0.0789272944027068490, 0.3145803238578359639, 0.1485569608098213922,
         0.2545598088968246131, 0.0483571631942767421, 0.0070413465271252917,
         0.0508483589802035673, 0.8724974721884621864, 0.1605102180246753551,
         0.5840743840364566175, 0.4382718269681136202, 0.9528405584114081339,
         0.2329044092861747294, 0.5859153544674560176, 0.8064312206579657971],
        1 =>
        [0.5851946422124185698, 0.0773379345691123099, 0.7166282400543453334,
         0.3203570514066231833, 0.6530930076222578595, 0.2366391513734555918,
         0.7096838914472360926, 0.5577872440804085840, 0.0507900217217578386,
         0.2367818832081209912, 0.9437409715735081139, 0.4456708824294643989,
         0.7636794266904740613, 0.1450714895828306705, 0.0211240395813758752,
         0.1525450769406111462, 0.6174924165653870034, 0.4815306540740260654,
         0.7522231521093702966, 0.3148154809043408608, 0.8585216752342246238,
         0.6987132278585241884, 0.7577460634023684971, 0.4192936619738978354],
        Int64(2)^32 =>
        [0.9262377264309376024, 0.8354629112182574424, 0.1878431925440584571,
         0.3297440126430100094, 0.5402822540569656162, 0.8136704831208338984,
         0.7458235620861592974, 0.8201455119180884878, 0.8556499214817800958,
         0.5217083321266742235, 0.1835695964904275890, 0.6912309580542508325,
         0.4303038831150767241, 0.9418660572220058924, 0.1146544263022086785,
         0.8013346510146608370, 0.6567284985579240342, 0.3401312026411986711,
         0.3199271240192740340, 0.6107096843461274904, 0.3115926468885286127,
         0.1895431852488782543, 0.9098590120021339267, 0.2050781237987520100],
        typemax(Int64) =>
        [0.7932778610948740816, 0.3734837512097641809, 0.4003635844200839066,
         0.2642441753022539696, 0.8435718862417675989, 0.5996737527010649326,
         0.2592634627050232065, 0.7302011895477420466, 0.0679970382392385275,
         0.0777636071926277594, 0.9513238090110549549, 0.1286523286704006618,
         0.3620349797067561326, 0.2187559397428240348, 0.1208698967929713319,
         0.1413011948896074621, 0.5101784014171362180, 0.1411332235862896578,
         0.8650217525819665631, 0.5771692253821305573, 0.7376248001192464709,
         0.1897371938050098627, 0.8431170858467222917, 0.0142466392990996393]
    ),
    Normal{Float64} => Dict(
        0 =>
        [-0.381111861786743722, -0.020452508120591215, +0.610788422210481796,
         -1.385748932245142839, -1.611731486297559135, -0.110517958623616241,
         -0.503001669385000350, +0.265474785013935066, +0.547305897889466042,
         +0.108473227118974030, +0.718753376471714445, -0.282678969833291605,
         +0.736726902332106914, -0.134961030673573013, +0.006949743869390782,
         +0.077725160632003479, +0.510076650626809736, -0.426360569496689379,
         +0.908664368119342147, -0.730524759144574709, -1.232581867613880222,
         +0.398240840524731410, -1.139673658738002970, -0.821968503141728313],
        1 =>
        [-0.532520074864123116, +0.098465514284785005, +0.752886522124523450,
         -0.843537403874254577, -2.013829355631106655, -0.269807641197127135,
         +1.032293472303989157, +0.675566099119190633, +0.082160827543964254,
         +0.246926640359151073, -1.500529147318949708, +0.328632009212124654,
         -1.853198706543207619, -0.337190826546952760, +0.035662516379140363,
         +0.232143558890440915, +0.556345368618102021, -1.027821009268467423,
         +1.206403573149015029, -0.620592199441276415, +0.612308205879786516,
         +1.491394429348988471, -0.675799668973327217, -0.751223710193982930],
        Int64(2)^32 =>
        [+2.804497592250339011, +1.277061645230312958, +0.121477387690437907,
         +0.187076393406817809, +0.627670131300367640, -1.703321215824013413,
         -0.989982760767698200, +2.075029846471020178, -1.649703602248066669,
         -0.531759939161147721, +0.609495986040443971, -0.603631997036122026,
         -0.684174512146213942, +0.534356647282485442, -0.092174031696126188,
         -1.285167816972012433, +0.999411412925283571, -0.499305278581140211,
         -0.091555014119427833, -1.350741201226236088, +0.482633667214938111,
         -0.377021488481488309, +0.463503407362597097, +0.397140231988096948],
        typemax(Int64) =>
        [-1.529449500521834260, -0.425833043072113893, +0.751955071680120102,
         -0.295503514518007215, -0.493166268112920858, -0.488318336729492652,
         -0.221460042280709618, +1.749374475915582039, +0.209670644309441018,
         +0.166809441113434515, +1.422070714069686215, -0.201905699115775966,
         +0.792459370505811722, -0.300645840135806364, +0.220282309568965884,
         +0.117923668733925277, +0.786760475994732755, -0.098886664279309366,
         +1.136538822658988090, -1.629277960475042697, -1.097667207947351953,
         +0.316259702942887966, -1.604310346528319942, -0.027958930823246426],
    ),
    Exponential{Float64} => Dict(
        0 =>
        [+0.290443376756253313, +0.023107801871801649, +0.602445039808046201,
         +0.809080223295992051, +1.000988927033177101, +0.264416567316517359,
         +0.620552542494976045, +0.670911854378504646, +0.088847225724062964,
         +0.242968221532827683, +0.747559288415950429, +0.200756450113355078,
         +1.069994735701830679, +0.189708173540399205, +0.009436464636036371,
         +0.352940169680237725, +0.455343388287083484, +0.560636133492580124,
         +0.124215981573885054, +0.296580109076140352, +2.424871194870999336,
         +0.186103706973448774, +0.858731419298913834, +1.163246417195959559],
        1 =>
        [+0.674990107171162257, +0.186569786854466957, +1.092357077170384105,
         +1.095860857333019078, +3.225480781007138642, +0.435163300108867002,
         +2.820713900366846882, +1.177949909079809343, +0.025211559614314250,
         +0.355336719748536645, +0.378642730871126820, +0.346359637424302036,
         +2.138641751151649562, +0.363542010086324974, +0.015483132528467234,
         +0.937262071676046249, +0.692276643844622619, +0.952454488432565638,
         +0.333481484835768782, +0.483612444263148922, +0.629264342409806110,
         +1.372023120746223457, +0.841369485855095078, +0.438607768727813097],
        Int64(2)^32 =>
        [+4.301903604378438217, +5.798976162863313633, +0.116262999011904108,
         +0.163680985957347869, +1.030481683072774768, +1.518325010610733328,
         +2.054668731968426698, +2.524719717518081552, +1.214564758793303501,
         +0.752544460856171993, +1.040180627988793294, +0.737862246265513999,
         +0.172644234291837201, +0.467531051284808818, +0.105231573151698218,
         +0.366119257230970885, +4.035048035845405501, +1.451422316778351984,
         +0.060772937253374834, +1.337722289946995380, +0.051452552989185357,
         +0.300272614348955136, +0.378059311825467925, +0.293455165778313376],
        typemax(Int64) =>
        [+1.126029828119699872, +0.686811209261761424, +0.509836696167542347,
         +0.464964296843861813, +0.450819900116565198, +0.563226973228172834,
         +0.265664126146503754, +1.963481563365191640, +0.328625588378420153,
         +0.154936598094436634, +4.597690643152912315, +0.039603426460420012,
         +0.764555080732192693, +0.679541058538978282, +0.135508395324274611,
         +0.137243906430860846, +0.053486342196888477, +0.101871384862385714,
         +2.289254085681110773, +2.324958005392129046, +3.492832668884421121,
         +0.126229525545209859, +1.139368981849247842, +0.021547655127562688],
    ),
    Float32 => Dict(
        0 =>
        [0.420698285102844f0, 0.488105177879333f0, 0.267643690109253f0,
         0.784768223762512f0, 0.540994763374329f0, 0.670924305915833f0,
         0.010995507240295f0, 0.477138519287109f0, 0.094086647033691f0,
         0.527673721313477f0, 0.366811752319336f0, 0.033917069435120f0,
         0.760983943939209f0, 0.305844187736511f0, 0.131725788116455f0,
         0.859405279159546f0, 0.611514329910278f0, 0.136226296424866f0,
         0.233490705490112f0, 0.448277354240417f0, 0.584921956062317f0,
         0.622289896011353f0, 0.707746386528015f0, 0.899915337562561f0],
        1 =>
        [0.262094855308533f0, 0.464315652847290f0, 0.802931308746338f0,
         0.354304671287537f0, 0.622984528541565f0, 0.012773156166077f0,
         0.032986640930176f0, 0.431415557861328f0, 0.282259941101074f0,
         0.583021402359009f0, 0.100435376167297f0, 0.101751327514648f0,
         0.282951951026917f0, 0.917532801628113f0, 0.395177364349365f0,
         0.578216075897217f0, 0.834543228149414f0, 0.408678889274597f0,
         0.700472354888916f0, 0.344832062721252f0, 0.754765987396240f0,
         0.866869688034058f0, 0.123239398002625f0, 0.699746251106262f0],
        Int64(2)^32 =>
        [0.917783975601196f0, 0.087920904159546f0, 0.094120264053345f0,
         0.794192314147949f0, 0.472978830337524f0, 0.340562701225281f0,
         0.968284964561462f0, 0.956171035766602f0, 0.698651671409607f0,
         0.066846489906311f0, 0.683287858963013f0, 0.853219389915466f0,
         0.165132641792297f0, 0.122622489929199f0, 0.413703560829163f0,
         0.907442688941956f0, 0.957183361053467f0, 0.961637139320374f0,
         0.845764756202698f0, 0.202137589454651f0, 0.507538318634033f0,
         0.727950215339661f0, 0.565004587173462f0, 0.355084896087646f0],
        typemax(Int64) =>
        [0.755414366722107f0, 0.129167199134827f0, 0.699199438095093f0,
         0.385208964347839f0, 0.904178023338318f0, 0.515083193778992f0,
         0.670723795890808f0, 0.575981140136719f0, 0.932798862457275f0,
         0.713915824890137f0, 0.951078891754150f0, 0.024201750755310f0,
         0.731067657470703f0, 0.875146985054016f0, 0.724588394165039f0,
         0.367073297500610f0, 0.651520013809204f0, 0.460271239280701f0,
         0.208518743515015f0, 0.409237980842590f0, 0.153837561607361f0,
         0.278416395187378f0, 0.801312088966370f0, 0.233442664146423f0],
    ),
    Normal{Float32} => Dict(
        0 =>
        [-0.38111186027527f0, -0.02045250870287f0, +0.61078840494156f0,
         -1.38574898242950f0, -1.61173152923584f0, -0.11051795631647f0,
         -0.50300168991089f0, +0.26547479629517f0, +0.54730588197708f0,
         +0.10847322642803f0, +0.71875339746475f0, -0.28267896175385f0,
         +0.73672688007355f0, -0.13496102392673f0, +0.00694974372163f0,
         +0.07772515714169f0, +0.51007664203644f0, -0.42636057734489f0,
         +0.90866434574127f0, -0.73052477836609f0, -1.23258185386658f0,
         +0.39824083447456f0, -1.13967370986938f0, -0.82196849584579f0],
        1 =>
        [-0.53252005577087f0, +0.09846551716328f0, +0.75288653373718f0,
         -0.84353739023209f0, -2.01382946968079f0, -0.26980763673782f0,
         +1.03229343891144f0, +0.67556607723236f0, +0.08216083049774f0,
         +0.24692663550377f0, -1.50052917003632f0, +0.32863199710846f0,
         -1.85319864749908f0, -0.33719083666801f0, +0.03566251695156f0,
         +0.23214356601238f0, +0.55634534358978f0, -1.02782106399536f0,
         +1.20640361309052f0, -0.62059217691422f0, +0.61230820417404f0,
         +1.49139440059662f0, -0.67579966783524f0, -0.75122368335724f0],
        Int64(2)^32 =>
        [+2.80449748039246f0, +1.27706170082092f0, +0.12147738784552f0,
         +0.18707638978958f0, +0.62767010927200f0, -1.70332121849060f0,
         -0.98998278379440f0, +2.07502985000610f0, -1.64970362186432f0,
         -0.53175991773605f0, +0.60949599742889f0, -0.60363197326660f0,
         -0.68417453765869f0, +0.53435665369034f0, -0.09217403084040f0,
         -1.28516781330109f0, +0.99941140413284f0, -0.49930527806282f0,
         -0.09155501425266f0, -1.35074114799500f0, +0.48263368010521f0,
         -0.37702149152756f0, +0.46350342035294f0, +0.39714023470879f0],
        typemax(Int64) =>
        [-1.52944946289063f0, -0.42583304643631f0, +0.75195509195328f0,
         -0.29550352692604f0, -0.49316626787186f0, -0.48831832408905f0,
         -0.22146004438400f0, +1.74937450885773f0, +0.20967064797878f0,
         +0.16680943965912f0, +1.42207074165344f0, -0.20190569758415f0,
         +0.79245936870575f0, -0.30064582824707f0, +0.22028231620789f0,
         +0.11792366951704f0, +0.78676044940948f0, -0.09888666123152f0,
         +1.13653886318207f0, -1.62927794456482f0, -1.09766721725464f0,
         +0.31625971198082f0, -1.60431039333344f0, -0.02795893140137f0],
    ),
    Exponential{Float32} => Dict(
        0 =>
        [+0.29044339060783f0, +0.02310780249536f0, +0.60244506597519f0,
         +0.80908024311066f0, +1.00098896026611f0, +0.26441657543182f0,
         +0.62055253982544f0, +0.67091184854507f0, +0.08884722739458f0,
         +0.24296821653843f0, +0.74755930900574f0, +0.20075644552708f0,
         +1.06999468803406f0, +0.18970817327499f0, +0.00943646486849f0,
         +0.35294017195702f0, +0.45534339547157f0, +0.56063616275787f0,
         +0.12421598285437f0, +0.29658010601997f0, +2.42487120628357f0,
         +0.18610370159149f0, +0.85873144865036f0, +1.16324639320374f0],
        1 =>
        [+0.67499011754990f0, +0.18656978011131f0, +1.09235703945160f0,
         +1.09586083889008f0, +3.22548079490662f0, +0.43516328930855f0,
         +2.82071399688721f0, +1.17794990539551f0, +0.02521155960858f0,
         +0.35533672571182f0, +0.37864273786545f0, +0.34635964035988f0,
         +2.13864183425903f0, +0.36354202032089f0, +0.01548313256353f0,
         +0.93726205825806f0, +0.69227665662766f0, +0.95245450735092f0,
         +0.33348149061203f0, +0.48361244797707f0, +0.62926435470581f0,
         +1.37202310562134f0, +0.84136950969696f0, +0.43860778212547f0],
        Int64(2)^32 =>
        [+4.30190372467041f0, +5.79897594451904f0, +0.11626300215721f0,
         +0.16368098556995f0, +1.03048169612885f0, +1.51832497119904f0,
         +2.05466866493225f0, +2.52471971511841f0, +1.21456480026245f0,
         +0.75254446268082f0, +1.04018068313599f0, +0.73786222934723f0,
         +0.17264422774315f0, +0.46753105521202f0, +0.10523157566786f0,
         +0.36611926555634f0, +4.03504800796509f0, +1.45142233371735f0,
         +0.06077293679118f0, +1.33772230148315f0, +0.05145255476236f0,
         +0.30027261376381f0, +0.37805929780006f0, +0.29345515370369f0],
        typemax(Int64) =>
        [+1.12602984905243f0, +0.68681120872498f0, +0.50983667373657f0,
         +0.46496430039406f0, +0.45081990957260f0, +0.56322699785233f0,
         +0.26566413044930f0, +1.96348154544830f0, +0.32862558960915f0,
         +0.15493659675121f0, +4.59769058227539f0, +0.03960342705250f0,
         +0.76455509662628f0, +0.67954105138779f0, +0.13550838828087f0,
         +0.13724391162395f0, +0.05348634347320f0, +0.10187138617039f0,
         +2.28925418853760f0, +2.32495808601379f0, +3.49283266067505f0,
         +0.12622952461243f0, +1.13936901092529f0, +0.02154765464365f0],
    ),
    Float16 => Dict(
        0 =>
        Float16[0.360351563, 0.557617188, 0.537109375,
                0.821289063, 0.829101563, 0.211914063,
                0.075195313, 0.718750000, 0.757812500,
                0.703125000, 0.921875000, 0.848632813,
                0.980468750, 0.475585938, 0.097656250,
                0.248046875, 0.525390625, 0.965820313,
                0.755859375, 0.288085938, 0.680664063,
                0.798828125, 0.858398438, 0.106445313],
        1 =>
        Float16[0.081054688, 0.673828125, 0.613281250,
                0.463867188, 0.489257813, 0.637695313,
                0.226562500, 0.156250000, 0.273437500,
                0.111328125, 0.766601563, 0.546875000,
                0.942382813, 0.428710938, 0.292968750,
                0.746093750, 0.578125000, 0.897460938,
                0.269531250, 0.864257813, 0.042968750,
                0.396484375, 0.577148438, 0.321289063],
        Int64(2)^32 =>
        Float16[0.486328125, 0.248046875, 0.033203125,
                0.023437500, 0.642578125, 0.889648438,
                0.190429688, 0.953125000, 0.354492188,
                0.606445313, 0.494140625, 0.573242188,
                0.766601563, 0.523437500, 0.059570313,
                0.770507813, 0.246093750, 0.731445313,
                0.504882813, 0.911132813, 0.753906250,
                0.368164063, 0.517578125, 0.855468750],
        typemax(Int64) =>
        Float16[0.354492188, 0.137695313, 0.841796875,
                0.631835938, 0.026367188, 0.561523438,
                0.569335938, 0.437500000, 0.488281250,
                0.398437500, 0.238281250, 0.260742188,
                0.906250000, 0.204101563, 0.828125000,
                0.064453125, 0.251953125, 0.541992188,
                0.185546875, 0.477539063, 0.237304688,
                0.787109375, 0.348632813, 0.362304688],
    ),
    Normal{Float16} => Dict(
        0 =>
        Float16[-0.381103516, -0.020446777, +0.610839844,
                -1.385742188, -1.611328125, -0.110534668,
                -0.502929688, +0.265380859, +0.547363281,
                +0.108459473, +0.718750000, -0.282714844,
                +0.736816406, -0.135009766, +0.006950378,
                +0.077697754, +0.510253906, -0.426269531,
                +0.908691406, -0.730468750, -1.232421875,
                +0.398193359, -1.139648438, -0.821777344],
        1 =>
        Float16[-0.532714844, +0.098449707, +0.752929688,
                -0.843750000, -2.013671875, -0.269775391,
                +1.032226563, +0.675781250, +0.082153320,
                +0.246948242, -1.500976563, +0.328613281,
                -1.853515625, -0.337158203, +0.035675049,
                +0.232177734, +0.556152344, -1.027343750,
                +1.206054688, -0.620605469, +0.612304688,
                +1.491210938, -0.675781250, -0.751464844],
        Int64(2)^32 =>
        Float16[+2.804687500, +1.277343750, +0.121459961,
                +0.187133789, +0.627441406, -1.703125000,
                -0.989746094, +2.074218750, -1.649414063,
                -0.531738281, +0.609375000, -0.603515625,
                -0.684082031, +0.534179688, -0.092163086,
                -1.285156250, +0.999511719, -0.499267578,
                -0.091552734, -1.350585938, +0.482666016,
                -0.376953125, +0.463623047, +0.397216797],
        typemax(Int64) =>
        Float16[-1.529296875, -0.425781250, +0.751953125,
                -0.295410156, -0.493164063, -0.488281250,
                -0.221435547, +1.749023438, +0.209716797,
                +0.166870117, +1.421875000, -0.201904297,
                +0.792480469, -0.300537109, +0.220336914,
                +0.117919922, +0.786621094, -0.098876953,
                +1.136718750, -1.628906250, -1.097656250,
                +0.316162109, -1.604492188, -0.027954102],
    ),
    Exponential{Float16} => Dict(
        0 =>
        Float16[+0.290527344, +0.023101807, +0.602539063,
                +0.809082031, +1.000976563, +0.264404297,
                +0.620605469, +0.670898438, +0.088867188,
                +0.242919922, +0.747558594, +0.200805664,
                +1.070312500, +0.189697266, +0.009437561,
                +0.353027344, +0.455322266, +0.560546875,
                +0.124206543, +0.296630859, +2.425781250,
                +0.186157227, +0.858886719, +1.163085938],
        1 =>
        Float16[+0.674804688, +0.186523438, +1.092773438,
                +1.095703125, +3.224609375, +0.435058594,
                +2.820312500, +1.177734375, +0.025207520,
                +0.355224609, +0.378662109, +0.346435547,
                +2.138671875, +0.363525391, +0.015480042,
                +0.937500000, +0.692382813, +0.952636719,
                +0.333496094, +0.483642578, +0.629394531,
                +1.372070313, +0.841308594, +0.438720703],
        Int64(2)^32 =>
        Float16[+4.300781250, +5.800781250, +0.116271973,
                +0.163696289, +1.030273438, +1.518554688,
                +2.054687500, +2.525390625, +1.214843750,
                +0.752441406, +1.040039063, +0.737792969,
                +0.172607422, +0.467529297, +0.105224609,
                +0.366210938, +4.035156250, +1.451171875,
                +0.060760498, +1.337890625, +0.051452637,
                +0.300292969, +0.378173828, +0.293457031],
        typemax(Int64) =>
        Float16[+1.125976563, +0.687011719, +0.509765625,
                +0.464843750, +0.450927734, +0.562988281,
                +0.265625000, +1.963867188, +0.328613281,
                +0.154907227, +4.597656250, +0.039611816,
                +0.764648438, +0.679687500, +0.135498047,
                +0.137207031, +0.053497314, +0.101867676,
                +2.289062500, +2.324218750, +3.492187500,
                +0.126220703, +1.139648438, +0.021545410],
    )
)

max_stars_repo_name: rfourquet/StableRNGs

max_issues_repo_name: rfourquet/StableRNGs

max_forks_repo_name: rfourquet/StableRNGs


text:
# Note that this script can accept some limited command-line arguments, run
# `julia build_tarballs.jl --help` to see a usage message.
using BinaryBuilder

name = "COINMumpsBuilder"
version = v"1.6.0"

# Collection of sources required to build COINMumpsBuilder
sources = [
    "https://github.com/coin-or-tools/ThirdParty-Mumps/archive/releases/1.6.0.tar.gz" =>
    "3f2bb7d13333e85a29cd2dadc78a38bbf469bc3920c4c0933a90b7d8b8dc798a",
    "./bundled"
]

# Bash recipe for building across all platforms
script = raw"""
cd $WORKSPACE/srcdir
cd ThirdParty-Mumps-releases-1.6.0/
./get.Mumps
patch -p1 < $WORKSPACE/srcdir/patches/quiet.diff
update_configure_scripts
# temporary fix
for path in ${LD_LIBRARY_PATH//:/ }; do
    for file in $(ls $path/*.la); do
        echo "$file"
        baddir=$(sed -n "s|libdir=||p" $file)
        sed -i~ -e "s|$baddir|'$path'|g" $file
    done
done
mkdir build
cd build/
## STATIC BUILD START
if [ $target = "x86_64-apple-darwin14" ]; then
  export AR=/opt/x86_64-apple-darwin14/bin/x86_64-apple-darwin14-ar
fi
../configure --prefix=$prefix --with-pic --disable-pkg-config --host=${target} --disable-shared --enable-static --enable-dependency-linking lt_cv_deplibs_check_method=pass_all \
--with-metis-lib="-L${prefix}/lib -lcoinmetis" --with-metis-incdir="$prefix/include/coin/ThirdParty" \
--with-blas-lib="-L$prefix/lib -lcoinblas"
## STATIC BUILD END

## DYNAMIC BUILD START
#../configure --prefix=$prefix --with-pic --disable-pkg-config --host=${target} --enable-shared --disable-static --enable-dependency-linking lt_cv_deplibs_check_method=pass_all \
#--with-metis-lib="-L${prefix}/lib -lcoinmetis" --with-metis-incdir="$prefix/include/coin/ThirdParty" \
#--with-blas-lib="-L$prefix/lib -lcoinblas"
## DYNAMIC BUILD END

make -j${nproc}
make install
"""

# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line
platforms = [
    Linux(:i686, libc=:glibc),
    Linux(:x86_64, libc=:glibc),
    Linux(:aarch64, libc=:glibc),
    Linux(:armv7l, libc=:glibc, call_abi=:eabihf),
    Linux(:powerpc64le, libc=:glibc),
    Linux(:i686, libc=:musl),
    Linux(:x86_64, libc=:musl),
    Linux(:aarch64, libc=:musl),
    Linux(:armv7l, libc=:musl, call_abi=:eabihf),
    MacOS(:x86_64),
    Windows(:i686),
    Windows(:x86_64)
]
platforms = expand_gcc_versions(platforms)
# To fix gcc4 bug in Windows
push!(platforms, Windows(:i686,compiler_abi=CompilerABI(:gcc6)))
push!(platforms, Windows(:x86_64,compiler_abi=CompilerABI(:gcc6)))

# The products that we will ensure are always built
products(prefix) = [
    LibraryProduct(prefix, "libcoinmumps", :libcoinmumps)
]

# Dependencies that must be installed before this package can be built
## STATIC BUILD START
dependencies = [
        "https://github.com/JuliaOpt/COINBLASBuilder/releases/download/v1.4.6-1-static/build_COINBLASBuilder.v1.4.6.jl",
        "https://github.com/JuliaOpt/COINMetisBuilder/releases/download/v1.3.5-1-static/build_COINMetisBuilder.v1.3.5.jl"
]
## STATIC BUILD END
## DYNAMIC BUILD START
#dependencies = [
#        "https://github.com/JuliaOpt/COINBLASBuilder/releases/download/v1.4.6-1/build_COINBLASBuilder.v1.4.6.jl",
#        "https://github.com/JuliaOpt/COINMetisBuilder/releases/download/v1.3.5-1/build_COINMetisBuilder.v1.3.5.jl"
#]
## DYNAMIC BUILD END

build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies)

ext: jl


text:
# Auto-generated by contrib/generate_exports.jl. Do not edit!

export a2af,
    a2tf,
    ab,
    ae2hd,
    af2a,
    anp,
    anpm,
    apcg,
    apcg13,
    apci,
    apci13,
    apco,
    apco13,
    apcs,
    apcs13,
    aper,
    aper13,
    apio,
    apio13,
    atcc13,
    atccq,
    atci13,
    atciq,
    atciqn,
    atciqz,
    atco13,
    atic13,
    aticq,
    aticqn,
    atio13,
    atioq,
    atoc13,
    atoi13,
    atoiq,
    bi00,
    bp00,
    bp06,
    bpn2xy,
    c2i00a,
    c2i00b,
    c2i06a,
    c2ibpn,
    c2ixy,
    c2ixys,
    c2s,
    c2t00a,
    c2t00b,
    c2t06a,
    c2tcio,
    c2teqx,
    c2tpe,
    c2txy,
    cal2jd,
    cp,
    cpv,
    cr,
    d2dtf,
    d2tf,
    dat,
    dtdb,
    dtf2d,
    eceq06,
    ecm06,
    ee00,
    ee00a,
    ee00b,
    ee06a,
    eect00,
    eform,
    eo06a,
    eors,
    epb,
    epb2jd,
    epj,
    epj2jd,
    epv00,
    eqec06,
    eqeq94,
    era00,
    fad03,
    fae03,
    faf03,
    faju03,
    fal03,
    falp03,
    fama03,
    fame03,
    fane03,
    faom03,
    fapa03,
    fasa03,
    faur03,
    fave03,
    fk425,
    fk45z,
    fk524,
    fk52h,
    fk54z,
    fk5hip,
    fk5hz,
    fw2m,
    fw2xy,
    g2icrs,
    gc2gd,
    gc2gde,
    gd2gc,
    gd2gce,
    gmst00,
    gmst06,
    gmst82,
    gst00a,
    gst00b,
    gst06,
    gst06a,
    gst94,
    h2fk5,
    hd2ae,
    hd2pa,
    hfk5z,
    icrs2g,
    ir,
    jd2cal,
    jdcalf,
    ld,
    ldn,
    ldsun,
    lteceq,
    ltecm,
    lteqec,
    ltp,
    ltpb,
    ltpecl,
    ltpequ,
    moon98,
    num00a,
    num00b,
    num06a,
    numat,
    nut00a,
    nut00b,
    nut06a,
    nut80,
    nutm80,
    obl06,
    obl80,
    p06e,
    p2pv,
    p2s,
    pap,
    pas,
    pb06,
    pdp,
    pfw06,
    plan94,
    pm,
    pmat00,
    pmat06,
    pmat76,
    pmp,
    pmpx,
    pmsafe,
    pn,
    pn00,
    pn00a,
    pn00b,
    pn06,
    pn06a,
    pnm00a,
    pnm00b,
    pnm06a,
    pnm80,
    pom00,
    ppp,
    ppsp,
    pr00,
    prec76,
    pv2p,
    pv2s,
    pvdpv,
    pvm,
    pvmpv,
    pvppv,
    pvstar,
    pvtob,
    pvu,
    pvup,
    pvxpv,
    pxp,
    refco,
    rm2v,
    rv2m,
    rx,
    rxp,
    rxpv,
    rxr,
    ry,
    rz,
    s00,
    s00a,
    s00b,
    s06,
    s06a,
    s2c,
    s2p,
    s2pv,
    s2xpv,
    sepp,
    seps,
    sp00,
    starpm,
    starpv,
    sxp,
    sxpv,
    taitt,
    taiut1,
    taiutc,
    tcbtdb,
    tcgtt,
    tdbtcb,
    tdbtt,
    tf2a,
    tf2d,
    tpors,
    tporv,
    tpsts,
    tpstv,
    tpxes,
    tpxev,
    tr,
    trxp,
    trxpv,
    tttai,
    tttcg,
    tttdb,
    ttut1,
    ut1tai,
    ut1tt,
    ut1utc,
    utctai,
    utcut1,
    xy06,
    xys00a,
    xys00b,
    xys06a,
    zp,
    zpv,
    zr


text:
@testset "1.3 Miscellaneous" begin
    include("1.3.1 Rational functions.jl")
    include("1.3.2 Algebraic functions.jl")
end

max_stars_repo_path: test/1 Algebraic functions/1.3 Miscellaneous/.jl


text:
import REPL
using REPL.TerminalMenus
TerminalMenus.config(
    scroll = :wrap,
    ctrl_c_interrupt = false,
    cursor = '▶',
    up_arrow = '🔼',
    down_arrow = '🔽',
)

#ごまちゃんが発話できる種類
options = ["goma", "kyu", "kyueeen", "Q", "ℚ", "ℂ", "ℤ", "ℕ"]
menu = RadioMenu(options, pagesize = 4)
message = "Choose your favorite fruit:\n(press `q` or `Ctrl-c` to cancel)"
choice = request(message,menu)

@show choice

if choice != -1
    println("Your favorite fruit is ", options[choice], "!")
else
    println("Menu canceled.")
end

max_stars_repo_name: terasakisatoshi/juliaExer

max_issues_repo_name: terasakisatoshi/juliaExer

max_forks_repo_name: terasakisatoshi/juliaExer


text:
module AdFem

    using SparseArrays
    using LinearAlgebra
    using PyCall
    using PyPlot
    using Parameters
    using Reexport
    using Statistics
    using MAT
    using WriteVTK
    @reexport using ADCME

    pts = @. ([-1/sqrt(3); 1/sqrt(3)] + 1)/2
    np = PyNULL()
    pv = PyNULL()
    LIBMFEM = abspath(joinpath(@__DIR__, "..",  "deps", "MFEM", "build", get_library_name("admfem")))
    LIBMFEM3 = abspath(joinpath(@__DIR__, "..",  "deps", "MFEM3", "build", get_library_name("admfem")))
    libmfem = missing
    libmfem3 = missing
    LIBADFEM = abspath(joinpath(@__DIR__, "..",  "deps", "build", get_library_name("adfem")))
    libadfem = missing

    function __init__()
        copy!(np, pyimport("numpy"))

        if !isfile(LIBMFEM) || !isfile(LIBADFEM) || !isfile(LIBMFEM3)
            precompile_adfem()
        end

        global libmfem = load_library(LIBMFEM)
        global libmfem3 = load_library(LIBMFEM3)
        global libadfem = load_library(LIBADFEM)
        try
            copy!(pv, pyimport("pyvista"))
        catch
            @warn """pyvista installation was not successful. 3D plots functionalities are disabled.
To fix the problem, check why `$(ADCME.get_pip()) install pyvista` or `python -c 'import pyvista'` failed."""
        end
    end

    include("ToolChain.jl")
    include("Struct.jl")
    include("Utils.jl")
    include("Core.jl")
    include("Plasticity.jl")
    include("InvCore.jl")
    include("Viscoelasticity.jl")
    include("Visualization.jl")
    include("Constitutive.jl")
    include("Solver.jl")
    include("MFEM/MFEM.jl")
    include("MFEM/MCore.jl")
    include("MFEM/MVisualize.jl")
    include("MFEM/MUtils.jl")
    include("MFEM/Mechanics.jl")
    include("MFEM/MGeom.jl")
    include("MFEM/MBDM.jl")
    include("MFEM3/MFEM.jl")
    include("MFEM3/MCore.jl")
    include("MFEM3/MVisualize.jl")
    include("pcl.jl")
    include("MFEM3/MUtils.jl")

end


text:
# This file is part of IntegerSequences.
# Copyright Peter Luschny. License is MIT.

(@__DIR__) ∉ LOAD_PATH && push!(LOAD_PATH, (@__DIR__))

module JacobiTheta

using Nemo

export ModuleJacobiTheta
export JacobiTheta3Powers, JacobiTheta4Powers
export L000122, L002448, L004018, L104794, L005875, L213384, L000118, L035016
export L008452, L096727, L000132, L000141, L008451, L000143, L000144, L008453
export L000145, L276285, L276286, L276287, L004402, L004406, L004407, L015128
export L004403, L001934, L004404, L004405, L004408, L004409, L004410, L004411
export L004412, L004413, L004414, L004420, L004421, L004415, L004416, L004417
export L004418, L004419, L004422, L004423, L004424, L004425

"""

The ``q``-expansion of the Jacobi theta functions 3 and 4 raised to the power ``r`` is computed for various values of ``r``.

* JacobiTheta3Powers, JacobiTheta4Powers, L000122, L002448, L004018, L104794, L005875, L213384, L000118, L035016, L008452, L096727, L000132, L000141, L008451, L000143, L000144, L008453, L000145, L276285, L276286, L276287, L004402, L004406, L004407, L015128, L004403, L001934, L004404, L004405, L004408, L004409, L004410, L004411, L004412, L004413, L004414, L004420, L004421, L004415, L004416, L004417, L004418, L004419, L004422, L004423, L004424, L004425
"""
const ModuleJacobiTheta = ""

"""

The ``q``-expansion to length len of the Jacobi theta function raised to the power ``r``, i.e. ``ϑ(q)^r`` where ``ϑ(q) = 1 + ∑_{k ≥ 1} q^{k^2}``. Number of ways of writing ``n`` as a sum of ``r`` squares.
"""
function JacobiTheta3Powers(len::Int, r::Int)
    len ≤ 0 && return fmpz[]
    R, x = PolynomialRing(ZZ, "x")
    e = theta_qexp(r, len, x)
    [fmpz(coeff(e, j)) for j ∈ 0:len-1]
end

"""

Return the ``q``-expansion to length ``len`` of the Jacobi theta function raised to the power ``r``, i.e. ``ϑ(-q)^r`` where ``ϑ(q) = 1 + ∑_{k ≥ 1} q^{k^2} .``
"""
function JacobiTheta4Powers(len::Int, r::Int)
    len ≤ 0 && return fmpz[]
    R, x = PolynomialRing(ZZ, "x")
    e = theta_qexp(r, len, -x)
    [fmpz(coeff(e, j)) for j ∈ 0:len-1]
end

"""

Return the number of ways of writing a nonnegative integer n as a square.
"""
L000122(len::Int) = JacobiTheta3Powers(len, 1)

"""

Return the expansion of Jacobi theta function ``ϑ(-q)``.
"""
L002448(len::Int) = JacobiTheta4Powers(len, 1)

"""

Return the number of ways of writing a nonnegative integer n as a sum of 2 squares.
"""
L004018(len::Int) = JacobiTheta3Powers(len, 2)

"""

Return the expansion of ``ϑ_4(q)^2`` in powers of q.
"""
L104794(len::Int) = JacobiTheta4Powers(len, 2)

"""

Return the number of ways of writing a nonnegative integer n as a sum of 3 squares.
"""
L005875(len::Int) = JacobiTheta3Powers(len, 3)

"""

Return the expansion of ``ϑ_4(q)^3`` in powers of q.
"""
L213384(len::Int) = JacobiTheta4Powers(len, 3)

"""

Number of ways of writing a nonnegative integer n as a sum of 4 squares.
"""
L000118(len::Int) = JacobiTheta3Powers(len, 4)

"""

Return the expansion of ``ϑ_4(q)^4`` in powers of q.
"""
L096727(len::Int) = JacobiTheta4Powers(len, 4)

"""

Return the number of ways of writing a nonnegative integer n as a sum of 5 squares.
"""
L000132(len::Int) = JacobiTheta3Powers(len, 5)

"""

Return the number of ways of writing a nonnegative integer n as a sum of 6 squares.
"""
L000141(len::Int) = JacobiTheta3Powers(len, 6)

"""

Return the nnumber of ways of writing a nonnegative integer n as a sum of 7 squares.
"""
L008451(len::Int) = JacobiTheta3Powers(len, 7)

"""

Return the number of ways of writing a nonnegative integer n as a sum of 8 squares.
"""
L000143(len::Int) = JacobiTheta3Powers(len, 8)

"""

Return the expansion of ``ϑ_4(q)^8`` in powers of q.
"""
L035016(len::Int) = JacobiTheta4Powers(len, 8)

"""

Return the number of ways of writing a nonnegative integer n as a sum of 9 squares.
"""
L008452(len::Int) = JacobiTheta3Powers(len, 9)

"""

Return the number of ways of writing a nonnegative integer n as a sum of 10 squares.
"""
L000144(len::Int) = JacobiTheta3Powers(len, 10)

"""

Return the number of ways of writing a nonnegative integer n as a sum of 11 squares.
"""
L008453(len::Int) = JacobiTheta3Powers(len, 11)

"""

Return the number of ways of writing a nonnegative integer n as a sum of 12 squares.
"""
L000145(len::Int) = JacobiTheta3Powers(len, 12)

"""

Return the number of ways of writing a nonnegative integer n as a sum of 13 squares.
"""
L276285(len::Int) = JacobiTheta3Powers(len, 13)

"""

Return the number of ways of writing a nonnegative integer n as a sum of 14 squares.
"""
L276286(len::Int) = JacobiTheta3Powers(len, 14)

"""

Return the nnumber of ways of writing a nonnegative integer n as a sum of 15 squares.
"""
L276287(len::Int) = JacobiTheta3Powers(len, 15)

"""

Return the expansion of ``1/ϑ_3(q)`` in powers of q.
"""
L004402(len::Int) = JacobiTheta3Powers(len, -1)

"""

Return the expansion of ``1/ϑ_4(q)`` in powers of q.
"""
L015128(len::Int) = JacobiTheta4Powers(len, -1)

"""

Return the expansion of ``1/ϑ_3(q)^2`` in powers of q.
"""
L004403(len::Int) = JacobiTheta3Powers(len, -2)

"""

Return the expansion of ``1/ϑ_4(q)^2`` in powers of q.
"""
L001934(len::Int) = JacobiTheta4Powers(len, -2)

"""

Return the expansion of ``1/ϑ_3(q)^3`` in powers of q.
"""
L004404(len::Int) = JacobiTheta3Powers(len, -3)

"""

Return the expansion of ``1/ϑ_3(q)^4`` in powers of q.
"""
L004405(len::Int) = JacobiTheta3Powers(len, -4)

"""

Return the expansion of ``1/ϑ_3(q)^5`` in powers of q.
"""
L004406(len::Int) = JacobiTheta3Powers(len, -5)

"""

Return the expansion of ``1/ϑ_3(q)^6`` in powers of q.
"""
L004407(len::Int) = JacobiTheta3Powers(len, -6)

"""

Return the expansion of ``1/ϑ_3(q)^7`` in powers of q.
"""
L004408(len::Int) = JacobiTheta3Powers(len, -7)

"""

Return the expansion of ``1/ϑ_3(q)^8`` in powers of q.
"""
L004409(len::Int) = JacobiTheta3Powers(len, -8)

"""

Return the expansion of ``1/ϑ_3(q)^9`` in powers of q.
"""
L004410(len::Int) = JacobiTheta3Powers(len, -9)

"""

Return the expansion of ``1/ϑ_3(q)^{10}`` in powers of q.
"""
L004411(len::Int) = JacobiTheta3Powers(len, -10)

"""

Return the expansion of ``1/ϑ_3(q)^{11}`` in powers of q.
"""
L004412(len::Int) = JacobiTheta3Powers(len, -11)

"""

Return the expansion of ``1/ϑ_3(q)^{12}`` in powers of q.
"""
L004413(len::Int) = JacobiTheta3Powers(len, -12)

"""

Return the expansion of ``1/ϑ_3(q)^{13}`` in powers of q.
"""
L004414(len::Int) = JacobiTheta3Powers(len, -13)

"""

Return the expansion of ``1/ϑ_3(q)^{14}`` in powers of q.
"""
L004415(len::Int) = JacobiTheta3Powers(len, -14)

"""

Return the expansion of ``1/ϑ_3(q)^{15}`` in powers of q.
"""
L004416(len::Int) = JacobiTheta3Powers(len, -15)

"""

Return the expansion of ``1/ϑ_3(q)^{16}`` in powers of q.
"""
L004417(len::Int) = JacobiTheta3Powers(len, -16)

"""

Return the expansion of ``1/ϑ_3(q)^{17}`` in powers of q.
"""
L004418(len::Int) = JacobiTheta3Powers(len, -17)

"""

Return the expansion of ``1/ϑ_3(q)^{18}`` in powers of q.
"""
L004419(len::Int) = JacobiTheta3Powers(len, -18)

"""

Return the expansion of ``1/ϑ_3(q)^{19}`` in powers of q.
"""
L004420(len::Int) = JacobiTheta3Powers(len, -19)

"""

Return the expansion of ``1/ϑ_3(q)^{20}`` in powers of q.
"""
L004421(len::Int) = JacobiTheta3Powers(len, -20)

"""

Return the expansion of ``1/ϑ_3(q)^{21}`` in powers of q.
"""
L004422(len::Int) = JacobiTheta3Powers(len, -21)

"""

Return the expansion of ``1/ϑ_3(q)^{22}`` in powers of q.
"""
L004423(len::Int) = JacobiTheta3Powers(len, -22)

"""

Return the expansion of ``1/ϑ_3(q)^{23}`` in powers of q.
"""
L004424(len::Int) = JacobiTheta3Powers(len, -23)

"""

Return the expansion of ``1/ϑ_3(q)^{24}`` in powers of q.
"""
L004425(len::Int) = JacobiTheta3Powers(len, -24)

#START-TEST-########################################################

using Test, SeqTests

function test()
    @testset "JacobiTheta" begin

        @test JacobiTheta3Powers(0, 1) == fmpz[]
        @test isa(JacobiTheta3Powers(30, 1)[end], fmpz)
        @test isa(JacobiTheta4Powers(30, 1)[end], fmpz)

        @test L035016(999 + 1)[end] == fmpz(-16565884160)
        @test L035016(1000 + 1)[end] == fmpz(18365675328)

        if data_installed()

            L = [
                L000122,
                L002448,
                L004018,
                L104794,
                L005875,
                L213384,
                L000118,
                L035016,
                L008452,
                L096727,
                L000132,
                L000141,
                L008451,
                L000143,
                L000144,
                L008453,
                L000145,
                L276285,
                L276286,
                L276287,
                L004402,
                L004406,
                L004407,
                L015128,
                L004403,
                L001934,
                L004404,
                L004405,
                L004408,
                L004409,
                L004410,
                L004411,
                L004412,
                L004413,
                L004414,
                L004420,
                L004421,
                L004415,
                L004416,
                L004417,
                L004418,
                L004419,
                L004422,
                L004423,
                L004424,
                L004425
            ]

            SeqTest(L, 'L')
        end
    end
end

function demo()
    for n ∈ 1:6
        println(n, ": ", JacobiTheta3Powers(8, n))
    end
    for n ∈ 0:6
        println(-n, ": ", JacobiTheta3Powers(8, -n))
    end
    println(L000143(10))
    println(L035016(10))
end

"""

L000143(100000)
     0.079399 seconds (100.01 k allocations: 2.289 MiB)
L035016(100000)
     0.078311 seconds (100.01 k allocations: 2.289 MiB)
"""
function perf()
    @time L000143(100000)
    @time L035016(100000)
end

function main()
    test()
    demo()
    perf()
end

main()

end # module

max_stars_repo_name: OpenLibMathSeq/Sequences

max_issues_repo_name: OpenLibMathSeq/Sequences


text:
@cenum ConfigFlags begin
    FLAG_VSYNC_HINT         = 0x00000040   # Set to try enabling V-Sync on GPU
    FLAG_FULLSCREEN_MODE    = 0x00000002   # Set to run program in fullscreen
    FLAG_WINDOW_RESIZABLE   = 0x00000004   # Set to allow resizable window
    FLAG_WINDOW_UNDECORATED = 0x00000008   # Set to disable window decoration (frame and buttons)
    FLAG_WINDOW_HIDDEN      = 0x00000080   # Set to hide window
    FLAG_WINDOW_MINIMIZED   = 0x00000200   # Set to minimize window (iconify)
    FLAG_WINDOW_MAXIMIZED   = 0x00000400   # Set to maximize window (expanded to monitor)
    FLAG_WINDOW_UNFOCUSED   = 0x00000800   # Set to window non focused
    FLAG_WINDOW_TOPMOST     = 0x00001000   # Set to window always on top
    FLAG_WINDOW_ALWAYS_RUN  = 0x00000100   # Set to allow windows running while minimized
    FLAG_WINDOW_TRANSPARENT = 0x00000010   # Set to allow transparent framebuffer
    FLAG_WINDOW_HIGHDPI     = 0x00002000   # Set to support HighDPI
    FLAG_MSAA_4X_HINT       = 0x00000020   # Set to try enabling MSAA 4X
    FLAG_INTERLACED_HINT    = 0x00010000   # Set to try enabling interlaced video format (for V3D)
end

@cenum TraceLogLevel begin
    LOG_ALL = 0        # Display all logs
    LOG_TRACE          # Trace logging, intended for internal use only
    LOG_DEBUG          # Debug logging, used for internal debugging, it should be disabled on release builds
    LOG_INFO           # Info logging, used for program execution info
    LOG_WARNING        # Warning logging, used on recoverable failures
    LOG_ERROR          # Error logging, used on unrecoverable failures
    LOG_FATAL          # Fatal logging, used to abort program: exit(EXIT_FAILURE)
    LOG_NONE           # Disable logging
end

@cenum KeyboardKey begin
    KEY_NULL            = 0        # Key: NULL, used for no key pressed
    # Alphanumeric keys
    KEY_APOSTROPHE      = 39       # Key: '
    KEY_COMMA           = 44       # Key: ,
    KEY_MINUS           = 45       # Key: -
    KEY_PERIOD          = 46       # Key: .
    KEY_SLASH           = 47       # Key: /
    KEY_ZERO            = 48       # Key: 0
    KEY_ONE             = 49       # Key: 1
    KEY_TWO             = 50       # Key: 2
    KEY_THREE           = 51       # Key: 3
    KEY_FOUR            = 52       # Key: 4
    KEY_FIVE            = 53       # Key: 5
    KEY_SIX             = 54       # Key: 6
    KEY_SEVEN           = 55       # Key: 7
    KEY_EIGHT           = 56       # Key: 8
    KEY_NINE            = 57       # Key: 9
    KEY_SEMICOLON       = 59       # Key: ;
    KEY_EQUAL           = 61       # Key: =
    KEY_A               = 65       # Key: A | a
    KEY_B               = 66       # Key: B | b
    KEY_C               = 67       # Key: C | c
    KEY_D               = 68       # Key: D | d
    KEY_E               = 69       # Key: E | e
    KEY_F               = 70       # Key: F | f
    KEY_G               = 71       # Key: G | g
    KEY_H               = 72       # Key: H | h
    KEY_I               = 73       # Key: I | i
    KEY_J               = 74       # Key: J | j
    KEY_K               = 75       # Key: K | k
    KEY_L               = 76       # Key: L | l
    KEY_M               = 77       # Key: M | m
    KEY_N               = 78       # Key: N | n
    KEY_O               = 79       # Key: O | o
    KEY_P               = 80       # Key: P | p
    KEY_Q               = 81       # Key: Q | q
    KEY_R               = 82       # Key: R | r
    KEY_S               = 83       # Key: S | s
    KEY_T               = 84       # Key: T | t
    KEY_U               = 85       # Key: U | u
    KEY_V               = 86       # Key: V | v
    KEY_W               = 87       # Key: W | w
    KEY_X               = 88       # Key: X | x
    KEY_Y               = 89       # Key: Y | y
    KEY_Z               = 90       # Key: Z | z
    KEY_LEFT_BRACKET    = 91       # Key: [
    KEY_BACKSLASH       = 92       # Key: '\'
    KEY_RIGHT_BRACKET   = 93       # Key: ]
    KEY_GRAVE           = 96       # Key: `
    # Function keys
    KEY_SPACE           = 32       # Key: Space
    KEY_ESCAPE          = 256      # Key: Esc
    KEY_ENTER           = 257      # Key: Enter
    KEY_TAB             = 258      # Key: Tab
    KEY_BACKSPACE       = 259      # Key: Backspace
    KEY_INSERT          = 260      # Key: Ins
    KEY_DELETE          = 261      # Key: Del
    KEY_RIGHT           = 262      # Key: Cursor right
    KEY_LEFT            = 263      # Key: Cursor left
    KEY_DOWN            = 264      # Key: Cursor down
    KEY_UP              = 265      # Key: Cursor up
    KEY_PAGE_UP         = 266      # Key: Page up
    KEY_PAGE_DOWN       = 267      # Key: Page down
    KEY_HOME            = 268      # Key: Home
    KEY_END             = 269      # Key: End
    KEY_CAPS_LOCK       = 280      # Key: Caps lock
    KEY_SCROLL_LOCK     = 281      # Key: Scroll down
    KEY_NUM_LOCK        = 282      # Key: Num lock
    KEY_PRINT_SCREEN    = 283      # Key: Print screen
    KEY_PAUSE           = 284      # Key: Pause
    KEY_F1              = 290      # Key: F1
    KEY_F2              = 291      # Key: F2
    KEY_F3              = 292      # Key: F3
    KEY_F4              = 293      # Key: F4
    KEY_F5              = 294      # Key: F5
    KEY_F6              = 295      # Key: F6
    KEY_F7              = 296      # Key: F7
    KEY_F8              = 297      # Key: F8
    KEY_F9              = 298      # Key: F9
    KEY_F10             = 299      # Key: F10
    KEY_F11             = 300      # Key: F11
    KEY_F12             = 301      # Key: F12
    KEY_LEFT_SHIFT      = 340      # Key: Shift left
    KEY_LEFT_CONTROL    = 341      # Key: Control left
    KEY_LEFT_ALT        = 342      # Key: Alt left
    KEY_LEFT_SUPER      = 343      # Key: Super left
    KEY_RIGHT_SHIFT     = 344      # Key: Shift right
    KEY_RIGHT_CONTROL   = 345      # Key: Control right
    KEY_RIGHT_ALT       = 346      # Key: Alt right
    KEY_RIGHT_SUPER     = 347      # Key: Super right
    KEY_KB_MENU         = 348      # Key: KB menu
    # Keypad keys
    KEY_KP_0            = 320      # Key: Keypad 0
    KEY_KP_1            = 321      # Key: Keypad 1
    KEY_KP_2            = 322      # Key: Keypad 2
    KEY_KP_3            = 323      # Key: Keypad 3
    KEY_KP_4            = 324      # Key: Keypad 4
    KEY_KP_5            = 325      # Key: Keypad 5
    KEY_KP_6            = 326      # Key: Keypad 6
    KEY_KP_7            = 327      # Key: Keypad 7
    KEY_KP_8            = 328      # Key: Keypad 8
    KEY_KP_9            = 329      # Key: Keypad 9
    KEY_KP_DECIMAL      = 330      # Key: Keypad .
    KEY_KP_DIVIDE       = 331      # Key: Keypad /
    KEY_KP_MULTIPLY     = 332      # Key: Keypad *
    KEY_KP_SUBTRACT     = 333      # Key: Keypad -
    KEY_KP_ADD          = 334      # Key: Keypad +
    KEY_KP_ENTER        = 335      # Key: Keypad Enter
    KEY_KP_EQUAL        = 336      # Key: Keypad =
    # Android key buttons
    KEY_BACK            = 4        # Key: Android back button
    KEY_MENU            = 82       # Key: Android menu button
    KEY_VOLUME_UP       = 24       # Key: Android volume up button
    KEY_VOLUME_DOWN     = 25       # Key: Android volume down button
end

@cenum MouseButton begin
    MOUSE_BUTTON_LEFT    = 0       # Mouse button left
    MOUSE_BUTTON_RIGHT   = 1       # Mouse button right
    MOUSE_BUTTON_MIDDLE  = 2       # Mouse button middle (pressed wheel)
    MOUSE_BUTTON_SIDE    = 3       # Mouse button side (advanced mouse device)
    MOUSE_BUTTON_EXTRA   = 4       # Mouse button extra (advanced mouse device)
    MOUSE_BUTTON_FORWARD = 5       # Mouse button fordward (advanced mouse device)
    MOUSE_BUTTON_BACK    = 6       # Mouse button back (advanced mouse device)
end

const MOUSE_LEFT_BUTTON   = MOUSE_BUTTON_LEFT
const MOUSE_RIGHT_BUTTON  = MOUSE_BUTTON_RIGHT
const MOUSE_MIDDLE_BUTTON =  MOUSE_BUTTON_MIDDLE

@cenum MouseCursor begin
    MOUSE_CURSOR_DEFAULT       = 0     # Default pointer shape
    MOUSE_CURSOR_ARROW         = 1     # Arrow shape
    MOUSE_CURSOR_IBEAM         = 2     # Text writing cursor shape
    MOUSE_CURSOR_CROSSHAIR     = 3     # Cross shape
    MOUSE_CURSOR_POINTING_HAND = 4     # Pointing hand cursor
    MOUSE_CURSOR_RESIZE_EW     = 5     # Horizontal resize/move arrow shape
    MOUSE_CURSOR_RESIZE_NS     = 6     # Vertical resize/move arrow shape
    MOUSE_CURSOR_RESIZE_NWSE   = 7     # Top-left to bottom-right diagonal resize/move arrow shape
    MOUSE_CURSOR_RESIZE_NESW   = 8     # The top-right to bottom-left diagonal resize/move arrow shape
    MOUSE_CURSOR_RESIZE_ALL    = 9     # The omni-directional resize/move cursor shape
    MOUSE_CURSOR_NOT_ALLOWED   = 10    # The operation-not-allowed shape
end

@cenum GamepadButton begin
    GAMEPAD_BUTTON_UNKNOWN = 0         # Unknown button, just for error checking
    GAMEPAD_BUTTON_LEFT_FACE_UP        # Gamepad left DPAD up button
    GAMEPAD_BUTTON_LEFT_FACE_RIGHT     # Gamepad left DPAD right button
    GAMEPAD_BUTTON_LEFT_FACE_DOWN      # Gamepad left DPAD down button
    GAMEPAD_BUTTON_LEFT_FACE_LEFT      # Gamepad left DPAD left button
    GAMEPAD_BUTTON_RIGHT_FACE_UP       # Gamepad right button up (i.e. PS3: Triangle, Xbox: Y)
    GAMEPAD_BUTTON_RIGHT_FACE_RIGHT    # Gamepad right button right (i.e. PS3: Square, Xbox: X)
    GAMEPAD_BUTTON_RIGHT_FACE_DOWN     # Gamepad right button down (i.e. PS3: Cross, Xbox: A)
    GAMEPAD_BUTTON_RIGHT_FACE_LEFT     # Gamepad right button left (i.e. PS3: Circle, Xbox: B)
    GAMEPAD_BUTTON_LEFT_TRIGGER_1      # Gamepad top/back trigger left (first), it could be a trailing button
    GAMEPAD_BUTTON_LEFT_TRIGGER_2      # Gamepad top/back trigger left (second), it could be a trailing button
    GAMEPAD_BUTTON_RIGHT_TRIGGER_1     # Gamepad top/back trigger right (one), it could be a trailing button
    GAMEPAD_BUTTON_RIGHT_TRIGGER_2     # Gamepad top/back trigger right (second), it could be a trailing button
    GAMEPAD_BUTTON_MIDDLE_LEFT         # Gamepad center buttons, left one (i.e. PS3: Select)
    GAMEPAD_BUTTON_MIDDLE              # Gamepad center buttons, middle one (i.e. PS3: PS, Xbox: XBOX)
    GAMEPAD_BUTTON_MIDDLE_RIGHT        # Gamepad center buttons, right one (i.e. PS3: Start)
    GAMEPAD_BUTTON_LEFT_THUMB          # Gamepad joystick pressed button left
    GAMEPAD_BUTTON_RIGHT_THUMB         # Gamepad joystick pressed button right
end

@cenum GamepadAxis begin
    GAMEPAD_AXIS_LEFT_X        = 0     # Gamepad left stick X axis
    GAMEPAD_AXIS_LEFT_Y        = 1     # Gamepad left stick Y axis
    GAMEPAD_AXIS_RIGHT_X       = 2     # Gamepad right stick X axis
    GAMEPAD_AXIS_RIGHT_Y       = 3     # Gamepad right stick Y axis
    GAMEPAD_AXIS_LEFT_TRIGGER  = 4     # Gamepad back trigger left, pressure level: [1..-1]
    GAMEPAD_AXIS_RIGHT_TRIGGER = 5     # Gamepad back trigger right, pressure level: [1..-1]
end

@cenum MaterialMapIndex begin
    MATERIAL_MAP_ALBEDO    = 0     # Albedo material (same as: MATERIAL_MAP_DIFFUSE)
    MATERIAL_MAP_METALNESS         # Metalness material (same as: MATERIAL_MAP_SPECULAR)
    MATERIAL_MAP_NORMAL            # Normal material
    MATERIAL_MAP_ROUGHNESS         # Roughness material
    MATERIAL_MAP_OCCLUSION         # Ambient occlusion material
    MATERIAL_MAP_EMISSION          # Emission material
    MATERIAL_MAP_HEIGHT            # Heightmap material
    MATERIAL_MAP_CUBEMAP           # Cubemap material (NOTE: Uses GL_TEXTURE_CUBE_MAP)
    MATERIAL_MAP_IRRADIANCE        # Irradiance material (NOTE: Uses GL_TEXTURE_CUBE_MAP)
    MATERIAL_MAP_PREFILTER         # Prefilter material (NOTE: Uses GL_TEXTURE_CUBE_MAP)
    MATERIAL_MAP_BRDF              # Brdf material
end

const MATERIAL_MAP_DIFFUSE  = MATERIAL_MAP_ALBEDO
const MATERIAL_MAP_SPECULAR = MATERIAL_MAP_METALNESS

@cenum ShaderLocationIndex begin
    SHADER_LOC_VERTEX_POSITION = 0 # Shader location: vertex attribute: position
    SHADER_LOC_VERTEX_TEXCOORD01   # Shader location: vertex attribute: texcoord01
    SHADER_LOC_VERTEX_TEXCOORD02   # Shader location: vertex attribute: texcoord02
    SHADER_LOC_VERTEX_NORMAL       # Shader location: vertex attribute: normal
    SHADER_LOC_VERTEX_TANGENT      # Shader location: vertex attribute: tangent
    SHADER_LOC_VERTEX_COLOR        # Shader location: vertex attribute: color
    SHADER_LOC_MATRIX_MVP          # Shader location: matrix uniform: model-view-projection
    SHADER_LOC_MATRIX_VIEW         # Shader location: matrix uniform: view (camera transform)
    SHADER_LOC_MATRIX_PROJECTION   # Shader location: matrix uniform: projection
    SHADER_LOC_MATRIX_MODEL        # Shader location: matrix uniform: model (transform)
    SHADER_LOC_MATRIX_NORMAL       # Shader location: matrix uniform: normal
    SHADER_LOC_VECTOR_VIEW         # Shader location: vector uniform: view
    SHADER_LOC_COLOR_DIFFUSE       # Shader location: vector uniform: diffuse color
    SHADER_LOC_COLOR_SPECULAR      # Shader location: vector uniform: specular color
    SHADER_LOC_COLOR_AMBIENT       # Shader location: vector uniform: ambient color
    SHADER_LOC_MAP_ALBEDO          # Shader location: sampler2d texture: albedo (same as: SHADER_LOC_MAP_DIFFUSE)
    SHADER_LOC_MAP_METALNESS       # Shader location: sampler2d texture: metalness (same as: SHADER_LOC_MAP_SPECULAR)
    SHADER_LOC_MAP_NORMAL          # Shader location: sampler2d texture: normal
    SHADER_LOC_MAP_ROUGHNESS       # Shader location: sampler2d texture: roughness
    SHADER_LOC_MAP_OCCLUSION       # Shader location: sampler2d texture: occlusion
    SHADER_LOC_MAP_EMISSION        # Shader location: sampler2d texture: emission
    SHADER_LOC_MAP_HEIGHT          # Shader location: sampler2d texture: height
    SHADER_LOC_MAP_CUBEMAP         # Shader location: samplerCube texture: cubemap
    SHADER_LOC_MAP_IRRADIANCE      # Shader location: samplerCube texture: irradiance
    SHADER_LOC_MAP_PREFILTER       # Shader location: samplerCube texture: prefilter
    SHADER_LOC_MAP_BRDF            # Shader location: sampler2d texture: brdf
end

const SHADER_LOC_MAP_DIFFUSE  = SHADER_LOC_MAP_ALBEDO
const SHADER_LOC_MAP_SPECULAR = SHADER_LOC_MAP_METALNESS

@cenum ShaderUniformDataType begin
    SHADER_UNIFORM_FLOAT = 0       # Shader uniform type: float
    SHADER_UNIFORM_VEC2            # Shader uniform type: vec2 (2 float)
    SHADER_UNIFORM_VEC3            # Shader uniform type: vec3 (3 float)
    SHADER_UNIFORM_VEC4            # Shader uniform type: vec4 (4 float)
    SHADER_UNIFORM_INT             # Shader uniform type: int
    SHADER_UNIFORM_IVEC2           # Shader uniform type: ivec2 (2 int)
    SHADER_UNIFORM_IVEC3           # Shader uniform type: ivec3 (3 int)
    SHADER_UNIFORM_IVEC4           # Shader uniform type: ivec4 (4 int)
    SHADER_UNIFORM_SAMPLER2D       # Shader uniform type: sampler2d
end

@cenum ShaderAttributeDataType begin
    SHADER_ATTRIB_FLOAT = 0        # Shader attribute type: float
    SHADER_ATTRIB_VEC2             # Shader attribute type: vec2 (2 float)
    SHADER_ATTRIB_VEC3             # Shader attribute type: vec3 (3 float)
    SHADER_ATTRIB_VEC4             # Shader attribute type: vec4 (4 float)
end

@cenum PixelFormat begin
    PIXELFORMAT_UNCOMPRESSED_GRAYSCALE = 1 # 8 bit per pixel (no alpha)
    PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA    # 8*2 bpp (2 channels)
    PIXELFORMAT_UNCOMPRESSED_R5G6B5        # 16 bpp
    PIXELFORMAT_UNCOMPRESSED_R8G8B8        # 24 bpp
    PIXELFORMAT_UNCOMPRESSED_R5G5B5A1      # 16 bpp (1 bit alpha)
    PIXELFORMAT_UNCOMPRESSED_R4G4B4A4      # 16 bpp (4 bit alpha)
    PIXELFORMAT_UNCOMPRESSED_R8G8B8A8      # 32 bpp
    PIXELFORMAT_UNCOMPRESSED_R32           # 32 bpp (1 channel - float)
    PIXELFORMAT_UNCOMPRESSED_R32G32B32     # 32*3 bpp (3 channels - float)
    PIXELFORMAT_UNCOMPRESSED_R32G32B32A32  # 32*4 bpp (4 channels - float)
    PIXELFORMAT_COMPRESSED_DXT1_RGB        # 4 bpp (no alpha)
    PIXELFORMAT_COMPRESSED_DXT1_RGBA       # 4 bpp (1 bit alpha)
    PIXELFORMAT_COMPRESSED_DXT3_RGBA       # 8 bpp
    PIXELFORMAT_COMPRESSED_DXT5_RGBA       # 8 bpp
    PIXELFORMAT_COMPRESSED_ETC1_RGB        # 4 bpp
    PIXELFORMAT_COMPRESSED_ETC2_RGB        # 4 bpp
    PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA   # 8 bpp
    PIXELFORMAT_COMPRESSED_PVRT_RGB        # 4 bpp
    PIXELFORMAT_COMPRESSED_PVRT_RGBA       # 4 bpp
    PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA   # 8 bpp
    PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA   # 2 bpp
end

@cenum TextureFilter begin
    TEXTURE_FILTER_POINT = 0               # No filter, just pixel aproximation
    TEXTURE_FILTER_BILINEAR                # Linear filtering
    TEXTURE_FILTER_TRILINEAR               # Trilinear filtering (linear with mipmaps)
    TEXTURE_FILTER_ANISOTROPIC_4X          # Anisotropic filtering 4x
    TEXTURE_FILTER_ANISOTROPIC_8X          # Anisotropic filtering 8x
    TEXTURE_FILTER_ANISOTROPIC_16X         # Anisotropic filtering 16x
end

@cenum TextureWrap begin
    TEXTURE_WRAP_REPEAT = 0                # Repeats texture in tiled mode
    TEXTURE_WRAP_CLAMP                     # Clamps texture to edge pixel in tiled mode
    TEXTURE_WRAP_MIRROR_REPEAT             # Mirrors and repeats the texture in tiled mode
    TEXTURE_WRAP_MIRROR_CLAMP              # Mirrors and clamps to border the texture in tiled mode
end

@cenum CubemapLayout begin
    CUBEMAP_LAYOUT_AUTO_DETECT = 0         # Automatically detect layout type
    CUBEMAP_LAYOUT_LINE_VERTICAL           # Layout is defined by a vertical line with faces
    CUBEMAP_LAYOUT_LINE_HORIZONTAL         # Layout is defined by an horizontal line with faces
    CUBEMAP_LAYOUT_CROSS_THREE_BY_FOUR     # Layout is defined by a 3x4 cross with cubemap faces
    CUBEMAP_LAYOUT_CROSS_FOUR_BY_THREE     # Layout is defined by a 4x3 cross with cubemap faces
    CUBEMAP_LAYOUT_PANORAMA                # Layout is defined by a panorama image (equirectangular map)
end

@cenum FontType begin
    FONT_DEFAULT = 0               # Default font generation, anti-aliased
    FONT_BITMAP                    # Bitmap font generation, no anti-aliasing
    FONT_SDF                       # SDF font generation, requires external shader
end

@cenum BlendMode begin
    BLEND_ALPHA = 0                # Blend textures considering alpha (default)
    BLEND_ADDITIVE                 # Blend textures adding colors
    BLEND_MULTIPLIED               # Blend textures multiplying colors
    BLEND_ADD_COLORS               # Blend textures adding colors (alternative)
    BLEND_SUBTRACT_COLORS          # Blend textures subtracting colors (alternative)
    BLEND_CUSTOM                   # Belnd textures using custom src/dst factors (use rlSetBlendMode())
end

@cenum Gesture begin
    GESTURE_NONE        = 0        # No gesture
    GESTURE_TAP         = 1        # Tap gesture
    GESTURE_DOUBLETAP   = 2        # Double tap gesture
    GESTURE_HOLD        = 4        # Hold gesture
    GESTURE_DRAG        = 8        # Drag gesture
    GESTURE_SWIPE_RIGHT = 16       # Swipe right gesture
    GESTURE_SWIPE_LEFT  = 32       # Swipe left gesture
    GESTURE_SWIPE_UP    = 64       # Swipe up gesture
    GESTURE_SWIPE_DOWN  = 128      # Swipe down gesture
    GESTURE_PINCH_IN    = 256      # Pinch in gesture
    GESTURE_PINCH_OUT   = 512      # Pinch out gesture
end

@cenum CameraMode begin
    CAMERA_CUSTOM = 0              # Custom camera
    CAMERA_FREE                    # Free camera
    CAMERA_ORBITAL                 # Orbital camera
    CAMERA_FIRST_PERSON            # First person camera
    CAMERA_THIRD_PERSON            # Third person camera
end

@cenum CameraProjection begin
    CAMERA_PERSPECTIVE = 0         # Perspective projection
    CAMERA_ORTHOGRAPHIC            # Orthographic projection
end

@cenum NPatchLayout begin
    NPATCH_NINE_PATCH = 0          # Npatch layout: 3x3 tiles
    NPATCH_THREE_PATCH_VERTICAL    # Npatch layout: 1x3 tiles
    NPATCH_THREE_PATCH_HORIZONTAL  # Npatch layout: 3x1 tiles
end

@cenum PhysicsShapeType begin
    PHYSICS_CIRCLE = 0
    PHYSICS_POLYGON
end


text:
export iauPpsp
"""
P-vector plus scaled p-vector.

This function is part of the International Astronomical Union's
SOFA (Standards Of Fundamental Astronomy) software collection.

Status:  vector/matrix support function.

Given:
   a      double[3]     first p-vector
   s      double        scalar (multiplier for b)
   b      double[3]     second p-vector

Returned:
   apsb   double[3]     a + s*b

Note:
   It is permissible for any of a, b and apsb to be the same array.

Called:
   iauSxp       multiply p-vector by scalar
   iauPpp       p-vector plus p-vector

This revision:  2013 June 18

SOFA release 2018-01-30

Copyright (C) 2018 IAU SOFA Board.  See notes at end.
"""

# void iauPpsp(double a[3], double s, double b[3], double apsb[3])
function iauPpsp(a::AbstractVector{<:Real}, s::Real, b::AbstractVector{<:Real})
   apsb = zeros(Float64, 3)
   ccall((:iauPpsp, libsofa_c), Cvoid,
         (Ptr{Cdouble}, Cdouble, Ptr{Cdouble}, Ptr{Cdouble}),
         convert(Array{Float64, 1}, a),
         convert(Float64, s),
         convert(Array{Float64, 1}, b),
         apsb)

   return SVector{3}(apsb)
end


text:
function [ varp ] = lateralSponge(varp,varb,x_loc,x_dist_in,dx,nx,trigpi,latdmpcoef,u_switch)
%UNTITLED2 Summary of this function goes here

%  by default, make the sponging layer 10% of the total domain width
      xwidth=0.1*(nx-1)*dx;

      coef=0.0;

%  if we're within the west sponge zone, then apply damping
        if x_loc <= xwidth
          coef =  0.5*(1.-cos(trigpi*(xwidth-x_loc))/xwidth);
        end

%  if we're within the east sponge zone, then apply damping
        if x_loc >= ((nx-1)*dx-xwidth)
          coef =  0.5*(1.-cos(trigpi*         ...
                       (x_loc-(nx-1)*dx-xwidth))/xwidth);
        end

%  apply sponge to slowly remove perturbations
        if coef > 0.0
          varp = varp - coef*(varp-varb);
        end

end

max_stars_repo_name: jeffreycunn/toy-atmospheric-model

max_issues_repo_name: jeffreycunn/toy-atmospheric-model

max_forks_repo_name: jeffreycunn/toy-atmospheric-model


text:
abstract type Oracle end

struct PoolOracle <: Oracle
    labels::Vector{Symbol}
end

function ask_oracle(oracle::PoolOracle, query_id::Int)
    return oracle.labels[query_id]
end

function initialize_oracle(oracle, labels::Vector{Symbol})::Oracle
    if oracle <: PoolOracle
        return PoolOracle(labels)
    end
    throw(ErrorException("Unknown oracle $(oracle)."))
end


text:
# create a border of a fixed size and fill it with a constant value
using Images, ImageView

pad_top = 25
pad_bottom = 25
pad_color = RGB4{N0f8}(0.5,0.5,0.) # border color

img = load("sample-images/cats-3061372_640.jpg");
img = padarray(img, Fill(pad_color, (pad_top, pad_bottom)))
img = parent(img) # reset indices to start from 1
imshow(img)

# create a border of a fixed size based on a content of an image
using Images, ImageView

pad_top = 25
pad_bottom = 25

img = load("sample-images/cats-3061372_640.jpg");
img = padarray(img, Pad(:reflect, pad_top, pad_bottom))
img = parent(img) # reset indices to start from 1
imshow(img)


text:
using GLFW

function test_mod(mods, name, expected)
    event = JGE.KeyEvent(GLFW.KEY_E, 0, GLFW.PRESS, mods)
    @test JGE.ismod(name, event) == expected
end

mods = ["shift", "ctrl", "alt"]

mod_matrix = [
    false false false;
    true false false;
    false true false;
    true true false;
    false false true;
    true false true;
    false true true;
    true true true
]

for value in 0:(size(mod_matrix)[1] - 1)
    for pair_mod_expected in zip(mods, mod_matrix[value + 1, :])
        m, expected = pair_mod_expected
        test_mod(value, m, expected)
    end
end


text:
using GLFW
using VulkanCore
using VulkanCore.LibVulkan

@assert GLFW.VulkanSupported()

const WIDTH = 800
const HEIGHT = 600

## init GLFW window
GLFW.WindowHint(GLFW.CLIENT_API, GLFW.NO_API)    # not to create an OpenGL context
GLFW.WindowHint(GLFW.RESIZABLE, 0)
window = GLFW.CreateWindow(WIDTH, HEIGHT, "Vulkan")

## init Vulkan
## creating instance
# fill application info
sType = VK_STRUCTURE_TYPE_APPLICATION_INFO
pApplicationName = pointer("Vulkan Instance")
applicationVersion = VK_MAKE_VERSION(1, 0, 0)
pEngineName = pointer("No Engine")
engineVersion = VK_MAKE_VERSION(1, 0, 0)
apiVersion = VK_API_VERSION_1_2
appInfoRef = VkApplicationInfo(
    sType,
    C_NULL,
    pApplicationName,
    applicationVersion,
    pEngineName,
    engineVersion,
    apiVersion,
) |> Ref

# checking for extension support
requiredExtensions = GLFW.GetRequiredInstanceExtensions()

extensionCountRef = Ref(Cuint(0))
vkEnumerateInstanceExtensionProperties(C_NULL, extensionCountRef, C_NULL)
extensions = Vector{VkExtensionProperties}(undef, extensionCountRef[])
vkEnumerateInstanceExtensionProperties(C_NULL, extensionCountRef, extensions)
extensionNames = map(extensions) do extension
    extension.extensionName |> collect |> String |> x -> strip(x, '\0')
end
extensionVersions = [ext.specVersion |> Int for ext in extensions]

@info "available extensions:"
for (ext, ver) in zip(extensionNames, extensionVersions)
    @info "  $ext: $ver"
end
if !all(x->x in extensionNames, requiredExtensions)
    @error "not all required extensions are supported."
end

# using validation layers
requiredLayers = ["VK_LAYER_KHRONOS_validation"]
layerCountRef = Ref(Cuint(0))
vkEnumerateInstanceLayerProperties(layerCountRef, C_NULL)
availableLayers = Vector{VkLayerProperties}(undef, layerCountRef[])
vkEnumerateInstanceLayerProperties(layerCountRef, availableLayers)
availableLayerNames = [strip(String(collect(layer.layerName)), '\0') for layer in availableLayers]
availableLayerDescription = [strip(String(collect(layer.description)), '\0') for layer in availableLayers]
@info "available layers:"
for (name,description) in zip(availableLayerNames, availableLayerDescription)
    @info "  $name: $description"
end
if !all(x->x in availableLayerNames, requiredLayers)
    @error "not all required layers are supported."
end

# add required extensions and layers
enabledExtensionCountRef = Ref(Cuint(length(requiredExtensions)))
ppEnabledExtensionNames = GLFW.GetRequiredInstanceExtensions(enabledExtensionCountRef)
enabledExtensionCount = enabledExtensionCountRef[]

enabledLayerCount = Cuint(length(requiredLayers))
ppEnabledLayerNames = Base.unsafe_convert(Ptr{Cstring}, Base.cconvert(Ptr{Cstring}, requiredLayers))

# create info
sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
flags = UInt32(0)
pApplicationInfo = Base.unsafe_convert(Ptr{VkApplicationInfo}, appInfoRef)
createInfoRef = VkInstanceCreateInfo(
    sType,
    C_NULL,
    flags,
    pApplicationInfo,
    enabledLayerCount,
    ppEnabledLayerNames,
    enabledExtensionCount,
    ppEnabledExtensionNames,
) |> Ref

# create instance
instanceRef = Ref(VkInstance(C_NULL))
result = GC.@preserve appInfoRef requiredLayers vkCreateInstance(createInfoRef, C_NULL, instanceRef)
@assert result == VK_SUCCESS "failed to create instance!"

## main loop
while !GLFW.WindowShouldClose(window)
    GLFW.PollEvents()
end

## cleaning up
vkDestroyInstance(instanceRef[], C_NULL)
GLFW.DestroyWindow(window)

max_stars_repo_name: Gnimuc/Videre

max_issues_repo_name: Gnimuc/Videre

max_forks_repo_name: Gnimuc/Videre


text:
# Compute the Markov blanket of an address specified in rand calls by using a static flow analysis.
function get_markov_blanket(flow, addr)
    addr = unwrap(addr)
    v, check = get_variable_by_address(flow, addr)
    !check && return nothing
    union(get_ancestors(flow, v), get_successors(flow, v))
end

function markov_blankets(flow, addrs)
    d = Dict()
    for k in addrs
        d[k] = get_markov_blanket(flow, k)
    end
    d
end

@inline check_change(st) = st.type == Change
@inline function check_removable(st)
    ex = st.expr
    ex isa Expr &&
    ex.head == :call &&
    (ex.args[1] isa IRTools.Inner.Self ||
    (ex.args[1] isa GlobalRef && ex.args[1].name == :record_cached!))
end

# This pass is a dataflow analysis which determines what deterministic statements can be safely removed. It leaves trace calls and record_cached! calls alone.
function no_change_prune(ir)
    us = IRTools.Inner.usecounts(ir)
    isused(x) = get(us, x, 0) > 0
    for v in reverse(keys(ir))
        if !isused(v) && !check_removable(ir[v])
            if isexpr(ir[v].expr)
                Mjolnir.effectful(Mjolnir.exprtype.((ir,), ir[v].expr.args)...) && continue
                map(v -> v isa Variable && (us[v] -= 1), ir[v].expr.args)
            elseif ir[v].expr isa Variable
                us[ir[v].expr] -= 1
            end
            delete!(ir, v)
        end
    end
    return ir
end

# This pass strips the types from all basic block arguments (and thus, branches).
function strip_types(ir)
    pr = Pipe(ir)
    for (v, st) in pr
        pr[v] = IRTools.Statement(st, type = Any)
    end
    new = IRTools.finish(pr)
    for bb in IRTools.blocks(new)
        at = IRTools.argtypes(bb)
        for (i, a) in enumerate(at)
            at[i] = Any
        end
    end
    new
end

# This pass wraps trace calls.
function trace_wrapper(ir)
    pr = Pipe(ir)
    for (v, st) in pr
        expr = st.expr
        if expr.head == :call && expr.args[1] == trace && expr.args[2] isa QuoteNode
            pr[v] = xcall(self, GlobalRef(parentmodule(@__MODULE__), :trace), expr.args[2 : end]...)
        end
    end
    IRTools.finish(pr)
end

function check_reach(v, ks, flow)
    for k in ks
        k_var, _ = get_variable_by_address(flow, k)
        (k_var in get_ancestors(flow, v) || k_var == v) && return false
    end
    true
end

# This pass inserts the return value of the call before any NoChange call nodes.
function substitute_get_value!(pr, v, st)
    expr = st.expr
    if expr.head == :call && expr.args[1] == trace && expr.args[2] isa QuoteNode
        pr[v] = xcall(GlobalRef(parentmodule(@__MODULE__), :record_cached!), self, expr.args[2])
    end
end

# This pass prunes the IR of any NoChange nodes.
function insert_cache_calls(ir, ks, flow)
    pr = Pipe(ir)
    for (v, st) in pr
        st.type != Change && check_reach(v, ks, flow) && substitute_get_value!(pr, v, st)
    end
    IRTools.finish(pr)
end

# This merges the meta from one piece of IR with the IR from a trace.
function reconstruct_ir(meta, tr)
    ir = IRTools.IR(copy(tr.defs), copy.(tr.blocks), copy(tr.lines), meta)
    ir
end

# Abstract interpretation - diff propagation inference.
@inline function diff_inference(f, type_params, args)
    args = map(args) do a
        create_flip_diff(a)
    end
    tr = _propagate(f, type_params, args)
    argument!(tr, at = 2)
    tr
end

# Full pipeline.
@inline function optimization_pipeline(meta, tr, ks)
    tr = reconstruct_ir(meta, tr)
    flow = flow_analysis(tr)
    tr = insert_cache_calls(tr, ks, flow)
    tr = strip_types(tr)
    tr = trace_wrapper(tr)
    tr = no_change_prune(tr)
    tr = renumber(tr)
    tr
end


text:
module SQL

import SQLite
import DataFrames

import Octo
import .Octo: QueryBuilders
import .QueryBuilders: DefaultArrangement, arrange

include("sql/adapter.jl")
include("sql/connect.jl")
include("sql/prepare.jl")
include("sql/query.jl")
include("sql/execute.jl")
include("sql/arrange.jl")
include("sql/table_from.jl")

end


text:
## ExoplanetsSysSims/src/abc_distance.jl
## (c) 2015 Eric B. Ford

dist_L1_fractional(x::Real, y::Real) =  (x==y==0.0) ? 0.0 : abs( (x-y)*2/(x+y) )
dist_L1_abs(x::Real, y::Real) =  abs(x-y)
dist_L2_fractional(x::Real, y::Real) =  (x==y==0.0) ? 0.0 : abs( (x-y)^2*2/(x^2+y^2) )
dist_L2_abs(x::Real, y::Real) =  (x-y)^2

# Library of functions to convert distance vector into a scalar distance
calc_scalar_distance_sum(d::Vector{Float64}) = sum(d)
calc_scalar_distance_rms(d::Vector{Float64}) = sqrt(sumsq(d))
calc_scalar_distance_max(d::Vector{Float64}) = maximum(d)

# How to combine two distances based on subsets of the full distance vector (should always be greater than either for two pass algorithm to work)
combine_scalar_distances_sum(d1::Float64, d2::Float64) = d1+d2
combine_scalar_distances_rms(d1::Float64, d2::Float64) = sqrt(d1*d1+d2*d2)
combine_scalar_distances_max(d1::Float64, d2::Float64) = max(d1,d2)

# Pick which one to be used
calc_scalar_distance(d::Vector{Float64}) = calc_scalar_distance_sum(d)
combine_scalar_distances(d1::Float64, d2::Float64) = combine_scalar_distances_sum(d1,d2)

# compute supremum of differences between empirical cdfs.
# Borrowed from JuliaStats/HypothesisTests.jl
function ksstats{T<:Real, S<:Real}(x::AbstractVector{T}, y::AbstractVector{S})
    n_x, n_y = length(x), length(y)
    sort_idx = sortperm([x; y])
    pdf_diffs = [ones(n_x)/n_x; -ones(n_y)/n_y][sort_idx]
    cdf_diffs = cumsum(pdf_diffs)
    deltap = maximum(cdf_diffs)
    deltan = -minimum(cdf_diffs)
    delta = max(deltap,deltan)
    (n_x, n_y, deltap, deltan, delta)
end
# weighted version   # WARNING:  Function is untested
function ksstats{T<:Real, S<:Real}(x::AbstractVector{T}, y::AbstractVector{S}, wx::AbstractVector{T}, wy::AbstractVector{T})
    n_x, n_y = length(x), length(y)
    wx .*= 1.0/sum(wx)
    wy .*= 1.0/sum(wy)
    sort_idx = sortperm([x; y])
    pdf_diffs = [wx; -wy][sort_idx]
    cdf_diffs = cumsum(pdf_diffs)
    deltap = maximum(cdf_diffs)
    deltan = -minimum(cdf_diffs)
    delta = max(deltap,deltan)
    (n_x, n_y, deltap, deltan, delta)  # should the first two values returned here be sum(wx) and sum(wy) before normalizing?  For now, we ignore all but the final delta anyway.
end

dist_KS{T<:Real, S<:Real}(x::AbstractVector{T}, y::AbstractVector{S}) = ksstats(x,y)[5]
dist_KS{T<:Real, S<:Real}(x::AbstractVector{T}, y::AbstractVector{S}, wx::AbstractVector{T}, wy::AbstractVector{T}) = ksstats(x,y,wx,wy)[5]

# TODO SCI: IMPORTANT:  Replace this distance function with something well thought out
function calc_distance_vector_demo(summary1::CatalogSummaryStatistics, summary2::CatalogSummaryStatistics, pass::Int64, sim_param::SimParam ; verbose::Bool = false)
  d = Array{Float64}(0)
  if pass == 1
    if verbose
      println("# Summary 1, pass 1: ",summary1)
      println("# Summary 2, pass 1: ",summary2)
    end
    d = zeros(3)
    # Since observed and simulated catalogs can have different summary statistics for the number of planets, prefer detections if avaliable (e.g., after pass2), otherwise use expected (e.g., from pass 1)
    np1 = haskey(summary1.stat,"planets detected") ? summary1.stat["planets detected"] : summary1.stat["expected planets detected"]
    np2 = haskey(summary2.stat,"planets detected") ? summary2.stat["planets detected"] : summary2.stat["expected planets detected"]
    d[1] = dist_L1_abs(np1/summary1.stat["num targets"],np2/summary2.stat["num targets"])    #  Normalize so different statistics weighted appropriately and not dominated by this one
    #println("np1 = ",np1,", np2 = ",np2)
    #println("np1 (normalized) = ",np1/summary1.stat["num targets"],", np2 (normalized) = ",np2/summary2.stat["num targets"],", d[1] = ",d[1])
    #d[2] = dist_L1_abs(summary1.stat["mean log10 P"],summary2.stat["mean log10 P"])
    #d[3] = dist_L1_abs(summary1.stat["mean log10 depth"],summary2.stat["mean log10 depth"])
    #d[4] = dist_L1_abs(summary1.stat["std log10 P"],summary2.stat["std log10 P"])
    #d[5] = dist_L1_abs(summary1.stat["std log10 depth"],summary2.stat["std log10 depth"])
    #d[2] = dist_KS(summary1.stat["P list"], summary2.stat["P list"])
    #d[3] = dist_KS(summary1.stat["depth list"], summary2.stat["depth list"])
    # EDITS for christiansen-single-bin
    #d[2] = dist_KS(summary1.stat["P list"], summary2.stat["P list"],summary1.stat["weight list"],summary2.stat["weight list"])
    #d[3] = dist_KS(summary1.stat["depth list"], summary2.stat["depth list"],summary1.stat["weight list"],summary2.stat["weight list"])
    # END EDITS
  elseif pass == 2
    max_tranets_in_sys = get_int(sim_param,"max_tranets_in_sys")
    d = zeros(max_tranets_in_sys)
    for n in 1:max_tranets_in_sys
      d[n] = n*dist_L1_abs(summary1.stat["num_sys_tranets"][n]/summary1.stat["num targets"],summary2.stat["num_sys_tranets"][n]/summary2.stat["num targets"])
    end
  else
    println("# calc_distance_vector_demo doesn't know what to do for pass= ", pass)
  end
  return d
end

function test_abc_distance(cat_obs::KeplerObsCatalog, cat_phys::KeplerPhysicalCatalog, sim_param::SimParam)
  ss_pass1 = calc_summary_stats_sim_pass_one_demo(cat_obs,cat_phys,sim_param)
  ss_pass2 = calc_summary_stats_sim_pass_two_demo(cat_obs,cat_phys,ss_pass1,sim_param)
  d1 = calc_distance_vector_demo(ss_pass1,ss_pass1, 1, sim_param)
  d2 = calc_distance_vector_demo(ss_pass2,ss_pass2, 2, sim_param)
end


text:
### A Pluto.jl notebook ###
# v0.16.1

using Markdown
using InteractiveUtils

# ╔═╡ 0b30d8f2-3788-11ec-0155-cd3fa7eec623
begin
	import Pkg
	Pkg.add(url = "https://github.com/frankhuettner/RICoverAlg.jl")
	using RICoverAlg
end

# ╔═╡ 5f1dbaf1-c88e-43d8-8039-2c5eeba35f23
md"To use the package, you have to add it from its github url:"

# ╔═╡ 810d16ce-035f-4f60-a19b-e0bff9adbc88
md"First, we define a utility table.  The rows contain the actions, the columns the utility in for each state

👉 number of rows = number of actions

👉 number of columns = number of states"

# ╔═╡ 8432015b-9df7-43cf-afb5-86e4ffac350e
UtilTable = [0   1   0   1;
    		 0   0   1   1;
    		1/2 1/2 1/2 1/2]

# ╔═╡ b85ce32d-6d90-4d32-8fd0-171d42d74912
md"Let's also define the cost of learning parameter."

# ╔═╡ 69ad0d60-17e7-4c17-9f95-91bacf47cc80
λ = 0.4

# ╔═╡ edbb7ffd-7325-4389-9164-4eebcb446160
md"Finally, we need a prior belief over the states of the world."

# ╔═╡ f85781f3-55c1-4575-a837-83ce075c9dd5
g = [0.45, 0.05, 0.05, 0.45]

# ╔═╡ ba5e447b-1e14-417d-ab4f-38f54a638d51
md"Calling the function `risolve(UtilTable, g, λ)` gives the solution."

# ╔═╡ d27bb77b-d681-4262-b67f-239972caf753
result = risolve(UtilTable, g, λ)

# ╔═╡ f5885dd3-cd81-4a6d-85dc-a5bce60c4bb2
result[1][1]

# ╔═╡ Cell order:
# ╟─5f1dbaf1-c88e-43d8-8039-2c5eeba35f23
# ╠═0b30d8f2-3788-11ec-0155-cd3fa7eec623
# ╟─810d16ce-035f-4f60-a19b-e0bff9adbc88
# ╠═8432015b-9df7-43cf-afb5-86e4ffac350e
# ╟─b85ce32d-6d90-4d32-8fd0-171d42d74912
# ╠═69ad0d60-17e7-4c17-9f95-91bacf47cc80
# ╟─edbb7ffd-7325-4389-9164-4eebcb446160
# ╠═f85781f3-55c1-4575-a837-83ce075c9dd5
# ╟─ba5e447b-1e14-417d-ab4f-38f54a638d51
# ╠═d27bb77b-d681-4262-b67f-239972caf753
# ╠═f5885dd3-cd81-4a6d-85dc-a5bce60c4bb2


text:
### A Pluto.jl notebook ###
# v0.12.21

using Markdown
using InteractiveUtils

# ╔═╡ 2466c2a4-90c7-11eb-3f9c-5b87a7a35bb6
begin
	using LinearAlgebra, Statistics, StatsBase
	using NMF
	using Plots, ColorSchemes
end

# ╔═╡ 969b3f50-90bb-11eb-2b67-c784d20c0eb2
function ingredients(path::String)
	# this is from the Julia source code (evalfile in base/loading.jl)
	# but with the modification that it returns the module instead of the last object
	name = Symbol(basename(path))
	m = Module(name)
	Core.eval(m,
        Expr(:toplevel,
             :(eval(x) = $(Expr(:core, :eval))($name, x)),
             :(include(x) = $(Expr(:top, :include))($name, x)),
             :(include(mapexpr::Function, x) = $(Expr(:top, :include))(mapexpr, $name, x)),
             :(include($path))))
	m
end

# ╔═╡ e84220a8-90bb-11eb-2fb8-adb6c87c2faa
const ROOT = "/home/nolln/root/data/seqspace/raw"

# ╔═╡ ce78d71a-917a-11eb-3cdd-b15aad75d147
const SAMPLE = 4

# ╔═╡ 0bb97860-917f-11eb-3dd7-cfd0c7d890cd
begin
	cdfplot(x; kwargs...) = plot(sort(x), range(0,1,length=length(x)); kwargs...)
	cdfplot!(x; kwargs...) = plot!(sort(x), range(0,1,length=length(x)); kwargs...)
end

# ╔═╡ be981c3a-90bb-11eb-3216-6bed955446f5
scRNA = ingredients("../src/scrna.jl").scRNA

# ╔═╡ f5ef8128-90bb-11eb-1f4b-053ed41f5038
begin
	seq = scRNA.process(scRNA.load("$ROOT/rep$SAMPLE"));
	seq = scRNA.filtergene(seq) do gene, _
		sum(gene) >= 1e-2*length(gene) && maximum(gene) > 1
	end
end;

# ╔═╡ 9fdf7a60-91c5-11eb-3de6-471a838376d4
Inference = ingredients("../src/infer.jl").Inference

# ╔═╡ ca2dba38-9184-11eb-1793-f588473daad1
#seq = scRNA.generate(5000,1000);

# ╔═╡ 4f65301e-9186-11eb-1faa-71977e8fb097
let p
	p = cdfplot(
		vec(mean(seq.data,dims=2)),
		xscale=:log10,
		legend=false,
		linewidth=3
	)
	xaxis!("mean expression/cell")
	yaxis!("CDF")
	p
end

# ╔═╡ 005bd1ce-9185-11eb-2b21-d5cbec6adaa4
let p
	cm = ColorSchemes.inferno
	χ  = log.(vec(mean(null.data,dims=2)))
	Z  = maximum(χ)

	p = cdfplot(vec(null.cdf[1,:]),
		alpha=0.05,
		color=get(cm, χ[1]/Z),
		label=""
	)
	for i ∈ sample(2:size(null.cdf,1), 2000; replace=false)
		cdfplot!(vec(null.cdf[i,:]),
			alpha=0.05,
			color=color=get(cm, χ[i]),
			label=""
		)
	end

	xaxis!("theoretical cumalant")
	yaxis!("empirical cumalant")
	title!("simulated")

	p
end

# ╔═╡ 92dd32aa-91c5-11eb-2ddb-81162244af44
N, Z = Inference.sinkhorn_full(float.(seq.data)); N = N*size(seq,2); Z = Z/size(seq,2);

# ╔═╡ 0b84e778-91c6-11eb-295e-017e9b891fd2
r = nnmf(N, 300, verbose=true)

# ╔═╡ 2cac3764-91c6-11eb-39fc-3519e4ef5082
Ñ = r.W*r.H

# ╔═╡ a727a460-91c6-11eb-2211-33a36d4bf469
cor(Ñ[:],N[:])

# ╔═╡ 5197a480-91c8-11eb-0e53-716feab57083
size(Z)

# ╔═╡ 4624c51c-91c6-11eb-1764-0718f223e90c
scatter((Z.*Ñ)[2,:], seq[2,:])

# ╔═╡ 9594926e-91d0-11eb-22de-bdfe3290b19b
function resample(data)
	new = zeros(eltype(data), size(data))
	for g ∈ 1:size(data,1)
		new[g,:] = sample(vec(data[g,:]), size(new,2))
	end
	return new
end

# ╔═╡ aada5fb0-91c3-11eb-2338-91e3968f7769
F = svd(N);

# ╔═╡ cad5ecb4-91d0-11eb-0fcd-df07d605f091
F̂ = svd(resample(N));

# ╔═╡ 98a7f47a-91d1-11eb-20e7-5d8c55c28141
import PyPlot

# ╔═╡ 08a0ec2e-91d1-11eb-3d7b-1d52eef0d4f8
PyPlot.clf(); PyPlot.matshow(Z); PyPlot.clim(0,1e2); PyPlot.colorbar(); PyPlot.gcf()

# ╔═╡ 32698128-91d2-11eb-097c-673f5ba12ec8
II = 3; plot(F.U[:,II]); plot!(F̂.U[:,II], alpha=0.1)

# ╔═╡ b2c2a048-91c3-11eb-1ea8-b59ec3068cc4
plot(F.S/sum(F.S),yscale=:log10,xscale=:log10); plot!(F̂.S/sum(F̂.S),yscale=:log10)

# ╔═╡ c50bbc00-91c3-11eb-1476-bdf3cc711ccd
d=50; s̃ = F.U[:,1:d]*Diagonal(F.S[1:d])*F.Vt[1:d,:]

# ╔═╡ df97e704-91c3-11eb-0c82-bda474df78e2
scatter((Z.*s̃)[2,:], seq[2,:])

# ╔═╡ 0ac3487a-91d2-11eb-3443-393a61806665
corspearman((Z.*s̃)[:], seq[:])

# ╔═╡ 46d9f150-9188-11eb-2a31-05c636ece036
#Z, fits = scRNA.normalize(seq.data; algo=:discrete);

# ╔═╡ 32f72b3e-9189-11eb-224b-652cfa96ef48
#=let p
	cm = ColorSchemes.inferno
	χ  = log.(fits.χ)
	Z  = maximum(χ)

	p = cdfplot(fits.cdf[1],
		alpha=0.05,
		color=get(cm, χ[1]/Z),
		label=""
	)
	for i ∈ sample(2:length(fits.cdf), 2000; replace=false)
		p = cdfplot!(fits.cdf[i],
			alpha=0.05,
			color=get(cm, χ[i]/Z),
			label=""
		)
	end

	xaxis!("theoretical cdf")
	yaxis!("empirical cdf")
	title!("fits")
	p
end=#

# ╔═╡ 6f544b52-9189-11eb-3441-d56a79284d8d
#=let p
	p = scatter(seq.α, fits.α,
		alpha=0.4,
		marker_z=log10.(fits.χ),
		legend=false
	)
	xaxis!("true α")
	yaxis!("estimated α")
	p
end=#

# ╔═╡ 831b028e-9189-11eb-0e67-73495bf432fb
#=let p
	p = scatter(seq.β, fits.β,
		alpha=0.4,
		marker_z=log10.(fits.χ),
		legend=false
	)
	xaxis!("true β")
	yaxis!("estimated β")
	p
end=#

# ╔═╡ bb739f56-9189-11eb-0b6e-bd72dd37a45f
#=let p
	p = scatter(seq.γ,
		fits.γ,
		alpha=0.4,
		marker_z=log10.(fits.χ),
		yscale=:log10,
		xscale=:log10,
		legend=false
	)
	xaxis!("true γ")
	yaxis!("estimated γ",(1e-1,1e5))
	p
end=#

# ╔═╡ 9251bd6c-919b-11eb-31f5-c921186904e9
#=let p
	p = scatter(fits.χ,
		fits.γ,
		marker_z=log10.(fits.M),
		alpha=0.4,
		yscale=:log10,
		xscale=:log10,
		legend=false
	)
	xaxis!("mean expression/cell")
	yaxis!("estimated γ")
end=#

# ╔═╡ edfd6656-918d-11eb-3fbc-0d2d50765d89
#s = seq.data; s₁, s₂ = scRNA.bisect(s);

# ╔═╡ 27bec0d0-918e-11eb-2f82-73cde54d9893
#cor(vec(s₁[:]), vec(s₂[:]))

# ╔═╡ ceb63308-918e-11eb-2be0-ed6fadea7600
#=c = [ let
		ḡ = float.(vec(sum(s₁.data, dims=1)))
		r = nnmf(float.(s₁.data) * Diagonal(1 ./ ḡ),
			k,
			init=:nndsvdar,
			alg=:multmse,
			maxiter=250,
			verbose=true
		)
		s̃ = (r.W*r.H) * Diagonal(ḡ)
		cor(log.(vec(s̃[:].+1e-3)), log.(vec(s₂[:].+1e-3)))
end for k ∈ [2, 5, 25, 50, 75, 100, 200, 300] ]=#

# ╔═╡ 2e41f6c6-9190-11eb-1016-430290dd8b67
#=let
	p = plot([2, 5, 25, 50, 75, 100, 200, 500], c)

	xaxis!("number of components")
	yaxis!("pearson correlation with complement")

	p
end=#

# ╔═╡ 1741edf0-919c-11eb-3501-bb5e40be67fc
#Z2, fits2 = scRNA.normalize(s; algo=:continuous, opt=:greedycd, k=50, δβ¯²=1e0);

# ╔═╡ c92e2f9e-919d-11eb-0c9f-33f59da11a29
#=let p
	cm = ColorSchemes.inferno
	χ  = log.(fits.χ)
	Z  = maximum(χ)

	p = cdfplot(fits2.cdf[1],
		alpha=0.05,
		color=get(cm, χ[1]/Z),
		label=""
	)
	for i ∈ sample(2:length(fits2.cdf), 2000; replace=false)
		p = cdfplot!(fits2.cdf[i],
			alpha=0.05,
			color=get(cm, χ[i]/Z),
			label=""
		)
	end

	xaxis!("theoretical cdf")
	yaxis!("empirical cdf")
	title!("fits")
	p
end=#

# ╔═╡ 7b64a0b6-919d-11eb-3d54-9113d80cd1d7
#=let p
	p = scatter(seq.α, fits2.α,
		alpha=0.4,
		marker_z=log10.(fits2.χ),
		legend=false
	)
	xaxis!("true α")
	yaxis!("estimated α")
	p
end=#

# ╔═╡ 8db73190-919d-11eb-1dc5-31b9ef5b6db3
#=let p
	p = scatter(seq.β, fits2.β,
		alpha=0.4,
		marker_z=log10.(fits2.χ),
		legend=false
	)
	xaxis!("true β")
	yaxis!("estimated β")
	p
end=#

# ╔═╡ a415ff16-919d-11eb-0a12-534402c02a08
#=let p
	p = scatter(seq.γ,
		fits2.γ,
		alpha=0.4,
		marker_z=log10.(fits2.χ),
		yscale=:log10,
		xscale=:log10,
		legend=false
	)
	xaxis!("true γ")
	yaxis!("estimated γ")
	p
end=#

# ╔═╡ 86aed80a-91a0-11eb-04b4-8bcf20b9badc
#s̄ = s ./ sum(s,dims=1);

# ╔═╡ cd74215a-91a0-11eb-0663-f1fd821d0062
#S = log.(vec(mean(s,dims=1))); S = S / mean(S)

# ╔═╡ e6816d60-91af-11eb-0886-b131ab8317de
#c = [corspearman(vec(Z2[i,:]), vec(Z[i,:])) for i in 1:size(Z,1)]

# ╔═╡ f5bbc96a-91af-11eb-1c94-a509691fd535
#scatter(mean(s,dims=2), c, alpha=0.1)

# ╔═╡ 9749a6d6-919e-11eb-3cfe-9b1bf258f3c0
#=let i=100
	p = scatter(Z2[i,:], Z[i,:],
		alpha=0.5,
		marker_z=s[i,:],
		markersize=5*S,
		label=""
	)

	xaxis!("gamma normalized")
	yaxis!("negative binomial normalized")
	p
end=#

# ╔═╡ 1f929770-91a9-11eb-3a82-038cea0bf31a
#F = svd(Z2)

# ╔═╡ 27934ac6-91a9-11eb-07a4-abda0d5a6851
#plot(F.S, xscale=:log10)

# ╔═╡ Cell order:
# ╟─2466c2a4-90c7-11eb-3f9c-5b87a7a35bb6
# ╟─969b3f50-90bb-11eb-2b67-c784d20c0eb2
# ╟─e84220a8-90bb-11eb-2fb8-adb6c87c2faa
# ╟─ce78d71a-917a-11eb-3cdd-b15aad75d147
# ╟─0bb97860-917f-11eb-3dd7-cfd0c7d890cd
# ╠═f5ef8128-90bb-11eb-1f4b-053ed41f5038
# ╠═be981c3a-90bb-11eb-3216-6bed955446f5
# ╠═9fdf7a60-91c5-11eb-3de6-471a838376d4
# ╠═ca2dba38-9184-11eb-1793-f588473daad1
# ╟─4f65301e-9186-11eb-1faa-71977e8fb097
# ╟─005bd1ce-9185-11eb-2b21-d5cbec6adaa4
# ╠═92dd32aa-91c5-11eb-2ddb-81162244af44
# ╠═0b84e778-91c6-11eb-295e-017e9b891fd2
# ╠═2cac3764-91c6-11eb-39fc-3519e4ef5082
# ╠═a727a460-91c6-11eb-2211-33a36d4bf469
# ╠═5197a480-91c8-11eb-0e53-716feab57083
# ╠═4624c51c-91c6-11eb-1764-0718f223e90c
# ╠═9594926e-91d0-11eb-22de-bdfe3290b19b
# ╠═aada5fb0-91c3-11eb-2338-91e3968f7769
# ╠═cad5ecb4-91d0-11eb-0fcd-df07d605f091
# ╠═98a7f47a-91d1-11eb-20e7-5d8c55c28141
# ╠═08a0ec2e-91d1-11eb-3d7b-1d52eef0d4f8
# ╠═32698128-91d2-11eb-097c-673f5ba12ec8
# ╠═b2c2a048-91c3-11eb-1ea8-b59ec3068cc4
# ╠═c50bbc00-91c3-11eb-1476-bdf3cc711ccd
# ╠═df97e704-91c3-11eb-0c82-bda474df78e2
# ╠═0ac3487a-91d2-11eb-3443-393a61806665
# ╠═46d9f150-9188-11eb-2a31-05c636ece036
# ╟─32f72b3e-9189-11eb-224b-652cfa96ef48
# ╟─6f544b52-9189-11eb-3441-d56a79284d8d
# ╟─831b028e-9189-11eb-0e67-73495bf432fb
# ╠═bb739f56-9189-11eb-0b6e-bd72dd37a45f
# ╠═9251bd6c-919b-11eb-31f5-c921186904e9
# ╠═edfd6656-918d-11eb-3fbc-0d2d50765d89
# ╠═27bec0d0-918e-11eb-2f82-73cde54d9893
# ╟─ceb63308-918e-11eb-2be0-ed6fadea7600
# ╟─2e41f6c6-9190-11eb-1016-430290dd8b67
# ╠═1741edf0-919c-11eb-3501-bb5e40be67fc
# ╠═c92e2f9e-919d-11eb-0c9f-33f59da11a29
# ╟─7b64a0b6-919d-11eb-3d54-9113d80cd1d7
# ╠═8db73190-919d-11eb-1dc5-31b9ef5b6db3
# ╠═a415ff16-919d-11eb-0a12-534402c02a08
# ╠═86aed80a-91a0-11eb-04b4-8bcf20b9badc
# ╠═cd74215a-91a0-11eb-0663-f1fd821d0062
# ╠═e6816d60-91af-11eb-0886-b131ab8317de
# ╠═f5bbc96a-91af-11eb-1c94-a509691fd535
# ╠═9749a6d6-919e-11eb-3cfe-9b1bf258f3c0
# ╠═1f929770-91a9-11eb-3a82-038cea0bf31a
# ╠═27934ac6-91a9-11eb-07a4-abda0d5a6851

max_stars_repo_name: nnoll/seqspace

max_issues_repo_name: nnoll/seqspace

max_forks_repo_name: nnoll/seqspace


text:
"""
    nitems(xs) -> n::Integer

Count number of items in `xs`.  Consume `xs` if necessary.

# Examples
```jldoctest
julia> using DataTools, Transducers

julia> nitems(1:10)
10

julia> 1:10 |> Filter(isodd) |> Map(inv) |> nitems
5
```
"""
nitems
nitems(xs) =
    if IteratorSize(xs) isa Union{HasLength, HasShape}
        length(xs)
    else
        xf, coll = extract_transducer(xs)
        _nitems(_pop_innermost_maplikes(xf), coll)
    end

_pop_innermost_maplikes(xf) = xf
_pop_innermost_maplikes(::Union{Map,MapSplat,Scan}) = IdentityTransducer()
function _pop_innermost_maplikes(xf::Composition)
    inner = _pop_innermost_maplikes(xf.inner)
    if inner isa IdentityTransducer
        return _pop_innermost_maplikes(xf.outer)
    else
        opcompose(xf.outer, inner)
    end
end

_nitems(::IdentityTransducer, xs) = _nitems(xs)
_nitems(xf, xs) = xs |> xf |> _nitems

_nitems(xs) =
    if IteratorSize(xs) isa Union{HasLength, HasShape}
        length(xs)
    else
        foldl(inc1, IdentityTransducer(), xs)
    end
# TODO: optimization for `Cat`.

"""
    firstitem(xs)

Get the first item of `xs`.  Consume `xs` if necessary.

# Examples
```jldoctest
julia> using DataTools, Transducers

julia> firstitem(3:7)
3

julia> 3:7 |> Map(x -> x + 1) |> Filter(isodd) |> firstitem
5
```
"""
firstitem
firstitem(xs::AbstractArray) = first(xs)
firstitem(xs) = foldl(right, Take(1), xs)

"""
    lastitem(xs)

Get the last item of `xs`.  Consume `xs` if necessary.

# Examples
```jldoctest
julia> using DataTools, Transducers

julia> lastitem(3:7)
7

julia> 3:7 |> Map(x -> x + 1) |> Filter(isodd) |> lastitem
7
```
"""
lastitem
lastitem(xs::AbstractArray) = last(xs)
lastitem(xs) = foldl(right, Map(identity), xs)

"""
    firstitems(xs, n::Integer)
    firstitems(n::Integer) -> xs -> firstitems(xs, n)

Get the first `n` items of `xs`.  Consume `xs` if necessary.
"""
firstitems
firstitems(n::Integer) = xs -> firstitems(xs, n)
firstitems(xs, n::Integer) = collect(Take(n), xs)
firstitems(xs::AbstractArray, n::Integer) = view(xs, firstindex(xs):firstindex(xs)+n-1)

"""
    lastitems(xs, n::Integer)
    lastitems(n::Integer) -> xs -> lastitems(xs, n)

Get the last `n` items of `xs`.  Consume `xs` if necessary.
"""
lastitems
lastitems(n::Integer) = xs -> lastitems(xs, n)
lastitems(xs, n::Integer) = collect(TakeLast(n), xs)
lastitems(xs::AbstractArray, n::Integer) = view(xs, lastindex(xs)-n+1:lastindex(xs))