text:
# using Lar
using SparseArrays

#=== GEOMETRY ===#
tetto = Lar.Model([
	1.2254249919808395 1.097291836779955 1.2026317426532434 1.1214764449420291 1.2881815375094732 1.3909191673306127 1.2826310624950579 1.403596973040044 1.0047654989725003 0.9544849952365216 0.980887788610001 1.0345235751527775 1.1697640454237979 1.301916913048839 0.9964908003139573 1.0989253984179315 1.1981031435393301 1.3231771722527648 1.4657096295767986 1.5126989887445341 1.5247466242851817 1.5512641578143602 1.478066615349083 1.6491712808697103 1.6026538933401684 0.7760904413287649 0.9236307522213864 0.8418715969503244 0.7091280120822796 0.7261721172212259 0.8375311502494822 0.8449941335074841 1.052734260528991 1.2616092255291365 1.1225901638459896 1.371097752369336 1.496925034305205 0.9209543996370461 1.072038135397202 1.2510808724127913 1.4084501623940529 1.6380705341015953 1.6022003842947727 1.6653723884663618 1.6781726986871612 1.5484703127586152 1.700842576258228 1.779538653298969 1.787156408180733 1.7390667271922633 0.6340150376647157 0.6474366615371009 0.7821346497827448 0.71317049270136 0.9081286762072903 0.5757646449030549 0.4691830644886783 0.5842344466268671 0.5364921982477023 0.6727039424660445 0.5136005409166768 0.6840367074407773 0.7890948183439145 1.0386132410807634 1.3177612386732027 1.1671428457470368 1.4311679854541337 0.9127607385899802 1.5227557020965947 0.7337318059111168 0.8680969259567834 0.9331859791175589 1.0602414415082024 1.19722253480622 1.4505729351245604 1.3386621242135883 1.6650102944806697 1.8256913871451164 1.7584511466826225 1.7461834019960347 1.8917704986036064 1.548235371022872 1.7345950587547931 1.89713866840674 1.8480386885399842 1.8720377998919753 1.9604944019181294 1.9798059122921996 2.0315733881690554 0.47239913639432307 0.6022799829100891 0.42322716841642893 0.4670748641954192 0.7835712129325768 0.4274085277186226 0.301989496989426 0.3027638259719725 0.2803843646372701 0.388220759927297 0.5194173254330076 0.28483445397296114 0.38977592931524163 0.5843050642226489 0.5166370383215624 0.7978199951633052 0.654484454257863 1.0228546544916943 1.3990999233511352 1.2173827612213877 1.4337988769029961 1.566058634721356 1.6703788819650052 0.8672784848597359 0.6858298813494812 0.943170736151446 0.8192171304903375 1.0052263546563274 1.1929722501601934 1.1804958979519735 1.315157870402483 1.5003684123836882 1.4882227008420337 1.7784244198575465 1.9513241764584792 1.909465100116326 2.1788690975113507 2.022966817641527 1.6488998417275735 1.8813314506315284 1.7725243919090095 1.9785767572368302 2.031041508475511 2.0082753214948283 2.1395953443277405 2.106672836635869 2.2275656452492587 2.157887977710624 0.4059732028230334 0.5617620172724536 0.6774892450993469 0.32652832766271755 0.3251829547637326 0.2298073509055593 0.30676714242190484 0.6362104228344747 0.17358819038711618 0.12479068526438311 0.08449337530369913 0.18560376196529735 0.4200836950109281 0.06988026105470074 0.11345521121705052 0.23448789488058416 0.3148969756282628 0.4229944757622349 0.32729117656909334 0.5491527087264803 0.5318392528127002 1.0912817054013713 1.0036757043760636 1.1790147834582976 1.4695273418074644 1.2589640047246309 1.5641065445376305 1.7295138134722465 1.8472755075230791 1.9245875723317345 0.7623056096502262 0.867108655927103 0.646526366991186 0.8055050582444955 0.9129144715545766 0.7604290746553009 1.0959831220016096 1.3062022604735781 1.2810826508509232 1.6213926891477377 1.3981455061915493 1.5518216652808825 1.6631731804212595 2.0787850520796276 2.0929951198697165 2.330895577356748 1.9016581862633821 1.8860604649139003 2.2245645850434674 2.231383818511739 2.3624170447406247 0.31962847441100206 0.4541962473850458 0.2509839379110699 0.6076281153756563 0.12711445414084943 0.1919672908483109 0.0488463119856809 0.10023660439484658 0.06583758767406697 -0.05174533541001649 0.7334649179239641 0.017744650992189234 -0.1425006032288677 -0.04582848246671217 -0.045730331247371435 -0.11320868358605857 -0.01622701971992148 -0.02635396492635489 0.11190582511915573 0.1842238726717845 0.19628584795644974 0.41882260500745505 0.16832492951109387 0.16662266728438727 0.29464166097937006 0.5349302503004825 0.42134048059987006 0.5718709390046326 1.0740579403017925 0.9585481980291187 1.1919452336065346 1.3535685135089084 1.661860791428133 2.111294382257396 0.8327343883948024 1.003623357469419 0.8293733015899964 1.015653600812358 1.1498297114983698 0.6413779638711208 0.9539299832085387 0.7698501665482695 1.0853336567454823 1.1970639186481817 1.3208608574061915 1.4910969088610986 1.4335532903787331 1.7543634194743747 1.6762906371508426 2.3607348839100593 2.4413624784257033 2.4962447585513576 0.17502804124162383 0.16477961966610052 0.33771523120108604 0.4941274795698595 0.5849690330448136 0.7076314121203681 0.033337810120005223 -0.03241537259490289 -0.1242245585640401 -0.032247214222539095 -0.12477040369201187 -0.2576246696174511 -0.3777396687460296 -0.25497095637822087 -0.17566715562374707 -0.22096958849624607 -0.28799718415899644 -0.14726787113836726 -0.14916741035058947 -0.046518807158628474 0.07916812850420402 0.019789462727840212 -0.042210820388775785 0.06259158334428544 0.08437754298318645 0.2919385348978224 0.33020477356616296 0.47031397221883287 0.44605022201498445 1.015155958104324 0.8243151886241742 0.9755643085487239 1.2205238779355712 0.887888665350083 0.8810443504930142 1.03114648834227 1.1421968671706428 1.208968894811712 0.6364258095942966 0.7569665913831622 1.278664093803958 1.3459875671994885 1.5575521003729134 1.5382133667731352 1.4684334889345765 2.658031688110081 0.19853071000937908 0.06354159916100502 0.05036201717728708 0.30996008221140614 0.47799253461296143 0.37219656003261425 0.5871099180779188 0.6960959942710117 -0.20715468504458723 -0.09006107238054756 -0.11381073109311893 -0.16862934434665344 -0.2543318543631106 -0.37208118982534133 -0.2684227806906695 -0.3954130768085905 -0.44225022401422287 -0.5672303854515137 -0.5200480970279708 -0.4798659231554697 -0.3243368532617441 -0.3509316333377429 -0.46742439772130684 -0.43024695746524255 -0.2803177434169819 -0.29573770026474555 -0.45515693154981174 -0.17656553086415622 -0.14524365362363292 -0.19175611477366938 -0.1720898570523391 -0.0459776100596187 0.1922369312409619 0.06350086103351377 -0.07625876308314745 0.1803463699860293 0.33193882127628294 0.2660444249894196 0.532537834649029 0.4077889632678362 0.8048773612157316 0.9901390403207883 0.8321216527486135 0.9649733918277971 0.6952087678364154 0.8129988524751086 1.0912431092543335 1.2926395302201183 1.1705856028835917 1.3417461606758347 0.5850182858124677 0.12801363273239816 0.06721149052760997 0.2651735186921296 -0.10349886745433244 -0.07974121957723576 0.4664544178997937 0.3350621604341998 0.6140707760195768 -0.2997944027194903 -0.36928692703463717 -0.3882008422761417 -0.26225366908600417 -0.2975585685650121 -0.4960030853471986 -0.3833379075368768 -0.49241962904763703 -0.6073002933130596 -0.7080809282659365 -0.740308859495826 -0.5960932349476625 -0.5893982940404939 -0.4772013507642795 -0.5814778396058473 -0.5558332039957969 -0.6111337271451297 -0.4786797232978732 -0.30372518458431075 -0.7174322380153232 -0.7044754856104929 -0.5981377250542323 -0.5405669369626016 -0.37893959792589127 -0.2694169724621621 -0.38098090764717585 -0.29532098865293743 -0.4281787350446058 -0.2681229935071491 -0.14391098177612147 0.01999884155330872 -0.2591331457525659 -0.13471419723974964 -0.03208343586321072 0.12527530530958042 0.18284665028456518 0.300219520005815 0.4075442544518687 0.49586242732283037 0.7649286832377684 0.873157940975665 0.9576306855117155 1.104092639391348 0.6050728109085592 0.7450253426043771 0.7438509763525045 1.0659511326602842 1.2458472551295179 -0.02880800232244217 -0.02168389527353108 0.09683542145985194 0.24804665184303912 -0.31575619912029024 -0.1841119614546743 0.4148317217038652 0.5446273324184966 -0.4604900815597083 -0.5418138696640266 -0.49861799839224663 -0.641273324095111 -0.5338631074338867 -0.45484666018451103 -0.5906753737333692 -0.6171283833900946 -0.7816798784765767 -0.9576085611248958 -0.8669896660514523 -0.7400229198383835 -0.8600981978967457 -0.8853406224102977 -0.850841087788374 -0.7122834171780207 -0.7056827830129551 -0.7119629613266387 -0.7981167849561362 -0.933950071025245 -0.8640293334739861 -0.7767568430849641 -0.6394881714729955 -0.5126129259263383 -0.5578693728273085 -0.3977102433114803 -0.5896632754660148 -0.48783801811267313 -0.3880780699494317 -0.15009006357489918 -0.04645058830967475 -0.3857847264687203 -0.25597071692948814 0.054969341402147764 0.2802438584003696 0.1122914905938727 0.5829006184661749 0.41760450186559905 0.8550757784185142 0.9832966433857028 1.09524224895195 0.6458415573728084 0.744504857233464 -0.14381059235964994 -0.2465046246575074 -0.10469594821261088 0.040277941472121964 -0.2670187309564718 0.19616396456987314 0.29943435279757313 -0.3751457993390267 0.42599012724519336 -0.5530058705947244 -0.6311874384269475 -0.7091557828633903 -0.7639357032244226 -0.8425934730425956 -0.80822516010355 -0.6958097349598383 -0.7939980321542103 -0.9908858697594716 -1.1022517245363588 -1.1130017933540919 -1.167217020270667 -1.0891205489476412 -0.912941610344795 -1.0101387354564273 -0.9530279142913606 -0.823238568405967 -0.9212263329397256 -0.8525188575569405 -1.0331720458253706 -1.0187822963796809 -1.1077628426200765 -0.9974793604930753 -1.0602629363213187 -1.0144908984924332 -0.9168723066029073 -0.7854743411016368 -0.8191133045286014 -0.6588098449495622 -0.7482571797930743 -0.7085642089851907 -0.5486277161759048 -0.5222262613242327 -0.31375893701592994 -0.18975909886175368 -0.11598561809408192 -0.43405105819220346 -0.04949173374351857 0.191069290832427 0.13453898045396226 0.32803682618614105 0.04388069640251446 0.5257184835627818 0.7674689100942879 0.42049362817096825 0.265344665327812 0.5884023766877395 0.48900864550251666 0.9259916936091309 0.9577548924661067 0.6935990024065312 0.843584504641177 0.7785748936214335 -0.37343345967028074 -0.4265539335996461 -0.16411694824482256 -0.01797417548128001 0.31515114030146163 -0.5056833111525182 -0.7178389255261983 -0.6837904579597404 -0.8225045707541284 -0.8762527842226912 -0.9444820012995341 -1.038859193537628 -1.0936986578322032 -1.0461635391432078 -1.1730785913851107 -1.2757157032513526 -1.3481150347724522 -1.4485017799576423 -1.222241542092237 -1.1692618960111354 -1.0729496738023205 -1.2579539967101367 -1.1068332387435724 -1.3863080644081007 -1.2657480166392623 -1.1781930134996181 -1.2360345125468264 -1.3313776884315245 -1.2329649446784072 -1.313517573904597 -1.1459773337395247 -1.2585683814942858 -1.1803303862197758 -1.0472935149660716 -0.9544005424633609 -1.0222593339631505 -0.8892774124100562 -0.8599972944724951 -0.8319580476888507 -0.7214345582627737 -0.5792143749177966 -0.42613946018496884 -0.3386634278736791 -0.45652853159785156 -0.22020367682256453 -0.09317936768781818 -0.2255224657946484 -0.14268737400614306 0.00214824747427092 -0.03769206267620705 0.0979190796756916 0.07227917753675847 0.2187450513125471 0.43346338160070896 0.354307755386684 0.3570129160932555 0.6183840321815968 0.4746874790098634 0.7549675622114859 -0.49799710225731686 -0.25938936718475913 -0.6074949249010946 -0.6026757485639109 -0.15968183073711895 -0.03637197481198742 0.19675755189010433 0.13738648960832808 -0.8826785775049498 -1.1618776586258002 -1.3459467873114863 -1.4791436667684088 -1.5420184329012492 -1.4902420788482664 -1.2899769401228072 -1.5902237212545476 -1.4787943490525204 -1.3871757038732262 -1.6575832960519206 -1.5087483637142238 -1.5241066347017407 -1.3603114658315127 -1.6489229216738255 -1.518183292066585 -1.3958534490267214 -1.483525483713459 -1.534660197966908 -1.3877790047142766 -1.4370710887730138 -1.262196099519874 -1.3881141003939124 -1.1546503134643848 -1.142053684367998 -0.9886556685331316 -1.053334638886306 -0.9476926542014786 -0.8273645389787928 -0.7134231383861402 -0.5575385394529435 -0.35287391329122 -0.7438612049063814 -0.60579702121405 -0.4930480535335804 -0.34504159647414695 -0.4820413349924835 -0.3811728510351222 -0.25703148894717587 -0.3523270081565335 -0.16671548638874947 -0.05892563395360157 0.18772770518979556 0.03578994155800819 0.30736900830616853 0.2765062946050305 0.4000410147163591 0.6391975184997638 0.5607102201226034 0.5792508819266021 0.07590547074049095 -1.736953376917892 -1.771993466349348 -1.6424812355944642 -1.8327293284249206 -1.9122437394078604 -1.860367788294335 -1.7278718358251328 -1.6784916780428476 -1.8532111997125476 -1.6438949987026503 -1.6213403324741396 -1.566062663090403 -1.3081051743689867 -1.4631891956224523 -1.4197146242128516 -1.2656236169233177 -1.2101930714284874 -1.0885129110051657 -1.1183031903140224 -0.9492093019463691 -0.8387861913267983 -0.910176808976934 -0.8130008990281431 -0.6614668779047358 -0.5989237270390518 -0.5011655066032028 -0.5307569239552614 -0.40624243739041865 -0.31493342088577836 -0.20907757035114444 -0.1428388362335534 0.15979762967456493 -0.030672403776931173 0.17522747110973305 0.30600713213128294 0.4393527647607264 0.4876506354460838 -2.125523428513515 -1.99451319525237 -1.817894080811043 -2.0215067915293146 -2.1720619135518837 -1.994514394625786 -2.0101061614718057 -1.9012840670095557 -1.7485608687034013 -1.6954502474609685 -1.9228980775018063 -1.836381517306762 -1.683772502255235 -1.549819778085218 -1.4940691406962534 -1.3165040264402375 -1.5623973979502848 -1.208172473618166 -1.2834347683004008 -1.164150579356638 -1.0226324903975612 -0.9482862415039881 -1.0677111727968136 -0.8659311642781948 -0.7219554396559594 -0.7642788307258522 -0.651707070663754 -0.7061612767554369 -0.5391012975848304 -0.3937952039566147 -0.29400441282721235 -0.18270998931415292 -0.05605715566517788 0.1145925446702672 0.10998726606564438 0.25385342339718964 0.4053225029669456 -2.29675313644073 -2.3163927814899026 -2.183566102837216 -2.0240360513463607 -2.1736527769590426 -2.0843481871353955 -2.15222401704571 -2.21035286965177 -1.966138992102034 -1.8710540830851066 -1.7198899523503672 -1.7957104507852075 -1.6155651108377458 -1.4276263934335023 -1.6869714284486705 -1.7547685340521777 -1.6230039338018938 -1.4576225814899726 -1.5283703383082252 -1.306321831398493 -1.2235681844932933 -1.3061003301713412 -1.1300461339118564 -1.0455399549550206 -0.9389890782686207 -0.9597818847414413 -0.8342343311033928 -0.8559560133736617 -0.755833799939241 -0.5946393757630414 -0.6003386038601921 -0.46128140622164304 -0.1525542963423815 -0.34778077045188194 -0.037013796692533435 -0.19583200842995047 -0.04107657146930441 0.16055851820227376 0.3378133077518868 -2.411497845552161 -2.283745107799689 -2.060018327961994 -2.463500038409654 -2.353072868691782 -2.1519400266071718 -2.28193886888226 -1.9408188178462267 -1.8425194539605616 -1.6106871403587537 -1.389978769642733 -1.4415907779538675 -1.4717476920477728 -1.3080983310184686 -1.1988078628376813 -1.0583396546970292 -1.1652907933895407 -1.1185506300411008 -1.0257888792212644 -0.9094615207508162 -0.9657155833514431 -0.7371913990942462 -0.6028791084991361 -0.47311108496746823 -0.3552495691009905 -0.48559988131724463 -0.1895509092756652 -0.12478790249476462 0.30567036571180384 0.2584744337732884 -2.5877461270515325 -2.520964354025203 -2.39387780214686 -1.9824005543748373 -1.4279635775341906 -1.2874396162342785 -1.421526368234336 -1.2735542346072926 -1.3458677952463787 -1.2098372960680546 -1.210268401040327 -1.0475825496203937 -1.1192616345606454 -0.8148902536434922 -1.1629227950349357 -1.0367366427594755 -0.8800264920771373 -0.7221685559506478 -0.5999290997744523 -0.38604260777735244 -0.5350189249004202 -0.17080790492281464 -2.808788233212695 -2.589097229645123 -2.408543660275746 -1.2347309596953222 -1.008156809301855 -0.882831892370345 -0.726667811624835 -0.5154465562577054 -0.39705703707868145 -0.3075562839824655 -0.020183889567680163 -2.655539837795515 -2.737911814283442 -2.523701107453635 -2.4900157302399073 -0.9902601220604111 -1.2734911668746258 -1.0798748975141377 -0.964461271799738 -0.6196048244950629 -0.507352352922202 -0.3391258792108178 -0.17549928648394816 -0.03874147232878136 0.08838845222795572 -2.6136871118893112 -2.714845487193237 -2.5591900581198344 -1.5359049881020383 -0.9277275838611836 -0.7460388340680112 -0.3646986979054313 -0.44854965745950026 -0.2861235722902262 -0.17178460846548044 -0.1918506569883514 -2.62654042266658 -2.694667343819069 -1.7307638963233425 -1.5727626046981937 -0.6573192955969906 -0.25764226432549703 -2.5979029625368026 -2.8336994922236314 -2.076207409245126 -2.6732927519318577 -2.1782935031721404 -2.5614653452210954 -2.4692223018564734
	1.883580212357888 1.8100072384201376 1.6081903999786615 1.9656062296800103 1.706951466049337 1.8098300895272357 2.0026731212962265 1.9426784635260832 1.7032467434119487 1.8325992632063173 1.992308578425395 1.5761357050553126 1.4827516533642164 1.5003345949136608 2.1211191325532512 2.1968332403566353 2.1074061813080975 2.1514549037511137 1.5882184931121808 1.7177300466824532 1.8512371995886125 1.9799932426355658 2.1263990008377323 1.8709575692027793 2.135201600145669 1.5234223386422585 1.497695543516469 1.7043116809839371 1.7879469804148758 1.9184523476975759 1.9791395352894408 2.1128679961082164 1.4332422368791915 1.2541790140239186 1.3226750203892692 1.3359316801590617 1.4543387012920135 2.25584790503806 2.3348789550806615 2.30691185531261 2.258087294813334 1.4339179166861202 1.5969835754167416 1.7390592589328306 2.0204526416436286 2.2836031289306558 2.271780072454751 1.8046376847032506 1.9344444043082696 2.140399057823498 1.392395500597965 1.5221030476046573 1.3804334027511167 1.6489571705958803 1.3459360269241782 1.6387632454863728 1.8329748173003142 1.7694838640268877 1.9441311296960673 2.0572381969616713 2.0811746222881298 2.2058895227905007 2.278413261311873 1.2086753997162 1.1357502340850631 1.1634488363284823 1.2184615477808913 1.213255625641663 1.3052530791212684 2.397240996312268 2.380414327888386 2.4934480666373964 2.5369817562724863 2.4334778407435844 2.3796550193015995 2.475688827733516 1.2868874569515287 1.354231847755031 1.468604726796969 1.6214693430073617 2.015249271373733 2.459484331834364 2.3981605605732255 2.1689297898014104 2.299384880210691 1.6109013649454835 1.7031209540991774 1.8857841125483668 2.010172182604743 1.253578428223682 1.2480238236501402 1.418985828851862 1.5444257513509265 1.2246541482313626 1.7025831769123678 1.6893825854069668 1.8222684764091928 1.9675822490543364 2.032993877993042 2.237081980753851 2.1542928990700556 2.2637576618999686 2.3620139269381686 2.4762043669972273 2.512274298552778 2.51810463410122 1.0613031139403828 0.9164271323921527 1.0410645030603018 1.0557805550814614 1.049406255381957 1.1240625421109738 1.0910230665043874 2.655784942443903 2.6244516496030816 2.653969463141896 2.7374684832062854 2.5798456406413166 2.7176047759016853 2.632939498875762 2.582057247847993 2.730972280278346 1.2101081472321908 1.3590461703949321 1.4861174270889694 1.9868160616372526 2.1628541837882653 2.567314673205651 2.448038558719611 2.611136118186768 2.3111625966274705 2.4403863059154927 1.5670214667550133 1.6086776401897733 1.8147168230796908 1.8576739123305215 2.129825608472862 1.0588687016375384 1.0887619170078564 1.1411183466602597 1.1796550425867167 1.3254691167930293 1.4187961293108806 1.5317645084857296 0.9709773616821398 1.6391683774839474 1.8307877028830069 1.9671204344922937 2.060681896091673 2.3984302169006124 2.143316061256652 2.2816067820991623 2.3571176639289555 2.511830158436164 2.5833625242274314 2.7385125497270217 2.6224425337864323 2.769789681125541 0.8170134052678666 0.9237182733104685 0.9088897272363938 0.679654544103288 0.8033696954372727 0.7849474153954108 0.8221533483825727 0.8705384954444662 1.0191906447908279 1.0095424264563366 0.8884428375288802 2.859125827059129 2.7831150529902193 2.8708277148879056 2.958570987426414 2.8423454933802113 2.771961944927956 2.9574071093374474 2.6985638790031268 2.876933246932283 2.8902751435524965 2.8279472406065627 1.2087848540684523 1.3728910736212403 1.9438294514355563 2.586698125569701 2.7169015355792903 1.479167730910759 1.7175706824925034 1.7235987736343734 0.9211887465750443 0.9204758388010503 1.0388741302110296 0.8457054999202771 1.1274344799360891 1.2413713571504559 1.2612988957752582 1.3825075348854532 1.5308001286186514 1.6495279564371583 0.8551173349303198 1.7542587807260914 1.815640413762654 1.9069689786714386 2.0540186082088097 2.1752823769416683 2.2587674603405454 2.4177032711136435 2.422823343022232 2.5344898074534794 2.665521144964578 2.8462643285290947 2.8180352614548876 2.957185810539947 2.9881841255306196 2.923824404163362 3.0815374794753794 3.0463000580400887 0.6834059038787572 0.7576538001759858 0.619854559822214 0.5991810078682298 0.6738457310377157 1.0170423944298268 0.7612535917116738 2.955669225026641 3.072048430775256 3.2446958067805793 2.960773566758689 3.1650507876570133 3.1313186238938155 3.208783910354762 3.079522739192124 3.1443976374300386 3.1247893154129396 3.006908673834945 3.1886450854599806 2.915043433351877 3.038017921453353 1.1077594869982184 1.5075711824602367 1.20552294736089 0.8103907858891541 0.9392764620468841 0.7882326152284778 0.7564636458170901 0.6603609483399531 0.7052015224250434 0.9580530636515399 1.13967222073697 1.3507687049644406 1.4442516039968563 1.5460096358338553 1.6655776807888218 1.834013887009072 1.888896937334278 1.9900505533240613 2.1138976295336223 2.287883675599034 2.35574680409602 2.5513032466853316 2.675114275056389 2.608472910200783 2.7882701500305385 2.965270007003638 3.064664448285598 3.190567509533493 3.129334238104923 3.261974504449155 3.2270297209585257 3.36188506731139 0.4254780455983753 0.6275359802970071 0.565178880748618 0.4631697276809881 3.2492977315120113 3.4163877427701053 3.375439388032551 3.279959217275689 3.4153495888414374 3.296074980654065 3.359831490079658 3.2701841787173866 3.378864675722581 3.1231388394316153 3.295473204699302 3.41559579886322 1.292426499192757 0.5686449581393869 0.6811335297448848 0.8150653036427675 0.6568507779950443 0.5888671874113114 0.5184759961867322 0.4799378310976552 0.5404364359440739 0.7917927462981571 0.9038287913205463 1.0409666646747266 1.1625640270710105 1.3047144513113487 1.4463355537156652 1.5326797645001196 1.5796846714898412 1.7122613717686859 1.7142714033631723 1.8333522870150327 2.0049500472159574 2.0172062792779175 2.1729168207919365 2.2856676569441676 2.4127686684988756 2.429721586444657 2.5690148826993213 2.731814189783428 2.709090649443722 2.8677590496428387 3.012499925880684 3.151331171245766 3.1643879286309113 3.268990765015679 3.3496072856587316 3.4037401195109225 3.4250348130853547 3.4338287377990824 3.5548821360420515 3.4581316260166126 3.5787416729399406 0.3478315301257391 0.29948078054095095 0.49895505448043753 3.5103518634079824 3.4839652346890997 3.578353447909873 3.53598259938707 3.519688692429951 3.6361557791631274 3.636731319704566 3.5733632734582796 0.4308778557627928 0.5494722566509931 0.4549587014863974 0.635618712752867 0.7739905233438287 0.4076063811248929 0.34441932756500826 0.3519067500429558 0.7044692770062975 0.8262202341500922 0.9652863418790787 1.0292483401112804 1.157599814569156 1.3573863366440364 1.2677113910175866 1.489175713683897 1.5912360551610945 1.6728413305925904 1.8672204338218077 2.0778463975457595 1.9476695671145676 2.147286084812849 2.234651924770434 2.3999778814591224 2.553320277820285 2.6040554880960114 2.7060099208630275 2.648169338027338 2.82364182524 2.693812612245514 2.85210122809897 2.836407148583785 2.9066714117470167 3.0053975507327984 3.102225590592459 3.143286230165469 3.317808771519487 3.2779159741124304 3.481353442322856 3.449803637363702 3.5270154770217577 3.6143231281184596 3.555998879647762 3.680287777101308 3.744465026593577 3.807134871620284 3.6687901099319618 0.19836312528190359 3.8129395342530494 3.6611672858139013 3.865423449309658 3.7304021338843008 3.7053668419176393 3.838795609207174 3.7453293180822396 3.746288082597827 0.46496804506349276 0.25554773350551185 0.29278774386530904 0.25389455156616014 0.5749829489805021 0.4763087049646675 0.23579716257257877 0.23919945953022026 0.5831175103384783 0.7659650782386676 0.9070641193605602 0.9432384024405498 1.0534345362846025 1.1529597874705564 1.2680463978017706 1.4503229806714415 1.5490215405218042 1.597068891691795 1.4373818326237946 1.4113650174927572 1.6973156643284115 1.8246987278590385 1.969962604934139 2.0257389432481197 2.2055370065909035 2.405912269465221 2.5293401347751705 2.594390563807206 2.704373064489971 2.9430052030819396 2.9371410554179316 3.011572329346522 3.161442657729941 3.2730287660831983 3.3040412251306344 3.382458511978891 3.4588314867104564 3.698319777588946 3.77663183518182 3.596979814574399 3.6028857685780307 3.8623498152735416 3.895982978517573 3.9785014183032517 3.8628094212204767 3.94216533611663 3.9564036341817506 3.941504024248055 4.0824878093148875 3.982296491557943 4.060126240596958 0.34495544579418125 0.16112144593850486 0.15702470445152183 0.1360115021793109 0.30886149077125014 0.007965159361464025 0.1325849454312551 0.40629159471113807 0.024394194495112043 0.48585670421481364 0.6387761847862983 0.7777809012643022 0.8983978283577099 1.025570875591739 1.1537684011088096 1.0899558794584365 1.2923663123616973 1.3779399609902436 1.4427436793267343 1.5728587661398539 1.6927612273604242 1.8313043622730891 1.2543948420515394 1.936789521200721 2.0608681371005986 2.1557616206735855 2.284262163304337 2.3931142489752 2.369300902761798 2.4969810427931045 2.6414852351350855 2.722628575721052 2.8417380094149265 2.9651396764475972 3.0694411741010157 3.0751367585301135 3.211824959563632 3.083967113298817 3.3197522097893764 3.4960913173937973 3.5045648505282996 3.636262199483881 3.78699285436362 3.8399814833426853 3.950866944620614 3.725845145044731 4.066116674916661 4.079389063949895 4.262637849742389 4.0403726484727045 4.174799347644855 4.06171732472495 4.18759112937045 4.142097983163467 4.245528305829557 4.180063132474858 4.413875333986287 4.082349827784512 4.216241379634089 4.296656910028741 4.29264957960198 4.414644719348978 0.12414614110551137 0.24857957923969076 0.016317472961767887 0.015378375589627069 -0.03501874579530462 0.3605141598944481 0.3389411192341574 0.5219656268097905 0.5721101839939444 0.696743143213904 0.8506272408953592 0.9819421604580383 1.1410233345184546 1.261788269026564 1.2563368681137714 1.4470147154419195 1.5753071504158014 1.804122884497801 1.815748827696777 1.9697385359324822 2.1283907646585023 2.0873998680846615 2.2674496389372205 2.277715191317099 2.219492731560189 2.392762076029828 2.5238422212494718 2.7076799859951466 2.788888687979227 2.9356318327557505 2.94637677851175 3.0515948530377606 3.160220838959801 3.116733837349866 3.217174074419714 3.3527624107986007 3.3582476247378086 3.493883620050703 3.6443978197693245 3.7126625194388083 3.7962682089871644 3.8618004449884484 3.9525355034563177 4.006615003023077 4.0677679744132655 4.195768976258889 4.2051124253486565 4.317029040103938 4.30842898822789 4.445521024182276 4.390324400621786 4.518012126470452 4.444742048449791 4.287082689637427 4.403509642340918 4.538877493409369 4.461053856149409 4.602207292312656 4.544348915658898 -0.09213886186386011 -0.08883156421235139 0.031115061184974646 0.17151798363688053 -0.18996815719057558 -0.11481147996867325 -0.44974598542797795 -0.33342796686767695 0.41352784324742986 0.9529215341111608 1.3223922243249502 1.5797870278560642 1.7088616418656342 1.944748556004012 1.9358713329267265 2.0702521937837317 2.1584580136393887 2.064770828792814 2.205070376413408 2.3699869108529246 2.5213113983481916 2.5692078260081352 2.7269099367895966 2.783272637025943 2.8229450651643613 2.9635939646436023 3.0810653609250096 3.0439939969475662 3.16783501650458 3.2607830952998857 3.3048358469746155 3.342070358940077 3.4888551069066542 3.4820563613440667 3.6152073982610515 3.7515320144474407 3.795203569568857 3.8936682937201645 3.9241042973591727 4.104934717169509 4.086446787604069 4.045973596906326 4.145352308924848 4.248838639855395 4.293355706165826 4.405783560818102 4.428855039895696 4.536716901613244 4.524509180021502 4.597897275186261 4.5842276332530645 4.696764747307787 4.819057548919256 4.672115677640454 4.714386056483718 4.634959547047679 4.744218791226102 4.872503464057274 -0.2171655463366764 2.081377602424839 2.3903686212696997 2.5836163385804163 2.5315021810675358 2.6472533616992897 2.832179347114239 2.8644301225817763 3.0306336370849523 3.1822698153727553 3.1649240559752005 3.2947101646357515 3.410861856599431 3.403829071275119 3.5017865856764994 3.6290265505812838 3.5260725678373737 3.6442902707282143 3.7501172566101726 3.882728944886952 3.8927764197652484 3.9499903634992566 4.06928720405846 4.2098817974303175 4.189140532311228 4.399415173712918 4.479787274512126 4.64048822771838 4.66175966438575 4.762410271943236 4.664326094742082 4.772446809396551 4.742757345363676 4.836036609100452 4.87298598182859 4.956380213025557 4.843038046157661 4.968694307778295 2.846595003289717 2.8396114678881106 2.9614188745996715 2.9676147054589217 3.091839655550464 3.0941052164951848 3.223300347720261 3.306232970241807 3.302081716760819 3.416654586210528 3.4729337888940726 3.581183694442909 3.5739859956449855 3.633467735135802 3.7533416463121068 3.7356273932740587 3.9241869543170793 3.7952893969378563 3.905651123708069 4.037806112105043 4.0100567916894 4.209243160147734 4.169017006317894 4.346917058557681 4.344399138671567 4.483235618089271 4.539524725462804 4.790800703520394 4.770819741671682 4.8849858058962745 4.967374375335041 4.903523249730637 4.970853351501541 4.991170579164244 5.124887102717411 5.090302491555503 5.075034033788024 3.179973208556299 3.4151667090718716 3.272079070817493 3.3558527330799315 3.404035243775965 3.492189258510998 3.613757689559643 3.7432094699777103 3.610800681497656 3.7198436154885437 3.722926606900004 3.8385230159865245 3.8080908612980564 3.8660598742520733 3.941379764616718 4.0889992913231055 4.088374617811612 4.000061802299629 4.178694991956754 4.053202584882266 4.162100596891398 4.263842809617886 4.290353280049814 4.387114871562963 4.469393418997039 4.630992540959994 4.644763763302622 4.773410138538177 4.928966289810335 4.897053310236954 5.048722327905271 5.01324560463921 5.058613264837384 5.1024874596554985 5.176875275965461 5.19147284060743 5.319349179048677 5.262164664002979 5.190282206898329 3.592113584128878 3.6404829129956155 3.752861694680025 3.7396181200395313 3.8018115371254395 3.85891257748223 3.912924451904752 3.859973865292916 3.960619592993324 4.356546092425265 4.166881697021209 4.287077883137091 4.426009830267564 4.4028325314160135 4.4789794045703 4.540721797127826 4.62874650309824 4.750120763157779 4.833494648669598 4.901660175738502 5.111037354941615 5.056785472123435 5.178954669260248 5.1588373720031235 5.252272993404908 5.293084569602284 5.33561497726484 5.4480007874237515 5.319221219167694 5.4511221464616995 3.7514711077014526 3.87387769711846 3.9799101718047725 3.9847022931387457 4.545406313662439 4.580659962612685 4.713638675369589 4.732602006210977 4.857466034886162 4.882975812350937 5.047263471048226 4.997093333213202 5.182761247592352 5.200443389763306 5.403932579946914 5.336521062257451 5.315880145621311 5.2963139570315505 5.368435036516675 5.392871997311851 5.540378327644381 5.570496318578988 4.190461106679012 3.994304863753344 4.108607353235672 5.6230295800625445 5.541308607272683 5.451967254396556 5.530555865568764 5.672679032604359 5.53437034586237 5.634117903890723 5.671800559012036 4.164092351597052 4.294904262727434 4.179010806072018 4.299896876966884 5.678256366892653 5.857611316154184 5.818439864787793 5.87366030168285 5.807599004860926 5.8847153758931094 5.777829891308187 5.8376523698918295 5.851529909349084 5.780595605509656 4.315006593325613 4.427432156210835 4.429291794534809 5.729896425363332 6.025997418500032 5.894885195303151 5.950540248925954 6.103121255066086 6.074842347550598 5.986508097576615 6.170474700849567 4.545597699785511 4.665016588548986 5.496001636006797 5.587496644467107 6.134203867347846 6.370029269951754 4.757436963604797 4.950494688375642 5.368799955578808 4.985722933632113 5.301216908591874 5.039624372769821 5.1497359772391835
	1.7761662584818718 1.7280608329254799 1.7290187417589036 1.7579894183165328 1.7684399236968564 1.8134678128453743 1.8103318674152933 1.8367013131513332 1.6854328894555135 1.6898338903338925 1.7210125884941438 1.6753905057985505 1.7010009558127832 1.742038631212821 1.7445031506024913 1.7854463969840682 1.8011462876607964 1.8440179973728341 1.8026249086566777 1.8353506923710403 1.858497760286327 1.885155963467524 1.8853979737361577 1.8976013163284642 1.9229426112928054 1.5924422267309768 1.631585216355463 1.638194379369893 1.6118761694561554 1.6360353711286968 1.677364470775953 1.699210159284464 1.6596663949826445 1.69409613155246 1.6637247158110358 1.7379801699901616 1.7920107190524481 1.7423467217932371 1.797932786574417 1.845912043854099 1.8845166789304408 1.830073717227854 1.8436274312123706 1.8829101237378703 1.9280333728377905 1.9290104942841286 1.9716049095719577 1.9257756125742462 1.9470893621462906 1.9633975893342495 1.5318275251929507 1.5548153629670556 1.5731641442069826 1.592604025252207 1.604747745612068 1.5511250366742593 1.548686958256727 1.5728211493905777 1.5846244873011164 1.6408967373772387 1.5981259798783212 1.6660638358083582 1.7073010419906045 1.6225192597065385 1.6930106023698783 1.6532621164588683 1.7381757131464703 1.5865753917096337 1.7775927019336248 1.7086748314700955 1.7452937983668955 1.7808615875825913 1.8242340378757333 1.8488620895182 1.9146577884688738 1.896225110422343 1.8162807565555559 1.872939889097847 1.8702025079753932 1.8891227275891072 1.9894157060350084 1.9548179724316412 2.0000186803784543 2.0135872617631247 2.0184939561900395 1.924186222382494 1.963490772068172 1.9959832037060845 2.029345443261356 1.4643812635866285 1.501353856395034 1.4744092348955815 1.5056219055791524 1.5506637074666323 1.517348986324505 1.4789153067071243 1.4986909220140394 1.5135581745078062 1.554557401678107 1.6227556785310298 1.542322037256627 1.5889601116214458 1.6600153712178605 1.65712668213595 1.7442455899153957 1.7033988201643746 1.5962526095424858 1.6844096377635984 1.6498744733980981 1.715007383734502 1.7525515439215915 1.7938878060577936 1.555359005136279 1.7327746823986039 1.8030401177823518 1.7713175931954253 1.8377228196586939 1.8691592296265767 1.885796418354323 1.9125212658779485 1.9589237893251437 1.9772984482709786 1.8379835781042013 1.9102019662482106 1.9167176217378348 2.068766040448547 2.049304042035561 1.9999711627981944 2.050050824235222 2.0423876987067 2.0582077227936972 2.0924842643364734 1.9573698774091848 2.0017069108356367 2.022440575261701 2.063935125801952 2.083701150510291 1.4164082378935656 1.4661340677702368 1.507508495704409 1.4110633836672533 1.4321242645877104 1.418104400463704 1.457116452977651 1.470466788239296 1.4341684278879074 1.4481616791590464 1.4564943005062463 1.49967798011728 1.617591554619705 1.4781646014648615 1.511188538393704 1.5575131364133312 1.6036702253254562 1.6456459124236282 1.6406261726446323 1.6881020768675847 1.704742473408825 1.5802217949488226 1.5704307190316533 1.619265328141353 1.6700667719196922 1.6270029218026316 1.7130760931966256 1.7666763385691846 1.8080584500232666 1.8524228346040668 1.512828849696729 1.5255057658647009 1.7512547691554334 1.786328005761165 1.8304839518862552 1.7990260853600482 1.8795587931602025 1.9303687002708587 1.9503428608988242 2.01127728106431 1.9725637607430049 2.019239849692023 2.0424686464186337 1.92518103990985 1.9534590518410613 2.10667503109707 2.076364786330784 2.0909821830180464 2.0073756990796987 2.044433910135706 2.083445855283757 1.3710299743709582 1.4100785788401666 1.3683713422584265 1.4437204204069298 1.3453596964755294 1.38099162749327 1.3422812821894776 1.3750660160460204 1.3868743374915615 1.3701300855949645 1.4817182477968887 1.40575682495284 1.3681628171569382 1.4097266442786227 1.4313893054719684 1.4295964392159162 1.4700963885579021 1.4905326904320109 1.5315136689507143 1.5689836326173128 1.5917706281008055 1.6831104786424507 1.6060732369038568 1.6260499330852736 1.667858511816955 1.728303579991528 1.7184567181148838 1.7570704994486157 1.555553930498143 1.5328689493940173 1.5805043661899174 1.6244883384444413 1.7251730118058237 1.9064305080945698 1.4967920967830202 1.8693583491112835 1.8357808441911228 1.9153805462067985 1.9126491249195408 1.7947648201786608 1.8807414274634349 1.8385788223421469 1.91135403001499 1.953407242047419 1.9865420785419339 2.018730786312032 2.0287253060980124 2.081814808284358 2.0771910972289223 1.9923534643867757 2.0746333957458964 2.0461641319834882 1.3126566915388536 1.3286366400814824 1.3567317975502995 1.397567211630959 1.409859498454447 1.4521460189631532 1.29315510829913 1.3007437440712029 1.3050879299134706 1.3456027251404594 1.3336531729104844 1.3125892246014204 1.3024213978127779 1.3462163169381185 1.384172175300819 1.3892116157732433 1.3953064599820935 1.446236792017823 1.474454586146328 1.5225361707894047 1.5493013628172403 1.5584766689395453 1.5664776420729714 1.6115936957334984 1.6364554786935868 1.687838177243282 1.7184862042361386 1.7541108962296232 1.7668912457598016 1.5004693329471666 1.4746697861882692 1.5095027905059024 1.5657678890211237 1.8788834340527245 1.9014744964430885 1.939123455951078 1.9573872367072305 1.9967338322184893 1.8126003777923194 1.8570525371180862 1.9956552706023674 2.031232727184344 2.055166325415664 2.07489359945142 2.072263196479956 2.106022581245625 1.2839290544503463 1.261202417318298 1.277071910527896 1.3293271912714528 1.3682156546776199 1.327077504310168 1.3839383571604083 1.4245492829749338 1.1987216382478 1.2492737566592669 1.2625394927939486 1.2644791498700436 1.2604566979786065 1.247032110928604 1.2898953466279863 1.2598619949444072 1.2657392108399859 1.2296710271015132 1.2609183733684144 1.2978553252519593 1.3449108081309578 1.3600811665589336 1.3427747628010474 1.3722910545853892 1.4184081996104656 1.4344146322640752 1.4119816417941988 1.4896967568483488 1.5221535582570493 1.529914850917999 1.5560618996154798 1.5946761145947477 1.6793756806581592 1.6537793606993323 1.621079347092589 1.6988734060944535 1.7442741222236515 1.742911169751124 1.8062153556207883 1.7876630322445048 1.4278637800137652 1.4746536194641222 1.4580241672804335 1.9397183762711039 1.8573463350093364 1.9055047286485323 1.9802283060093258 2.036428905844674 2.018051179494922 2.067936283128255 1.8384379376313504 1.243143141811628 1.2429000479075243 1.2865936250220837 1.2059045688469938 1.233174445203341 1.33819126497867 1.2906655675665775 1.3729467444858972 1.1589203026870867 1.156613073901431 1.1715694893077306 1.217624909914126 1.2262358986559736 1.197889812688533 1.217477502256374 1.2183214440116663 1.1999112953547397 1.1825942826172913 1.2018145954439825 1.274762721061478 1.2575589050137297 1.3195712368207118 1.302084580148013 1.333869013178678 1.3403388193504235 1.3863415108294623 1.4522454754788836 1.3233647800227721 1.3529503483885474 1.3647894891180579 1.404827730874747 1.4495454696310368 1.491749242823581 1.4738135894683726 1.5129824238942453 1.480367367016636 1.5526127165173338 1.582884047212857 1.6605047661683772 1.5746476091364034 1.6222077127326602 1.6649136891199388 1.7021176503908182 1.737153978178767 1.7807463098136314 1.8211932912119768 1.826536682809351 1.394250460606941 1.9575210233885278 1.9597700925553678 2.0324346722748023 1.8673766799623217 1.904413683848086 1.9237021804291594 2.0036687381703295 2.056151899250966 1.2025301140738778 1.1737927789123574 1.2137556415058885 1.2520296574450944 1.1352259289193651 1.1590117295561133 1.2978944985735694 1.3361600406086613 1.0943113016003674 1.0975502797908034 1.1308770840852738 1.0946924629390842 1.1421564359478045 1.179789119861683 1.157200420435011 1.1763204532626992 1.1429636202076248 1.0988446487552888 1.1017175501997531 1.1348318410424936 1.1419644252567098 1.1533606917879724 1.1847699679026422 1.2332902226498148 1.2616628149524176 1.289314979898431 1.2824067314955243 1.2524553235874527 1.2889800255883088 1.3494804246855232 1.3885570194948236 1.4364227209785674 1.445304110915682 1.5083202646090739 1.4570326981378474 1.4981963470006547 1.5384583174392399 1.6429364680391683 1.6846124955698962 1.5594501167466717 1.5980893528364268 1.7267322973859214 1.797225731292146 1.7604989521055117 1.880405422546216 1.8439862251393668 1.9733664808402502 2.008481242271217 2.061794333345677 1.9162976232883806 1.9564548380368538 1.1514128747106804 1.0944874264950122 1.135144992011623 1.1742347313845527 1.1102543736598633 1.2007526031746423 1.249134086092904 1.0931280280028493 1.2700392817695048 1.0530840320597163 1.0528342093122025 1.0505992700769167 1.052405942415068 1.04822972156533 1.077089997333452 1.100409927801676 1.1016201626473379 1.056923880325522 1.0340551560613227 1.0500700188797143 1.0519358799439351 1.0950412440667292 1.0614262448536835 1.1335406792203186 1.1684120773480144 1.2201360806735728 1.2105309575618413 1.2465363440656632 1.1904705178768378 1.2134417645966926 1.2088118327894466 1.2528375246984549 1.252093690228555 1.283566392067968 1.3273141941063569 1.3663833440881814 1.3767055576295695 1.4045364470371042 1.4132000467362213 1.450692213621325 1.4984735539461984 1.5255307113412266 1.6083614801698047 1.6522358950890987 1.6900144257642455 1.5643654800308024 1.7263169801146254 1.798262636880347 1.80877448830168 1.8323742157344967 1.7694738933067626 1.8930314074392882 1.9818891737129314 1.874241148914243 1.84431619427126 1.9286809150030524 1.934160282683612 2.012529333206747 2.0414693431982456 1.9764420557497877 2.019491883425041 2.01852491581289 1.052116696165056 1.0549676860143615 1.0971550100356844 1.1395381689911324 1.229048962040308 1.0484123474304512 0.9835102537255902 1.0203436740726162 0.9873611000595873 0.990058798211608 0.9928466010132945 0.9847060548319433 0.99215430477793 1.023752069034401 0.9860231803499329 0.9842128887769344 0.9820222923674082 0.9864776494961544 1.0540201597362484 1.0920901147671578 1.1434539582754917 1.083594957182425 1.1540537792557346 1.0742487922714052 1.1007608769552182 1.1517272290025118 1.1541824725600227 1.1534880850970821 1.1940695139708526 1.1922211440632395 1.2425490236119636 1.2252696249654063 1.2640147226355425 1.2963249281619924 1.3381297034013737 1.338333591719911 1.37783265548526 1.4063068391714184 1.4366088800332437 1.478809684011495 1.5324898586996918 1.5866693113400538 1.625470151230333 1.5991326635730516 1.6768900194058844 1.7326803293834312 1.6955487452501268 1.7361155230681447 1.7769912686357225 1.7855685671468533 1.8169050434064553 1.8282304831401395 1.8600662372280563 1.8993451041609257 1.8934430510560651 1.914145604822517 1.9787439638706807 1.9577010384590992 2.030738412378543 0.984053895879505 1.0539651534121726 0.9703279478321459 0.992386355317286 1.068096471269732 1.115031518419464 1.1335863443208252 1.1334247298246525 0.9465222194619185 0.944643376591677 0.9454440376568396 0.9445576278504201 0.9452533491851062 0.9950220045912205 1.0519846001932538 0.9843958400334267 1.0297939768545332 1.042667737130728 0.9846316732742723 1.0521989990846474 1.0699934217945835 1.1246974120814914 1.0639250837817367 1.1102568879210986 1.1516863112913813 1.1468699056630425 1.1492744037071734 1.1865565927246164 1.190434323632287 1.2549901180676228 1.2248344342717599 1.2982404311862745 1.3235006472359945 1.3671326949002838 1.3679031975062228 1.4186967414355613 1.4601321032650514 1.5077704346078706 1.5576039892957108 1.6437566455403072 1.5272760383933253 1.5614923728137338 1.6089182238876678 1.6672068195289644 1.633895132731761 1.6797840734770682 1.7192982218045456 1.7074400419153821 1.7596490727392058 1.801808264413558 1.8715627838821738 1.8439119525602012 1.9409217410840522 1.9103237565445668 1.9524859611725451 2.0103849982454847 2.003622878896449 2.027890803780683 1.1326410282201018 0.9433405444871937 0.9786044702889996 1.0447178280553207 0.9816966469484341 0.9755907824319029 1.017890988407128 1.0611864347510518 1.1000060006777952 1.0714789458267844 1.1298291145185242 1.1554858365528191 1.1886576478439403 1.2626776148405499 1.231966389856722 1.2633353214671819 1.2930225357753447 1.3265427813028992 1.3775159060720947 1.3883581816621549 1.4390354939563788 1.4795812926009373 1.476360747195699 1.5253192278449443 1.5663576936444934 1.6154909224101888 1.6557588311994367 1.6707914907230146 1.7101493781542203 1.7515242396253854 1.76789352968294 1.8030730175581675 1.886759387713389 1.8450640715263809 1.910408194486452 1.9607285546530935 1.982851427774425 2.015390737791546 0.9428628421116313 0.979953812465413 1.0492628891080307 0.990931803315277 0.9654027890934953 1.0173948639420165 1.03186565405138 1.0757293855450478 1.1195545920106564 1.1518636065204335 1.0939658373710337 1.1350643153398496 1.1784081029549327 1.2261336571964796 1.25999069901281 1.3090484411256003 1.2652450372766453 1.349345846840295 1.3436842646074234 1.397833668476101 1.4349268919668752 1.4858630004285402 1.4451973178703363 1.5300795543863936 1.5715999165604964 1.5797113887662866 1.620746289905131 1.641870434625605 1.6875381493379429 1.746612268396892 1.7877682337397893 1.810756321041136 1.857512577874376 1.9101534624955305 1.9284860447852015 1.965256840626496 2.00708157664304 0.942089261436745 0.9709768882353648 0.9885725813667969 1.047313902473828 1.0108704742321524 1.049823620451793 1.0479599274134708 1.0500919965068516 1.101667702644097 1.145375876255578 1.1898117705590308 1.1847579070429464 1.2326953132024465 1.2959059372361774 1.2315287274532751 1.2335206057042871 1.2717665874708362 1.3068928357595417 1.3125889644623017 1.3587330378156919 1.3988320184839798 1.3897871069720265 1.4449116263250301 1.4837349956049124 1.5268416712514175 1.5445664912241308 1.5831215173687847 1.595728029689064 1.6477449199840133 1.6899505565312003 1.7106060368261808 1.7458463817830956 1.84234735656274 1.7919995906829183 1.893363556249463 1.8493018333702302 1.913142379354562 1.9633965503394597 2.0043947153741324 0.9693379858907141 1.0136247381713623 1.0952529885787086 0.9759085931856615 1.0171881584558375 1.0841100135097603 1.0542321758451847 1.1456934275967883 1.1891014643798103 1.3148039321162344 1.3511170293741201 1.3537835292640137 1.3654489731932007 1.409654094728296 1.4526557761007997 1.5026096483325109 1.4844417156082774 1.515897826378133 1.5551536012709677 1.5990284934665866 1.6134647592216989 1.671973963116827 1.7290267836431708 1.7638240703920878 1.8118631011179853 1.7799409582701866 1.8723357154153168 1.9077133150592975 2.0140121382150027 2.0196855425750577 0.941502099884958 0.978941342565754 1.0315177286308859 1.1519450975960577 1.3957540270239621 1.4418270679310217 1.4223775108978056 1.4682210030662448 1.4655509714201695 1.5088830772091033 1.5329278252270626 1.5728813903341237 1.5793414986805585 1.6705020180334411 1.5991769311883282 1.6259740682470147 1.668533330581957 1.7115846647493322 1.7577616706992865 1.8235887191258566 1.8019442521491276 1.9123451325692193 0.9417729570891041 0.9768349561013279 1.0461846598037718 1.6105176067285265 1.664418151101974 1.6877383638781107 1.7447375004920533 1.8271032028319225 1.8412013823050064 1.88191725853035 1.971074294589085 0.9824823102436403 0.9777607671707541 1.0230365828076216 1.0506224841258263 1.689773229691838 1.6337519611844127 1.684323098883611 1.7260276378633208 1.8166471596095541 1.8606532913585612 1.893874917230121 1.9502844327821927 1.992116808579313 2.018670266983134 1.016862339583605 1.0039697351161663 1.049532424817155 1.5386111648638057 1.759127580217008 1.7927018903715837 1.9118436545348239 1.9098944836278595 1.9529931297267442 1.9732650643280196 1.9944920683708958 1.0470473912220912 1.0447943983036188 1.4475046662747593 1.506937156350897 1.8537243223618594 2.004708201774405 1.0865456976163026 1.0463418193289509 1.3282812714898176 1.098196164333948 1.2886356755926343 1.1386632139838928 1.1817017497545068
]);

#=== TOPOLOGY : 1-CELLS ===#
I = Array{Int64}([54, 73, 52, 73, 19, 30, 52, 84, 5, 54, 8, 84, 75, 80, 30, 80, 16, 19, 5, 23, 23, 38, 16, 36, 8, 14, 17, 36, 47, 75, 38, 44, 44, 62, 14, 17, 47, 65, 62, 70, 57, 65, 41, 70, 41, 79, 32, 57, 22, 79, 22, 59, 27, 32, 9, 21, 2, 49, 59, 64, 26, 58, 9, 26, 58, 77, 27, 35, 35, 77, 2, 21, 33, 49, 33, 37, 15, 37, 15, 48, 53, 64, 31, 48, 31, 56, 56, 74, 43, 74, 53, 68, 12, 43, 24, 68, 12, 69, 50, 69, 3, 45, 4, 24, 18, 50, 3, 67, 4, 39, 39, 51, 18, 29, 6, 45, 20, 67, 20, 72, 61, 72, 61, 85, 1, 85, 46, 60, 29, 46, 6, 10, 25, 60, 10, 28, 34, 83, 40, 55, 51, 55, 25, 42, 28, 76, 11, 83, 13, 34, 40, 63, 42, 82, 11, 71, 1, 71, 13, 78, 63, 78, 7, 76, 81, 82, 66, 81, 7, 66, ]);
J = Array{Int64}([132, 132, 137, 137, 166, 166, 183, 183, 185, 185, 188, 188, 220, 220, 221, 221, 222, 222, 236, 236, 237, 237, 238, 238, 239, 239, 240, 240, 273, 273, 284, 284, 285, 285, 286, 286, 328, 328, 336, 336, 385, 385, 393, 393, 442, 442, 453, 453, 503, 503, 506, 506, 511, 511, 513, 513, 516, 516, 565, 565, 566, 566, 568, 568, 570, 570, 572, 572, 573, 573, 574, 574, 575, 575, 576, 576, 577, 577, 578, 578, 623, 623, 625, 625, 626, 626, 628, 628, 629, 629, 661, 661, 662, 662, 698, 698, 699, 699, 700, 700, 714, 714, 737, 737, 738, 738, 747, 747, 766, 766, 767, 767, 768, 768, 771, 771, 772, 772, 774, 774, 776, 776, 778, 778, 782, 782, 790, 790, 791, 791, 792, 792, 802, 802, 804, 804, 806, 806, 813, 813, 814, 814, 816, 816, 817, 817, 818, 818, 819, 819, 825, 825, 827, 827, 828, 828, 829, 829, 830, 830, 831, 831, 832, 832, 833, 833, 835, 835, 837, 837, ]);
K = Array{Int8}([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ]);

Lar.addModelCells!(tetto, 1, SparseArrays.sparse(I, J, K, 85, 838))

#=== TOPOLOGY : 2-CELLS ===#
I = Array{Int64}([]);
J = Array{Int64}([]);
K = Array{Int8}([]);

Lar.addModelCells!(tetto, 2, SparseArrays.sparse(I, J, K, 0, 85))

#=== TOPOLOGY : 3-CELLS ===#
I = Array{Int64}([]);
J = Array{Int64}([]);
K = Array{Int8}([]);

Lar.addModelCells!(tetto, 3, SparseArrays.sparse(I, J, K, 0, 0))


text:
@testset "equations.jl" begin
    # Domains
    a = 0.0
    b = 1.0
    closed = ClosedIntervalDomain(a, b)
    periodic = PeriodicIntervalDomain(a, b)

    # Filters
    identity_filter = IdentityFilter()
    top_hat_filter = TopHatFilter(x -> 0.1)
    convolutional_filter = GaussianFilter(0.1)

    # AdvectionEquation
    eq = AdvectionEquation(closed, identity_filter)
    @test eq isa AdvectionEquation{ClosedIntervalDomain{typeof(a)},IdentityFilter}
    eq = AdvectionEquation(closed, top_hat_filter)
    @test eq isa AdvectionEquation{ClosedIntervalDomain{typeof(a)},TopHatFilter}
    eq = AdvectionEquation(closed, convolutional_filter)
    @test eq isa AdvectionEquation{ClosedIntervalDomain{typeof(a)},ConvolutionalFilter}
    eq = AdvectionEquation(periodic, identity_filter)
    @test eq isa AdvectionEquation{PeriodicIntervalDomain{typeof(a)},IdentityFilter}

    # DiffusionEquation
    f = (ξ, t) -> ξ + t
    g_a = t -> t
    g_b = t -> 0.0
    eq = DiffusionEquation(closed, identity_filter, f, g_a, g_b)
    @test eq isa DiffusionEquation{ClosedIntervalDomain{typeof(a)},IdentityFilter}
    eq = DiffusionEquation(closed, top_hat_filter, f, g_a, g_b)
    @test eq isa DiffusionEquation{ClosedIntervalDomain{typeof(a)},TopHatFilter}
    eq = DiffusionEquation(closed, convolutional_filter, f, g_a, g_b)
    @test eq isa DiffusionEquation{ClosedIntervalDomain{typeof(a)},ConvolutionalFilter}
    eq = DiffusionEquation(periodic, identity_filter, f, g_a, g_b)
    @test eq isa DiffusionEquation{PeriodicIntervalDomain{typeof(a)},IdentityFilter}

    # BurgersEquation
    eq = BurgersEquation(closed, identity_filter)
    @test eq isa BurgersEquation{ClosedIntervalDomain{typeof(a)},IdentityFilter}
    eq = BurgersEquation(closed, top_hat_filter)
    @test eq isa BurgersEquation{ClosedIntervalDomain{typeof(a)},TopHatFilter}
    eq = BurgersEquation(closed, convolutional_filter)
    @test eq isa BurgersEquation{ClosedIntervalDomain{typeof(a)},ConvolutionalFilter}
    eq = BurgersEquation(periodic, identity_filter)
    @test eq isa BurgersEquation{PeriodicIntervalDomain{typeof(a)},IdentityFilter}
end

ext: jl


text:
using FractionalSystems

G = fotf([-2, -4], [0.6, 0], [2, 3.8, 2.6, 2.5, 1.5], [3.5, 2.4, 1.8, 1.3, 0])
rlocus(G)


text:
using Documenter, ERFA

makedocs(format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true",
    ),
    sitename = "ERFA.jl",
    authors = "The JuliaAstro Contributors",
    pages = [
        "Home" => "index.md",
        "API" => "api.md",
    ],
    doctest = false,
)

deploydocs(repo = "github.com/JuliaAstro/ERFA.jl.git",
    target = "build",
)


text:
"""
    Events
"""
module Events

"""
Abstract type for events that callbacks can hook into
"""
abstract type FitEvent end

"""
Supertype for events that are called within `Zygote.gradient`.
They need to be handled differently because try/catch is not
supported by Zygote's compiler.
"""
abstract type GradEvent <: FitEvent end

"""
    Init <: FitEvent

Called once when the learner is created/the callback is added.
"""
struct Init <: FitEvent end

struct FitBegin <: FitEvent end
struct FitEnd <: FitEvent end

struct EpochBegin <: FitEvent end
struct EpochEnd <: FitEvent end

struct BatchBegin <: FitEvent end
struct BatchEnd <: FitEvent end

"""Called between calculating `y_pred` and calculating loss"""
struct LossBegin <: GradEvent end
"""Called between calculating loss and calculating gradients"""
struct BackwardBegin <: GradEvent end
"""Called between calculating gradients and updating parameters"""
struct BackwardEnd <: FitEvent end

export
    # asbtract
    FitEvent, GradEvent,
    # concrete
    Init,
    FitBegin, FitEnd,
    EpochBegin, EpochEnd,
    BatchBegin, BatchEnd,
    LossBegin,
    BackwardBegin, BackwardEnd

end # module

using .Events


text:
@testset "Sparse rref" begin
  M = sparse_matrix(zero_matrix(FlintQQ, 2, 2))
  @test rref(M) == (0, M)

  M = sparse_matrix(matrix(GF(5), 3, 3, [ 0, 1, 2, 0, 1, 3, 0, 0, 4 ]))
  @test rref(M) == (2, sparse_matrix(matrix(GF(5), 3, 3, [ 0, 1, 0, 0, 0, 1, 0, 0, 0, ])))

  for i in 1:10
    r = 20
    c = 10
    M = matrix(FlintQQ, rand([0,0,0,0,0,0,0,0,0,0,1], r, c))
    Ms = sparse_matrix(M)
    n, N = rref(M)
    ns, Ns = rref(Ms)
    @test n == ns
    @test matrix(Ns) == N
  end
end

@testset "Sparse kernel" begin
  M = sparse_matrix(zero_matrix(FlintQQ, 2, 2))
  @test nullspace(M) == (2, identity_matrix(FlintQQ, 2))

  M = sparse_matrix(matrix(GF(5), 3, 3, [ 0, 1, 2, 0, 1, 3, 0, 0, 4 ]))
  @test nullspace(M) == (1, matrix(GF(5), 3, 1, [ 1, 0, 0 ]))
  @test kernel(M, side = :left) == (1, matrix(GF(5), 1, 3, [ 4, 1, 1 ]))
  @test kernel(M, side = :right) == (1, matrix(GF(5), 3, 1, [ 1, 0, 0 ]))

  for i in 1:10
    r = 10
    c = 20
    M = matrix(FlintQQ, rand([0,0,0,0,0,0,0,0,0,0,1], r, c))
    @test nullspace(sparse_matrix(M)) == nullspace(M)
  end
end


text:
#=
This implements the basic event callbacks for a GLFW window.
It can be used as a template for any other window type with events you might want to
add to GLVisualize.
Simpley implement the same methods, and just type it with your window type.
=#

@field OpenGLVersion = v"3.1.0"

abstract type AbstractGLWindow <: AbstractWindow end

@composed type GLWindow <: AbstractGLWindow
    <: Window
    OpenGLVersion
end

@composed type GLFWWindow <: AbstractGLWindow
    <: GLWindow
end

function make_context_current(x::GLFW.Window)
    GLFW.MakeContextCurrent(x)
    GLAbstraction.make_context_current(x)
end
Base.show(io::IO, mt::MIME"text/plain", ::GLFWWindow) = println(io, "GLFWWindow")

function default(::Type{Scene}, p::Partial{<: AbstractGLWindow})
    make_context_current(get!(p, NativeWindow))
    cam = get!(p, Camera)
    ubo = UniformBuffer(SceneUniforms(cam))
    for field in FieldTraits.Fields(eltype(ubo))
        if haskey(cam, field)
            FieldTraits.link!(field, cam => ubo)
        end
    end
    ubo
end

"""
OpenGL context hint for the window creation with GLFW
Expects a Vector{Tuple{GLenum, Integer}}. E.g:
```Julia
    [
        (GLFW.CONTEXT_VERSION_MAJOR, major),
        (GLFW.CONTEXT_VERSION_MINOR, minor)
    ]
```
"""
@field ContextHints

"""
Tries to create sensible context hints!
Taken from lessons learned at:
[GLFW](http://www.glfw.org/docs/latest/window.html)
"""
function default(::Type{ContextHints}, p::Partial{GLFWWindow})
    version = get(p, OpenGLVersion)
    major, minor = version.major, version.minor
    # this is spaar...Modern OpenGL !!!!
    # core profile is only supported for OpenGL 3.2+ (and a must for OSX, so
    # for the sake of homogenity, we try to default to it for everyone!)
    if (major > 3 || (major == 3 && minor >= 2 ))
        profile = GLFW.OPENGL_CORE_PROFILE
    else
        profile = GLFW.OPENGL_ANY_PROFILE
    end
    [
        (GLFW.CONTEXT_VERSION_MAJOR, major),
        (GLFW.CONTEXT_VERSION_MINOR, minor),
        (GLFW.OPENGL_FORWARD_COMPAT, GL_TRUE),
        (GLFW.OPENGL_PROFILE, profile)
    ]
end

"""
OpenGL Framebuffer hint for the window creation with GLFW.
Expects a Vector{Tuple{GLenum, Integer}}. E.g:
```Julia
    [
        (GLFW.SAMPLES,      0),
        (GLFW.RED_BITS,     8),
        (GLFW.GREEN_BITS,   8),
        (GLFW.BLUE_BITS,    8)
    ]
```
"""
@field FramebufferHints = [
    (GLFW.SAMPLES,      0),
    (GLFW.DEPTH_BITS,   32),

    (GLFW.ALPHA_BITS,   8),
    (GLFW.RED_BITS,     8),
    (GLFW.GREEN_BITS,   8),
    (GLFW.BLUE_BITS,    8),

    (GLFW.STENCIL_BITS, 0),
    (GLFW.AUX_BUFFERS,  0)
]

"""
Callback which can be used to catch OpenGL errors.
"""
function openglerrorcallback(
        source::GLenum, typ::GLenum,
        id::GLuint, severity::GLenum,
        length::GLsizei, message::Ptr{GLchar},
        userParam::Ptr{Void}
    )
    # TODO introduce debug levels
    if typ == GL_DEBUG_TYPE_ERROR
        # output = typ == GL_DEBUG_TYPE_ERROR ? error : info
        errormessage = """
             ________________________________________________________________
            | OpenGL Error!
            | source: $(GLENUM(source).name) | type: $(GLENUM(typ).name)
            |  $(unsafe_string(message, length))
            |________________________________________________________________
        """
        error(errormessage)
    end
    nothing
end

global const _openglerrorcallback = cfunction(
    openglerrorcallback, Void,
    (GLenum, GLenum,GLuint, GLenum, GLsizei, Ptr{GLchar}, Ptr{Void})
)
function default(::Type{NativeWindow}, data::Partial{GLFWWindow})
    area = get(data, Area)
    # we create a new context, so we need to clear the shader cache.
    # TODO, cache shaders in GLAbstraction per GL context
    GLFW.WindowHint(GLFW.VISIBLE, get(data, Visible))
    GLFW.WindowHint(GLFW.FOCUSED, get(data, Focused))

    for ch in get(data, FramebufferHints)
        GLFW.WindowHint(ch[1], ch[2])
    end
    for wh in get(data, ContextHints)
        GLFW.WindowHint(wh[1], wh[2])
    end
    debugging = get(data, Debugging)
    @static if is_apple()
        if debugging
            warn("OpenGL debug message callback not available on osx")
            debugging = false
        end
    end
    GLFW.WindowHint(GLFW.OPENGL_DEBUG_CONTEXT, Cint(debugging))
    resolution = round.(Int, widths(get(data, Area)))
    name = get(data, Name)
    window = GLFW.CreateWindow(resolution..., String(name))
    GLFW.MakeContextCurrent(window)

    # tell GLAbstraction that we created a new context.
    # This is important for resource tracking
    GLAbstraction.new_context(window)

    debugging && glDebugMessageCallbackARB(_openglerrorcallback, C_NULL)
    window
end

"""
Adds the Mouse.Position event via GLFW
"""
function add!(window::GLFWWindow, ::Type{Mouse.Position})
    GLFW.SetCursorPosCallback(window[NativeWindow], (native_window, x, y) -> begin
        window[Mouse.Position] = (x, window[Area].h - y)
    end)
    return
end

"""
Adds the Mouse.Scroll event via GLFW
"""
function add!(window::GLFWWindow, ::Type{Mouse.Scroll})
    GLFW.SetScrollCallback(window[NativeWindow], (native_window, xoffset, yoffset) -> begin
        window[Mouse.Scroll] = (xoffset, yoffset)
    end)
    return
end

"""
Adds the Mouse.Buttons event via GLFW
"""
function add!(window::GLFWWindow, ::Type{Mouse.Buttons})
    GLFW.SetMouseButtonCallback(window[NativeWindow], (native_window, button, action, mods) -> begin
        set = window[Mouse.Buttons]
        button_enum = Mouse.Button(button)
        if button != GLFW.KEY_UNKNOWN
            if action == GLFW.PRESS
                push!(set, button_enum)
            elseif action == GLFW.RELEASE
                delete!(set, button_enum)
            elseif action == GLFW.REPEAT
                # nothing needs to be done, besides returning the same set of keys
            else
                error("Unrecognized enum value for GLFW button press action: $action")
            end
        end
        window[Mouse.Buttons] = set # trigger setfield event!
    end)
    return
end

function add!(window::GLFWWindow, ::Type{Area})
    GLFW.SetFramebufferSizeCallback(window[NativeWindow], (native_window, w, h) -> begin
        rect = window[Area]
        window[Area] = IRect(minimum(rect), w, h)
    end)
    GLFW.SetWindowPosCallback(window[NativeWindow], (native_window, x, y) -> begin
        rect = window[Area]
        window[Area] = IRect(x, y, widths(rect))
    end)
    return
end

"""
Adds the Keyboard.Buttons event via GLFW
"""
function add!(window::GLFWWindow, ::Type{Keyboard.Buttons})
    GLFW.SetKeyCallback(window[NativeWindow], (native_window, button, scancode, action, mods) -> begin
        set = window[Keyboard.Buttons]
        button_enum = Keyboard.Button(button)
        if button != GLFW.KEY_UNKNOWN
            if action == GLFW.PRESS
                push!(set, button_enum)
            elseif action == GLFW.RELEASE
                delete!(set, button_enum)
            elseif action == GLFW.REPEAT
                # nothing needs to be done, besides returning the same set of keys
            else
                error("Unrecognized enum value for GLFW button press action: $action")
            end
        end
        window[Keyboard.Buttons] = set # trigger setfield event!
    end)
    return
end

"""
[GLFW Docs](http://www.glfw.org/docs/latest/group__window.html#ga6b5f973531ea91663ad707ba4f2ac104)
"""
function add!(window::GLFWWindow, ::Type{Focused})
    GLFW.SetWindowFocusCallback(window[NativeWindow], (native_window, focus::Bool) -> begin
        window[Focused] = focus
    end)
end

"""
[GLFW Docs](http://www.glfw.org/docs/latest/group__input.html#ga1e008c7a8751cea648c8f42cc91104cf)
"""
function add!(window::GLFWWindow, ::Type{Keyboard.Unicode})
    GLFW.SetCharCallback(window[NativeWindow], (native_window, c::Char) -> begin
        s[Keyboard.Unicode] = c
    end)
end

"""
[GLFW Docs](http://www.glfw.org/docs/latest/group__input.html#gacc95e259ad21d4f666faa6280d4018fd)
"""
function add!(window::GLFWWindow, ::Type{DroppedFiles})
    GLFW.SetDropCallback(window[NativeWindow], (native_window, files) -> begin
        window[DroppedFiles] = map(String, files)
    end)
end

"""
[GLFW Docs](http://www.glfw.org/docs/latest/group__window.html#gaade9264e79fae52bdb78e2df11ee8d6a)
"""
function add!(window::GLFWWindow, ::Type{Open})
    GLFW.SetWindowCloseCallback(window[NativeWindow], native_window -> begin
        window[Open] = false
    end)
end

show!(window::GLFWWindow) = GLFW.ShowWindow(window[NativeWindow])
destroy!(window::GLFWWindow) = GLFW.DestroyWindow(window[NativeWindow])
swapbuffers!(window::GLFWWindow) = GLFW.SwapBuffers(window[NativeWindow])

function renderloop(window::GLFWWindow)
    try
        nativew = window[NativeWindow]
        make_context_current(nativew)
        GLAbstraction.enabletransparency()
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LEQUAL)
        glClearColor(window[Visualize.Color]...)
        while isopen(window) && !(nativew.handle == C_NULL)
            tstart = time_ns()
            GLFW.PollEvents()
            poll_actions()
            glViewport(0, 0, widths(window[Area])...)

            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

            for (prim, (drawable, args)) in window[Renderlist]
                drawable(args...)
            end

            swapbuffers!(window)
            yield()
            glFinish()
            tdiff = (1/60) - (time_ns() - tstart)
            if tdiff > 0.0
                println(tdif)
                sleep(tdiff)
            end
        end
    catch e
        rethrow()
    finally
        destroy!(window)
    end
end

using Visualize: TextureAtlas, get_texture_atlas
using GPUArrays.GLBackend: GLSampler

# Each opengl context needs it's own texture, since they're not valid across context
const texture_cache = Dict{GLAbstraction.GLContext, GLSampler{Float32, 2}}()
function atlas_texture(atlas::TextureAtlas = get_texture_atlas())
    ctx = GLAbstraction.current_context()
    get!(texture_cache, ctx) do
        GLSampler(
            Array(atlas.images);
            minfilter = :linear,
            magfilter = :linear,
            anisotropic = 16f0,
        )
    end
end

function glwindow(args...)
    window = GLFWWindow(args)
    for event in NativeWindowEvents
        add!(window, event)
    end
    add!(window, Mouse.Drag)
    cam = window[Camera]
    if isa(cam, PerspectiveCamera)
        add!(cam, Translation, window,
            Mouse.right, Set([Keyboard.left_control])
        )
        add!(cam, Rotation, window,
            Mouse.left, Set([Keyboard.left_control])
        )
        add!(cam, ProjectionView)
        add!(cam, EyePosition, LookAt)
    else
        add!(cam, window, Pan)
        add!(cam, window, Zoom)
        on(cam, Projection, View) do p, v
            cam[ProjectionView] = p * v
        end
    end
    # scene = window[Scene]
    # for field in FieldTraits.Fields(eltype(scene))
    #     if haskey(cam, field)
    #         FieldTraits.link!(field, cam => scene)
    #     end
    # end
    window
end


text:
# AUTO GENERATED FILE - DO NOT EDIT

export radiogroup

"""
    radiogroup(;kwargs...)

A RadioGroup component.
Capture user feedback limited to small set of options. For more information, see: https://mantine.dev/core/radio-group/
Keyword arguments:
- `id` (String; optional): The ID of this component, used to identify dash components in callbacks
- `className` (String; optional): Often used with CSS to style elements with common properties
- `color` (a value equal to: "dark", "gray", "red", "pink", "grape", "violet", "indigo", "blue", "cyan", "teal", "green", "lime", "yellow", "orange"; optional): Active radio color from theme.colors
- `data` (optional): RadioGroup options. data has the following type: Array of lists containing elements 'label', 'value'.
Those elements have the following types:
  - `label` (String; required): The option's label
  - `value` (String; required): Option's values
- `description` (String; optional): Input description, displayed after label
- `error` (String; optional): Displays error message after input
- `label` (String; optional): Input label, displayed before input
- `required` (Bool; optional): Adds red asterisk on the right side of label
- `size` (a value equal to: "xs", "sm", "md", "lg", "xl"; optional): Predefined label fontSize, radio width, height and border-radius
- `spacing` (a value equal to: "xs", "sm", "md", "lg", "xl"; optional): Spacing between radios in horizontal variant
- `style` (Dict; optional): Inline style override
- `value` (String; optional): Value of currently selected radio (controlled)
- `variant` (a value equal to: "horizontal", "vertical"; optional): Radios position
"""
function radiogroup(; kwargs...)
        available_props = Symbol[:id, :className, :color, :data, :description, :error, :label, :required, :size, :spacing, :style, :value, :variant]
        wild_props = Symbol[]
        return Component("radiogroup", "RadioGroup", "dash_mantine_components", available_props, wild_props; kwargs...)
end


text:
using KrigingEstimators
using GeoStatsBase
using Variography
using LinearAlgebra
using Statistics
using Plots, VisualRegressionTests
using Test, Pkg, Random

# workaround GR warnings
ENV["GKSwstype"] = "100"

# environment settings
islinux = Sys.islinux()
istravis = "TRAVIS" ∈ keys(ENV)
datadir = joinpath(@__DIR__,"data")
visualtests = !istravis || (istravis && islinux)
if !istravis
  Pkg.add("Gtk")
  using Gtk
end

# dummy variables for testing
include("dummy.jl")

# list of tests
testfiles = [
  "estimators.jl",
  "solvers.jl"
]

@testset "KrigingEstimators.jl" begin
  for testfile in testfiles
    include(testfile)
  end
end


text:
function _attach_ports!(component::PSY.DynamicComponent)
    PSY.get_ext(component)[PORTS] = Ports(component)
    return
end

function index_local_states(component::PSY.DynamicComponent, device_states::Vector{Symbol})
    component_state_index = Vector{Int}(undef, PSY.get_n_states(component))
    component_states = PSY.get_states(component)
    for (ix, s) in enumerate(component_states)
        component_state_index[ix] = findfirst(x -> x == s, device_states)
    end
    return component_state_index
end

function index_port_mapping!(component::PSY.DynamicComponent, device_states::Vector{Symbol})
    _attach_ports!(component)
    index_component_inputs = Vector{Int}()
    for i in PSY.get_ext(component)[PORTS][:states]
        tmp = [(ix, var) for (ix, var) in enumerate(device_states) if var == i]
        isempty(tmp) && continue
        push!(index_component_inputs, tmp[1][1])
    end
    return index_component_inputs
end

function _add_dynamic_bus_states!(
    DAE_vector::Vector{Bool},
    voltage_buses_ix::Vector{Int},
    bus_ix::Int,
    n_buses::Int,
)
    push!(voltage_buses_ix, bus_ix)
    DAE_vector[bus_ix] = DAE_vector[bus_ix + n_buses] = true
    return
end

function index_dynamic_lines!(
    inputs::SimulationInputs,
    branch::PSY.DynamicBranch,
    n_buses::Int,
)
    DAE_vector = get_DAE_vector(inputs)
    voltage_buses_ix = get_voltage_buses_ix(inputs)
    arc = PSY.get_arc(branch)
    from_bus_number = PSY.get_number(arc.from)
    to_bus_number = PSY.get_number(arc.to)
    bus_ix_from = get_lookup(inputs)[from_bus_number]
    bus_ix_to = get_lookup(inputs)[to_bus_number]
    b_from = PSY.get_b(branch).from
    b_to = PSY.get_b(branch).to
    total_shunts = get_total_shunts(inputs)
    total_shunts[bus_ix_from, bus_ix_from] += 1im * b_from
    total_shunts[bus_ix_to, bus_ix_to] += 1im * b_to
    b_from > 0.0 &&
        _add_dynamic_bus_states!(DAE_vector, voltage_buses_ix, bus_ix_from, n_buses)
    b_to > 0.0 && _add_dynamic_bus_states!(DAE_vector, voltage_buses_ix, bus_ix_to, n_buses)
    return
end

function index_static_injection(inputs::SimulationInputs, ::PSY.StaticInjection)
    return
end

function add_states_to_global!(
    global_state_index::MAPPING_DICT,
    state_space_ix::Vector{Int},
    device::PSY.Device,
)
    global_state_index[PSY.get_name(device)] = Dict{Symbol, Int}()
    for s in PSY.get_states(device)
        state_space_ix[1] += 1
        global_state_index[PSY.get_name(device)][s] = state_space_ix[1]
    end

    return
end

function index_dynamic_injection(
    inputs::SimulationInputs,
    dynamic_device::PSY.DynamicInjection,
    state_space_ix::Vector{Int},
)
    DAE_vector = get_DAE_vector(inputs)
    make_device_index!(dynamic_device, DAE_vector)
    add_states_to_global!(inputs.global_index, state_space_ix, dynamic_device)
    return
end

var_count(::PSY.DynamicGenerator) = GEN_INNER_VARS_SIZE
var_count(::PSY.DynamicInverter) = INV_INNER_VARS_SIZE

function attach_inner_vars!(
    dynamic_device::T,
    ::Type{U} = Real,
) where {T <: PSY.DynamicInjection, U <: Real}
    dynamic_device.ext[INNER_VARS] = zeros(U, var_count(dynamic_device))
    return
end

function _attach_control_refs!(device::PSY.StaticInjection)
    dynamic_device = PSY.get_dynamic_injector(device)
    dynamic_device.ext[CONTROL_REFS] = [
        PSY.get_V_ref(dynamic_device),
        PSY.get_ω_ref(dynamic_device),
        PSY.get_P_ref(dynamic_device),
        PSY.get_reactive_power(device),
    ]
    return
end

function _attach_control_refs!(device::PSY.Source)
    device.ext[CONTROL_REFS] =
        [PSY.get_internal_voltage(device), PSY.get_internal_angle(device)]
    return
end

function _attach_control_refs!(device::PSY.ElectricLoad)
    return
end

function _get_internal_mapping(
    dynamic_device::PSY.DynamicInjection,
    key::AbstractString,
    ty::Type{T},
) where {T <: PSY.DynamicComponent}
    device_index = PSY.get_ext(dynamic_device)[key]
    val = get(device_index, ty, nothing)
    @assert !isnothing(val)
    return val
end

function get_local_state_ix(
    dynamic_device::PSY.DynamicInjection,
    ty::Type{T},
) where {T <: PSY.DynamicComponent}
    return _get_internal_mapping(dynamic_device, LOCAL_STATE_MAPPING, ty)
end

function get_input_port_ix(
    dynamic_device::PSY.DynamicInjection,
    ty::Type{T},
) where {T <: PSY.DynamicComponent}
    return _get_internal_mapping(dynamic_device, INPUT_PORT_MAPPING, ty)
end

"""
Default implementation to index the devices states and maps to the ports
"""
function make_device_index!(dynamic_device::PSY.DynamicInjection, ::Vector{Bool})
    device_states = PSY.get_states(dynamic_device)
    device_state_mapping = DEVICE_INTERNAL_MAPPING()
    input_port_mapping = DEVICE_INTERNAL_MAPPING()
    attach_inner_vars!(dynamic_device)
    for c in PSY.get_dynamic_components(dynamic_device)
        device_state_mapping[typeof(c)] = index_local_states(c, device_states)
        input_port_mapping[typeof(c)] = index_port_mapping!(c, device_states)
    end
    dynamic_device.ext[LOCAL_STATE_MAPPING] = device_state_mapping
    dynamic_device.ext[INPUT_PORT_MAPPING] = input_port_mapping
    return
end


text:
using Documenter, Feather

makedocs(
    modules = [Feather],
    format = :html,
    sitename = "Feather.jl",
    pages = ["Home" => "index.md"]
)

deploydocs(
    deps = Deps.pip("mkdocs", "python-markdown-math"),
    repo = "github.com/JuliaData/Feather.jl.git",
    julia = "1.0",
    osname = "linux"
)


text:
# AUTO GENERATED FILE - DO NOT EDIT

export ''_dashmqtt

"""
    ''_dashmqtt(;kwargs...)

A DashMqtt component.
ExampleComponent is an example component.
It takes a property, `label`, and
displays it.
It renders an input with the property `value`
which is editable by the user.
Keyword arguments:
- `state` (Dict; optional): This MQTT connection state (in the readyState prop) and any associated information.
- `broker_url` (String; optional): The MQTT broker endpoint (e.g. 'mqtt://test.mosquitto.org').
- `protocol` (String; optional): One the following protocols: 'mqtt', 'mqtts', 'tcp', 'tls', 'ws', 'wss'.
Defaults to 'mqtt' which then is defaulted to 'ws' by MQTT.js
From (https://github.com/mqttjs/MQTT.js/issues/628#issuecomment-345412483)
There is no way for JavaScript running in browsers to open TCP sockets so "normal" MQTT is impossible in browser apps.
To get around this limitation, MQTT.js uses MQTT over WebSockets instead when it detects it's running in a browser.
- `broker_port` (Real; optional): The MQTT broker port, defaults to
Default to 8080 as MQTT over WebSockets, unencrypted as per
https://test.mosquitto.org/
- `broker_path` (String; optional): MQTT broker path
- `options` (Dict; optional): MQTT options (optional).
Otherwise defaults to DEFAULT_OPTIONS
- `topics` (Array of Strings; optional): MQTT topics this component is subscribed to.
- `id` (String; optional): The ID used to identify this component in Dash callbacks.
- `message` (Dict; optional): Topic or topic and payload to send.
When this property is set, a message is published
The topic is required, the payload is not.
- `incoming` (Dict; optional): Incoming message
"""
function ''_dashmqtt(; kwargs...)
        available_props = Symbol[:state, :broker_url, :protocol, :broker_port, :broker_path, :options, :topics, :id, :message, :incoming]
        wild_props = Symbol[]
        return Component("''_dashmqtt", "DashMqtt", "dash_mqtt", available_props, wild_props; kwargs...)
end


text:
"""
    is_diagonal_noise(prob::DEProblem)
"""
is_diagonal_noise(prob::DEProblem) = false
is_diagonal_noise(prob::AbstractRODEProblem{uType,tType,iip,Nothing}) where {uType,tType,iip} = true
is_diagonal_noise(prob::AbstractSDDEProblem{uType,tType,lType,iip,Nothing}) where {uType,tType,lType,iip,ND} = true

"""
    isinplace(prob::DEProblem)

Determine whether the function of the given problem operates in place or not.
"""
function isinplace(prob::DEProblem) end
isinplace(prob::AbstractLinearProblem{bType,iip}) where {bType,iip} = iip
isinplace(prob::AbstractNonlinearProblem{uType,iip}) where {uType,iip} = iip
isinplace(prob::AbstractQuadratureProblem{iip}) where {iip} = iip
isinplace(prob::AbstractODEProblem{uType,tType,iip}) where {uType,tType,iip} = iip
isinplace(prob::AbstractRODEProblem{uType,tType,iip,ND}) where {uType,tType,iip,ND} = iip
isinplace(prob::AbstractDDEProblem{uType,tType,lType,iip}) where {uType,tType,lType,iip} = iip
isinplace(prob::AbstractDAEProblem{uType,duType,tType,iip}) where {uType,duType,tType,iip} = iip
isinplace(prob::AbstractNoiseProblem) = isinplace(prob.noise)
isinplace(::SplitFunction{iip}) where iip = iip
isinplace(prob::AbstractSDDEProblem{uType,tType,lType,iip,ND}) where {uType,tType,lType,iip,ND} = iip


text:
module ConnectionPools

export Pod, Pool, acquire, release

import Base: acquire, release

connectionid(x) = objectid(x)

"""
    ConnectionTracker(conn::T)

Wraps a `Connection` of type `T`.
A `Connection` object must support the following interface:
  * `isopen(x)`: check if a `Connection` object is still open and can be used
  * `close(x)`: close a `Connection` object; `isopen(x)` should return false after calling `close`
  * `ConnectionPools.connectionid(x)`: optional method to distinguish `Connection` objects from each other; by default, calls `objectid(x)`, which is valid for `mutable struct` objects

The `idle_timestamp` field is a timestamp to track when a `Connection` was returned to a `Pod` and became idle_timestamp.

The `times_used` field keeps track of how many times the connection has been "used" (i.e. acquired then released).
"""
mutable struct ConnectionTracker{T}
    conn::T
    idle_timestamp::Float64
    times_used::Int
end

ConnectionTracker(conn::T) where {T} = ConnectionTracker(conn, time(), 0)

"""
    Pod(T; max_concurrent_connections::Int, idle_timeout::Int)

A threadsafe object for managing a pool of and the reuse of `Connection` objects (see [`ConnectionTracker`](@ref)).

A Pod manages a collection of `Connection`s and the following keyword arguments allow configuring the management thereof:

  * `max_concurrent_connections::Int=typemax(Int)`: controls the max # of currently acquired `Connection`s allowed
  * `idle_timeout::Int=typemax(Int)`: controls the max # of seconds a `Connection` may be idle_timeout before it should be closed and not reused

After creating a `Pod`, `Connection`s can be acquired by calling [`acquire`](@ref) and MUST
be subsequently released by calling [`release`](@ref).
"""
struct Pod{T}
    # this lock/condition protects the `conns` Vector and `active` Dict
    # no changes to either field should be made without holding this lock
    lock::Threads.Condition
    conns::Vector{ConnectionTracker{T}}
    active::Dict{Any, ConnectionTracker{T}}
    max_concurrent_connections::Int
    idle_timeout::Int
end

const MAX = typemax(Int)

function Pod(T; max_concurrent_connections::Int=MAX, idle_timeout::Int=MAX)
    return Pod(Threads.Condition(), ConnectionTracker{T}[], Dict{Any, ConnectionTracker{T}}(), max_concurrent_connections, idle_timeout)
end

# check if an idle_timeout `Connection` is still valid to be reused
function isvalid(pod::Pod{C}, conn::ConnectionTracker{C}) where {C}
    if (time() - conn.idle_timestamp) > pod.idle_timeout
        # println("connection idle_timeout timeout")
        # if the connection has been idle_timeout too long, close it
        close(conn.conn)
    elseif isopen(conn.conn)
        # println("found a valid connection to reuse")
        # dump(conn.conn)
        # otherwise, if the connection is open, this is a valid connection we can use!
        return true
    else
        # println("connection no longer open")
    end
    return false
end

function trackconnection!(pod::Pod{C}, conn::ConnectionTracker{C}) where {C}
    conn.times_used += 1
    id = connectionid(conn.conn)
    if haskey(pod.active, id)
        error("connection to be acquired is already an active, tracked connection from the pod according to the `connectionid(conn)`")
    end
    pod.active[id] = conn
    return conn.conn
end

"""
    acquire(f, pod::Pod{C}) -> C

Check first for existing `Connection`s in a `Pod` still valid to reuse,
and if so, return one. If no existing `Connection` is available for reuse,
call the provided function `f()`, which must return a new connection instance of type `C`.
This new connection instance will be tracked by the `Pod` and MUST be returned to the `Pod`
after use by calling `release(pod, conn)`.
"""
function acquire(f, pod::Pod)
    lock(pod.lock)
    try
        # if there are idle connections in the pod,
        # let's check if they're still valid and can be used again
        while !isempty(pod.conns)
            # Pod connections are FIFO, so grab the earliest returned connection
            # println("checking idle_timeout connections for reuse")
            conn = popfirst!(pod.conns)
            if isvalid(pod, conn)
                return trackconnection!(pod, conn)
            else
                # nothing, let the non-valid connection fall into GC oblivion
            end
        end
        # There were no idle connections able to be reused
        # If there are not too many already-active connections, create new
        if length(pod.active) < pod.max_concurrent_connections
            # println("no idle_timeout connections to reuse; creating new")
            return trackconnection!(pod, ConnectionTracker(f()))
        end
        # If we reach here, there were no valid idle connections and too many
        # currently-active connections, so we need to wait until for a "release"
        # event, which will mean a connection has been returned that can be reused,
        # or a "slot" has opened up so we can create a new connection, otherwise,
        # we'll just need to start the loop back over and wait again
        while true
            # this `wait` call will block on our Pod `lock` condition
            # until a connection is `release`ed and the condition
            # is notified
            # println("connection pool maxxed out; waiting for connection to be released to the pod")
            conn = wait(pod.lock)
            if conn !== nothing
                # println("checking recently released connection validity for reuse")
                if isvalid(pod, conn)
                    return trackconnection!(pod, conn)
                end
            end
            # if the Connection just returned to the Pod wasn't valid, the active
            # count should have at least went down, so we should be able to create a new one
            if length(pod.active) < pod.max_concurrent_connections
                return trackconnection!(pod, ConnectionTracker(f()))
            end
            # If for some reason there were still too many active connections, let's
            # start the loop back over waiting for connections to be returned
        end
    finally
        unlock(pod.lock)
    end
end

# ability to provide an already created connection object to insert into the Pod
# if Pod is already at max_concurrent_connections, acquire will wait until an
# active connection is released back to the pod
# it will be tracked among active connections and must be released
function acquire(pod::Pod{C}, c::C) where {C}
    lock(pod.lock)
    try
        if length(pod.active) < pod.max_concurrent_connections
            return trackconnection!(pod, ConnectionTracker(c))
        else
            while true
                # wait until pod gets a connection released
                conn = wait(pod.lock)
                if conn !== nothing
                    push!(pod.conns, conn)
                else
                    conn = ConnectionTracker(c)
                end
                return trackconnection!(pod, conn)
            end
        end
    finally
        unlock(pod.lock)
    end
end

function release(pod::Pod{C}, conn::C; return_for_reuse::Bool=true) where {C}
    lock(pod.lock)
    try
        # We first want to look up the corresponding ConnectionTracker object in our
        # Pod `active` Dict that tracks active connections
        id = connectionid(conn)
        # if, for some reason, it's not in our `active` tracking Dict
        # then something is wrong; you're trying to release a `Connection`
        # that this Pod currently doesn't think is active
        if !haskey(pod.active, id)
            error("couldn't find connection id in pod's current list of active connections; invalid release call; each acquired connection should be `release`ed ONLY once")
        end
        conn_tracker = pod.active[id]
        # remove the ConnectionTracker from our `active` Dict tracker
        delete!(pod.active, id)
        if return_for_reuse && isopen(conn)
            # reset the idle_timestamp of the ConnectionTracker
            conn_tracker.idle_timestamp = time()
            # check if there are any tasks waiting to acquire a connection
            if isempty(pod.lock)
                # if not, we put the connection back in the pod idle queue
                # in this case, there's no need to notify the pod lock/condition
                # since there's no one waiting to be notified anyway
                # println("returning connection (id='$(id)') to pod idle_timeout queue for reuse")
                push!(pod.conns, conn_tracker)
            else
                # if there are waiters, we notify the pod condition and pass the
                # ConnectionTracker object in the notification; we ensure to pass
                # all=false, so only one waiter is woken up and receives the
                # ConnectionTracker
                # println("returning connection (id='$(id)') to a waiting task for reuse")
                notify(pod.lock, conn_tracker; all=false)
            end
        else
            # if the user has, for whatever reason, requested this connection not be reused
            # anymore by passing `return_for_reuse=false`, then we've still removed it from
            # the `active` tracking and want to notify the pod in case there are waiting
            # acquire tasks that can now create a new connection
            # println("connection not reuseable; notifying pod that a connection has been released though")
            notify(pod.lock, nothing; all=false)
        end
    finally
        unlock(pod.lock)
    end
    return
end

"""
    Pool(T)

A threadsafe convenience object for managing multiple [`Pod`](@ref)s of connections.
A `Pod` of reuseable connections will be looked up by the `key` when calling `acquire(f, pool, key)`.
"""
struct Pool{C}
    lock::ReentrantLock
    pods::Dict{Any, Pod{C}}
end

Pool(C) = Pool(ReentrantLock(), Dict{Any, Pod{C}}())

"""
    acquire(f, pool::Pool{C}, key; max_concurrent_connections::Int, idle_timeout::Int, reuse::Int) -> C

Get a connection from a `pool`, looking up a `Pod` of reuseable connections
by the provided `key`. If no `Pod` exists for the given key yet, one will be
created and passed the `max`, `idle_timeout`, and `reuse` keyword arguments if provided.
The provided function `f` must create a new connection instance of type `C`.
The acquired connection MUST be returned to the pool by calling `release(pool, key, conn)` exactly once.
"""
function acquire(f, pool::Pool{C}, key; kw...) where {C}
    pod = lock(pool.lock) do
        get!(() -> Pod(C; kw...), pool.pods, key)
    end
    return acquire(f, pod)
end

function acquire(pool::Pool{C}, key, conn::C; kw...) where {C}
    pod = lock(pool.lock) do
        get!(() -> Pod(C; kw...), pool.pods, key)
    end
    return acquire(pod, conn)
end

"""
    release(pool::Pool{C}, key, conn::C)

Return an acquired connection to a `pool` with the same `key` provided when it was acquired.
"""
function release(pool::Pool{C}, key, conn::C; kw...) where {C}
    pod = lock(pool.lock) do
        pool.pods[key]
    end
    release(pod, conn; kw...)
    return
end

function reset!(pool::Pool)
    lock(pool.lock) do
        for pod in values(pool.pods)
            lock(pod.lock) do
                foreach(pod.conns) do conn
                    close(conn.conn)
                end
                empty!(pod.conns)
                for conn in values(pod.active)
                    close(conn.conn)
                end
                empty!(pod.active)
            end
        end
        empty!(pool.pods)
    end
    return
end

end # module


text:
function score(str)

end


text:
using DrWatson
@quickactivate "EPExperiment"

using EPExperiments

using Random
using Logging
using LoggingExtras
using JLD2
using FileIO
using CSV
using DataFrames
using LinearAlgebra: I
using StatsFuns: logsumexp
using StatsPlots

const LOG_DIR_NAME = "posterior_predictive_estimate"
const LOG_FILENAME = "out.log"

@with_kw struct PostPredEstimateConfig{T<:AnISConfig}
    experiment_name::String = "test"
    num_replications::Int = 1
    num_samples::Int = 10
    num_betas::Int = 101
    anis_params::T = AnISHMCConfig{Turing.ForwardDiffAD{10}}(
        proposal=AdvancedHMC.NUTS{MultinomialTS,GeneralisedNoUTurn}(
            AdvancedHMC.Leapfrog(0.5)
        ),
        num_steps=1,
        rejection_type=SimpleRejection()
    )
    seed::Int = 1234
end

function reprocess_pp_results(experiment_name; mcmc_baseline_name=nothing)
    result_folder = datadir(LOG_DIR_NAME, experiment_name)
    results = load(joinpath(result_folder, "results.jld2"))

    logger = TeeLogger(
        ConsoleLogger(),
        FileLogger(joinpath(result_folder, LOG_FILENAME))
    )

    process_post_pred_results(
        results["exp_estimate"],
        results["tabi_results"],
        results["experiment_config"],
        result_folder,
        logger;
        mcmc_baseline_name=mcmc_baseline_name
    )
end

function process_post_pred_results(
    exp_estimate,
    tabi_results,
    experiment_config,
    result_folder,
    logger;
    mcmc_baseline_name=nothing
)
    Z2_chn = tabi_results[:Z2_info]
    num_chains = size(Z2_chn, 3)
    num_samples = size(Z2_chn, 1)
    Z2_xs = Z2_chn[namesingroup(Z2_chn,:x)].value.data
    Z2_fxs = mapslices(Z2_xs; dims=[2]) do (x)
        pdf(MvNormal(-POST_PRED_Y_OBSERVED, 0.5*I), x)
    end
    Z2_fxs = reshape(Z2_fxs, (num_samples, num_chains))

    Z1_chn = tabi_results[:Z1_positive_info]
    Z1_xs = Z1_chn[namesingroup(Z1_chn,:x)].value.data
    Z1_fxs = mapslices(Z1_xs; dims=[2]) do (x)
        pdf(MvNormal(-POST_PRED_Y_OBSERVED, 0.5*I), x)
    end
    Z1_fxs = reshape(Z1_fxs, (num_samples, num_chains))

    Z2_lws = Array(Z2_chn[:log_weight])
    normalisation = exp(logsumexp(Z2_lws))
    anis_estimate = sum(exp.(Z2_lws) .* Z2_fxs) / normalisation

    Z1_lws = Array(Z1_chn[:log_weight])
    Z1_lws_retargeted = Z1_lws .- log.(Z1_fxs)
    Z2_lws_retargeted = Z2_lws .+ log.(Z2_fxs)

    ESS_retargeted = (
        Z1_positive_info = compute_ess(Z1_lws_retargeted),
        Z2_info = compute_ess(Z2_lws_retargeted)
    )

    num_xlogspaced = 100
    ep, _ = convergence_plot(
        "post_pred",
        Z1_chn,
        Z2_chn,
        x -> pdf(MvNormal(-POST_PRED_Y_OBSERVED, 0.5*I), x),
        POST_PRED_GROUND_TRUTH;
        num_xlogspaced=num_xlogspaced
    )
    savefig(ep, joinpath(result_folder, "error_plot.png"))

    ess_plot = make_ess_plot(
        Z1_lws,
        Z2_lws,
        Z2_lws_retargeted;
        take_min=false,
        legend=:topleft,
        num_xlogspaced=num_xlogspaced)
    savefig(ess_plot, joinpath(result_folder, "ess_plot.pdf"))

    if !isnothing(mcmc_baseline_name)
        # RSE plot
        mcmc_results = load(datadir(
            "posterior_predictive_mh_baseline",
            mcmc_baseline_name,
            "ess.jld2"
        ))
        mcmc_estimates = mcmc_results["exp_estimates"]
        fake_ess = mcmc_results["fake_ess"]

        mcmc_rse = relative_squared_error.(
            POST_PRED_GROUND_TRUTH, mcmc_estimates
        )

        mds, qs = get_median_and_quantiles(mcmc_rse)

        num_samples = size(Z2_lws, 1)
        if !isnothing(num_xlogspaced)
            log_ixs = unique(round.(Int, geomspace(1, num_samples, num_xlogspaced)))
            @show 450*log_ixs
            mds = mds[450*log_ixs]
            qs = qs[:,450*log_ixs]
            plot_ixs = log_ixs
        else
            ixs = Array(0:4500:size(mcmc_rse, 1))
            ixs[1] = 90
            mds = mds[ixs]
            qs = qs[:,ixs]

            plot_ixs = Array(0:50:10_000)
            plot_ixs[1] = 1
        end
        plot!(
            ep,
            plot_ixs,
            mds,
            ribbon=[(mds.-qs[1,:]), (qs[2,:]-mds)],
            label="MCMC"
        )
        savefig(ep, joinpath(result_folder, "error_plot_mcmc.pdf"))
    end

    with_logger(logger) do
        @info "Expectation estimate TABI: $(exp_estimate)"
        @info "Expectation estimate AnIS: $(anis_estimate)"

        for (k, est_results) in pairs(tabi_results)
            if isnothing(est_results)
                continue
            end
            msg = string([
                "$(string(k)):\n",
                "ESS: $(est_results.info[:ess])\n",
                "ESS retargeted: $(ESS_retargeted[k])\n",
                "Log evidence: $(est_results.logevidence)\n",
            ]...)

            @info "$(msg)"
        end
    end
end

function post_pred_estimate(experiment_config)
    @unpack seed, num_samples, num_replications = experiment_config
    @unpack num_betas, anis_params = experiment_config

    result_folder = mkpath(joinpath(
        datadir(LOG_DIR_NAME),
        savename(experiment_config)
    ))
    logger = TeeLogger(
        ConsoleLogger(),
        FileLogger(joinpath(result_folder, LOG_FILENAME))
    )

    Random.seed!(seed)

    post_pred_exp = post_pred(POST_PRED_Y_OBSERVED)

    # Make AnIS algorithm
    betas = Array(range(0, 1; length=num_betas))
    anis_alg = get_anis_alg(anis_params, betas)
    tabi = TABI(
        TuringAlgorithm(anis_alg, num_samples),
        TuringAlgorithm(anis_alg, 0),
        TuringAlgorithm(anis_alg, num_samples)
    )

    # Replicate results N times
    Z1_chns = Chains[]
    Z2_chns = Chains[]
    exp_ests = []
    for n in 1:num_replications
        println("Run $n:")
        @time begin
        exp_estimate, tabi_results = estimate_expectation(
            post_pred_exp,
            tabi;
            store_intermediate_samples=true
        )
        end
        push!(Z1_chns, tabi_results[:Z1_positive_info])
        push!(Z2_chns, tabi_results[:Z2_info])
        push!(exp_ests, exp_estimate)
    end

    Z1_chns = chainscat(Z1_chns...)
    Z2_chns = chainscat(Z2_chns...)
    tabi_results = (
        Z1_positive_info = Z1_chns,
        Z2_info = Z2_chns
    )
    exp_estimate = mean(exp_ests)

    # Save results and experiment config
    @tagsave(joinpath(result_folder, "results.jld2"), Dict(
        "exp_estimate" => exp_estimate,
        "tabi_results" => tabi_results,
        "experiment_config" => experiment_config
    ))

    # Process results
    process_post_pred_results(
        exp_estimate, tabi_results, experiment_config, result_folder, logger
    )

    @show POST_PRED_Y_OBSERVED
    @show pdf(
        MvNormal(POST_PRED_Y_OBSERVED / 2, I), -POST_PRED_Y_OBSERVED
    )
end

# This sets the transition kernel for AnIS.
function kernel_fn(prior_sample::AbstractArray, i)
    return MvNormal(size(prior_sample, 1), 0.5)
end
kernel_fn(prior_sample::NamedTuple, i) = map(x -> kernel_fn(x, i), prior_sample)

post_pred_estimate(PostPredEstimateConfig(
    experiment_name="collect_samples",
    num_samples=1_000,
    num_betas=101,
    num_replications=5,
    anis_params=AnISMHConfig(
        transition_kernel_cfg=MHFunction(
            kernel_fn=kernel_fn
        )
    )
))


text:
module QuCircuit

using QuComputStates,QuBase

import QuComputStates: stlzState

const σ₀=I
const σ₁=[0 1;1 0]
const σ₂=[0 -im;im 0]
const σ₃=[1 0;0 -1]
const sigmax = [0 1;1 0]
const sigmay = [0 -im;im 0]
const sigmaz = [1 0;0 -1]
const hadamard = [1/sqrt(2) 1/sqrt(2);1/sqrt(2) -1/sqrt(2)]

include("op.jl")
include("gates.jl")
include("circuit.jl")
include("process.jl")
include("chp.jl")

export σ₀,σ₁,σ₂,σ₃,sigmax,sigmay,sigmaz,hadamard

end # module


text:
module BSplineTests

include("constant.jl")
include("linear.jl")
include("quadratic.jl")
include("cubic.jl")
include("mixed.jl")
include("multivalued.jl")

end


text:
function load_robot()
    robot = Robot([0.,0.,0.], [0.,0.,0.], 0.1, 0.3, nothing)
    return robot
end

function load_object(pose, dimensions, id)
    dimensions = [0.4, 0.4]
    object = Object(id, pose, dimensions, :orange)
    return object
end

function init_environment(num_objects, positions)
    dimensions = [0.4, 0.4]
    objects = []
    for i=1:num_objects
        push!(objects, load_object(positions[i][1:2], dimensions, i))
    end
    return objects
end


text:
using QMTK
using Compat.Test

lhs = rand(5); rhs = rand(5)
@test_throws TypeError dot(Ket(RHS, rhs), Ket(LHS, lhs))
@test dot(Ket(LHS, lhs), Ket(RHS, rhs)) == dot(lhs, rhs)


text:
module STMOZOO

# execute your source file and export the module you made
include("local_greedydesc.jl")
export LocalSearch

end # module


text:
@testset "can_avx" begin

    @test LoopVectorization.ArrayInterface.can_avx(log)
    @test LoopVectorization.ArrayInterface.can_avx(log1p)
    @test LoopVectorization.ArrayInterface.can_avx(exp)
    @test LoopVectorization.ArrayInterface.can_avx(+)
    @test LoopVectorization.ArrayInterface.can_avx(-)
    @test LoopVectorization.ArrayInterface.can_avx(Base.FastMath.add_fast)
    @test LoopVectorization.ArrayInterface.can_avx(/)
    @test LoopVectorization.ArrayInterface.can_avx(sqrt)
    @test !LoopVectorization.ArrayInterface.can_avx(clenshaw)

end