text:
module Rhmc
    import ..AlgRemez:AlgRemez_coeffs,calc_coefficients

    const coeffs_12 = AlgRemez_coeffs(35.76877880344718, [-2.611603580931762e-6, -2.8381078304162547e-5, -0.00024575851782184877, -0.0020470080999742007, -0.016923799105426088, -0.14034361960343106, -1.1877898203825932, -10.955212949978659, -146.07789284928893, -14714.341373866839], [0.00023220051347978252, 0.0014679843480651033, 0.006577084315568452, 0.027426964178005095, 0.11250019513122003, 0.46049080638938455, 1.8988299965694169, 8.104664281763002, 40.29762890763353, 497.70654517555414], 10)
    const coeffs_m12 = AlgRemez_coeffs(0.027957342505180133, [0.009504168034266293, 0.014392806670277538, 0.02668521749757119, 0.05270932006455869, 0.10589384745339038, 0.2139495082299973, 0.4353956294494188, 0.9089955204708765, 2.107201294600078, 7.749985438494519], [5.143593197266517e-5, 0.0006352731089632578, 0.003158674944452018, 0.013481986300116959, 0.055592857978478315, 0.22755516086118974, 0.9333880277034011, 3.892302237847687, 17.438878032822647, 110.24954086601954], 10)
    const coeffs_14 = AlgRemez_coeffs(6.9461071718499525, [-3.7385105377001425e-6, -1.7764883979837546e-5, -6.334438533952787e-5, -0.00021317868898123004, -0.0007061292823812292, -0.0023271447494456277, -0.007658442853216887, -0.025215367727471134, -0.08325492911813415, -0.27706279011926743, -0.9413396741768589, -3.376769295570277, -14.000699219260555, -87.48968373506541, -2438.159453743938], [7.533204879983615e-5, 0.0004155648337491737, 0.001355472748322587, 0.0038120901090773723, 0.010182414902576235, 0.02668386113490887, 0.06943317053167551, 0.18025949646037842, 0.46811809693900475, 1.219485561990294, 3.205950452609407, 8.636487104246942, 24.866247747939997, 87.21468047228943, 671.5034010759199], 15)
    const coeffs_m14 = AlgRemez_coeffs(0.14396552993778106, [0.00034605541183977854, 0.0007361352806089118, 0.0014491361385218552, 0.002897390997668544, 0.005861553385743302, 0.011923530079141716, 0.0243152683972108, 0.04966483224890658, 0.10166850937810712, 0.20917319384688998, 0.4358756590644266, 0.9388526693245018, 2.2065131459490663, 6.583620229613641, 42.16178846519866], [3.8123410780916776e-5, 0.0002935285649316097, 0.0010295079603283045, 0.002964168149734324, 0.007985151479544388, 0.020992458457826137, 0.054687054756901776, 0.14201748314340246, 0.3686998563362629, 0.959381398013239, 2.5141383694277666, 6.715476095132465, 18.886399620855748, 61.602902654298305, 339.8288033824946], 15)
    const coeffs_18 =AlgRemez_coeffs(2.6226563721874356, [-5.960771208125207e-6, -2.365926748832181e-5, -7.312974957271435e-5, -0.00021647258378734637, -0.0006342614065525487, -0.0018530026882076763, -0.005410134459579222, -0.01580639454625644, -0.04630025630383474, -0.13658135694721724, -0.4103890831099445, -1.2939417075231405, -4.636609634886856, -23.781760392176484, -426.7735702750801], [6.511406585080085e-5, 0.0003827736362029256, 0.001267715019499123, 0.003583090268588116, 0.009587354346137916, 0.02513865988838697, 0.06541997845298224, 0.169826364132841, 0.4409229237078518, 1.1481048390885387, 3.015181840776192, 8.102022022873221, 23.168853584928378, 79.54719981908272, 550.2916347706022], 15)
    const coeffs_m18 = AlgRemez_coeffs(0.3812928032069815, [5.704553583093206e-5, 0.00015212625565764492, 0.000349624141431336, 0.0007978804843345692, 0.0018271691389798897, 0.004194095333537474, 0.009639799649923194, 0.022183627514153276, 0.05116785778935707, 0.11868662341141359, 0.2793062781945737, 0.6824916959670321, 1.8418776768771283, 6.536228531781246, 56.90662030012766], [4.652078712894077e-5, 0.0003218215104770888, 0.0011049316663925537, 0.003159705062233523, 0.00849036686736275, 0.02229761527729769, 0.05806003413186596, 0.15074220148748674, 0.39131776875161906, 1.018351818022971, 2.6701839814977193, 7.144670683970085, 20.193812967613667, 66.8802591890845, 393.15622001947446], 15)

    const coneffs_12_n15 = AlgRemez_coeffs(52.801530615011785, [-6.603122250408879e-7, -4.385050932934162e-6, -2.0643603407379996e-5, -8.956905281940202e-5, -0.00037893462099888793, -0.0015892755651349718, -0.006647330899525596, -0.027809825699088738, -0.11674098552484793, -0.49492401946519393, -2.1537889443543996, -10.04004845875417, -56.31414203731785, -541.0537188024954, -47896.82148291968], [9.76789330722235e-5, 0.0004861285762563459, 0.0015447925188979874, 0.0043078364853888105, 0.011474686157071166, 0.03004933652397656, 0.07819887457469368, 0.20311391670879247, 0.5278790951523255, 1.3769550228941574, 3.6292670454376412, 9.835734487685084, 28.774699349047975, 106.22558098021766, 1108.8405448985493], 15)
    const coneffs_m12_n15 =  AlgRemez_coeffs(0.018938844922720747, [0.006232875919569935, 0.007671885966613157, 0.010882179000141433, 0.016605126881131888, 0.02616286350978532, 0.04176562692239934, 0.06703080125283097, 0.10785465346597474, 0.17392670732092233, 0.28161086985411626, 0.46047137387370596, 0.772252892886211, 1.3840926887668725, 2.9688778021493913, 11.07305624880225], [2.308717887146002e-5, 0.0002409965637633696, 0.000889670459783518, 0.0026027542764653425, 0.007053765864978664, 0.018591747424104358, 0.04849595340124775, 0.1260376463356921, 0.327370440293837, 0.8519322874091946, 2.2309978372893666, 5.942658243141148, 16.571804748421712, 52.66096512396873, 262.08312473142433], 15)

    const coeffs_14_n10 = AlgRemez_coeffs(5.7165557622098175, [-1.1472527436322903e-5, -8.22437195900441e-5, -0.0004911917249478209, -0.0028595740550169564, -0.01657546771377983, -0.09632764566721617, -0.5684080282956644, -3.574637513226843, -29.402805614736042, -910.454747964212], [0.00017585352463504747, 0.0012116676043259563, 0.005511731061457466, 0.023034355065820862, 0.09439559579370578, 0.38561054626048247, 1.5842943313284588, 6.695935386170518, 32.015219356384215, 297.1675517580863], 10)
    const coeffs_m14_n10 = AlgRemez_coeffs(0.17493050738884694, [0.000659835331355923, 0.0018359285824308825, 0.0051025759090143645, 0.014493338675151415, 0.04146036428067062, 0.1190535368426458, 0.3449286017982327, 1.0347965655277906, 3.585219290905995, 23.743072811520367], [8.614668677164346e-5, 0.0007996196969643771, 0.0038232149092825908, 0.01615861364506301, 0.06638822575850153, 0.2711990933978193, 1.1113834065181245, 4.644638810303384, 21.127906621091135, 145.57570030585526], 10)

    const coeffs_m18_n10 = AlgRemez_coeffs(2.3792132499634393, [-1.6178331673230056e-5, -9.324673262980408e-5, -0.0004616164445402523, -0.0022470840473836217, -0.01091397032788275, -0.05314702608352868, -0.26225649448725546, -1.3670670699683314, -8.966025770950466, -176.1213306168453], [0.00015069584886010342, 0.0010969629890608236, 0.005038625333107273, 0.021097078414511326, 0.0864633632847519, 0.35303065630397845, 1.4486843270648686, 6.09968682387749, 28.716462343100822, 241.67613686838126], 10)
    const coeffs_18_n10 = AlgRemez_coeffs(0.4203070069550793, [0.00012205466614334875, 0.0004400966659764438, 0.0014872525305126727, 0.005058114989269569, 0.017260926270113545, 0.05909197271336461, 0.20435471009883857, 0.7359818587930066, 3.136603644754106, 28.83640562962562], [0.0001059268835215699, 0.0008914747121053526, 0.004196936783670219, 0.017671206571184022, 0.07251494889428817, 0.29607916032240045, 1.2134381593989532, 5.080750861110906, 23.33715928002066, 169.8786011269988], 10)

    const coeffs_316_n10 = AlgRemez_coeffs(3.6809859856076006, [-1.4492439436302e-5, -9.325476513375239e-5, -0.0005071773835707172, -0.0026999592253987474, -0.014325236111130017, -0.07620155177935224, -0.41114554274869747, -2.35339815434199, -17.267065062531614, -422.4465412221929], [0.00016303402995984946, 0.0011532592270673625, 0.0052705350023899665, 0.022045664212880994, 0.0903433419964063, 0.36894937239787706, 1.5148499066294283, 6.3897804653772265, 30.306897030377673, 267.14586644977305], 10)
    const coeffs_m316_n10 =AlgRemez_coeffs(0.27166634263480777, [0.00030127966033026253, 0.0009568206736816092, 0.002933718947418554, 0.009119086793578451, 0.028492150876835938, 0.08933146506111686, 0.28275207514646944, 0.9292775534445537, 3.568717153874218, 27.75108312820713], [9.582779752578782e-5, 0.0008446922155818269, 0.004006397424561391, 0.016899364014855124, 0.06938621370628821, 0.2833634381271653, 1.1612260693439331, 4.857191914747077, 22.197958099237212, 157.02243271729554], 10)

    const coeffs_316_n15 = AlgRemez_coeffs(4.2601351799946645, [-5.023302802829547e-6, -2.1843311323189485e-5, -7.254415803782998e-5, -0.0002289965679798019, -0.0007134236414181523, -0.0022137164653857557, -0.006861858446079219, -0.02128182783145359, -0.06618296999948652, -0.207357120165794, -0.6624861478137918, -2.227666341673426, -8.583213356909058, -48.53180515400818, -1076.3618464670292], [7.014496443573226e-5, 0.00039896918707646683, 0.0013110417415338306, 0.0036960849688970486, 0.009880823466054303, 0.02590035710683382, 0.06739735489315007, 0.1749645841058223, 0.45430953626678655, 1.1832196715749264, 3.10894106240096, 8.364243408717298, 23.998297315757416, 83.25209805059654, 605.9438836424484], 15)
    const coeffs_m316_n15 = AlgRemez_coeffs(0.2347343353553519, [0.00014920674448005303, 0.0003563945408705788, 0.000758549665008001, 0.0016206595372869222, 0.0034885648102461727, 0.007538469145878805, 0.016320652512563715, 0.03538372896378343, 0.07688666469222608, 0.1679598441650826, 0.3719256994781029, 0.8531787934463007, 2.1481488833037776, 6.9844905769574215, 51.96265478033731], [4.224813665271006e-5, 0.00030749975795734996, 0.0010667423468910398, 0.0030606474189069427, 0.008234314992201796, 0.02163588099065754, 0.05634924639787175, 0.14631532507468242, 0.3798368651200859, 0.9884033604017544, 2.5908771761735383, 6.926247695988255, 19.52645685411185, 64.16535619602493, 364.9584857007813], 15)

    const coeffs_116_n10 = AlgRemez_coeffs(1.5415518868736153, [-1.3479430121943058e-5, -6.94201538082298e-5, -0.0003126661939194834, -0.0013916886233759954, -0.006188076237322275, -0.027589016753023186, -0.1245324898468633, -0.5914596709482897, -3.4742286716222375, -55.54678127697615], [0.00013882712073814147, 0.0010427057329816902, 0.004815645332230554, 0.020186910321409287, 0.0827478002270612, 0.3378178395072549, 1.3856209433222577, 5.824639577289666, 27.23321780251678, 219.83080818097415], 10)
    const coeffs_m116_n10 = AlgRemez_coeffs(0.6486969452764099, [3.700042842098551e-5, 0.00015079448163203167, 0.0005611926716449521, 0.0020879435883160474, 0.0077820860771356136, 0.029091606762512965, 0.10993281201125081, 0.4340071720814183, 2.0553558161578303, 22.51375139207575], [0.00011645319512688589, 0.0009400284676471159, 0.004395121734195312, 0.018475471320908106, 0.07578048583029384, 0.30937378310665936, 1.2681484978337598, 5.316006107979378, 24.551509779077374, 184.40200923195147], 10)

    const coeffs_116_n15 = AlgRemez_coeffs(1.6185000680192376, [-5.275675561552804e-6, -1.905943830174897e-5, -5.478386501649487e-5, -0.00015202846127429466, -0.0004188910583023452, -0.0011522244219551656, -0.0031687543411440307, -0.008721356054902667, -0.024063908877878376, -0.06684019299723166, -0.1889040831737245, -0.5586308875508903, -1.862986712921942, -8.688215410720257, -127.95388494297556], [6.023769511309328e-5, 0.0003669695054114907, 0.0012254661358547714, 0.0034730288868307802, 0.00930178587200822, 0.02439813812025899, 0.06349925407787103, 0.16483979007187546, 0.4279439408590773, 1.1140995783995267, 2.9245453049405072, 7.849370085647775, 22.3756796801671, 76.0768845108769, 502.52795266083274], 15)
    const coeffs_m116_n15 =AlgRemez_coeffs(0.6178560135767099, [1.6310151533358196e-5, 4.832257950125254e-5, 0.00011977943286380154, 0.00029186384567718237, 0.0007109672662139922, 0.0017334632661060681, 0.004229776095431311, 0.010332011458502688, 0.025297423528509576, 0.06230869743700897, 0.15584518249535737, 0.4057262213366748, 1.174289038326619, 4.555909744162507, 46.80220939431267], [5.094243984727753e-5, 0.0003365016872679626, 0.0011440993241734155, 0.00326140820481996, 0.008753497494722783, 0.022978197367937252, 0.059820919414372856, 0.15530230891969457, 0.4031543420747268, 1.0492603933061206, 2.7521596768893435, 7.371087553308721, 20.89001013654598, 69.76056490387172, 424.9830600579467], 15)

    const coeffs_38_n10 = AlgRemez_coeffs(14.032828673577047, [-5.930471386844274e-6, -5.249034334202079e-5, -0.00037766559307773336, -0.0026295890024527822, -0.018198590793797723, -0.12629023185141475, -0.8919733058167283, -6.783663999961085, -70.6380847108092, -3725.110827418723], [0.00020298654720113192, 0.0013351272311909414, 0.006023489042020999, 0.02513922675688908, 0.10305054546222052, 0.42131759133882224, 1.733786698287018, 7.360926272951278, 35.83579250165611, 376.4480662247984], 10)
    const coeffs_m38_n10 = AlgRemez_coeffs(0.07126147003297621, [0.002659984067675914, 0.005566149503394092, 0.012669205231737415, 0.030026900325213806, 0.07199470450611001, 0.1734151948594954, 0.4210503400166998, 1.0533219869109964, 2.9797791991044296, 14.5648052061407], [6.800406828152703e-5, 0.0007143695789291371, 0.0034778231775083363, 0.01476536878803651, 0.060761763871882986, 0.248421780643415, 1.0183288550426342, 4.250028483725888, 19.17420257930374, 126.11673213315908], 10)

    const coeffs_58_n10 = AlgRemez_coeffs(97.26497431269344, [-1.007469384641391e-6, -1.3386535465427254e-5, -0.00013942426924235733, -0.001389817230580669, -0.013736158506036026, -0.13623801102629404, -1.3835325478601752, -15.527236289001818, -268.88390324035515, -62261.283349000536], [0.0002636099164974018, 0.0016109320470394626, 0.007175997589553093, 0.0299144352285052, 0.12282482017026194, 0.5035121167155298, 2.081333558150099, 8.93903213958087, 45.559156297451935, 703.5181978030724], 10)
    const coeffs_m58_n10 =AlgRemez_coeffs(0.010281193277090048, [0.03182419183885205, 0.03277203765655622, 0.049159012643237764, 0.08079714113313465, 0.1359466247564687, 0.2303472367124537, 0.3929036494259198, 0.684957768483517, 1.3049796445178938, 3.667738443775162], [3.638853988417498e-5, 0.0005619068060185254, 0.00286384472057624, 0.012299806486930154, 0.05084286782807114, 0.20842692840512883, 0.8557741372835946, 3.567448244027953, 15.89142139610864, 97.11319035394607], 10)

    const coeffs_516_n15 =AlgRemez_coeffs(11.385541027213957, [-2.5883990136186256e-6, -1.34107963702085e-5, -5.1305022750383463e-5, -0.00018403727430983343, -0.0006480993109305678, -0.0022685391428745247, -0.007926337469655412, -0.027705911719169148, -0.09712862656012108, -0.34335602958570954, -1.2407498008705067, -4.749596848376581, -21.208578393694413, -146.87357279994382, -5244.956733611847], [8.067707940961776e-5, 0.0004325694384053837, 0.0014010351574290606, 0.003931185020736206, 0.010492357283010274, 0.027489824654688577, 0.07152927679994464, 0.18571634020264421, 0.482363504952572, 1.256945813827612, 3.3063437707307237, 8.919233063854097, 25.775125213469988, 91.46117039274736, 749.7290740634378], 15)
    const coeffs_m516_n15 =AlgRemez_coeffs(0.0878306966361791, [0.0007509277962442122, 0.0014129771103351901, 0.0025690642606846677, 0.004804704680853413, 0.009133835322768288, 0.017489465723451957, 0.03359412543590045, 0.06464533476923524, 0.12467226990157802, 0.24158352510716458, 0.47376218666651115, 0.9583492339226309, 2.103423848192116, 5.767769271520715, 32.00338130302361], [3.414566792941776e-5, 0.0002799002012555704, 0.0009932056503307125, 0.002870201935158085, 0.007742691557551572, 0.020366828640006118, 0.05307200842758016, 0.13784462892207863, 0.3578954121345152, 0.9312536664592276, 2.439871166172806, 6.512031325151368, 18.272203851741118, 59.181249822852465, 317.3144118172943], 15)

    const coeffs_716_n15 =AlgRemez_coeffs(31.313197770970913, [-1.0793214732696161e-6, -6.609525631069224e-6, -2.905266889459055e-5, -0.00011832919708565384, -0.00047093001543932836, -0.001859542777802144, -0.007324798573105492, -0.028860675260254678, -0.11408254589714387, -0.4551842257788603, -1.8615313222732597, -8.123102336434437, -42.18571390497898, -362.1399905644311, -22908.575751045388], [9.18485167615663e-5, 0.0004678419477166609, 0.001495666144301569, 0.004178972999211195, 0.01113824571344111, 0.029171852531255857, 0.07591010443427565, 0.19713779123944156, 0.5122275275730622, 1.335632265381022, 3.517850872464474, 9.518299441967585, 27.726378456762344, 100.92979716585268, 961.3902264441133], 15)
    const coeffs_m716_n15 =AlgRemez_coeffs(0.031935416092413786, [0.0031537964827845935, 0.004523479906318463, 0.006982550569387302, 0.011408753013703721, 0.019140376596269052, 0.032467464921531894, 0.05532588334038562, 0.09449344790923538, 0.1617452326920084, 0.27804374861930287, 0.48301182539416243, 0.862159797570612, 1.652538890256914, 3.842438751470821, 16.279516536550958], [2.6628105108459994e-5, 0.0002536416471533462, 0.0009233084674192736, 0.002689556065774295, 0.007277170331573949, 0.01916695235922365, 0.04997779038017147, 0.12985840938486778, 0.3372410061978633, 0.8775582549161446, 2.2983870762616716, 6.125907012280805, 17.116119193802056, 54.71933443536391, 278.71979758210136], 15)

    const coeffs_78_n10 =AlgRemez_coeffs(1230.7719922257754, [-7.817436007295994e-8, -1.5398021609880276e-6, -2.3190014141727902e-5, -0.00033171176364069267, -0.004697430148092109, -0.06685632163466347, -0.9823098960589322, -16.530089305894354, -511.16599403729646, -2.920627728485016e6], [0.0003335200885599715, 0.0019301557290464593, 0.008525380241714172, 0.035565228835393155, 0.146468332579182, 0.6028801585440726, 2.5078222334346627, 10.939452955175021, 59.42578612318403, 2393.738561025292], 10)
    const coeffs_m78_n10 =AlgRemez_coeffs(0.0008124981770112931, [0.32236862575088493, 0.09154657032332804, 0.08736027363216234, 0.09878363843685596, 0.11633502625015543, 0.1384850370099463, 0.1658592335867067, 0.20179179005458292, 0.2614027908690245, 0.44447806728898276], [1.0694568077240211e-5, 0.00043078942105929615, 0.0023401535803387373, 0.010208060068491684, 0.04246283384383194, 0.17478180811651173, 0.7198041693611674, 3.0027986170916754, 13.26317851702411, 76.75699568962177], 10)

    const coeffs_34_n10 =AlgRemez_coeffs(298.58720499477124, [-3.299101948582033e-7, -5.343176675575475e-6, -6.691835387626825e-5, -0.0007987743389585288, -0.00944538212770885, -0.11215721771054094, -1.3687895490220674, -18.766585249990396, -429.50705022860484, -322534.27299739956], [0.00029733856237739, 0.0017647191251857377, 0.007824038043560863, 0.03262029939367273, 0.13411408952863116, 0.5508126601932356, 2.2834892835910865, 9.878246105384765, 51.83533147717517, 1121.8951948139681], 10)
    const coeffs_m34_n10 =AlgRemez_coeffs(0.003349105330945148, [0.10250175133410291, 0.06394086808888692, 0.07692819871571034, 0.10500227685207546, 0.14786976782579872, 0.2100538823110672, 0.3002674185903645, 0.4372636075937648, 0.6862910593983804, 1.4926337354888635], [2.281853074898407e-5, 0.0004938716367864367, 0.0025915531691445815, 0.011210913133667372, 0.046476782125921066, 0.1908822562191337, 0.7847874015823891, 3.271967730405996, 14.506557805512303, 86.09714056365083], 10)

    const coeffs_38_n15=AlgRemez_coeffs(18.79461012834135, [-1.7046360675558396e-6, -9.610444656158535e-6, -3.942131666362604e-5, -0.0001506945528158633, -0.0005641655383593682, -0.0020973965186186732, -0.007780906711025815, -0.028875180111212696, -0.10748670775823455, -0.4036619555800518, -1.5516514552511727, -6.3405809684551775, -30.519208440243514, -234.92699627297367, -11006.565500273748], [8.618191632608366e-5, 0.00044999205720852386, 0.001447756780073927, 0.004053451322420477, 0.010810886447089106, 0.028318922501614753, 0.07368759207257308, 0.19134055525396876, 0.4970612673774702, 1.2956456408246217, 3.41026142515494, 9.21299036770491, 26.72755284565795, 96.02146305474176, 844.4911661436578], 15)
    const coeffs_m38_n15 =AlgRemez_coeffs(0.05320674348504038, [0.001561750230863162, 0.00257837609723268, 0.004323195247122347, 0.007559234131636582, 0.013501089188020132, 0.02433298126687033, 0.04402353307877137, 0.07981060819389385, 0.14500783100849374, 0.26465315222557295, 0.4884655289370063, 0.928106060143738, 1.903223926786511, 4.802681253420789, 23.224659637688003], [3.0314112244538444e-5, 0.0002666070603965435, 0.000957813090776804, 0.0027786852019012083, 0.00750675587835232, 0.019758488890300845, 0.05150270536078457, 0.13379285936544294, 0.3474126278246031, 0.9039891965713133, 2.367983432745513, 6.315605631773869, 17.68252813755967, 56.88989303234991, 297.0460752246229], 15)

    """
    f(x) = x^(y/z) = coeffs.α0 + sum_i^n coeffs.α[i]/(x + coeffs.β[i])
    f(x) = x^(-y/z) = coeffs_inverse.α0 + sum_i^n coeffs_inverse.α[i]/(x + coeffs_inverse.β[i])
    """
    struct RHMC #type for the rational Hybrid Monte Carlo
        y::Int64
        z::Int64
        coeffs::AlgRemez_coeffs
        coeffs_inverse::AlgRemez_coeffs

        function RHMC(order::Rational;n=10,lambda_low=0.0004,lambda_high=64,precision=42)
            num = numerator(order)
            den = denominator(order)
            return RHMC(num,den,n=n,lambda_low=lambda_low,lambda_high=lambda_high,precision=precision)
        end

        function RHMC(y,z;n=10,lambda_low=0.0004,lambda_high=64,precision=42)
            println("-------------------------------------------------------------")
            println("RHMC mode!")

            order = y // z # y/z
            num = numerator(order)
            den = denominator(order)
            @assert num != 0 "numerator should not be zero!"
            @assert num*den != 1 "$(num ÷ den) should not be 1!"

            if n == 10 && num == 1 && den == 2
                coeffs =coeffs_12
                coeffs_inverse =coeffs_m12
            elseif n == 10 && num == 3 && den == 8
                    coeffs =coeffs_38_n10
                    coeffs_inverse =coeffs_m38_n10
            elseif n == 10 && num == 5 && den == 8
                    coeffs =coeffs_58_n10
                    coeffs_inverse =coeffs_m58_n10
            elseif n == 10 && num == 7 && den == 8
                    coeffs =coeffs_78_n10
                    coeffs_inverse =coeffs_m78_n10
            elseif n == 10 && num == 3 && den == 4
                    coeffs =coeffs_34_n10
                    coeffs_inverse =coeffs_m34_n10
            elseif n == 15 && num == 3 && den == 16
                    coeffs =coeffs_316_n15
                    coeffs_inverse =coeffs_m316_n15
            elseif n == 15 && num == 5 && den == 16
                    coeffs =coeffs_516_n15
                    coeffs_inverse =coeffs_m516_n15
            elseif n == 15 && num == 7 && den == 16
                    coeffs =coeffs_716_n15
                    coeffs_inverse =coeffs_m716_n15
            elseif n == 15 && num == 1 && den == 16
                    coeffs =coeffs_116_n15
                    coeffs_inverse =coeffs_m116_n15
            elseif n == 15 && num == 1 && den == 2
                    coeffs =coeffs_12_n15
                    coeffs_inverse =coeffs_m12_n15

            elseif n == 15 && num == 3 && den == 8
                coeffs =coeffs_38_n15
                coeffs_inverse =coeffs_m38_n15
            elseif n == 15 && num == 1 && den == 4
                coeffs =coeffs_14
                coeffs_inverse =coeffs_m14
            elseif n == 10 && num == 1 && den == 4
                coeffs =coeffs_14_n10
                coeffs_inverse =coeffs_m14_n10
            elseif n == 15 && num == 1 && den == 8
                coeffs =coeffs_18
                coeffs_inverse =coeffs_m18
            elseif n == 10 && num == 1 && den == 8
                coeffs =coeffs_18_n10
                coeffs_inverse =coeffs_m18_n10
            elseif n == 10 && num == -1 && den == 2
                coeffs =coeffs_m12
                coeffs_inverse =coeffs_12
            elseif n == 15 && num == -1 && den == 2
                coeffs =coeffs_m12_n15
                coeffs_inverse =coeffs_12_n15
            elseif n == 15 && num == -1 && den == 4
                coeffs =coeffs_m14
                coeffs_inverse =coeffs_14
            elseif n == 10 && num == -1 && den == 4
                coeffs =coeffs_m14_n10
                coeffs_inverse =coeffs_14_n10
            elseif n == 15 && num == -1 && den == 8
                coeffs =coeffs_18
                coeffs_inverse =coeffs_18
            elseif n == 10 && num == -1 && den == 8
                coeffs =coeffs_18_n10
                coeffs_inverse =coeffs_18_n10
            else
                println("$y//$z with the order $n: coefficients for RHMC should be calculated")
                coeff_plus,coeff_minus = calc_coefficients(abs(num),den,n,lambda_low,lambda_high,precision=precision)
                if num > 0
                    coeffs =coeff_plus
                    coeffs_inverse =coeff_minus
                elseif num < 0
                    coeffs_inverse =coeff_plus
                    coeffs =coeff_minus
                end
            end

            println("the coefficients for x^{$num/$den}: ")
            display(coeffs)
            println("the coefficients for x^{-$num/$den}: ")
            display(coeffs_inverse)
            println("-------------------------------------------------------------")

            return new(num,den,coeffs,coeffs_inverse)
        end
    end

    function get_α(x::RHMC)
        return x.coeffs.α
    end

    function get_α0(x::RHMC)
        return x.coeffs.α0
    end

    function get_β(x::RHMC)
        return x.coeffs.β
    end

    function get_order(x::RHMC)
        return x.coeffs.n
    end

    function get_α_inverse(x::RHMC)
        return x.coeffs_inverse.α
    end

    function get_α0_inverse(x::RHMC)
        return x.coeffs_inverse.α0
    end

    function get_β_inverse(x::RHMC)
        return x.coeffs_inverse.β
    end

end


text:
using MolecularConformation, PrettyTables, DelimitedFiles, BenchmarkTools

BenchmarkTools.DEFAULT_PARAMETERS.samples = 1000

include("rmsd.jl")

"""
The perform functions is used to run tests in order to compare algorithms.
The use is pretty simple but depends on PrettyTables.jl package. Consequently,
the user need to install this package (installation: pkg> add PrettyTables).
To run perform script just type (inside examples/tests_in_pdbfiles folder):

julia> include(perform.jl)
julia> perform()

As output a table is printed and .tex file is write in file. Several arguments can
be modified. By default the perform() function has the following arguments
perform(;writefile="latex",allsolutions=false,highlight="PT",color = :yellow)

As optional argument we can setup if we want all solutions:
julia> perform(allsolutions=true)

Or what aspect of the table given by output we want highlighted:
julia> perform(highlight="PT") # for best processing time
julia> perform(highlight="LDE") #for best LDE

Changing writefile="html" and output.html file is provided.

"""
function perform(f::Function=median;writefile=:latex,allsolutions=false,highlight="PT",color = :yellow)

	opt_classic = ConformationSetup(0.000001,classicBP,allsolutions)
	#opt_classicOpt = ConformationSetup(0.000001,classicBPOpt,allsolutions)
	opt_quaternion = ConformationSetup(0.000001,quaternionBP,allsolutions)

	# primary run to optimize
	data = preprocessing("toyinstance.nmr")
	solc = conformation(data,opt_classic);
	#sol = conformation(data,opt_classicOpt);
	solq = conformation(data,opt_quaternion);
	# run to all
	list_of_problems = ["pdb1a03","pdb1a57","pdb1a7f"]
#	list_of_problems = ["pdb1a03","pdb1a57","pdb1a7f","pdb1acz","pdb2l2g","pdb2l2i","pdb2l3b","pdb2l3d","pdb2l32","pdb2l33","pdb1bct","pdb2jmy","pdb2kxa"]
#	list_of_problems = ["pdb1a03"]
	table_header = ["problem", "method", "LDE", "PT ", "Num. sol","rmsd","Improv"]
	table_header2 = ["problem", "method", " [ +- , / , √ ] node", " [+- , / , √ ] virtual path"," [ +- , / , √ ] ddf ", " Num. Branch ", " Num. Pru ", "Improv. nop", "Improv. tot"]
	# defing array to storage table
	content = Array{Any,2}(undef,2*length(list_of_problems),7)
	content2 = Array{Any,2}(undef,2*length(list_of_problems),9)
	k=1
	c = 10.0^(-9)
	for prob in list_of_problems
		data = preprocessing("$(prob).nmr")
		solq = conformation(data,opt_quaternion)
		bch = @benchmark conformation($(data),$(opt_quaternion))
		content[k,1] = prob
		content[k,2] = "quaternionBP"
		content[k,3] = outputfilter(solq,"lde")
		content[k,4] = f(bch).time*c
		content[k,5] = solq.number
		content[k,6] = " - "
		content2[k,1] = prob
		content2[k,2] = "quaternionBP"
		content2[k,3] = solq.nop.node
		content2[k,4] = solq.nop.virtual_path
		content2[k,5] = solq.nop.ddf
		content2[k,6] = solq.nop.branch
		content2[k,7] = solq.nop.prune

		k = k+1

		content[k,2] = "classicBP"
		solc = conformation(data,opt_classic)
		bch = @benchmark conformation($(data),$(opt_classic))
		content[k,1] = prob
		content[k,3] = outputfilter(solc,"lde")
		content[k,4] = f(bch).time*c
		content[k,5] = solc.number
		content[k,6] = evalrmsd2(solc,solq)[2]
		content[k-1,7] = (-1.0+content[k,4]/content[k-1,4])*100 #tc = tq+ptq
		content[k,7] = " - "

		content2[k,1] = prob
		content2[k,2] = "classicBP"
		content2[k,3] = solc.nop.node
		content2[k,4] = solc.nop.virtual_path
		content2[k,5] = solc.nop.ddf
		content2[k,6] = solc.nop.branch
		content2[k,7] = solc.nop.prune
		content2[k-1,8] = (-1.0.+content2[k,3]./content2[k-1,3]).*100
		content2[k,8] = " - "
		content2[k-1,9] = (-1.0+sum(content2[k,3])/sum(content2[k-1,3]))*100
		content2[k,9] = " - "
		k = k+1

	#sol = conformation(data,opt_classic)
	#bch = @benchmark conformation($(data),$(opt_classic))
	#content[k,1] = prob
	#content[k,2] = "quaternionBP"
	#content[k,3] = outputfilter(sol,"lde")
	#content[k,4] = f(bch).time*c
	#content[k,5] = sol.number
	#content[k,6] = evalrmsd(sol,"$(prob).xyz")[2]
	#content2[k,1] = prob
	#content2[k,2] = "quaternionBP"
	#content2[k,3] = sol.nop.node
	#content2[k,4] = sol.nop.virtual_path
	#content2[k,5] = sol.nop.ddf
	#content2[k,6] = sol.nop.branch
	#content2[k,7] = sol.nop.prune
	#k = k+1

	end
	#if highlight == "PT"
	#	H1 = Highlighter((content,i,j)->isodd(i)&&content[i,4]==minimum(content[i:i+1,4]), Crayon(foreground = color))
	#	H2 = Highlighter((content,i,j)->!isodd(i)&&content[i,4]==minimum(content[i-1:i,4]), Crayon(foreground = color))
	#elseif	highlight == "LDE"
	#	H1 = Highlighter((content,i,j)->isodd(i)&&content[i,3]==minimum(content[i:i+1,3]), Crayon(foreground = color))
	#	H2 = Highlighter((content,i,j)->!isodd(i)&&content[i,3]==minimum(content[i-1:i,3]), Crayon(foreground = color))
	#elseif highlight == "NOP"
	#	H3 = Highlighter((content2,i,j)->isodd(i)&&content2[i,3]==minimum(content2[i:i+1,3]), Crayon(foreground = color))
	#	H4 = Highlighter((content2,i,j)->!isodd(i)&&content2[i,3]==minimum(content2[i-1:i,3]), Crayon(foreground = color))
	#else
	#	error("highlight option not recognized")
	#end

	#pretty_table(content,table_header;formatters=ft_printf("%5.3f",[4,7]),highlighters=(H1,H2))
	#pretty_table(content2,table_header2;formatters=ft_printf("%5.3f",[4,7]),highlighters=(H1,H2))
	if writefile==:latex
		open("output.tex","w") do f
			pretty_table(f,content,table_header,backend=:latex)
			pretty_table(f,content2,table_header2,backend=:latex)
		end
	else
		open("output.html","w") do f
			pretty_table(f,content,table_header,backend=:html)
			pretty_table(f,content2,table_header2,backend=:html)
		end
	end
end

function vec2array(vec)
	len = length(vec)
	A=zeros(len,3)
	for i=1:len
		A[i,1] = vec[i][1]
		A[i,2] = vec[i][2]
		A[i,3] = vec[i][3]
	end
	return A
end

function evalrmsd(sols::ConformationOutput,file::String)
	coordsols = outputfilter(sols,"xyz")
	valrmsd = [1000.0,1000.0]
	xyzfile = readdlm(file)
	coordfile = Float64.(copy(xyzfile[2:xyzfile[1,1]+1,2:4]))
	#display(coordfile)
	for k=1:sols.number
		coords = vec2array(coordsols[:,k])
		valrmsdaux = rmsd(coords,coordfile)
		if valrmsdaux[2] <= valrmsd[2]
			valrmsd = [valrmsdaux[1],valrmsdaux[2]]
		end
	end
	return valrmsd
end

function evalrmsd2(sols1::ConformationOutput,sols2::ConformationOutput)
	coordsols1 = outputfilter(sols1,"xyz")
	coordsols2 = outputfilter(sols2,"xyz")
	valrmsd = [1000.0,1000.0]
	#display(coordfile)
	for k=1:sols1.number
		coords1 = vec2array(coordsols1[:,k])
		coords2 = vec2array(coordsols2[:,k])
		valrmsdaux = rmsd(coords1,coords2)
		if valrmsdaux[2] <= valrmsd[2]
			valrmsd = [valrmsdaux[1],valrmsdaux[2]]
		end
	end
	return valrmsd
end

ext: jl


text:
function reverseWord(s::String)
    result::Array{Char} = []
    cache::Array{Char} = []
    for c in s
        c == ' ' && begin
            append!(result,cache);
            cache = []
            push!(result,c);
            continue
        end

        cache = append!([c],cache)
    end

    append!(result,cache);
    String(result)
end

max_stars_repo_name: ccqpein/Arithmetic-Exercises

max_issues_repo_name: ccqpein/Arithmetic-Exercises

max_forks_repo_name: ccqpein/Arithmetic-Exercises


text:
using DFControl, Test

@test eltype(Calculations.qe_flaginfo(Exec(; exec = "projwfc.x"), :calculation)) == Nothing
@test eltype(Calculations.qe_flaginfo(Exec(; exec = "pw.x"), :calculation)) ==
      eltype(Calculations.qe_flaginfo(:calculation))


text:
## This makes implementing operators simpler
# but overrided BandedMatrix directly is likely to be faster

abstract TridiagonalOperator{T} <: Operator{T}
abstract SymTridiagonalOperator{T} <: TridiagonalOperator{T}
abstract BidiagonalOperator{T} <: TridiagonalOperator{T}
abstract DiagonalOperator{T} <: BidiagonalOperator{T}
# override getindex

bandinds(::TridiagonalOperator)=-1,1
bandinds(::BidiagonalOperator)=0,1
bandinds(::DiagonalOperator)=0,0

Base.Tridiagonal{T}(J::TridiagonalOperator{T},n::Integer)=Tridiagonal(T[J.γ(k) for k=2:n],
T[J.α(k) for k=1:n],
T[J.β(k) for k=1:n-1])

function symmetrize{T}(J::TridiagonalOperator{T},n::Integer)
    d=Array(T,n)
    d[1]=1
    for k=2:n
        d[k]=sqrt(J[k,k-1]/J[k-1,k])*d[k-1]
    end

   SymTridiagonal(
    T[J[k,k] for k=1:n],
    T[J[k,k+1]*d[k+1]/d[k] for k=1:n-1])
end

immutable DiagIteratorOperator{IT,T} <: DiagonalOperator{T}
    iterator::IT
end

DiagIteratorOperator(it) = DiagIteratorOperator{typeof(it),eltype(it)}(it)

getindex(D::DiagIteratorOperator,k::Integer,j::Integer) =
    k==j? D.iterator[k] : zero(eltype(D))

domainspace(D::DiagIteratorOperator) = ℓ⁰
rangespace(D::DiagIteratorOperator) = ℓ⁰

Base.diagm(c::AbstractCount) = DiagIteratorOperator(c)


text:
using JLD2

RESULTS_DIR = "C:\\Users\\xinle\\Documents\\OceanParameterizations.jl\\final_results"
NDE_DIR = "18sim_old"

function open_NDE_profile(filepath)
    file = jldopen(filepath)
    NDE_profile = file["NDE_profile"]
    close(file)
    return NDE_profile
end

files_training = [
    "train_wind_-5e-4_cooling_3e-8_new"
    "train_wind_-5e-4_cooling_2e-8_new"
    "train_wind_-5e-4_cooling_1e-8_new"

    "train_wind_-3.5e-4_cooling_3e-8_new"
    "train_wind_-3.5e-4_cooling_2e-8_new"
    "train_wind_-3.5e-4_cooling_1e-8_new"

    "train_wind_-2e-4_cooling_3e-8_new"
    "train_wind_-2e-4_cooling_2e-8_new"
    "train_wind_-2e-4_cooling_1e-8_new"

    "train_wind_-5e-4_heating_-3e-8_new"
    "train_wind_-5e-4_heating_-2e-8_new"
    "train_wind_-5e-4_heating_-1e-8_new"

    "train_wind_-3.5e-4_heating_-3e-8_new"
    "train_wind_-3.5e-4_heating_-2e-8_new"
    "train_wind_-3.5e-4_heating_-1e-8_new"

    "train_wind_-2e-4_heating_-3e-8_new"
    "train_wind_-2e-4_heating_-2e-8_new"
    "train_wind_-2e-4_heating_-1e-8_new"
]

NDE_profiles_training = [
    open_NDE_profile(joinpath(RESULTS_DIR, NDE_DIR, file, "profiles_fluxes_oceananigans.jld2")) for file in files_training
]

function calculate_losses(NDE_profiles)
    @inline T_loss(data) = sum(data) / 1153

    return [
        (
            NN = T_loss(profile["T_losses"]),
            mpp = T_loss(profile["T_losses_modified_pacanowski_philander"]),
            kpp = T_loss(profile["T_losses_kpp"]),
        ) for profile in NDE_profiles
    ]
end

@show calculate_losses(NDE_profiles_training)

files_training = [
    "test_wind_-4.5e-4_cooling_2.5e-8"
    "test_wind_-4.5e-4_cooling_1.5e-8"
    "test_wind_-2.5e-4_cooling_2.5e-8"
    "test_wind_-2.5e-4_cooling_1.5e-8"

    "test_wind_-4.5e-4_heating_-2.5e-8"
    "test_wind_-4.5e-4_heating_-1.5e-8"
    "test_wind_-2.5e-4_heating_-2.5e-8"
    "test_wind_-2.5e-4_heating_-1.5e-8"
]

NDE_profiles_training = [
    open_NDE_profile(joinpath(RESULTS_DIR, NDE_DIR, file, "profiles_fluxes_oceananigans.jld2")) for file in files_training
]

@show calculate_losses(NDE_profiles_training)

files_training = [
    "test_wind_-5.5e-4_new"
    "test_wind_-5.5e-4_cooling_3.5e-8"
    "test_wind_-5.5e-4_heating_-3.5e-8"

    "test_wind_-1.5e-4_cooling_3.5e-8"
    "test_wind_-1.5e-4_heating_-3.5e-8"
]

NDE_profiles_training = [
    open_NDE_profile(joinpath(RESULTS_DIR, NDE_DIR, file, "profiles_fluxes_oceananigans.jld2")) for file in files_training
]

@show calculate_losses(NDE_profiles_training)

NDE_DIR = "3sim_diurnal"

files_training = [
    "test_wind_-5.5e-4_new"
    "test_wind_-5.5e-4_cooling_3.5e-8"
    "test_wind_-5.5e-4_heating_-3.5e-8"

    "test_wind_-1.5e-4_cooling_3.5e-8"
    "test_wind_-1.5e-4_heating_-3.5e-8"
]

NDE_profiles_training = [
    open_NDE_profile(joinpath(RESULTS_DIR, NDE_DIR, file, "profiles_fluxes_oceananigans.jld2")) for file in files_training
]

@show calculate_losses(NDE_profiles_training)

NDE_DIR = "18sim_old"

files_training = [
    "test_wind_-5.5e-4_diurnal_5.5e-8"
    "test_wind_-1.5e-4_diurnal_5.5e-8"
]

NDE_profiles_training = [
    open_NDE_profile(joinpath(RESULTS_DIR, NDE_DIR, file, "profiles_fluxes_oceananigans.jld2")) for file in files_training
]

@show calculate_losses(NDE_profiles_training)

NDE_DIR = "3sim_diurnal"

files_training = [
    "test_wind_-5.5e-4_diurnal_5.5e-8"
    "test_wind_-1.5e-4_diurnal_5.5e-8"
]

NDE_profiles_training = [
    open_NDE_profile(joinpath(RESULTS_DIR, NDE_DIR, file, "profiles_fluxes_oceananigans.jld2")) for file in files_training
]

@show calculate_losses(NDE_profiles_training)

files_training = [
    "test_wind_-4.5e-4_diurnal_4e-8"
    "test_wind_-4.5e-4_diurnal_2e-8"
    "test_wind_-3e-4_diurnal_4e-8"
    "test_wind_-3e-4_diurnal_2e-8"
]

NDE_profiles_training = [
    open_NDE_profile(joinpath(RESULTS_DIR, NDE_DIR, file, "profiles_fluxes_oceananigans.jld2")) for file in files_training
]

@show calculate_losses(NDE_profiles_training)

files_training = [
    "train_wind_-5e-4_diurnal_5e-8"
    "train_wind_-3.5e-4_diurnal_5e-8"
    "train_wind_-2e-4_diurnal_5e-8"
]

NDE_profiles_training = [
    open_NDE_profile(joinpath(RESULTS_DIR, NDE_DIR, file, "profiles_fluxes_oceananigans.jld2")) for file in files_training
]

@show calculate_losses(NDE_profiles_training)


text:
macro register(name, N::Integer)
    return register(nothing, _parse_name(name)..., N)
end

macro register(ctx::Symbol, name, N::Integer)
    return register(ctx, _parse_name(name)..., N)
end

_parse_name(name) = Meta.isexpr(name, :(-->)) ? name.args : (name, name)

function register(ctx::Union{Symbol,Nothing}, name, alias, N::Integer)
    name = esc(name)
    alias = esc(alias)
    symbols = Any[gensym("symvar") for _ in 1:N]
    ret = register_promote(name, symbols)

    arglist = [Expr(:(::), s, :Sym) for s in symbols]
    e = if ctx === nothing
        quote
            function $name($(arglist...))
                apply($alias, $(symbols...))
            end
        end
    else
        quote
            function $name($(arglist...))
                apply($alias, $(symbols...); context=$(esc(ctx)))
            end
        end
    end

    push!(ret.args, e)

    return ret
end

function register_promote(name, symbols)
    N = length(symbols)
    ret = Expr(:block)

    if N > 1
        for has_types in Iterators.product(((true, false) for _ in 1:N)...)
            (all(has_types) || !any(has_types)) && continue
            arglist = [has_type ? Expr(:(::), s, :Sym) : s for (has_type, s) in zip(has_types, symbols)]
            e = :($name($(arglist...)) = $name(promote($(symbols...))...))
            push!(ret.args, e)
        end
    end

    return ret
end


text:
###### BEGIN: LINE NUMBER SENSITIVITY ##########
@traitdef BacktraceTr{X}

@traitimpl BacktraceTr{Integer}

@traitfn foo{X;  BacktraceTr{X}}(A::X) = backtrace()
@traitfn foo{X; !BacktraceTr{X}}(A::X) = backtrace()
###### END:   LINE NUMBER SENSITIVITY ##########
# (the tests below depend on the particular line numbers in the code above)

function hasline(bt, n)
    for b in bt
        lkup = StackTraces.lookup(b)
        if length(lkup) >= 2
            l1, l2 = lkup[1], lkup[2]
            if (contains(string(l1.file), "backtraces.jl") &&
                l1.func == :foo &&
                l1.line == n &&
                contains(string(l2.file), "SimpleTraits.jl"))
                return true
            end
        end
    end
    false
end

@test hasline(foo(1), 6)
@test hasline(foo(1.0), 7)

nothing


text:
mutable struct ManifoldsManifold
    vars::Vector{String}
    exp::Vector{Token} # replace with a vector of unified tokens/values when inline eval is ready
end

function Base.show(io::IO, m::ManifoldsManifold)
    print(io, "(manifolds.manifold of "*join(m.vars, ' ')*")")
end

max_stars_repo_name: Aetherlang/aetherlang

max_issues_repo_name: gojakuch/aetherlang

max_forks_repo_name: gojakuch/aetherlang


text:
# This file was generated by the Julia Swagger Code Generator
# Do not modify this file directly. Modify the swagger specification instead.

mutable struct VirtualMachineScaleSetVMInstanceRequiredIDs <: SwaggerModel
    instanceIds::Any # spec type: Union{ Nothing, Vector{String} } # spec name: instanceIds

    function VirtualMachineScaleSetVMInstanceRequiredIDs(;instanceIds=nothing)
        o = new()
        validate_property(VirtualMachineScaleSetVMInstanceRequiredIDs, Symbol("instanceIds"), instanceIds)
        setfield!(o, Symbol("instanceIds"), instanceIds)
        o
    end
end # type VirtualMachineScaleSetVMInstanceRequiredIDs

const _property_map_VirtualMachineScaleSetVMInstanceRequiredIDs = Dict{Symbol,Symbol}(Symbol("instanceIds")=>Symbol("instanceIds"))
const _property_types_VirtualMachineScaleSetVMInstanceRequiredIDs = Dict{Symbol,String}(Symbol("instanceIds")=>"Vector{String}")
Base.propertynames(::Type{ VirtualMachineScaleSetVMInstanceRequiredIDs }) = collect(keys(_property_map_VirtualMachineScaleSetVMInstanceRequiredIDs))
Swagger.property_type(::Type{ VirtualMachineScaleSetVMInstanceRequiredIDs }, name::Symbol) = Union{Nothing,eval(Meta.parse(_property_types_VirtualMachineScaleSetVMInstanceRequiredIDs[name]))}
Swagger.field_name(::Type{ VirtualMachineScaleSetVMInstanceRequiredIDs }, property_name::Symbol) =  _property_map_VirtualMachineScaleSetVMInstanceRequiredIDs[property_name]

function check_required(o::VirtualMachineScaleSetVMInstanceRequiredIDs)
    (getproperty(o, Symbol("instanceIds")) === nothing) && (return false)
    true
end

function validate_property(::Type{ VirtualMachineScaleSetVMInstanceRequiredIDs }, name::Symbol, val)
end


text:
__precompile__()
# Ordinary Differential Equation Solvers

module ODE

using Polynomials, LinearAlgebra
using Polynomials.PolyCompat
using Compat
using Reexport
@reexport using DiffEqBase

import DiffEqBase: solve

const warnkeywords =
    (:save_idxs, :d_discontinuities, :isoutofdomain, :unstable_check,
     :calck, :progress,
     :internalnorm, :gamma, :beta1, :beta2, :qmax, :qmin, :qoldinit)

function __init__()
    global warnlist = Set(warnkeywords)
end

include("algorithm_types.jl")

## minimal function export list
# adaptive non-stiff:
export ode23, ode45, ode78
# non-adaptive non-stiff:
export ode4, ode4ms
# adaptive stiff:
export ode23s
# non-adaptive stiff:
export ode4s

# Common Interface
export ODEjlAlgorithm

## complete function export list: see runtests.jl

###############################################################################
## Coefficient Tableaus
###############################################################################

# Butcher Tableaus, or more generally coefficient tables
# see Hairer & Wanner 1992, p. 134, 166

abstract type Tableau{Name, S, T<:Real} end
# Name is the name of the tableau/method (a symbol)
# S is the number of stages (an int)
# T is the type of the coefficients
#
# TODO: have a type parameter which specifies adaptive vs non-adaptive
#
# For all types of tableaus it assumes fields:
# order::(Int...) # order of the method(s)
#
# For Runge-Kutta methods it assumes fields:
# a::Matrix{T}  # SxS matrix
# b::Matrix{T}  # 1 or 2 x S matrix (fixed step/ adaptive)
# c::Vector{T}  # S
#
# For a tableau:
#  c1  | a_11   ....   a_1s
#  .   | a_21 .          .
#  .   | a_31     .      .
#  .   | ....         .  .
#  c_s | a_s1  ....... a_ss
# -----+--------------------
#      | b_1     ...   b_s   this is the one used for stepping
#      | b'_1    ...   b'_s  this is the one used for error-checking

Base.eltype(b::Tableau{N,S,T}) where {N,S,T} = T
order(b::Tableau) = b.order
# Subtypes need to define a convert method to convert to a different
# eltype with signature:
Base.convert(::Type{Tnew}, tab::Tableau) where {Tnew<:Real} =
    error("Define convert method for concrete Tableau types")

###############################################################################
## HELPER FUNCTIONS
###############################################################################

# estimator for initial step based on book
# "Solving Ordinary Differential Equations I" by Hairer et al., p.169
function hinit(F, x0, t0::T, tend, p, reltol, abstol) where T
    # Returns first step, direction of integration and F evaluated at t0
    tdir = sign(tend-t0)
    tdir==0 && error("Zero time span")
    tau = max(reltol*norm(x0, Inf), abstol)
    d0 = norm(x0, Inf)/tau
    f0 = F(t0, x0)
    d1 = norm(f0, Inf)/tau
    if d0 < 1e-5 || d1 < 1e-5
        h0 = 1e-6
    else
        h0 = 0.01*(d0/d1)
    end
    h0 = convert(T,h0)
    # perform Euler step
    x1 = x0 + tdir*h0*f0
    f1 = F(t0 + tdir*h0, x1)
    # estimate second derivative
    d2 = norm(f1 - f0, Inf)/(tau*h0)
    if max(d1, d2) <= 1e-15
        h1 = max(T(10)^(-6), T(10)^(-3)*h0)
    else
        pow = -(2 + log10(max(d1, d2)))/(p + 1)
        h1 = 10^pow
    end
    h1 = convert(T,h1)
    return tdir*min(100*h0, h1, tdir*(tend-t0)), tdir, f0
end

# isoutofdomain takes the state and returns true if state is outside
# of the allowed domain.  Used in adaptive step-control.
isoutofdomain(x) = isnan(x)

function make_consistent_types(fn, y0, tspan, btab::Tableau)
    # There are a few types involved in a call to a ODE solver which
    # somehow need to be consistent:
    #
    # Et = eltype(tspan)
    # Ey = eltype(y0)
    # Ef = eltype(Tf)
    #
    # There are also the types of the containers, but they are not
    # needed as `similar` is used to make containers.
    # Tt = typeof(tspan)
    # Ty = typeof(y0)              # note, this can be a scalar
    # Tf = typeof(F(tspan(1),y0))  # note, this can be a scalar
    #
    # Returns
    # - Et: eltype of time, needs to be a real "continuous" type, at
    #       the moment a AbstractFloat
    # - Eyf: suitable eltype of y and f(t,y)
    #   --> both of these are set to typeof(y0[1]/(tspan[end]-tspan[1]))
    # - Ty: container type of y0
    # - btab: tableau with entries converted to Et

    # Needed interface:
    # On components: /, -
    # On container: eltype, promote_type
    # On time container: eltype

    Ty = typeof(y0)
    Eyf = typeof(y0[1]/(tspan[end]-tspan[1]))

    Et = eltype(tspan)
    @assert Et<:Real
    if !(Et<:AbstractFloat)
        Et = promote_type(Et, Float64)
    end

    # if all are Floats, make them the same
    if Et<:AbstractFloat &&  Eyf<:AbstractFloat
        Et = promote_type(Et, Eyf)
        Eyf = Et
    end

    !isconcretetype(Et) && @warn("The eltype(tspan) is not a concrete type!  Change type of tspan for better performance.")
    !isconcretetype(Eyf) && @warn("The eltype(y0/tspan[1]) is not a concrete type!  Change type of y0 and/or tspan for better performance.")

    btab_ = convert(Et, btab)
    return Et, Eyf, Ty, btab_
end

###############################################################################
## NON-STIFF SOLVERS
###############################################################################

include("runge_kutta.jl")

# ODE_MS Fixed-step, fixed-order multi-step numerical method
#   with Adams-Bashforth-Moulton coefficients
function ode_ms(F, x0, tspan, order::Integer; kwargs...)
    h = diff(tspan)
    x = Vector{typeof(x0)}(undef,length(tspan))
    x[1] = x0

    if 1 <= order <= 4
        b = ms_coefficients4
    else
        b = zeros(order, order)
        b[1:4, 1:4] = ms_coefficients4
        for s = 5:order
            for j = 0:(s - 1)
                # Assign in correct order for multiplication below
                #  (a factor depending on j and s) .* (an integral of a polynomial with -(0:s), except -j, as roots)
                p_int = polyint(poly(diagm(0 => -[0:j - 1; j + 1:s - 1])))
                b[s, s - j] = ((-1)^j / factorial(j)
                               / factorial(s - 1 - j) * polyval(p_int, 1))
            end
        end
    end

    # TODO: use a better data structure here (should be an order-element circ buffer)
    xdot = similar(x)
    for i = 1:length(tspan)-1
        # Need to run the first several steps at reduced order
        steporder = min(i, order)
        xdot[i] = F(tspan[i], x[i])

        x[i+1] = x[i]
        for j = 1:steporder
            x[i+1] += h[i]*b[steporder, j]*xdot[i-(steporder-1) + (j-1)]
        end
    end
    return vcat(tspan), x
end

# Use order 4 by default
ode4ms(F, x0, tspan; kwargs...) = ode_ms(F, x0, tspan, 4; kwargs...)
ode5ms(F, x0, tspan; kwargs...) = ODE.ode_ms(F, x0, tspan, 5; kwargs...)

###############################################################################
## STIFF SOLVERS
###############################################################################

# Crude forward finite differences estimator of Jacobian as fallback

# FIXME: This doesn't really work if x is anything but a Vector or a scalar
function fdjacobian(F, x::Number, t)
    ftx = F(t, x)

    # The 100 below is heuristic
    dx = (x .+ (x==0))./100
    dFdx = (F(t,x+dx)-ftx)./dx

    return dFdx
end

function fdjacobian(F, x, t)
    ftx = F(t, x)
    lx = max(length(x),1)
    dFdx = zeros(eltype(x), lx, lx)
    for j = 1:lx
        # The 100 below is heuristic
        dx = zeros(eltype(x), lx)
        dx[j] = (x[j] .+ (x[j]==0))./100
        dFdx[:,j] = (F(t,x+dx)-ftx)./dx[j]
    end
    return dFdx
end

# ODE23S  Solve stiff systems based on a modified Rosenbrock triple
# (also used by MATLAB's ODE23s); see Sec. 4.1 in
#
# [SR97] L.F. Shampine and M.W. Reichelt: "The MATLAB ODE Suite," SIAM Journal on Scientific Computing, Vol. 18, 1997, pp. 1–22
#
# supports keywords: points = :all | :specified (using dense output)
#                    jacobian = G(t,y)::Function | nothing (FD)
function ode23s(F, y0, tspan;
                reltol = 1.0e-5, abstol = 1.0e-8,
                jacobian=nothing,
                points=:all,
                norm=LinearAlgebra.norm,
                minstep=abs(tspan[end] - tspan[1])/1e18,
                maxstep=abs(tspan[end] - tspan[1])/2.5,
                initstep=0.)

    # select method for computing the Jacobian
    if typeof(jacobian) == Function
        jac = jacobian
    else
        # fallback finite-difference
        jac = (t, y)->fdjacobian(F, y, t)
    end

    # constants
    d = 1/(2 + sqrt(2))
    e32 = 6 + sqrt(2)

    # initialization
    t = tspan[1]

    tfinal = tspan[end]

    h = initstep
    if h == 0.
        # initial guess at a step size
        h, tdir, F0 = hinit(F, y0, t, tfinal, 3, reltol, abstol)
    else
        tdir = sign(tfinal - t)
        F0 = F(t,y0)
    end
    h = tdir * min(abs(h), maxstep)

    y = y0
    tout = [t]         # first output time
    yout = [deepcopy(y)]        # first output solution

    J = jac(t,y)    # get Jacobian of F wrt y

    while abs(t - tfinal) > 0 && minstep < abs(h)
        if abs(t-tfinal) < abs(h)
            h = tfinal - t
        end

        if size(J,1) == 1
            W = I - h*d*J
        else
            # note: if there is a mass matrix M on the lhs of the ODE, i.e.,
            #   M * dy/dt = F(t,y)
            # we can simply replace eye(J) by M in the following expression
            # (see Sec. 5 in [SR97])

            W = lu( I - h*d*J )
        end

        # approximate time-derivative of F
        T = h*d*(F(t + h/100, y) - F0)/(h/100)

        # modified Rosenbrock formula
        k1 = W\(F0 + T)
        F1 = F(t + 0.5*h, y + 0.5*h*k1)
        k2 = W\(F1 - k1) + k1
        ynew = y + h*k2
        F2 = F(t + h, ynew)
        k3 = W\(F2 - e32*(k2 - F1) - 2*(k1 - F0) + T )

        err = (abs(h)/6)*norm(k1 - 2*k2 + k3) # error estimate
        delta = max(reltol*max(norm(y),norm(ynew)), abstol) # allowable error

        # check if new solution is acceptable
        if  err <= delta

            if points==:specified || points==:all
                # only points in tspan are requested
                # -> find relevant points in (t,t+h]
                for toi in tspan[(tspan.>t) .& (tspan.<=t+h)]
                    # rescale to (0,1]
                    s = (toi-t)/h

                    # use interpolation formula to get solutions at t=toi
                    push!(tout, toi)
                    push!(yout, y + h*( k1*s*(1-s)/(1-2*d) + k2*s*(s-2*d)/(1-2*d)))
                end
            end
            if (points==:all) && (tout[end]!=t+h)
                # add the intermediate points
                push!(tout, t + h)
                push!(yout, ynew)
            end

            # update solution
            t = t + h
            y = ynew

            F0 = F2         # use FSAL property
            J = jac(t,y)    # get Jacobian of F wrt y
                            # for new solution
        end

        # update of the step size
        h = tdir*min( maxstep, abs(h)*0.8*(delta/err)^(1/3) )
    end

    return tout, yout
end

#ODEROSENBROCK Solve stiff differential equations, Rosenbrock method
#   with provided coefficients.
function oderosenbrock(F, x0, tspan, gamma, a, b, c; jacobian=nothing, kwargs...)

    if typeof(jacobian) == Function
        G = jacobian
    else
        G = (t, x)->fdjacobian(F, x, t)
    end

    h = diff(tspan)
    x = Vector{typeof(x0)}(undef,length(tspan))
    x[1] = x0

    solstep = 1
    while solstep < length(tspan)
        ts = tspan[solstep]
        hs = h[solstep]
        xs = x[solstep]
        dFdx = G(ts, xs)

        jac = I/(gamma*hs) - dFdx

        g = Vector{typeof(x0)}(undef,size(a,1))
        g[1] = (jac \ F(ts + b[1]*hs, xs))
        x[solstep+1] = x[solstep] + b[1]*g[1]

        for i = 2:size(a,1)
            dx = zero(x0)
            dF = zero(x0/hs)
            for j = 1:i-1
                dx += a[i,j]*g[j]
                dF += c[i,j]*g[j]
            end
            g[i] = (jac \ (F(ts + b[i]*hs, xs + dx) + dF/hs))
            x[solstep+1] += b[i]*g[i]
        end
        solstep += 1
    end
    return vcat(tspan), x
end

# Kaps-Rentrop coefficients
const kr4_coefficients = (0.231,
                          [0              0             0 0
                           2              0             0 0
                           4.452470820736 4.16352878860 0 0
                           4.452470820736 4.16352878860 0 0],
                          [3.95750374663  4.62489238836 0.617477263873 1.28261294568],
                          [ 0               0                0        0
                           -5.07167533877   0                0        0
                            6.02015272865   0.1597500684673  0        0
                           -1.856343618677 -8.50538085819   -2.08407513602 0],)

ode4s_kr(F, x0, tspan; jacobian=nothing, kwargs...) = oderosenbrock(F, x0, tspan, kr4_coefficients...; jacobian=jacobian, kwargs...)

# Shampine coefficients
const s4_coefficients = (0.5,
                         [ 0    0    0 0
                           2    0    0 0
                          48/25 6/25 0 0
                          48/25 6/25 0 0],
                         [19/9 1/2 25/108 125/108],
                         [   0       0      0   0
                            -8       0      0   0
                           372/25   12/5    0   0
                          -112/125 -54/125 -2/5 0],)

ode4s_s(F, x0, tspan; jacobian=nothing, kwargs...) =
    oderosenbrock(F, x0, tspan, s4_coefficients...; jacobian=jacobian, kwargs...)

# Use Shampine coefficients by default (matching Numerical Recipes)
ode4s(F, x0, tspan; jacobian=nothing, kwargs...) =
    ode4s_s(F, x0, tspan; jacobian=nothing, kwargs...)

const ms_coefficients4 = [ 1      0      0     0
                          -1/2    3/2    0     0
                          5/12  -4/3  23/12 0
                          -9/24   37/24 -59/24 55/24]

####### Common Interface Bindings

include("common.jl")

end # module ODE


text:
module Toetactic
export GameEnv, GameSpec, Board
include("game.jl")
module Training
using AlphaZero
import ..GameSpec
include("params.jl")
end
end


text:
CPYTHON_OBJECTS = [
	# types
	:PyType_Type,       # builtin 'type'
	:PyBaseObject_Type, # builtin 'object'
	:PySuper_Type,      # builtin 'super'
	:PyLong_Type,       # builtin 'int'
	:PyUnicode_Type,    # builtin 'str'
	:PyTuple_Type,      # builtin 'tuple'
	:PyList_Type,       # builtin 'list'
	:PyBool_Type,       # bulitin 'bool'
	:PyFloat_Type,      # builtin 'float'
	:PyComplex_Type,    # builtin 'complex'
	:PyDict_Type,       # builtin 'dict'
	:PySlice_Type,      # builtin 'slice'
	:PyRange_Type,      # builtin 'range' ('xrange' in python 2)
	# objects
	:_Py_NoneStruct => :Py_None,
	:_Py_TrueStruct => :Py_True,
	:_Py_FalseStruct => :Py_False,
	:_Py_EllipsisObject => :Py_Ellipsis,
	:_Py_NotImplementedStruct => :Py_NotImplemented,
]

CPYTHON_OBJECT_POINTERS = [
	# exception types
	:PyExc_ArithmeticError,
	:PyExc_AttributeError,
	:PyExc_EOFError,
	:PyExc_ImportError,
	:PyExc_IndexError,
	:PyExc_IOError,
	:PyExc_KeyboardInterrupt,
	:PyExc_KeyError,
	:PyExc_MemoryError,
	:PyExc_OverflowError,
	:PyExc_RuntimeError,
	:PyExc_SystemError,
	:PyExc_SyntaxError,
	:PyExc_TypeError,
	:PyExc_ValueError,
	:PyExc_ZeroDivisionError,
]

for name in CPYTHON_OBJECTS
	jname = Symbol(:C, name isa Pair ? name[2] : name)
	jfname = Symbol(jname, :_NewRef)
	@eval const $jname = Ref{PyPtr}(C_NULL)
	@eval function $jfname()
		r = $jname[]
		CPy_IncRef(r)
		r
	end
end

for name in CPYTHON_OBJECT_POINTERS
	jname = Symbol(:C, name isa Pair ? name[2] : name)
	jfname = Symbol(jname, :_NewRef)
	@eval const $jname = Ref{PyPtr}(C_NULL)
	@eval function $jfname()
		r = $jname[]
		CPy_IncRef(r)
		r
	end
end

@eval function capi_init()
	$([begin
	    cname, jname = name isa Pair ? name : name=>name
	    jname = Symbol(:C, jname)
	    cnamesym = QuoteNode(cname)
	    :($jname[] = @pyglobalobj($cnamesym))
	end for name in CPYTHON_OBJECTS]...)
	$([begin
	    cname, jname = name isa Pair ? name : name=>name
	    jname = Symbol(:C, jname)
	    cnamesym = QuoteNode(cname)
	    :($jname[] = @pyglobalobjptr($cnamesym))
	end for name in CPYTHON_OBJECT_POINTERS]...)
end


text:
module quizzes

function literal_variables1(;arg1="replace_me1", arg2=0)
    try
        assert(typeof(arg1)==String)
    catch
        return "arg1 is not a string"
    end
    try
        assert(arg1 == "327")
    catch
        return "arg1 is a string but is not the correct value"
    end
    try
        assert(typeof(arg2)==Int64)
    catch
        return "arg2 is not of the correct type"
    end
    try
        assert(arg2==327)
    catch
        return "The integer value of arg2 is not correct"
    end
    return "Your value seems to be correct."
end

function test_quadratic(myfunc)
    x = rand(-10:10)
    x0 = rand(-10:10)
    a = rand(-10:10)
    b = rand(-10:10)
    result =  myfunc(x,x0,a,b)
    if result == false
        return "Your function is not correct. Did you forget to set a value for y or explicitly return a value?"
    end
    try
        assert(typeof(result) <: Number)
    catch
        return "Your function is not returning a number."
    end
    try
        assert(result == (x-x0)^2 + a*x + b)
    catch
        return "Your function is returning a number but it is not the correct value."
    end
    return "Your function seems to be correct"

end

function test_bmi(myfunc)
    mass = 15*randn() + 80
    height = 30*randn()+ 165

    result =  myfunc(mass, height)
    if ! (typeof(result) <: Number)
        return "Your function is not correct. You are not returning a number. You are return a type $(typeof(result))"
    else
        if result == mass/height^2
            return "Your function seems to be correct"
        else
            return "Your function is returning a number but it is not the correct value."
        end
    end

end

function test_pediatric_age(myfunc)

    function _ref(myage)
        if myage < 1
            return "NEONATES"
        elseif myage < 24
            return "INFANTS"
        elseif myage < 144
            return "CHILDREN"
        elseif myage < 12*16
            return "ADOLESCENTS"
        else
            return "OTHER"
        end
    end
    for i in 1:100
        age = rand(0:18*12)
        my_group = myfunc(age)
        ref_group = _ref(age)
        if !(typeof(my_group) <: String)
            return "Your function is not correct. You are not returning a string. You are return a type $(typeof(my_group))"
        else
            try
                assert(my_group == ref_group)
            catch
                return "You mapped the age $age to the group $my_group when the correct group was $ref_group"
            end
        end
    end
    return "Your function seems to be correct"
end

function test_random_integer(myfunc)
    result =  myfunc()
    results = []
    if !(typeof(result) <: Number)
        return "Your function is not correct. Instead of returning a number you are returning a $(typeof(result))"
    elseif !(typeof(result) <: Int64)
        return "Your function returns a number but it was not an unsigned integer"
    else
        for i in 1:1000
            result = myfunc()
            results = append!(results, result)
            try
                assert(20 <= result <= 50)
            catch:
                return "Your function returned an integer but the value $result is not in the specified range"
            end
        end
    end
    try
        assert(20 in results)
        assert(50 in results)
    catch
        return "You do not seem to have the correct range of numbers"
    end
    return "Your function seems to be correct"
end

function test_json()
    try
        assert(!(Pkg.installed("JSON")==nothing))
    catch
        return "JSON package is not installed"
    end
    return "JSON package is installed"
end

end

max_stars_repo_name: chapmanbe/ODEClass

max_issues_repo_name: chapmanbe/ODEClass

max_forks_repo_name: chapmanbe/ODEClass


text:
@inline function handle_tstop!(integrator)
    tstops = integrator.opts.tstops
    if !isempty(tstops)
      tdir_t = integrator.tdir * integrator.t
      tdir_ts_top = first(tstops)
      if tdir_t == tdir_ts_top
        pop!(tstops)
        integrator.just_hit_tstop = true
      elseif tdir_t > tdir_ts_top
        if !integrator.dtchangeable
          change_t_via_interpolation!(integrator, integrator.tdir * pop!(tstops), Val{true})
          integrator.just_hit_tstop = true
        else
          error("Something went wrong. Integrator stepped past tstops but the algorithm was dtchangeable. Please report this error.")
        end
      end
      isempty(integrator.opts.d_discontinuities) || handle_discontinuities!(integrator)
    end
  end
#=
Dealing with discontinuities

If we hit a discontinuity (this is checked in `apply_step!`), then we remove the
discontinuity, additional discontinuities at the current time point (if present), and
maybe also discontinuities and time stops coming shortly after the current time point
in `handle_discontinuities!`. The order of the discontinuity at the current time point is
defined as the lowest order of all these discontinuities.

If the problem is not neutral, we will only add additional discontinuities if
this order is less or equal to the order of the algorithm in
`add_next_discontinuities!`. If we add discontinuities, we add discontinuities
of the next order caused by constant lags (these we can calculate explicitly and
just add them to `d_discontinuities` and `tstops`) and we add the current
discontinuity to `tracked_discontinuities` which is the array of old
discontinuities that are checked by a `DiscontinuityCallback` (if existent).
=#

# handle discontinuities at the current time point of the `integrator`
function handle_discontinuities!(integrator::SDDEIntegrator)
    # remove all discontinuities at current time point and calculate minimal order
    # of these discontinuities
    d = pop!(integrator.opts.d_discontinuities)
    order = d.order
    while !isempty(integrator.opts.d_discontinuities) &&
        first(integrator.opts.d_discontinuities) == integrator.tdir * integrator.t

        d2 = pop!(integrator.opts.d_discontinuities)
        order = min(order, d2.order)
    end

    # remove all discontinuities close to the current time point as well and
    # calculate minimal order of these discontinuities
    # integrator.EEst has unitless type of integrator.t
    if typeof(integrator.EEst) <: AbstractFloat
        maxΔt = 10eps(integrator.t)

        while !isempty(integrator.opts.d_discontinuities) &&
            abs(first(integrator.opts.d_discontinuities).t - integrator.tdir * integrator.t) < maxΔt

            d2 = pop!(integrator.opts.d_discontinuities)
            order = min(order, d2.order)
        end

        # also remove all corresponding time stops
        while !isempty(integrator.opts.tstops) &&
            abs(first(integrator.opts.tstops) - integrator.tdir * integrator.t) < maxΔt

            pop!(integrator.opts.tstops)
        end
    end

    # add discontinuities of next order to integrator
    add_next_discontinuities!(integrator, order)
    nothing
end

"""
    add_next_discontinuities!(integrator::DDEIntegrator, order[, t=integrator.t])

Add discontinuities of next order that are propagated from discontinuity of
order `order` at time `t` in `integrator`, but only if `order` is less or equal
than the order of the applied method or the problem is neutral.

Discontinuities caused by constant delays are immediately calculated, and
discontinuities caused by dependent delays are tracked by a callback.
"""
function add_next_discontinuities!(integrator, _order, t = integrator.t)
    neutral = integrator.sol.prob.neutral
    order = Rational{Int}(_order)
    next_order = neutral ? order : order + 1//2

  # only track discontinuities up to order of the applied method
    alg_order = StochasticDiffEq.alg_order(getalg(integrator.alg))
    next_order <= alg_order + 1//2 || return

  # discontinuities caused by constant lags
    if has_constant_lags(integrator)
        constant_lags = integrator.sol.prob.constant_lags
        maxlag = integrator.tdir * (integrator.sol.prob.tspan[end] - t)

        for lag in constant_lags
            if integrator.tdir * lag < maxlag
        # calculate discontinuity and add it to heap of discontinuities and time stops
                d = Discontinuity(integrator.tdir * (t + lag), next_order)
                push!(integrator.opts.d_discontinuities, d)
                push!(integrator.opts.tstops, d.t)
            end
        end
    end

  # track propagated discontinuities with callback
    push!(integrator.tracked_discontinuities, Discontinuity(integrator.tdir * t, order))
    nothing
end


text:
using BlockCoordinateDescent
using Base.Test

# write your own tests here
include("bcdExample.jl")


text:
Tables.istable(::Type{<:File}) = true
Tables.columnaccess(::Type{<:File}) = true
Tables.schema(f::File)  = Tables.Schema(getnames(f), _eltype.(gettypes(f)))
Tables.columns(f::File) = f
Tables.columnnames(f::File) = getnames(f)
Base.propertynames(f::File) = getnames(f)

function Base.getproperty(f::File, col::Symbol)
    lookup = getfield(f, :lookup)
    return get(lookup, col) do
        getfield(f, col)
    end
end

Tables.getcolumn(f::File, nm::Symbol) = getcolumn(f, nm)
Tables.getcolumn(f::File, i::Int) = getcolumn(f, i)

# Column2
 # copy
 # BroadcastStyle/broadcasted
Base.mapreduce(f, op, xs::Column2; kwargs...) = Base.mapfoldl(f, op, xs; kwargs...)

@inline function Base.iterate(c::Column2)
    length(c) == 0 && return nothing
    array_lens = [length(x) for x in c.columns]
    st = ThreadedIterationState(2, 1, 2, array_lens[1], array_lens)
    return c.columns[1][1], st
end

@inline function Base.iterate(c::Column2, st)
    row = st.row
    array_index = st.array_index
    array_i = st.array_i
    row > length(c) && return nothing
    if array_i + 1 > st.array_len
        st.array_index += 1
        st.array_i = 1
        st.array_len = st.array_lens[min(end, st.array_index)]
    else
        st.array_i += 1
    end
    st.row += 1
    return c.columns[array_index][array_i], st
end

Base.@propagate_inbounds function Base.getindex(c::Column2, i::Integer)
    i′ = i
    for C in c.columns
        n = length(C)
        i′ ≤ n && return C[i′]
        i′ -= n
    end
    throw(BoundsError(c, i))
end

Base.copy(c::Union{Column{Missing, Missing}, Column2{Missing, Missing}}) = missings(length(c))

function Base.copy(c::Union{Column{T}, Column2{T}}) where {T}
    len = length(c)
    A = (T == String || T == Union{String, Missing}) ? StringVector{T}(undef, len) : Vector{T}(undef, len)
    if T <: Int64 || T <: Float64 || T <: Dates.TimeType
        if c isa Column
            memcpy!(pointer(A), 1, pointer(c.tape), 1, len * 8)
            return A
        else
            doff = 1
            for cx in c.columns
                n = length(cx) * 8
                memcpy!(pointer(A), doff, pointer(cx.tape), 1, n)
                doff += n
            end
            return A
        end
    end
    for (i, x) in enumerate(c)
        @inbounds A[i] = x
    end
    return A
end

function Base.copy(col::Union{Column{T, S}, Column2{T, S}}) where {T <: Union{String, Union{String, Missing}}, S <: Union{PooledString, Union{PooledString, Missing}}}
    len = length(col)
    c = col isa Column ? col : col.columns[1]
    catg = c.catg
    crefs = c.refs
    if S === PooledString
        refs = Dict{String, UInt32}()
        foreach(x->setindex!(refs, UInt32(x[1]), x[2]), enumerate(crefs))
        values = Vector{UInt32}(undef, len)
        if col isa Column
            tape = c.tape
            @simd for i = 1:len
                @inbounds values[i] = ref(tape[i])
            end
        else
            i = 1
            for cx in col.columns
                tape = cx.tape
                @simd for j = 1:length(cx)
                    @inbounds values[i] = ref(tape[j])
                    i += 1
                end
            end
        end
    else
        if catg
            refs = Dict{String, UInt32}()
            foreach(x->setindex!(refs, UInt32(x[1]), x[2]), enumerate(crefs))
            missingref = UInt32(0)
            values = Vector{UInt32}(undef, len)
        else # Union{PooledString, Missing}
            refs = Dict{Union{String, Missing}, UInt32}()
            foreach(x->setindex!(refs, UInt32(x[1]), x[2]), enumerate(crefs))
            missingref = UInt32(length(refs) + 1)
            refs[missing] = missingref
            values = Vector{UInt32}(undef, len)
        end
        if col isa Column
            tape = c.tape
            @simd for i = 1:len
                @inbounds v = ref(tape[i])
                @inbounds values[i] = ifelse(v == UInt32(0), missingref, v)
            end
        else
            i = 1
            for cx in col.columns
                tape = cx.tape
                @simd for j = 1:length(cx)
                    @inbounds v = ref(tape[j])
                    @inbounds values[i] = ifelse(v == UInt32(0), missingref, v)
                    i += 1
                end
            end
        end
    end
    if catg
        pool = CategoricalPool(refs)
        levels!(pool, sort(levels(pool)))
        A = CategoricalArray{T, 1}(values, pool)
    else
        A = PooledArray(PooledArrays.RefArray(values), refs)
    end
    return A
end

Base.@propagate_inbounds function Base.getindex(c::Column{Missing}, row::Int)
    @boundscheck checkbounds(c, row)
    return missing
end

Base.@propagate_inbounds function Base.getindex(c::Column{T, S}, row::Int) where {T, S}
    @boundscheck checkbounds(c, row)
    @inbounds x = reinterp_func(T)(c.tape[row])
    return x
end

Base.@propagate_inbounds function Base.getindex(c::Column{Union{T, Missing}, S}, row::Int) where {T, S}
    @boundscheck checkbounds(c, row)
    @inbounds x = c.tape[row]
    return ifelse(x === c.sentinel, missing, reinterp_func(T)(x))
end

Base.@propagate_inbounds function Base.getindex(c::Column{T, PooledString}, row::Int) where {T}
    @boundscheck checkbounds(c, row)
    @inbounds x = c.tape[row]
    @inbounds str = c.refs[x]
    return str
end

Base.@propagate_inbounds function Base.getindex(c::Column{T, Union{PooledString, Missing}}, row::Int) where {T}
    @boundscheck checkbounds(c, row)
    @inbounds x = c.tape[row]
    if x == 0
        return missing
    else
        @inbounds y = c.refs[x]
        return y
    end
end

Base.@propagate_inbounds function Base.getindex(c::Column{T, String}, row::Int) where {T}
    @boundscheck checkbounds(c, row)
    @inbounds offlen = c.tape[row]
    s = PointerString(pointer(c.buf, getpos(offlen)), getlen(offlen))
    return escapedvalue(offlen) ? unescape(s, c.e) : String(s)
end

Base.@propagate_inbounds function Base.getindex(c::Column{T, Union{String, Missing}}, row::Int) where {T}
    @boundscheck checkbounds(c, row)
    @inbounds offlen = c.tape[row]
    if missingvalue(offlen)
        return missing
    else
        s = PointerString(pointer(c.buf, getpos(offlen)), getlen(offlen))
        return escapedvalue(offlen) ? unescape(s, c.e) : String(s)
    end
end


text:
# This file was generated by the Julia Swagger Code Generator
# Do not modify this file directly. Modify the swagger specification instead.

struct RouteTablesApi <: SwaggerApi
    client::Swagger.Client
end

"""

Create or updates a route table in a specified resource group.
Param: resourceGroupName::String (required)
Param: routeTableName::String (required)
Param: parameters::RouteTable (required)
Param: api_version::String (required)
Param: subscriptionId::String (required)
Return: RouteTable
"""
function _swaggerinternal_routeTablesCreateOrUpdate(_api::RouteTablesApi, resourceGroupName::String, routeTableName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "PUT", RouteTable, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}", ["azure_auth"], parameters)
    Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName)  # type String
    Swagger.set_param(_ctx.path, "routeTableName", routeTableName)  # type String
    Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId)  # type String
    Swagger.set_param(_ctx.query, "api-version", api_version)  # type String
    Swagger.set_header_accept(_ctx, ["application/json"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType])
    return _ctx
end

function routeTablesCreateOrUpdate(_api::RouteTablesApi, resourceGroupName::String, routeTableName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = _swaggerinternal_routeTablesCreateOrUpdate(_api, resourceGroupName, routeTableName, parameters, api_version, subscriptionId; _mediaType=_mediaType)
    Swagger.exec(_ctx)
end

function routeTablesCreateOrUpdate(_api::RouteTablesApi, response_stream::Channel, resourceGroupName::String, routeTableName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = _swaggerinternal_routeTablesCreateOrUpdate(_api, resourceGroupName, routeTableName, parameters, api_version, subscriptionId; _mediaType=_mediaType)
    Swagger.exec(_ctx, response_stream)
end

"""

Deletes the specified route table.
Param: resourceGroupName::String (required)
Param: routeTableName::String (required)
Param: api_version::String (required)
Param: subscriptionId::String (required)
Return: Nothing
"""
function _swaggerinternal_routeTablesDelete(_api::RouteTablesApi, resourceGroupName::String, routeTableName::String, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "DELETE", Nothing, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}", ["azure_auth"])
    Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName)  # type String
    Swagger.set_param(_ctx.path, "routeTableName", routeTableName)  # type String
    Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId)  # type String
    Swagger.set_param(_ctx.query, "api-version", api_version)  # type String
    Swagger.set_header_accept(_ctx, ["application/json"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType])
    return _ctx
end

function routeTablesDelete(_api::RouteTablesApi, resourceGroupName::String, routeTableName::String, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = _swaggerinternal_routeTablesDelete(_api, resourceGroupName, routeTableName, api_version, subscriptionId; _mediaType=_mediaType)
    Swagger.exec(_ctx)
end

function routeTablesDelete(_api::RouteTablesApi, response_stream::Channel, resourceGroupName::String, routeTableName::String, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = _swaggerinternal_routeTablesDelete(_api, resourceGroupName, routeTableName, api_version, subscriptionId; _mediaType=_mediaType)
    Swagger.exec(_ctx, response_stream)
end

"""

Gets the specified route table.
Param: resourceGroupName::String (required)
Param: routeTableName::String (required)
Param: api_version::String (required)
Param: subscriptionId::String (required)
Param: expand::String
Return: RouteTable
"""
function _swaggerinternal_routeTablesGet(_api::RouteTablesApi, resourceGroupName::String, routeTableName::String, api_version::String, subscriptionId::String; expand=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", RouteTable, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}", ["azure_auth"])
    Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName)  # type String
    Swagger.set_param(_ctx.path, "routeTableName", routeTableName)  # type String
    Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId)  # type String
    Swagger.set_param(_ctx.query, "api-version", api_version)  # type String
    Swagger.set_param(_ctx.query, "\$expand", expand)  # type String
    Swagger.set_header_accept(_ctx, ["application/json"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType])
    return _ctx
end

function routeTablesGet(_api::RouteTablesApi, resourceGroupName::String, routeTableName::String, api_version::String, subscriptionId::String; expand=nothing, _mediaType=nothing)
    _ctx = _swaggerinternal_routeTablesGet(_api, resourceGroupName, routeTableName, api_version, subscriptionId; expand=expand, _mediaType=_mediaType)
    Swagger.exec(_ctx)
end

function routeTablesGet(_api::RouteTablesApi, response_stream::Channel, resourceGroupName::String, routeTableName::String, api_version::String, subscriptionId::String; expand=nothing, _mediaType=nothing)
    _ctx = _swaggerinternal_routeTablesGet(_api, resourceGroupName, routeTableName, api_version, subscriptionId; expand=expand, _mediaType=_mediaType)
    Swagger.exec(_ctx, response_stream)
end

"""

Gets all route tables in a resource group.
Param: resourceGroupName::String (required)
Param: api_version::String (required)
Param: subscriptionId::String (required)
Return: RouteTableListResult
"""
function _swaggerinternal_routeTablesList(_api::RouteTablesApi, resourceGroupName::String, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", RouteTableListResult, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables", ["azure_auth"])
    Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName)  # type String
    Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId)  # type String
    Swagger.set_param(_ctx.query, "api-version", api_version)  # type String
    Swagger.set_header_accept(_ctx, ["application/json"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType])
    return _ctx
end

function routeTablesList(_api::RouteTablesApi, resourceGroupName::String, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = _swaggerinternal_routeTablesList(_api, resourceGroupName, api_version, subscriptionId; _mediaType=_mediaType)
    Swagger.exec(_ctx)
end

function routeTablesList(_api::RouteTablesApi, response_stream::Channel, resourceGroupName::String, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = _swaggerinternal_routeTablesList(_api, resourceGroupName, api_version, subscriptionId; _mediaType=_mediaType)
    Swagger.exec(_ctx, response_stream)
end

"""

Gets all route tables in a subscription.
Param: api_version::String (required)
Param: subscriptionId::String (required)
Return: RouteTableListResult
"""
function _swaggerinternal_routeTablesListAll(_api::RouteTablesApi, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", RouteTableListResult, "/subscriptions/{subscriptionId}/providers/Microsoft.Network/routeTables", ["azure_auth"])
    Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId)  # type String
    Swagger.set_param(_ctx.query, "api-version", api_version)  # type String
    Swagger.set_header_accept(_ctx, ["application/json"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType])
    return _ctx
end

function routeTablesListAll(_api::RouteTablesApi, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = _swaggerinternal_routeTablesListAll(_api, api_version, subscriptionId; _mediaType=_mediaType)
    Swagger.exec(_ctx)
end

function routeTablesListAll(_api::RouteTablesApi, response_stream::Channel, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = _swaggerinternal_routeTablesListAll(_api, api_version, subscriptionId; _mediaType=_mediaType)
    Swagger.exec(_ctx, response_stream)
end

"""

Updates a route table tags.
Param: resourceGroupName::String (required)
Param: routeTableName::String (required)
Param: parameters::TagsObject (required)
Param: api_version::String (required)
Param: subscriptionId::String (required)
Return: RouteTable
"""
function _swaggerinternal_routeTablesUpdateTags(_api::RouteTablesApi, resourceGroupName::String, routeTableName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "PATCH", RouteTable, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}", ["azure_auth"], parameters)
    Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName)  # type String
    Swagger.set_param(_ctx.path, "routeTableName", routeTableName)  # type String
    Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId)  # type String
    Swagger.set_param(_ctx.query, "api-version", api_version)  # type String
    Swagger.set_header_accept(_ctx, ["application/json"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType])
    return _ctx
end

function routeTablesUpdateTags(_api::RouteTablesApi, resourceGroupName::String, routeTableName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = _swaggerinternal_routeTablesUpdateTags(_api, resourceGroupName, routeTableName, parameters, api_version, subscriptionId; _mediaType=_mediaType)
    Swagger.exec(_ctx)
end

function routeTablesUpdateTags(_api::RouteTablesApi, response_stream::Channel, resourceGroupName::String, routeTableName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing)
    _ctx = _swaggerinternal_routeTablesUpdateTags(_api, resourceGroupName, routeTableName, parameters, api_version, subscriptionId; _mediaType=_mediaType)
    Swagger.exec(_ctx, response_stream)
end

export routeTablesCreateOrUpdate, routeTablesDelete, routeTablesGet, routeTablesList, routeTablesListAll, routeTablesUpdateTags