camera.283d5d54.js 1.6 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568
  1. // modules are defined as an array
  2. // [ module function, map of requires ]
  3. //
  4. // map of requires is short require name -> numeric require
  5. //
  6. // anything defined in a previous bundle is accessed via the
  7. // orig method which is the require for previous bundles
  8. parcelRequire = (function (modules, cache, entry, globalName) {
  9. // Save the require from previous bundle to this closure if any
  10. var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
  11. var nodeRequire = typeof require === 'function' && require;
  12. function newRequire(name, jumped) {
  13. if (!cache[name]) {
  14. if (!modules[name]) {
  15. // if we cannot find the module within our internal map or
  16. // cache jump to the current global require ie. the last bundle
  17. // that was added to the page.
  18. var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
  19. if (!jumped && currentRequire) {
  20. return currentRequire(name, true);
  21. }
  22. // If there are other bundles on this page the require from the
  23. // previous one is saved to 'previousRequire'. Repeat this as
  24. // many times as there are bundles until the module is found or
  25. // we exhaust the require chain.
  26. if (previousRequire) {
  27. return previousRequire(name, true);
  28. }
  29. // Try the node require function if it exists.
  30. if (nodeRequire && typeof name === 'string') {
  31. return nodeRequire(name);
  32. }
  33. var err = new Error('Cannot find module \'' + name + '\'');
  34. err.code = 'MODULE_NOT_FOUND';
  35. throw err;
  36. }
  37. localRequire.resolve = resolve;
  38. localRequire.cache = {};
  39. var module = cache[name] = new newRequire.Module(name);
  40. modules[name][0].call(module.exports, localRequire, module, module.exports, this);
  41. }
  42. return cache[name].exports;
  43. function localRequire(x) {
  44. return newRequire(localRequire.resolve(x));
  45. }
  46. function resolve(x) {
  47. return modules[name][1][x] || x;
  48. }
  49. }
  50. function Module(moduleName) {
  51. this.id = moduleName;
  52. this.bundle = newRequire;
  53. this.exports = {};
  54. }
  55. newRequire.isParcelRequire = true;
  56. newRequire.Module = Module;
  57. newRequire.modules = modules;
  58. newRequire.cache = cache;
  59. newRequire.parent = previousRequire;
  60. newRequire.register = function (id, exports) {
  61. modules[id] = [function (require, module) {
  62. module.exports = exports;
  63. }, {}];
  64. };
  65. var error;
  66. for (var i = 0; i < entry.length; i++) {
  67. try {
  68. newRequire(entry[i]);
  69. } catch (e) {
  70. // Save first error but execute all entries
  71. if (!error) {
  72. error = e;
  73. }
  74. }
  75. }
  76. if (entry.length) {
  77. // Expose entry point to Node, AMD or browser globals
  78. // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
  79. var mainExports = newRequire(entry[entry.length - 1]);
  80. // CommonJS
  81. if (typeof exports === "object" && typeof module !== "undefined") {
  82. module.exports = mainExports;
  83. // RequireJS
  84. } else if (typeof define === "function" && define.amd) {
  85. define(function () {
  86. return mainExports;
  87. });
  88. // <script>
  89. } else if (globalName) {
  90. this[globalName] = mainExports;
  91. }
  92. }
  93. // Override the current require with this new one
  94. parcelRequire = newRequire;
  95. if (error) {
  96. // throw error from earlier, _after updating parcelRequire_
  97. throw error;
  98. }
  99. return newRequire;
  100. })({
  101. "node_modules/parcel-bundler/src/builtins/_empty.js": [function (require, module, exports) {
  102. }, {}], "node_modules/process/browser.js": [function (require, module, exports) {
  103. // shim for using process in browser
  104. var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it
  105. // don't break things. But we need to wrap it in a try catch in case it is
  106. // wrapped in strict mode code which doesn't define any globals. It's inside a
  107. // function because try/catches deoptimize in certain engines.
  108. var cachedSetTimeout;
  109. var cachedClearTimeout;
  110. function defaultSetTimout() {
  111. throw new Error('setTimeout has not been defined');
  112. }
  113. function defaultClearTimeout() {
  114. throw new Error('clearTimeout has not been defined');
  115. }
  116. (function () {
  117. try {
  118. if (typeof setTimeout === 'function') {
  119. cachedSetTimeout = setTimeout;
  120. } else {
  121. cachedSetTimeout = defaultSetTimout;
  122. }
  123. } catch (e) {
  124. cachedSetTimeout = defaultSetTimout;
  125. }
  126. try {
  127. if (typeof clearTimeout === 'function') {
  128. cachedClearTimeout = clearTimeout;
  129. } else {
  130. cachedClearTimeout = defaultClearTimeout;
  131. }
  132. } catch (e) {
  133. cachedClearTimeout = defaultClearTimeout;
  134. }
  135. })();
  136. function runTimeout(fun) {
  137. if (cachedSetTimeout === setTimeout) {
  138. //normal enviroments in sane situations
  139. return setTimeout(fun, 0);
  140. } // if setTimeout wasn't available but was latter defined
  141. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  142. cachedSetTimeout = setTimeout;
  143. return setTimeout(fun, 0);
  144. }
  145. try {
  146. // when when somebody has screwed with setTimeout but no I.E. maddness
  147. return cachedSetTimeout(fun, 0);
  148. } catch (e) {
  149. try {
  150. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  151. return cachedSetTimeout.call(null, fun, 0);
  152. } catch (e) {
  153. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  154. return cachedSetTimeout.call(this, fun, 0);
  155. }
  156. }
  157. }
  158. function runClearTimeout(marker) {
  159. if (cachedClearTimeout === clearTimeout) {
  160. //normal enviroments in sane situations
  161. return clearTimeout(marker);
  162. } // if clearTimeout wasn't available but was latter defined
  163. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  164. cachedClearTimeout = clearTimeout;
  165. return clearTimeout(marker);
  166. }
  167. try {
  168. // when when somebody has screwed with setTimeout but no I.E. maddness
  169. return cachedClearTimeout(marker);
  170. } catch (e) {
  171. try {
  172. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  173. return cachedClearTimeout.call(null, marker);
  174. } catch (e) {
  175. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  176. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  177. return cachedClearTimeout.call(this, marker);
  178. }
  179. }
  180. }
  181. var queue = [];
  182. var draining = false;
  183. var currentQueue;
  184. var queueIndex = -1;
  185. function cleanUpNextTick() {
  186. if (!draining || !currentQueue) {
  187. return;
  188. }
  189. draining = false;
  190. if (currentQueue.length) {
  191. queue = currentQueue.concat(queue);
  192. } else {
  193. queueIndex = -1;
  194. }
  195. if (queue.length) {
  196. drainQueue();
  197. }
  198. }
  199. function drainQueue() {
  200. if (draining) {
  201. return;
  202. }
  203. var timeout = runTimeout(cleanUpNextTick);
  204. draining = true;
  205. var len = queue.length;
  206. while (len) {
  207. currentQueue = queue;
  208. queue = [];
  209. while (++queueIndex < len) {
  210. if (currentQueue) {
  211. currentQueue[queueIndex].run();
  212. }
  213. }
  214. queueIndex = -1;
  215. len = queue.length;
  216. }
  217. currentQueue = null;
  218. draining = false;
  219. runClearTimeout(timeout);
  220. }
  221. process.nextTick = function (fun) {
  222. var args = new Array(arguments.length - 1);
  223. if (arguments.length > 1) {
  224. for (var i = 1; i < arguments.length; i++) {
  225. args[i - 1] = arguments[i];
  226. }
  227. }
  228. queue.push(new Item(fun, args));
  229. if (queue.length === 1 && !draining) {
  230. runTimeout(drainQueue);
  231. }
  232. }; // v8 likes predictible objects
  233. function Item(fun, array) {
  234. this.fun = fun;
  235. this.array = array;
  236. }
  237. Item.prototype.run = function () {
  238. this.fun.apply(null, this.array);
  239. };
  240. process.title = 'browser';
  241. process.env = {};
  242. process.argv = [];
  243. process.version = ''; // empty string to avoid regexp issues
  244. process.versions = {};
  245. function noop() { }
  246. process.on = noop;
  247. process.addListener = noop;
  248. process.once = noop;
  249. process.off = noop;
  250. process.removeListener = noop;
  251. process.removeAllListeners = noop;
  252. process.emit = noop;
  253. process.prependListener = noop;
  254. process.prependOnceListener = noop;
  255. process.listeners = function (name) {
  256. return [];
  257. };
  258. process.binding = function (name) {
  259. throw new Error('process.binding is not supported');
  260. };
  261. process.cwd = function () {
  262. return '/';
  263. };
  264. process.chdir = function (dir) {
  265. throw new Error('process.chdir is not supported');
  266. };
  267. process.umask = function () {
  268. return 0;
  269. };
  270. }, {}], "node_modules/base64-js/index.js": [function (require, module, exports) {
  271. 'use strict'
  272. exports.byteLength = byteLength
  273. exports.toByteArray = toByteArray
  274. exports.fromByteArray = fromByteArray
  275. var lookup = []
  276. var revLookup = []
  277. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  278. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  279. for (var i = 0, len = code.length; i < len; ++i) {
  280. lookup[i] = code[i]
  281. revLookup[code.charCodeAt(i)] = i
  282. }
  283. // Support decoding URL-safe base64 strings, as Node.js does.
  284. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  285. revLookup['-'.charCodeAt(0)] = 62
  286. revLookup['_'.charCodeAt(0)] = 63
  287. function getLens(b64) {
  288. var len = b64.length
  289. if (len % 4 > 0) {
  290. throw new Error('Invalid string. Length must be a multiple of 4')
  291. }
  292. // Trim off extra bytes after placeholder bytes are found
  293. // See: https://github.com/beatgammit/base64-js/issues/42
  294. var validLen = b64.indexOf('=')
  295. if (validLen === -1) validLen = len
  296. var placeHoldersLen = validLen === len
  297. ? 0
  298. : 4 - (validLen % 4)
  299. return [validLen, placeHoldersLen]
  300. }
  301. // base64 is 4/3 + up to two characters of the original data
  302. function byteLength(b64) {
  303. var lens = getLens(b64)
  304. var validLen = lens[0]
  305. var placeHoldersLen = lens[1]
  306. return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  307. }
  308. function _byteLength(b64, validLen, placeHoldersLen) {
  309. return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  310. }
  311. function toByteArray(b64) {
  312. var tmp
  313. var lens = getLens(b64)
  314. var validLen = lens[0]
  315. var placeHoldersLen = lens[1]
  316. var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
  317. var curByte = 0
  318. // if there are placeholders, only get up to the last complete 4 chars
  319. var len = placeHoldersLen > 0
  320. ? validLen - 4
  321. : validLen
  322. var i
  323. for (i = 0; i < len; i += 4) {
  324. tmp =
  325. (revLookup[b64.charCodeAt(i)] << 18) |
  326. (revLookup[b64.charCodeAt(i + 1)] << 12) |
  327. (revLookup[b64.charCodeAt(i + 2)] << 6) |
  328. revLookup[b64.charCodeAt(i + 3)]
  329. arr[curByte++] = (tmp >> 16) & 0xFF
  330. arr[curByte++] = (tmp >> 8) & 0xFF
  331. arr[curByte++] = tmp & 0xFF
  332. }
  333. if (placeHoldersLen === 2) {
  334. tmp =
  335. (revLookup[b64.charCodeAt(i)] << 2) |
  336. (revLookup[b64.charCodeAt(i + 1)] >> 4)
  337. arr[curByte++] = tmp & 0xFF
  338. }
  339. if (placeHoldersLen === 1) {
  340. tmp =
  341. (revLookup[b64.charCodeAt(i)] << 10) |
  342. (revLookup[b64.charCodeAt(i + 1)] << 4) |
  343. (revLookup[b64.charCodeAt(i + 2)] >> 2)
  344. arr[curByte++] = (tmp >> 8) & 0xFF
  345. arr[curByte++] = tmp & 0xFF
  346. }
  347. return arr
  348. }
  349. function tripletToBase64(num) {
  350. return lookup[num >> 18 & 0x3F] +
  351. lookup[num >> 12 & 0x3F] +
  352. lookup[num >> 6 & 0x3F] +
  353. lookup[num & 0x3F]
  354. }
  355. function encodeChunk(uint8, start, end) {
  356. var tmp
  357. var output = []
  358. for (var i = start; i < end; i += 3) {
  359. tmp =
  360. ((uint8[i] << 16) & 0xFF0000) +
  361. ((uint8[i + 1] << 8) & 0xFF00) +
  362. (uint8[i + 2] & 0xFF)
  363. output.push(tripletToBase64(tmp))
  364. }
  365. return output.join('')
  366. }
  367. function fromByteArray(uint8) {
  368. var tmp
  369. var len = uint8.length
  370. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  371. var parts = []
  372. var maxChunkLength = 16383 // must be multiple of 3
  373. // go through the array every three bytes, we'll deal with trailing stuff later
  374. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  375. parts.push(encodeChunk(
  376. uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
  377. ))
  378. }
  379. // pad the end with zeros, but make sure to not forget the extra bytes
  380. if (extraBytes === 1) {
  381. tmp = uint8[len - 1]
  382. parts.push(
  383. lookup[tmp >> 2] +
  384. lookup[(tmp << 4) & 0x3F] +
  385. '=='
  386. )
  387. } else if (extraBytes === 2) {
  388. tmp = (uint8[len - 2] << 8) + uint8[len - 1]
  389. parts.push(
  390. lookup[tmp >> 10] +
  391. lookup[(tmp >> 4) & 0x3F] +
  392. lookup[(tmp << 2) & 0x3F] +
  393. '='
  394. )
  395. }
  396. return parts.join('')
  397. }
  398. }, {}], "node_modules/ieee754/index.js": [function (require, module, exports) {
  399. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  400. var e, m
  401. var eLen = (nBytes * 8) - mLen - 1
  402. var eMax = (1 << eLen) - 1
  403. var eBias = eMax >> 1
  404. var nBits = -7
  405. var i = isLE ? (nBytes - 1) : 0
  406. var d = isLE ? -1 : 1
  407. var s = buffer[offset + i]
  408. i += d
  409. e = s & ((1 << (-nBits)) - 1)
  410. s >>= (-nBits)
  411. nBits += eLen
  412. for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) { }
  413. m = e & ((1 << (-nBits)) - 1)
  414. e >>= (-nBits)
  415. nBits += mLen
  416. for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) { }
  417. if (e === 0) {
  418. e = 1 - eBias
  419. } else if (e === eMax) {
  420. return m ? NaN : ((s ? -1 : 1) * Infinity)
  421. } else {
  422. m = m + Math.pow(2, mLen)
  423. e = e - eBias
  424. }
  425. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  426. }
  427. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  428. var e, m, c
  429. var eLen = (nBytes * 8) - mLen - 1
  430. var eMax = (1 << eLen) - 1
  431. var eBias = eMax >> 1
  432. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  433. var i = isLE ? 0 : (nBytes - 1)
  434. var d = isLE ? 1 : -1
  435. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  436. value = Math.abs(value)
  437. if (isNaN(value) || value === Infinity) {
  438. m = isNaN(value) ? 1 : 0
  439. e = eMax
  440. } else {
  441. e = Math.floor(Math.log(value) / Math.LN2)
  442. if (value * (c = Math.pow(2, -e)) < 1) {
  443. e--
  444. c *= 2
  445. }
  446. if (e + eBias >= 1) {
  447. value += rt / c
  448. } else {
  449. value += rt * Math.pow(2, 1 - eBias)
  450. }
  451. if (value * c >= 2) {
  452. e++
  453. c /= 2
  454. }
  455. if (e + eBias >= eMax) {
  456. m = 0
  457. e = eMax
  458. } else if (e + eBias >= 1) {
  459. m = ((value * c) - 1) * Math.pow(2, mLen)
  460. e = e + eBias
  461. } else {
  462. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  463. e = 0
  464. }
  465. }
  466. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) { }
  467. e = (e << mLen) | m
  468. eLen += mLen
  469. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) { }
  470. buffer[offset + i - d] |= s * 128
  471. }
  472. }, {}], "node_modules/isarray/index.js": [function (require, module, exports) {
  473. var toString = {}.toString;
  474. module.exports = Array.isArray || function (arr) {
  475. return toString.call(arr) == '[object Array]';
  476. };
  477. }, {}], "node_modules/buffer/index.js": [function (require, module, exports) {
  478. var global = arguments[3];
  479. /*!
  480. * The buffer module from node.js, for the browser.
  481. *
  482. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  483. * @license MIT
  484. */
  485. /* eslint-disable no-proto */
  486. 'use strict'
  487. var base64 = require('base64-js')
  488. var ieee754 = require('ieee754')
  489. var isArray = require('isarray')
  490. exports.Buffer = Buffer
  491. exports.SlowBuffer = SlowBuffer
  492. exports.INSPECT_MAX_BYTES = 50
  493. /**
  494. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  495. * === true Use Uint8Array implementation (fastest)
  496. * === false Use Object implementation (most compatible, even IE6)
  497. *
  498. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  499. * Opera 11.6+, iOS 4.2+.
  500. *
  501. * Due to various browser bugs, sometimes the Object implementation will be used even
  502. * when the browser supports typed arrays.
  503. *
  504. * Note:
  505. *
  506. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  507. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  508. *
  509. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  510. *
  511. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  512. * incorrect length in some situations.
  513. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  514. * get the Object implementation, which is slower but behaves correctly.
  515. */
  516. Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
  517. ? global.TYPED_ARRAY_SUPPORT
  518. : typedArraySupport()
  519. /*
  520. * Export kMaxLength after typed array support is determined.
  521. */
  522. exports.kMaxLength = kMaxLength()
  523. function typedArraySupport() {
  524. try {
  525. var arr = new Uint8Array(1)
  526. arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }
  527. return arr.foo() === 42 && // typed array instances can be augmented
  528. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  529. arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
  530. } catch (e) {
  531. return false
  532. }
  533. }
  534. function kMaxLength() {
  535. return Buffer.TYPED_ARRAY_SUPPORT
  536. ? 0x7fffffff
  537. : 0x3fffffff
  538. }
  539. function createBuffer(that, length) {
  540. if (kMaxLength() < length) {
  541. throw new RangeError('Invalid typed array length')
  542. }
  543. if (Buffer.TYPED_ARRAY_SUPPORT) {
  544. // Return an augmented `Uint8Array` instance, for best performance
  545. that = new Uint8Array(length)
  546. that.__proto__ = Buffer.prototype
  547. } else {
  548. // Fallback: Return an object instance of the Buffer class
  549. if (that === null) {
  550. that = new Buffer(length)
  551. }
  552. that.length = length
  553. }
  554. return that
  555. }
  556. /**
  557. * The Buffer constructor returns instances of `Uint8Array` that have their
  558. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  559. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  560. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  561. * returns a single octet.
  562. *
  563. * The `Uint8Array` prototype remains unmodified.
  564. */
  565. function Buffer(arg, encodingOrOffset, length) {
  566. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  567. return new Buffer(arg, encodingOrOffset, length)
  568. }
  569. // Common case.
  570. if (typeof arg === 'number') {
  571. if (typeof encodingOrOffset === 'string') {
  572. throw new Error(
  573. 'If encoding is specified then the first argument must be a string'
  574. )
  575. }
  576. return allocUnsafe(this, arg)
  577. }
  578. return from(this, arg, encodingOrOffset, length)
  579. }
  580. Buffer.poolSize = 8192 // not used by this implementation
  581. // TODO: Legacy, not needed anymore. Remove in next major version.
  582. Buffer._augment = function (arr) {
  583. arr.__proto__ = Buffer.prototype
  584. return arr
  585. }
  586. function from(that, value, encodingOrOffset, length) {
  587. if (typeof value === 'number') {
  588. throw new TypeError('"value" argument must not be a number')
  589. }
  590. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  591. return fromArrayBuffer(that, value, encodingOrOffset, length)
  592. }
  593. if (typeof value === 'string') {
  594. return fromString(that, value, encodingOrOffset)
  595. }
  596. return fromObject(that, value)
  597. }
  598. /**
  599. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  600. * if value is a number.
  601. * Buffer.from(str[, encoding])
  602. * Buffer.from(array)
  603. * Buffer.from(buffer)
  604. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  605. **/
  606. Buffer.from = function (value, encodingOrOffset, length) {
  607. return from(null, value, encodingOrOffset, length)
  608. }
  609. if (Buffer.TYPED_ARRAY_SUPPORT) {
  610. Buffer.prototype.__proto__ = Uint8Array.prototype
  611. Buffer.__proto__ = Uint8Array
  612. if (typeof Symbol !== 'undefined' && Symbol.species &&
  613. Buffer[Symbol.species] === Buffer) {
  614. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  615. Object.defineProperty(Buffer, Symbol.species, {
  616. value: null,
  617. configurable: true
  618. })
  619. }
  620. }
  621. function assertSize(size) {
  622. if (typeof size !== 'number') {
  623. throw new TypeError('"size" argument must be a number')
  624. } else if (size < 0) {
  625. throw new RangeError('"size" argument must not be negative')
  626. }
  627. }
  628. function alloc(that, size, fill, encoding) {
  629. assertSize(size)
  630. if (size <= 0) {
  631. return createBuffer(that, size)
  632. }
  633. if (fill !== undefined) {
  634. // Only pay attention to encoding if it's a string. This
  635. // prevents accidentally sending in a number that would
  636. // be interpretted as a start offset.
  637. return typeof encoding === 'string'
  638. ? createBuffer(that, size).fill(fill, encoding)
  639. : createBuffer(that, size).fill(fill)
  640. }
  641. return createBuffer(that, size)
  642. }
  643. /**
  644. * Creates a new filled Buffer instance.
  645. * alloc(size[, fill[, encoding]])
  646. **/
  647. Buffer.alloc = function (size, fill, encoding) {
  648. return alloc(null, size, fill, encoding)
  649. }
  650. function allocUnsafe(that, size) {
  651. assertSize(size)
  652. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
  653. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  654. for (var i = 0; i < size; ++i) {
  655. that[i] = 0
  656. }
  657. }
  658. return that
  659. }
  660. /**
  661. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  662. * */
  663. Buffer.allocUnsafe = function (size) {
  664. return allocUnsafe(null, size)
  665. }
  666. /**
  667. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  668. */
  669. Buffer.allocUnsafeSlow = function (size) {
  670. return allocUnsafe(null, size)
  671. }
  672. function fromString(that, string, encoding) {
  673. if (typeof encoding !== 'string' || encoding === '') {
  674. encoding = 'utf8'
  675. }
  676. if (!Buffer.isEncoding(encoding)) {
  677. throw new TypeError('"encoding" must be a valid string encoding')
  678. }
  679. var length = byteLength(string, encoding) | 0
  680. that = createBuffer(that, length)
  681. var actual = that.write(string, encoding)
  682. if (actual !== length) {
  683. // Writing a hex string, for example, that contains invalid characters will
  684. // cause everything after the first invalid character to be ignored. (e.g.
  685. // 'abxxcd' will be treated as 'ab')
  686. that = that.slice(0, actual)
  687. }
  688. return that
  689. }
  690. function fromArrayLike(that, array) {
  691. var length = array.length < 0 ? 0 : checked(array.length) | 0
  692. that = createBuffer(that, length)
  693. for (var i = 0; i < length; i += 1) {
  694. that[i] = array[i] & 255
  695. }
  696. return that
  697. }
  698. function fromArrayBuffer(that, array, byteOffset, length) {
  699. array.byteLength // this throws if `array` is not a valid ArrayBuffer
  700. if (byteOffset < 0 || array.byteLength < byteOffset) {
  701. throw new RangeError('\'offset\' is out of bounds')
  702. }
  703. if (array.byteLength < byteOffset + (length || 0)) {
  704. throw new RangeError('\'length\' is out of bounds')
  705. }
  706. if (byteOffset === undefined && length === undefined) {
  707. array = new Uint8Array(array)
  708. } else if (length === undefined) {
  709. array = new Uint8Array(array, byteOffset)
  710. } else {
  711. array = new Uint8Array(array, byteOffset, length)
  712. }
  713. if (Buffer.TYPED_ARRAY_SUPPORT) {
  714. // Return an augmented `Uint8Array` instance, for best performance
  715. that = array
  716. that.__proto__ = Buffer.prototype
  717. } else {
  718. // Fallback: Return an object instance of the Buffer class
  719. that = fromArrayLike(that, array)
  720. }
  721. return that
  722. }
  723. function fromObject(that, obj) {
  724. if (Buffer.isBuffer(obj)) {
  725. var len = checked(obj.length) | 0
  726. that = createBuffer(that, len)
  727. if (that.length === 0) {
  728. return that
  729. }
  730. obj.copy(that, 0, 0, len)
  731. return that
  732. }
  733. if (obj) {
  734. if ((typeof ArrayBuffer !== 'undefined' &&
  735. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  736. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  737. return createBuffer(that, 0)
  738. }
  739. return fromArrayLike(that, obj)
  740. }
  741. if (obj.type === 'Buffer' && isArray(obj.data)) {
  742. return fromArrayLike(that, obj.data)
  743. }
  744. }
  745. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  746. }
  747. function checked(length) {
  748. // Note: cannot use `length < kMaxLength()` here because that fails when
  749. // length is NaN (which is otherwise coerced to zero.)
  750. if (length >= kMaxLength()) {
  751. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  752. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  753. }
  754. return length | 0
  755. }
  756. function SlowBuffer(length) {
  757. if (+length != length) { // eslint-disable-line eqeqeq
  758. length = 0
  759. }
  760. return Buffer.alloc(+length)
  761. }
  762. Buffer.isBuffer = function isBuffer(b) {
  763. return !!(b != null && b._isBuffer)
  764. }
  765. Buffer.compare = function compare(a, b) {
  766. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  767. throw new TypeError('Arguments must be Buffers')
  768. }
  769. if (a === b) return 0
  770. var x = a.length
  771. var y = b.length
  772. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  773. if (a[i] !== b[i]) {
  774. x = a[i]
  775. y = b[i]
  776. break
  777. }
  778. }
  779. if (x < y) return -1
  780. if (y < x) return 1
  781. return 0
  782. }
  783. Buffer.isEncoding = function isEncoding(encoding) {
  784. switch (String(encoding).toLowerCase()) {
  785. case 'hex':
  786. case 'utf8':
  787. case 'utf-8':
  788. case 'ascii':
  789. case 'latin1':
  790. case 'binary':
  791. case 'base64':
  792. case 'ucs2':
  793. case 'ucs-2':
  794. case 'utf16le':
  795. case 'utf-16le':
  796. return true
  797. default:
  798. return false
  799. }
  800. }
  801. Buffer.concat = function concat(list, length) {
  802. if (!isArray(list)) {
  803. throw new TypeError('"list" argument must be an Array of Buffers')
  804. }
  805. if (list.length === 0) {
  806. return Buffer.alloc(0)
  807. }
  808. var i
  809. if (length === undefined) {
  810. length = 0
  811. for (i = 0; i < list.length; ++i) {
  812. length += list[i].length
  813. }
  814. }
  815. var buffer = Buffer.allocUnsafe(length)
  816. var pos = 0
  817. for (i = 0; i < list.length; ++i) {
  818. var buf = list[i]
  819. if (!Buffer.isBuffer(buf)) {
  820. throw new TypeError('"list" argument must be an Array of Buffers')
  821. }
  822. buf.copy(buffer, pos)
  823. pos += buf.length
  824. }
  825. return buffer
  826. }
  827. function byteLength(string, encoding) {
  828. if (Buffer.isBuffer(string)) {
  829. return string.length
  830. }
  831. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  832. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  833. return string.byteLength
  834. }
  835. if (typeof string !== 'string') {
  836. string = '' + string
  837. }
  838. var len = string.length
  839. if (len === 0) return 0
  840. // Use a for loop to avoid recursion
  841. var loweredCase = false
  842. for (; ;) {
  843. switch (encoding) {
  844. case 'ascii':
  845. case 'latin1':
  846. case 'binary':
  847. return len
  848. case 'utf8':
  849. case 'utf-8':
  850. case undefined:
  851. return utf8ToBytes(string).length
  852. case 'ucs2':
  853. case 'ucs-2':
  854. case 'utf16le':
  855. case 'utf-16le':
  856. return len * 2
  857. case 'hex':
  858. return len >>> 1
  859. case 'base64':
  860. return base64ToBytes(string).length
  861. default:
  862. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  863. encoding = ('' + encoding).toLowerCase()
  864. loweredCase = true
  865. }
  866. }
  867. }
  868. Buffer.byteLength = byteLength
  869. function slowToString(encoding, start, end) {
  870. var loweredCase = false
  871. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  872. // property of a typed array.
  873. // This behaves neither like String nor Uint8Array in that we set start/end
  874. // to their upper/lower bounds if the value passed is out of range.
  875. // undefined is handled specially as per ECMA-262 6th Edition,
  876. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  877. if (start === undefined || start < 0) {
  878. start = 0
  879. }
  880. // Return early if start > this.length. Done here to prevent potential uint32
  881. // coercion fail below.
  882. if (start > this.length) {
  883. return ''
  884. }
  885. if (end === undefined || end > this.length) {
  886. end = this.length
  887. }
  888. if (end <= 0) {
  889. return ''
  890. }
  891. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  892. end >>>= 0
  893. start >>>= 0
  894. if (end <= start) {
  895. return ''
  896. }
  897. if (!encoding) encoding = 'utf8'
  898. while (true) {
  899. switch (encoding) {
  900. case 'hex':
  901. return hexSlice(this, start, end)
  902. case 'utf8':
  903. case 'utf-8':
  904. return utf8Slice(this, start, end)
  905. case 'ascii':
  906. return asciiSlice(this, start, end)
  907. case 'latin1':
  908. case 'binary':
  909. return latin1Slice(this, start, end)
  910. case 'base64':
  911. return base64Slice(this, start, end)
  912. case 'ucs2':
  913. case 'ucs-2':
  914. case 'utf16le':
  915. case 'utf-16le':
  916. return utf16leSlice(this, start, end)
  917. default:
  918. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  919. encoding = (encoding + '').toLowerCase()
  920. loweredCase = true
  921. }
  922. }
  923. }
  924. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  925. // Buffer instances.
  926. Buffer.prototype._isBuffer = true
  927. function swap(b, n, m) {
  928. var i = b[n]
  929. b[n] = b[m]
  930. b[m] = i
  931. }
  932. Buffer.prototype.swap16 = function swap16() {
  933. var len = this.length
  934. if (len % 2 !== 0) {
  935. throw new RangeError('Buffer size must be a multiple of 16-bits')
  936. }
  937. for (var i = 0; i < len; i += 2) {
  938. swap(this, i, i + 1)
  939. }
  940. return this
  941. }
  942. Buffer.prototype.swap32 = function swap32() {
  943. var len = this.length
  944. if (len % 4 !== 0) {
  945. throw new RangeError('Buffer size must be a multiple of 32-bits')
  946. }
  947. for (var i = 0; i < len; i += 4) {
  948. swap(this, i, i + 3)
  949. swap(this, i + 1, i + 2)
  950. }
  951. return this
  952. }
  953. Buffer.prototype.swap64 = function swap64() {
  954. var len = this.length
  955. if (len % 8 !== 0) {
  956. throw new RangeError('Buffer size must be a multiple of 64-bits')
  957. }
  958. for (var i = 0; i < len; i += 8) {
  959. swap(this, i, i + 7)
  960. swap(this, i + 1, i + 6)
  961. swap(this, i + 2, i + 5)
  962. swap(this, i + 3, i + 4)
  963. }
  964. return this
  965. }
  966. Buffer.prototype.toString = function toString() {
  967. var length = this.length | 0
  968. if (length === 0) return ''
  969. if (arguments.length === 0) return utf8Slice(this, 0, length)
  970. return slowToString.apply(this, arguments)
  971. }
  972. Buffer.prototype.equals = function equals(b) {
  973. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  974. if (this === b) return true
  975. return Buffer.compare(this, b) === 0
  976. }
  977. Buffer.prototype.inspect = function inspect() {
  978. var str = ''
  979. var max = exports.INSPECT_MAX_BYTES
  980. if (this.length > 0) {
  981. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  982. if (this.length > max) str += ' ... '
  983. }
  984. return '<Buffer ' + str + '>'
  985. }
  986. Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
  987. if (!Buffer.isBuffer(target)) {
  988. throw new TypeError('Argument must be a Buffer')
  989. }
  990. if (start === undefined) {
  991. start = 0
  992. }
  993. if (end === undefined) {
  994. end = target ? target.length : 0
  995. }
  996. if (thisStart === undefined) {
  997. thisStart = 0
  998. }
  999. if (thisEnd === undefined) {
  1000. thisEnd = this.length
  1001. }
  1002. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  1003. throw new RangeError('out of range index')
  1004. }
  1005. if (thisStart >= thisEnd && start >= end) {
  1006. return 0
  1007. }
  1008. if (thisStart >= thisEnd) {
  1009. return -1
  1010. }
  1011. if (start >= end) {
  1012. return 1
  1013. }
  1014. start >>>= 0
  1015. end >>>= 0
  1016. thisStart >>>= 0
  1017. thisEnd >>>= 0
  1018. if (this === target) return 0
  1019. var x = thisEnd - thisStart
  1020. var y = end - start
  1021. var len = Math.min(x, y)
  1022. var thisCopy = this.slice(thisStart, thisEnd)
  1023. var targetCopy = target.slice(start, end)
  1024. for (var i = 0; i < len; ++i) {
  1025. if (thisCopy[i] !== targetCopy[i]) {
  1026. x = thisCopy[i]
  1027. y = targetCopy[i]
  1028. break
  1029. }
  1030. }
  1031. if (x < y) return -1
  1032. if (y < x) return 1
  1033. return 0
  1034. }
  1035. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  1036. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  1037. //
  1038. // Arguments:
  1039. // - buffer - a Buffer to search
  1040. // - val - a string, Buffer, or number
  1041. // - byteOffset - an index into `buffer`; will be clamped to an int32
  1042. // - encoding - an optional encoding, relevant is val is a string
  1043. // - dir - true for indexOf, false for lastIndexOf
  1044. function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
  1045. // Empty buffer means no match
  1046. if (buffer.length === 0) return -1
  1047. // Normalize byteOffset
  1048. if (typeof byteOffset === 'string') {
  1049. encoding = byteOffset
  1050. byteOffset = 0
  1051. } else if (byteOffset > 0x7fffffff) {
  1052. byteOffset = 0x7fffffff
  1053. } else if (byteOffset < -0x80000000) {
  1054. byteOffset = -0x80000000
  1055. }
  1056. byteOffset = +byteOffset // Coerce to Number.
  1057. if (isNaN(byteOffset)) {
  1058. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  1059. byteOffset = dir ? 0 : (buffer.length - 1)
  1060. }
  1061. // Normalize byteOffset: negative offsets start from the end of the buffer
  1062. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  1063. if (byteOffset >= buffer.length) {
  1064. if (dir) return -1
  1065. else byteOffset = buffer.length - 1
  1066. } else if (byteOffset < 0) {
  1067. if (dir) byteOffset = 0
  1068. else return -1
  1069. }
  1070. // Normalize val
  1071. if (typeof val === 'string') {
  1072. val = Buffer.from(val, encoding)
  1073. }
  1074. // Finally, search either indexOf (if dir is true) or lastIndexOf
  1075. if (Buffer.isBuffer(val)) {
  1076. // Special case: looking for empty string/buffer always fails
  1077. if (val.length === 0) {
  1078. return -1
  1079. }
  1080. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  1081. } else if (typeof val === 'number') {
  1082. val = val & 0xFF // Search for a byte value [0-255]
  1083. if (Buffer.TYPED_ARRAY_SUPPORT &&
  1084. typeof Uint8Array.prototype.indexOf === 'function') {
  1085. if (dir) {
  1086. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  1087. } else {
  1088. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  1089. }
  1090. }
  1091. return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
  1092. }
  1093. throw new TypeError('val must be string, number or Buffer')
  1094. }
  1095. function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
  1096. var indexSize = 1
  1097. var arrLength = arr.length
  1098. var valLength = val.length
  1099. if (encoding !== undefined) {
  1100. encoding = String(encoding).toLowerCase()
  1101. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  1102. encoding === 'utf16le' || encoding === 'utf-16le') {
  1103. if (arr.length < 2 || val.length < 2) {
  1104. return -1
  1105. }
  1106. indexSize = 2
  1107. arrLength /= 2
  1108. valLength /= 2
  1109. byteOffset /= 2
  1110. }
  1111. }
  1112. function read(buf, i) {
  1113. if (indexSize === 1) {
  1114. return buf[i]
  1115. } else {
  1116. return buf.readUInt16BE(i * indexSize)
  1117. }
  1118. }
  1119. var i
  1120. if (dir) {
  1121. var foundIndex = -1
  1122. for (i = byteOffset; i < arrLength; i++) {
  1123. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  1124. if (foundIndex === -1) foundIndex = i
  1125. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  1126. } else {
  1127. if (foundIndex !== -1) i -= i - foundIndex
  1128. foundIndex = -1
  1129. }
  1130. }
  1131. } else {
  1132. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  1133. for (i = byteOffset; i >= 0; i--) {
  1134. var found = true
  1135. for (var j = 0; j < valLength; j++) {
  1136. if (read(arr, i + j) !== read(val, j)) {
  1137. found = false
  1138. break
  1139. }
  1140. }
  1141. if (found) return i
  1142. }
  1143. }
  1144. return -1
  1145. }
  1146. Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
  1147. return this.indexOf(val, byteOffset, encoding) !== -1
  1148. }
  1149. Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
  1150. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  1151. }
  1152. Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
  1153. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  1154. }
  1155. function hexWrite(buf, string, offset, length) {
  1156. offset = Number(offset) || 0
  1157. var remaining = buf.length - offset
  1158. if (!length) {
  1159. length = remaining
  1160. } else {
  1161. length = Number(length)
  1162. if (length > remaining) {
  1163. length = remaining
  1164. }
  1165. }
  1166. // must be an even number of digits
  1167. var strLen = string.length
  1168. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
  1169. if (length > strLen / 2) {
  1170. length = strLen / 2
  1171. }
  1172. for (var i = 0; i < length; ++i) {
  1173. var parsed = parseInt(string.substr(i * 2, 2), 16)
  1174. if (isNaN(parsed)) return i
  1175. buf[offset + i] = parsed
  1176. }
  1177. return i
  1178. }
  1179. function utf8Write(buf, string, offset, length) {
  1180. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  1181. }
  1182. function asciiWrite(buf, string, offset, length) {
  1183. return blitBuffer(asciiToBytes(string), buf, offset, length)
  1184. }
  1185. function latin1Write(buf, string, offset, length) {
  1186. return asciiWrite(buf, string, offset, length)
  1187. }
  1188. function base64Write(buf, string, offset, length) {
  1189. return blitBuffer(base64ToBytes(string), buf, offset, length)
  1190. }
  1191. function ucs2Write(buf, string, offset, length) {
  1192. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  1193. }
  1194. Buffer.prototype.write = function write(string, offset, length, encoding) {
  1195. // Buffer#write(string)
  1196. if (offset === undefined) {
  1197. encoding = 'utf8'
  1198. length = this.length
  1199. offset = 0
  1200. // Buffer#write(string, encoding)
  1201. } else if (length === undefined && typeof offset === 'string') {
  1202. encoding = offset
  1203. length = this.length
  1204. offset = 0
  1205. // Buffer#write(string, offset[, length][, encoding])
  1206. } else if (isFinite(offset)) {
  1207. offset = offset | 0
  1208. if (isFinite(length)) {
  1209. length = length | 0
  1210. if (encoding === undefined) encoding = 'utf8'
  1211. } else {
  1212. encoding = length
  1213. length = undefined
  1214. }
  1215. // legacy write(string, encoding, offset, length) - remove in v0.13
  1216. } else {
  1217. throw new Error(
  1218. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  1219. )
  1220. }
  1221. var remaining = this.length - offset
  1222. if (length === undefined || length > remaining) length = remaining
  1223. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  1224. throw new RangeError('Attempt to write outside buffer bounds')
  1225. }
  1226. if (!encoding) encoding = 'utf8'
  1227. var loweredCase = false
  1228. for (; ;) {
  1229. switch (encoding) {
  1230. case 'hex':
  1231. return hexWrite(this, string, offset, length)
  1232. case 'utf8':
  1233. case 'utf-8':
  1234. return utf8Write(this, string, offset, length)
  1235. case 'ascii':
  1236. return asciiWrite(this, string, offset, length)
  1237. case 'latin1':
  1238. case 'binary':
  1239. return latin1Write(this, string, offset, length)
  1240. case 'base64':
  1241. // Warning: maxLength not taken into account in base64Write
  1242. return base64Write(this, string, offset, length)
  1243. case 'ucs2':
  1244. case 'ucs-2':
  1245. case 'utf16le':
  1246. case 'utf-16le':
  1247. return ucs2Write(this, string, offset, length)
  1248. default:
  1249. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  1250. encoding = ('' + encoding).toLowerCase()
  1251. loweredCase = true
  1252. }
  1253. }
  1254. }
  1255. Buffer.prototype.toJSON = function toJSON() {
  1256. return {
  1257. type: 'Buffer',
  1258. data: Array.prototype.slice.call(this._arr || this, 0)
  1259. }
  1260. }
  1261. function base64Slice(buf, start, end) {
  1262. if (start === 0 && end === buf.length) {
  1263. return base64.fromByteArray(buf)
  1264. } else {
  1265. return base64.fromByteArray(buf.slice(start, end))
  1266. }
  1267. }
  1268. function utf8Slice(buf, start, end) {
  1269. end = Math.min(buf.length, end)
  1270. var res = []
  1271. var i = start
  1272. while (i < end) {
  1273. var firstByte = buf[i]
  1274. var codePoint = null
  1275. var bytesPerSequence = (firstByte > 0xEF) ? 4
  1276. : (firstByte > 0xDF) ? 3
  1277. : (firstByte > 0xBF) ? 2
  1278. : 1
  1279. if (i + bytesPerSequence <= end) {
  1280. var secondByte, thirdByte, fourthByte, tempCodePoint
  1281. switch (bytesPerSequence) {
  1282. case 1:
  1283. if (firstByte < 0x80) {
  1284. codePoint = firstByte
  1285. }
  1286. break
  1287. case 2:
  1288. secondByte = buf[i + 1]
  1289. if ((secondByte & 0xC0) === 0x80) {
  1290. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  1291. if (tempCodePoint > 0x7F) {
  1292. codePoint = tempCodePoint
  1293. }
  1294. }
  1295. break
  1296. case 3:
  1297. secondByte = buf[i + 1]
  1298. thirdByte = buf[i + 2]
  1299. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  1300. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  1301. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  1302. codePoint = tempCodePoint
  1303. }
  1304. }
  1305. break
  1306. case 4:
  1307. secondByte = buf[i + 1]
  1308. thirdByte = buf[i + 2]
  1309. fourthByte = buf[i + 3]
  1310. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  1311. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  1312. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  1313. codePoint = tempCodePoint
  1314. }
  1315. }
  1316. }
  1317. }
  1318. if (codePoint === null) {
  1319. // we did not generate a valid codePoint so insert a
  1320. // replacement char (U+FFFD) and advance only 1 byte
  1321. codePoint = 0xFFFD
  1322. bytesPerSequence = 1
  1323. } else if (codePoint > 0xFFFF) {
  1324. // encode to utf16 (surrogate pair dance)
  1325. codePoint -= 0x10000
  1326. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  1327. codePoint = 0xDC00 | codePoint & 0x3FF
  1328. }
  1329. res.push(codePoint)
  1330. i += bytesPerSequence
  1331. }
  1332. return decodeCodePointsArray(res)
  1333. }
  1334. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  1335. // the lowest limit is Chrome, with 0x10000 args.
  1336. // We go 1 magnitude less, for safety
  1337. var MAX_ARGUMENTS_LENGTH = 0x1000
  1338. function decodeCodePointsArray(codePoints) {
  1339. var len = codePoints.length
  1340. if (len <= MAX_ARGUMENTS_LENGTH) {
  1341. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  1342. }
  1343. // Decode in chunks to avoid "call stack size exceeded".
  1344. var res = ''
  1345. var i = 0
  1346. while (i < len) {
  1347. res += String.fromCharCode.apply(
  1348. String,
  1349. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  1350. )
  1351. }
  1352. return res
  1353. }
  1354. function asciiSlice(buf, start, end) {
  1355. var ret = ''
  1356. end = Math.min(buf.length, end)
  1357. for (var i = start; i < end; ++i) {
  1358. ret += String.fromCharCode(buf[i] & 0x7F)
  1359. }
  1360. return ret
  1361. }
  1362. function latin1Slice(buf, start, end) {
  1363. var ret = ''
  1364. end = Math.min(buf.length, end)
  1365. for (var i = start; i < end; ++i) {
  1366. ret += String.fromCharCode(buf[i])
  1367. }
  1368. return ret
  1369. }
  1370. function hexSlice(buf, start, end) {
  1371. var len = buf.length
  1372. if (!start || start < 0) start = 0
  1373. if (!end || end < 0 || end > len) end = len
  1374. var out = ''
  1375. for (var i = start; i < end; ++i) {
  1376. out += toHex(buf[i])
  1377. }
  1378. return out
  1379. }
  1380. function utf16leSlice(buf, start, end) {
  1381. var bytes = buf.slice(start, end)
  1382. var res = ''
  1383. for (var i = 0; i < bytes.length; i += 2) {
  1384. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  1385. }
  1386. return res
  1387. }
  1388. Buffer.prototype.slice = function slice(start, end) {
  1389. var len = this.length
  1390. start = ~~start
  1391. end = end === undefined ? len : ~~end
  1392. if (start < 0) {
  1393. start += len
  1394. if (start < 0) start = 0
  1395. } else if (start > len) {
  1396. start = len
  1397. }
  1398. if (end < 0) {
  1399. end += len
  1400. if (end < 0) end = 0
  1401. } else if (end > len) {
  1402. end = len
  1403. }
  1404. if (end < start) end = start
  1405. var newBuf
  1406. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1407. newBuf = this.subarray(start, end)
  1408. newBuf.__proto__ = Buffer.prototype
  1409. } else {
  1410. var sliceLen = end - start
  1411. newBuf = new Buffer(sliceLen, undefined)
  1412. for (var i = 0; i < sliceLen; ++i) {
  1413. newBuf[i] = this[i + start]
  1414. }
  1415. }
  1416. return newBuf
  1417. }
  1418. /*
  1419. * Need to make sure that buffer isn't trying to write out of bounds.
  1420. */
  1421. function checkOffset(offset, ext, length) {
  1422. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  1423. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  1424. }
  1425. Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
  1426. offset = offset | 0
  1427. byteLength = byteLength | 0
  1428. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1429. var val = this[offset]
  1430. var mul = 1
  1431. var i = 0
  1432. while (++i < byteLength && (mul *= 0x100)) {
  1433. val += this[offset + i] * mul
  1434. }
  1435. return val
  1436. }
  1437. Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
  1438. offset = offset | 0
  1439. byteLength = byteLength | 0
  1440. if (!noAssert) {
  1441. checkOffset(offset, byteLength, this.length)
  1442. }
  1443. var val = this[offset + --byteLength]
  1444. var mul = 1
  1445. while (byteLength > 0 && (mul *= 0x100)) {
  1446. val += this[offset + --byteLength] * mul
  1447. }
  1448. return val
  1449. }
  1450. Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
  1451. if (!noAssert) checkOffset(offset, 1, this.length)
  1452. return this[offset]
  1453. }
  1454. Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
  1455. if (!noAssert) checkOffset(offset, 2, this.length)
  1456. return this[offset] | (this[offset + 1] << 8)
  1457. }
  1458. Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
  1459. if (!noAssert) checkOffset(offset, 2, this.length)
  1460. return (this[offset] << 8) | this[offset + 1]
  1461. }
  1462. Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
  1463. if (!noAssert) checkOffset(offset, 4, this.length)
  1464. return ((this[offset]) |
  1465. (this[offset + 1] << 8) |
  1466. (this[offset + 2] << 16)) +
  1467. (this[offset + 3] * 0x1000000)
  1468. }
  1469. Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
  1470. if (!noAssert) checkOffset(offset, 4, this.length)
  1471. return (this[offset] * 0x1000000) +
  1472. ((this[offset + 1] << 16) |
  1473. (this[offset + 2] << 8) |
  1474. this[offset + 3])
  1475. }
  1476. Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
  1477. offset = offset | 0
  1478. byteLength = byteLength | 0
  1479. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1480. var val = this[offset]
  1481. var mul = 1
  1482. var i = 0
  1483. while (++i < byteLength && (mul *= 0x100)) {
  1484. val += this[offset + i] * mul
  1485. }
  1486. mul *= 0x80
  1487. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1488. return val
  1489. }
  1490. Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
  1491. offset = offset | 0
  1492. byteLength = byteLength | 0
  1493. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1494. var i = byteLength
  1495. var mul = 1
  1496. var val = this[offset + --i]
  1497. while (i > 0 && (mul *= 0x100)) {
  1498. val += this[offset + --i] * mul
  1499. }
  1500. mul *= 0x80
  1501. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1502. return val
  1503. }
  1504. Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {
  1505. if (!noAssert) checkOffset(offset, 1, this.length)
  1506. if (!(this[offset] & 0x80)) return (this[offset])
  1507. return ((0xff - this[offset] + 1) * -1)
  1508. }
  1509. Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
  1510. if (!noAssert) checkOffset(offset, 2, this.length)
  1511. var val = this[offset] | (this[offset + 1] << 8)
  1512. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1513. }
  1514. Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
  1515. if (!noAssert) checkOffset(offset, 2, this.length)
  1516. var val = this[offset + 1] | (this[offset] << 8)
  1517. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1518. }
  1519. Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
  1520. if (!noAssert) checkOffset(offset, 4, this.length)
  1521. return (this[offset]) |
  1522. (this[offset + 1] << 8) |
  1523. (this[offset + 2] << 16) |
  1524. (this[offset + 3] << 24)
  1525. }
  1526. Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
  1527. if (!noAssert) checkOffset(offset, 4, this.length)
  1528. return (this[offset] << 24) |
  1529. (this[offset + 1] << 16) |
  1530. (this[offset + 2] << 8) |
  1531. (this[offset + 3])
  1532. }
  1533. Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
  1534. if (!noAssert) checkOffset(offset, 4, this.length)
  1535. return ieee754.read(this, offset, true, 23, 4)
  1536. }
  1537. Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
  1538. if (!noAssert) checkOffset(offset, 4, this.length)
  1539. return ieee754.read(this, offset, false, 23, 4)
  1540. }
  1541. Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
  1542. if (!noAssert) checkOffset(offset, 8, this.length)
  1543. return ieee754.read(this, offset, true, 52, 8)
  1544. }
  1545. Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
  1546. if (!noAssert) checkOffset(offset, 8, this.length)
  1547. return ieee754.read(this, offset, false, 52, 8)
  1548. }
  1549. function checkInt(buf, value, offset, ext, max, min) {
  1550. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  1551. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  1552. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1553. }
  1554. Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
  1555. value = +value
  1556. offset = offset | 0
  1557. byteLength = byteLength | 0
  1558. if (!noAssert) {
  1559. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  1560. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1561. }
  1562. var mul = 1
  1563. var i = 0
  1564. this[offset] = value & 0xFF
  1565. while (++i < byteLength && (mul *= 0x100)) {
  1566. this[offset + i] = (value / mul) & 0xFF
  1567. }
  1568. return offset + byteLength
  1569. }
  1570. Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
  1571. value = +value
  1572. offset = offset | 0
  1573. byteLength = byteLength | 0
  1574. if (!noAssert) {
  1575. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  1576. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1577. }
  1578. var i = byteLength - 1
  1579. var mul = 1
  1580. this[offset + i] = value & 0xFF
  1581. while (--i >= 0 && (mul *= 0x100)) {
  1582. this[offset + i] = (value / mul) & 0xFF
  1583. }
  1584. return offset + byteLength
  1585. }
  1586. Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
  1587. value = +value
  1588. offset = offset | 0
  1589. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  1590. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  1591. this[offset] = (value & 0xff)
  1592. return offset + 1
  1593. }
  1594. function objectWriteUInt16(buf, value, offset, littleEndian) {
  1595. if (value < 0) value = 0xffff + value + 1
  1596. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  1597. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  1598. (littleEndian ? i : 1 - i) * 8
  1599. }
  1600. }
  1601. Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
  1602. value = +value
  1603. offset = offset | 0
  1604. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1605. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1606. this[offset] = (value & 0xff)
  1607. this[offset + 1] = (value >>> 8)
  1608. } else {
  1609. objectWriteUInt16(this, value, offset, true)
  1610. }
  1611. return offset + 2
  1612. }
  1613. Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
  1614. value = +value
  1615. offset = offset | 0
  1616. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1617. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1618. this[offset] = (value >>> 8)
  1619. this[offset + 1] = (value & 0xff)
  1620. } else {
  1621. objectWriteUInt16(this, value, offset, false)
  1622. }
  1623. return offset + 2
  1624. }
  1625. function objectWriteUInt32(buf, value, offset, littleEndian) {
  1626. if (value < 0) value = 0xffffffff + value + 1
  1627. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  1628. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  1629. }
  1630. }
  1631. Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
  1632. value = +value
  1633. offset = offset | 0
  1634. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1635. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1636. this[offset + 3] = (value >>> 24)
  1637. this[offset + 2] = (value >>> 16)
  1638. this[offset + 1] = (value >>> 8)
  1639. this[offset] = (value & 0xff)
  1640. } else {
  1641. objectWriteUInt32(this, value, offset, true)
  1642. }
  1643. return offset + 4
  1644. }
  1645. Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
  1646. value = +value
  1647. offset = offset | 0
  1648. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1649. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1650. this[offset] = (value >>> 24)
  1651. this[offset + 1] = (value >>> 16)
  1652. this[offset + 2] = (value >>> 8)
  1653. this[offset + 3] = (value & 0xff)
  1654. } else {
  1655. objectWriteUInt32(this, value, offset, false)
  1656. }
  1657. return offset + 4
  1658. }
  1659. Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {
  1660. value = +value
  1661. offset = offset | 0
  1662. if (!noAssert) {
  1663. var limit = Math.pow(2, 8 * byteLength - 1)
  1664. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1665. }
  1666. var i = 0
  1667. var mul = 1
  1668. var sub = 0
  1669. this[offset] = value & 0xFF
  1670. while (++i < byteLength && (mul *= 0x100)) {
  1671. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  1672. sub = 1
  1673. }
  1674. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1675. }
  1676. return offset + byteLength
  1677. }
  1678. Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {
  1679. value = +value
  1680. offset = offset | 0
  1681. if (!noAssert) {
  1682. var limit = Math.pow(2, 8 * byteLength - 1)
  1683. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1684. }
  1685. var i = byteLength - 1
  1686. var mul = 1
  1687. var sub = 0
  1688. this[offset + i] = value & 0xFF
  1689. while (--i >= 0 && (mul *= 0x100)) {
  1690. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  1691. sub = 1
  1692. }
  1693. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1694. }
  1695. return offset + byteLength
  1696. }
  1697. Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
  1698. value = +value
  1699. offset = offset | 0
  1700. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  1701. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  1702. if (value < 0) value = 0xff + value + 1
  1703. this[offset] = (value & 0xff)
  1704. return offset + 1
  1705. }
  1706. Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
  1707. value = +value
  1708. offset = offset | 0
  1709. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1710. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1711. this[offset] = (value & 0xff)
  1712. this[offset + 1] = (value >>> 8)
  1713. } else {
  1714. objectWriteUInt16(this, value, offset, true)
  1715. }
  1716. return offset + 2
  1717. }
  1718. Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
  1719. value = +value
  1720. offset = offset | 0
  1721. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1722. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1723. this[offset] = (value >>> 8)
  1724. this[offset + 1] = (value & 0xff)
  1725. } else {
  1726. objectWriteUInt16(this, value, offset, false)
  1727. }
  1728. return offset + 2
  1729. }
  1730. Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
  1731. value = +value
  1732. offset = offset | 0
  1733. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1734. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1735. this[offset] = (value & 0xff)
  1736. this[offset + 1] = (value >>> 8)
  1737. this[offset + 2] = (value >>> 16)
  1738. this[offset + 3] = (value >>> 24)
  1739. } else {
  1740. objectWriteUInt32(this, value, offset, true)
  1741. }
  1742. return offset + 4
  1743. }
  1744. Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
  1745. value = +value
  1746. offset = offset | 0
  1747. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1748. if (value < 0) value = 0xffffffff + value + 1
  1749. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1750. this[offset] = (value >>> 24)
  1751. this[offset + 1] = (value >>> 16)
  1752. this[offset + 2] = (value >>> 8)
  1753. this[offset + 3] = (value & 0xff)
  1754. } else {
  1755. objectWriteUInt32(this, value, offset, false)
  1756. }
  1757. return offset + 4
  1758. }
  1759. function checkIEEE754(buf, value, offset, ext, max, min) {
  1760. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1761. if (offset < 0) throw new RangeError('Index out of range')
  1762. }
  1763. function writeFloat(buf, value, offset, littleEndian, noAssert) {
  1764. if (!noAssert) {
  1765. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  1766. }
  1767. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  1768. return offset + 4
  1769. }
  1770. Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
  1771. return writeFloat(this, value, offset, true, noAssert)
  1772. }
  1773. Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
  1774. return writeFloat(this, value, offset, false, noAssert)
  1775. }
  1776. function writeDouble(buf, value, offset, littleEndian, noAssert) {
  1777. if (!noAssert) {
  1778. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  1779. }
  1780. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  1781. return offset + 8
  1782. }
  1783. Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
  1784. return writeDouble(this, value, offset, true, noAssert)
  1785. }
  1786. Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
  1787. return writeDouble(this, value, offset, false, noAssert)
  1788. }
  1789. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  1790. Buffer.prototype.copy = function copy(target, targetStart, start, end) {
  1791. if (!start) start = 0
  1792. if (!end && end !== 0) end = this.length
  1793. if (targetStart >= target.length) targetStart = target.length
  1794. if (!targetStart) targetStart = 0
  1795. if (end > 0 && end < start) end = start
  1796. // Copy 0 bytes; we're done
  1797. if (end === start) return 0
  1798. if (target.length === 0 || this.length === 0) return 0
  1799. // Fatal error conditions
  1800. if (targetStart < 0) {
  1801. throw new RangeError('targetStart out of bounds')
  1802. }
  1803. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  1804. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  1805. // Are we oob?
  1806. if (end > this.length) end = this.length
  1807. if (target.length - targetStart < end - start) {
  1808. end = target.length - targetStart + start
  1809. }
  1810. var len = end - start
  1811. var i
  1812. if (this === target && start < targetStart && targetStart < end) {
  1813. // descending copy from end
  1814. for (i = len - 1; i >= 0; --i) {
  1815. target[i + targetStart] = this[i + start]
  1816. }
  1817. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  1818. // ascending copy from start
  1819. for (i = 0; i < len; ++i) {
  1820. target[i + targetStart] = this[i + start]
  1821. }
  1822. } else {
  1823. Uint8Array.prototype.set.call(
  1824. target,
  1825. this.subarray(start, start + len),
  1826. targetStart
  1827. )
  1828. }
  1829. return len
  1830. }
  1831. // Usage:
  1832. // buffer.fill(number[, offset[, end]])
  1833. // buffer.fill(buffer[, offset[, end]])
  1834. // buffer.fill(string[, offset[, end]][, encoding])
  1835. Buffer.prototype.fill = function fill(val, start, end, encoding) {
  1836. // Handle string cases:
  1837. if (typeof val === 'string') {
  1838. if (typeof start === 'string') {
  1839. encoding = start
  1840. start = 0
  1841. end = this.length
  1842. } else if (typeof end === 'string') {
  1843. encoding = end
  1844. end = this.length
  1845. }
  1846. if (val.length === 1) {
  1847. var code = val.charCodeAt(0)
  1848. if (code < 256) {
  1849. val = code
  1850. }
  1851. }
  1852. if (encoding !== undefined && typeof encoding !== 'string') {
  1853. throw new TypeError('encoding must be a string')
  1854. }
  1855. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  1856. throw new TypeError('Unknown encoding: ' + encoding)
  1857. }
  1858. } else if (typeof val === 'number') {
  1859. val = val & 255
  1860. }
  1861. // Invalid ranges are not set to a default, so can range check early.
  1862. if (start < 0 || this.length < start || this.length < end) {
  1863. throw new RangeError('Out of range index')
  1864. }
  1865. if (end <= start) {
  1866. return this
  1867. }
  1868. start = start >>> 0
  1869. end = end === undefined ? this.length : end >>> 0
  1870. if (!val) val = 0
  1871. var i
  1872. if (typeof val === 'number') {
  1873. for (i = start; i < end; ++i) {
  1874. this[i] = val
  1875. }
  1876. } else {
  1877. var bytes = Buffer.isBuffer(val)
  1878. ? val
  1879. : utf8ToBytes(new Buffer(val, encoding).toString())
  1880. var len = bytes.length
  1881. for (i = 0; i < end - start; ++i) {
  1882. this[i + start] = bytes[i % len]
  1883. }
  1884. }
  1885. return this
  1886. }
  1887. // HELPER FUNCTIONS
  1888. // ================
  1889. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
  1890. function base64clean(str) {
  1891. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  1892. str = stringtrim(str).replace(INVALID_BASE64_RE, '')
  1893. // Node converts strings with length < 2 to ''
  1894. if (str.length < 2) return ''
  1895. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  1896. while (str.length % 4 !== 0) {
  1897. str = str + '='
  1898. }
  1899. return str
  1900. }
  1901. function stringtrim(str) {
  1902. if (str.trim) return str.trim()
  1903. return str.replace(/^\s+|\s+$/g, '')
  1904. }
  1905. function toHex(n) {
  1906. if (n < 16) return '0' + n.toString(16)
  1907. return n.toString(16)
  1908. }
  1909. function utf8ToBytes(string, units) {
  1910. units = units || Infinity
  1911. var codePoint
  1912. var length = string.length
  1913. var leadSurrogate = null
  1914. var bytes = []
  1915. for (var i = 0; i < length; ++i) {
  1916. codePoint = string.charCodeAt(i)
  1917. // is surrogate component
  1918. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  1919. // last char was a lead
  1920. if (!leadSurrogate) {
  1921. // no lead yet
  1922. if (codePoint > 0xDBFF) {
  1923. // unexpected trail
  1924. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1925. continue
  1926. } else if (i + 1 === length) {
  1927. // unpaired lead
  1928. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1929. continue
  1930. }
  1931. // valid lead
  1932. leadSurrogate = codePoint
  1933. continue
  1934. }
  1935. // 2 leads in a row
  1936. if (codePoint < 0xDC00) {
  1937. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1938. leadSurrogate = codePoint
  1939. continue
  1940. }
  1941. // valid surrogate pair
  1942. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  1943. } else if (leadSurrogate) {
  1944. // valid bmp char, but last char was a lead
  1945. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1946. }
  1947. leadSurrogate = null
  1948. // encode utf8
  1949. if (codePoint < 0x80) {
  1950. if ((units -= 1) < 0) break
  1951. bytes.push(codePoint)
  1952. } else if (codePoint < 0x800) {
  1953. if ((units -= 2) < 0) break
  1954. bytes.push(
  1955. codePoint >> 0x6 | 0xC0,
  1956. codePoint & 0x3F | 0x80
  1957. )
  1958. } else if (codePoint < 0x10000) {
  1959. if ((units -= 3) < 0) break
  1960. bytes.push(
  1961. codePoint >> 0xC | 0xE0,
  1962. codePoint >> 0x6 & 0x3F | 0x80,
  1963. codePoint & 0x3F | 0x80
  1964. )
  1965. } else if (codePoint < 0x110000) {
  1966. if ((units -= 4) < 0) break
  1967. bytes.push(
  1968. codePoint >> 0x12 | 0xF0,
  1969. codePoint >> 0xC & 0x3F | 0x80,
  1970. codePoint >> 0x6 & 0x3F | 0x80,
  1971. codePoint & 0x3F | 0x80
  1972. )
  1973. } else {
  1974. throw new Error('Invalid code point')
  1975. }
  1976. }
  1977. return bytes
  1978. }
  1979. function asciiToBytes(str) {
  1980. var byteArray = []
  1981. for (var i = 0; i < str.length; ++i) {
  1982. // Node's code seems to be doing this and not & 0x7F..
  1983. byteArray.push(str.charCodeAt(i) & 0xFF)
  1984. }
  1985. return byteArray
  1986. }
  1987. function utf16leToBytes(str, units) {
  1988. var c, hi, lo
  1989. var byteArray = []
  1990. for (var i = 0; i < str.length; ++i) {
  1991. if ((units -= 2) < 0) break
  1992. c = str.charCodeAt(i)
  1993. hi = c >> 8
  1994. lo = c % 256
  1995. byteArray.push(lo)
  1996. byteArray.push(hi)
  1997. }
  1998. return byteArray
  1999. }
  2000. function base64ToBytes(str) {
  2001. return base64.toByteArray(base64clean(str))
  2002. }
  2003. function blitBuffer(src, dst, offset, length) {
  2004. for (var i = 0; i < length; ++i) {
  2005. if ((i + offset >= dst.length) || (i >= src.length)) break
  2006. dst[i + offset] = src[i]
  2007. }
  2008. return i
  2009. }
  2010. function isnan(val) {
  2011. return val !== val // eslint-disable-line no-self-compare
  2012. }
  2013. }, { "base64-js": "node_modules/base64-js/index.js", "ieee754": "node_modules/ieee754/index.js", "isarray": "node_modules/isarray/index.js", "buffer": "node_modules/buffer/index.js" }], "node_modules/@tensorflow/tfjs-core/dist/tf-core.esm.js": [function (require, module, exports) {
  2014. var global = arguments[3];
  2015. var process = require("process");
  2016. var Buffer = require("buffer").Buffer;
  2017. "use strict";
  2018. Object.defineProperty(exports, "__esModule", {
  2019. value: true
  2020. });
  2021. exports.backend = on;
  2022. exports.buffer = ur;
  2023. exports.customGrad = oo;
  2024. exports.deprecationWarn = ze;
  2025. exports.disableDeprecationWarnings = Ve;
  2026. exports.dispose = Xe;
  2027. exports.disposeVariables = Ge;
  2028. exports.enableDebugMode = Ue;
  2029. exports.enableProdMode = We;
  2030. exports.engine = He;
  2031. exports.env = a;
  2032. exports.fill = Ln;
  2033. exports.findBackend = en;
  2034. exports.findBackendFactory = nn;
  2035. exports.getBackend = Ze;
  2036. exports.getKernel = s;
  2037. exports.getKernelsForBackend = c;
  2038. exports.grad = Zr;
  2039. exports.grads = to;
  2040. exports.keep = $e;
  2041. exports.linspace = Wn;
  2042. exports.memory = qe;
  2043. exports.nextFrame = ep;
  2044. exports.ones = Bn;
  2045. exports.op = Cn;
  2046. exports.print = sr;
  2047. exports.profile = Ke;
  2048. exports.range = Un;
  2049. exports.ready = Je;
  2050. exports.registerBackend = rn;
  2051. exports.registerKernel = l;
  2052. exports.removeBackend = tn;
  2053. exports.scalar = An;
  2054. exports.setBackend = Qe;
  2055. exports.setPlatform = an;
  2056. exports.tensor = kn;
  2057. exports.tensor1d = Dn;
  2058. exports.tensor2d = Tn;
  2059. exports.tensor3d = Nn;
  2060. exports.tensor4d = Fn;
  2061. exports.tensor5d = On;
  2062. exports.tensor6d = _n;
  2063. exports.tidy = je;
  2064. exports.time = Ye;
  2065. exports.unregisterKernel = h;
  2066. exports.valueAndGrad = eo;
  2067. exports.valueAndGrads = no;
  2068. exports.variable = Mn;
  2069. exports.variableGrads = ro;
  2070. exports.zeros = Pn;
  2071. exports.isFinite = exports.irfft = exports.io = exports.inTopKAsync = exports.image = exports.imag = exports.ifft = exports.hannWindow = exports.hammingWindow = exports.greaterStrict = exports.greaterEqualStrict = exports.greaterEqual = exports.greater = exports.gatherND = exports.gather = exports.fused = exports.frame = exports.floorDiv = exports.floor = exports.fft = exports.eye = exports.expm1 = exports.expandDims = exports.exp = exports.erf = exports.equalStrict = exports.equal = exports.elu = exports.dropout = exports.dot = exports.divStrict = exports.div = exports.diag = exports.depthwiseConv2d = exports.depthToSpace = exports.cumsum = exports.cosh = exports.cos = exports.conv3dTranspose = exports.conv3d = exports.conv2dTranspose = exports.conv2d = exports.conv1d = exports.concat4d = exports.concat3d = exports.concat2d = exports.concat1d = exports.concat = exports.complex = exports.clone = exports.clipByValue = exports.ceil = exports.cast = exports.browser = exports.booleanMaskAsync = exports.batchToSpaceND = exports.batchNormalization4d = exports.batchNormalization3d = exports.batchNormalization2d = exports.batchNormalization = exports.batchNorm4d = exports.batchNorm3d = exports.batchNorm2d = exports.batchNorm = exports.basicLSTMCell = exports.backend_util = exports.avgPool3d = exports.avgPool = exports.atanh = exports.atan2 = exports.atan = exports.asinh = exports.asin = exports.argMin = exports.argMax = exports.any = exports.all = exports.addStrict = exports.addN = exports.add = exports.acosh = exports.acos = exports.abs = exports.Variable = exports.TensorBuffer = exports.Tensor = exports.SGDOptimizer = exports.Reduction = exports.Rank = exports.RMSPropOptimizer = exports.Optimizer = exports.MomentumOptimizer = exports.KernelBackend = exports.Environment = exports.ENV = exports.DataStorage = exports.AdamaxOptimizer = exports.AdamOptimizer = exports.AdagradOptimizer = exports.AdadeltaOptimizer = void 0;
  2072. exports.stack = exports.squeeze = exports.squaredDifferenceStrict = exports.squaredDifference = exports.square = exports.sqrt = exports.split = exports.spectral = exports.sparseToDense = exports.spaceToBatchND = exports.softplus = exports.softmax = exports.slice_util = exports.slice4d = exports.slice3d = exports.slice2d = exports.slice1d = exports.slice = exports.sinh = exports.sin = exports.signal = exports.sign = exports.sigmoid = exports.setdiff1dAsync = exports.serialization = exports.separableConv2d = exports.selu = exports.scatterND = exports.rsqrt = exports.round = exports.rfft = exports.reverse4d = exports.reverse3d = exports.reverse2d = exports.reverse1d = exports.reverse = exports.reshape = exports.relu6 = exports.relu = exports.reciprocal = exports.real = exports.randomUniform = exports.randomNormal = exports.randomGamma = exports.rand = exports.prod = exports.prelu = exports.powStrict = exports.pow = exports.pool = exports.pad4d = exports.pad3d = exports.pad2d = exports.pad1d = exports.pad = exports.outerProduct = exports.onesLike = exports.oneHot = exports.notEqualStrict = exports.notEqual = exports.norm = exports.neg = exports.multinomial = exports.multiRNNCell = exports.mulStrict = exports.mul = exports.movingAverage = exports.moments = exports.modStrict = exports.mod = exports.minimumStrict = exports.minimum = exports.min = exports.mean = exports.maximumStrict = exports.maximum = exports.maxPool3d = exports.maxPool = exports.max = exports.math = exports.matMul = exports.losses = exports.logicalXor = exports.logicalOr = exports.logicalNot = exports.logicalAnd = exports.logSumExp = exports.logSoftmax = exports.logSigmoid = exports.log1p = exports.log = exports.localResponseNormalization = exports.linalg = exports.lessStrict = exports.lessEqualStrict = exports.lessEqual = exports.less = exports.leakyRelu = exports.isNaN = exports.isInf = void 0;
  2073. exports.zerosLike = exports.whereAsync = exports.where = exports.webgl = exports.version_core = exports.util = exports.unstack = exports.unsortedSegmentSum = exports.truncatedNormal = exports.transpose = exports.train = exports.topk = exports.tile = exports.test_util = exports.tensor_util = exports.tanh = exports.tan = exports.sum = exports.subStrict = exports.sub = exports.stridedSlice = exports.stft = exports.step = void 0;
  2074. /**
  2075. * @license
  2076. * Copyright 2019 Google LLC. All Rights Reserved.
  2077. * Licensed under the Apache License, Version 2.0 (the "License");
  2078. * you may not use this file except in compliance with the License.
  2079. * You may obtain a copy of the License at
  2080. *
  2081. * http://www.apache.org/licenses/LICENSE-2.0
  2082. *
  2083. * Unless required by applicable law or agreed to in writing, software
  2084. * distributed under the License is distributed on an "AS IS" BASIS,
  2085. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2086. * See the License for the specific language governing permissions and
  2087. * limitations under the License.
  2088. * =============================================================================
  2089. */
  2090. var t = function (e, n) {
  2091. return (t = Object.setPrototypeOf || {
  2092. __proto__: []
  2093. } instanceof Array && function (t, e) {
  2094. t.__proto__ = e;
  2095. } || function (t, e) {
  2096. for (var n in e) e.hasOwnProperty(n) && (t[n] = e[n]);
  2097. })(e, n);
  2098. };
  2099. function e(e, n) {
  2100. function r() {
  2101. this.constructor = e;
  2102. }
  2103. t(e, n), e.prototype = null === n ? Object.create(n) : (r.prototype = n.prototype, new r());
  2104. }
  2105. function n(t, e, n, r) {
  2106. return new (n || (n = Promise))(function (o, a) {
  2107. function i(t) {
  2108. try {
  2109. s(r.next(t));
  2110. } catch (t) {
  2111. a(t);
  2112. }
  2113. }
  2114. function u(t) {
  2115. try {
  2116. s(r.throw(t));
  2117. } catch (t) {
  2118. a(t);
  2119. }
  2120. }
  2121. function s(t) {
  2122. t.done ? o(t.value) : new n(function (e) {
  2123. e(t.value);
  2124. }).then(i, u);
  2125. }
  2126. s((r = r.apply(t, e || [])).next());
  2127. });
  2128. }
  2129. function r(t, e) {
  2130. var n,
  2131. r,
  2132. o,
  2133. a,
  2134. i = {
  2135. label: 0,
  2136. sent: function () {
  2137. if (1 & o[0]) throw o[1];
  2138. return o[1];
  2139. },
  2140. trys: [],
  2141. ops: []
  2142. };
  2143. return a = {
  2144. next: u(0),
  2145. throw: u(1),
  2146. return: u(2)
  2147. }, "function" == typeof Symbol && (a[Symbol.iterator] = function () {
  2148. return this;
  2149. }), a;
  2150. function u(a) {
  2151. return function (u) {
  2152. return function (a) {
  2153. if (n) throw new TypeError("Generator is already executing.");
  2154. for (; i;) try {
  2155. if (n = 1, r && (o = 2 & a[0] ? r.return : a[0] ? r.throw || ((o = r.return) && o.call(r), 0) : r.next) && !(o = o.call(r, a[1])).done) return o;
  2156. switch (r = 0, o && (a = [2 & a[0], o.value]), a[0]) {
  2157. case 0:
  2158. case 1:
  2159. o = a;
  2160. break;
  2161. case 4:
  2162. return i.label++, {
  2163. value: a[1],
  2164. done: !1
  2165. };
  2166. case 5:
  2167. i.label++, r = a[1], a = [0];
  2168. continue;
  2169. case 7:
  2170. a = i.ops.pop(), i.trys.pop();
  2171. continue;
  2172. default:
  2173. if (!(o = (o = i.trys).length > 0 && o[o.length - 1]) && (6 === a[0] || 2 === a[0])) {
  2174. i = 0;
  2175. continue;
  2176. }
  2177. if (3 === a[0] && (!o || a[1] > o[0] && a[1] < o[3])) {
  2178. i.label = a[1];
  2179. break;
  2180. }
  2181. if (6 === a[0] && i.label < o[1]) {
  2182. i.label = o[1], o = a;
  2183. break;
  2184. }
  2185. if (o && i.label < o[2]) {
  2186. i.label = o[2], i.ops.push(a);
  2187. break;
  2188. }
  2189. o[2] && i.ops.pop(), i.trys.pop();
  2190. continue;
  2191. }
  2192. a = e.call(t, i);
  2193. } catch (t) {
  2194. a = [6, t], r = 0;
  2195. } finally {
  2196. n = o = 0;
  2197. }
  2198. if (5 & a[0]) throw a[1];
  2199. return {
  2200. value: a[0] ? a[1] : void 0,
  2201. done: !0
  2202. };
  2203. }([a, u]);
  2204. };
  2205. }
  2206. }
  2207. var o = function () {
  2208. function t(t) {
  2209. this.global = t, this.flags = {}, this.flagRegistry = {}, this.urlFlags = {}, this.populateURLFlags();
  2210. }
  2211. return t.prototype.setPlatform = function (t, e) {
  2212. null != this.platform && console.warn("Platform " + this.platformName + " has already been set. Overwriting the platform with " + e + "."), this.platformName = t, this.platform = e;
  2213. }, t.prototype.registerFlag = function (t, e, n) {
  2214. if (this.flagRegistry[t] = {
  2215. evaluationFn: e,
  2216. setHook: n
  2217. }, null != this.urlFlags[t]) {
  2218. var r = this.urlFlags[t];
  2219. console.warn("Setting feature override from URL " + t + ": " + r + "."), this.set(t, r);
  2220. }
  2221. }, t.prototype.get = function (t) {
  2222. return t in this.flags ? this.flags[t] : (this.flags[t] = this.evaluateFlag(t), this.flags[t]);
  2223. }, t.prototype.getNumber = function (t) {
  2224. return this.get(t);
  2225. }, t.prototype.getBool = function (t) {
  2226. return this.get(t);
  2227. }, t.prototype.getFlags = function () {
  2228. return this.flags;
  2229. }, Object.defineProperty(t.prototype, "features", {
  2230. get: function () {
  2231. return this.flags;
  2232. },
  2233. enumerable: !0,
  2234. configurable: !0
  2235. }), t.prototype.set = function (t, e) {
  2236. if (null == this.flagRegistry[t]) throw new Error("Cannot set flag " + t + " as it has not been registered.");
  2237. this.flags[t] = e, null != this.flagRegistry[t].setHook && this.flagRegistry[t].setHook(e);
  2238. }, t.prototype.evaluateFlag = function (t) {
  2239. if (null == this.flagRegistry[t]) throw new Error("Cannot evaluate flag '" + t + "': no evaluation function found.");
  2240. return this.flagRegistry[t].evaluationFn();
  2241. }, t.prototype.setFlags = function (t) {
  2242. this.flags = Object.assign({}, t);
  2243. }, t.prototype.reset = function () {
  2244. this.flags = {}, this.urlFlags = {}, this.populateURLFlags();
  2245. }, t.prototype.populateURLFlags = function () {
  2246. var t = this;
  2247. if (void 0 !== this.global && void 0 !== this.global.location && void 0 !== this.global.location.search) {
  2248. var e,
  2249. n,
  2250. r = (e = this.global.location.search, n = {}, e.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, function (t) {
  2251. for (var e = [], r = 1; r < arguments.length; r++) e[r - 1] = arguments[r];
  2252. return function (t, e, n) {
  2253. t[decodeURIComponent(e)] = decodeURIComponent(n || "");
  2254. }(n, e[0], e[1]), e.join("=");
  2255. }), n);
  2256. if ("tfjsflags" in r) r.tfjsflags.split(",").forEach(function (e) {
  2257. var n = e.split(":"),
  2258. r = n[0],
  2259. o = n[1];
  2260. t.urlFlags[r] = function (t, e) {
  2261. if ("true" === (e = e.toLowerCase()) || "false" === e) return "true" === e;
  2262. if ("" + +e === e) return +e;
  2263. throw new Error("Could not parse value flag value " + e + " for flag " + t + ".");
  2264. }(r, o);
  2265. });
  2266. }
  2267. }, t;
  2268. }();
  2269. exports.Environment = o;
  2270. function a() {
  2271. return i;
  2272. }
  2273. var i = null;
  2274. exports.ENV = i;
  2275. var u = new Map();
  2276. function s(t, e) {
  2277. var n = f(t, e);
  2278. return u.get(n);
  2279. }
  2280. function c(t) {
  2281. for (var e = u.entries(), n = []; ;) {
  2282. var r = e.next(),
  2283. o = r.done,
  2284. a = r.value;
  2285. if (o) break;
  2286. var i = a[0],
  2287. s = a[1];
  2288. i.split("_")[0] === t && n.push(s);
  2289. }
  2290. return n;
  2291. }
  2292. function l(t) {
  2293. var e = t.kernelName,
  2294. n = t.backendName,
  2295. r = f(e, n);
  2296. if (u.has(r)) throw new Error("The kernel '" + e + "' for backend '" + n + "' is already registered");
  2297. u.set(r, t);
  2298. }
  2299. function h(t, e) {
  2300. var n = f(t, e);
  2301. if (!u.has(n)) throw new Error("The kernel '" + t + "' for backend '" + e + "' is not registered");
  2302. u.delete(n);
  2303. }
  2304. function f(t, e) {
  2305. return e + "_" + t;
  2306. }
  2307. function p(t) {
  2308. for (var e = t.length, n = 0, r = 0; e > 0;) r = Math.random() * e | 0, n = t[--e], t[e] = t[r], t[r] = n;
  2309. }
  2310. function d(t, e, n) {
  2311. return Math.max(t, Math.min(e, n));
  2312. }
  2313. function v(t) {
  2314. return t % 2 == 0 ? t : t + 1;
  2315. }
  2316. function m(t) {
  2317. for (var e = 0, n = 0; n < t.length; n++) e += t[n];
  2318. return e;
  2319. }
  2320. function g(t, e) {
  2321. if (!t) throw new Error("string" == typeof e ? e : e());
  2322. }
  2323. function y(t, e, n) {
  2324. void 0 === n && (n = ""), g(C(t, e), function () {
  2325. return n + " Shapes " + t + " and " + e + " must match";
  2326. });
  2327. }
  2328. function x(t) {
  2329. g(null != t, function () {
  2330. return "The input to the tensor constructor must be a non-null value.";
  2331. });
  2332. }
  2333. function b(t, e, n) {
  2334. if (void 0 === e && (e = []), void 0 === n && (n = !1), null == e && (e = []), Array.isArray(t) || B(t) && !n) for (var r = 0; r < t.length; ++r) b(t[r], e, n); else e.push(t);
  2335. return e;
  2336. }
  2337. function w(t) {
  2338. if (0 === t.length) return 1;
  2339. for (var e = t[0], n = 1; n < t.length; n++) e *= t[n];
  2340. return e;
  2341. }
  2342. function C(t, e) {
  2343. if (t === e) return !0;
  2344. if (null == t || null == e) return !1;
  2345. if (t.length !== e.length) return !1;
  2346. for (var n = 0; n < t.length; n++) if (t[n] !== e[n]) return !1;
  2347. return !0;
  2348. }
  2349. function E(t) {
  2350. return t % 1 == 0;
  2351. }
  2352. function R(t) {
  2353. if (null != Math.tanh) return Math.tanh(t);
  2354. if (t === 1 / 0) return 1;
  2355. if (t === -1 / 0) return -1;
  2356. var e = Math.exp(2 * t);
  2357. return (e - 1) / (e + 1);
  2358. }
  2359. function I(t) {
  2360. var e = Math.ceil(Math.sqrt(t));
  2361. return [e, Math.ceil(t / e)];
  2362. }
  2363. function k(t, e) {
  2364. return e <= t.length ? t : t + " ".repeat(e - t.length);
  2365. }
  2366. function S(t, e, n) {
  2367. return void 0 === e && (e = function (t) {
  2368. return 0;
  2369. }), new Promise(function (r, o) {
  2370. var a = 0,
  2371. i = function () {
  2372. if (t()) r(); else {
  2373. var u = e(++a);
  2374. null != n && a >= n ? o() : setTimeout(i, u);
  2375. }
  2376. };
  2377. i();
  2378. });
  2379. }
  2380. function A(t, e) {
  2381. for (var n = 1, r = -1, o = 0; o < t.length; ++o) if (t[o] >= 0) n *= t[o]; else if (-1 === t[o]) {
  2382. if (-1 !== r) throw Error("Shapes can only have 1 implicit size. Found -1 at dim " + r + " and dim " + o);
  2383. r = o;
  2384. } else if (t[o] < 0) throw Error("Shapes can not be < 0. Found " + t[o] + " at dim " + o);
  2385. if (-1 === r) {
  2386. if (e > 0 && e !== n) throw Error("Size(" + e + ") must match the product of shape " + t);
  2387. return t;
  2388. }
  2389. if (0 === n) throw Error("Cannot infer the missing size in [" + t + "] when there are 0 elements");
  2390. if (e % n != 0) throw Error("The implicit shape can't be a fractional number. Got " + e + " / " + n);
  2391. var a = t.slice();
  2392. return a[r] = e / n, a;
  2393. }
  2394. function D(t, e) {
  2395. var n = e.length;
  2396. return g((t = null == t ? e.map(function (t, e) {
  2397. return e;
  2398. }) : [].concat(t)).every(function (t) {
  2399. return t >= -n && t < n;
  2400. }), function () {
  2401. return "All values in axis param must be in range [-" + n + ", " + n + ") but got axis " + t;
  2402. }), g(t.every(function (t) {
  2403. return E(t);
  2404. }), function () {
  2405. return "All values in axis param must be integers but got axis " + t;
  2406. }), t.map(function (t) {
  2407. return t < 0 ? n + t : t;
  2408. });
  2409. }
  2410. function T(t, e) {
  2411. for (var n = [], r = [], o = null != e && Array.isArray(e) && 0 === e.length, a = null == e || o ? null : D(e, t).sort(), i = 0, u = 0; u < t.length; ++u) {
  2412. if (null != a) {
  2413. if (a[i] === u && 1 !== t[u]) throw new Error("Can't squeeze axis " + u + " since its dim '" + t[u] + "' is not 1");
  2414. (null == a[i] || a[i] > u) && 1 === t[u] && (n.push(t[u]), r.push(u)), a[i] <= u && i++;
  2415. }
  2416. 1 !== t[u] && (n.push(t[u]), r.push(u));
  2417. }
  2418. return {
  2419. newShape: n,
  2420. keptDims: r
  2421. };
  2422. }
  2423. function N(t, e) {
  2424. var n = null;
  2425. if (null == t || "float32" === t) n = new Float32Array(e); else if ("int32" === t) n = new Int32Array(e); else {
  2426. if ("bool" !== t) throw new Error("Unknown data type " + t);
  2427. n = new Uint8Array(e);
  2428. }
  2429. return n;
  2430. }
  2431. function F(t, e) {
  2432. var n = null;
  2433. if (null == t || "float32" === t) n = new Float32Array(e); else if ("int32" === t) n = new Int32Array(e); else if ("bool" === t) n = new Uint8Array(e); else {
  2434. if ("string" !== t) throw new Error("Unknown data type " + t);
  2435. n = new Array(e);
  2436. }
  2437. return n;
  2438. }
  2439. function O(t, e) {
  2440. for (var n = 0; n < t.length; n++) {
  2441. var r = t[n];
  2442. if (isNaN(r) || !isFinite(r)) throw Error("A tensor of type " + e + " being uploaded contains " + r + ".");
  2443. }
  2444. }
  2445. function _(t) {
  2446. return "bool" === t || "complex64" === t || "float32" === t || "int32" === t || "string" === t;
  2447. }
  2448. function M(t, e) {
  2449. return "complex64" !== e && ("float32" !== e || "complex64" === t) && ("int32" !== e || "float32" === t || "complex64" === t) && ("bool" !== e || "bool" !== t);
  2450. }
  2451. function B(t) {
  2452. return t instanceof Float32Array || t instanceof Int32Array || t instanceof Uint8Array;
  2453. }
  2454. function P(t) {
  2455. if ("float32" === t || "int32" === t) return 4;
  2456. if ("complex64" === t) return 8;
  2457. if ("bool" === t) return 1;
  2458. throw new Error("Unknown dtype " + t);
  2459. }
  2460. function L(t) {
  2461. if (null == t) return 0;
  2462. var e = 0;
  2463. return t.forEach(function (t) {
  2464. return e += t.length;
  2465. }), e;
  2466. }
  2467. function W(t) {
  2468. return "string" == typeof t || t instanceof String;
  2469. }
  2470. function U(t) {
  2471. return "boolean" == typeof t;
  2472. }
  2473. function V(t) {
  2474. return "number" == typeof t;
  2475. }
  2476. function z(t) {
  2477. return Array.isArray(t) ? z(t[0]) : t instanceof Float32Array ? "float32" : t instanceof Int32Array || t instanceof Uint8Array ? "int32" : V(t) ? "float32" : W(t) ? "string" : U(t) ? "bool" : "float32";
  2478. }
  2479. function G(t) {
  2480. return !!(t && t.constructor && t.call && t.apply);
  2481. }
  2482. function H(t, e) {
  2483. for (var n = e; n < t; ++n) if (t % n == 0) return n;
  2484. return t;
  2485. }
  2486. function q(t) {
  2487. var e = t.length;
  2488. if (e < 2) return [];
  2489. var n = new Array(e - 1);
  2490. n[e - 2] = t[e - 1];
  2491. for (var r = e - 3; r >= 0; --r) n[r] = n[r + 1] * t[r + 1];
  2492. return n;
  2493. }
  2494. function K(t, e, n) {
  2495. if ("string" === e) throw new Error("Cannot convert a string[] to a TypedArray");
  2496. if (Array.isArray(t) && (t = b(t)), n && O(t, e), function (t, e) {
  2497. return t instanceof Float32Array && "float32" === e || t instanceof Int32Array && "int32" === e || t instanceof Uint8Array && "bool" === e;
  2498. }(t, e)) return t;
  2499. if (null == e || "float32" === e || "complex64" === e) return new Float32Array(t);
  2500. if ("int32" === e) return new Int32Array(t);
  2501. if ("bool" === e) {
  2502. for (var r = new Uint8Array(t.length), o = 0; o < r.length; ++o) 0 !== Math.round(t[o]) && (r[o] = 1);
  2503. return r;
  2504. }
  2505. throw new Error("Unknown data type " + e);
  2506. }
  2507. function j(t, e) {
  2508. if (0 === t.length) return e[0];
  2509. var n = t.reduce(function (t, e) {
  2510. return t * e;
  2511. });
  2512. if (0 === n) return [];
  2513. if (n !== e.length) throw new Error("[" + t + "] does not match the input size.");
  2514. return function t(e, n, r) {
  2515. var o = new Array();
  2516. if (1 === n.length) for (var a = n[0], i = 0; i < a; i++) o[i] = r[e + i]; else {
  2517. a = n[0];
  2518. var u = n.slice(1),
  2519. s = u.reduce(function (t, e) {
  2520. return t * e;
  2521. });
  2522. for (i = 0; i < a; i++) o[i] = t(e + i * s, u, r);
  2523. }
  2524. return o;
  2525. }(0, t, e);
  2526. }
  2527. function X(t, e) {
  2528. for (var n = $(t, e), r = 0; r < n.length; r++) n[r] = 1;
  2529. return n;
  2530. }
  2531. function $(t, e) {
  2532. if (null == e || "float32" === e || "complex64" === e) return new Float32Array(t);
  2533. if ("int32" === e) return new Int32Array(t);
  2534. if ("bool" === e) return new Uint8Array(t);
  2535. throw new Error("Unknown data type " + e);
  2536. }
  2537. function Y() {
  2538. return a().platform.now();
  2539. }
  2540. function Q(t) {
  2541. t.forEach(function (e) {
  2542. g(Number.isInteger(e) && e >= 0, function () {
  2543. return "Tensor must have a shape comprised of positive integers but got shape [" + t + "].";
  2544. });
  2545. });
  2546. }
  2547. function J(t, e) {
  2548. return void 0 === e && (e = "utf-8"), e = e || "utf-8", a().platform.encode(t, e);
  2549. }
  2550. function Z(t, e) {
  2551. return void 0 === e && (e = "utf-8"), e = e || "utf-8", a().platform.decode(t, e);
  2552. }
  2553. var tt = Object.freeze({
  2554. shuffle: p,
  2555. clamp: d,
  2556. nearestLargerEven: v,
  2557. sum: m,
  2558. randUniform: function (t, e) {
  2559. var n = Math.random();
  2560. return e * n + (1 - n) * t;
  2561. },
  2562. distSquared: function (t, e) {
  2563. for (var n = 0, r = 0; r < t.length; r++) {
  2564. var o = Number(t[r]) - Number(e[r]);
  2565. n += o * o;
  2566. }
  2567. return n;
  2568. },
  2569. assert: g,
  2570. assertShapesMatch: y,
  2571. assertNonNull: x,
  2572. flatten: b,
  2573. sizeFromShape: w,
  2574. isScalarShape: function (t) {
  2575. return 0 === t.length;
  2576. },
  2577. arraysEqual: C,
  2578. isInt: E,
  2579. tanh: R,
  2580. sizeToSquarishShape: I,
  2581. createShuffledIndices: function (t) {
  2582. for (var e = new Uint32Array(t), n = 0; n < t; ++n) e[n] = n;
  2583. return p(e), e;
  2584. },
  2585. rightPad: k,
  2586. repeatedTry: S,
  2587. inferFromImplicitShape: A,
  2588. parseAxisParam: D,
  2589. squeezeShape: T,
  2590. getTypedArrayFromDType: N,
  2591. getArrayFromDType: F,
  2592. checkConversionForErrors: O,
  2593. isValidDtype: _,
  2594. hasEncodingLoss: M,
  2595. isTypedArray: B,
  2596. bytesPerElement: P,
  2597. bytesFromStringArray: L,
  2598. isString: W,
  2599. isBoolean: U,
  2600. isNumber: V,
  2601. inferDtype: z,
  2602. isFunction: G,
  2603. nearestDivisor: H,
  2604. computeStrides: q,
  2605. toTypedArray: K,
  2606. toNestedArray: j,
  2607. makeOnesTypedArray: X,
  2608. makeZerosTypedArray: $,
  2609. now: Y,
  2610. assertNonNegativeIntegerDimensions: Q,
  2611. fetch: function (t, e) {
  2612. return a().platform.fetch(t, e);
  2613. },
  2614. encodeString: J,
  2615. decodeString: Z
  2616. }),
  2617. et = function () {
  2618. function t(t, e) {
  2619. this.backendTimer = t, this.logger = e, null == e && (this.logger = new nt());
  2620. }
  2621. return t.prototype.profileKernel = function (t, e, n) {
  2622. var r,
  2623. o = this,
  2624. a = this.backendTimer.time(function () {
  2625. r = n();
  2626. });
  2627. return r.forEach(function (n) {
  2628. n.data().then(function (r) {
  2629. !function (t, e, n) {
  2630. if ("float32" !== e) return !1;
  2631. for (var r = 0; r < t.length; r++) {
  2632. var o = t[r];
  2633. if (isNaN(o) || !isFinite(o)) return console.warn("Found " + o + " in the result of '" + n + "'"), !0;
  2634. }
  2635. }(r, n.dtype, t), a.then(function (a) {
  2636. var i = "";
  2637. null != a.getExtraProfileInfo && (i = a.getExtraProfileInfo()), o.logger.logKernelProfile(t, n, r, a.kernelMs, e, i);
  2638. });
  2639. });
  2640. }), r;
  2641. }, t;
  2642. }();
  2643. exports.util = tt;
  2644. var nt = function () {
  2645. function t() { }
  2646. return t.prototype.logKernelProfile = function (t, e, n, r, o, a) {
  2647. var i = k(r + "ms", 9),
  2648. u = k(t, 25),
  2649. s = e.rank,
  2650. c = e.size,
  2651. l = k(e.shape.toString(), 14),
  2652. h = "";
  2653. for (var f in o) {
  2654. var p = o[f].shape,
  2655. d = p.length;
  2656. h += f + ": " + d + "D " + (d > 0 ? p : "") + " ";
  2657. }
  2658. console.log("%c" + u + "\t%c" + i + "\t%c" + s + "D " + l + "\t%c" + c + "\t%c" + h + "\t%c" + a, "font-weight:bold", "color:red", "color:blue", "color: orange", "color: green", "color: steelblue");
  2659. }, t;
  2660. }();
  2661. var rt = 20,
  2662. ot = 3,
  2663. at = 7;
  2664. function it(t, e, n, r) {
  2665. var o = q(e),
  2666. a = function (t, e, n, r) {
  2667. var o = w(e),
  2668. a = r[r.length - 1],
  2669. i = new Array(a).fill(0),
  2670. u = e.length,
  2671. s = "complex64" === n ? ct(t) : t;
  2672. if (u > 1) for (var c = 0; c < o / a; c++) for (var l = c * a, h = 0; h < a; h++) i[h] = Math.max(i[h], ut(s[l + h], 0, n).length);
  2673. return i;
  2674. }(t, e, n, o),
  2675. i = e.length,
  2676. u = function t(e, n, r, o, a, i) {
  2677. void 0 === i && (i = !0);
  2678. var u = "complex64" === r ? 2 : 1;
  2679. var s = n[0];
  2680. var c = n.length;
  2681. if (0 === c) {
  2682. if ("complex64" === r) {
  2683. var l = ct(e);
  2684. return [ut(l[0], 0, r)];
  2685. }
  2686. return "bool" === r ? [st(e[0])] : [e[0].toString()];
  2687. }
  2688. if (1 === c) {
  2689. if (s > rt) {
  2690. var h = ot * u,
  2691. f = Array.from(e.slice(0, h)),
  2692. p = Array.from(e.slice(s - ot * u, s));
  2693. return "complex64" === r && (f = ct(f), p = ct(p)), ["[" + f.map(function (t, e) {
  2694. return ut(t, a[e], r);
  2695. }).join(", ") + ", ..., " + p.map(function (t, e) {
  2696. return ut(t, a[s - ot + e], r);
  2697. }).join(", ") + "]"];
  2698. }
  2699. var d = "complex64" === r ? ct(e) : Array.from(e);
  2700. return ["[" + d.map(function (t, e) {
  2701. return ut(t, a[e], r);
  2702. }).join(", ") + "]"];
  2703. }
  2704. var v = n.slice(1);
  2705. var m = o.slice(1);
  2706. var g = o[0] * u;
  2707. var y = [];
  2708. if (s > rt) {
  2709. for (var x = 0; x < ot; x++) {
  2710. var b = x * g,
  2711. w = b + g;
  2712. y.push.apply(y, t(e.slice(b, w), v, r, m, a, !1));
  2713. }
  2714. y.push("...");
  2715. for (var x = s - ot; x < s; x++) {
  2716. var b = x * g,
  2717. w = b + g;
  2718. y.push.apply(y, t(e.slice(b, w), v, r, m, a, x === s - 1));
  2719. }
  2720. } else for (var x = 0; x < s; x++) {
  2721. var b = x * g,
  2722. w = b + g;
  2723. y.push.apply(y, t(e.slice(b, w), v, r, m, a, x === s - 1));
  2724. }
  2725. var C = 2 === c ? "," : "";
  2726. y[0] = "[" + y[0] + C;
  2727. for (var x = 1; x < y.length - 1; x++) y[x] = " " + y[x] + C;
  2728. var E = ",\n";
  2729. for (var x = 2; x < c; x++) E += "\n";
  2730. y[y.length - 1] = " " + y[y.length - 1] + "]" + (i ? "" : E);
  2731. return y;
  2732. }(t, e, n, o, a),
  2733. s = ["Tensor"];
  2734. return r && (s.push(" dtype: " + n), s.push(" rank: " + i), s.push(" shape: [" + e + "]"), s.push(" values:")), s.push(u.map(function (t) {
  2735. return " " + t;
  2736. }).join("\n")), s.join("\n");
  2737. }
  2738. function ut(t, e, n) {
  2739. return k(Array.isArray(t) ? parseFloat(t[0].toFixed(at)) + " + " + parseFloat(t[1].toFixed(at)) + "j" : W(t) ? "'" + t + "'" : "bool" === n ? st(t) : parseFloat(t.toFixed(at)).toString(), e);
  2740. }
  2741. function st(t) {
  2742. return 0 === t ? "false" : "true";
  2743. }
  2744. function ct(t) {
  2745. for (var e = [], n = 0; n < t.length; n += 2) e.push([t[n], t[n + 1]]);
  2746. return e;
  2747. }
  2748. var lt = function () {
  2749. function t(t, e, n) {
  2750. var r = this;
  2751. if (this.dtype = e, this.shape = t.slice(), this.size = w(t), null != n) {
  2752. var o = n.length;
  2753. g(o === this.size, function () {
  2754. return "Length of values '" + o + "' does not match the size inferred by the shape '" + r.size + "'.";
  2755. });
  2756. }
  2757. if ("complex64" === e) throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");
  2758. this.values = n || F(e, this.size), this.strides = q(t);
  2759. }
  2760. return t.prototype.set = function (t) {
  2761. for (var e = this, n = [], r = 1; r < arguments.length; r++) n[r - 1] = arguments[r];
  2762. 0 === n.length && (n = [0]), g(n.length === this.rank, function () {
  2763. return "The number of provided coordinates (" + n.length + ") must match the rank (" + e.rank + ")";
  2764. });
  2765. var o = this.locToIndex(n);
  2766. this.values[o] = t;
  2767. }, t.prototype.get = function () {
  2768. for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];
  2769. 0 === t.length && (t = [0]);
  2770. for (var n = 0, r = 0, o = t; r < o.length; r++) {
  2771. var a = o[r];
  2772. if (a < 0 || a >= this.shape[n]) {
  2773. var i = "Requested out of range element at " + t + ". Buffer shape=" + this.shape;
  2774. throw new Error(i);
  2775. }
  2776. n++;
  2777. }
  2778. for (var u = t[t.length - 1], s = 0; s < t.length - 1; ++s) u += this.strides[s] * t[s];
  2779. return this.values[u];
  2780. }, t.prototype.locToIndex = function (t) {
  2781. if (0 === this.rank) return 0;
  2782. if (1 === this.rank) return t[0];
  2783. for (var e = t[t.length - 1], n = 0; n < t.length - 1; ++n) e += this.strides[n] * t[n];
  2784. return e;
  2785. }, t.prototype.indexToLoc = function (t) {
  2786. if (0 === this.rank) return [];
  2787. if (1 === this.rank) return [t];
  2788. for (var e = new Array(this.shape.length), n = 0; n < e.length - 1; ++n) e[n] = Math.floor(t / this.strides[n]), t -= e[n] * this.strides[n];
  2789. return e[e.length - 1] = t, e;
  2790. }, Object.defineProperty(t.prototype, "rank", {
  2791. get: function () {
  2792. return this.shape.length;
  2793. },
  2794. enumerable: !0,
  2795. configurable: !0
  2796. }), t.prototype.toTensor = function () {
  2797. return ht().makeTensor(this.values, this.shape, this.dtype);
  2798. }, t;
  2799. }(),
  2800. ht = null,
  2801. ft = null,
  2802. pt = null;
  2803. exports.TensorBuffer = lt;
  2804. var dt = function () {
  2805. function t(t, e, n, r) {
  2806. this.kept = !1, this.isDisposedInternal = !1, this.shape = t.slice(), this.dtype = e || "float32", this.size = w(t), this.strides = q(t), this.dataId = n, this.id = r, this.rankType = this.rank < 5 ? this.rank.toString() : "higher";
  2807. }
  2808. return t.prototype.flatten = function () {
  2809. return this.throwIfDisposed(), this.as1D();
  2810. }, t.prototype.asScalar = function () {
  2811. return this.throwIfDisposed(), g(1 === this.size, function () {
  2812. return "The array must have only 1 element.";
  2813. }), this.reshape([]);
  2814. }, t.prototype.as1D = function () {
  2815. return this.throwIfDisposed(), this.reshape([this.size]);
  2816. }, t.prototype.as2D = function (t, e) {
  2817. return this.throwIfDisposed(), this.reshape([t, e]);
  2818. }, t.prototype.as3D = function (t, e, n) {
  2819. return this.throwIfDisposed(), this.reshape([t, e, n]);
  2820. }, t.prototype.as4D = function (t, e, n, r) {
  2821. return this.throwIfDisposed(), this.reshape([t, e, n, r]);
  2822. }, t.prototype.as5D = function (t, e, n, r, o) {
  2823. return this.throwIfDisposed(), this.reshape([t, e, n, r, o]);
  2824. }, t.prototype.asType = function (t) {
  2825. return this.throwIfDisposed(), ft.cast(this, t);
  2826. }, Object.defineProperty(t.prototype, "rank", {
  2827. get: function () {
  2828. return this.shape.length;
  2829. },
  2830. enumerable: !0,
  2831. configurable: !0
  2832. }), t.prototype.buffer = function () {
  2833. return n(this, void 0, void 0, function () {
  2834. var t;
  2835. return r(this, function (e) {
  2836. switch (e.label) {
  2837. case 0:
  2838. return [4, this.data()];
  2839. case 1:
  2840. return t = e.sent(), [2, ft.buffer(this.shape, this.dtype, t)];
  2841. }
  2842. });
  2843. });
  2844. }, t.prototype.bufferSync = function () {
  2845. return ft.buffer(this.shape, this.dtype, this.dataSync());
  2846. }, t.prototype.array = function () {
  2847. return n(this, void 0, void 0, function () {
  2848. var t;
  2849. return r(this, function (e) {
  2850. switch (e.label) {
  2851. case 0:
  2852. return [4, this.data()];
  2853. case 1:
  2854. return t = e.sent(), [2, j(this.shape, t)];
  2855. }
  2856. });
  2857. });
  2858. }, t.prototype.arraySync = function () {
  2859. return j(this.shape, this.dataSync());
  2860. }, t.prototype.data = function () {
  2861. return n(this, void 0, void 0, function () {
  2862. var t, e;
  2863. return r(this, function (n) {
  2864. switch (n.label) {
  2865. case 0:
  2866. return this.throwIfDisposed(), t = ht().read(this.dataId), "string" !== this.dtype ? [3, 2] : [4, t];
  2867. case 1:
  2868. e = n.sent();
  2869. try {
  2870. return [2, e.map(function (t) {
  2871. return Z(t);
  2872. })];
  2873. } catch (t) {
  2874. throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
  2875. }
  2876. n.label = 2;
  2877. case 2:
  2878. return [2, t];
  2879. }
  2880. });
  2881. });
  2882. }, t.prototype.dataSync = function () {
  2883. this.throwIfDisposed();
  2884. var t = ht().readSync(this.dataId);
  2885. if ("string" === this.dtype) try {
  2886. return t.map(function (t) {
  2887. return Z(t);
  2888. });
  2889. } catch (t) {
  2890. throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
  2891. }
  2892. return t;
  2893. }, t.prototype.bytes = function () {
  2894. return n(this, void 0, void 0, function () {
  2895. var t;
  2896. return r(this, function (e) {
  2897. switch (e.label) {
  2898. case 0:
  2899. return this.throwIfDisposed(), [4, ht().read(this.dataId)];
  2900. case 1:
  2901. return t = e.sent(), "string" === this.dtype ? [2, t] : [2, new Uint8Array(t.buffer)];
  2902. }
  2903. });
  2904. });
  2905. }, t.prototype.dispose = function () {
  2906. this.isDisposed || (ht().disposeTensor(this), this.isDisposedInternal = !0);
  2907. }, Object.defineProperty(t.prototype, "isDisposed", {
  2908. get: function () {
  2909. return this.isDisposedInternal;
  2910. },
  2911. enumerable: !0,
  2912. configurable: !0
  2913. }), t.prototype.throwIfDisposed = function () {
  2914. if (this.isDisposed) throw new Error("Tensor is disposed.");
  2915. }, t.prototype.toFloat = function () {
  2916. return this.asType("float32");
  2917. }, t.prototype.toInt = function () {
  2918. return this.asType("int32");
  2919. }, t.prototype.toBool = function () {
  2920. return this.asType("bool");
  2921. }, t.prototype.print = function (t) {
  2922. return void 0 === t && (t = !1), ft.print(this, t);
  2923. }, t.prototype.reshape = function (t) {
  2924. return this.throwIfDisposed(), ft.reshape(this, t);
  2925. }, t.prototype.reshapeAs = function (t) {
  2926. return this.throwIfDisposed(), this.reshape(t.shape);
  2927. }, t.prototype.expandDims = function (t) {
  2928. return void 0 === t && (t = 0), ft.expandDims(this, t);
  2929. }, t.prototype.cumsum = function (t, e, n) {
  2930. return void 0 === t && (t = 0), void 0 === e && (e = !1), void 0 === n && (n = !1), ft.cumsum(this, t, e, n);
  2931. }, t.prototype.squeeze = function (t) {
  2932. return this.throwIfDisposed(), ft.squeeze(this, t);
  2933. }, t.prototype.clone = function () {
  2934. return this.throwIfDisposed(), ft.clone(this);
  2935. }, t.prototype.oneHot = function (t, e, n) {
  2936. return this.throwIfDisposed(), ft.oneHot(this, t, e, n);
  2937. }, t.prototype.toString = function (t) {
  2938. return void 0 === t && (t = !1), it(this.dataSync(), this.shape, this.dtype, t);
  2939. }, t.prototype.tile = function (t) {
  2940. return this.throwIfDisposed(), ft.tile(this, t);
  2941. }, t.prototype.gather = function (t, e) {
  2942. return void 0 === e && (e = 0), this.throwIfDisposed(), ft.gather(this, t, e);
  2943. }, t.prototype.matMul = function (t, e, n) {
  2944. return void 0 === e && (e = !1), void 0 === n && (n = !1), this.throwIfDisposed(), ft.matMul(this, t, e, n);
  2945. }, t.prototype.dot = function (t) {
  2946. return this.throwIfDisposed(), ft.dot(this, t);
  2947. }, t.prototype.norm = function (t, e, n) {
  2948. return void 0 === t && (t = "euclidean"), void 0 === e && (e = null), void 0 === n && (n = !1), this.throwIfDisposed(), ft.norm(this, t, e, n);
  2949. }, t.prototype.slice = function (t, e) {
  2950. return this.throwIfDisposed(), ft.slice(this, t, e);
  2951. }, t.prototype.reverse = function (t) {
  2952. return this.throwIfDisposed(), ft.reverse(this, t);
  2953. }, t.prototype.concat = function (e, n) {
  2954. return void 0 === n && (n = 0), this.throwIfDisposed(), e instanceof t && (e = [e]), ft.concat([this].concat(e), n);
  2955. }, t.prototype.split = function (t, e) {
  2956. return void 0 === e && (e = 0), this.throwIfDisposed(), ft.split(this, t, e);
  2957. }, t.prototype.stack = function (t, e) {
  2958. return void 0 === e && (e = 0), ft.stack([this, t], e);
  2959. }, t.prototype.unstack = function (t) {
  2960. return void 0 === t && (t = 0), ft.unstack(this, t);
  2961. }, t.prototype.pad = function (t, e) {
  2962. return void 0 === e && (e = 0), ft.pad(this, t, e);
  2963. }, t.prototype.batchNormalization = function (t, e, n, r, o) {
  2964. return void 0 === n && (n = .001), pt("tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon"), this.batchNorm(t, e, o, r, n);
  2965. }, t.prototype.batchNorm = function (t, e, n, r, o) {
  2966. return void 0 === o && (o = .001), this.throwIfDisposed(), ft.batchNorm(this, t, e, n, r, o);
  2967. }, t.prototype.all = function (t, e) {
  2968. return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.all(this, t, e);
  2969. }, t.prototype.any = function (t, e) {
  2970. return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.any(this, t, e);
  2971. }, t.prototype.logSumExp = function (t, e) {
  2972. return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.logSumExp(this, t, e);
  2973. }, t.prototype.sum = function (t, e) {
  2974. return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.sum(this, t, e);
  2975. }, t.prototype.prod = function (t, e) {
  2976. return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.prod(this, t, e);
  2977. }, t.prototype.mean = function (t, e) {
  2978. return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.mean(this, t, e);
  2979. }, t.prototype.min = function (t, e) {
  2980. return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.min(this, t, e);
  2981. }, t.prototype.max = function (t, e) {
  2982. return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.max(this, t, e);
  2983. }, t.prototype.argMin = function (t) {
  2984. return void 0 === t && (t = null), this.throwIfDisposed(), ft.argMin(this, t);
  2985. }, t.prototype.argMax = function (t) {
  2986. return void 0 === t && (t = null), this.throwIfDisposed(), ft.argMax(this, t);
  2987. }, t.prototype.cast = function (t) {
  2988. return this.throwIfDisposed(), ft.cast(this, t);
  2989. }, t.prototype.add = function (t) {
  2990. return this.throwIfDisposed(), ft.add(this, t);
  2991. }, t.prototype.addStrict = function (t) {
  2992. return this.throwIfDisposed(), ft.addStrict(this, t);
  2993. }, t.prototype.atan2 = function (t) {
  2994. return this.throwIfDisposed(), ft.atan2(this, t);
  2995. }, t.prototype.sub = function (t) {
  2996. return this.throwIfDisposed(), ft.sub(this, t);
  2997. }, t.prototype.subStrict = function (t) {
  2998. return this.throwIfDisposed(), ft.subStrict(this, t);
  2999. }, t.prototype.pow = function (t) {
  3000. return this.throwIfDisposed(), ft.pow(this, t);
  3001. }, t.prototype.powStrict = function (t) {
  3002. return this.throwIfDisposed(), ft.powStrict(this, t);
  3003. }, t.prototype.mul = function (t) {
  3004. return this.throwIfDisposed(), ft.mul(this, t);
  3005. }, t.prototype.mulStrict = function (t) {
  3006. return this.throwIfDisposed(), ft.mulStrict(this, t);
  3007. }, t.prototype.div = function (t) {
  3008. return this.throwIfDisposed(), ft.div(this, t);
  3009. }, t.prototype.floorDiv = function (t) {
  3010. return this.throwIfDisposed(), ft.floorDiv(this, t);
  3011. }, t.prototype.divStrict = function (t) {
  3012. return this.throwIfDisposed(), ft.divStrict(this, t);
  3013. }, t.prototype.minimum = function (t) {
  3014. return this.throwIfDisposed(), ft.minimum(this, t);
  3015. }, t.prototype.minimumStrict = function (t) {
  3016. return this.throwIfDisposed(), ft.minimumStrict(this, t);
  3017. }, t.prototype.maximum = function (t) {
  3018. return this.throwIfDisposed(), ft.maximum(this, t);
  3019. }, t.prototype.maximumStrict = function (t) {
  3020. return this.throwIfDisposed(), ft.maximumStrict(this, t);
  3021. }, t.prototype.mod = function (t) {
  3022. return this.throwIfDisposed(), ft.mod(this, t);
  3023. }, t.prototype.modStrict = function (t) {
  3024. return this.throwIfDisposed(), ft.modStrict(this, t);
  3025. }, t.prototype.squaredDifference = function (t) {
  3026. return this.throwIfDisposed(), ft.squaredDifference(this, t);
  3027. }, t.prototype.squaredDifferenceStrict = function (t) {
  3028. return this.throwIfDisposed(), ft.squaredDifferenceStrict(this, t);
  3029. }, t.prototype.transpose = function (t) {
  3030. return this.throwIfDisposed(), ft.transpose(this, t);
  3031. }, t.prototype.notEqual = function (t) {
  3032. return this.throwIfDisposed(), ft.notEqual(this, t);
  3033. }, t.prototype.notEqualStrict = function (t) {
  3034. return this.throwIfDisposed(), ft.notEqualStrict(this, t);
  3035. }, t.prototype.less = function (t) {
  3036. return this.throwIfDisposed(), ft.less(this, t);
  3037. }, t.prototype.lessStrict = function (t) {
  3038. return this.throwIfDisposed(), ft.lessStrict(this, t);
  3039. }, t.prototype.equal = function (t) {
  3040. return this.throwIfDisposed(), ft.equal(this, t);
  3041. }, t.prototype.equalStrict = function (t) {
  3042. return this.throwIfDisposed(), ft.equalStrict(this, t);
  3043. }, t.prototype.lessEqual = function (t) {
  3044. return this.throwIfDisposed(), ft.lessEqual(this, t);
  3045. }, t.prototype.lessEqualStrict = function (t) {
  3046. return this.throwIfDisposed(), ft.lessEqualStrict(this, t);
  3047. }, t.prototype.greater = function (t) {
  3048. return this.throwIfDisposed(), ft.greater(this, t);
  3049. }, t.prototype.greaterStrict = function (t) {
  3050. return this.throwIfDisposed(), ft.greaterStrict(this, t);
  3051. }, t.prototype.greaterEqual = function (t) {
  3052. return this.throwIfDisposed(), ft.greaterEqual(this, t);
  3053. }, t.prototype.greaterEqualStrict = function (t) {
  3054. return this.throwIfDisposed(), ft.greaterEqualStrict(this, t);
  3055. }, t.prototype.logicalAnd = function (t) {
  3056. return this.throwIfDisposed(), ft.logicalAnd(this, t);
  3057. }, t.prototype.logicalOr = function (t) {
  3058. return this.throwIfDisposed(), ft.logicalOr(this, t);
  3059. }, t.prototype.logicalNot = function () {
  3060. return this.throwIfDisposed(), ft.logicalNot(this);
  3061. }, t.prototype.logicalXor = function (t) {
  3062. return this.throwIfDisposed(), ft.logicalXor(this, t);
  3063. }, t.prototype.where = function (t, e) {
  3064. return this.throwIfDisposed(), ft.where(t, this, e);
  3065. }, t.prototype.neg = function () {
  3066. return this.throwIfDisposed(), ft.neg(this);
  3067. }, t.prototype.ceil = function () {
  3068. return this.throwIfDisposed(), ft.ceil(this);
  3069. }, t.prototype.floor = function () {
  3070. return this.throwIfDisposed(), ft.floor(this);
  3071. }, t.prototype.sign = function () {
  3072. return this.throwIfDisposed(), ft.sign(this);
  3073. }, t.prototype.isNaN = function () {
  3074. return this.throwIfDisposed(), ft.isNaN(this);
  3075. }, t.prototype.isInf = function () {
  3076. return this.throwIfDisposed(), ft.isInf(this);
  3077. }, t.prototype.isFinite = function () {
  3078. return this.throwIfDisposed(), ft.isFinite(this);
  3079. }, t.prototype.exp = function () {
  3080. return this.throwIfDisposed(), ft.exp(this);
  3081. }, t.prototype.expm1 = function () {
  3082. return this.throwIfDisposed(), ft.expm1(this);
  3083. }, t.prototype.log = function () {
  3084. return this.throwIfDisposed(), ft.log(this);
  3085. }, t.prototype.log1p = function () {
  3086. return this.throwIfDisposed(), ft.log1p(this);
  3087. }, t.prototype.sqrt = function () {
  3088. return this.throwIfDisposed(), ft.sqrt(this);
  3089. }, t.prototype.rsqrt = function () {
  3090. return this.throwIfDisposed(), ft.rsqrt(this);
  3091. }, t.prototype.square = function () {
  3092. return this.throwIfDisposed(), ft.square(this);
  3093. }, t.prototype.reciprocal = function () {
  3094. return this.throwIfDisposed(), ft.reciprocal(this);
  3095. }, t.prototype.abs = function () {
  3096. return this.throwIfDisposed(), ft.abs(this);
  3097. }, t.prototype.clipByValue = function (t, e) {
  3098. return this.throwIfDisposed(), ft.clipByValue(this, t, e);
  3099. }, t.prototype.relu = function () {
  3100. return this.throwIfDisposed(), ft.relu(this);
  3101. }, t.prototype.relu6 = function () {
  3102. return this.throwIfDisposed(), ft.relu6(this);
  3103. }, t.prototype.elu = function () {
  3104. return this.throwIfDisposed(), ft.elu(this);
  3105. }, t.prototype.selu = function () {
  3106. return this.throwIfDisposed(), ft.selu(this);
  3107. }, t.prototype.leakyRelu = function (t) {
  3108. return void 0 === t && (t = .2), this.throwIfDisposed(), ft.leakyRelu(this, t);
  3109. }, t.prototype.prelu = function (t) {
  3110. return this.throwIfDisposed(), ft.prelu(this, t);
  3111. }, t.prototype.sigmoid = function () {
  3112. return this.throwIfDisposed(), ft.sigmoid(this);
  3113. }, t.prototype.logSigmoid = function () {
  3114. return this.throwIfDisposed(), ft.logSigmoid(this);
  3115. }, t.prototype.softplus = function () {
  3116. return this.throwIfDisposed(), ft.softplus(this);
  3117. }, t.prototype.zerosLike = function () {
  3118. return this.throwIfDisposed(), ft.zerosLike(this);
  3119. }, t.prototype.onesLike = function () {
  3120. return this.throwIfDisposed(), ft.onesLike(this);
  3121. }, t.prototype.sin = function () {
  3122. return this.throwIfDisposed(), ft.sin(this);
  3123. }, t.prototype.cos = function () {
  3124. return this.throwIfDisposed(), ft.cos(this);
  3125. }, t.prototype.tan = function () {
  3126. return this.throwIfDisposed(), ft.tan(this);
  3127. }, t.prototype.asin = function () {
  3128. return this.throwIfDisposed(), ft.asin(this);
  3129. }, t.prototype.acos = function () {
  3130. return this.throwIfDisposed(), ft.acos(this);
  3131. }, t.prototype.atan = function () {
  3132. return this.throwIfDisposed(), ft.atan(this);
  3133. }, t.prototype.sinh = function () {
  3134. return this.throwIfDisposed(), ft.sinh(this);
  3135. }, t.prototype.cosh = function () {
  3136. return this.throwIfDisposed(), ft.cosh(this);
  3137. }, t.prototype.tanh = function () {
  3138. return this.throwIfDisposed(), ft.tanh(this);
  3139. }, t.prototype.asinh = function () {
  3140. return this.throwIfDisposed(), ft.asinh(this);
  3141. }, t.prototype.acosh = function () {
  3142. return this.throwIfDisposed(), ft.acosh(this);
  3143. }, t.prototype.atanh = function () {
  3144. return this.throwIfDisposed(), ft.atanh(this);
  3145. }, t.prototype.erf = function () {
  3146. return this.throwIfDisposed(), ft.erf(this);
  3147. }, t.prototype.round = function () {
  3148. return this.throwIfDisposed(), ft.round(this);
  3149. }, t.prototype.step = function (t) {
  3150. return void 0 === t && (t = 0), this.throwIfDisposed(), ft.step(this, t);
  3151. }, t.prototype.softmax = function (t) {
  3152. return void 0 === t && (t = -1), this.throwIfDisposed(), ft.softmax(this, t);
  3153. }, t.prototype.logSoftmax = function (t) {
  3154. return void 0 === t && (t = -1), this.throwIfDisposed(), ft.logSoftmax(this, t);
  3155. }, t.prototype.resizeBilinear = function (t, e) {
  3156. return void 0 === e && (e = !1), this.throwIfDisposed(), ft.image.resizeBilinear(this, t, e);
  3157. }, t.prototype.resizeNearestNeighbor = function (t, e) {
  3158. return void 0 === e && (e = !1), this.throwIfDisposed(), ft.image.resizeNearestNeighbor(this, t, e);
  3159. }, t.prototype.conv1d = function (t, e, n, r, o, a) {
  3160. return void 0 === r && (r = "NWC"), void 0 === o && (o = 1), this.throwIfDisposed(), ft.conv1d(this, t, e, n, r, o, a);
  3161. }, t.prototype.conv2d = function (t, e, n, r, o, a) {
  3162. return void 0 === r && (r = "NHWC"), void 0 === o && (o = [1, 1]), this.throwIfDisposed(), ft.conv2d(this, t, e, n, r, o, a);
  3163. }, t.prototype.conv2dTranspose = function (t, e, n, r, o) {
  3164. return this.throwIfDisposed(), ft.conv2dTranspose(this, t, e, n, r, o);
  3165. }, t.prototype.depthwiseConv2D = function (t, e, n, r, o, a) {
  3166. return void 0 === r && (r = "NHWC"), void 0 === o && (o = [1, 1]), this.throwIfDisposed(), ft.depthwiseConv2d(this, t, e, n, r, o, a);
  3167. }, t.prototype.separableConv2d = function (t, e, n, r, o, a) {
  3168. return void 0 === o && (o = [1, 1]), void 0 === a && (a = "NHWC"), this.throwIfDisposed(), ft.separableConv2d(this, t, e, n, r, o, a);
  3169. }, t.prototype.avgPool = function (t, e, n, r) {
  3170. return this.throwIfDisposed(), ft.avgPool(this, t, e, n, r);
  3171. }, t.prototype.maxPool = function (t, e, n, r) {
  3172. return this.throwIfDisposed(), ft.maxPool(this, t, e, n, r);
  3173. }, t.prototype.localResponseNormalization = function (t, e, n, r) {
  3174. return void 0 === t && (t = 5), void 0 === e && (e = 1), void 0 === n && (n = 1), void 0 === r && (r = .5), ft.localResponseNormalization(this, t, e, n, r);
  3175. }, t.prototype.pool = function (t, e, n, r, o) {
  3176. return this.throwIfDisposed(), ft.pool(this, t, e, n, r, o);
  3177. }, t.prototype.variable = function (t, e, n) {
  3178. return void 0 === t && (t = !0), this.throwIfDisposed(), ht().makeVariable(this, t, e, n);
  3179. }, t.prototype.unsortedSegmentSum = function (t, e) {
  3180. return this.throwIfDisposed(), ft.unsortedSegmentSum(this, t, e);
  3181. }, t.prototype.batchToSpaceND = function (t, e) {
  3182. return this.throwIfDisposed(), ft.batchToSpaceND(this, t, e);
  3183. }, t.prototype.spaceToBatchND = function (t, e) {
  3184. return this.throwIfDisposed(), ft.spaceToBatchND(this, t, e);
  3185. }, t.prototype.topk = function (t, e) {
  3186. return void 0 === t && (t = 1), void 0 === e && (e = !0), this.throwIfDisposed(), ft.topk(this, t, e);
  3187. }, t.prototype.stridedSlice = function (t, e, n, r, o, a, i, u) {
  3188. return void 0 === r && (r = 0), void 0 === o && (o = 0), void 0 === a && (a = 0), void 0 === i && (i = 0), void 0 === u && (u = 0), this.throwIfDisposed(), ft.stridedSlice(this, t, e, n, r, o, a, i, u);
  3189. }, t.prototype.depthToSpace = function (t, e) {
  3190. return this.throwIfDisposed(), ft.depthToSpace(this, t, e);
  3191. }, t.prototype.fft = function () {
  3192. return this.throwIfDisposed(), ft.spectral.fft(this);
  3193. }, t.prototype.ifft = function () {
  3194. return this.throwIfDisposed(), ft.spectral.ifft(this);
  3195. }, t.prototype.rfft = function () {
  3196. return this.throwIfDisposed(), ft.spectral.rfft(this);
  3197. }, t.prototype.irfft = function () {
  3198. return this.throwIfDisposed(), ft.spectral.irfft(this);
  3199. }, t;
  3200. }();
  3201. exports.Tensor = dt;
  3202. Object.defineProperty(dt, Symbol.hasInstance, {
  3203. value: function (t) {
  3204. return !!t && null != t.dataId && null != t.shape && null != t.dtype;
  3205. }
  3206. });
  3207. var vt,
  3208. mt,
  3209. gt,
  3210. yt,
  3211. xt,
  3212. bt = function (t) {
  3213. function n(e, n, r, o) {
  3214. var a = t.call(this, e.shape, e.dtype, e.dataId, o) || this;
  3215. return a.trainable = n, a.name = r, a;
  3216. }
  3217. return e(n, t), n.prototype.assign = function (t) {
  3218. if (t.dtype !== this.dtype) throw new Error("dtype of the new value (" + t.dtype + ") and previous value (" + this.dtype + ") must match");
  3219. if (!C(t.shape, this.shape)) throw new Error("shape of the new value (" + t.shape + ") and previous value (" + this.shape + ") must match");
  3220. ht().disposeTensor(this), this.dataId = t.dataId, ht().incRef(this, null);
  3221. }, n.prototype.dispose = function () {
  3222. ht().disposeVariable(this), this.isDisposedInternal = !0;
  3223. }, n;
  3224. }(dt);
  3225. exports.Variable = bt;
  3226. exports.Rank = vt;
  3227. Object.defineProperty(bt, Symbol.hasInstance, {
  3228. value: function (t) {
  3229. return t instanceof dt && null != t.assign && t.assign instanceof Function;
  3230. }
  3231. }), function (t) {
  3232. t.R0 = "R0", t.R1 = "R1", t.R2 = "R2", t.R3 = "R3", t.R4 = "R4", t.R5 = "R5", t.R6 = "R6";
  3233. }(vt || (exports.Rank = vt = {})), function (t) {
  3234. t.float32 = "float32", t.int32 = "int32", t.bool = "int32", t.complex64 = "complex64";
  3235. }(mt || (mt = {})), function (t) {
  3236. t.float32 = "float32", t.int32 = "int32", t.bool = "bool", t.complex64 = "complex64";
  3237. }(gt || (gt = {})), function (t) {
  3238. t.float32 = "float32", t.int32 = "float32", t.bool = "float32", t.complex64 = "complex64";
  3239. }(yt || (yt = {})), function (t) {
  3240. t.float32 = "complex64", t.int32 = "complex64", t.bool = "complex64", t.complex64 = "complex64";
  3241. }(xt || (xt = {}));
  3242. var wt = {
  3243. float32: yt,
  3244. int32: mt,
  3245. bool: gt,
  3246. complex64: xt
  3247. };
  3248. function Ct(t, e) {
  3249. if ("string" === t || "string" === e) {
  3250. if ("string" === t && "string" === e) return "string";
  3251. throw new Error("Can not upcast " + t + " with " + e);
  3252. }
  3253. return wt[t][e];
  3254. }
  3255. function Et(t) {
  3256. return Ct(t, "int32");
  3257. }
  3258. function Rt(t, e) {
  3259. if (t.dtype === e.dtype) return [t, e];
  3260. var n = Ct(t.dtype, e.dtype);
  3261. return [t.cast(n), e.cast(n)];
  3262. }
  3263. function It(t, e) {
  3264. g(t.dtype === e.dtype, function () {
  3265. return "The dtypes of the first(" + t.dtype + ") and second(" + e.dtype + ") input must match";
  3266. });
  3267. }
  3268. function kt(t) {
  3269. var e = [];
  3270. return function t(e, n, r) {
  3271. if (null == e) return;
  3272. if (e instanceof dt) return void n.push(e);
  3273. if (o = e, !Array.isArray(o) && "object" != typeof o) return;
  3274. var o;
  3275. var a = e;
  3276. for (var i in a) {
  3277. var u = a[i];
  3278. r.has(u) || (r.add(u), t(u, n, r));
  3279. }
  3280. }(t, e, new Set()), e;
  3281. }
  3282. var St,
  3283. At = Object.freeze({
  3284. makeTypesMatch: Rt,
  3285. assertTypesMatch: It,
  3286. isTensorInList: function (t, e) {
  3287. for (var n = 0; n < e.length; n++) if (e[n].id === t.id) return !0;
  3288. return !1;
  3289. },
  3290. getTensorsInContainer: kt
  3291. }),
  3292. Dt = function () {
  3293. function t() {
  3294. this.registeredVariables = {}, this.nextTapeNodeId = 0, this.numBytes = 0, this.numTensors = 0, this.numStringTensors = 0, this.numDataBuffers = 0, this.gradientDepth = 0, this.kernelDepth = 0, this.scopeStack = [], this.numDataMovesStack = [], this.nextScopeId = 0, this.tensorInfo = new WeakMap(), this.profiling = !1, this.activeProfile = {
  3295. newBytes: 0,
  3296. newTensors: 0,
  3297. peakBytes: 0,
  3298. kernels: [],
  3299. result: null
  3300. };
  3301. }
  3302. return t.prototype.dispose = function () {
  3303. for (var t in this.registeredVariables) this.registeredVariables[t].dispose();
  3304. }, t;
  3305. }(),
  3306. Tt = function () {
  3307. function t(t) {
  3308. this.ENV = t, this.registry = {}, this.registryFactory = {}, this.pendingBackendInitId = 0, this.state = new Dt();
  3309. }
  3310. return t.prototype.ready = function () {
  3311. return n(this, void 0, void 0, function () {
  3312. var t, e, n;
  3313. return r(this, function (r) {
  3314. switch (r.label) {
  3315. case 0:
  3316. if (null != this.pendingBackendInit) return [2, this.pendingBackendInit.then(function () { })];
  3317. if (null != this.backendInstance) return [2];
  3318. t = this.getSortedBackends(), e = 0, r.label = 1;
  3319. case 1:
  3320. return e < t.length ? (n = t[e], [4, this.initializeBackend(n).success]) : [3, 5];
  3321. case 2:
  3322. return r.sent() ? [4, this.setBackend(n)] : [3, 4];
  3323. case 3:
  3324. return r.sent(), [2];
  3325. case 4:
  3326. return e++, [3, 1];
  3327. case 5:
  3328. throw new Error("Could not initialize any backends, all backend initializations failed.");
  3329. }
  3330. });
  3331. });
  3332. }, Object.defineProperty(t.prototype, "backend", {
  3333. get: function () {
  3334. if (null != this.pendingBackendInit) throw new Error("Backend '" + this.backendName + "' has not yet been initialized. Make sure to await tf.ready() before calling other methods");
  3335. if (null == this.backendInstance) {
  3336. var t = this.initializeBackendsAndReturnBest(),
  3337. e = t.name;
  3338. if (t.asyncInit) throw new Error("The highest priority backend '" + e + "' has not yet been initialized. Make sure to await tf.ready() before calling other methods");
  3339. this.setBackend(e);
  3340. }
  3341. return this.backendInstance;
  3342. },
  3343. enumerable: !0,
  3344. configurable: !0
  3345. }), t.prototype.backendNames = function () {
  3346. return Object.keys(this.registryFactory);
  3347. }, t.prototype.findBackend = function (t) {
  3348. if (!(t in this.registry)) {
  3349. if (!(t in this.registryFactory)) return null;
  3350. if (this.initializeBackend(t).asyncInit) return null;
  3351. }
  3352. return this.registry[t];
  3353. }, t.prototype.findBackendFactory = function (t) {
  3354. return t in this.registryFactory ? this.registryFactory[t].factory : null;
  3355. }, t.prototype.registerBackend = function (t, e, n) {
  3356. return void 0 === n && (n = 1), t in this.registryFactory ? (console.warn(t + " backend was already registered. Reusing existing backend factory."), !1) : (this.registryFactory[t] = {
  3357. factory: e,
  3358. priority: n
  3359. }, !0);
  3360. }, t.prototype.setBackend = function (t) {
  3361. return n(this, void 0, void 0, function () {
  3362. var e, n, o;
  3363. return r(this, function (r) {
  3364. switch (r.label) {
  3365. case 0:
  3366. if (null == this.registryFactory[t]) throw new Error("Backend name '" + t + "' not found in registry");
  3367. return this.backendName = t, null != this.registry[t] ? [3, 4] : (this.backendInstance = null, e = this.initializeBackend(t), n = e.success, e.asyncInit ? [4, n] : [3, 2]);
  3368. case 1:
  3369. return o = r.sent(), [3, 3];
  3370. case 2:
  3371. o = n, r.label = 3;
  3372. case 3:
  3373. if (!o) return [2, !1];
  3374. r.label = 4;
  3375. case 4:
  3376. return this.backendInstance = this.registry[t], this.setupRegisteredKernels(), this.profiler = new et(this.backendInstance), [2, !0];
  3377. }
  3378. });
  3379. });
  3380. }, t.prototype.setupRegisteredKernels = function () {
  3381. var t = this;
  3382. c(this.backendName).forEach(function (e) {
  3383. null != e.setupFunc && e.setupFunc(t.backendInstance);
  3384. });
  3385. }, t.prototype.disposeRegisteredKernels = function (t) {
  3386. var e = this;
  3387. c(t).forEach(function (n) {
  3388. null != n.disposeFunc && n.disposeFunc(e.registry[t]);
  3389. });
  3390. }, t.prototype.initializeBackend = function (t) {
  3391. var e = this,
  3392. n = this.registryFactory[t];
  3393. if (null == n) throw new Error("Cannot initialize backend " + t + ", no registration found.");
  3394. try {
  3395. var r = n.factory();
  3396. if (Promise.resolve(r) === r) {
  3397. var o = ++this.pendingBackendInitId,
  3398. a = r.then(function (n) {
  3399. return !(o < e.pendingBackendInitId) && (e.registry[t] = n, e.pendingBackendInit = null, !0);
  3400. }).catch(function (n) {
  3401. return !(o < e.pendingBackendInitId) && (e.pendingBackendInit = null, console.warn("Initialization of backend " + t + " failed"), console.warn(n.stack || n.message), !1);
  3402. });
  3403. return this.pendingBackendInit = a, {
  3404. success: a,
  3405. asyncInit: !0
  3406. };
  3407. }
  3408. return this.registry[t] = r, {
  3409. success: !0,
  3410. asyncInit: !1
  3411. };
  3412. } catch (e) {
  3413. return console.warn("Initialization of backend " + t + " failed"), console.warn(e.stack || e.message), {
  3414. success: !1,
  3415. asyncInit: !1
  3416. };
  3417. }
  3418. }, t.prototype.removeBackend = function (t) {
  3419. if (!(t in this.registryFactory)) throw new Error(t + " backend not found in registry");
  3420. this.backendName === t && null != this.pendingBackendInit && this.pendingBackendInitId++, t in this.registry && (this.disposeRegisteredKernels(t), this.registry[t].dispose(), delete this.registry[t]), delete this.registryFactory[t], this.backendName === t && (this.pendingBackendInit = null, this.backendName = null, this.backendInstance = null);
  3421. }, t.prototype.getSortedBackends = function () {
  3422. var t = this;
  3423. if (0 === Object.keys(this.registryFactory).length) throw new Error("No backend found in registry.");
  3424. return Object.keys(this.registryFactory).sort(function (e, n) {
  3425. return t.registryFactory[n].priority - t.registryFactory[e].priority;
  3426. });
  3427. }, t.prototype.initializeBackendsAndReturnBest = function () {
  3428. for (var t = this.getSortedBackends(), e = 0; e < t.length; e++) {
  3429. var n = t[e],
  3430. r = this.initializeBackend(n),
  3431. o = r.success,
  3432. a = r.asyncInit;
  3433. if (a || o) return {
  3434. name: n,
  3435. asyncInit: a
  3436. };
  3437. }
  3438. throw new Error("Could not initialize any backends, all backend initializations failed.");
  3439. }, t.prototype.moveData = function (t, e) {
  3440. var n = this.state.tensorInfo.get(e),
  3441. r = n.backend,
  3442. o = this.readSync(e);
  3443. r.disposeData(e), n.backend = t, t.move(e, o, n.shape, n.dtype), this.shouldCheckForMemLeaks() && this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1]++;
  3444. }, t.prototype.tidy = function (t, e) {
  3445. var n,
  3446. r = this,
  3447. o = null;
  3448. if (null == e) {
  3449. if ("function" != typeof t) throw new Error("Please provide a function to tidy()");
  3450. e = t;
  3451. } else {
  3452. if ("string" != typeof t && !(t instanceof String)) throw new Error("When calling with two arguments, the first argument to tidy() must be a string");
  3453. if ("function" != typeof e) throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");
  3454. o = t;
  3455. }
  3456. return this.scopedRun(function () {
  3457. return r.startScope(o);
  3458. }, function () {
  3459. return r.endScope(n);
  3460. }, function () {
  3461. return (n = e()) instanceof Promise && console.error("Cannot return a Promise inside of tidy."), n;
  3462. });
  3463. }, t.prototype.scopedRun = function (t, e, n) {
  3464. t();
  3465. try {
  3466. var r = n();
  3467. return e(), r;
  3468. } catch (t) {
  3469. throw e(), t;
  3470. }
  3471. }, t.prototype.nextTensorId = function () {
  3472. return t.nextTensorId++;
  3473. }, t.prototype.nextVariableId = function () {
  3474. return t.nextVariableId++;
  3475. }, t.prototype.clone = function (t) {
  3476. var e = this.makeTensorFromDataId(t.dataId, t.shape, t.dtype),
  3477. n = {
  3478. x: t
  3479. };
  3480. return this.addTapeNode(this.state.activeScope.name, n, [e], function (t) {
  3481. return {
  3482. x: function () {
  3483. return t.toFloat();
  3484. }
  3485. };
  3486. }, []), e;
  3487. }, t.prototype.runKernel = function (t, e, n, r, o) {
  3488. return this.runKernelFunc(null, e, null, t, n, r, o);
  3489. }, t.prototype.shouldCheckForMemLeaks = function () {
  3490. return this.ENV.getBool("IS_TEST");
  3491. }, t.prototype.checkKernelForMemLeak = function (t, e, n) {
  3492. var r = this.backend.numDataIds(),
  3493. o = 0;
  3494. n.forEach(function (t) {
  3495. o += "complex64" === t.dtype ? 3 : 1;
  3496. });
  3497. var a = this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1],
  3498. i = r - e - o - a;
  3499. if (i > 0) throw new Error("Backend '" + this.backendName + "' has an internal memory leak (" + i + " data ids) after running '" + t + "'");
  3500. }, t.prototype.runKernelFunc = function (t, e, n, r, o, a, i) {
  3501. var u,
  3502. c = this;
  3503. void 0 === a && (a = []), void 0 === i && (i = []);
  3504. var l,
  3505. h = [],
  3506. f = this.isTapeOn(),
  3507. p = null != this.state.activeScope ? this.state.activeScope.name : "",
  3508. d = function (t) {
  3509. f && (h = t.map(function (t) {
  3510. return c.keep(c.clone(t));
  3511. }));
  3512. },
  3513. v = this.state.numBytes,
  3514. m = this.state.numTensors;
  3515. this.shouldCheckForMemLeaks() && this.state.numDataMovesStack.push(0);
  3516. var g,
  3517. y = s(r, this.backendName);
  3518. return l = null != y ? function () {
  3519. var t = c.backend.numDataIds();
  3520. g = y.kernelFunc({
  3521. inputs: e,
  3522. attrs: o,
  3523. backend: c.backend
  3524. });
  3525. var n = Array.isArray(g) ? g : [g];
  3526. c.shouldCheckForMemLeaks() && c.checkKernelForMemLeak(p, t, n);
  3527. var r = n.map(function (t) {
  3528. var e = t.dataId,
  3529. n = t.shape,
  3530. r = t.dtype;
  3531. return c.makeTensorFromDataId(e, n, r);
  3532. }),
  3533. u = r.filter(function (t, e) {
  3534. return i[e];
  3535. });
  3536. return d(a.slice().concat(u)), r;
  3537. } : function () {
  3538. var e = c.backend.numDataIds();
  3539. g = c.tidy(function () {
  3540. return t(c.backend, d);
  3541. });
  3542. var n = Array.isArray(g) ? g : [g];
  3543. return c.shouldCheckForMemLeaks() && c.checkKernelForMemLeak(p, e, n), n;
  3544. }, this.scopedRun(function () {
  3545. return c.state.kernelDepth++;
  3546. }, function () {
  3547. return c.state.kernelDepth--;
  3548. }, function () {
  3549. u = c.ENV.getBool("DEBUG") ? c.profiler.profileKernel(p, e, function () {
  3550. return l();
  3551. }) : l();
  3552. }), f && this.addTapeNode(p, e, u, n, h), this.state.profiling && this.state.activeProfile.kernels.push({
  3553. name: p,
  3554. bytesAdded: this.state.numBytes - v,
  3555. totalBytesSnapshot: this.state.numBytes,
  3556. tensorsAdded: this.state.numTensors - m,
  3557. totalTensorsSnapshot: this.state.numTensors,
  3558. inputShapes: Object.keys(e).map(function (t) {
  3559. return e[t].shape;
  3560. }),
  3561. outputShapes: u.map(function (t) {
  3562. return t.shape;
  3563. })
  3564. }), Array.isArray(g) ? u : u[0];
  3565. }, t.prototype.makeTensor = function (t, e, n, r) {
  3566. if (null == t) throw new Error("Values passed to engine.makeTensor() are null");
  3567. n = n || "float32", r = r || this.backend;
  3568. var o = t;
  3569. "string" === n && W(t[0]) && (o = t.map(function (t) {
  3570. return J(t);
  3571. }));
  3572. var a = r.write(o, e, n),
  3573. i = new dt(e, n, a, this.nextTensorId());
  3574. if (this.incRef(i, r), "string" === n) {
  3575. var u = this.state.tensorInfo.get(a),
  3576. s = L(o);
  3577. this.state.numBytes += s - u.bytes, u.bytes = s;
  3578. }
  3579. return i;
  3580. }, t.prototype.makeTensorFromDataId = function (t, e, n, r) {
  3581. var o = new dt(e, n = n || "float32", t, this.nextTensorId());
  3582. return this.incRef(o, r), o;
  3583. }, t.prototype.makeVariable = function (t, e, n, r) {
  3584. void 0 === e && (e = !0), n = n || this.nextVariableId().toString(), null != r && r !== t.dtype && (t = t.asType(r));
  3585. var o = new bt(t, e, n, this.nextTensorId());
  3586. if (null != this.state.registeredVariables[o.name]) throw new Error("Variable with name " + o.name + " was already registered");
  3587. return this.state.registeredVariables[o.name] = o, this.incRef(o, this.backend), o;
  3588. }, t.prototype.incRef = function (t, e) {
  3589. var n = this.state.tensorInfo.has(t.dataId) ? this.state.tensorInfo.get(t.dataId).refCount : 0;
  3590. if (this.state.numTensors++, "string" === t.dtype && this.state.numStringTensors++, 0 === n) {
  3591. this.state.numDataBuffers++;
  3592. var r = 0;
  3593. "complex64" !== t.dtype && "string" !== t.dtype && (r = t.size * P(t.dtype)), this.state.tensorInfo.set(t.dataId, {
  3594. backend: e || this.backend,
  3595. dtype: t.dtype,
  3596. shape: t.shape,
  3597. bytes: r,
  3598. refCount: 0
  3599. }), this.state.numBytes += r;
  3600. }
  3601. this.state.tensorInfo.get(t.dataId).refCount++, t instanceof bt || this.track(t);
  3602. }, t.prototype.disposeTensor = function (t) {
  3603. if (this.state.tensorInfo.has(t.dataId)) {
  3604. this.state.numTensors--, "string" === t.dtype && this.state.numStringTensors--;
  3605. var e = this.state.tensorInfo.get(t.dataId);
  3606. e.refCount <= 1 ? ("complex64" !== t.dtype && (this.state.numBytes -= e.bytes), this.state.numDataBuffers--, e.backend.disposeData(t.dataId), this.state.tensorInfo.delete(t.dataId)) : this.state.tensorInfo.get(t.dataId).refCount--;
  3607. }
  3608. }, t.prototype.disposeVariables = function () {
  3609. for (var t in this.state.registeredVariables) {
  3610. var e = this.state.registeredVariables[t];
  3611. this.disposeVariable(e);
  3612. }
  3613. }, t.prototype.disposeVariable = function (t) {
  3614. this.disposeTensor(t), null != this.state.registeredVariables[t.name] && delete this.state.registeredVariables[t.name];
  3615. }, t.prototype.memory = function () {
  3616. var t = this.backend.memory();
  3617. return t.numTensors = this.state.numTensors, t.numDataBuffers = this.state.numDataBuffers, t.numBytes = this.state.numBytes, this.state.numStringTensors > 0 && (t.unreliable = !0, null == t.reasons && (t.reasons = []), t.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")), t;
  3618. }, t.prototype.profile = function (t) {
  3619. return n(this, void 0, void 0, function () {
  3620. var e, n;
  3621. return r(this, function (r) {
  3622. return this.state.profiling = !0, e = this.state.numBytes, n = this.state.numTensors, this.state.activeProfile.kernels = [], this.state.activeProfile.result = t(), this.state.profiling = !1, this.state.activeProfile.peakBytes = Math.max.apply(Math, this.state.activeProfile.kernels.map(function (t) {
  3623. return t.totalBytesSnapshot;
  3624. })), this.state.activeProfile.newBytes = this.state.numBytes - e, this.state.activeProfile.newTensors = this.state.numTensors - n, [2, this.state.activeProfile];
  3625. });
  3626. });
  3627. }, t.prototype.isTapeOn = function () {
  3628. return this.state.gradientDepth > 0 && 0 === this.state.kernelDepth;
  3629. }, t.prototype.addTapeNode = function (t, e, n, r, o) {
  3630. var a = this,
  3631. i = {
  3632. id: this.state.nextTapeNodeId++,
  3633. name: t,
  3634. inputs: e,
  3635. outputs: n,
  3636. saved: o
  3637. };
  3638. null != r && (i.gradient = function (t) {
  3639. return t = t.map(function (t, e) {
  3640. if (null == t) {
  3641. var r = n[e],
  3642. o = $(r.size, r.dtype);
  3643. return a.makeTensor(o, r.shape, r.dtype);
  3644. }
  3645. return t;
  3646. }), r(t.length > 1 ? t : t[0], o);
  3647. }), this.state.activeTape.push(i);
  3648. }, t.prototype.keep = function (t) {
  3649. return t.kept = !0, t;
  3650. }, t.prototype.startTape = function () {
  3651. 0 === this.state.gradientDepth && (this.state.activeTape = []), this.state.gradientDepth++;
  3652. }, t.prototype.endTape = function () {
  3653. this.state.gradientDepth--;
  3654. }, t.prototype.startScope = function (t) {
  3655. var e = {
  3656. track: [],
  3657. name: "unnamed scope",
  3658. id: this.state.nextScopeId++
  3659. };
  3660. t && (e.name = t), this.state.scopeStack.push(e), this.state.activeScope = e;
  3661. }, t.prototype.endScope = function (t) {
  3662. for (var e = this, n = kt(t), r = new Set(n.map(function (t) {
  3663. return t.id;
  3664. })), o = 0; o < this.state.activeScope.track.length; o++) {
  3665. var a = this.state.activeScope.track[o];
  3666. a.kept || r.has(a.id) || a.dispose();
  3667. }
  3668. var i = this.state.scopeStack.pop();
  3669. this.state.activeScope = 0 === this.state.scopeStack.length ? null : this.state.scopeStack[this.state.scopeStack.length - 1], n.forEach(function (t) {
  3670. t.kept || t.scopeId !== i.id || e.track(t);
  3671. });
  3672. }, t.prototype.gradients = function (t, e, n, r) {
  3673. var o = this;
  3674. if (void 0 === r && (r = !1), g(e.length > 0, function () {
  3675. return "gradients() received an empty list of xs.";
  3676. }), null != n && "float32" !== n.dtype) throw new Error("dy must have 'float32' dtype, but has '" + n.dtype + "'");
  3677. var a = this.scopedRun(function () {
  3678. return o.startTape();
  3679. }, function () {
  3680. return o.endTape();
  3681. }, function () {
  3682. return o.tidy("forward", t);
  3683. });
  3684. g(a instanceof dt, function () {
  3685. return "The result y returned by f() must be a tensor.";
  3686. });
  3687. var i = function (t, e, n) {
  3688. for (var r = {}, o = {}, a = 0; a < e.length; a++) r[e[a].id] = !0;
  3689. for (a = 0; a < t.length; a++) {
  3690. var i = (d = t[a]).inputs;
  3691. for (var u in i) {
  3692. for (var s = i[u], c = !1, l = 0; l < e.length; l++) if (r[s.id]) {
  3693. d.outputs.forEach(function (t) {
  3694. return r[t.id] = !0;
  3695. }), c = !0, o[d.id] = !0;
  3696. break;
  3697. }
  3698. if (c) break;
  3699. }
  3700. }
  3701. var h = {};
  3702. h[n.id] = !0;
  3703. var f = {};
  3704. for (a = t.length - 1; a >= 0; a--) for (i = (d = t[a]).inputs, l = 0; l < d.outputs.length; l++) if (h[d.outputs[l].id]) {
  3705. for (var u in i) h[i[u].id] = !0, f[d.id] = !0;
  3706. break;
  3707. }
  3708. var p = [];
  3709. for (a = 0; a < t.length; a++) {
  3710. var d;
  3711. if (o[(d = t[a]).id] && f[d.id]) {
  3712. var v = {};
  3713. for (var u in d.inputs) {
  3714. var m = d.inputs[u];
  3715. r[m.id] && (v[u] = m);
  3716. }
  3717. var g = Object.assign({}, d);
  3718. g.inputs = v, g.outputs = d.outputs, p.push(g);
  3719. }
  3720. }
  3721. return p;
  3722. }(this.state.activeTape, e, a);
  3723. if (!r && 0 === i.length && e.length > 0) throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that the f you passed encloses all operations that lead from x to y.");
  3724. return this.tidy("backward", function () {
  3725. var t,
  3726. r,
  3727. u = {};
  3728. u[a.id] = null == n ? (t = a.shape, r = X(w(t), "float32"), Nt.makeTensor(r, t, "float32")) : n, function (t, e, n) {
  3729. for (var r = function (r) {
  3730. var o = e[r],
  3731. a = [];
  3732. if (o.outputs.forEach(function (e) {
  3733. var n = t[e.id];
  3734. null != n ? a.push(n) : a.push(null);
  3735. }), null == o.gradient) throw new Error("Cannot compute gradient: gradient function not found for " + o.name + ".");
  3736. var i = o.gradient(a),
  3737. u = function (e) {
  3738. if (!(e in i)) throw new Error("Cannot backprop through input " + e + ". Available gradients found: " + Object.keys(i) + ".");
  3739. var r = n(function () {
  3740. return i[e]();
  3741. });
  3742. if ("float32" !== r.dtype) throw new Error("Error in gradient for op " + o.name + ". The gradient of input " + e + " must have 'float32' dtype, but has '" + r.dtype + "'");
  3743. var a = o.inputs[e];
  3744. if (!C(r.shape, a.shape)) throw new Error("Error in gradient for op " + o.name + ". The gradient of input '" + e + "' has shape '" + r.shape + "', which does not match the shape of the input '" + a.shape + "'");
  3745. if (null == t[a.id]) t[a.id] = r; else {
  3746. var u = t[a.id];
  3747. t[a.id] = u.add(r), u.dispose();
  3748. }
  3749. };
  3750. for (var s in o.inputs) u(s);
  3751. }, o = e.length - 1; o >= 0; o--) r(o);
  3752. }(u, i, function (t) {
  3753. return o.tidy(t);
  3754. });
  3755. var s = e.map(function (t) {
  3756. return u[t.id];
  3757. });
  3758. return 0 === o.state.gradientDepth && (o.state.activeTape.forEach(function (t) {
  3759. for (var e in t.saved) t.saved[e].dispose();
  3760. }), o.state.activeTape = null), {
  3761. value: a,
  3762. grads: s
  3763. };
  3764. });
  3765. }, t.prototype.customGrad = function (t) {
  3766. var e = this;
  3767. return g(G(t), function () {
  3768. return "The f passed in customGrad(f) must be a function.";
  3769. }), function () {
  3770. for (var n, r = [], o = 0; o < arguments.length; o++) r[o] = arguments[o];
  3771. g(r.every(function (t) {
  3772. return t instanceof dt;
  3773. }), function () {
  3774. return "The args passed in customGrad(f)(x1, x2,...) must all be tensors";
  3775. });
  3776. var a = {};
  3777. return r.forEach(function (t, e) {
  3778. a[e] = t;
  3779. }), e.runKernelFunc(function (e, o) {
  3780. return g((n = t.apply(void 0, r.concat([o]))).value instanceof dt, function () {
  3781. return "The function f passed in customGrad(f) must return an object where `obj.value` is a tensor";
  3782. }), g(G(n.gradFunc), function () {
  3783. return "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function.";
  3784. }), n.value;
  3785. }, a, function (t, e) {
  3786. var o = n.gradFunc(t, e),
  3787. a = Array.isArray(o) ? o : [o];
  3788. g(a.length === r.length, function () {
  3789. return "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns the same number of tensors as inputs passed to f(...).";
  3790. }), g(a.every(function (t) {
  3791. return t instanceof dt;
  3792. }), function () {
  3793. return "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors.";
  3794. });
  3795. var i = {};
  3796. return a.forEach(function (t, e) {
  3797. i[e] = function () {
  3798. return t;
  3799. };
  3800. }), i;
  3801. });
  3802. };
  3803. }, t.prototype.readSync = function (t) {
  3804. return this.state.tensorInfo.get(t).backend.readSync(t);
  3805. }, t.prototype.read = function (t) {
  3806. return this.state.tensorInfo.get(t).backend.read(t);
  3807. }, t.prototype.fromPixels = function (t, e) {
  3808. return this.backend.fromPixels(t, e);
  3809. }, t.prototype.time = function (t) {
  3810. return n(this, void 0, void 0, function () {
  3811. var e, n;
  3812. return r(this, function (r) {
  3813. switch (r.label) {
  3814. case 0:
  3815. return e = Y(), [4, this.backend.time(t)];
  3816. case 1:
  3817. return (n = r.sent()).wallMs = Y() - e, [2, n];
  3818. }
  3819. });
  3820. });
  3821. }, t.prototype.track = function (t) {
  3822. return null != this.state.activeScope && (t.scopeId = this.state.activeScope.id, this.state.activeScope.track.push(t)), t;
  3823. }, Object.defineProperty(t.prototype, "registeredVariables", {
  3824. get: function () {
  3825. return this.state.registeredVariables;
  3826. },
  3827. enumerable: !0,
  3828. configurable: !0
  3829. }), t.prototype.reset = function () {
  3830. for (var t in this.pendingBackendInitId++, this.state.dispose(), this.ENV.reset(), this.state = new Dt(), this.registry) this.disposeRegisteredKernels(t), this.registry[t].dispose(), delete this.registry[t];
  3831. this.backendName = null, this.backendInstance = null, this.pendingBackendInit = null;
  3832. }, t.nextTensorId = 0, t.nextVariableId = 0, t;
  3833. }();
  3834. exports.tensor_util = At;
  3835. var Nt = function () {
  3836. var t = function () {
  3837. if (null == St) {
  3838. var t = void 0;
  3839. if ("undefined" != typeof window) t = window; else if ("undefined" != typeof global) t = global; else if ("undefined" != typeof process) t = process; else {
  3840. if ("undefined" == typeof self) throw new Error("Could not find a global object");
  3841. t = self;
  3842. }
  3843. St = t;
  3844. }
  3845. return St;
  3846. }();
  3847. if (null == t._tfengine) {
  3848. var e = new o(t);
  3849. t._tfengine = new Tt(e);
  3850. }
  3851. return function (t) {
  3852. exports.ENV = i = t;
  3853. }(t._tfengine.ENV), ht = function () {
  3854. return t._tfengine;
  3855. }, t._tfengine;
  3856. }();
  3857. function Ft() {
  3858. return "undefined" != typeof window && null != window.document || "undefined" != typeof WorkerGlobalScope;
  3859. }
  3860. var Ot = a();
  3861. Ot.registerFlag("DEBUG", function () {
  3862. return !1;
  3863. }, function (t) {
  3864. t && console.warn("Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.");
  3865. }), Ot.registerFlag("IS_BROWSER", function () {
  3866. return Ft();
  3867. }), Ot.registerFlag("IS_NODE", function () {
  3868. return "undefined" != typeof process && void 0 !== process.versions && void 0 !== process.versions.node;
  3869. }), Ot.registerFlag("IS_CHROME", function () {
  3870. return "undefined" != typeof navigator && null != navigator && null != navigator.userAgent && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
  3871. }), Ot.registerFlag("PROD", function () {
  3872. return !1;
  3873. }), Ot.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY", function () {
  3874. return Ot.getBool("DEBUG");
  3875. }), Ot.registerFlag("DEPRECATION_WARNINGS_ENABLED", function () {
  3876. return !0;
  3877. }), Ot.registerFlag("IS_TEST", function () {
  3878. return !1;
  3879. });
  3880. var _t,
  3881. Mt,
  3882. Bt,
  3883. Pt = {},
  3884. Lt = {
  3885. alpha: !1,
  3886. antialias: !1,
  3887. premultipliedAlpha: !1,
  3888. preserveDrawingBuffer: !1,
  3889. depth: !1,
  3890. stencil: !1,
  3891. failIfMajorPerformanceCaveat: !0
  3892. };
  3893. function Wt(t, e) {
  3894. Pt[t] = e;
  3895. }
  3896. function Ut(t) {
  3897. t in Pt || (Pt[t] = function (t) {
  3898. if (1 !== t && 2 !== t) throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");
  3899. var e = Vt(t);
  3900. if (e.addEventListener("webglcontextlost", function (e) {
  3901. e.preventDefault(), delete Pt[t];
  3902. }, !1), 1 === t) return e.getContext("webgl", Lt) || e.getContext("experimental-webgl", Lt);
  3903. return e.getContext("webgl2", Lt);
  3904. }(t));
  3905. var e = Pt[t];
  3906. return e.isContextLost() ? (delete Pt[t], Ut(t)) : (e.disable(e.DEPTH_TEST), e.disable(e.STENCIL_TEST), e.disable(e.BLEND), e.disable(e.DITHER), e.disable(e.POLYGON_OFFSET_FILL), e.disable(e.SAMPLE_COVERAGE), e.enable(e.SCISSOR_TEST), e.enable(e.CULL_FACE), e.cullFace(e.BACK), Pt[t]);
  3907. }
  3908. function Vt(t) {
  3909. if ("undefined" != typeof OffscreenCanvas && 2 === t) return new OffscreenCanvas(300, 150);
  3910. if ("undefined" != typeof document) return document.createElement("canvas");
  3911. throw new Error("Cannot create a canvas in this context");
  3912. }
  3913. function zt(t, e) {
  3914. return [e, t];
  3915. }
  3916. function Gt(t) {
  3917. var e = w(t);
  3918. return I(Math.ceil(e / 4));
  3919. }
  3920. function Ht(t, e) {
  3921. return [Math.max(1, Math.ceil(e / 2)), Math.max(1, Math.ceil(t / 2))];
  3922. }
  3923. function qt(t, e) {
  3924. var n,
  3925. r,
  3926. o,
  3927. i,
  3928. u,
  3929. s,
  3930. c,
  3931. l,
  3932. h,
  3933. f = t;
  3934. return 2 === a().getNumber("WEBGL_VERSION") ? (n = f.R32F, r = f.R16F, o = f.RGBA16F, i = f.RGBA32F, u = f.RED, s = 4, c = 1, l = f.HALF_FLOAT, h = f.FLOAT) : (n = t.RGBA, r = t.RGBA, o = t.RGBA, i = f.RGBA, u = t.RGBA, s = 4, c = 4, l = null != e ? e.HALF_FLOAT_OES : null, h = t.FLOAT), {
  3935. internalFormatFloat: n,
  3936. internalFormatHalfFloat: r,
  3937. internalFormatPackedHalfFloat: o,
  3938. internalFormatPackedFloat: i,
  3939. textureFormatFloat: u,
  3940. downloadTextureFormat: t.RGBA,
  3941. downloadUnpackNumChannels: s,
  3942. defaultNumChannels: c,
  3943. textureTypeHalfFloat: l,
  3944. textureTypeFloat: h
  3945. };
  3946. }
  3947. function Kt(t, e, n) {
  3948. var r = n();
  3949. return e && function (t) {
  3950. var e = t.getError();
  3951. if (e !== t.NO_ERROR) throw new Error("WebGL Error: " + Yt(t, e));
  3952. }(t), r;
  3953. }
  3954. !function (t) {
  3955. t[t.DENSE = 0] = "DENSE", t[t.SHARED_BATCH = 1] = "SHARED_BATCH";
  3956. }(_t || (_t = {})), function (t) {
  3957. t[t.RENDER = 0] = "RENDER", t[t.UPLOAD = 1] = "UPLOAD", t[t.PIXELS = 2] = "PIXELS", t[t.DOWNLOAD = 3] = "DOWNLOAD";
  3958. }(Mt || (Mt = {})), function (t) {
  3959. t[t.UNPACKED_FLOAT16 = 0] = "UNPACKED_FLOAT16", t[t.UNPACKED_FLOAT32 = 1] = "UNPACKED_FLOAT32", t[t.PACKED_4X1_UNSIGNED_BYTE = 2] = "PACKED_4X1_UNSIGNED_BYTE", t[t.PACKED_2X2_FLOAT32 = 3] = "PACKED_2X2_FLOAT32", t[t.PACKED_2X2_FLOAT16 = 4] = "PACKED_2X2_FLOAT16";
  3960. }(Bt || (Bt = {}));
  3961. var jt = 5.96e-8,
  3962. Xt = 65504;
  3963. function $t(t) {
  3964. return !!(a().getBool("WEBGL_RENDER_FLOAT32_ENABLED") || 0 === t || jt < Math.abs(t) && Math.abs(t) < Xt);
  3965. }
  3966. function Yt(t, e) {
  3967. switch (e) {
  3968. case t.NO_ERROR:
  3969. return "NO_ERROR";
  3970. case t.INVALID_ENUM:
  3971. return "INVALID_ENUM";
  3972. case t.INVALID_VALUE:
  3973. return "INVALID_VALUE";
  3974. case t.INVALID_OPERATION:
  3975. return "INVALID_OPERATION";
  3976. case t.INVALID_FRAMEBUFFER_OPERATION:
  3977. return "INVALID_FRAMEBUFFER_OPERATION";
  3978. case t.OUT_OF_MEMORY:
  3979. return "OUT_OF_MEMORY";
  3980. case t.CONTEXT_LOST_WEBGL:
  3981. return "CONTEXT_LOST_WEBGL";
  3982. default:
  3983. return "Unknown error code " + e;
  3984. }
  3985. }
  3986. function Qt(t, e, n) {
  3987. return be(t, e, function () {
  3988. return t.getExtension(n);
  3989. }, 'Extension "' + n + '" not supported on this browser.');
  3990. }
  3991. function Jt(t, e, n) {
  3992. var r = be(t, e, function () {
  3993. return t.createShader(t.VERTEX_SHADER);
  3994. }, "Unable to create vertex WebGLShader.");
  3995. if (Kt(t, e, function () {
  3996. return t.shaderSource(r, n);
  3997. }), Kt(t, e, function () {
  3998. return t.compileShader(r);
  3999. }), !1 === t.getShaderParameter(r, t.COMPILE_STATUS)) throw console.log(t.getShaderInfoLog(r)), new Error("Failed to compile vertex shader.");
  4000. return r;
  4001. }
  4002. function Zt(t, e, n) {
  4003. var r = be(t, e, function () {
  4004. return t.createShader(t.FRAGMENT_SHADER);
  4005. }, "Unable to create fragment WebGLShader.");
  4006. if (Kt(t, e, function () {
  4007. return t.shaderSource(r, n);
  4008. }), Kt(t, e, function () {
  4009. return t.compileShader(r);
  4010. }), !1 === t.getShaderParameter(r, t.COMPILE_STATUS)) throw function (t, e) {
  4011. var n = ne.exec(e);
  4012. if (null == n) return console.log("Couldn't parse line number in error: " + e), void console.log(t);
  4013. for (var r = +n[1], o = t.split("\n"), a = o.length.toString().length + 2, i = o.map(function (t, e) {
  4014. return k((e + 1).toString(), a) + t;
  4015. }), u = 0, s = 0; s < i.length; s++) u = Math.max(i[s].length, u);
  4016. var c = i.slice(0, r - 1),
  4017. l = i.slice(r - 1, r),
  4018. h = i.slice(r);
  4019. console.log(c.join("\n")), console.log(e.split("\n")[0]), console.log("%c " + k(l[0], u), "border:1px solid red; background-color:#e3d2d2; color:#a61717"), console.log(h.join("\n"));
  4020. }(n, t.getShaderInfoLog(r)), new Error("Failed to compile fragment shader.");
  4021. return r;
  4022. }
  4023. var te,
  4024. ee,
  4025. ne = /ERROR: [0-9]+:([0-9]+):/g;
  4026. function re(t, e) {
  4027. return be(t, e, function () {
  4028. return t.createProgram();
  4029. }, "Unable to create WebGLProgram.");
  4030. }
  4031. function oe(t, e, n) {
  4032. if (Kt(t, e, function () {
  4033. return t.linkProgram(n);
  4034. }), !1 === t.getProgramParameter(n, t.LINK_STATUS)) throw console.log(t.getProgramInfoLog(n)), new Error("Failed to link vertex and fragment shaders.");
  4035. }
  4036. function ae(t, e, n) {
  4037. if (Kt(t, e, function () {
  4038. return t.validateProgram(n);
  4039. }), !1 === t.getProgramParameter(n, t.VALIDATE_STATUS)) throw console.log(t.getProgramInfoLog(n)), new Error("Shader program validation failed.");
  4040. }
  4041. function ie(t, e, n) {
  4042. var r = be(t, e, function () {
  4043. return t.createBuffer();
  4044. }, "Unable to create WebGLBuffer");
  4045. return Kt(t, e, function () {
  4046. return t.bindBuffer(t.ARRAY_BUFFER, r);
  4047. }), Kt(t, e, function () {
  4048. return t.bufferData(t.ARRAY_BUFFER, n, t.STATIC_DRAW);
  4049. }), r;
  4050. }
  4051. function ue(t, e, n) {
  4052. var r = be(t, e, function () {
  4053. return t.createBuffer();
  4054. }, "Unable to create WebGLBuffer");
  4055. return Kt(t, e, function () {
  4056. return t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, r);
  4057. }), Kt(t, e, function () {
  4058. return t.bufferData(t.ELEMENT_ARRAY_BUFFER, n, t.STATIC_DRAW);
  4059. }), r;
  4060. }
  4061. function se(t, e) {
  4062. return be(t, e, function () {
  4063. return t.createTexture();
  4064. }, "Unable to create WebGLTexture.");
  4065. }
  4066. function ce(t, e) {
  4067. var n = a().getNumber("WEBGL_MAX_TEXTURE_SIZE");
  4068. if (t <= 0 || e <= 0) {
  4069. var r = "[" + t + "x" + e + "]";
  4070. throw new Error("Requested texture size " + r + " is invalid.");
  4071. }
  4072. if (t > n || e > n) {
  4073. r = "[" + t + "x" + e + "]";
  4074. throw new Error("Requested texture size " + r + " greater than WebGL maximum on this browser / GPU " + ("[" + n + "x" + n + "]") + ".");
  4075. }
  4076. }
  4077. function le(t, e) {
  4078. return be(t, e, function () {
  4079. return t.createFramebuffer();
  4080. }, "Unable to create WebGLFramebuffer.");
  4081. }
  4082. function he(t, e, n, r, o, a, i, u) {
  4083. var s = t.getAttribLocation(n, r);
  4084. return -1 !== s && (Kt(t, e, function () {
  4085. return t.bindBuffer(t.ARRAY_BUFFER, o);
  4086. }), Kt(t, e, function () {
  4087. return t.vertexAttribPointer(s, a, t.FLOAT, !1, i, u);
  4088. }), Kt(t, e, function () {
  4089. return t.enableVertexAttribArray(s);
  4090. }), !0);
  4091. }
  4092. function fe(t, e, n, r) {
  4093. we(t, r), Kt(t, e, function () {
  4094. return t.activeTexture(t.TEXTURE0 + r);
  4095. }), Kt(t, e, function () {
  4096. return t.bindTexture(t.TEXTURE_2D, n);
  4097. });
  4098. }
  4099. function pe(t, e, n, r) {
  4100. return be(t, e, function () {
  4101. return t.getUniformLocation(n, r);
  4102. }, 'uniform "' + r + '" not present in program.');
  4103. }
  4104. function de(t, e, n) {
  4105. return t.getUniformLocation(e, n);
  4106. }
  4107. function ve(t, e, n, r, o, a) {
  4108. Kt(t, e, function () {
  4109. return fe(t, e, r, a);
  4110. }), Kt(t, e, function () {
  4111. return t.uniform1i(o, a);
  4112. });
  4113. }
  4114. function me(t, e, n, r) {
  4115. Kt(t, e, function () {
  4116. return t.bindFramebuffer(t.FRAMEBUFFER, r);
  4117. }), Kt(t, e, function () {
  4118. return t.framebufferTexture2D(t.FRAMEBUFFER, t.COLOR_ATTACHMENT0, t.TEXTURE_2D, n, 0);
  4119. });
  4120. }
  4121. function ge(t, e, n) {
  4122. Kt(t, e, function () {
  4123. return t.bindFramebuffer(t.FRAMEBUFFER, n);
  4124. }), Kt(t, e, function () {
  4125. return t.framebufferTexture2D(t.FRAMEBUFFER, t.COLOR_ATTACHMENT0, t.TEXTURE_2D, null, 0);
  4126. });
  4127. }
  4128. function ye(t) {
  4129. var e = t.checkFramebufferStatus(t.FRAMEBUFFER);
  4130. if (e !== t.FRAMEBUFFER_COMPLETE) throw new Error("Error binding framebuffer: " + xe(t, e));
  4131. }
  4132. function xe(t, e) {
  4133. switch (e) {
  4134. case t.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
  4135. return "FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
  4136. case t.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
  4137. return "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
  4138. case t.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
  4139. return "FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
  4140. case t.FRAMEBUFFER_UNSUPPORTED:
  4141. return "FRAMEBUFFER_UNSUPPORTED";
  4142. default:
  4143. return "unknown error " + e;
  4144. }
  4145. }
  4146. function be(t, e, n, r) {
  4147. var o = Kt(t, e, function () {
  4148. return n();
  4149. });
  4150. if (null == o) throw new Error(r);
  4151. return o;
  4152. }
  4153. function we(t, e) {
  4154. var n = t.MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1,
  4155. r = e + t.TEXTURE0;
  4156. if (r < t.TEXTURE0 || r > n) throw new Error("textureUnit must be in " + ("[gl.TEXTURE0, gl.TEXTURE" + n + "]") + ".");
  4157. }
  4158. function Ce(t, e) {
  4159. return void 0 === e && (e = 2), w(t.slice(0, t.length - e));
  4160. }
  4161. function Ee(t) {
  4162. if (0 === t.length) throw Error("Cannot get rows and columns of an empty shape array.");
  4163. return [t.length > 1 ? t[t.length - 2] : 1, t[t.length - 1]];
  4164. }
  4165. function Re(t) {
  4166. var e = [1, 1, 1];
  4167. return 0 === t.length || 1 === t.length && 1 === t[0] || (e = [Ce(t)].concat(Ee(t))), e;
  4168. }
  4169. function Ie(t, e) {
  4170. var n;
  4171. void 0 === e && (e = !1);
  4172. var r = a().getNumber("WEBGL_MAX_TEXTURE_SIZE");
  4173. if (e && (r *= 2, 1 === (t = t.map(function (e, n) {
  4174. return n >= t.length - 2 ? v(t[n]) : t[n];
  4175. })).length && (t = [2, t[0]])), 2 !== t.length) {
  4176. var o = T(t);
  4177. t = o.newShape;
  4178. }
  4179. var i = w(t);
  4180. if (t.length <= 1 && i <= r) return [1, i];
  4181. if (2 === t.length && t[0] <= r && t[1] <= r) return t;
  4182. if (3 === t.length && t[0] * t[1] <= r && t[2] <= r) return [t[0] * t[1], t[2]];
  4183. if (3 === t.length && t[0] <= r && t[1] * t[2] <= r) return [t[0], t[1] * t[2]];
  4184. if (4 === t.length && t[0] * t[1] * t[2] <= r && t[3] <= r) return [t[0] * t[1] * t[2], t[3]];
  4185. if (4 === t.length && t[0] <= r && t[1] * t[2] * t[3] <= r) return [t[0], t[1] * t[2] * t[3]];
  4186. if (e) {
  4187. var u = Ce(t),
  4188. s = 2,
  4189. c = 2;
  4190. return t.length && (s = (n = Ee(t))[0], c = n[1]), I(i = u * (s / 2) * (c / 2)).map(function (t) {
  4191. return 2 * t;
  4192. });
  4193. }
  4194. return I(i);
  4195. }
  4196. function ke(t) {
  4197. return t % 2 == 0;
  4198. }
  4199. function Se(t, e) {
  4200. if (C(t = t.slice(-2), e = e.slice(-2))) return !0;
  4201. if (!t.length || !e.length) return !0;
  4202. if (0 === t[0] || 0 === t[1] || 0 === e[0] || 0 === e[1]) return !0;
  4203. if (t.length !== e.length) {
  4204. var n = t.slice(-1)[0],
  4205. r = e.slice(-1)[0];
  4206. if (n === r) return !0;
  4207. if (ke(n) && ke(r) && (1 === t[0] || 1 === e[0])) return !0;
  4208. }
  4209. return t[1] === e[1] && ke(t[0]) && ke(e[0]);
  4210. }
  4211. function Ae(t) {
  4212. if (null == te) {
  4213. var e = Ut(t);
  4214. te = e.getParameter(e.MAX_TEXTURE_SIZE);
  4215. }
  4216. return te;
  4217. }
  4218. function De(t) {
  4219. if (null == ee) {
  4220. var e = Ut(t);
  4221. ee = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS);
  4222. }
  4223. return Math.min(16, ee);
  4224. }
  4225. function Te(t) {
  4226. if (0 === t) return 0;
  4227. var e = Ut(t);
  4228. return Ne(e, "EXT_disjoint_timer_query_webgl2") && 2 === t ? 2 : Ne(e, "EXT_disjoint_timer_query") ? 1 : 0;
  4229. }
  4230. function Ne(t, e) {
  4231. return null != t.getExtension(e);
  4232. }
  4233. function Fe(t) {
  4234. try {
  4235. if (null != Ut(t)) return !0;
  4236. } catch (t) {
  4237. return !1;
  4238. }
  4239. return !1;
  4240. }
  4241. function Oe(t) {
  4242. if (0 === t) return !1;
  4243. var e = Ut(t);
  4244. if (1 === t) {
  4245. if (!Ne(e, "OES_texture_float")) return !1;
  4246. } else if (!Ne(e, "EXT_color_buffer_float")) return !1;
  4247. return Me(e);
  4248. }
  4249. function _e(t) {
  4250. if (0 === t) return !1;
  4251. var e = Ut(t);
  4252. if (1 !== t) {
  4253. if (Ne(e, "EXT_color_buffer_float")) return Me(e);
  4254. if (Ne(e, "EXT_color_buffer_half_float")) {
  4255. var n = e.getExtension("EXT_color_buffer_half_float");
  4256. return function (t, e) {
  4257. var n = qt(t, e),
  4258. r = t.createTexture();
  4259. t.bindTexture(t.TEXTURE_2D, r);
  4260. t.texImage2D(t.TEXTURE_2D, 0, n.internalFormatHalfFloat, 1, 1, 0, n.textureFormatFloat, n.textureTypeHalfFloat, null);
  4261. var o = t.createFramebuffer();
  4262. t.bindFramebuffer(t.FRAMEBUFFER, o), t.framebufferTexture2D(t.FRAMEBUFFER, t.COLOR_ATTACHMENT0, t.TEXTURE_2D, r, 0);
  4263. var a = t.checkFramebufferStatus(t.FRAMEBUFFER) === t.FRAMEBUFFER_COMPLETE;
  4264. return t.bindTexture(t.TEXTURE_2D, null), t.bindFramebuffer(t.FRAMEBUFFER, null), t.deleteTexture(r), t.deleteFramebuffer(o), a;
  4265. }(e, n);
  4266. }
  4267. return !1;
  4268. }
  4269. return !!Ne(e, "OES_texture_float") && !!Ne(e, "WEBGL_color_buffer_float") && Me(e);
  4270. }
  4271. function Me(t) {
  4272. var e = qt(t),
  4273. n = t.createTexture();
  4274. t.bindTexture(t.TEXTURE_2D, n);
  4275. t.texImage2D(t.TEXTURE_2D, 0, e.internalFormatFloat, 1, 1, 0, e.textureFormatFloat, e.textureTypeFloat, null);
  4276. var r = t.createFramebuffer();
  4277. t.bindFramebuffer(t.FRAMEBUFFER, r), t.framebufferTexture2D(t.FRAMEBUFFER, t.COLOR_ATTACHMENT0, t.TEXTURE_2D, n, 0);
  4278. var o = t.checkFramebufferStatus(t.FRAMEBUFFER) === t.FRAMEBUFFER_COMPLETE;
  4279. return t.bindTexture(t.TEXTURE_2D, null), t.bindFramebuffer(t.FRAMEBUFFER, null), t.deleteTexture(n), t.deleteFramebuffer(r), o;
  4280. }
  4281. function Be(t) {
  4282. return 2 === t && null != Ut(t).fenceSync;
  4283. }
  4284. var Pe = Object.freeze({
  4285. callAndCheck: Kt,
  4286. canBeRepresented: $t,
  4287. getWebGLErrorMessage: Yt,
  4288. getExtensionOrThrow: Qt,
  4289. createVertexShader: Jt,
  4290. createFragmentShader: Zt,
  4291. createProgram: re,
  4292. linkProgram: oe,
  4293. validateProgram: ae,
  4294. createStaticVertexBuffer: ie,
  4295. createStaticIndexBuffer: ue,
  4296. getNumChannels: function () {
  4297. return 2 === a().getNumber("WEBGL_VERSION") ? 1 : 4;
  4298. },
  4299. createTexture: se,
  4300. validateTextureSize: ce,
  4301. createFramebuffer: le,
  4302. bindVertexBufferToProgramAttribute: he,
  4303. bindTextureUnit: fe,
  4304. unbindTextureUnit: function (t, e, n) {
  4305. we(t, n), Kt(t, e, function () {
  4306. return t.activeTexture(t.TEXTURE0 + n);
  4307. }), Kt(t, e, function () {
  4308. return t.bindTexture(t.TEXTURE_2D, null);
  4309. });
  4310. },
  4311. getProgramUniformLocationOrThrow: pe,
  4312. getProgramUniformLocation: de,
  4313. bindTextureToProgramUniformSampler: ve,
  4314. bindCanvasToFramebuffer: function (t, e) {
  4315. Kt(t, e, function () {
  4316. return t.bindFramebuffer(t.FRAMEBUFFER, null);
  4317. }), Kt(t, e, function () {
  4318. return t.viewport(0, 0, t.canvas.width, t.canvas.height);
  4319. }), Kt(t, e, function () {
  4320. return t.scissor(0, 0, t.canvas.width, t.canvas.height);
  4321. });
  4322. },
  4323. bindColorTextureToFramebuffer: me,
  4324. unbindColorTextureFromFramebuffer: ge,
  4325. validateFramebuffer: ye,
  4326. getFramebufferErrorMessage: xe,
  4327. getBatchDim: Ce,
  4328. getRowsCols: Ee,
  4329. getShapeAs3D: Re,
  4330. getTextureShapeFromLogicalShape: Ie,
  4331. isReshapeFree: Se,
  4332. getWebGLMaxTextureSize: Ae,
  4333. resetMaxTextureSize: function () {
  4334. te = null;
  4335. },
  4336. resetMaxTexturesInShader: function () {
  4337. ee = null;
  4338. },
  4339. getMaxTexturesInShader: De,
  4340. getWebGLDisjointQueryTimerVersion: Te,
  4341. hasExtension: Ne,
  4342. isWebGLVersionEnabled: Fe,
  4343. isCapableOfRenderingToFloatTexture: Oe,
  4344. isDownloadFloatTextureEnabled: _e,
  4345. isWebGLFenceEnabled: Be
  4346. }),
  4347. Le = a();
  4348. function We() {
  4349. a().set("PROD", !0);
  4350. }
  4351. function Ue() {
  4352. a().set("DEBUG", !0);
  4353. }
  4354. function Ve() {
  4355. a().set("DEPRECATION_WARNINGS_ENABLED", !1), console.warn("TensorFlow.js deprecation warnings have been disabled.");
  4356. }
  4357. function ze(t) {
  4358. a().getBool("DEPRECATION_WARNINGS_ENABLED") && console.warn(t + " You can disable deprecation warnings with tf.disableDeprecationWarnings().");
  4359. }
  4360. function Ge() {
  4361. Nt.disposeVariables();
  4362. }
  4363. function He() {
  4364. return Nt;
  4365. }
  4366. function qe() {
  4367. return Nt.memory();
  4368. }
  4369. function Ke(t) {
  4370. return Nt.profile(t);
  4371. }
  4372. function je(t, e) {
  4373. return Nt.tidy(t, e);
  4374. }
  4375. function Xe(t) {
  4376. kt(t).forEach(function (t) {
  4377. return t.dispose();
  4378. });
  4379. }
  4380. function $e(t) {
  4381. return Nt.keep(t);
  4382. }
  4383. function Ye(t) {
  4384. return Nt.time(t);
  4385. }
  4386. function Qe(t) {
  4387. return Nt.setBackend(t);
  4388. }
  4389. function Je() {
  4390. return Nt.ready();
  4391. }
  4392. function Ze() {
  4393. return Nt.backendName;
  4394. }
  4395. function tn(t) {
  4396. Nt.removeBackend(t);
  4397. }
  4398. function en(t) {
  4399. return Nt.findBackend(t);
  4400. }
  4401. function nn(t) {
  4402. return Nt.findBackendFactory(t);
  4403. }
  4404. function rn(t, e, n) {
  4405. return void 0 === n && (n = 1), Nt.registerBackend(t, e, n);
  4406. }
  4407. function on() {
  4408. return Nt.backend;
  4409. }
  4410. function an(t, e) {
  4411. a().setPlatform(t, e);
  4412. }
  4413. function un() {
  4414. for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];
  4415. a().getBool("IS_TEST") || console.warn.apply(console, t);
  4416. }
  4417. function sn(t, e) {
  4418. var n = t;
  4419. if (B(t)) return "string" === e ? [] : [t.length];
  4420. if (!Array.isArray(t)) return [];
  4421. for (var r = []; Array.isArray(n) || B(n) && "string" !== e;) r.push(n.length), n = n[0];
  4422. return Array.isArray(t) && a().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY") && function t(e, n, r) {
  4423. r = r || [];
  4424. if (!Array.isArray(e) && !B(e)) return void g(0 === n.length, function () {
  4425. return "Element arr[" + r.join("][") + "] is a primitive, but should be an array/TypedArray of " + n[0] + " elements";
  4426. });
  4427. g(n.length > 0, function () {
  4428. return "Element arr[" + r.join("][") + "] should be a primitive, but is an array of " + e.length + " elements";
  4429. });
  4430. g(e.length === n[0], function () {
  4431. return "Element arr[" + r.join("][") + "] should have " + n[0] + " elements, but has " + e.length + " elements";
  4432. });
  4433. var o = n.slice(1);
  4434. for (var a = 0; a < e.length; ++a) t(e[a], o, r.concat(a));
  4435. }(t, r, []), r;
  4436. }
  4437. function cn(t, e, n, r) {
  4438. if (null != t && ("numeric" !== t && t !== e || "numeric" === t && "string" === e)) throw new Error("Argument '" + n + "' passed to '" + r + "' must be " + t + " tensor, but got " + e + " tensor");
  4439. }
  4440. function ln(t, e, n, r) {
  4441. if (void 0 === r && (r = "numeric"), t instanceof dt) return cn(r, t.dtype, e, n), t;
  4442. var o = z(t);
  4443. if ("string" !== o && ["bool", "int32", "float32"].indexOf(r) >= 0 && (o = r), cn(r, o, e, n), null == t || !B(t) && !Array.isArray(t) && "number" != typeof t && "boolean" != typeof t && "string" != typeof t) {
  4444. var i = null == t ? "null" : t.constructor.name;
  4445. throw new Error("Argument '" + e + "' passed to '" + n + "' must be a Tensor or TensorLike, but got '" + i + "'");
  4446. }
  4447. var u = sn(t, o);
  4448. B(t) || Array.isArray(t) || (t = [t]);
  4449. var s = "string" !== o ? K(t, o, a().getBool("DEBUG")) : b(t, [], !0);
  4450. return Nt.makeTensor(s, u, o);
  4451. }
  4452. function hn(t, e, n, r) {
  4453. if (void 0 === r && (r = "numeric"), !Array.isArray(t)) throw new Error("Argument " + e + " passed to " + n + " must be a `Tensor[]` or `TensorLike[]`");
  4454. return t.map(function (t, r) {
  4455. return ln(t, e + "[" + r + "]", n);
  4456. }, r);
  4457. }
  4458. function fn(t, e) {
  4459. for (var n = 0; n < t.length; ++n) if (t[t.length - n - 1] !== e - 1 - n) return !1;
  4460. return !0;
  4461. }
  4462. function pn(t, e, n) {
  4463. for (var r = t.length + e.length, o = [], a = 0, i = 0, u = 0; u < r; u++) -1 === n.indexOf(u) ? o.push(t[a++]) : o.push(e[i++]);
  4464. return o;
  4465. }
  4466. function dn(t, e) {
  4467. for (var n = [], r = t.length, o = 0; o < r; o++) -1 === e.indexOf(o) && n.push(t[o]);
  4468. return [n, e.map(function (e) {
  4469. return t[e];
  4470. })];
  4471. }
  4472. function vn(t, e) {
  4473. return pn(t, e.map(function (t) {
  4474. return 1;
  4475. }), e);
  4476. }
  4477. function mn(t, e, n) {
  4478. g(fn(e, n), function () {
  4479. return t + " supports only inner-most axes for now. Got axes " + e + " and rank-" + n + " input.";
  4480. });
  4481. }
  4482. function gn(t, e) {
  4483. if (fn(t, e)) return null;
  4484. for (var n = [], r = 0; r < e; ++r) -1 === t.indexOf(r) && n.push(r);
  4485. return t.forEach(function (t) {
  4486. return n.push(t);
  4487. }), n;
  4488. }
  4489. function yn(t) {
  4490. return t.map(function (t, e) {
  4491. return [e, t];
  4492. }).sort(function (t, e) {
  4493. return t[1] - e[1];
  4494. }).map(function (t) {
  4495. return t[0];
  4496. });
  4497. }
  4498. function xn(t, e) {
  4499. for (var n = [], r = e - t; r < e; ++r) n.push(r);
  4500. return n;
  4501. }
  4502. function bn(t, e) {
  4503. var n = t[0].length;
  4504. t.forEach(function (t, e) {
  4505. g(t.length === n, function () {
  4506. return "Error in concat" + n + "D: rank of tensors[" + e + "] must be the same as the rank of the rest (" + n + ")";
  4507. });
  4508. }), g(e >= 0 && e < n, function () {
  4509. return "Error in concat" + n + "D: axis must be between 0 and " + (n - 1) + ".";
  4510. });
  4511. var r = t[0];
  4512. t.forEach(function (t, o) {
  4513. for (var a = 0; a < n; a++) g(a === e || t[a] === r[a], function () {
  4514. return "Error in concat" + n + "D: Shape of tensors[" + o + "] (" + t + ") does not match the shape of the rest (" + r + ") along the non-concatenated axis " + o + ".";
  4515. });
  4516. });
  4517. }
  4518. function wn(t, e) {
  4519. for (var n = t[0].slice(), r = 1; r < t.length; r++) n[e] += t[r][e];
  4520. return n;
  4521. }
  4522. function Cn(t) {
  4523. var e = Object.keys(t);
  4524. if (1 !== e.length) throw new Error("Please provide an object with a single key (operation name) mapping to a function. Got an object with " + e.length + " keys.");
  4525. var n = e[0],
  4526. r = t[n];
  4527. n.endsWith("_") && (n = n.substring(0, n.length - 1));
  4528. var o = function () {
  4529. for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];
  4530. Nt.startScope(n);
  4531. try {
  4532. var o = r.apply(void 0, t);
  4533. return o instanceof Promise && console.error("Cannot return a Promise inside of tidy."), Nt.endScope(o), o;
  4534. } catch (t) {
  4535. throw Nt.endScope(null), t;
  4536. }
  4537. };
  4538. return Object.defineProperty(o, "name", {
  4539. value: n,
  4540. configurable: !0
  4541. }), o;
  4542. }
  4543. Le.registerFlag("HAS_WEBGL", function () {
  4544. return Le.getNumber("WEBGL_VERSION") > 0;
  4545. }), Le.registerFlag("WEBGL_VERSION", function () {
  4546. return Fe(2) ? 2 : Fe(1) ? 1 : 0;
  4547. }), Le.registerFlag("WEBGL_BUFFER_SUPPORTED", function () {
  4548. return 2 === Le.get("WEBGL_VERSION");
  4549. }), Le.registerFlag("WEBGL_CPU_FORWARD", function () {
  4550. return !0;
  4551. }), Le.registerFlag("WEBGL_FORCE_F16_TEXTURES", function () {
  4552. return !1;
  4553. }), Le.registerFlag("WEBGL_PACK", function () {
  4554. return Le.getBool("HAS_WEBGL");
  4555. }), Le.registerFlag("WEBGL_PACK_NORMALIZATION", function () {
  4556. return Le.getBool("WEBGL_PACK");
  4557. }), Le.registerFlag("WEBGL_PACK_CLIP", function () {
  4558. return Le.getBool("WEBGL_PACK");
  4559. }), Le.registerFlag("WEBGL_PACK_DEPTHWISECONV", function () {
  4560. return !1;
  4561. }), Le.registerFlag("WEBGL_PACK_BINARY_OPERATIONS", function () {
  4562. return Le.getBool("WEBGL_PACK");
  4563. }), Le.registerFlag("WEBGL_PACK_UNARY_OPERATIONS", function () {
  4564. return Le.getBool("WEBGL_PACK");
  4565. }), Le.registerFlag("WEBGL_PACK_ARRAY_OPERATIONS", function () {
  4566. return Le.getBool("WEBGL_PACK");
  4567. }), Le.registerFlag("WEBGL_PACK_IMAGE_OPERATIONS", function () {
  4568. return Le.getBool("WEBGL_PACK");
  4569. }), Le.registerFlag("WEBGL_PACK_REDUCE", function () {
  4570. return Le.getBool("WEBGL_PACK");
  4571. }), Le.registerFlag("WEBGL_LAZILY_UNPACK", function () {
  4572. return Le.getBool("WEBGL_PACK");
  4573. }), Le.registerFlag("WEBGL_CONV_IM2COL", function () {
  4574. return Le.getBool("WEBGL_PACK");
  4575. }), Le.registerFlag("WEBGL_MAX_TEXTURE_SIZE", function () {
  4576. return Ae(Le.getNumber("WEBGL_VERSION"));
  4577. }), Le.registerFlag("WEBGL_MAX_TEXTURES_IN_SHADER", function () {
  4578. return De(Le.getNumber("WEBGL_VERSION"));
  4579. }), Le.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION", function () {
  4580. var t = Le.getNumber("WEBGL_VERSION");
  4581. return 0 === t ? 0 : Te(t);
  4582. }), Le.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE", function () {
  4583. return Le.getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") > 0 && (t = navigator.userAgent || navigator.vendor || window.opera, !(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0, 4))));
  4584. var t;
  4585. }), Le.registerFlag("WEBGL_RENDER_FLOAT32_CAPABLE", function () {
  4586. return Oe(Le.getNumber("WEBGL_VERSION"));
  4587. }), Le.registerFlag("WEBGL_RENDER_FLOAT32_ENABLED", function () {
  4588. return !Le.getBool("WEBGL_FORCE_F16_TEXTURES") && Le.getBool("WEBGL_RENDER_FLOAT32_CAPABLE");
  4589. }), Le.registerFlag("WEBGL_DOWNLOAD_FLOAT_ENABLED", function () {
  4590. return _e(Le.getNumber("WEBGL_VERSION"));
  4591. }), Le.registerFlag("WEBGL_FENCE_API_ENABLED", function () {
  4592. return Be(Le.getNumber("WEBGL_VERSION"));
  4593. }), Le.registerFlag("WEBGL_SIZE_UPLOAD_UNIFORM", function () {
  4594. return Le.getBool("WEBGL_RENDER_FLOAT32_ENABLED") ? 4 : 0;
  4595. }), pt = ze;
  4596. var En = Cn({
  4597. complex_: function (t, e) {
  4598. var n = ln(t, "real", "complex"),
  4599. r = ln(e, "imag", "complex");
  4600. return y(n.shape, r.shape, "real and imag shapes, " + n.shape + " and " + r.shape + ", must match in call to tf.complex()."), Nt.runKernelFunc(function (t) {
  4601. return t.complex(n, r);
  4602. }, {
  4603. $real: n,
  4604. $imag: r
  4605. });
  4606. }
  4607. }),
  4608. Rn = Cn({
  4609. real_: function (t) {
  4610. var e = ln(t, "input", "real");
  4611. return Nt.runKernelFunc(function (t) {
  4612. return t.real(e);
  4613. }, {
  4614. $input: e
  4615. });
  4616. }
  4617. }),
  4618. In = Cn({
  4619. imag_: function (t) {
  4620. var e = ln(t, "input", "imag");
  4621. return Nt.runKernelFunc(function (t) {
  4622. return t.imag(e);
  4623. }, {
  4624. $input: e
  4625. });
  4626. }
  4627. });
  4628. exports.imag = In;
  4629. exports.real = Rn;
  4630. exports.complex = En;
  4631. function kn(t, e, n) {
  4632. return Sn(t, e, sn(t, n), n);
  4633. }
  4634. function Sn(t, e, n, r) {
  4635. if (null == r && (r = z(t)), "complex64" === r) throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).");
  4636. if (!B(t) && !Array.isArray(t) && "number" != typeof t && "boolean" != typeof t && "string" != typeof t) throw new Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray");
  4637. if (null != e) {
  4638. Q(e);
  4639. var o = w(e),
  4640. i = w(n);
  4641. g(o === i, function () {
  4642. return "Based on the provided shape, [" + e + "], the tensor should have " + o + " values but has " + i;
  4643. });
  4644. for (var u = 0; u < n.length; ++u) {
  4645. var s = n[u],
  4646. c = u !== n.length - 1 || s !== w(e.slice(u));
  4647. g(n[u] === e[u] || !c, function () {
  4648. return "Error creating a new Tensor. Inferred shape (" + n + ") does not match the provided shape (" + e + "). ";
  4649. });
  4650. }
  4651. }
  4652. return B(t) || Array.isArray(t) || (t = [t]), e = e || n, t = "string" !== r ? K(t, r, a().getBool("DEBUG")) : b(t, [], !0), Nt.makeTensor(t, e, r);
  4653. }
  4654. function An(t, e) {
  4655. if ((B(t) && "string" !== e || Array.isArray(t)) && "complex64" !== e) throw new Error("Error creating a new Scalar: value must be a primitive (number|boolean|string)");
  4656. if ("string" === e && B(t) && !(t instanceof Uint8Array)) throw new Error("When making a scalar from encoded string, the value must be `Uint8Array`.");
  4657. return Sn(t, [], [], e);
  4658. }
  4659. function Dn(t, e) {
  4660. x(t);
  4661. var n = sn(t, e);
  4662. if (1 !== n.length) throw new Error("tensor1d() requires values to be a flat/TypedArray");
  4663. return Sn(t, null, n, e);
  4664. }
  4665. function Tn(t, e, n) {
  4666. if (x(t), null != e && 2 !== e.length) throw new Error("tensor2d() requires shape to have two numbers");
  4667. var r = sn(t, n);
  4668. if (2 !== r.length && 1 !== r.length) throw new Error("tensor2d() requires values to be number[][] or flat/TypedArray");
  4669. if (1 === r.length && null == e) throw new Error("tensor2d() requires shape to be provided when `values` are a flat/TypedArray");
  4670. return Sn(t, e, r, n);
  4671. }
  4672. function Nn(t, e, n) {
  4673. if (x(t), null != e && 3 !== e.length) throw new Error("tensor3d() requires shape to have three numbers");
  4674. var r = sn(t, n);
  4675. if (3 !== r.length && 1 !== r.length) throw new Error("tensor3d() requires values to be number[][][] or flat/TypedArray");
  4676. if (1 === r.length && null == e) throw new Error("tensor3d() requires shape to be provided when `values` are a flat array");
  4677. return Sn(t, e, r, n);
  4678. }
  4679. function Fn(t, e, n) {
  4680. if (x(t), null != e && 4 !== e.length) throw new Error("tensor4d() requires shape to have four numbers");
  4681. var r = sn(t, n);
  4682. if (4 !== r.length && 1 !== r.length) throw new Error("tensor4d() requires values to be number[][][][] or flat/TypedArray");
  4683. if (1 === r.length && null == e) throw new Error("tensor4d() requires shape to be provided when `values` are a flat array");
  4684. return Sn(t, e, r, n);
  4685. }
  4686. function On(t, e, n) {
  4687. if (x(t), null != e && 5 !== e.length) throw new Error("tensor5d() requires shape to have five numbers");
  4688. var r = sn(t, n);
  4689. if (5 !== r.length && 1 !== r.length) throw new Error("tensor5d() requires values to be number[][][][][] or flat/TypedArray");
  4690. if (1 === r.length && null == e) throw new Error("tensor5d() requires shape to be provided when `values` are a flat array");
  4691. return Sn(t, e, r, n);
  4692. }
  4693. function _n(t, e, n) {
  4694. if (x(t), null != e && 6 !== e.length) throw new Error("tensor6d() requires shape to have six numbers");
  4695. var r = sn(t, n);
  4696. if (6 !== r.length && 1 !== r.length) throw new Error("tensor6d() requires values to be number[][][][][][] or flat/TypedArray");
  4697. if (1 === r.length && null == e) throw new Error("tensor6d() requires shape to be provided when `values` are a flat array");
  4698. return Sn(t, e = e || r, r, n);
  4699. }
  4700. function Mn(t, e, n, r) {
  4701. return void 0 === e && (e = !0), Nt.makeVariable(t, e, n, r);
  4702. }
  4703. function Bn(t, e) {
  4704. if (void 0 === e && (e = "float32"), "complex64" === e) {
  4705. var n = Bn(t, "float32"),
  4706. r = Pn(t, "float32");
  4707. return En(n, r);
  4708. }
  4709. var o = X(w(t), e);
  4710. return Nt.makeTensor(o, t, e);
  4711. }
  4712. function Pn(t, e) {
  4713. if (void 0 === e && (e = "float32"), "complex64" === e) {
  4714. var n = Pn(t, "float32"),
  4715. r = Pn(t, "float32");
  4716. return En(n, r);
  4717. }
  4718. var o = $(w(t), e);
  4719. return Nt.makeTensor(o, t, e);
  4720. }
  4721. function Ln(t, e, n) {
  4722. return Nt.runKernelFunc(function (r) {
  4723. return r.fill(t, e, n);
  4724. }, {});
  4725. }
  4726. function Wn(t, e, n) {
  4727. if (n <= 0) throw new Error("The number of values should be positive.");
  4728. return Nt.runKernelFunc(function (r) {
  4729. return r.linspace(t, e, n);
  4730. }, {});
  4731. }
  4732. function Un(t, e, n, r) {
  4733. if (void 0 === n && (n = 1), void 0 === r && (r = "float32"), 0 === n) throw new Error("Cannot have a step of zero");
  4734. if (t === e || t < e && n < 0 || e < t && n > 1) return Pn([0], r);
  4735. var o = $(Math.abs(Math.ceil((e - t) / n)), r);
  4736. e < t && 1 === n && (n = -1), o[0] = t;
  4737. for (var a = 1; a < o.length; a++) o[a] = o[a - 1] + n;
  4738. return Dn(o, r);
  4739. }
  4740. var Vn = Cn({
  4741. onesLike_: function (t) {
  4742. var e = ln(t, "x", "onesLike");
  4743. if ("complex64" === e.dtype) {
  4744. var n = Vn(Rn(e)),
  4745. r = zn(In(e));
  4746. return En(n, r);
  4747. }
  4748. return Nt.runKernelFunc(function (t) {
  4749. return t.onesLike(e);
  4750. }, {
  4751. $x: e
  4752. }, function (t, e) {
  4753. return {
  4754. $x: function () {
  4755. return zn(t);
  4756. }
  4757. };
  4758. });
  4759. }
  4760. }),
  4761. zn = Cn({
  4762. zerosLike_: function (t) {
  4763. var e = ln(t, "x", "zerosLike");
  4764. return Nt.runKernelFunc(function (t) {
  4765. return t.zerosLike(e);
  4766. }, {
  4767. $x: e
  4768. }, function (t, e) {
  4769. return {
  4770. $x: function () {
  4771. return zn(t);
  4772. }
  4773. };
  4774. });
  4775. }
  4776. });
  4777. exports.zerosLike = zn;
  4778. exports.onesLike = Vn;
  4779. var Gn = Cn({
  4780. concat_: function (t, e) {
  4781. void 0 === e && (e = 0), g(t.length >= 1, function () {
  4782. return "Pass at least one tensor to concat";
  4783. });
  4784. var n = hn(t, "tensors", "concat");
  4785. "complex64" === n[0].dtype && n.forEach(function (t) {
  4786. if ("complex64" !== t.dtype) throw new Error("Cannot concatenate complex64 tensors with a tensor\n with dtype " + t.dtype + ". ");
  4787. }), e = D(e, n[0].shape)[0];
  4788. var r = wn(n.map(function (t) {
  4789. return t.shape;
  4790. }), e);
  4791. if (0 === w(r)) return kn([], r);
  4792. if (1 === (n = n.filter(function (t) {
  4793. return t.size > 0;
  4794. })).length) return n[0];
  4795. var o = n.map(function (t) {
  4796. return t.shape;
  4797. });
  4798. bn(o, e);
  4799. var a = n;
  4800. return Nt.runKernelFunc(function (t) {
  4801. return t.concat(n, e);
  4802. }, a, function (t) {
  4803. var n = o.map(function (t) {
  4804. return t[e];
  4805. });
  4806. return Xn(t, n, e).map(function (t) {
  4807. return function () {
  4808. return t;
  4809. };
  4810. });
  4811. });
  4812. }
  4813. }),
  4814. Hn = Cn({
  4815. concat1d_: function (t) {
  4816. return Gn(t, 0);
  4817. }
  4818. }),
  4819. qn = Cn({
  4820. concat2d_: function (t, e) {
  4821. return Gn(t, e);
  4822. }
  4823. }),
  4824. Kn = Cn({
  4825. concat3d_: function (t, e) {
  4826. return Gn(t, e);
  4827. }
  4828. }),
  4829. jn = Cn({
  4830. concat4d_: function (t, e) {
  4831. return Gn(t, e);
  4832. }
  4833. }),
  4834. Xn = Cn({
  4835. split_: function (t, e, n) {
  4836. void 0 === n && (n = 0);
  4837. var r,
  4838. o = ln(t, "x", "split");
  4839. return n = D(n, o.shape)[0], "number" == typeof e ? (g(o.shape[n] % e == 0, function () {
  4840. return "Number of splits must evenly divide the axis.";
  4841. }), r = new Array(e).fill(o.shape[n] / e)) : (g(o.shape[n] === e.reduce(function (t, e) {
  4842. return t + e;
  4843. }), function () {
  4844. return "The sum of sizes must match the size of the axis dimension.";
  4845. }), r = e), Nt.runKernelFunc(function (t) {
  4846. return t.split(o, r, n);
  4847. }, {
  4848. $x: o
  4849. }, function (t) {
  4850. return {
  4851. $x: function () {
  4852. return Gn(t, n);
  4853. }
  4854. };
  4855. });
  4856. }
  4857. });
  4858. exports.split = Xn;
  4859. exports.concat4d = jn;
  4860. exports.concat3d = Kn;
  4861. exports.concat2d = qn;
  4862. exports.concat1d = Hn;
  4863. exports.concat = Gn;
  4864. "undefined" != typeof globalThis ? globalThis : "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self && self;
  4865. function $n(t, e) {
  4866. return t(e = {
  4867. exports: {}
  4868. }, e.exports), e.exports;
  4869. }
  4870. var Yn = $n(function (t) {
  4871. !function (t, e, n) {
  4872. function r(t) {
  4873. var e,
  4874. n = this,
  4875. r = (e = 4022871197, function (t) {
  4876. t = t.toString();
  4877. for (var n = 0; n < t.length; n++) {
  4878. var r = .02519603282416938 * (e += t.charCodeAt(n));
  4879. r -= e = r >>> 0, e = (r *= e) >>> 0, e += 4294967296 * (r -= e);
  4880. }
  4881. return 2.3283064365386963e-10 * (e >>> 0);
  4882. });
  4883. n.next = function () {
  4884. var t = 2091639 * n.s0 + 2.3283064365386963e-10 * n.c;
  4885. return n.s0 = n.s1, n.s1 = n.s2, n.s2 = t - (n.c = 0 | t);
  4886. }, n.c = 1, n.s0 = r(" "), n.s1 = r(" "), n.s2 = r(" "), n.s0 -= r(t), n.s0 < 0 && (n.s0 += 1), n.s1 -= r(t), n.s1 < 0 && (n.s1 += 1), n.s2 -= r(t), n.s2 < 0 && (n.s2 += 1), r = null;
  4887. }
  4888. function o(t, e) {
  4889. return e.c = t.c, e.s0 = t.s0, e.s1 = t.s1, e.s2 = t.s2, e;
  4890. }
  4891. function a(t, e) {
  4892. var n = new r(t),
  4893. a = e && e.state,
  4894. i = n.next;
  4895. return i.int32 = function () {
  4896. return 4294967296 * n.next() | 0;
  4897. }, i.double = function () {
  4898. return i() + 1.1102230246251565e-16 * (2097152 * i() | 0);
  4899. }, i.quick = i, a && ("object" == typeof a && o(a, n), i.state = function () {
  4900. return o(n, {});
  4901. }), i;
  4902. }
  4903. e && e.exports ? e.exports = a : n && n.amd ? n(function () {
  4904. return a;
  4905. }) : this.alea = a;
  4906. }(0, t, !1);
  4907. }),
  4908. Qn = $n(function (t) {
  4909. !function (t, e, n) {
  4910. function r(t) {
  4911. var e = this,
  4912. n = "";
  4913. e.x = 0, e.y = 0, e.z = 0, e.w = 0, e.next = function () {
  4914. var t = e.x ^ e.x << 11;
  4915. return e.x = e.y, e.y = e.z, e.z = e.w, e.w ^= e.w >>> 19 ^ t ^ t >>> 8;
  4916. }, t === (0 | t) ? e.x = t : n += t;
  4917. for (var r = 0; r < n.length + 64; r++) e.x ^= 0 | n.charCodeAt(r), e.next();
  4918. }
  4919. function o(t, e) {
  4920. return e.x = t.x, e.y = t.y, e.z = t.z, e.w = t.w, e;
  4921. }
  4922. function a(t, e) {
  4923. var n = new r(t),
  4924. a = e && e.state,
  4925. i = function () {
  4926. return (n.next() >>> 0) / 4294967296;
  4927. };
  4928. return i.double = function () {
  4929. do {
  4930. var t = ((n.next() >>> 11) + (n.next() >>> 0) / 4294967296) / (1 << 21);
  4931. } while (0 === t);
  4932. return t;
  4933. }, i.int32 = n.next, i.quick = i, a && ("object" == typeof a && o(a, n), i.state = function () {
  4934. return o(n, {});
  4935. }), i;
  4936. }
  4937. e && e.exports ? e.exports = a : n && n.amd ? n(function () {
  4938. return a;
  4939. }) : this.xor128 = a;
  4940. }(0, t, !1);
  4941. }),
  4942. Jn = $n(function (t) {
  4943. !function (t, e, n) {
  4944. function r(t) {
  4945. var e = this,
  4946. n = "";
  4947. e.next = function () {
  4948. var t = e.x ^ e.x >>> 2;
  4949. return e.x = e.y, e.y = e.z, e.z = e.w, e.w = e.v, (e.d = e.d + 362437 | 0) + (e.v = e.v ^ e.v << 4 ^ t ^ t << 1) | 0;
  4950. }, e.x = 0, e.y = 0, e.z = 0, e.w = 0, e.v = 0, t === (0 | t) ? e.x = t : n += t;
  4951. for (var r = 0; r < n.length + 64; r++) e.x ^= 0 | n.charCodeAt(r), r == n.length && (e.d = e.x << 10 ^ e.x >>> 4), e.next();
  4952. }
  4953. function o(t, e) {
  4954. return e.x = t.x, e.y = t.y, e.z = t.z, e.w = t.w, e.v = t.v, e.d = t.d, e;
  4955. }
  4956. function a(t, e) {
  4957. var n = new r(t),
  4958. a = e && e.state,
  4959. i = function () {
  4960. return (n.next() >>> 0) / 4294967296;
  4961. };
  4962. return i.double = function () {
  4963. do {
  4964. var t = ((n.next() >>> 11) + (n.next() >>> 0) / 4294967296) / (1 << 21);
  4965. } while (0 === t);
  4966. return t;
  4967. }, i.int32 = n.next, i.quick = i, a && ("object" == typeof a && o(a, n), i.state = function () {
  4968. return o(n, {});
  4969. }), i;
  4970. }
  4971. e && e.exports ? e.exports = a : n && n.amd ? n(function () {
  4972. return a;
  4973. }) : this.xorwow = a;
  4974. }(0, t, !1);
  4975. }),
  4976. Zn = $n(function (t) {
  4977. !function (t, e, n) {
  4978. function r(t) {
  4979. var e = this;
  4980. e.next = function () {
  4981. var t,
  4982. n,
  4983. r = e.x,
  4984. o = e.i;
  4985. return t = r[o], n = (t ^= t >>> 7) ^ t << 24, n ^= (t = r[o + 1 & 7]) ^ t >>> 10, n ^= (t = r[o + 3 & 7]) ^ t >>> 3, n ^= (t = r[o + 4 & 7]) ^ t << 7, t = r[o + 7 & 7], n ^= (t ^= t << 13) ^ t << 9, r[o] = n, e.i = o + 1 & 7, n;
  4986. }, function (t, e) {
  4987. var n,
  4988. r = [];
  4989. if (e === (0 | e)) r[0] = e; else for (e = "" + e, n = 0; n < e.length; ++n) r[7 & n] = r[7 & n] << 15 ^ e.charCodeAt(n) + r[n + 1 & 7] << 13;
  4990. for (; r.length < 8;) r.push(0);
  4991. for (n = 0; n < 8 && 0 === r[n]; ++n);
  4992. for (8 == n ? r[7] = -1 : r[n], t.x = r, t.i = 0, n = 256; n > 0; --n) t.next();
  4993. }(e, t);
  4994. }
  4995. function o(t, e) {
  4996. return e.x = t.x.slice(), e.i = t.i, e;
  4997. }
  4998. function a(t, e) {
  4999. null == t && (t = +new Date());
  5000. var n = new r(t),
  5001. a = e && e.state,
  5002. i = function () {
  5003. return (n.next() >>> 0) / 4294967296;
  5004. };
  5005. return i.double = function () {
  5006. do {
  5007. var t = ((n.next() >>> 11) + (n.next() >>> 0) / 4294967296) / (1 << 21);
  5008. } while (0 === t);
  5009. return t;
  5010. }, i.int32 = n.next, i.quick = i, a && (a.x && o(a, n), i.state = function () {
  5011. return o(n, {});
  5012. }), i;
  5013. }
  5014. e && e.exports ? e.exports = a : n && n.amd ? n(function () {
  5015. return a;
  5016. }) : this.xorshift7 = a;
  5017. }(0, t, !1);
  5018. }),
  5019. tr = $n(function (t) {
  5020. !function (t, e, n) {
  5021. function r(t) {
  5022. var e = this;
  5023. e.next = function () {
  5024. var t,
  5025. n,
  5026. r = e.w,
  5027. o = e.X,
  5028. a = e.i;
  5029. return e.w = r = r + 1640531527 | 0, n = o[a + 34 & 127], t = o[a = a + 1 & 127], n ^= n << 13, t ^= t << 17, n ^= n >>> 15, t ^= t >>> 12, n = o[a] = n ^ t, e.i = a, n + (r ^ r >>> 16) | 0;
  5030. }, function (t, e) {
  5031. var n,
  5032. r,
  5033. o,
  5034. a,
  5035. i,
  5036. u = [],
  5037. s = 128;
  5038. for (e === (0 | e) ? (r = e, e = null) : (e += "\0", r = 0, s = Math.max(s, e.length)), o = 0, a = -32; a < s; ++a) e && (r ^= e.charCodeAt((a + 32) % e.length)), 0 === a && (i = r), r ^= r << 10, r ^= r >>> 15, r ^= r << 4, r ^= r >>> 13, a >= 0 && (i = i + 1640531527 | 0, o = 0 == (n = u[127 & a] ^= r + i) ? o + 1 : 0);
  5039. for (o >= 128 && (u[127 & (e && e.length || 0)] = -1), o = 127, a = 512; a > 0; --a) r = u[o + 34 & 127], n = u[o = o + 1 & 127], r ^= r << 13, n ^= n << 17, r ^= r >>> 15, n ^= n >>> 12, u[o] = r ^ n;
  5040. t.w = i, t.X = u, t.i = o;
  5041. }(e, t);
  5042. }
  5043. function o(t, e) {
  5044. return e.i = t.i, e.w = t.w, e.X = t.X.slice(), e;
  5045. }
  5046. function a(t, e) {
  5047. null == t && (t = +new Date());
  5048. var n = new r(t),
  5049. a = e && e.state,
  5050. i = function () {
  5051. return (n.next() >>> 0) / 4294967296;
  5052. };
  5053. return i.double = function () {
  5054. do {
  5055. var t = ((n.next() >>> 11) + (n.next() >>> 0) / 4294967296) / (1 << 21);
  5056. } while (0 === t);
  5057. return t;
  5058. }, i.int32 = n.next, i.quick = i, a && (a.X && o(a, n), i.state = function () {
  5059. return o(n, {});
  5060. }), i;
  5061. }
  5062. e && e.exports ? e.exports = a : n && n.amd ? n(function () {
  5063. return a;
  5064. }) : this.xor4096 = a;
  5065. }(0, t, !1);
  5066. }),
  5067. er = $n(function (t) {
  5068. !function (t, e, n) {
  5069. function r(t) {
  5070. var e = this,
  5071. n = "";
  5072. e.next = function () {
  5073. var t = e.b,
  5074. n = e.c,
  5075. r = e.d,
  5076. o = e.a;
  5077. return t = t << 25 ^ t >>> 7 ^ n, n = n - r | 0, r = r << 24 ^ r >>> 8 ^ o, o = o - t | 0, e.b = t = t << 20 ^ t >>> 12 ^ n, e.c = n = n - r | 0, e.d = r << 16 ^ n >>> 16 ^ o, e.a = o - t | 0;
  5078. }, e.a = 0, e.b = 0, e.c = -1640531527, e.d = 1367130551, t === Math.floor(t) ? (e.a = t / 4294967296 | 0, e.b = 0 | t) : n += t;
  5079. for (var r = 0; r < n.length + 20; r++) e.b ^= 0 | n.charCodeAt(r), e.next();
  5080. }
  5081. function o(t, e) {
  5082. return e.a = t.a, e.b = t.b, e.c = t.c, e.d = t.d, e;
  5083. }
  5084. function a(t, e) {
  5085. var n = new r(t),
  5086. a = e && e.state,
  5087. i = function () {
  5088. return (n.next() >>> 0) / 4294967296;
  5089. };
  5090. return i.double = function () {
  5091. do {
  5092. var t = ((n.next() >>> 11) + (n.next() >>> 0) / 4294967296) / (1 << 21);
  5093. } while (0 === t);
  5094. return t;
  5095. }, i.int32 = n.next, i.quick = i, a && ("object" == typeof a && o(a, n), i.state = function () {
  5096. return o(n, {});
  5097. }), i;
  5098. }
  5099. e && e.exports ? e.exports = a : n && n.amd ? n(function () {
  5100. return a;
  5101. }) : this.tychei = a;
  5102. }(0, t, !1);
  5103. }),
  5104. nr = $n(function (t) {
  5105. !function (e, n) {
  5106. var r,
  5107. o = this,
  5108. a = 256,
  5109. i = 6,
  5110. u = "random",
  5111. s = n.pow(a, i),
  5112. c = n.pow(2, 52),
  5113. l = 2 * c,
  5114. h = a - 1;
  5115. function f(t, h, f) {
  5116. var g = [],
  5117. y = v(function t(e, n) {
  5118. var r,
  5119. o = [],
  5120. a = typeof e;
  5121. if (n && "object" == a) for (r in e) try {
  5122. o.push(t(e[r], n - 1));
  5123. } catch (t) { }
  5124. return o.length ? o : "string" == a ? e : e + "\0";
  5125. }((h = 1 == h ? {
  5126. entropy: !0
  5127. } : h || {}).entropy ? [t, m(e)] : null == t ? function () {
  5128. try {
  5129. var t;
  5130. return r && (t = r.randomBytes) ? t = t(a) : (t = new Uint8Array(a), (o.crypto || o.msCrypto).getRandomValues(t)), m(t);
  5131. } catch (t) {
  5132. var n = o.navigator,
  5133. i = n && n.plugins;
  5134. return [+new Date(), o, i, o.screen, m(e)];
  5135. }
  5136. }() : t, 3), g),
  5137. x = new p(g),
  5138. b = function () {
  5139. for (var t = x.g(i), e = s, n = 0; t < c;) t = (t + n) * a, e *= a, n = x.g(1);
  5140. for (; t >= l;) t /= 2, e /= 2, n >>>= 1;
  5141. return (t + n) / e;
  5142. };
  5143. return b.int32 = function () {
  5144. return 0 | x.g(4);
  5145. }, b.quick = function () {
  5146. return x.g(4) / 4294967296;
  5147. }, b.double = b, v(m(x.S), e), (h.pass || f || function (t, e, r, o) {
  5148. return o && (o.S && d(o, x), t.state = function () {
  5149. return d(x, {});
  5150. }), r ? (n[u] = t, e) : t;
  5151. })(b, y, "global" in h ? h.global : this == n, h.state);
  5152. }
  5153. function p(t) {
  5154. var e,
  5155. n = t.length,
  5156. r = this,
  5157. o = 0,
  5158. i = r.i = r.j = 0,
  5159. u = r.S = [];
  5160. for (n || (t = [n++]); o < a;) u[o] = o++;
  5161. for (o = 0; o < a; o++) u[o] = u[i = h & i + t[o % n] + (e = u[o])], u[i] = e;
  5162. (r.g = function (t) {
  5163. for (var e, n = 0, o = r.i, i = r.j, u = r.S; t--;) e = u[o = h & o + 1], n = n * a + u[h & (u[o] = u[i = h & i + e]) + (u[i] = e)];
  5164. return r.i = o, r.j = i, n;
  5165. })(a);
  5166. }
  5167. function d(t, e) {
  5168. return e.i = t.i, e.j = t.j, e.S = t.S.slice(), e;
  5169. }
  5170. function v(t, e) {
  5171. for (var n, r = t + "", o = 0; o < r.length;) e[h & o] = h & (n ^= 19 * e[h & o]) + r.charCodeAt(o++);
  5172. return m(e);
  5173. }
  5174. function m(t) {
  5175. return String.fromCharCode.apply(0, t);
  5176. }
  5177. if (n["seed" + u] = f, v(n.random(), e), t.exports) {
  5178. t.exports = f;
  5179. try {
  5180. r = require("crypto");
  5181. } catch (t) { }
  5182. }
  5183. }([], Math);
  5184. });
  5185. nr.alea = Yn, nr.xor128 = Qn, nr.xorwow = Jn, nr.xorshift7 = Zn, nr.xor4096 = tr, nr.tychei = er;
  5186. var rr = nr.alea,
  5187. or = function () {
  5188. function t(t, e, n, r, o) {
  5189. this.mean = t, this.stdDev = e, this.dtype = n, this.nextVal = NaN, this.truncated = r, this.truncated && (this.upper = this.mean + 2 * this.stdDev, this.lower = this.mean - 2 * this.stdDev);
  5190. var a = o || Math.random();
  5191. this.random = rr(a.toString());
  5192. }
  5193. return t.prototype.nextValue = function () {
  5194. if (!isNaN(this.nextVal)) {
  5195. var t = this.nextVal;
  5196. return this.nextVal = NaN, t;
  5197. }
  5198. for (var e, n, r = !1; !r;) {
  5199. var o = void 0,
  5200. a = void 0,
  5201. i = void 0;
  5202. do {
  5203. i = (o = 2 * this.random() - 1) * o + (a = 2 * this.random() - 1) * a;
  5204. } while (i >= 1 || 0 === i);
  5205. var u = Math.sqrt(-2 * Math.log(i) / i);
  5206. e = this.mean + this.stdDev * o * u, n = this.mean + this.stdDev * a * u, this.truncated && !this.isValidTruncated(e) || (r = !0);
  5207. }
  5208. return this.truncated && !this.isValidTruncated(n) || (this.nextVal = this.convertValue(n)), this.convertValue(e);
  5209. }, t.prototype.convertValue = function (t) {
  5210. return null == this.dtype || "float32" === this.dtype ? t : Math.round(t);
  5211. }, t.prototype.isValidTruncated = function (t) {
  5212. return t <= this.upper && t >= this.lower;
  5213. }, t;
  5214. }(),
  5215. ar = function () {
  5216. function t(t, e, n, r) {
  5217. this.alpha = t, this.beta = 1 / e, this.dtype = n;
  5218. var o = r || Math.random();
  5219. this.randu = rr(o.toString()), this.randn = new or(0, 1, n, !1, this.randu()), this.d = t < 1 ? t + 2 / 3 : t - 1 / 3, this.c = 1 / Math.sqrt(9 * this.d);
  5220. }
  5221. return t.prototype.nextValue = function () {
  5222. for (var t, e, n, r, o, a; ;) {
  5223. do {
  5224. r = this.randn.nextValue(), a = 1 + this.c * r;
  5225. } while (a <= 0);
  5226. if (a *= a * a, e = 1 - .331 * (t = r * r) * t, n = .5 * t + this.d * (1 - a + Math.log(a)), (o = this.randu()) < e || Math.log(o) < n) break;
  5227. }
  5228. return a = 1 / this.beta * this.d * a, this.alpha < 1 && (a *= Math.pow(this.randu(), 1 / this.alpha)), this.convertValue(a);
  5229. }, t.prototype.convertValue = function (t) {
  5230. return "float32" === this.dtype ? t : Math.round(t);
  5231. }, t;
  5232. }(),
  5233. ir = function () {
  5234. function t(t, e, n, r) {
  5235. var o = this;
  5236. if (void 0 === t && (t = 0), void 0 === e && (e = 1), this.canReturnFloat = function () {
  5237. return null == o.dtype || "float32" === o.dtype;
  5238. }, this.min = t, this.range = e - t, this.dtype = n, null == r && (r = Math.random()), "number" == typeof r && (r = r.toString()), !this.canReturnFloat() && this.range <= 1) throw new Error("The difference between " + t + " - " + e + " <= 1 and dtype is not float");
  5239. this.random = rr(r);
  5240. }
  5241. return t.prototype.convertValue = function (t) {
  5242. return this.canReturnFloat() ? t : Math.round(t);
  5243. }, t.prototype.nextValue = function () {
  5244. return this.convertValue(this.min + this.range * this.random());
  5245. }, t;
  5246. }();
  5247. function ur(t, e, n) {
  5248. return void 0 === e && (e = "float32"), e = e || "float32", Q(t), new lt(t, e, n);
  5249. }
  5250. function sr(t, e) {
  5251. void 0 === e && (e = !1), console.log(t.toString(e));
  5252. }
  5253. var cr = Cn({
  5254. batchToSpaceND_: function (t, e, n) {
  5255. var r = ln(t, "x", "batchToSpaceND"),
  5256. o = e.reduce(function (t, e) {
  5257. return t * e;
  5258. });
  5259. return g(r.rank >= 1 + e.length, function () {
  5260. return "input rank is " + r.rank + " but should be > than blockShape.length " + e.length;
  5261. }), g(n.length === e.length, function () {
  5262. return "crops.length is " + n.length + " but should be equal to blockShape.length " + e.length;
  5263. }), g(r.shape[0] % o == 0, function () {
  5264. return "input tensor batch is " + r.shape[0] + " but is not divisible by the product of the elements of blockShape " + e.join(" * ") + " === " + o;
  5265. }), Nt.runKernelFunc(function (t) {
  5266. return t.batchToSpaceND(r, e, n);
  5267. }, {
  5268. $x: r
  5269. }, function (t) {
  5270. return {
  5271. $x: function () {
  5272. return t.spaceToBatchND(e, n);
  5273. }
  5274. };
  5275. });
  5276. }
  5277. }),
  5278. lr = Cn({
  5279. cast_: function (t, e) {
  5280. var n = ln(t, "x", "cast");
  5281. if (!_(e)) throw new Error("Failed to cast to unknown dtype " + e);
  5282. if ("string" === e && "string" !== n.dtype || "string" !== e && "string" === n.dtype) throw new Error("Only strings can be casted to strings");
  5283. var r = {
  5284. dtype: e
  5285. };
  5286. return Nt.runKernelFunc(function (t) {
  5287. return t.cast(n, e);
  5288. }, {
  5289. x: n
  5290. }, function (t) {
  5291. return {
  5292. x: function () {
  5293. return t.clone();
  5294. }
  5295. };
  5296. }, "Cast", r);
  5297. }
  5298. }),
  5299. hr = Cn({
  5300. clone_: function (t) {
  5301. var e = ln(t, "x", "clone", null);
  5302. return Nt.runKernelFunc(function () {
  5303. return Nt.makeTensorFromDataId(e.dataId, e.shape, e.dtype);
  5304. }, {
  5305. $x: e
  5306. }, function (t) {
  5307. return {
  5308. $x: function () {
  5309. return t.toFloat();
  5310. }
  5311. };
  5312. });
  5313. }
  5314. }),
  5315. fr = Cn({
  5316. cumsum_: function (t, e, n, r) {
  5317. void 0 === e && (e = 0), void 0 === n && (n = !1), void 0 === r && (r = !1);
  5318. var o = ln(t, "x", "cumsum"),
  5319. a = gn([e |= 0], o.rank),
  5320. i = o;
  5321. null != a && (i = o.transpose(a));
  5322. var u = xn(1, o.rank)[0],
  5323. s = Nt.runKernelFunc(function (t) {
  5324. return t.cumsum(i, u, n, r);
  5325. }, {
  5326. permutedX: i
  5327. }, function (t) {
  5328. return {
  5329. permutedX: function () {
  5330. return t.cumsum(e, n, !r);
  5331. }
  5332. };
  5333. });
  5334. return null != a && (s = s.transpose(a)), s;
  5335. }
  5336. }),
  5337. pr = Cn({
  5338. depthToSpace_: function (t, e, n) {
  5339. void 0 === n && (n = "NHWC");
  5340. var r = ln(t, "x", "depthToSpace"),
  5341. o = "NHWC" === n ? r.shape[1] : r.shape[2],
  5342. a = "NHWC" === n ? r.shape[2] : r.shape[3],
  5343. i = "NHWC" === n ? r.shape[3] : r.shape[1];
  5344. return g(o * e >= 0, function () {
  5345. return "Negative dimension size caused by overflow when multiplying\n " + o + " and " + e + " for depthToSpace with input shape\n " + r.shape;
  5346. }), g(a * e >= 0, function () {
  5347. return "Negative dimension size caused by overflow when multiplying\n " + a + " and " + e + " for depthToSpace with input shape\n " + r.shape;
  5348. }), g(i % (e * e) == 0, function () {
  5349. return "Dimension size must be evenly divisible by " + e * e + " but is " + i + " for depthToSpace with input shape " + r.shape;
  5350. }), Nt.runKernelFunc(function (t) {
  5351. return t.depthToSpace(r, e, n);
  5352. }, {
  5353. $x: r
  5354. });
  5355. }
  5356. }),
  5357. dr = Cn({
  5358. expandDims_: function (t, e) {
  5359. void 0 === e && (e = 0);
  5360. var n = ln(t, "x", "expandDims", null);
  5361. g(e <= n.rank, function () {
  5362. return "Axis must be <= rank of the tensor";
  5363. });
  5364. var r = n.shape.slice();
  5365. return e < 0 && (g(-(n.rank + 1) <= e, function () {
  5366. return "Axis must be in the interval [" + -(n.rank + 1) + ", " + n.rank + "]";
  5367. }), e = n.rank + e + 1), r.splice(e, 0, 1), Sr(n, r);
  5368. }
  5369. }),
  5370. vr = Cn({
  5371. eye_: function (t, e, n, r) {
  5372. void 0 === r && (r = "float32"), null == e && (e = t);
  5373. for (var o = ur([t, e], r), a = t <= e ? t : e, i = 0; i < a; ++i) o.set(1, i, i);
  5374. var u = o.toTensor().as2D(t, e);
  5375. if (null == n) return u;
  5376. if (1 === n.length) return Nr(dr(u, 0), [n[0], 1, 1]);
  5377. if (2 === n.length) return Nr(dr(dr(u, 0), 0), [n[0], n[1], 1, 1]);
  5378. if (3 === n.length) return Nr(dr(dr(dr(u, 0), 0), 0), [n[0], n[1], n[2], 1, 1]);
  5379. throw new Error("eye() currently supports only 1D and 2D batchShapes, but received " + n.length + "D.");
  5380. }
  5381. }),
  5382. mr = Cn({
  5383. multinomial_: function (t, e, n, r) {
  5384. void 0 === r && (r = !1);
  5385. var o = ln(t, "logits", "multinomial"),
  5386. a = o.size,
  5387. i = o.rank;
  5388. if (a < 2) throw new Error("Error in multinomial: you need at least 2 outcomes, but got " + a + ".");
  5389. if (i > 2) throw new Error("Rank of probabilities must be 1 or 2, but is " + i);
  5390. n = n || Math.random();
  5391. var u = 1 === i ? o.as2D(1, -1) : o,
  5392. s = Nt.runKernelFunc(function (t) {
  5393. return t.multinomial(u, r, e, n);
  5394. }, {
  5395. logits2D: u
  5396. });
  5397. return 1 === i ? s.as1D() : s;
  5398. }
  5399. }),
  5400. gr = Cn({
  5401. oneHot_: function (t, e, n, r) {
  5402. if (void 0 === n && (n = 1), void 0 === r && (r = 0), e < 2) throw new Error("Error in oneHot: depth must be >=2, but it is " + e);
  5403. var o = ln(t, "indices", "oneHot", "int32"),
  5404. a = o.shape.concat([e]);
  5405. return o = o.flatten(), Nt.runKernelFunc(function (t) {
  5406. return t.oneHot(o, e, n, r);
  5407. }, {
  5408. $indices: o
  5409. }, function (t) {
  5410. return {
  5411. $indices: function () {
  5412. return Pn(o.shape, "float32");
  5413. }
  5414. };
  5415. }).reshape(a);
  5416. }
  5417. }),
  5418. yr = Cn({
  5419. pad_: function (t, e, n) {
  5420. void 0 === n && (n = 0);
  5421. var r = ln(t, "x", "pad");
  5422. if (0 === r.rank) throw new Error("pad(scalar) is not defined. Pass non-scalar to pad");
  5423. var o = e.map(function (t) {
  5424. return t[0];
  5425. });
  5426. return Nt.runKernelFunc(function (t) {
  5427. return t.pad(r, e, n);
  5428. }, {
  5429. $x: r
  5430. }, function (t) {
  5431. return {
  5432. $x: function () {
  5433. return t.slice(o, r.shape);
  5434. }
  5435. };
  5436. });
  5437. }
  5438. }),
  5439. xr = Cn({
  5440. pad1d_: function (t, e, n) {
  5441. return void 0 === n && (n = 0), g(2 === e.length, function () {
  5442. return "Invalid number of paddings. Must be length of 2.";
  5443. }), yr(t, [e], n);
  5444. }
  5445. }),
  5446. br = Cn({
  5447. pad2d_: function (t, e, n) {
  5448. return void 0 === n && (n = 0), g(2 === e.length && 2 === e[0].length && 2 === e[1].length, function () {
  5449. return "Invalid number of paddings. Must be length of 2 each.";
  5450. }), yr(t, e, n);
  5451. }
  5452. }),
  5453. wr = Cn({
  5454. pad3d_: function (t, e, n) {
  5455. return void 0 === n && (n = 0), g(3 === e.length && 2 === e[0].length && 2 === e[1].length && 2 === e[2].length, function () {
  5456. return "Invalid number of paddings. Must be length of 2 each.";
  5457. }), yr(t, e, n);
  5458. }
  5459. }),
  5460. Cr = Cn({
  5461. pad4d_: function (t, e, n) {
  5462. return void 0 === n && (n = 0), g(4 === e.length && 2 === e[0].length && 2 === e[1].length && 2 === e[2].length && 2 === e[3].length, function () {
  5463. return "Invalid number of paddings. Must be length of 2 each.";
  5464. }), yr(t, e, n);
  5465. }
  5466. }),
  5467. Er = Cn({
  5468. rand_: function (t, e, n) {
  5469. var r = w(t),
  5470. o = null;
  5471. if (null == n || "float32" === n) o = new Float32Array(r); else if ("int32" === n) o = new Int32Array(r); else {
  5472. if ("bool" !== n) throw new Error("Unknown data type " + n);
  5473. o = new Uint8Array(r);
  5474. }
  5475. for (var a = 0; a < r; a++) o[a] = e();
  5476. return Nt.makeTensor(o, t, n);
  5477. }
  5478. }),
  5479. Rr = Cn({
  5480. randomNormal_: function (t, e, n, r, o) {
  5481. if (void 0 === e && (e = 0), void 0 === n && (n = 1), null != r && "bool" === r) throw new Error("Unsupported data type " + r);
  5482. for (var a = new or(e, n, r, !1, o), i = ur(t, r), u = 0; u < i.values.length; u++) i.values[u] = a.nextValue();
  5483. return i.toTensor();
  5484. }
  5485. }),
  5486. Ir = Cn({
  5487. randomGamma_: function (t, e, n, r, o) {
  5488. if (void 0 === n && (n = 1), void 0 === r && (r = "float32"), null == n && (n = 1), null == r && (r = "float32"), "float32" !== r && "int32" !== r) throw new Error("Unsupported data type " + r);
  5489. for (var a = new ar(e, n, r, o), i = ur(t, r), u = 0; u < i.values.length; u++) i.values[u] = a.nextValue();
  5490. return i.toTensor();
  5491. }
  5492. }),
  5493. kr = Cn({
  5494. randomUniform_: function (t, e, n, r, o) {
  5495. void 0 === e && (e = 0), void 0 === n && (n = 1), void 0 === r && (r = "float32");
  5496. for (var a = ur(t, r), i = new ir(e, n, null, o), u = 0; u < a.values.length; u++) a.values[u] = i.nextValue();
  5497. return a.toTensor();
  5498. }
  5499. }),
  5500. Sr = Cn({
  5501. reshape_: function (t, e) {
  5502. var n = ln(t, "x", "reshape", null);
  5503. e = A(e, n.size), g(n.size === w(e), function () {
  5504. return "new shape and old shape must have the same number of elements.";
  5505. });
  5506. var r = {
  5507. shape: e
  5508. };
  5509. return Nt.runKernelFunc(function (t) {
  5510. return t.reshape(n, e);
  5511. }, {
  5512. x: n
  5513. }, function (t) {
  5514. return {
  5515. x: function () {
  5516. return t.reshape(n.shape);
  5517. }
  5518. };
  5519. }, "Reshape", r);
  5520. }
  5521. }),
  5522. Ar = Cn({
  5523. spaceToBatchND_: function (t, e, n) {
  5524. var r = ln(t, "x", "spaceToBatchND");
  5525. return g(r.rank >= 1 + e.length, function () {
  5526. return "input rank " + r.rank + " should be > than [blockShape] " + e.length;
  5527. }), g(n.length === e.length, function () {
  5528. return "paddings.shape[0] " + n.length + " must be equal to [blockShape] " + e.length;
  5529. }), g(r.shape.reduce(function (t, r, o) {
  5530. return o > 0 && o <= e.length ? t && (r + n[o - 1][0] + n[o - 1][1]) % e[o - 1] == 0 : t;
  5531. }, !0), function () {
  5532. return "input spatial dimensions " + r.shape.slice(1) + " with paddings " + n.toString() + " must be divisible by blockShapes " + e.toString();
  5533. }), Nt.runKernelFunc(function (t) {
  5534. return t.spaceToBatchND(r, e, n);
  5535. }, {
  5536. $x: r
  5537. }, function (t) {
  5538. return {
  5539. $x: function () {
  5540. return t.batchToSpaceND(e, n);
  5541. }
  5542. };
  5543. });
  5544. }
  5545. }),
  5546. Dr = Cn({
  5547. squeeze_: function (t, e) {
  5548. var n = ln(t, "x", "squeeze");
  5549. return Sr(n, T(n.shape, e).newShape);
  5550. }
  5551. }),
  5552. Tr = Cn({
  5553. stack_: function (t, e) {
  5554. void 0 === e && (e = 0);
  5555. var n = hn(t, "tensors", "stack");
  5556. if (g(n.length >= 1, function () {
  5557. return "Pass at least one tensor to tf.stack";
  5558. }), 1 === n.length) return n[0].expandDims(e);
  5559. var r = n[0].rank,
  5560. o = n[0].shape,
  5561. a = n[0].dtype;
  5562. g(e <= r, function () {
  5563. return "Axis must be <= rank of the tensor";
  5564. }), n.forEach(function (t) {
  5565. y(o, t.shape, "All tensors passed to stack must have matching shapes");
  5566. }), n.forEach(function (t) {
  5567. g(a === t.dtype, function () {
  5568. return "All tensors passed to stack must have matching dtypes";
  5569. });
  5570. });
  5571. var i = n.map(function (t) {
  5572. return t.expandDims(e);
  5573. });
  5574. return Gn(i, e);
  5575. }
  5576. }),
  5577. Nr = Cn({
  5578. tile_: function (t, e) {
  5579. var n = ln(t, "x", "tile", null);
  5580. return g(n.rank === e.length, function () {
  5581. return "Error in transpose: rank of input " + n.rank + " must match length of reps " + e + ".";
  5582. }), Nt.runKernelFunc(function (t, r) {
  5583. var o = t.tile(n, e);
  5584. return r([n]), o;
  5585. }, {
  5586. $x: n
  5587. }, function (t, n) {
  5588. var r = n[0];
  5589. return {
  5590. $x: function () {
  5591. var n = zn(r);
  5592. if (1 === r.rank) for (var o = 0; o < e[0]; ++o) n = n.add(t.slice([o * r.shape[0]], [r.shape[0]])); else if (2 === r.rank) for (o = 0; o < e[0]; ++o) for (var a = 0; a < e[1]; ++a) n = n.add(t.slice([o * r.shape[0], a * r.shape[1]], [r.shape[0], r.shape[1]])); else if (3 === r.rank) for (o = 0; o < e[0]; ++o) for (a = 0; a < e[1]; ++a) for (var i = 0; i < e[2]; ++i) n = n.add(t.slice([o * r.shape[0], a * r.shape[1], i * r.shape[2]], [r.shape[0], r.shape[1], r.shape[2]])); else {
  5593. if (4 !== r.rank) throw new Error("Gradient for tile operation is not implemented for rank-" + r.rank + " tensors yet.");
  5594. for (o = 0; o < e[0]; ++o) for (a = 0; a < e[1]; ++a) for (i = 0; i < e[2]; ++i) for (var u = 0; u < e[3]; ++u) n = n.add(t.slice([o * r.shape[0], a * r.shape[1], i * r.shape[2], u * r.shape[3]], [r.shape[0], r.shape[1], r.shape[2], r.shape[3]]));
  5595. }
  5596. return n;
  5597. }
  5598. };
  5599. });
  5600. }
  5601. }),
  5602. Fr = Cn({
  5603. truncatedNormal_: function (t, e, n, r, o) {
  5604. if (void 0 === e && (e = 0), void 0 === n && (n = 1), null != r && "bool" === r) throw new Error("Unsupported data type " + r);
  5605. for (var a = new or(e, n, r, !0, o), i = ur(t, r), u = 0; u < i.values.length; u++) i.values[u] = a.nextValue();
  5606. return i.toTensor();
  5607. }
  5608. }),
  5609. Or = Cn({
  5610. unstack_: function (t, e) {
  5611. void 0 === e && (e = 0), e = e || 0;
  5612. var n = ln(t, "x", "unstack");
  5613. return g(e >= -n.shape.length && e < n.shape.length, function () {
  5614. return "Axis = " + e + " is not in [-" + n.shape.length + ", " + n.shape.length + ")";
  5615. }), e < 0 && (e += n.shape.length), Nt.runKernelFunc(function (t) {
  5616. return t.unstack(n, e);
  5617. }, {
  5618. $x: n
  5619. }, function (t) {
  5620. return {
  5621. $x: function () {
  5622. return Tr(t, e);
  5623. }
  5624. };
  5625. });
  5626. }
  5627. }),
  5628. _r = function (t, e) {
  5629. return n(this, void 0, void 0, function () {
  5630. var n, o, a, i, u, s, c, l, h, f;
  5631. return r(this, function (r) {
  5632. switch (r.label) {
  5633. case 0:
  5634. return n = ln(t, "x", "setdiff1d"), o = ln(e, "y", "setdiff1d"), g(n.dtype === o.dtype, function () {
  5635. return "x and y should have the same dtype, but got x (" + n.dtype + ") and y (" + o.dtype + ").";
  5636. }), g(1 === n.rank, function () {
  5637. return "x should be 1D tensor, but got x (" + n.shape + ").";
  5638. }), g(1 === o.rank, function () {
  5639. return "y should be 1D tensor, but got y (" + o.shape + ").";
  5640. }), [4, n.data()];
  5641. case 1:
  5642. return a = r.sent(), [4, o.data()];
  5643. case 2:
  5644. for (i = r.sent(), u = new Set(i), s = 0, h = 0; h < a.length; h++) u.has(a[h]) || s++;
  5645. for (c = new lt([s], n.dtype), l = new lt([s], "int32"), h = 0, f = 0; h < a.length; h++) u.has(a[h]) || (c.values[f] = a[h], l.values[f] = h, f++);
  5646. return [2, [c.toTensor(), l.toTensor()]];
  5647. }
  5648. });
  5649. });
  5650. };
  5651. exports.setdiff1dAsync = _r;
  5652. exports.unstack = Or;
  5653. exports.truncatedNormal = Fr;
  5654. exports.tile = Nr;
  5655. exports.stack = Tr;
  5656. exports.squeeze = Dr;
  5657. exports.spaceToBatchND = Ar;
  5658. exports.reshape = Sr;
  5659. exports.randomUniform = kr;
  5660. exports.randomGamma = Ir;
  5661. exports.randomNormal = Rr;
  5662. exports.rand = Er;
  5663. exports.pad4d = Cr;
  5664. exports.pad3d = wr;
  5665. exports.pad2d = br;
  5666. exports.pad1d = xr;
  5667. exports.pad = yr;
  5668. exports.oneHot = gr;
  5669. exports.multinomial = mr;
  5670. exports.eye = vr;
  5671. exports.expandDims = dr;
  5672. exports.depthToSpace = pr;
  5673. exports.cumsum = fr;
  5674. exports.clone = hr;
  5675. exports.cast = lr;
  5676. exports.batchToSpaceND = cr;
  5677. function Mr(t, e, n, r) {
  5678. void 0 === r && (r = !0);
  5679. var o = [];
  5680. if (r) (o = o.concat(e.slice(0))).push(t[0] / n), o = o.concat(t.slice(1)); else {
  5681. o = o.concat(t[0]);
  5682. for (var a = e.length, i = 0; i < a; ++i) o = o.concat([t[i + 1] / e[i], e[i]]);
  5683. o = o.concat(t.slice(a + 1));
  5684. }
  5685. return o;
  5686. }
  5687. function Br(t, e, n) {
  5688. void 0 === n && (n = !0);
  5689. var r = [];
  5690. if (n) {
  5691. r.push(e);
  5692. for (var o = e + 1; o < t; ++o) o <= 2 * e ? (r.push(o), r.push(o - (e + 1))) : r.push(o);
  5693. } else {
  5694. var a = [],
  5695. i = [];
  5696. for (o = 1; o < t; ++o) o >= 2 * e + 1 || o % 2 == 1 ? i.push(o) : a.push(o);
  5697. r.push.apply(r, a), r.push(0), r.push.apply(r, i);
  5698. }
  5699. return r;
  5700. }
  5701. function Pr(t, e, n, r) {
  5702. void 0 === r && (r = !0);
  5703. var o = [];
  5704. r ? o.push(t[0] / n) : o.push(t[0] * n);
  5705. for (var a = 1; a < t.length; ++a) a <= e.length ? r ? o.push(e[a - 1] * t[a]) : o.push(t[a] / e[a - 1]) : o.push(t[a]);
  5706. return o;
  5707. }
  5708. function Lr(t, e) {
  5709. for (var n = [0], r = 0; r < e; ++r) n.push(t[r][0]);
  5710. return n;
  5711. }
  5712. function Wr(t, e, n) {
  5713. for (var r = t.slice(0, 1), o = 0; o < n; ++o) r.push(t[o + 1] - e[o][0] - e[o][1]);
  5714. return r;
  5715. }
  5716. function Ur(t, e) {
  5717. if (t.rank < 1) throw new Error("tf.gatherND() expects the input to be rank 1 or higher, but the rank was " + t.rank + ".");
  5718. if (e.rank < 1) throw new Error("tf.gatherND() expects the indices to be rank 1 or higher, but the rank was " + e.rank + ".");
  5719. if ("int32" !== e.dtype) throw new Error("tf.gatherND() expects the indices to be int32 type, but the dtype was " + e.dtype + ".");
  5720. if (e.shape[e.rank - 1] > t.rank) throw new Error("index innermost dimension length must be <= tensor rank; saw: " + e.shape[e.rank - 1] + " vs. " + t.rank);
  5721. if (0 === t.size) throw new Error("Requested more than 0 entries, but input is empty. Input shape: " + t.shape + ".");
  5722. for (var n = e.shape, r = n[n.length - 1], o = 1, a = 0; a < n.length - 1; ++a) o *= n[a];
  5723. var i = t.shape,
  5724. u = n.slice();
  5725. u.pop();
  5726. var s = 1;
  5727. for (a = r; a < t.rank; ++a) s *= i[a], u.push(i[a]);
  5728. var c = q(t.shape).map(function (t) {
  5729. return t / s;
  5730. }).concat([1]).slice(0, r);
  5731. return [u, o, s, c];
  5732. }
  5733. var Vr = 30;
  5734. function zr(t) {
  5735. return t <= Vr ? t : H(t, Math.floor(Math.sqrt(t)));
  5736. }
  5737. function Gr(t, e, n) {
  5738. if (e.rank < 1) throw new Error("tf.scatterND() expects the indices to be rank 1 or higher, but the rank was " + e.rank + ".");
  5739. if (t.rank < 1) throw new Error("tf.scatterND() expects the updates to be rank 1 or higher, but the rank was " + t.rank + ".");
  5740. if ("int32" !== e.dtype) throw new Error("The dtype of 'indices' should be int32, but got dtype: " + e.dtype);
  5741. if (n.length < 1) throw new Error("Output rank must be greater or equal to 1, but got shape: " + n);
  5742. if (0 === n.length) {
  5743. if (0 === e.size) throw new Error("Indices specified for empty output. indices shape: " + e.shape);
  5744. if (0 === t.size) throw new Error("Updates specified for empty output. updates shape: " + t.shape);
  5745. }
  5746. !function (t, e, n) {
  5747. var r = e.rank > 1 ? e.shape[e.rank - 1] : 1,
  5748. o = e.rank > 1 ? e.rank - 1 : 1,
  5749. a = "Must have updates.shape = indices.shape[:batchDim] + shape[sliceDim:], got updates.shape: " + n.shape + ", indices.shape: " + e.shape + ", shape: " + t + ", sliceDim: " + r + ", and batchDim: " + o + ".";
  5750. if (n.rank < o) throw new Error(a + " update.rank < " + o + ". ");
  5751. if (t.length < r + (n.rank - o)) throw new Error(a + " Output shape length < " + (r + (n.rank - o)));
  5752. if (n.rank !== o + t.length - r) throw new Error(a + " update.rank != " + (o + t.length - r));
  5753. for (var i = 0; i < o; ++i) if (n.shape[i] !== e.shape[i]) throw new Error(a + " updates.shape[" + i + "] (" + n.shape[i] + ") != indices.shape[" + i + "] (" + e.shape[i] + ").");
  5754. for (i = 0; i < n.rank - o; ++i) if (n.shape[i + o] !== t[i + r]) throw new Error(a + " updates.shape[" + (i + o) + "] (" + n.shape[i + o] + ") != shape[" + (i + o) + "] (" + t[i + o] + ")");
  5755. }(n, e, t);
  5756. }
  5757. function Hr(t, e, n) {
  5758. for (var r = e.rank > 1 ? e.shape[e.rank - 1] : 1, o = n.length, a = 1, i = r; i < o; ++i) a *= n[i];
  5759. var u = r < 1 ? 1 : r;
  5760. return {
  5761. sliceRank: r,
  5762. numUpdates: e.size / u,
  5763. sliceSize: a,
  5764. strides: q(n.slice(0, r)).concat([1]),
  5765. outputSize: w(n)
  5766. };
  5767. }
  5768. function qr(t, e, n) {
  5769. g(t.rank === e.length, function () {
  5770. return "Error in slice" + t.rank + "D: Length of begin " + e + " must match the rank of the array (" + t.rank + ").";
  5771. }), g(t.rank === n.length, function () {
  5772. return "Error in slice" + t.rank + "D: Length of size " + n + " must match the rank of the array (" + t.rank + ").";
  5773. });
  5774. for (var r = function (r) {
  5775. g(e[r] + n[r] <= t.shape[r], function () {
  5776. return "Error in slice" + t.rank + "D: begin[" + r + "] + size[" + r + "] (" + (e[r] + n[r]) + ") would overflow input.shape[" + r + "] (" + t.shape[r] + ")";
  5777. });
  5778. }, o = 0; o < t.rank; ++o) r(o);
  5779. }
  5780. function Kr(t) {
  5781. for (var e = [], n = 0; t > 0;) 1 & t && e.push(n), t /= 2, n++;
  5782. return e;
  5783. }
  5784. function jr(t, e, n) {
  5785. for (var r = [], o = 0; o < t.length; o++) r[o] = Math.ceil((e[o] - t[o]) / n[o]);
  5786. return r;
  5787. }
  5788. function Xr(t, e, n, r, o) {
  5789. var a = e[o],
  5790. i = n[o] || 1;
  5791. (t & 1 << o || null == a) && (a = i > 0 ? Number.MIN_SAFE_INTEGER : Number.MAX_SAFE_INTEGER);
  5792. var u = r[o];
  5793. return a < 0 && (a += u), a = d(0, a, u - 1);
  5794. }
  5795. function $r(t, e, n, r, o) {
  5796. var a = e[o],
  5797. i = n[o] || 1;
  5798. (t & 1 << o || null == a) && (a = i > 0 ? Number.MAX_SAFE_INTEGER : Number.MIN_SAFE_INTEGER);
  5799. var u = r[o];
  5800. return a < 0 && (a += u), a = i > 0 ? d(0, a, u) : d(-1, a, u - 1);
  5801. }
  5802. function Yr(t, e, n) {
  5803. for (var r = n.length, o = 0; o < n.length; o++) if (n[o] > 1) {
  5804. r = o;
  5805. break;
  5806. }
  5807. for (o = r + 1; o < n.length; o++) if (e[o] > 0 || n[o] !== t[o]) return !1;
  5808. return !0;
  5809. }
  5810. function Qr(t, e) {
  5811. for (var n = t.length > 0 ? t[t.length - 1] : 1, r = 0; r < t.length - 1; r++) n += t[r] * e[r];
  5812. return n;
  5813. }
  5814. var Jr = Object.freeze({
  5815. assertParamsValid: qr,
  5816. maskToAxes: Kr,
  5817. computeOutShape: jr,
  5818. startForAxis: Xr,
  5819. stopForAxis: $r,
  5820. isSliceContinous: Yr,
  5821. computeFlatOffset: Qr
  5822. });
  5823. exports.slice_util = Jr;
  5824. function Zr(t) {
  5825. return g(G(t), function () {
  5826. return "The f passed in grad(f) must be a function";
  5827. }), function (e, n) {
  5828. var r = ln(e, "x", "tf.grad", null),
  5829. o = null != n ? ln(n, "dy", "tf.grad") : null;
  5830. return Nt.tidy(function () {
  5831. var e = Nt.gradients(function () {
  5832. return t(r);
  5833. }, [r], o),
  5834. n = e.value,
  5835. a = e.grads;
  5836. return null != o && y(n.shape, o.shape, "The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"), ao(a), a[0];
  5837. });
  5838. };
  5839. }
  5840. function to(t) {
  5841. return g(G(t), function () {
  5842. return "The f passed in grads(f) must be a function";
  5843. }), function (e, n) {
  5844. g(Array.isArray(e), function () {
  5845. return "The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s";
  5846. });
  5847. var r = hn(e, "args", "tf.grads", null),
  5848. o = null != n ? ln(n, "dy", "tf.grads") : null;
  5849. return Nt.tidy(function () {
  5850. var e = Nt.gradients(function () {
  5851. return t.apply(void 0, r);
  5852. }, r, o),
  5853. n = e.value,
  5854. a = e.grads;
  5855. return null != o && y(n.shape, o.shape, "The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"), ao(a), a;
  5856. });
  5857. };
  5858. }
  5859. function eo(t) {
  5860. return g(G(t), function () {
  5861. return "The f passed in valueAndGrad(f) must be a function";
  5862. }), function (e, n) {
  5863. g(e instanceof dt, function () {
  5864. return "The x passed in valueAndGrad(f)(x) must be a tensor";
  5865. }), g(null == n || n instanceof dt, function () {
  5866. return "The dy passed in valueAndGrad(f)(x, dy) must be a tensor";
  5867. });
  5868. var r = Nt.gradients(function () {
  5869. return t(e);
  5870. }, [e], n),
  5871. o = r.grads,
  5872. a = r.value;
  5873. return ao(o), {
  5874. grad: o[0],
  5875. value: a
  5876. };
  5877. };
  5878. }
  5879. function no(t) {
  5880. return g(G(t), function () {
  5881. return "The f passed in valueAndGrads(f) must be a function";
  5882. }), function (e, n) {
  5883. g(Array.isArray(e) && e.every(function (t) {
  5884. return t instanceof dt;
  5885. }), function () {
  5886. return "The args passed in valueAndGrads(f)(args) must be array of tensors";
  5887. }), g(null == n || n instanceof dt, function () {
  5888. return "The dy passed in valueAndGrads(f)(args, dy) must be a tensor";
  5889. });
  5890. var r = Nt.gradients(function () {
  5891. return t.apply(void 0, e);
  5892. }, e, n);
  5893. return null != n && y(r.value.shape, n.shape, "The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"), ao(r.grads), r;
  5894. };
  5895. }
  5896. function ro(t, e) {
  5897. g(G(t), function () {
  5898. return "The f passed in variableGrads(f) must be a function";
  5899. }), g(null == e || Array.isArray(e) && e.every(function (t) {
  5900. return t instanceof bt;
  5901. }), function () {
  5902. return "The varList passed in variableGrads(f, varList) must be an array of variables";
  5903. });
  5904. var n = null != e;
  5905. if (!n) for (var r in e = [], Nt.registeredVariables) e.push(Nt.registeredVariables[r]);
  5906. var o = n ? e.filter(function (t) {
  5907. return !t.trainable;
  5908. }) : null,
  5909. a = e.length;
  5910. g((e = e.filter(function (t) {
  5911. return t.trainable;
  5912. })).length > 0, function () {
  5913. return "variableGrads() expects at least one of the input variables to be trainable, but none of the " + a + " variables is trainable.";
  5914. });
  5915. var i = Nt.gradients(t, e, null, !0),
  5916. u = i.value,
  5917. s = i.grads;
  5918. g(s.some(function (t) {
  5919. return null != t;
  5920. }), function () {
  5921. return "Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize().";
  5922. }), g(0 === u.rank, function () {
  5923. return "The f passed in variableGrads(f) must return a scalar, but it returned a rank-" + u.rank + " tensor";
  5924. });
  5925. var c = {};
  5926. return e.forEach(function (t, e) {
  5927. null != s[e] && (c[t.name] = s[e]);
  5928. }), null != o && o.forEach(function (t) {
  5929. return c[t.name] = null;
  5930. }), {
  5931. value: u,
  5932. grads: c
  5933. };
  5934. }
  5935. function oo(t) {
  5936. return Nt.customGrad(t);
  5937. }
  5938. function ao(t) {
  5939. if (t.filter(function (t) {
  5940. return null == t;
  5941. }).length > 0) throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that\n the f you passed encloses all operations that lead from x to y.");
  5942. }
  5943. var io = Cn({
  5944. softmax_: function (t, e) {
  5945. void 0 === e && (e = -1);
  5946. var n = ln(t, "logits", "softmax");
  5947. if (-1 === e && (e = n.rank - 1), e !== n.rank - 1) throw Error("Softmax along a non-last dimension is not yet supported. Logits was rank " + n.rank + " and dim was " + e);
  5948. return oo(function (t, n) {
  5949. var r = t.logSumExp([e], !0),
  5950. o = t.toFloat().sub(r).exp();
  5951. return n([o]), {
  5952. value: o,
  5953. gradFunc: function (t, n) {
  5954. var r = n[0],
  5955. o = t.mul(r);
  5956. return o.sub(o.sum([e], !0).mul(r));
  5957. }
  5958. };
  5959. })(n);
  5960. }
  5961. }),
  5962. uo = Cn({
  5963. logSoftmax_: function (t, e) {
  5964. void 0 === e && (e = -1);
  5965. var n = ln(t, "logits", "logSoftmax");
  5966. if (-1 === e && (e = n.rank - 1), e !== n.rank - 1) throw Error("Log Softmax along a non-last dimension is not yet supported. Logits was rank " + n.rank + " and axis was " + e);
  5967. return oo(function (t, n) {
  5968. var r = t.max(e, !0),
  5969. o = t.sub(r),
  5970. a = o.toFloat().sub(o.exp().sum(e, !0).log());
  5971. return n([a]), {
  5972. value: a,
  5973. gradFunc: function (t, n) {
  5974. var r = n[0].exp();
  5975. return t.sub(t.sum(e, !0).mul(r));
  5976. }
  5977. };
  5978. })(n);
  5979. }
  5980. }),
  5981. so = function () {
  5982. function t(t, e) {
  5983. this.backend = t, this.dataMover = e, this.data = new WeakMap(), this.dataIdsCount = 0;
  5984. }
  5985. return t.prototype.get = function (t) {
  5986. return this.data.has(t) || this.dataMover.moveData(this.backend, t), this.data.get(t);
  5987. }, t.prototype.set = function (t, e) {
  5988. this.dataIdsCount++, this.data.set(t, e);
  5989. }, t.prototype.has = function (t) {
  5990. return this.data.has(t);
  5991. }, t.prototype.delete = function (t) {
  5992. return this.dataIdsCount--, this.data.delete(t);
  5993. }, t.prototype.numDataIds = function () {
  5994. return this.dataIdsCount;
  5995. }, t;
  5996. }(),
  5997. co = function () {
  5998. function t() { }
  5999. return t.prototype.time = function (t) {
  6000. return lo();
  6001. }, t.prototype.read = function (t) {
  6002. return lo();
  6003. }, t.prototype.readSync = function (t) {
  6004. return lo();
  6005. }, t.prototype.numDataIds = function () {
  6006. return lo();
  6007. }, t.prototype.disposeData = function (t) {
  6008. return lo();
  6009. }, t.prototype.fromPixels = function (t, e) {
  6010. return lo();
  6011. }, t.prototype.write = function (t, e, n) {
  6012. return lo();
  6013. }, t.prototype.move = function (t, e, n, r) {
  6014. return lo();
  6015. }, t.prototype.memory = function () {
  6016. return lo();
  6017. }, t.prototype.floatPrecision = function () {
  6018. return lo();
  6019. }, t.prototype.epsilon = function () {
  6020. return 32 === this.floatPrecision() ? 1e-7 : 1e-4;
  6021. }, t.prototype.batchMatMul = function (t, e, n, r) {
  6022. return lo();
  6023. }, t.prototype.fusedBatchMatMul = function (t) {
  6024. t.a, t.b, t.transposeA, t.transposeB, t.bias, t.activation, t.preluActivationWeights;
  6025. return lo();
  6026. }, t.prototype.slice = function (t, e, n) {
  6027. return lo();
  6028. }, t.prototype.stridedSlice = function (t, e, n, r) {
  6029. return lo();
  6030. }, t.prototype.unstack = function (t, e) {
  6031. return lo();
  6032. }, t.prototype.reverse = function (t, e) {
  6033. return lo();
  6034. }, t.prototype.concat = function (t, e) {
  6035. return lo();
  6036. }, t.prototype.neg = function (t) {
  6037. return lo();
  6038. }, t.prototype.add = function (t, e) {
  6039. return lo();
  6040. }, t.prototype.addN = function (t) {
  6041. return lo();
  6042. }, t.prototype.subtract = function (t, e) {
  6043. return lo();
  6044. }, t.prototype.multiply = function (t, e) {
  6045. return lo();
  6046. }, t.prototype.realDivide = function (t, e) {
  6047. return lo();
  6048. }, t.prototype.floorDiv = function (t, e) {
  6049. return lo();
  6050. }, t.prototype.sum = function (t, e) {
  6051. return lo();
  6052. }, t.prototype.prod = function (t, e) {
  6053. return lo();
  6054. }, t.prototype.unsortedSegmentSum = function (t, e, n) {
  6055. return lo();
  6056. }, t.prototype.argMin = function (t, e) {
  6057. return lo();
  6058. }, t.prototype.argMax = function (t, e) {
  6059. return lo();
  6060. }, t.prototype.equal = function (t, e) {
  6061. return lo();
  6062. }, t.prototype.notEqual = function (t, e) {
  6063. return lo();
  6064. }, t.prototype.less = function (t, e) {
  6065. return lo();
  6066. }, t.prototype.lessEqual = function (t, e) {
  6067. return lo();
  6068. }, t.prototype.greater = function (t, e) {
  6069. return lo();
  6070. }, t.prototype.greaterEqual = function (t, e) {
  6071. return lo();
  6072. }, t.prototype.logicalNot = function (t) {
  6073. return lo();
  6074. }, t.prototype.logicalAnd = function (t, e) {
  6075. return lo();
  6076. }, t.prototype.logicalOr = function (t, e) {
  6077. return lo();
  6078. }, t.prototype.where = function (t) {
  6079. return lo();
  6080. }, t.prototype.select = function (t, e, n) {
  6081. return lo();
  6082. }, t.prototype.topk = function (t, e, n) {
  6083. return lo();
  6084. }, t.prototype.min = function (t, e) {
  6085. return lo();
  6086. }, t.prototype.minimum = function (t, e) {
  6087. return lo();
  6088. }, t.prototype.mod = function (t, e) {
  6089. return lo();
  6090. }, t.prototype.max = function (t, e) {
  6091. return lo();
  6092. }, t.prototype.maximum = function (t, e) {
  6093. return lo();
  6094. }, t.prototype.all = function (t, e) {
  6095. return lo();
  6096. }, t.prototype.any = function (t, e) {
  6097. return lo();
  6098. }, t.prototype.squaredDifference = function (t, e) {
  6099. return lo();
  6100. }, t.prototype.ceil = function (t) {
  6101. return lo();
  6102. }, t.prototype.floor = function (t) {
  6103. return lo();
  6104. }, t.prototype.round = function (t) {
  6105. return lo();
  6106. }, t.prototype.sign = function (t) {
  6107. return lo();
  6108. }, t.prototype.isNaN = function (t) {
  6109. return lo();
  6110. }, t.prototype.isInf = function (t) {
  6111. return lo();
  6112. }, t.prototype.isFinite = function (t) {
  6113. return lo();
  6114. }, t.prototype.pow = function (t, e) {
  6115. return lo();
  6116. }, t.prototype.exp = function (t) {
  6117. return lo();
  6118. }, t.prototype.expm1 = function (t) {
  6119. return lo();
  6120. }, t.prototype.log = function (t) {
  6121. return lo();
  6122. }, t.prototype.log1p = function (t) {
  6123. return lo();
  6124. }, t.prototype.sqrt = function (t) {
  6125. return lo();
  6126. }, t.prototype.rsqrt = function (t) {
  6127. return lo();
  6128. }, t.prototype.square = function (t) {
  6129. return lo();
  6130. }, t.prototype.reciprocal = function (t) {
  6131. return lo();
  6132. }, t.prototype.relu = function (t) {
  6133. return lo();
  6134. }, t.prototype.relu6 = function (t) {
  6135. return lo();
  6136. }, t.prototype.prelu = function (t, e) {
  6137. return lo();
  6138. }, t.prototype.elu = function (t) {
  6139. return lo();
  6140. }, t.prototype.eluDer = function (t, e) {
  6141. return lo();
  6142. }, t.prototype.selu = function (t) {
  6143. return lo();
  6144. }, t.prototype.int = function (t) {
  6145. return lo();
  6146. }, t.prototype.clip = function (t, e, n) {
  6147. return lo();
  6148. }, t.prototype.abs = function (t) {
  6149. return lo();
  6150. }, t.prototype.complexAbs = function (t) {
  6151. return lo();
  6152. }, t.prototype.sigmoid = function (t) {
  6153. return lo();
  6154. }, t.prototype.softplus = function (t) {
  6155. return lo();
  6156. }, t.prototype.sin = function (t) {
  6157. return lo();
  6158. }, t.prototype.cos = function (t) {
  6159. return lo();
  6160. }, t.prototype.tan = function (t) {
  6161. return lo();
  6162. }, t.prototype.asin = function (t) {
  6163. return lo();
  6164. }, t.prototype.acos = function (t) {
  6165. return lo();
  6166. }, t.prototype.atan = function (t) {
  6167. return lo();
  6168. }, t.prototype.atan2 = function (t, e) {
  6169. return lo();
  6170. }, t.prototype.sinh = function (t) {
  6171. return lo();
  6172. }, t.prototype.cosh = function (t) {
  6173. return lo();
  6174. }, t.prototype.tanh = function (t) {
  6175. return lo();
  6176. }, t.prototype.asinh = function (t) {
  6177. return lo();
  6178. }, t.prototype.acosh = function (t) {
  6179. return lo();
  6180. }, t.prototype.atanh = function (t) {
  6181. return lo();
  6182. }, t.prototype.erf = function (t) {
  6183. return lo();
  6184. }, t.prototype.step = function (t, e) {
  6185. return lo();
  6186. }, t.prototype.fusedConv2d = function (t) {
  6187. t.input, t.filter, t.convInfo, t.bias, t.activation, t.preluActivationWeights;
  6188. return lo();
  6189. }, t.prototype.conv2d = function (t, e, n) {
  6190. return lo();
  6191. }, t.prototype.conv2dDerInput = function (t, e, n) {
  6192. return lo();
  6193. }, t.prototype.conv2dDerFilter = function (t, e, n) {
  6194. return lo();
  6195. }, t.prototype.fusedDepthwiseConv2D = function (t) {
  6196. t.input, t.filter, t.convInfo, t.bias, t.activation, t.preluActivationWeights;
  6197. return lo();
  6198. }, t.prototype.depthwiseConv2D = function (t, e, n) {
  6199. return lo();
  6200. }, t.prototype.depthwiseConv2DDerInput = function (t, e, n) {
  6201. return lo();
  6202. }, t.prototype.depthwiseConv2DDerFilter = function (t, e, n) {
  6203. return lo();
  6204. }, t.prototype.conv3d = function (t, e, n) {
  6205. return lo();
  6206. }, t.prototype.conv3dDerInput = function (t, e, n) {
  6207. return lo();
  6208. }, t.prototype.conv3dDerFilter = function (t, e, n) {
  6209. return lo();
  6210. }, t.prototype.maxPool = function (t, e) {
  6211. return lo();
  6212. }, t.prototype.maxPoolBackprop = function (t, e, n, r) {
  6213. return lo();
  6214. }, t.prototype.avgPool = function (t, e) {
  6215. return lo();
  6216. }, t.prototype.avgPoolBackprop = function (t, e, n) {
  6217. return lo();
  6218. }, t.prototype.avgPool3d = function (t, e) {
  6219. return lo();
  6220. }, t.prototype.avgPool3dBackprop = function (t, e, n) {
  6221. return lo();
  6222. }, t.prototype.maxPool3d = function (t, e) {
  6223. return lo();
  6224. }, t.prototype.maxPool3dBackprop = function (t, e, n, r) {
  6225. return lo();
  6226. }, t.prototype.reshape = function (t, e) {
  6227. return lo();
  6228. }, t.prototype.cast = function (t, e) {
  6229. return lo();
  6230. }, t.prototype.tile = function (t, e) {
  6231. return lo();
  6232. }, t.prototype.pad = function (t, e, n) {
  6233. return lo();
  6234. }, t.prototype.transpose = function (t, e) {
  6235. return lo();
  6236. }, t.prototype.gather = function (t, e, n) {
  6237. return lo();
  6238. }, t.prototype.gatherND = function (t, e) {
  6239. return lo();
  6240. }, t.prototype.scatterND = function (t, e, n) {
  6241. return lo();
  6242. }, t.prototype.batchToSpaceND = function (t, e, n) {
  6243. return lo();
  6244. }, t.prototype.spaceToBatchND = function (t, e, n) {
  6245. return lo();
  6246. }, t.prototype.resizeBilinear = function (t, e, n, r) {
  6247. return lo();
  6248. }, t.prototype.resizeBilinearBackprop = function (t, e, n) {
  6249. return lo();
  6250. }, t.prototype.resizeNearestNeighbor = function (t, e, n, r) {
  6251. return lo();
  6252. }, t.prototype.resizeNearestNeighborBackprop = function (t, e, n) {
  6253. return lo();
  6254. }, t.prototype.batchNormalization = function (t, e, n, r, o, a) {
  6255. return lo();
  6256. }, t.prototype.localResponseNormalization4D = function (t, e, n, r, o) {
  6257. return lo();
  6258. }, t.prototype.LRNGrad = function (t, e, n, r, o, a, i) {
  6259. return lo();
  6260. }, t.prototype.multinomial = function (t, e, n, r) {
  6261. return lo();
  6262. }, t.prototype.oneHot = function (t, e, n, r) {
  6263. return lo();
  6264. }, t.prototype.cumsum = function (t, e, n, r) {
  6265. return lo();
  6266. }, t.prototype.nonMaxSuppression = function (t, e, n, r, o) {
  6267. return lo();
  6268. }, t.prototype.fft = function (t) {
  6269. return lo();
  6270. }, t.prototype.ifft = function (t) {
  6271. return lo();
  6272. }, t.prototype.complex = function (t, e) {
  6273. return lo();
  6274. }, t.prototype.real = function (t) {
  6275. return lo();
  6276. }, t.prototype.imag = function (t) {
  6277. return lo();
  6278. }, t.prototype.cropAndResize = function (t, e, n, r, o, a) {
  6279. return lo();
  6280. }, t.prototype.depthToSpace = function (t, e, n) {
  6281. return lo();
  6282. }, t.prototype.split = function (t, e, n) {
  6283. return lo();
  6284. }, t.prototype.sparseToDense = function (t, e, n, r) {
  6285. return lo();
  6286. }, t.prototype.diag = function (t) {
  6287. return lo();
  6288. }, t.prototype.fill = function (t, e, n) {
  6289. throw new Error("Not yet implemented.");
  6290. }, t.prototype.onesLike = function (t) {
  6291. return lo();
  6292. }, t.prototype.zerosLike = function (t) {
  6293. return lo();
  6294. }, t.prototype.linspace = function (t, e, n) {
  6295. return lo();
  6296. }, t.prototype.dispose = function () {
  6297. return lo();
  6298. }, t;
  6299. }();
  6300. exports.KernelBackend = co;
  6301. exports.DataStorage = so;
  6302. exports.logSoftmax = uo;
  6303. exports.softmax = io;
  6304. function lo() {
  6305. throw new Error("Not yet implemented or not found in the registry. Did you forget to import the kernel?");
  6306. }
  6307. function ho(t, e) {
  6308. for (var n = t.length, r = [], o = 0; o < n; o++) {
  6309. var a = n - 1 - o,
  6310. i = t[a] || 1;
  6311. (e[e.length - 1 - o] || 1) > 1 && 1 === i && r.unshift(a);
  6312. }
  6313. return r;
  6314. }
  6315. function fo(t, e) {
  6316. for (var n = [], r = 0; r < e.length; r++) {
  6317. var o = t[t.length - r - 1],
  6318. a = e.length - r - 1,
  6319. i = e[a];
  6320. (null == o || 1 === o && i > 1) && n.unshift(a);
  6321. }
  6322. return n;
  6323. }
  6324. function po(t, e) {
  6325. for (var n = [], r = Math.max(t.length, e.length), o = 0; o < r; o++) {
  6326. var a = t[t.length - o - 1];
  6327. null == a && (a = 1);
  6328. var i = e[e.length - o - 1];
  6329. if (null == i && (i = 1), 1 === a) n.unshift(i); else if (1 === i) n.unshift(a); else {
  6330. if (a !== i) throw Error("Operands could not be broadcast together with shapes " + t + " and " + e + ".");
  6331. n.unshift(a);
  6332. }
  6333. }
  6334. return n;
  6335. }
  6336. function vo(t, e, n, r, o, a, i) {
  6337. void 0 === i && (i = "channelsLast");
  6338. var u,
  6339. s = bo(e),
  6340. c = s[0],
  6341. l = s[1];
  6342. if ("channelsLast" === i) u = [c, l, t[3], t[3]]; else {
  6343. if ("channelsFirst" !== i) throw new Error("Unknown dataFormat " + i);
  6344. u = [c, l, t[1], t[1]];
  6345. }
  6346. return go(t, u, n, r, o, a, !1, i);
  6347. }
  6348. function mo(t, e, n, r, o, a, i) {
  6349. void 0 === i && (i = "NDHWC");
  6350. var u,
  6351. s,
  6352. c = wo(e),
  6353. l = c[0],
  6354. h = c[1],
  6355. f = c[2];
  6356. if ("NDHWC" === i) s = "channelsLast", u = [l, h, f, t[4], t[4]]; else {
  6357. if ("NCDHW" !== i) throw new Error("Unknown dataFormat " + i);
  6358. s = "channelsFirst", u = [l, h, f, t[1], t[1]];
  6359. }
  6360. return yo(t, u, n, r, o, !1, s, a);
  6361. }
  6362. function go(t, e, n, r, o, a, i, u) {
  6363. void 0 === i && (i = !1), void 0 === u && (u = "channelsLast");
  6364. var s = [-1, -1, -1, -1],
  6365. c = s[0],
  6366. l = s[1],
  6367. h = s[2],
  6368. f = s[3];
  6369. if ("channelsLast" === u) c = t[0], l = t[1], h = t[2], f = t[3]; else {
  6370. if ("channelsFirst" !== u) throw new Error("Unknown dataFormat " + u);
  6371. c = t[0], f = t[1], l = t[2], h = t[3];
  6372. }
  6373. var p,
  6374. d = e[0],
  6375. v = e[1],
  6376. m = e[3],
  6377. y = bo(n),
  6378. x = y[0],
  6379. b = y[1],
  6380. w = bo(r),
  6381. C = w[0],
  6382. R = w[1],
  6383. I = Co(d, C),
  6384. k = Co(v, R),
  6385. S = function (t, e, n, r, o, a, i, u) {
  6386. var s, c, l;
  6387. if ("number" == typeof t) {
  6388. var h = 0 === t ? "VALID" : "NUMBER";
  6389. s = {
  6390. top: t,
  6391. bottom: t,
  6392. left: t,
  6393. right: t,
  6394. type: h
  6395. };
  6396. var f = function (t, e, n, r, o) {
  6397. null == r && (r = xo(t, e, n));
  6398. var a = t[0],
  6399. i = t[1],
  6400. u = Eo((a - e + 2 * r) / n + 1, o);
  6401. g(E(u), function () {
  6402. return "The output # of rows (" + u + ") must be an integer. Change the stride and/or zero pad parameters";
  6403. });
  6404. var s = Eo((i - e + 2 * r) / n + 1, o);
  6405. return g(E(s), function () {
  6406. return "The output # of columns (" + s + ") must be an integer. Change the stride and/or zero pad parameters";
  6407. }), [u, s];
  6408. }([e, n], a, r, t, u);
  6409. c = f[0], l = f[1];
  6410. } else if ("same" === t) {
  6411. c = Math.ceil(e / r), l = Math.ceil(n / o);
  6412. var p = Math.max(0, (c - 1) * r + a - e),
  6413. d = Math.max(0, (l - 1) * o + i - n),
  6414. v = Math.floor(p / 2),
  6415. m = p - v,
  6416. y = Math.floor(d / 2),
  6417. x = d - y;
  6418. s = {
  6419. top: v,
  6420. bottom: m,
  6421. left: y,
  6422. right: x,
  6423. type: "SAME"
  6424. };
  6425. } else {
  6426. if ("valid" !== t) throw Error("Unknown padding parameter: " + t);
  6427. s = {
  6428. top: 0,
  6429. bottom: 0,
  6430. left: 0,
  6431. right: 0,
  6432. type: "VALID"
  6433. }, c = Math.ceil((e - a + 1) / r), l = Math.ceil((n - i + 1) / o);
  6434. }
  6435. return {
  6436. padInfo: s,
  6437. outHeight: c,
  6438. outWidth: l
  6439. };
  6440. }(o, l, h, x, b, I, k, a),
  6441. A = S.padInfo,
  6442. D = S.outHeight,
  6443. T = S.outWidth,
  6444. N = i ? m * f : m;
  6445. return "channelsFirst" === u ? p = [c, N, D, T] : "channelsLast" === u && (p = [c, D, T, N]), {
  6446. batchSize: c,
  6447. dataFormat: u,
  6448. inHeight: l,
  6449. inWidth: h,
  6450. inChannels: f,
  6451. outHeight: D,
  6452. outWidth: T,
  6453. outChannels: N,
  6454. padInfo: A,
  6455. strideHeight: x,
  6456. strideWidth: b,
  6457. filterHeight: d,
  6458. filterWidth: v,
  6459. effectiveFilterHeight: I,
  6460. effectiveFilterWidth: k,
  6461. dilationHeight: C,
  6462. dilationWidth: R,
  6463. inShape: t,
  6464. outShape: p,
  6465. filterShape: e
  6466. };
  6467. }
  6468. function yo(t, e, n, r, o, a, i, u) {
  6469. void 0 === a && (a = !1), void 0 === i && (i = "channelsLast");
  6470. var s = [-1, -1, -1, -1, -1],
  6471. c = s[0],
  6472. l = s[1],
  6473. h = s[2],
  6474. f = s[3],
  6475. p = s[4];
  6476. if ("channelsLast" === i) c = t[0], l = t[1], h = t[2], f = t[3], p = t[4]; else {
  6477. if ("channelsFirst" !== i) throw new Error("Unknown dataFormat " + i);
  6478. c = t[0], p = t[1], l = t[2], h = t[3], f = t[4];
  6479. }
  6480. var d,
  6481. v = e[0],
  6482. m = e[1],
  6483. y = e[2],
  6484. x = e[4],
  6485. b = wo(n),
  6486. w = b[0],
  6487. C = b[1],
  6488. R = b[2],
  6489. I = wo(r),
  6490. k = I[0],
  6491. S = I[1],
  6492. A = I[2],
  6493. D = Co(v, k),
  6494. T = Co(m, S),
  6495. N = Co(y, A),
  6496. F = function (t, e, n, r, o, a, i, u, s, c, l) {
  6497. var h, f, p, d;
  6498. if ("number" == typeof t) {
  6499. var v = 0 === t ? "VALID" : "NUMBER";
  6500. h = {
  6501. top: t,
  6502. bottom: t,
  6503. left: t,
  6504. right: t,
  6505. front: t,
  6506. back: t,
  6507. type: v
  6508. };
  6509. var m = function (t, e, n, r, o, a) {
  6510. null == o && (o = xo(t, e, r));
  6511. var i = t[0],
  6512. u = t[1],
  6513. s = t[2],
  6514. c = Eo((i - e + 2 * o) / r + 1, a);
  6515. g(E(c), function () {
  6516. return "The output # of depths (" + c + ") must be an integer. Change the stride and/or zero pad parameters";
  6517. });
  6518. var l = Eo((u - e + 2 * o) / r + 1, a);
  6519. g(E(l), function () {
  6520. return "The output # of rows (" + l + ") must be an integer. Change the stride and/or zero pad parameters";
  6521. });
  6522. var h = Eo((s - e + 2 * o) / r + 1, a);
  6523. return g(E(h), function () {
  6524. return "The output # of columns (" + h + ") must be an integer. Change the stride and/or zero pad parameters";
  6525. }), [c, l, h, n];
  6526. }([e, n, r, 1], u, 1, o, t, l);
  6527. f = m[0], p = m[1], d = m[2];
  6528. } else if ("same" === t) {
  6529. f = Math.ceil(e / o), p = Math.ceil(n / a), d = Math.ceil(r / i);
  6530. var y = (f - 1) * o + u - e,
  6531. x = (p - 1) * a + s - n,
  6532. b = (d - 1) * i + c - r,
  6533. w = Math.floor(y / 2),
  6534. C = y - w,
  6535. R = Math.floor(x / 2),
  6536. I = x - R,
  6537. k = Math.floor(b / 2),
  6538. S = b - k;
  6539. h = {
  6540. top: R,
  6541. bottom: I,
  6542. left: k,
  6543. right: S,
  6544. front: w,
  6545. back: C,
  6546. type: "SAME"
  6547. };
  6548. } else {
  6549. if ("valid" !== t) throw Error("Unknown padding parameter: " + t);
  6550. h = {
  6551. top: 0,
  6552. bottom: 0,
  6553. left: 0,
  6554. right: 0,
  6555. front: 0,
  6556. back: 0,
  6557. type: "VALID"
  6558. }, f = Math.ceil((e - u + 1) / o), p = Math.ceil((n - s + 1) / a), d = Math.ceil((r - c + 1) / i);
  6559. }
  6560. return {
  6561. padInfo: h,
  6562. outDepth: f,
  6563. outHeight: p,
  6564. outWidth: d
  6565. };
  6566. }(o, l, h, f, w, C, R, D, T, N, u),
  6567. O = F.padInfo,
  6568. _ = F.outDepth,
  6569. M = F.outHeight,
  6570. B = F.outWidth,
  6571. P = a ? x * p : x;
  6572. return "channelsFirst" === i ? d = [c, P, _, M, B] : "channelsLast" === i && (d = [c, _, M, B, P]), {
  6573. batchSize: c,
  6574. dataFormat: i,
  6575. inDepth: l,
  6576. inHeight: h,
  6577. inWidth: f,
  6578. inChannels: p,
  6579. outDepth: _,
  6580. outHeight: M,
  6581. outWidth: B,
  6582. outChannels: P,
  6583. padInfo: O,
  6584. strideDepth: w,
  6585. strideHeight: C,
  6586. strideWidth: R,
  6587. filterDepth: v,
  6588. filterHeight: m,
  6589. filterWidth: y,
  6590. effectiveFilterDepth: D,
  6591. effectiveFilterHeight: T,
  6592. effectiveFilterWidth: N,
  6593. dilationDepth: k,
  6594. dilationHeight: S,
  6595. dilationWidth: A,
  6596. inShape: t,
  6597. outShape: d,
  6598. filterShape: e
  6599. };
  6600. }
  6601. function xo(t, e, n, r) {
  6602. void 0 === r && (r = 1);
  6603. var o = Co(e, r);
  6604. return Math.floor((t[0] * (n - 1) - n + o) / 2);
  6605. }
  6606. function bo(t) {
  6607. return "number" == typeof t ? [t, t, t] : 2 === t.length ? [t[0], t[1], 1] : t;
  6608. }
  6609. function wo(t) {
  6610. return "number" == typeof t ? [t, t, t] : t;
  6611. }
  6612. function Co(t, e) {
  6613. return e <= 1 ? t : t + (t - 1) * (e - 1);
  6614. }
  6615. function Eo(t, e) {
  6616. if (!e) return t;
  6617. switch (e) {
  6618. case "round":
  6619. return Math.round(t);
  6620. case "ceil":
  6621. return Math.ceil(t);
  6622. case "floor":
  6623. return Math.floor(t);
  6624. default:
  6625. throw new Error("Unknown roundingMode " + e);
  6626. }
  6627. }
  6628. function Ro(t) {
  6629. var e = bo(t),
  6630. n = e[0],
  6631. r = e[1],
  6632. o = e[2];
  6633. return 1 === n && 1 === r && 1 === o;
  6634. }
  6635. function Io(t, e) {
  6636. return Ro(t) || Ro(e);
  6637. }
  6638. function ko(t) {
  6639. if ("NHWC" === t) return "channelsLast";
  6640. if ("NCHW" === t) return "channelsFirst";
  6641. throw new Error("Unknown dataFormat " + t);
  6642. }
  6643. function So(t, e, n) {
  6644. if ("complex64" === e) {
  6645. if ("complex64" === t.dtype) return t.clone();
  6646. var r = Pn(t.shape),
  6647. o = t.toFloat(),
  6648. a = n.complex(o, r);
  6649. return r.dispose(), o.dispose(), a;
  6650. }
  6651. if (!M(t.dtype, e)) return Nt.makeTensorFromDataId(t.dataId, t.shape, e);
  6652. if ("complex64" === t.dtype) {
  6653. var i = n.real(t);
  6654. a = i.cast(e);
  6655. return i.dispose(), a;
  6656. }
  6657. if ("int32" === e) return n.int(t);
  6658. if ("bool" === e) {
  6659. var u = An(0, t.dtype);
  6660. a = n.notEqual(t, u);
  6661. return u.dispose(), a;
  6662. }
  6663. throw new Error("Error in Cast: failed to cast " + t.dtype + " to " + e);
  6664. }
  6665. function Ao(t, e) {
  6666. return Nt.makeTensorFromDataId(t.dataId, e, t.dtype);
  6667. }
  6668. function Do(t, e, n) {
  6669. var r = (e - t) / (n - 1),
  6670. o = $(n, "float32");
  6671. o[0] = t;
  6672. for (var a = 1; a < o.length; a++) o[a] = o[a - 1] + r;
  6673. return Dn(o, "float32");
  6674. }
  6675. var To = Object.freeze({
  6676. castTensor: So,
  6677. reshapeTensor: Ao,
  6678. linspaceImpl: Do,
  6679. upcastType: Ct,
  6680. axesAreInnerMostDims: fn,
  6681. combineLocations: pn,
  6682. computeOutAndReduceShapes: dn,
  6683. expandShapeToKeepDim: vn,
  6684. assertAxesAreInnerMostDims: mn,
  6685. getAxesPermutation: gn,
  6686. getUndoAxesPermutation: yn,
  6687. getInnerMostAxes: xn,
  6688. getBroadcastDims: ho,
  6689. getReductionAxes: fo,
  6690. assertAndGetBroadcastShape: po,
  6691. assertParamsConsistent: bn,
  6692. computeOutShape: wn,
  6693. computePool2DInfo: vo,
  6694. computePool3DInfo: mo,
  6695. computeConv2DInfo: go,
  6696. computeConv3DInfo: yo,
  6697. computeDefaultPad: xo,
  6698. tupleValuesAreOne: Ro,
  6699. eitherStridesOrDilationsAreOne: Io,
  6700. convertConv2DDataFormat: ko
  6701. });
  6702. exports.backend_util = To;
  6703. function No(t, e) {
  6704. if (t.length !== e.length) throw new Error("Cannot merge real and imag arrays of different lengths. real:" + t.length + ", imag: " + e.length + ".");
  6705. for (var n = new Float32Array(2 * t.length), r = 0; r < n.length; r += 2) n[r] = t[r / 2], n[r + 1] = e[r / 2];
  6706. return n;
  6707. }
  6708. function Fo(t, e) {
  6709. return {
  6710. real: t[2 * e],
  6711. imag: t[2 * e + 1]
  6712. };
  6713. }
  6714. function Oo(t, e, n, r) {
  6715. t[2 * r] = e, t[2 * r + 1] = n;
  6716. }
  6717. function _o(t, e, n) {
  6718. var r = (n ? 2 : -2) * Math.PI * (t / e);
  6719. return {
  6720. real: Math.cos(r),
  6721. imag: Math.sin(r)
  6722. };
  6723. }
  6724. function Mo(t, e, n, r, o) {
  6725. for (var a = Array.from(e).map(function (t, e) {
  6726. return {
  6727. score: t,
  6728. boxIndex: e
  6729. };
  6730. }).filter(function (t) {
  6731. return t.score > o;
  6732. }).sort(function (t, e) {
  6733. return e.score - t.score;
  6734. }), i = [], u = 0; u < a.length; u++) {
  6735. var s = a[u],
  6736. c = s.score,
  6737. l = s.boxIndex;
  6738. if (c < o) break;
  6739. for (var h = !1, f = i.length - 1; f >= 0; --f) {
  6740. if (Bo(t, l, i[f]) >= r) {
  6741. h = !0;
  6742. break;
  6743. }
  6744. }
  6745. if (!h && (i.push(l), i.length >= n)) break;
  6746. }
  6747. return Dn(i, "int32");
  6748. }
  6749. function Bo(t, e, n) {
  6750. var r = t.subarray(4 * e, 4 * e + 4),
  6751. o = t.subarray(4 * n, 4 * n + 4),
  6752. a = Math.min(r[0], r[2]),
  6753. i = Math.min(r[1], r[3]),
  6754. u = Math.max(r[0], r[2]),
  6755. s = Math.max(r[1], r[3]),
  6756. c = Math.min(o[0], o[2]),
  6757. l = Math.min(o[1], o[3]),
  6758. h = Math.max(o[0], o[2]),
  6759. f = Math.max(o[1], o[3]),
  6760. p = (u - a) * (s - i),
  6761. d = (h - c) * (f - l);
  6762. if (p <= 0 || d <= 0) return 0;
  6763. var v = Math.max(a, c),
  6764. m = Math.max(i, l),
  6765. g = Math.min(u, h),
  6766. y = Math.min(s, f),
  6767. x = Math.max(g - v, 0) * Math.max(y - m, 0);
  6768. return x / (p + d - x);
  6769. }
  6770. function Po(t, e, n) {
  6771. var r = new Array(t.rank).fill(0),
  6772. o = t.shape.slice();
  6773. return e.map(function (e) {
  6774. o[n] = e;
  6775. var a = t.slice(r, o);
  6776. return r[n] += e, a;
  6777. });
  6778. }
  6779. function Lo(t, e) {
  6780. for (var n = new Array(t.rank), r = 0; r < n.length; r++) n[r] = t.shape[r] * e[r];
  6781. var o = ur(n, t.dtype);
  6782. for (r = 0; r < o.values.length; ++r) {
  6783. for (var a = o.indexToLoc(r), i = new Array(t.rank), u = 0; u < i.length; u++) i[u] = a[u] % t.shape[u];
  6784. var s = t.locToIndex(i);
  6785. o.values[r] = t.values[s];
  6786. }
  6787. return o.toTensor();
  6788. }
  6789. function Wo(t, e, n, r, o) {
  6790. for (var a = e[e.length - 1], i = [t.length / a, a], u = i[0], s = i[1], c = N(n, u * r), l = N("int32", u * r), h = 0; h < u; h++) {
  6791. for (var f = h * s, p = t.subarray(f, f + s), d = [], v = 0; v < p.length; v++) d.push({
  6792. value: p[v],
  6793. index: v
  6794. });
  6795. d.sort(function (t, e) {
  6796. return e.value - t.value;
  6797. });
  6798. var m = h * r,
  6799. g = c.subarray(m, m + r),
  6800. y = l.subarray(m, m + r);
  6801. for (v = 0; v < r; v++) g[v] = d[v].value, y[v] = d[v].index;
  6802. }
  6803. var x = e.slice();
  6804. return x[x.length - 1] = r, [kn(c, x, n), kn(l, x, "int32")];
  6805. }
  6806. function Uo(t, e) {
  6807. for (var n = [], r = 0; r < e.length; r++) e[r] && n.push(r);
  6808. var o = ur(t, "int32"),
  6809. a = ur([n.length, t.length], "int32");
  6810. for (r = 0; r < n.length; r++) {
  6811. var i = o.indexToLoc(n[r]),
  6812. u = r * t.length;
  6813. a.values.set(i, u);
  6814. }
  6815. return a.toTensor();
  6816. }
  6817. var Vo = function () {
  6818. return function (t, e) {
  6819. this.outputShape = [], this.outputShape = t, this.variableNames = e.map(function (t, e) {
  6820. return "T" + e;
  6821. });
  6822. var n = [];
  6823. this.variableNames.forEach(function (t) {
  6824. n.push("float v" + t + " = get" + t + "AtOutCoords();");
  6825. });
  6826. var r = this.variableNames.map(function (t) {
  6827. return "v" + t;
  6828. }).join(" + ");
  6829. this.userCode = "\n void main() {\n " + n.join("\n ") + "\n\n float result = " + r + ";\n setOutput(result);\n }\n ";
  6830. };
  6831. }(),
  6832. zo = function () {
  6833. return function (t, e) {
  6834. this.outputShape = [], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t, this.variableNames = e.map(function (t, e) {
  6835. return "T" + e;
  6836. });
  6837. var n = [];
  6838. this.variableNames.forEach(function (t) {
  6839. n.push("vec4 v" + t + " = get" + t + "AtOutCoords();");
  6840. });
  6841. var r = this.variableNames.map(function (t) {
  6842. return "v" + t;
  6843. }).join(" + ");
  6844. this.userCode = "\n void main() {\n " + n.join("\n ") + "\n\n vec4 result = " + r + ";\n setOutput(result);\n }\n ";
  6845. };
  6846. }(),
  6847. Go = function () {
  6848. return function (t, e, n) {
  6849. this.variableNames = ["A"];
  6850. var r = t.windowSize,
  6851. o = t.batchSize,
  6852. a = t.inSize,
  6853. i = Math.ceil(a / r);
  6854. n || this.variableNames.push("bestIndicesA"), this.outputShape = [o, i];
  6855. var u = "max" === e ? ">" : "<",
  6856. s = n ? "inOffset + i;" : "round(getBestIndicesA(batch, inOffset + i));";
  6857. this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * " + r + ";\n\n int bestIndex = inOffset;\n float bestValue = getA(batch, bestIndex);\n\n for (int i = 0; i < " + r + "; i++) {\n int inIdx = " + s + ";\n float candidate = getA(batch, inIdx);\n if (candidate " + u + " bestValue) {\n bestValue = candidate;\n bestIndex = inIdx;\n }\n }\n setOutput(float(bestIndex));\n }\n ";
  6858. };
  6859. }();
  6860. function Ho(t, e) {
  6861. return ["x", "y", "z", "w", "u", "v"].slice(0, e).map(function (e) {
  6862. return t + "." + e;
  6863. });
  6864. }
  6865. function qo(t, e) {
  6866. return 1 === e ? [t] : Ho(t, e);
  6867. }
  6868. function Ko() {
  6869. var t, e, n, r, o, i, u, s, c, l;
  6870. return 2 === a().getNumber("WEBGL_VERSION") ? (t = "#version 300 es", e = "in", n = "out", r = "in", o = "texture", i = "outputColor", u = "out vec4 outputColor;", s = "\n bool isnan_custom(float val) {\n return (val > 0.0 || val < 0.0) ? false : val != 0.0;\n }\n\n bvec4 isnan_custom(vec4 val) {\n return bvec4(isnan_custom(val.x),\n isnan_custom(val.y), isnan_custom(val.z), isnan_custom(val.w));\n }\n\n #define isnan(value) isnan_custom(value)\n ", c = "", l = "\n #define round(value) newRound(value)\n int newRound(float value) {\n return int(floor(value + 0.5));\n }\n\n ivec4 newRound(vec4 value) {\n return ivec4(floor(value + vec4(0.5)));\n }\n ") : (t = "", e = "attribute", n = "varying", r = "varying", o = "texture2D", i = "gl_FragColor", u = "", s = "\n #define isnan(value) isnan_custom(value)\n bool isnan_custom(float val) {\n return (val > 0. || val < 1. || val == 0.) ? false : true;\n }\n bvec4 isnan_custom(vec4 val) {\n return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));\n }\n ", c = "\n uniform float INFINITY;\n\n bool isinf(float val) {\n return abs(val) == INFINITY;\n }\n bvec4 isinf(vec4 val) {\n return equal(abs(val), vec4(INFINITY));\n }\n ", l = "\n int round(float value) {\n return int(floor(value + 0.5));\n }\n\n ivec4 round(vec4 value) {\n return ivec4(floor(value + vec4(0.5)));\n }\n "), {
  6871. version: t,
  6872. attribute: e,
  6873. varyingVs: n,
  6874. varyingFs: r,
  6875. texture2D: o,
  6876. output: i,
  6877. defineOutput: u,
  6878. defineSpecialNaN: s,
  6879. defineSpecialInf: c,
  6880. defineRound: l
  6881. };
  6882. }
  6883. function jo(t, e, n) {
  6884. void 0 === n && (n = "index");
  6885. var r = q(e);
  6886. return r.map(function (e, o) {
  6887. return "int " + t[o] + " = " + n + " / " + e + "; " + (o === r.length - 1 ? "int " + t[o + 1] + " = " + n + " - " + t[o] + " * " + e : "index -= " + t[o] + " * " + e) + ";";
  6888. }).join("");
  6889. }
  6890. function Xo(t) {
  6891. var e = q(t).map(function (t) {
  6892. return t.toString();
  6893. });
  6894. return "\n int getFlatIndex(ivec3 coords) {\n return coords.x * " + e[0] + " + coords.y * " + e[1] + " + coords.z;\n }\n";
  6895. }
  6896. var $o = "\n const float FLOAT_MAX = 1.70141184e38;\n const float FLOAT_MIN = 1.17549435e-38;\n\n lowp vec4 encode_float(highp float v) {\n if (isnan(v)) {\n return vec4(255, 255, 255, 255);\n }\n\n highp float av = abs(v);\n\n if(av < FLOAT_MIN) {\n return vec4(0.0, 0.0, 0.0, 0.0);\n } else if(v > FLOAT_MAX) {\n return vec4(0.0, 0.0, 128.0, 127.0) / 255.0;\n } else if(v < -FLOAT_MAX) {\n return vec4(0.0, 0.0, 128.0, 255.0) / 255.0;\n }\n\n highp vec4 c = vec4(0,0,0,0);\n\n highp float e = floor(log2(av));\n highp float m = exp2(fract(log2(av))) - 1.0;\n\n c[2] = floor(128.0 * m);\n m -= c[2] / 128.0;\n c[1] = floor(32768.0 * m);\n m -= c[1] / 32768.0;\n c[0] = floor(8388608.0 * m);\n\n highp float ebias = e + 127.0;\n c[3] = floor(ebias / 2.0);\n ebias -= c[3] * 2.0;\n c[2] += floor(ebias) * 128.0;\n\n c[3] += 128.0 * step(0.0, -v);\n\n return c / 255.0;\n }\n";
  6897. function Yo(t, e, n, r) {
  6898. var o = [];
  6899. t.forEach(function (t) {
  6900. var e = w(t.shapeInfo.logicalShape);
  6901. t.shapeInfo.isUniform ? o.push("uniform float " + t.name + (e > 1 ? "[" + e + "]" : "") + ";") : (o.push("uniform sampler2D " + t.name + ";"), o.push("uniform int offset" + t.name + ";"));
  6902. });
  6903. var a,
  6904. i,
  6905. u = o.join("\n"),
  6906. s = t.map(function (t) {
  6907. return function (t, e, n) {
  6908. void 0 === n && (n = !1);
  6909. var r = "";
  6910. r += n ? Jo(t) : Qo(t);
  6911. var o = t.shapeInfo.logicalShape,
  6912. a = e.logicalShape;
  6913. o.length <= a.length && (r += n ? function (t, e) {
  6914. var n,
  6915. r = t.name,
  6916. o = r.charAt(0).toUpperCase() + r.slice(1),
  6917. a = "get" + o + "AtOutCoords",
  6918. i = t.shapeInfo.logicalShape.length,
  6919. u = e.logicalShape.length,
  6920. s = ho(t.shapeInfo.logicalShape, e.logicalShape),
  6921. c = aa(u),
  6922. l = u - i,
  6923. h = ["x", "y", "z", "w", "u", "v"];
  6924. n = 0 === i ? "" : u < 2 && s.length >= 1 ? "coords = 0;" : s.map(function (t) {
  6925. return "coords." + h[t + l] + " = 0;";
  6926. }).join("\n");
  6927. var f = "";
  6928. f = u < 2 && i > 0 ? "coords" : t.shapeInfo.logicalShape.map(function (t, e) {
  6929. return "coords." + h[e + l];
  6930. }).join(", ");
  6931. var p = "return outputValue;",
  6932. d = 1 === w(t.shapeInfo.logicalShape),
  6933. v = 1 === w(e.logicalShape);
  6934. if (1 !== i || d || v) {
  6935. if (d && !v) p = 1 === u ? "\n return vec4(outputValue.x, outputValue.x, 0., 0.);\n " : "\n return vec4(outputValue.x);\n "; else if (s.length) {
  6936. var m = i - 2,
  6937. g = i - 1;
  6938. s.indexOf(m) > -1 && s.indexOf(g) > -1 ? p = "return vec4(outputValue.x);" : s.indexOf(m) > -1 ? p = "return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);" : s.indexOf(g) > -1 && (p = "return vec4(outputValue.xx, outputValue.zz);");
  6939. }
  6940. } else p = "\n return vec4(outputValue.xy, outputValue.xy);\n ";
  6941. return "\n vec4 " + a + "() {\n " + c + " coords = getOutputCoords();\n " + n + "\n vec4 outputValue = get" + o + "(" + f + ");\n " + p + "\n }\n ";
  6942. }(t, e) : function (t, e) {
  6943. var n = t.name,
  6944. r = n.charAt(0).toUpperCase() + n.slice(1),
  6945. o = "get" + r + "AtOutCoords",
  6946. a = e.texShape,
  6947. i = t.shapeInfo.texShape,
  6948. u = t.shapeInfo.logicalShape.length,
  6949. s = e.logicalShape.length;
  6950. if (!t.shapeInfo.isUniform && u === s && null == t.shapeInfo.flatOffset && C(i, a)) return "\n float " + o + "() {\n return sampleTexture(" + n + ", resultUV);\n }\n ";
  6951. var c,
  6952. l = aa(s),
  6953. h = ho(t.shapeInfo.logicalShape, e.logicalShape),
  6954. f = s - u,
  6955. p = ["x", "y", "z", "w", "u", "v"];
  6956. c = 0 === u ? "" : s < 2 && h.length >= 1 ? "coords = 0;" : h.map(function (t) {
  6957. return "coords." + p[t + f] + " = 0;";
  6958. }).join("\n");
  6959. var d = "";
  6960. d = s < 2 && u > 0 ? "coords" : t.shapeInfo.logicalShape.map(function (t, e) {
  6961. return "coords." + p[e + f];
  6962. }).join(", ");
  6963. return "\n float " + o + "() {\n " + l + " coords = getOutputCoords();\n " + c + "\n return get" + r + "(" + d + ");\n }\n ";
  6964. }(t, e));
  6965. return r;
  6966. }(t, e, r);
  6967. }).join("\n"),
  6968. c = e.texShape,
  6969. l = Ko(),
  6970. h = function (t) {
  6971. return "\n float sampleTexture(sampler2D textureSampler, vec2 uv) {\n return " + t.texture2D + "(textureSampler, uv).r;\n }\n ";
  6972. }(l),
  6973. f = function (t) {
  6974. return t.version + "\n precision highp float;\n precision highp int;\n precision highp sampler2D;\n " + t.varyingFs + " vec2 resultUV;\n " + t.defineOutput + "\n const vec2 halfCR = vec2(0.5, 0.5);\n\n struct ivec5\n {\n int x;\n int y;\n int z;\n int w;\n int u;\n };\n\n struct ivec6\n {\n int x;\n int y;\n int z;\n int w;\n int u;\n int v;\n };\n\n uniform float NAN;\n " + t.defineSpecialNaN + "\n " + t.defineSpecialInf + "\n " + t.defineRound + "\n\n int imod(int x, int y) {\n return x - y * (x / y);\n }\n\n int idiv(int a, int b, float sign) {\n int res = a / b;\n int mod = imod(a, b);\n if (sign < 0. && mod != 0) {\n res -= 1;\n }\n return res;\n }\n\n //Based on the work of Dave Hoskins\n //https://www.shadertoy.com/view/4djSRW\n #define HASHSCALE1 443.8975\n float random(float seed){\n vec2 p = resultUV * seed;\n vec3 p3 = fract(vec3(p.xyx) * HASHSCALE1);\n p3 += dot(p3, p3.yzx + 19.19);\n return fract((p3.x + p3.y) * p3.z);\n }\n\n " + Zo + "\n " + ta + "\n " + ea + "\n ";
  6975. }(l);
  6976. return e.isPacked ? (a = function (t, e) {
  6977. switch (t.length) {
  6978. case 0:
  6979. return "\n int getOutputCoords() {\n return 0;\n }\n ";
  6980. case 1:
  6981. return function (t, e) {
  6982. var n = [Math.ceil(e[0] / 2), Math.ceil(e[1] / 2)];
  6983. if (1 === n[0]) return "\n int getOutputCoords() {\n return 2 * int(resultUV.x * " + n[1] + ".0);\n }\n ";
  6984. if (1 === n[1]) return "\n int getOutputCoords() {\n return 2 * int(resultUV.y * " + n[0] + ".0);\n }\n ";
  6985. return "\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + n[0] + ", " + n[1] + "));\n return 2 * (resTexRC.x * " + n[1] + " + resTexRC.y);\n }\n ";
  6986. }(0, e);
  6987. case 2:
  6988. return function (t, e) {
  6989. var n = [Math.ceil(e[0] / 2), Math.ceil(e[1] / 2)];
  6990. if (C(t, e)) return "\n ivec2 getOutputCoords() {\n return 2 * ivec2(resultUV.yx * vec2(" + n[0] + ", " + n[1] + "));\n }\n ";
  6991. var r = Math.ceil(t[1] / 2);
  6992. return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + n[0] + ", " + n[1] + "));\n\n int index = resTexRC.x * " + n[1] + " + resTexRC.y;\n int r = 2 * (index / " + r + ");\n int c = imod(index, " + r + ") * 2;\n\n return ivec2(r, c);\n }\n ";
  6993. }(t, e);
  6994. case 3:
  6995. return n = t, r = e, o = [Math.ceil(r[0] / 2), Math.ceil(r[1] / 2)], a = Math.ceil(n[2] / 2), i = a * Math.ceil(n[1] / 2), "\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + o[0] + ", " + o[1] + "));\n int index = resTexRC.x * " + o[1] + " + resTexRC.y;\n\n int b = index / " + i + ";\n index -= b * " + i + ";\n\n int r = 2 * (index / " + a + ");\n int c = imod(index, " + a + ") * 2;\n\n return ivec3(b, r, c);\n }\n ";
  6996. default:
  6997. return function (t, e) {
  6998. for (var n = [Math.ceil(e[0] / 2), Math.ceil(e[1] / 2)], r = Math.ceil(t[t.length - 1] / 2), o = r * Math.ceil(t[t.length - 2] / 2), a = o, i = "", u = "b, r, c", s = 2; s < t.length - 1; s++) a *= t[t.length - s - 1], i = "\n int b" + s + " = index / " + a + ";\n index -= b" + s + " * " + a + ";\n " + i, u = "b" + s + ", " + u;
  6999. return "\n ivec" + t.length + " getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + n[0] + ", " + n[1] + "));\n int index = resTexRC.x * " + n[1] + " + resTexRC.y;\n\n " + i + "\n\n int b = index / " + o + ";\n index -= b * " + o + ";\n\n int r = 2 * (index / " + r + ");\n int c = imod(index, " + r + ") * 2;\n\n return ivec" + t.length + "(" + u + ");\n }\n ";
  7000. }(t, e);
  7001. }
  7002. var n, r, o, a, i;
  7003. }(e.logicalShape, c), i = function (t) {
  7004. return "\n void setOutput(vec4 val) {\n " + t.output + " = val;\n }\n ";
  7005. }(l)) : (a = function (t, e) {
  7006. switch (t.length) {
  7007. case 0:
  7008. return "\n int getOutputCoords() {\n return 0;\n }\n ";
  7009. case 1:
  7010. return function (t, e) {
  7011. if (1 === e[0]) return "\n int getOutputCoords() {\n return int(resultUV.x * " + e[1] + ".0);\n }\n ";
  7012. if (1 === e[1]) return "\n int getOutputCoords() {\n return int(resultUV.y * " + e[0] + ".0);\n }\n ";
  7013. return "\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + e[0] + ", " + e[1] + "));\n return resTexRC.x * " + e[1] + " + resTexRC.y;\n }\n ";
  7014. }(0, e);
  7015. case 2:
  7016. return function (t, e) {
  7017. if (C(t, e)) return "\n ivec2 getOutputCoords() {\n return ivec2(resultUV.yx * vec2(" + e[0] + ", " + e[1] + "));\n }\n ";
  7018. if (1 === t[1]) return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + e[0] + ", " + e[1] + "));\n int index = resTexRC.x * " + e[1] + " + resTexRC.y;\n return ivec2(index, 0);\n }\n ";
  7019. if (1 === t[0]) return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + e[0] + ", " + e[1] + "));\n int index = resTexRC.x * " + e[1] + " + resTexRC.y;\n return ivec2(0, index);\n }\n ";
  7020. return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + e[0] + ", " + e[1] + "));\n int index = resTexRC.x * " + e[1] + " + resTexRC.y;\n int r = index / " + t[1] + ";\n int c = index - r * " + t[1] + ";\n return ivec2(r, c);\n }\n ";
  7021. }(t, e);
  7022. case 3:
  7023. return n = e, r = jo(["r", "c", "d"], t), "\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + n[0] + ", " + n[1] + "));\n int index = resTexRC.x * " + n[1] + " + resTexRC.y;\n " + r + "\n return ivec3(r, c, d);\n }\n ";
  7024. case 4:
  7025. return function (t, e) {
  7026. var n = jo(["r", "c", "d", "d2"], t);
  7027. return "\n ivec4 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + e[0] + ", " + e[1] + "));\n int index = resTexRC.x * " + e[1] + " + resTexRC.y;\n " + n + "\n return ivec4(r, c, d, d2);\n }\n ";
  7028. }(t, e);
  7029. case 5:
  7030. return function (t, e) {
  7031. var n = jo(["r", "c", "d", "d2", "d3"], t);
  7032. return "\n ivec5 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx * vec2(" + e[0] + ",\n " + e[1] + "));\n\n int index = resTexRC.x * " + e[1] + " + resTexRC.y;\n\n " + n + "\n\n ivec5 outShape = ivec5(r, c, d, d2, d3);\n return outShape;\n }\n ";
  7033. }(t, e);
  7034. case 6:
  7035. return function (t, e) {
  7036. var n = jo(["r", "c", "d", "d2", "d3", "d4"], t);
  7037. return "\n ivec6 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + e[0] + ", " + e[1] + "));\n int index = resTexRC.x * " + e[1] + " + resTexRC.y;\n\n " + n + "\n\n ivec6 result = ivec6(r, c, d, d2, d3, d4);\n return result;\n }\n ";
  7038. }(t, e);
  7039. default:
  7040. throw new Error(t.length + "-D output sampling is not yet supported");
  7041. }
  7042. var n, r;
  7043. }(e.logicalShape, c), i = function (t) {
  7044. return "\n void setOutput(float val) {\n " + t.output + " = vec4(val, 0, 0, 0);\n }\n ";
  7045. }(l)), r && (f += na), [f, h, i, u, a, s, n].join("\n");
  7046. }
  7047. function Qo(t) {
  7048. var e = t.shapeInfo.logicalShape;
  7049. switch (e.length) {
  7050. case 0:
  7051. return function (t) {
  7052. var e = t.name,
  7053. n = "get" + e.charAt(0).toUpperCase() + e.slice(1);
  7054. if (t.shapeInfo.isUniform) return "float " + n + "() {return " + e + ";}";
  7055. var r = t.shapeInfo.texShape,
  7056. o = r[0],
  7057. a = r[1];
  7058. if (1 === o && 1 === a) return "\n float " + n + "() {\n return sampleTexture(" + e + ", halfCR);\n }\n ";
  7059. var i = t.shapeInfo.texShape,
  7060. u = i[0],
  7061. s = i[1],
  7062. c = ra(e);
  7063. return "\n float " + n + "() {\n vec2 uv = uvFromFlat(" + u + ", " + s + ", " + c + ");\n return sampleTexture(" + e + ", uv);\n }\n ";
  7064. }(t);
  7065. case 1:
  7066. return function (t) {
  7067. var e = t.name,
  7068. n = "get" + e.charAt(0).toUpperCase() + e.slice(1);
  7069. if (t.shapeInfo.isUniform) return "\n float " + n + "(int index) {\n " + oa(t) + "\n }\n ";
  7070. var r = t.shapeInfo.texShape,
  7071. o = r[0],
  7072. a = r[1];
  7073. if (1 === a && 1 === o) return "\n float " + n + "(int index) {\n return sampleTexture(" + e + ", halfCR);\n }\n ";
  7074. var i = ra(e);
  7075. if (1 === a) return "\n float " + n + "(int index) {\n vec2 uv = vec2(0.5, (float(index + " + i + ") + 0.5) / " + o + ".0);\n return sampleTexture(" + e + ", uv);\n }\n ";
  7076. if (1 === o) return "\n float " + n + "(int index) {\n vec2 uv = vec2((float(index + " + i + ") + 0.5) / " + a + ".0, 0.5);\n return sampleTexture(" + e + ", uv);\n }\n ";
  7077. return "\n float " + n + "(int index) {\n vec2 uv = uvFromFlat(" + o + ", " + a + ", index + " + i + ");\n return sampleTexture(" + e + ", uv);\n }\n ";
  7078. }(t);
  7079. case 2:
  7080. return function (t) {
  7081. var e = t.shapeInfo.logicalShape,
  7082. n = t.name,
  7083. r = "get" + n.charAt(0).toUpperCase() + n.slice(1),
  7084. o = t.shapeInfo.texShape;
  7085. if (null != o && C(e, o)) {
  7086. var a = o[0],
  7087. i = o[1];
  7088. return "\n float " + r + "(int row, int col) {\n vec2 uv = (vec2(col, row) + halfCR) / vec2(" + i + ".0, " + a + ".0);\n return sampleTexture(" + n + ", uv);\n }\n ";
  7089. }
  7090. var u = T(e),
  7091. s = u.newShape,
  7092. c = u.keptDims,
  7093. l = s;
  7094. if (l.length < e.length) {
  7095. var h = ia(t, l);
  7096. return "\n " + Qo(h) + "\n float " + r + "(int row, int col) {\n return " + r + "(" + ua(["row", "col"], c) + ");\n }\n ";
  7097. }
  7098. if (t.shapeInfo.isUniform) return "\n float " + r + "(int row, int col) {\n int index = round(dot(vec2(row, col), vec2(" + e[1] + ", 1)));\n " + oa(t) + "\n }\n ";
  7099. var f = o[0],
  7100. p = o[1],
  7101. d = ra(n);
  7102. if (1 === p) return "\n float " + r + "(int row, int col) {\n float index = dot(vec3(row, col, " + d + "), vec3(" + e[1] + ", 1, 1));\n vec2 uv = vec2(0.5, (index + 0.5) / " + f + ".0);\n return sampleTexture(" + n + ", uv);\n }\n ";
  7103. if (1 === f) return "\n float " + r + "(int row, int col) {\n float index = dot(vec3(row, col, " + d + "), vec3(" + e[1] + ", 1, 1));\n vec2 uv = vec2((index + 0.5) / " + p + ".0, 0.5);\n return sampleTexture(" + n + ", uv);\n }\n ";
  7104. return "\n float " + r + "(int row, int col) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * " + e[1] + " + col + " + d + ";\n vec2 uv = uvFromFlat(" + f + ", " + p + ", index);\n return sampleTexture(" + n + ", uv);\n }\n";
  7105. }(t);
  7106. case 3:
  7107. return function (t) {
  7108. var e = t.shapeInfo.logicalShape,
  7109. n = t.name,
  7110. r = "get" + n.charAt(0).toUpperCase() + n.slice(1),
  7111. o = e[1] * e[2],
  7112. a = e[2],
  7113. i = T(e),
  7114. u = i.newShape,
  7115. s = i.keptDims,
  7116. c = u;
  7117. if (c.length < e.length) {
  7118. var l = ia(t, c);
  7119. return "\n " + Qo(l) + "\n float " + r + "(int row, int col, int depth) {\n return " + r + "(" + ua(["row", "col", "depth"], s) + ");\n }\n ";
  7120. }
  7121. if (t.shapeInfo.isUniform) return "\n float " + r + "(int row, int col, int depth) {\n int index = round(dot(vec3(row, col, depth),\n vec3(" + o + ", " + a + ", 1)));\n " + oa(t) + "\n }\n ";
  7122. var h = t.shapeInfo.texShape,
  7123. f = h[0],
  7124. p = h[1],
  7125. d = t.shapeInfo.flatOffset;
  7126. if (p === o && null == d) return "\n float " + r + "(int row, int col, int depth) {\n float texR = float(row);\n float texC = dot(vec2(col, depth), vec2(" + a + ", 1));\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + p + ".0, " + f + ".0);\n return sampleTexture(" + n + ", uv);\n }\n ";
  7127. if (p === a && null == d) return "\n float " + r + "(int row, int col, int depth) {\n float texR = dot(vec2(row, col), vec2(" + e[1] + ", 1));\n float texC = float(depth);\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2(" + p + ".0, " + f + ".0);\n return sampleTexture(" + n + ", uv);\n }\n ";
  7128. var v = ra(n);
  7129. return "\n float " + r + "(int row, int col, int depth) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * " + o + " + col * " + a + " + depth + " + v + ";\n vec2 uv = uvFromFlat(" + f + ", " + p + ", index);\n return sampleTexture(" + n + ", uv);\n }\n ";
  7130. }(t);
  7131. case 4:
  7132. return function (t) {
  7133. var e = t.shapeInfo.logicalShape,
  7134. n = t.name,
  7135. r = "get" + n.charAt(0).toUpperCase() + n.slice(1),
  7136. o = e[3],
  7137. a = e[2] * o,
  7138. i = e[1] * a,
  7139. u = T(e),
  7140. s = u.newShape,
  7141. c = u.keptDims;
  7142. if (s.length < e.length) {
  7143. var l = ia(t, s);
  7144. return "\n " + Qo(l) + "\n float " + r + "(int row, int col, int depth, int depth2) {\n return " + r + "(" + ua(["row", "col", "depth", "depth2"], c) + ");\n }\n ";
  7145. }
  7146. if (t.shapeInfo.isUniform) return "\n float " + r + "(int row, int col, int depth, int depth2) {\n int index = round(dot(vec4(row, col, depth, depth2),\n vec4(" + i + ", " + a + ", " + o + ", 1)));\n " + oa(t) + "\n }\n ";
  7147. var h = t.shapeInfo.flatOffset,
  7148. f = t.shapeInfo.texShape,
  7149. p = f[0],
  7150. d = f[1];
  7151. if (d === i && null == h) return "\n float " + r + "(int row, int col, int depth, int depth2) {\n float texR = float(row);\n float texC =\n dot(vec3(col, depth, depth2),\n vec3(" + a + ", " + o + ", 1));\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + d + ".0, " + p + ".0);\n return sampleTexture(" + n + ", uv);\n }\n ";
  7152. if (d === o && null == h) return "\n float " + r + "(int row, int col, int depth, int depth2) {\n float texR = dot(vec3(row, col, depth),\n vec3(" + e[1] * e[2] + ", " + e[2] + ", 1));\n float texC = float(depth2);\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + d + ".0, " + p + ".0);\n return sampleTexture(" + n + ", uv);\n }\n ";
  7153. var v = ra(n);
  7154. return "\n float " + r + "(int row, int col, int depth, int depth2) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * " + i + " + col * " + a + " +\n depth * " + o + " + depth2;\n vec2 uv = uvFromFlat(" + p + ", " + d + ", index + " + v + ");\n return sampleTexture(" + n + ", uv);\n }\n ";
  7155. }(t);
  7156. case 5:
  7157. return function (t) {
  7158. var e = t.shapeInfo.logicalShape,
  7159. n = t.name,
  7160. r = "get" + n.charAt(0).toUpperCase() + n.slice(1),
  7161. o = e[4],
  7162. a = e[3] * o,
  7163. i = e[2] * a,
  7164. u = e[1] * i,
  7165. s = T(e),
  7166. c = s.newShape,
  7167. l = s.keptDims;
  7168. if (c.length < e.length) {
  7169. var h = ia(t, c);
  7170. return "\n " + Qo(h) + "\n float " + r + "(int row, int col, int depth, int depth2, int depth3) {\n return " + r + "(" + ua(["row", "col", "depth", "depth2", "depth3"], l) + ");\n }\n ";
  7171. }
  7172. if (t.shapeInfo.isUniform) return "\n float " + r + "(int row, int col, int depth, int depth2, int depth3) {\n float index = dot(\n vec4(row, col, depth, depth2),\n vec4(" + u + ", " + i + ", " + a + ", " + o + ")) +\n depth3;\n " + oa(t) + "\n }\n ";
  7173. var f = t.shapeInfo.flatOffset,
  7174. p = t.shapeInfo.texShape,
  7175. d = p[0],
  7176. v = p[1];
  7177. if (v === u && null == f) return "\n float " + r + "(int row, int col, int depth, int depth2, int depth3) {\n int texR = row;\n float texC = dot(vec4(col, depth, depth2, depth3),\n vec4(" + i + ", " + a + ", " + o + ", 1));\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + v + ".0, " + d + ".0);\n return sampleTexture(" + n + ", uv);\n }\n ";
  7178. if (v === o && null == f) return "\n float " + r + "(int row, int col, int depth, int depth2, int depth3) {\n float texR = dot(\n vec4(row, col, depth, depth2),\n vec4(" + e[1] * e[2] * e[3] + ",\n " + e[2] * e[3] + ", " + e[3] + ", 1));\n int texC = depth3;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + v + ".0, " + d + ".0);\n return sampleTexture(" + n + ", uv);\n }\n ";
  7179. var m = ra(n);
  7180. return "\n float " + r + "(int row, int col, int depth, int depth2, int depth3) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * " + u + " + col * " + i + " + depth * " + a + " +\n depth2 * " + o + " + depth3 + " + m + ";\n vec2 uv = uvFromFlat(" + d + ", " + v + ", index);\n return sampleTexture(" + n + ", uv);\n }\n ";
  7181. }(t);
  7182. case 6:
  7183. return function (t) {
  7184. var e = t.shapeInfo.logicalShape,
  7185. n = t.name,
  7186. r = "get" + n.charAt(0).toUpperCase() + n.slice(1),
  7187. o = T(e),
  7188. a = o.newShape,
  7189. i = o.keptDims;
  7190. if (a.length < e.length) {
  7191. var u = ia(t, a);
  7192. return "\n " + Qo(u) + "\n float " + r + "(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n return " + r + "(" + ua(["row", "col", "depth", "depth2", "depth3", "depth4"], i) + ");\n }\n ";
  7193. }
  7194. var s = e[5],
  7195. c = e[4] * s,
  7196. l = e[3] * c,
  7197. h = e[2] * l,
  7198. f = e[1] * h;
  7199. if (t.shapeInfo.isUniform) return "\n float " + r + "(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n int index = round(dot(\n vec4(row, col, depth, depth2),\n vec4(" + f + ", " + h + ", " + l + ", " + c + ")) +\n dot(\n vec2(depth3, depth4),\n vec2(" + s + ", 1)));\n " + oa(t) + "\n }\n ";
  7200. var p = t.shapeInfo.flatOffset,
  7201. d = t.shapeInfo.texShape,
  7202. v = d[0],
  7203. m = d[1];
  7204. if (m === f && null == p) return "\n float " + r + "(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n int texR = row;\n float texC = dot(vec4(col, depth, depth2, depth3),\n vec4(" + h + ", " + l + ", " + c + ", " + s + ")) +\n float(depth4);\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + m + ".0, " + v + ".0);\n return sampleTexture(" + n + ", uv);\n }\n ";
  7205. if (m === s && null == p) return "\n float " + r + "(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n float texR = dot(vec4(row, col, depth, depth2),\n vec4(" + e[1] * e[2] * e[3] * e[4] + ",\n " + e[2] * e[3] * e[4] + ",\n " + e[3] * e[4] + ",\n " + e[4] + ")) + float(depth3);\n int texC = depth4;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + m + ".0, " + v + ".0);\n return sampleTexture(" + n + ", uv);\n }\n ";
  7206. var g = ra(n);
  7207. return "\n float " + r + "(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * " + f + " + col * " + h + " + depth * " + l + " +\n depth2 * " + c + " + depth3 * " + s + " + depth4 + " + g + ";\n vec2 uv = uvFromFlat(" + v + ", " + m + ", index);\n return sampleTexture(" + n + ", uv);\n }\n ";
  7208. }(t);
  7209. default:
  7210. throw new Error(e.length + "-D input sampling is not yet supported");
  7211. }
  7212. }
  7213. function Jo(t) {
  7214. var e, n, r;
  7215. switch (t.shapeInfo.logicalShape.length) {
  7216. case 0:
  7217. return e = t.name, n = "get" + e.charAt(0).toUpperCase() + e.slice(1), r = Ko(), "\n vec4 " + n + "() {\n return " + r.texture2D + "(" + e + ", halfCR);\n }\n ";
  7218. case 1:
  7219. return function (t) {
  7220. var e = t.name,
  7221. n = "get" + e.charAt(0).toUpperCase() + e.slice(1),
  7222. r = t.shapeInfo.texShape,
  7223. o = [Math.ceil(r[0] / 2), Math.ceil(r[1] / 2)],
  7224. a = Ko();
  7225. return "\n vec4 " + n + "(int index) {\n vec2 uv = packedUVfrom1D(\n " + o[0] + ", " + o[1] + ", index);\n return " + a.texture2D + "(" + e + ", uv);\n }\n ";
  7226. }(t);
  7227. case 2:
  7228. return function (t) {
  7229. var e = t.shapeInfo.logicalShape,
  7230. n = t.name,
  7231. r = "get" + n.charAt(0).toUpperCase() + n.slice(1),
  7232. o = t.shapeInfo.texShape,
  7233. a = o[0],
  7234. i = o[1],
  7235. u = Ko();
  7236. if (null != o && C(e, o)) return "\n vec4 " + r + "(int row, int col) {\n vec2 uv = (vec2(col, row) + halfCR) / vec2(" + i + ".0, " + a + ".0);\n\n return " + u.texture2D + "(" + n + ", uv);\n }\n ";
  7237. var s = [Math.ceil(o[0] / 2), Math.ceil(o[1] / 2)],
  7238. c = Math.ceil(e[1] / 2);
  7239. return "\n vec4 " + r + "(int row, int col) {\n vec2 uv = packedUVfrom2D(" + c + ", " + s[0] + ", " + s[1] + ", row, col);\n return " + u.texture2D + "(" + n + ", uv);\n }\n ";
  7240. }(t);
  7241. case 3:
  7242. return function (t) {
  7243. var e = t.shapeInfo.logicalShape,
  7244. n = t.name,
  7245. r = "get" + n.charAt(0).toUpperCase() + n.slice(1),
  7246. o = t.shapeInfo.texShape,
  7247. a = [Math.ceil(o[0] / 2), Math.ceil(o[1] / 2)];
  7248. if (1 === e[0]) {
  7249. var i = e.slice(1),
  7250. u = ia(t, i);
  7251. return "\n " + Jo(u) + "\n vec4 " + r + "(int b, int row, int col) {\n return " + r + "(" + ua(["b", "row", "col"], [1, 2]) + ");\n }\n ";
  7252. }
  7253. var s = a[0],
  7254. c = a[1],
  7255. l = Math.ceil(e[2] / 2),
  7256. h = l * Math.ceil(e[1] / 2),
  7257. f = Ko();
  7258. return "\n vec4 " + r + "(int b, int row, int col) {\n vec2 uv = packedUVfrom3D(\n " + s + ", " + c + ", " + h + ", " + l + ", b, row, col);\n return " + f.texture2D + "(" + n + ", uv);\n }\n ";
  7259. }(t);
  7260. default:
  7261. return function (t) {
  7262. for (var e = t.shapeInfo.logicalShape, n = e.length, r = t.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = t.shapeInfo.texShape, i = [Math.ceil(a[0] / 2), Math.ceil(a[1] / 2)], u = i[0], s = i[1], c = Math.ceil(e[n - 1] / 2), l = c * Math.ceil(e[n - 2] / 2), h = "int b, int row, int col", f = "b * " + l + " + (row / 2) * " + c + " + (col / 2)", p = 2; p < n - 1; p++) h = "int b" + p + ", " + h, l *= e[n - p - 1], f = "b" + p + " * " + l + " + " + f;
  7263. var d = Ko();
  7264. return "\n vec4 " + o + "(" + h + ") {\n int index = " + f + ";\n int texR = index / " + s + ";\n int texC = index - texR * " + s + ";\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2(" + s + ", " + u + ");\n return " + d.texture2D + "(" + r + ", uv);\n }\n ";
  7265. }(t);
  7266. }
  7267. }
  7268. var Zo = "\nvec2 uvFromFlat(int texNumR, int texNumC, int index) {\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\nvec2 packedUVfrom1D(int texNumR, int texNumC, int index) {\n int texelIndex = index / 2;\n int texR = texelIndex / texNumC;\n int texC = texelIndex - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n",
  7269. ta = "\nvec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,\n int texNumC, int row, int col) {\n int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);\n int texR = texelIndex / texNumC;\n int texC = texelIndex - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n",
  7270. ea = "\nvec2 packedUVfrom3D(int texNumR, int texNumC,\n int texelsInBatch, int texelsInLogicalRow, int b,\n int row, int col) {\n int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2);\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n",
  7271. na = "\n float getChannel(vec4 frag, vec2 innerDims) {\n vec2 modCoord = mod(innerDims, 2.);\n return modCoord.x == 0. ?\n (modCoord.y == 0. ? frag.r : frag.g) :\n (modCoord.y == 0. ? frag.b : frag.a);\n }\n float getChannel(vec4 frag, int dim) {\n float modCoord = mod(float(dim), 2.);\n return modCoord == 0. ? frag.r : frag.g;\n }\n";
  7272. function ra(t) {
  7273. return "offset" + t;
  7274. }
  7275. function oa(t) {
  7276. var e = t.name,
  7277. n = w(t.shapeInfo.logicalShape);
  7278. return n < 2 ? "return " + e + ";" : "\n for (int i = 0; i < " + n + "; i++) {\n if (i == index) {\n return " + e + "[i];\n }\n }\n ";
  7279. }
  7280. function aa(t) {
  7281. if (t <= 1) return "int";
  7282. if (2 === t) return "ivec2";
  7283. if (3 === t) return "ivec3";
  7284. if (4 === t) return "ivec4";
  7285. if (5 === t) return "ivec5";
  7286. if (6 === t) return "ivec6";
  7287. throw Error("GPU for rank " + t + " is not yet supported");
  7288. }
  7289. function ia(t, e) {
  7290. var n = JSON.parse(JSON.stringify(t));
  7291. return n.shapeInfo.logicalShape = e, n;
  7292. }
  7293. function ua(t, e) {
  7294. return e.map(function (e) {
  7295. return t[e];
  7296. }).join(", ");
  7297. }
  7298. var sa = function () {
  7299. return function (t, e, n, r) {
  7300. this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, g(t.length > 2, function () {
  7301. return "Packed arg" + (n.charAt(0).toUpperCase() + n.slice(1)) + " supports only inputs with rank above 2.";
  7302. });
  7303. var o = t[t.length - 1],
  7304. a = Math.ceil(o / e);
  7305. this.outputShape = t.slice(0, -1), a > 1 && this.outputShape.push(a), r || this.variableNames.push("bestIndicesA");
  7306. var i,
  7307. u,
  7308. s = this.outputShape,
  7309. c = s.length,
  7310. l = aa(c),
  7311. h = qo("coords", c);
  7312. if (1 === a) {
  7313. var f = aa(u = c + 1);
  7314. i = "\n " + f + " sourceLocR = " + f + "(" + h.join() + ", 0);\n ++" + h[c - 1] + ";\n " + f + " sourceLocG = " + f + "(" + h.join() + ", 0);\n ++" + h[c - 2] + ";\n " + f + " sourceLocA = " + f + "(" + h.join() + ", 0);\n --" + h[c - 1] + ";\n " + f + " sourceLocB = " + f + "(" + h.join() + ", 0);\n --" + h[c - 2] + ";";
  7315. } else u = c, i = "\n " + l + " sourceLocR = coords;\n ++" + h[c - 1] + ";\n " + l + " sourceLocG = coords;\n ++" + h[c - 2] + ";\n " + l + " sourceLocA = coords;\n --" + h[c - 1] + ";\n " + l + " sourceLocB = coords;\n --" + h[c - 2] + ";";
  7316. var p = ["x", "y", "z", "w", "u", "v"].slice(0, u),
  7317. d = "." + p[u - 1],
  7318. v = p.map(function (t) {
  7319. return "int " + t;
  7320. }),
  7321. m = qo("sourceLocR", u - 1).concat("inIdx.r"),
  7322. y = qo("sourceLocG", u - 1).concat("inIdx.g"),
  7323. x = qo("sourceLocB", u - 1).concat("inIdx.b"),
  7324. b = qo("sourceLocA", u - 1).concat("inIdx.a"),
  7325. w = "max" === n ? "greaterThan" : "lessThan",
  7326. C = r ? "" : "\n inIdx = round(vec4(getBestIndicesAChannel(" + m.join() + "),\n getBestIndicesAChannel(" + y.join() + "),\n getBestIndicesAChannel(" + x.join() + "),\n getBestIndicesAChannel(" + b.join() + ")));",
  7327. E = "vec4(\n getAChannel(" + m.join() + "),\n hasNextCol ? getAChannel(" + y.join() + ") : 0.,\n hasNextRow ? getAChannel(" + x.join() + ") : 0.,\n hasNextRow && hasNextCol ? getAChannel(" + b.join() + ") : 0.)",
  7328. R = r ? "" : "\n float getBestIndicesAChannel(" + v.join() + ") {\n return getChannel(getBestIndicesA(" + p.join() + "),\n vec2(" + p.slice(-2).join() + "));\n }";
  7329. this.userCode = "\n float getAChannel(" + v.join() + ") {\n return getChannel(getA(" + p.join() + "),\n vec2(" + p.slice(-2).join() + "));\n }\n " + R + "\n void main() {\n " + l + " coords = getOutputCoords();\n bool hasNextCol = " + h[c - 1] + " < " + (s[c - 1] - 1) + ";\n bool hasNextRow = " + h[c - 2] + " < " + (s[c - 2] - 1) + ";\n " + i + "\n ivec4 srcIdx = ivec4(sourceLocR" + d + ", sourceLocG" + d + ",\n sourceLocB" + d + ", sourceLocA" + d + ") * " + e + ";\n ivec4 inIdx = srcIdx;\n vec4 bestIndex = vec4(inIdx);\n vec4 bestValue = " + E + ";\n\n for (int i = 0; i < " + e + "; i++) {\n inIdx = srcIdx;\n " + C + "\n vec4 candidate = " + E + ";\n bvec4 nan = isnan(candidate);\n bvec4 replace = bvec4(\n vec4(" + w + "(candidate, bestValue)) * (vec4(1.0) - vec4(nan)));\n\n bestValue = vec4(replace.x ? candidate.x : bestValue.x,\n replace.y ? candidate.y : bestValue.y,\n replace.z ? candidate.z : bestValue.z,\n replace.w ? candidate.w : bestValue.w);\n bestIndex = mix(bestIndex, vec4(inIdx), vec4(replace));\n srcIdx++;\n }\n setOutput(bestIndex);\n }\n ";
  7330. };
  7331. }(),
  7332. ca = function () {
  7333. return function (t) {
  7334. this.variableNames = ["dy"], this.outputShape = t.inShape;
  7335. var e = t.filterHeight,
  7336. n = t.filterWidth,
  7337. r = t.strideHeight,
  7338. o = t.strideWidth,
  7339. a = t.dilationHeight,
  7340. i = t.dilationWidth,
  7341. u = t.effectiveFilterHeight,
  7342. s = t.effectiveFilterWidth,
  7343. c = u - 1 - t.padInfo.top,
  7344. l = s - 1 - t.padInfo.left,
  7345. h = 1 / (e * n);
  7346. this.userCode = "\n const ivec2 pads = ivec2(" + c + ", " + l + ");\n const float avgMultiplier = float(" + h + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + u + ";\n wR += " + a + ") {\n float dyR = float(dyRCorner + wR) / " + r + ".0;\n\n if (dyR < 0.0 || dyR >= " + t.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < " + s + ";\n wC+= " + i + ") {\n float dyC = float(dyCCorner + wC) / " + o + ".0;\n\n if (dyC < 0.0 || dyC >= " + t.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n\n dotProd += dyValue * avgMultiplier;\n }\n }\n setOutput(dotProd);\n }\n ";
  7347. };
  7348. }(),
  7349. la = function () {
  7350. return function (t) {
  7351. this.variableNames = ["dy"], this.outputShape = t.inShape;
  7352. var e = t.filterDepth,
  7353. n = t.filterHeight,
  7354. r = t.filterWidth,
  7355. o = t.strideDepth,
  7356. a = t.strideHeight,
  7357. i = t.strideWidth,
  7358. u = t.dilationDepth,
  7359. s = t.dilationHeight,
  7360. c = t.dilationWidth,
  7361. l = t.effectiveFilterDepth,
  7362. h = t.effectiveFilterHeight,
  7363. f = t.effectiveFilterWidth,
  7364. p = l - 1 - t.padInfo.front,
  7365. d = h - 1 - t.padInfo.top,
  7366. v = f - 1 - t.padInfo.left,
  7367. m = 1 / (e * n * r);
  7368. this.userCode = "\n const ivec3 pads = ivec3(" + p + ", " + d + ", " + v + ");\n const float avgMultiplier = float(" + m + ");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int ch = coords.u;\n\n ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;\n int dyDCorner = dyCorner.x;\n int dyRCorner = dyCorner.y;\n int dyCCorner = dyCorner.z;\n\n // Convolve dy(?, ?, ?, d) with pos mask(:, :, :, ch) to get\n // dx(xD, xR, xC, ch).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n\n for (int wD = 0; wD < " + l + ";\n wD += " + u + ") {\n float dyD = float(dyDCorner + wD) / " + o + ".0;\n\n if (dyD < 0.0 || dyD >= " + t.outDepth + ".0 || fract(dyD) > 0.0) {\n continue;\n }\n int idyD = int(dyD);\n\n for (int wR = 0; wR < " + h + ";\n wR += " + s + ") {\n float dyR = float(dyRCorner + wR) / " + a + ".0;\n\n if (dyR < 0.0 || dyR >= " + t.outHeight + ".0 ||\n fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < " + f + ";\n wC += " + c + ") {\n float dyC = float(dyCCorner + wC) / " + i + ".0;\n\n if (dyC < 0.0 || dyC >= " + t.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(batch, idyD, idyR, idyC, ch);\n\n dotProd += dyValue * avgMultiplier;\n }\n }\n }\n setOutput(dotProd);\n }\n ";
  7369. };
  7370. }(),
  7371. ha = function () {
  7372. return function (t, e, n, r, o, a) {
  7373. this.outputShape = [], this.variableNames = ["x", "mean", "variance"], po(t, e), po(t, n);
  7374. var i = "0.0";
  7375. null != r && (po(t, r), this.variableNames.push("offset"), i = "getOffsetAtOutCoords()");
  7376. var u = "1.0";
  7377. null != o && (po(t, o), this.variableNames.push("scale"), u = "getScaleAtOutCoords()"), this.outputShape = t, this.userCode = "\n void main() {\n float x = getXAtOutCoords();\n float mean = getMeanAtOutCoords();\n float variance = getVarianceAtOutCoords();\n float offset = " + i + ";\n float scale = " + u + ";\n float inv = scale * inversesqrt(variance + float(" + a + "));\n setOutput(dot(vec3(x, -mean, offset), vec3(inv, inv, 1)));\n }\n ";
  7378. };
  7379. }(),
  7380. fa = function () {
  7381. return function (t, e, n, r, o, a) {
  7382. this.packedInputs = !0, this.packedOutput = !0, this.variableNames = ["x", "mean", "variance"], po(t, e), po(t, n);
  7383. var i = "vec4(0.0)";
  7384. null != r && (po(t, r), this.variableNames.push("offset"), i = "getOffsetAtOutCoords()");
  7385. var u = "vec4(1.0)";
  7386. null != o && (po(t, o), this.variableNames.push("scale"), u = "getScaleAtOutCoords()"), this.outputShape = t, this.userCode = "\n void main() {\n vec4 offset = " + i + ";\n vec4 scale = " + u + ";\n\n vec4 x = getXAtOutCoords();\n vec4 mean = getMeanAtOutCoords();\n vec4 variance = getVarianceAtOutCoords();\n\n vec4 inv = scale * inversesqrt(variance + vec4(" + a + "));\n\n setOutput((x - mean) * inv + offset);\n }\n ";
  7387. };
  7388. }(),
  7389. pa = "return areal * breal - aimag * bimag;",
  7390. da = "return areal * bimag + aimag * breal;",
  7391. va = function () {
  7392. return function (t, e, n) {
  7393. this.variableNames = ["AReal", "AImag", "BReal", "BImag"], this.outputShape = po(e, n), this.userCode = "\n float binaryOpComplex(\n float areal, float aimag, float breal, float bimag) {\n " + t + "\n }\n\n void main() {\n float areal = getARealAtOutCoords();\n float aimag = getAImagAtOutCoords();\n float breal = getBRealAtOutCoords();\n float bimag = getBImagAtOutCoords();\n setOutput(binaryOpComplex(areal, aimag, breal, bimag));\n }\n ";
  7394. };
  7395. }(),
  7396. ma = "return a + b;",
  7397. ga = "return a - b;",
  7398. ya = "return a * b;",
  7399. xa = "return (a < 0.) ? b * a : a;",
  7400. ba = function () {
  7401. return function (t, e, n) {
  7402. this.variableNames = ["A", "B"], this.outputShape = po(e, n), this.userCode = "\n float binaryOperation(float a, float b) {\n " + t + "\n }\n\n void main() {\n float a = getAAtOutCoords();\n float b = getBAtOutCoords();\n setOutput(binaryOperation(a, b));\n }\n ";
  7403. };
  7404. }(),
  7405. wa = "\n vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));\n return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);\n",
  7406. Ca = function () {
  7407. return function (t, e, n, r) {
  7408. void 0 === r && (r = !1), this.variableNames = ["A", "B"], this.supportsBroadcasting = !0, this.packedInputs = !0, this.packedOutput = !0, this.outputShape = po(e, n);
  7409. var o = this.outputShape.length,
  7410. a = "";
  7411. if (r) if (0 === o || 1 === w(this.outputShape)) a = "\n result.y = 0.;\n result.z = 0.;\n result.w = 0.;\n "; else if (a = "\n " + aa(o) + " coords = getOutputCoords();\n ", 1 === o) a += "\n result.y = (coords + 1) >= " + this.outputShape[0] + " ? 0. : result.y;\n result.z = 0.;\n result.w = 0.;\n "; else {
  7412. var i = qo("coords", o);
  7413. a += "\n bool nextRowOutOfBounds =\n (" + i[o - 2] + " + 1) >= " + this.outputShape[o - 2] + ";\n bool nextColOutOfBounds =\n (" + i[o - 1] + " + 1) >= " + this.outputShape[o - 1] + ";\n result.y = nextColOutOfBounds ? 0. : result.y;\n result.z = nextRowOutOfBounds ? 0. : result.z;\n result.w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result.w;\n ";
  7414. }
  7415. this.userCode = "\n vec4 binaryOperation(vec4 a, vec4 b) {\n " + t + "\n }\n\n void main() {\n vec4 a = getAAtOutCoords();\n vec4 b = getBAtOutCoords();\n\n vec4 result = binaryOperation(a, b);\n " + a + "\n\n setOutput(result);\n }\n ";
  7416. };
  7417. }(),
  7418. Ea = function () {
  7419. function t(t) {
  7420. this.variableNames = ["A"], this.outputShape = t, this.userCode = "\n uniform float minVal;\n uniform float maxVal;\n\n void main() {\n float value = getAAtOutCoords();\n if (isnan(value)) {\n setOutput(value);\n return;\n }\n\n setOutput(clamp(value, minVal, maxVal));\n }\n ";
  7421. }
  7422. return t.prototype.getCustomSetupFunc = function (t, e) {
  7423. var n = this;
  7424. return function (r, o) {
  7425. null == n.minLoc && (n.minLoc = r.getUniformLocationNoThrow(o, "minVal"), n.maxLoc = r.getUniformLocationNoThrow(o, "maxVal")), r.gl.uniform1f(n.minLoc, t), r.gl.uniform1f(n.maxLoc, e);
  7426. };
  7427. }, t;
  7428. }(),
  7429. Ra = function () {
  7430. function t(t) {
  7431. this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t, this.userCode = "\n uniform float minVal;\n uniform float maxVal;\n\n void main() {\n vec4 value = getAAtOutCoords();\n\n if (any(isnan(value))) {\n setOutput(value);\n return;\n }\n\n setOutput(clamp(value, vec4(minVal), vec4(maxVal)));\n }\n ";
  7432. }
  7433. return t.prototype.getCustomSetupFunc = function (t, e) {
  7434. var n = this;
  7435. return function (r, o) {
  7436. null == n.minLoc && (n.minLoc = r.getUniformLocationNoThrow(o, "minVal"), n.maxLoc = r.getUniformLocationNoThrow(o, "maxVal")), r.gl.uniform1f(n.minLoc, t), r.gl.uniform1f(n.maxLoc, e);
  7437. };
  7438. }, t;
  7439. }(),
  7440. Ia = function () {
  7441. return function (t) {
  7442. this.variableNames = ["real", "imag"], this.outputShape = t, this.userCode = "\n void main() {\n float re = abs(getRealAtOutCoords());\n float im = abs(getImagAtOutCoords());\n float mx = max(re, im);\n\n // sadly the length function in glsl is not underflow-safe\n // (at least not on Intel GPUs). So the safe solution is\n // to ensure underflow-safety in all cases.\n setOutput(\n mx == 0.0 ? 0.0 : mx * length(vec2(1, min(re, im)/mx))\n );\n }\n ";
  7443. };
  7444. }(),
  7445. ka = function () {
  7446. return function (t) {
  7447. this.outputShape = [], this.outputShape = wn(t, 1), this.variableNames = t.map(function (t, e) {
  7448. return "T" + e;
  7449. });
  7450. var e = new Array(t.length - 1);
  7451. e[0] = t[0][1];
  7452. for (var n = 1; n < e.length; n++) e[n] = e[n - 1] + t[n][1];
  7453. var r = ["if (yC < " + e[0] + ") setOutput(getT0(yR, yC));"];
  7454. for (n = 1; n < e.length; n++) {
  7455. var o = e[n - 1];
  7456. r.push("else if (yC < " + e[n] + ") setOutput(getT" + n + "(yR, yC-" + o + "));");
  7457. }
  7458. var a = e.length,
  7459. i = e[e.length - 1];
  7460. r.push("else setOutput(getT" + a + "(yR, yC-" + i + "));"), this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n int yR = coords.x;\n int yC = coords.y;\n\n " + r.join("\n ") + "\n }\n ";
  7461. };
  7462. }(),
  7463. Sa = function () {
  7464. return function (t, e) {
  7465. this.packedInputs = !0, this.packedOutput = !0, this.outputShape = [], this.outputShape = wn(t, e);
  7466. var n = this.outputShape,
  7467. r = n.length,
  7468. o = aa(r),
  7469. a = qo("coords", r),
  7470. i = ["x", "y", "z", "w", "u", "v"].slice(0, r);
  7471. this.variableNames = t.map(function (t, e) {
  7472. return "T" + e;
  7473. });
  7474. var u = new Array(t.length - 1);
  7475. u[0] = t[0][e];
  7476. for (var s = 1; s < u.length; s++) u[s] = u[s - 1] + t[s][e];
  7477. var c = i[e],
  7478. l = i.slice(-2),
  7479. h = i.join(),
  7480. f = "if (" + c + " < " + u[0] + ") {\n return getChannel(\n getT0(" + h + "), vec2(" + l.join() + "));\n }";
  7481. for (s = 1; s < u.length; s++) {
  7482. var p = u[s - 1];
  7483. f += "\n if (" + c + " < " + u[s] + " && " + c + " >= " + u[s - 1] + ") {\n return getChannel(\n getT" + s + "(" + Aa(i, c, p) + "),\n vec2(" + Aa(l, c, p) + "));\n }";
  7484. }
  7485. var d = u.length,
  7486. v = u[u.length - 1];
  7487. f += "\n return getChannel(\n getT" + d + "(" + Aa(i, c, v) + "),\n vec2(" + Aa(l, c, v) + "));", this.userCode = "\n float getValue(" + i.map(function (t) {
  7488. return "int " + t;
  7489. }) + ") {\n " + f + "\n }\n\n void main() {\n " + o + " coords = getOutputCoords();\n vec4 result = vec4(getValue(" + a + "), 0., 0., 0.);\n\n " + a[r - 1] + " = " + a[r - 1] + " + 1;\n if (" + a[r - 1] + " < " + n[r - 1] + ") {\n result.g = getValue(" + a + ");\n }\n\n " + a[r - 2] + " = " + a[r - 2] + " + 1;\n if (" + a[r - 2] + " < " + n[r - 2] + ") {\n result.a = getValue(" + a + ");\n }\n\n " + a[r - 1] + " = " + a[r - 1] + " - 1;\n if (" + a[r - 2] + " < " + n[r - 2] + " &&\n " + a[r - 1] + " < " + n[r - 1] + ") {\n result.b = getValue(" + a + ");\n }\n setOutput(result);\n }\n ";
  7490. };
  7491. }();
  7492. function Aa(t, e, n) {
  7493. var r = t.indexOf(e);
  7494. return t.map(function (t, e) {
  7495. return e === r ? t + " - " + n : t;
  7496. }).join();
  7497. }
  7498. var Da = function () {
  7499. return function (t) {
  7500. this.variableNames = ["x", "dy"], this.outputShape = t.filterShape;
  7501. var e = t.strideHeight,
  7502. n = t.strideWidth,
  7503. r = t.padInfo.top,
  7504. o = t.padInfo.left,
  7505. a = "channelsLast" === t.dataFormat;
  7506. this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int wR = coords.x;\n int wC = coords.y;\n int d1 = coords.z;\n int d2 = coords.w;\n\n // Convolve x(?, ?, d1) with dy(:, :, d2) to get dw(wR, wC, d1, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n\n for (int b = 0; b < " + t.batchSize + "; b++) {\n for (int yR = 0; yR < " + t.outHeight + "; yR++) {\n int xR = wR + yR * " + e + " - " + r + ";\n\n if (xR < 0 || xR >= " + t.inHeight + ") {\n continue;\n }\n\n for (int yC = 0; yC < " + t.outWidth + "; yC++) {\n int xC = wC + yC * " + n + " - " + o + ";\n\n if (xC < 0 || xC >= " + t.inWidth + ") {\n continue;\n }\n\n if (" + a + ") {\n float dyValue = getDy(b, yR, yC, d2);\n float xValue = getX(b, xR, xC, d1);\n dotProd += (xValue * dyValue);\n } else {\n float dyValue = getDy(b, d2, yR, yC);\n float xValue = getX(b, d1, xR, xC);\n dotProd += (xValue * dyValue);\n }\n\n }\n }\n }\n setOutput(dotProd);\n }\n ";
  7507. };
  7508. }(),
  7509. Ta = function () {
  7510. return function (t) {
  7511. this.variableNames = ["dy", "W"], this.outputShape = t.inShape;
  7512. var e = t.filterHeight,
  7513. n = t.filterWidth,
  7514. r = t.strideHeight,
  7515. o = t.strideWidth,
  7516. a = "channelsLast" === t.dataFormat,
  7517. i = e - 1 - t.padInfo.top,
  7518. u = n - 1 - t.padInfo.left,
  7519. s = a ? 1 : 2,
  7520. c = a ? 2 : 3,
  7521. l = a ? 3 : 1;
  7522. this.userCode = "\n const ivec2 pads = ivec2(" + i + ", " + u + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d1 = coords[" + l + "];\n\n ivec2 dyCorner = ivec2(coords[" + s + "], coords[" + c + "]) - pads;\n int dyRCorner = dyCorner.x;\n int dyCCorner = dyCorner.y;\n\n // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + e + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + r + ".0;\n\n if (dyR < 0.0 || dyR >= " + t.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = " + e + " - 1 - wR;\n\n for (int wC = 0; wC < " + n + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + o + ".0;\n\n if (dyC < 0.0 || dyC >= " + t.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = " + n + " - 1 - wC;\n\n for (int d2 = 0; d2 < " + t.outChannels + "; d2++) {\n\n if (" + a + ") {\n float xValue = getDy(batch, idyR, idyC, d2);\n float wValue = getW(wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n } else {\n float xValue = getDy(batch, d2, idyR, idyC);\n float wValue = getW(wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n }\n\n }\n }\n }\n setOutput(dotProd);\n }\n ";
  7523. };
  7524. }(),
  7525. Na = function () {
  7526. return function (t) {
  7527. this.variableNames = ["x", "dy"], this.outputShape = t.filterShape;
  7528. var e = t.strideDepth,
  7529. n = t.strideHeight,
  7530. r = t.strideWidth,
  7531. o = t.padInfo.front,
  7532. a = t.padInfo.top,
  7533. i = t.padInfo.left;
  7534. this.userCode = "\n void main() {\n ivec5 coords = getOutputCoords();\n int wF = coords.x;\n int wR = coords.y;\n int wC = coords.z;\n int d1 = coords.w;\n int d2 = coords.u;\n\n float dotProd = 0.0;\n\n for (int b = 0; b < " + t.batchSize + "; b++) {\n for (int yF = 0; yF < " + t.outDepth + "; yF++) {\n int xF = wF + yF * " + e + " - " + o + ";\n\n if (xF < 0 || xF >= " + t.inDepth + ") {\n continue;\n }\n\n for (int yR = 0; yR < " + t.outHeight + "; yR++) {\n int xR = wR + yR * " + n + " - " + a + ";\n\n if (xR < 0 || xR >= " + t.inHeight + ") {\n continue;\n }\n\n for (int yC = 0; yC < " + t.outWidth + "; yC++) {\n int xC = wC + yC * " + r + " - " + i + ";\n\n if (xC < 0 || xC >= " + t.inWidth + ") {\n continue;\n }\n\n float dyValue = getDy(b, yF, yR, yC, d2);\n float xValue = getX(b, xF, xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n }\n }\n setOutput(dotProd);\n }\n ";
  7535. };
  7536. }(),
  7537. Fa = function () {
  7538. return function (t) {
  7539. this.variableNames = ["dy", "W"], this.outputShape = t.inShape;
  7540. var e = t.filterDepth,
  7541. n = t.filterHeight,
  7542. r = t.filterWidth,
  7543. o = t.strideDepth,
  7544. a = t.strideHeight,
  7545. i = t.strideWidth,
  7546. u = e - 1 - t.padInfo.front,
  7547. s = n - 1 - t.padInfo.top,
  7548. c = r - 1 - t.padInfo.left;
  7549. this.userCode = "\n const ivec3 pads = ivec3(" + u + ", " + s + ", " + c + ");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int d1 = coords.u;\n\n\n ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;\n int dyFCorner = dyCorner.x;\n int dyRCorner = dyCorner.y;\n int dyCCorner = dyCorner.z;\n\n float dotProd = 0.0;\n for (int wF = 0; wF < " + e + "; wF++) {\n float dyF = float(dyFCorner + wF) / " + o + ".0;\n\n if (dyF < 0.0 || dyF >= " + t.outDepth + ".0 || fract(dyF) > 0.0) {\n continue;\n }\n int idyF = int(dyF);\n\n int wFPerm = " + e + " - 1 - wF;\n\n for (int wR = 0; wR < " + n + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + a + ".0;\n\n if (dyR < 0.0 || dyR >= " + t.outHeight + ".0 ||\n fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = " + n + " - 1 - wR;\n\n for (int wC = 0; wC < " + r + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + i + ".0;\n\n if (dyC < 0.0 || dyC >= " + t.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = " + r + " - 1 - wC;\n\n for (int d2 = 0; d2 < " + t.outChannels + "; d2++) {\n float xValue = getDy(batch, idyF, idyR, idyC, d2);\n float wValue = getW(wFPerm, wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n }\n }\n }\n }\n setOutput(dotProd);\n }\n ";
  7550. };
  7551. }(),
  7552. Oa = function () {
  7553. return function (t) {
  7554. this.variableNames = ["x", "dy"], this.outputShape = t.filterShape;
  7555. var e = t.strideHeight,
  7556. n = t.strideWidth,
  7557. r = t.padInfo.top,
  7558. o = t.padInfo.left,
  7559. a = t.outChannels / t.inChannels;
  7560. this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int wR = coords.x;\n int wC = coords.y;\n int d1 = coords.z;\n int dm = coords.w;\n int d2 = d1 * " + a + " + dm;\n\n float dotProd = 0.0;\n\n // TO DO: Vec4 over the batch size\n for (int b = 0; b < " + t.batchSize + "; b++) {\n for (int yR = 0; yR < " + t.outHeight + "; yR++) {\n int xR = wR + yR * " + e + " - " + r + ";\n\n if (xR < 0 || xR >= " + t.inHeight + ") {\n continue;\n }\n\n for (int yC = 0; yC < " + t.outWidth + "; yC++) {\n int xC = wC + yC * " + n + " - " + o + ";\n\n if (xC < 0 || xC >= " + t.inWidth + ") {\n continue;\n }\n\n float dyValue = getDy(b, yR, yC, d2);\n float xValue = getX(b, xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n }\n setOutput(dotProd);\n }\n ";
  7561. };
  7562. }(),
  7563. _a = function () {
  7564. return function (t) {
  7565. this.variableNames = ["dy", "W"], this.outputShape = t.inShape;
  7566. var e = t.filterHeight,
  7567. n = t.filterWidth,
  7568. r = t.strideHeight,
  7569. o = t.strideWidth,
  7570. a = e - 1 - t.padInfo.top,
  7571. i = n - 1 - t.padInfo.left,
  7572. u = t.outChannels / t.inChannels;
  7573. this.userCode = "\n const ivec2 pads = ivec2(" + a + ", " + i + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d1 = coords[3];\n ivec2 dyCorner = coords.yz - pads;\n int dyRCorner = dyCorner.x;\n int dyCCorner = dyCorner.y;\n\n float dotProd = 0.0;\n\n for (int wR = 0; wR < " + e + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + r + ".0;\n\n if (dyR < 0.0 || dyR >= " + t.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = " + e + " - 1 - wR;\n\n for (int wC = 0; wC < " + n + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + o + ".0;\n\n if (dyC < 0.0 || dyC >= " + t.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = " + n + " - 1 - wC;\n\n // TO DO: Vec4 over the channelMul\n for (int dm = 0; dm < " + u + "; dm++) {\n int d2 = d1 * " + u + " + dm;\n float xValue = getDy(batch, idyR, idyC, d2);\n float wValue = getW(wRPerm, wCPerm, d1, dm);\n dotProd += xValue * wValue;\n }\n }\n }\n setOutput(dotProd);\n }\n ";
  7574. };
  7575. }(),
  7576. Ma = function () {
  7577. return function (t, e, n, r) {
  7578. void 0 === e && (e = !1), void 0 === n && (n = null), void 0 === r && (r = !1), this.variableNames = ["x", "W"], this.outputShape = t.outShape;
  7579. var o = t.padInfo.top,
  7580. a = t.padInfo.left,
  7581. i = t.strideHeight,
  7582. u = t.strideWidth,
  7583. s = t.dilationHeight,
  7584. c = t.dilationWidth,
  7585. l = t.filterHeight,
  7586. h = t.filterWidth,
  7587. f = 4 * Math.floor(t.inChannels / 4),
  7588. p = t.inChannels % 4,
  7589. d = "channelsLast" === t.dataFormat,
  7590. v = d ? 1 : 2,
  7591. m = d ? 2 : 3,
  7592. g = d ? 3 : 1,
  7593. y = "",
  7594. x = "";
  7595. n && (y = r ? "float activation(float a) {\n float b = getPreluActivationWeightsAtOutCoords();\n " + n + "\n }" : "\n float activation(float x) {\n " + n + "\n }\n ", x = "result = activation(result);");
  7596. var b = e ? "result += getBiasAtOutCoords();" : "";
  7597. e && this.variableNames.push("bias"), r && this.variableNames.push("preluActivationWeights"), this.userCode = "\n " + y + "\n\n const ivec2 strides = ivec2(" + i + ", " + u + ");\n const ivec2 pads = ivec2(" + o + ", " + a + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d2 = coords[" + g + "];\n\n ivec2 xRCCorner =\n ivec2(coords[" + v + "], coords[" + m + "]) * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + l + "; wR++) {\n int xR = xRCorner + wR * " + s + ";\n\n if (xR < 0 || xR >= " + t.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + h + "; wC++) {\n int xC = xCCorner + wC * " + c + ";\n\n if (xC < 0 || xC >= " + t.inWidth + ") {\n continue;\n }\n\n for (int d1 = 0; d1 < " + f + "; d1 += 4) {\n vec4 wValues = vec4(\n getW(wR, wC, d1, d2),\n getW(wR, wC, d1 + 1, d2),\n getW(wR, wC, d1 + 2, d2),\n getW(wR, wC, d1 + 3, d2)\n );\n\n if (" + d + ") {\n vec4 xValues = vec4(\n getX(batch, xR, xC, d1),\n getX(batch, xR, xC, d1 + 1),\n getX(batch, xR, xC, d1 + 2),\n getX(batch, xR, xC, d1 + 3)\n );\n dotProd += dot(xValues, wValues);\n } else {\n vec4 xValues = vec4(\n getX(batch, d1, xR, xC),\n getX(batch, d1 + 1, xR, xC),\n getX(batch, d1 + 2, xR, xC),\n getX(batch, d1 + 3, xR, xC)\n );\n dotProd += dot(xValues, wValues);\n }\n }\n\n if (" + (1 === p) + ") {\n\n if (" + d + ") {\n dotProd +=\n getX(batch, xR, xC, " + f + ") *\n getW(wR, wC, " + f + ", d2);\n } else {\n dotProd +=\n getX(batch, " + f + ", xR, xC) *\n getW(wR, wC, " + f + ", d2);\n }\n\n } else if (" + (2 === p) + ") {\n vec2 wValues = vec2(\n getW(wR, wC, " + f + ", d2),\n getW(wR, wC, " + f + " + 1, d2)\n );\n\n if (" + d + ") {\n vec2 xValues = vec2(\n getX(batch, xR, xC, " + f + "),\n getX(batch, xR, xC, " + f + " + 1)\n );\n dotProd += dot(xValues, wValues);\n } else {\n vec2 xValues = vec2(\n getX(batch, " + f + ", xR, xC),\n getX(batch, " + f + " + 1, xR, xC)\n );\n dotProd += dot(xValues, wValues);\n }\n\n } else if (" + (3 === p) + ") {\n vec3 wValues = vec3(\n getW(wR, wC, " + f + ", d2),\n getW(wR, wC, " + f + " + 1, d2),\n getW(wR, wC, " + f + " + 2, d2)\n );\n\n if (" + d + ") {\n vec3 xValues = vec3(\n getX(batch, xR, xC, " + f + "),\n getX(batch, xR, xC, " + f + " + 1),\n getX(batch, xR, xC, " + f + " + 2)\n );\n dotProd += dot(xValues, wValues);\n } else {\n vec3 xValues = vec3(\n getX(batch, " + f + ", xR, xC),\n getX(batch, " + f + " + 1, xR, xC),\n getX(batch, " + f + " + 2, xR, xC)\n );\n dotProd += dot(xValues, wValues);\n }\n\n }\n }\n }\n\n float result = dotProd;\n " + b + "\n " + x + "\n setOutput(result);\n }\n ";
  7598. };
  7599. }(),
  7600. Ba = function () {
  7601. return function (t) {
  7602. this.variableNames = ["x", "W"], this.outputShape = t.outShape;
  7603. var e = t.padInfo.front,
  7604. n = t.padInfo.top,
  7605. r = t.padInfo.left,
  7606. o = t.strideDepth,
  7607. a = t.strideHeight,
  7608. i = t.strideWidth,
  7609. u = t.dilationDepth,
  7610. s = t.dilationHeight,
  7611. c = t.dilationWidth,
  7612. l = t.filterDepth,
  7613. h = t.filterHeight,
  7614. f = t.filterWidth,
  7615. p = 4 * Math.floor(t.inChannels / 4),
  7616. d = t.inChannels % 4;
  7617. this.userCode = "\n const ivec3 strides = ivec3(" + o + ", " + a + ", " + i + ");\n const ivec3 pads = ivec3(" + e + ", " + n + ", " + r + ");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int d2 = coords.u;\n\n ivec3 xFRCCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;\n int xFCorner = xFRCCorner.x;\n int xRCorner = xFRCCorner.y;\n int xCCorner = xFRCCorner.z;\n\n // Convolve x(?, ?, ?, d1) with w(:, :, :, d1, d2) to get\n // y(yF, yR, yC, d2). ? = to be determined. : = across all\n // values in that axis.\n float dotProd = 0.0;\n for (int wF = 0; wF < " + l + "; wF++) {\n int xF = xFCorner + wF * " + u + ";\n\n if (xF < 0 || xF >= " + t.inDepth + ") {\n continue;\n }\n\n for (int wR = 0; wR < " + h + "; wR++) {\n int xR = xRCorner + wR * " + s + ";\n\n if (xR < 0 || xR >= " + t.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + f + "; wC++) {\n int xC = xCCorner + wC * " + c + ";\n\n if (xC < 0 || xC >= " + t.inWidth + ") {\n continue;\n }\n\n for (int d1 = 0; d1 < " + p + "; d1 += 4) {\n vec4 xValues = vec4(\n getX(batch, xF, xR, xC, d1),\n getX(batch, xF, xR, xC, d1 + 1),\n getX(batch, xF, xR, xC, d1 + 2),\n getX(batch, xF, xR, xC, d1 + 3)\n );\n vec4 wValues = vec4(\n getW(wF, wR, wC, d1, d2),\n getW(wF, wR, wC, d1 + 1, d2),\n getW(wF, wR, wC, d1 + 2, d2),\n getW(wF, wR, wC, d1 + 3, d2)\n );\n\n dotProd += dot(xValues, wValues);\n }\n\n if (" + (1 === d) + ") {\n dotProd +=\n getX(batch, xF, xR, xC, " + p + ") *\n getW(wF, wR, wC, " + p + ", d2);\n } else if (" + (2 === d) + ") {\n vec2 xValues = vec2(\n getX(batch, xF, xR, xC, " + p + "),\n getX(batch, xF, xR, xC, " + p + " + 1)\n );\n vec2 wValues = vec2(\n getW(wF, wR, wC, " + p + ", d2),\n getW(wF, wR, wC, " + p + " + 1, d2)\n );\n dotProd += dot(xValues, wValues);\n } else if (" + (3 === d) + ") {\n vec3 xValues = vec3(\n getX(batch, xF, xR, xC, " + p + "),\n getX(batch, xF, xR, xC, " + p + " + 1),\n getX(batch, xF, xR, xC, " + p + " + 2)\n );\n vec3 wValues = vec3(\n getW(wF, wR, wC, " + p + ", d2),\n getW(wF, wR, wC, " + p + " + 1, d2),\n getW(wF, wR, wC, " + p + " + 2, d2)\n );\n dotProd += dot(xValues, wValues);\n }\n }\n }\n }\n setOutput(dotProd);\n }\n ";
  7618. };
  7619. }(),
  7620. Pa = function () {
  7621. return function (t, e, n, r) {
  7622. void 0 === e && (e = !1), void 0 === n && (n = null), void 0 === r && (r = !1), this.variableNames = ["x", "W"], this.outputShape = t.outShape;
  7623. var o = t.inHeight,
  7624. a = t.inWidth,
  7625. i = t.padInfo.top,
  7626. u = t.padInfo.left,
  7627. s = t.strideHeight,
  7628. c = t.strideWidth,
  7629. l = t.dilationHeight,
  7630. h = t.dilationWidth,
  7631. f = t.filterHeight,
  7632. p = t.filterWidth,
  7633. d = t.outChannels / t.inChannels,
  7634. v = "",
  7635. m = "";
  7636. n && (v = r ? "float activation(float a) {\n float b = getPreluActivationWeightsAtOutCoords();\n " + n + "\n }" : "\n float activation(float x) {\n " + n + "\n }\n ", m = "result = activation(result);");
  7637. var g = e ? "result += getBiasAtOutCoords();" : "";
  7638. e && this.variableNames.push("bias"), r && this.variableNames.push("preluActivationWeights"), this.userCode = "\n " + v + "\n\n const ivec2 strides = ivec2(" + s + ", " + c + ");\n const ivec2 pads = ivec2(" + i + ", " + u + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords.x;\n ivec2 xRCCorner = coords.yz * strides - pads;\n int d2 = coords.w;\n int d1 = d2 / " + d + ";\n int q = d2 - d1 * " + d + ";\n\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n // TO DO(dsmilkov): Flatten the two for loops and vec4 the operations.\n for (int wR = 0; wR < " + f + "; wR++) {\n int xR = xRCorner + wR * " + l + ";\n\n if (xR < 0 || xR >= " + o + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + p + "; wC++) {\n int xC = xCCorner + wC * " + h + ";\n\n if (xC < 0 || xC >= " + a + ") {\n continue;\n }\n\n float xVal = getX(batch, xR, xC, d1);\n float wVal = getW(wR, wC, d1, q);\n dotProd += xVal * wVal;\n }\n }\n\n float result = dotProd;\n " + g + "\n " + m + "\n setOutput(result);\n }\n ";
  7639. };
  7640. }(),
  7641. La = function () {
  7642. return function (t, e, n, r) {
  7643. void 0 === e && (e = !1), void 0 === n && (n = null), void 0 === r && (r = !1), this.variableNames = ["x", "W"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t.outShape;
  7644. for (var o = t.inHeight, a = t.inWidth, i = t.padInfo.top, u = t.padInfo.left, s = t.strideHeight, c = t.strideWidth, l = t.dilationHeight, h = t.dilationWidth, f = t.filterHeight, p = t.filterWidth, d = p, m = "int xR; int xC; int xCOffset;", g = 0; g < f; g++) for (var y = 0; y < p; y++) m += "\n vec4 xTexelR" + g + "C" + 2 * y + " = vec4(0.);\n vec4 wR" + g + "C" + y + " = vec4(0.);\n vec4 xR" + g + "C" + y + " = vec4(0.);";
  7645. for (g = 0; g < f; g++) for (var x = 0; x < d; x++) {
  7646. if (m += "\n xR = xRCorner + " + g * l + ";\n xC = xCCorner + " + (y = 2 * x) * h + ";\n ", 1 === c) {
  7647. if (y < p && (m += u % 2 == 1 ? "\n xCOffset = xC + 1;\n if(xR >= 0 && xR < " + o + " && xCOffset >= 0 && xCOffset < " + a + ") {\n xTexelR" + g + "C" + y + " = getX(batch, xR, xCOffset, d1);\n } else {\n xTexelR" + g + "C" + y + " = vec4(0.);\n }\n\n xCOffset = xC + 1 - 2;\n if(xR >= 0 && xR < " + o + " && xCOffset >= 0 && xCOffset < " + a + ") {\n vec4 previous = getX(batch, xR, xCOffset, d1);\n xR" + g + "C" + y + " = vec4(previous.zw, xTexelR" + g + "C" + y + ".xy);\n } else {\n xR" + g + "C" + y + " = vec4(0, 0, xTexelR" + g + "C" + y + ".xy);\n }\n " : "\n if(xR >= 0 && xR < " + o + " && xC >= 0 && xC < " + a + ") {\n xTexelR" + g + "C" + y + " = getX(batch, xR, xC, d1);\n } else {\n xTexelR" + g + "C" + y + " = vec4(0.);\n }\n\n xR" + g + "C" + y + " = xTexelR" + g + "C" + y + ";\n ", y + 1 < p)) {
  7648. var b = u % 2 == 0 ? v(h) : h;
  7649. h % 2 == 0 && u % 2 == 1 || h % 2 != 0 && u % 2 != 1 ? (m += "\n xCOffset = xC + " + u % 2 + " + " + b + ";\n\n if(xR >= 0 && xR < " + o + " &&\n xCOffset >= 0 && xCOffset < " + a + ") {\n xTexelR" + g + "C" + (y + 2) + " = getX(batch, xR, xCOffset, d1);\n }\n ", h > 1 && (m += "\n xCOffset -= 2;\n if(xR >= 0 && xR < " + o + " &&\n xCOffset >= 0 && xCOffset < " + a + ") {\n xTexelR" + g + "C" + y + " = getX(batch, xR, xCOffset, d1);\n } else {\n xTexelR" + g + "C" + y + " = vec4(0.);\n }\n "), m += "\n xR" + g + "C" + (y + 1) + " = vec4(\n xTexelR" + g + "C" + y + ".zw, xTexelR" + g + "C" + (y + 2) + ".xy);\n ") : m += "\n xCOffset = xC + " + b + ";\n\n if(xR >= 0 && xR < " + o + " &&\n xCOffset >= 0 && xCOffset < " + a + ") {\n xTexelR" + g + "C" + (y + 2) + " = getX(batch, xR, xCOffset, d1);\n }\n\n xR" + g + "C" + (y + 1) + " = xTexelR" + g + "C" + (y + 2) + ";\n ";
  7650. }
  7651. } else y < p && (m += "\n if(xR >= 0 && xR < " + o + ") {\n ", u % 2 == 1 ? (m += "\n xCOffset = xC + 1 - " + c + ";\n if(xCOffset >= 0 && xCOffset < " + a + ") {\n xTexelR" + g + "C" + y + " = getX(batch, xR, xCOffset, d1);\n } else {\n xTexelR" + g + "C" + y + " = vec4(0.);\n }\n\n if(xC + 1 >= 0 && xC + 1 < " + a + ") {\n xTexelR" + g + "C" + (y + 2) + " = getX(batch, xR, xC + 1, d1);\n } else {\n xTexelR" + g + "C" + (y + 2) + " = vec4(0.);\n }\n\n xR" + g + "C" + y + " = vec4(\n xTexelR" + g + "C" + y + ".zw, xTexelR" + g + "C" + (y + 2) + ".zw);\n ", y + 1 < p && (m += "\n vec4 final = vec4(0.);\n xCOffset = xC + 1 + " + c + ";\n if(xCOffset >= 0 && xCOffset < " + a + ") {\n final = getX(batch, xR, xCOffset, d1);\n }\n xR" + g + "C" + (y + 1) + " = vec4(xTexelR" + g + "C" + (y + 2) + ".xy, final.xy);\n ")) : (m += "\n if(xC >= 0 && xC < " + a + ") {\n xTexelR" + g + "C" + y + " = getX(batch, xR, xC, d1);\n } else {\n xTexelR" + g + "C" + y + " = vec4(0.);\n }\n\n xCOffset = xC + " + c + ";\n if(xCOffset >= 0 && xCOffset < " + a + ") {\n xTexelR" + g + "C" + (y + 2) + " = getX(batch, xR, xCOffset, d1);\n } else {\n xTexelR" + g + "C" + (y + 2) + " = vec4(0.);\n }\n\n xR" + g + "C" + y + " = vec4(\n xTexelR" + g + "C" + y + ".xy, xTexelR" + g + "C" + (y + 2) + ".xy);\n ", y + 1 < p && (m += "\n xR" + g + "C" + (y + 1) + " = vec4(\n xTexelR" + g + "C" + y + ".zw, xTexelR" + g + "C" + (y + 2) + ".zw);\n ")), m += "}");
  7652. y < p && (m += "\n vec4 wTexelR" + g + "C" + y + " = getW(" + g + ", " + y + ", d1, q);\n wR" + g + "C" + y + " = vec4(wTexelR" + g + "C" + y + ".xz, wTexelR" + g + "C" + y + ".xz);\n ", y + 1 < p && (m += "\n vec4 wTexelR" + g + "C" + (y + 1) + " = getW(" + g + ", " + (y + 1) + ", d1, q);\n wR" + g + "C" + (y + 1) + " =\n vec4(wTexelR" + g + "C" + (y + 1) + ".xz, wTexelR" + g + "C" + (y + 1) + ".xz);"));
  7653. }
  7654. for (g = 0; g < f; g++) for (y = 0; y < p; y++) m += "dotProd += xR" + g + "C" + y + " * wR" + g + "C" + y + ";";
  7655. var w = "",
  7656. C = "";
  7657. n && (w = r ? "vec4 activation(vec4 a) {\n vec4 b = getPreluActivationWeightsAtOutCoords();\n " + n + "\n }" : "vec4 activation(vec4 x) {\n " + n + "\n }", C = "result = activation(result);");
  7658. var E = e ? "result += getBiasAtOutCoords();" : "";
  7659. e && this.variableNames.push("bias"), r && this.variableNames.push("preluActivationWeights"), this.userCode = "\n " + w + "\n\n const ivec2 strides = ivec2(" + s + ", " + c + ");\n const ivec2 pads = ivec2(" + i + ", " + u + ");\n\n void main() {\n\n ivec4 coords = getOutputCoords();\n int batch = coords.x;\n ivec2 xRCCorner = coords.yz * strides - pads;\n int d2 = coords.w;\n int d1 = d2;\n int q = 0;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n vec4 dotProd = vec4(0.);\n\n " + m + "\n\n vec4 result = dotProd;\n " + E + "\n " + C + "\n setOutput(result);\n }\n ";
  7660. };
  7661. }(),
  7662. Wa = function () {
  7663. return function (t, e, n, r, o) {
  7664. this.variableNames = ["Image", "Boxes", "BoxInd"], this.outputShape = [];
  7665. var a = t[0],
  7666. i = t[1],
  7667. u = t[2],
  7668. s = t[3],
  7669. c = e[0],
  7670. l = n[0],
  7671. h = n[1];
  7672. this.outputShape = [c, l, h, s];
  7673. var f = "bilinear" === r ? 1 : 0,
  7674. p = [i - 1 + ".0", u - 1 + ".0"],
  7675. d = p[0],
  7676. v = p[1],
  7677. m = l > 1 ? ["" + (i - 1) / (l - 1), "(y2-y1) * height_ratio", "y1*" + d + " + float(y)*(height_scale)"] : ["0.0", "0.0", "0.5 * (y1+y2) * " + d],
  7678. g = m[0],
  7679. y = m[1],
  7680. x = m[2],
  7681. b = h > 1 ? ["" + (u - 1) / (h - 1), "(x2-x1) * width_ratio", "x1*" + v + " + float(x)*(width_scale)"] : ["0.0", "0.0", "0.5 * (x1+x2) * " + v],
  7682. w = b[0],
  7683. C = b[1],
  7684. E = b[2];
  7685. this.userCode = "\n const float height_ratio = float(" + g + ");\n const float width_ratio = float(" + w + ");\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int y = coords[1];\n int x = coords[2];\n int d = coords[3];\n\n // get box vals\n float y1 = getBoxes(b,0);\n float x1 = getBoxes(b,1);\n float y2 = getBoxes(b,2);\n float x2 = getBoxes(b,3);\n\n // get image in batch index\n int bInd = round(getBoxInd(b));\n if(bInd < 0 || bInd >= " + a + ") {\n return;\n }\n\n float height_scale = " + y + ";\n float width_scale = " + C + ";\n\n float in_y = " + x + ";\n if( in_y < 0.0 || in_y > " + d + " ) {\n setOutput(float(" + o + "));\n return;\n }\n float in_x = " + E + ";\n if( in_x < 0.0 || in_x > " + v + " ) {\n setOutput(float(" + o + "));\n return;\n }\n\n vec2 sourceFracIndexCR = vec2(in_x,in_y);\n if(" + f + " == 1) {\n // Compute the four integer indices.\n ivec2 sourceFloorCR = ivec2(sourceFracIndexCR);\n ivec2 sourceCeilCR = ivec2(ceil(sourceFracIndexCR));\n\n float topLeft = getImage(b, sourceFloorCR.y, sourceFloorCR.x, d);\n float bottomLeft = getImage(b, sourceCeilCR.y, sourceFloorCR.x, d);\n float topRight = getImage(b, sourceFloorCR.y, sourceCeilCR.x, d);\n float bottomRight = getImage(b, sourceCeilCR.y, sourceCeilCR.x, d);\n\n vec2 fracCR = sourceFracIndexCR - vec2(sourceFloorCR);\n\n float top = topLeft + (topRight - topLeft) * fracCR.x;\n float bottom = bottomLeft + (bottomRight - bottomLeft) * fracCR.x;\n float newValue = top + (bottom - top) * fracCR.y;\n setOutput(newValue);\n } else {\n // Compute the coordinators of nearest neighbor point.\n ivec2 sourceNearestCR = ivec2(floor(\n sourceFracIndexCR + vec2(0.5,0.5)));\n float newValue = getImage(b, sourceNearestCR.y, sourceNearestCR.x, d);\n setOutput(newValue);\n }\n }\n ";
  7686. };
  7687. }(),
  7688. Ua = function () {
  7689. return function (t, e, n) {
  7690. this.variableNames = ["x"], this.outputShape = t;
  7691. var r = t.length,
  7692. o = t[t.length - 1],
  7693. a = n ? "<" : ">";
  7694. this.userCode = "\n int getIndex(int i) {\n " + (n ? "return " + o + " -i - 1;" : "return i;") + "\n }\n\n void main() {\n " + aa(r) + " coords = getOutputCoords();\n int end = " + Va(r, "coords") + ";\n float val = 0.0;\n for (int i = " + o + " - 1; i >= 0; i -= 1) {\n int idx = getIndex(i);\n if (idx " + a + " end) {\n continue;\n }\n if (idx == end && " + e + ") {\n continue;\n }\n " + Va(r, "coords") + " = idx;\n val += getX(" + function (t, e) {
  7695. if (1 === t) return "" + e;
  7696. if (2 === t) return e + ".x, " + e + ".y";
  7697. if (3 === t) return e + ".x, " + e + ".y, " + e + ".z";
  7698. if (4 === t) return e + ".x, " + e + ".y, " + e + ".z, " + e + ".w";
  7699. throw Error("Cumulative sum for rank " + t + " is not yet supported");
  7700. }(r, "coords") + ");\n }\n setOutput(val);\n }\n ";
  7701. };
  7702. }();
  7703. function Va(t, e) {
  7704. if (1 === t) return "" + e;
  7705. if (2 === t) return e + ".y";
  7706. if (3 === t) return e + ".z";
  7707. if (4 === t) return e + ".w";
  7708. throw Error("Cumulative sum for rank " + t + " is not yet supported");
  7709. }
  7710. var za = function () {
  7711. return function (t) {
  7712. this.variableNames = ["A"], this.packedInputs = !1, this.packedOutput = !0, this.outPackingScheme = _t.DENSE;
  7713. var e = Gt(t),
  7714. n = Ko();
  7715. this.outputShape = t, this.userCode = "\n ivec3 outCoordsFromFlatIndex(int index) {\n " + jo(["r", "c", "d"], t) + "\n return ivec3(r, c, d);\n }\n\n void main() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + e[0] + ", " + e[1] + "));\n int index = 4 * (resTexRC.x * " + e[1] + " + resTexRC.y);\n\n vec4 result = vec4(0.);\n\n for (int i=0; i<4; i++) {\n int flatIndex = index + i;\n ivec3 rc = outCoordsFromFlatIndex(flatIndex);\n result[i] = getA(rc.x, rc.y, rc.z);\n }\n\n " + n.output + " = result;\n }\n ";
  7716. };
  7717. }(),
  7718. Ga = function () {
  7719. return function (t) {
  7720. this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outPackingScheme = _t.DENSE;
  7721. var e = Gt(t),
  7722. n = Ko();
  7723. this.outputShape = t, this.userCode = "\n ivec3 outCoordsFromFlatIndex(int index) {\n " + jo(["r", "c", "d"], t) + "\n return ivec3(r, c, d);\n }\n\n void main() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + e[0] + ", " + e[1] + "));\n int index = 4 * (resTexRC.x * " + e[1] + " + resTexRC.y);\n\n vec4 result = vec4(0.);\n\n for (int i=0; i<4; i++) {\n int flatIndex = index + i;\n ivec3 rc = outCoordsFromFlatIndex(flatIndex);\n result[i] = getChannel(getA(rc.x, rc.y, rc.z), vec2(rc.y, rc.z));\n }\n\n " + n.output + " = result;\n }\n ";
  7724. };
  7725. }(),
  7726. Ha = function () {
  7727. function t(t, e, n) {
  7728. this.variableNames = ["x"], this.outputShape = [], this.outputShape = t, this.blockSize = e, this.dataFormat = n, this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int h = " + this.getHeightCoordString() + ";\n int w = " + this.getWidthCoordString() + ";\n int d = " + this.getDepthCoordString() + ";\n\n int in_h = h / " + e + ";\n int offset_h = imod(h, " + e + ");\n int in_w = w / " + e + ";\n int offset_w = imod(w, " + e + ");\n int offset_d = (offset_h * " + e + " + offset_w) *\n " + this.getOutputDepthSize() + ";\n int in_d = d + offset_d;\n\n float result = " + this.getInputSamplingString() + ";\n setOutput(result);\n }\n ";
  7729. }
  7730. return t.prototype.getHeightCoordString = function () {
  7731. return "NHWC" === this.dataFormat ? "coords[1]" : "coords[2]";
  7732. }, t.prototype.getWidthCoordString = function () {
  7733. return "NHWC" === this.dataFormat ? "coords[2]" : "coords[3]";
  7734. }, t.prototype.getDepthCoordString = function () {
  7735. return "NHWC" === this.dataFormat ? "coords[3]" : "coords[1]";
  7736. }, t.prototype.getOutputDepthSize = function () {
  7737. return "NHWC" === this.dataFormat ? this.outputShape[3] : this.outputShape[1];
  7738. }, t.prototype.getInputSamplingString = function () {
  7739. return "NHWC" === this.dataFormat ? "getX(b, in_h, in_w, in_d)" : "getX(b, in_d, in_h, in_w)";
  7740. }, t;
  7741. }(),
  7742. qa = function () {
  7743. return function (t) {
  7744. this.variableNames = ["X"], this.outputShape = [t, t], this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n float val = coords[0] == coords[1] ? getX(coords[0]) : 0.0;\n setOutput(val);\n }\n ";
  7745. };
  7746. }(),
  7747. Ka = function () {
  7748. return function (t) {
  7749. this.variableNames = ["A"], this.outTexUsage = Mt.DOWNLOAD;
  7750. var e = Ko();
  7751. this.outputShape = t, this.userCode = "\n " + $o + "\n\n void main() {\n float x = getAAtOutCoords();\n " + e.output + " = encode_float(x);\n }\n ";
  7752. };
  7753. }(),
  7754. ja = function () {
  7755. return function (t) {
  7756. this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !1, this.outTexUsage = Mt.DOWNLOAD;
  7757. var e = Ko();
  7758. this.outputShape = t, this.userCode = "\n " + $o + "\n\n void main() {\n ivec3 coords = getOutputCoords();\n float x = getChannel(getAAtOutCoords(), vec2(coords.y, coords.z));\n " + e.output + " = encode_float(x);\n }\n ";
  7759. };
  7760. }(),
  7761. Xa = function () {
  7762. return function (t, e, n) {
  7763. void 0 === n && (n = !1), this.variableNames = ["A"];
  7764. var r = Ko(),
  7765. o = e[0],
  7766. a = e[1];
  7767. this.outputShape = t;
  7768. var i = "result";
  7769. n && (i = "floor(result * 255. + 0.5)"), this.userCode = "\n " + Xo(t) + "\n\n void main() {\n ivec3 coords = getOutputCoords();\n\n int flatIndex = getFlatIndex(coords);\n int offset = imod(flatIndex, 4);\n\n flatIndex = idiv(flatIndex, 4, 1.);\n \n int r = flatIndex / " + a + ";\n int c = imod(flatIndex, " + a + ");\n vec2 uv = (vec2(c, r) + halfCR) / vec2(" + a + ".0, " + o + ".0);\n vec4 values = " + r.texture2D + "(A, uv);\n\n float result;\n\n if(offset == 0) {\n result = values[0];\n } else if(offset == 1) {\n result = values[1];\n } else if(offset == 2) {\n result = values[2];\n } else {\n result = values[3];\n }\n\n " + r.output + " = vec4(" + i + ", 0., 0., 0.);\n }\n ";
  7770. };
  7771. }(),
  7772. $a = function () {
  7773. return function (t, e, n) {
  7774. void 0 === n && (n = !1), this.variableNames = ["A"], this.packedInputs = !1, this.packedOutput = !0;
  7775. var r = Ko(),
  7776. o = e[0],
  7777. a = e[1];
  7778. this.outputShape = t;
  7779. var i = "",
  7780. u = "result";
  7781. n && (u = "floor(result * 255. + 0.5)");
  7782. for (var s = 0; s <= 1; s++) for (var c = 0; c <= 1; c++) {
  7783. var l = 2 * s + c;
  7784. i += "\n localCoords = coords;\n if(localCoords[2] + " + c + " < " + t[2] + ") {\n localCoords[2] += " + c + ";\n if(localCoords[1] + " + s + " < " + t[1] + ") {\n localCoords[1] += " + s + ";\n\n flatIndex = getFlatIndex(localCoords);\n offset = imod(flatIndex, 4);\n\n flatIndex = idiv(flatIndex, 4, 1.);\n\n r = flatIndex / " + a + ";\n c = imod(flatIndex, " + a + ");\n uv = (vec2(c, r) + halfCR) / vec2(" + a + ".0, " + o + ".0);\n values = " + r.texture2D + "(A, uv);\n\n if(offset == 0) {\n result[" + l + "] = values[0];\n } else if(offset == 1) {\n result[" + l + "] = values[1];\n } else if(offset == 2) {\n result[" + l + "] = values[2];\n } else {\n result[" + l + "] = values[3];\n }\n }\n }\n ";
  7785. }
  7786. this.userCode = "\n " + Xo(t) + "\n\n void main() {\n ivec3 coords = getOutputCoords();\n\n vec4 result = vec4(0.);\n int flatIndex, r, c, offset;\n ivec3 localCoords;\n vec2 uv;\n vec4 values;\n\n " + i + "\n\n " + r.output + " = " + u + ";\n }\n ";
  7787. };
  7788. }(),
  7789. Ya = "return real * expR - imag * expI;",
  7790. Qa = "return real * expI + imag * expR;",
  7791. Ja = function () {
  7792. return function (t, e, n) {
  7793. this.variableNames = ["real", "imag"];
  7794. var r = e[1];
  7795. this.outputShape = e;
  7796. var o = n ? "2.0 * " + Math.PI : "-2.0 * " + Math.PI,
  7797. a = n ? r + ".0" : "1.0";
  7798. this.userCode = "\n const float exponentMultiplier = " + o + ";\n\n float unaryOpComplex(float real, float expR, float imag, float expI) {\n " + t + "\n }\n\n float mulMatDFT(int batch, int index) {\n float indexRatio = float(index) / float(" + r + ");\n float exponentMultiplierTimesIndexRatio =\n exponentMultiplier * indexRatio;\n\n float result = 0.0;\n\n for (int i = 0; i < " + r + "; i++) {\n // x = (-2|2 * PI / N) * index * i;\n float x = exponentMultiplierTimesIndexRatio * float(i);\n float expR = cos(x);\n float expI = sin(x);\n float real = getReal(batch, i);\n float imag = getImag(batch, i);\n\n result +=\n unaryOpComplex(real, expR, imag, expI) / " + a + ";\n }\n\n return result;\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n setOutput(mulMatDFT(coords[0], coords[1]));\n }\n ";
  7799. };
  7800. }(),
  7801. Za = function () {
  7802. function t(t, e) {
  7803. this.outputShape = [], this.variableNames = ["x"], this.outputShape = t, this.userCode = "\n uniform float value;\n void main() {\n // Input can be obtained from uniform value.\n setOutput(value);\n }\n ";
  7804. }
  7805. return t.prototype.getCustomSetupFunc = function (t) {
  7806. var e = this;
  7807. return function (n, r) {
  7808. null == e.valueLoc && (e.valueLoc = n.getUniformLocationNoThrow(r, "value")), n.gl.uniform1f(e.valueLoc, t);
  7809. };
  7810. }, t;
  7811. }(),
  7812. ti = function () {
  7813. return function (t) {
  7814. this.variableNames = ["A"];
  7815. var e = Ko(),
  7816. n = t[0],
  7817. r = t[1];
  7818. this.outputShape = t, this.userCode = "\n void main() {\n ivec3 coords = getOutputCoords();\n int texR = coords[0];\n int texC = coords[1];\n int depth = coords[2];\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2(" + r + ".0, " + n + ".0);\n\n vec4 values = " + e.texture2D + "(A, uv);\n float value;\n if (depth == 0) {\n value = values.r;\n } else if (depth == 1) {\n value = values.g;\n } else if (depth == 2) {\n value = values.b;\n } else if (depth == 3) {\n value = values.a;\n }\n\n setOutput(floor(value * 255.0 + 0.5));\n }\n ";
  7819. };
  7820. }(),
  7821. ei = function () {
  7822. return function (t) {
  7823. this.variableNames = ["A"], this.packedInputs = !1, this.packedOutput = !0;
  7824. var e = Ko(),
  7825. n = t[0],
  7826. r = t[1];
  7827. this.outputShape = t, this.userCode = "\n void main() {\n ivec3 coords = getOutputCoords();\n int texR = coords[0];\n int texC = coords[1];\n int depth = coords[2];\n\n vec4 result = vec4(0.);\n\n for(int row=0; row<=1; row++) {\n for(int col=0; col<=1; col++) {\n texC = coords[1] + row;\n depth = coords[2] + col;\n\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + r + ".0, " + n + ".0);\n vec4 values = " + e.texture2D + "(A, uv);\n float value;\n if (depth == 0) {\n value = values.r;\n } else if (depth == 1) {\n value = values.g;\n } else if (depth == 2) {\n value = values.b;\n } else if (depth == 3) {\n value = values.a;\n }\n\n result[row * 2 + col] = floor(value * 255.0 + 0.5);\n }\n }\n\n " + e.output + " = result;\n }\n ";
  7828. };
  7829. }(),
  7830. ni = function () {
  7831. return function (t, e, n) {
  7832. this.variableNames = ["A", "indices"];
  7833. var r = t.slice();
  7834. r[n] = e, this.outputShape = r, this.rank = r.length;
  7835. var o = aa(this.rank),
  7836. a = function (t, e) {
  7837. var n = t.length;
  7838. if (n > 4) throw Error("Gather for rank " + n + " is not yet supported");
  7839. if (1 === n) return "int(getIndices(resRC))";
  7840. for (var r = ["resRC.x", "resRC.y", "resRC.z", "resRC.w"], o = [], a = 0; a < t.length; a++) a === e ? o.push("int(getIndices(" + r[a] + "))") : o.push("" + r[a]);
  7841. return o.join();
  7842. }(t, n);
  7843. this.userCode = "\n void main() {\n " + o + " resRC = getOutputCoords();\n setOutput(getA(" + a + "));\n }\n ";
  7844. };
  7845. }();
  7846. var ri = function () {
  7847. return function (t, e, n) {
  7848. this.sliceDim = t, this.strides = e, this.variableNames = ["x", "indices"], this.outputShape = n;
  7849. var r = aa(e.length),
  7850. o = aa(n.length),
  7851. a = this.sliceDim > 1 ? "strides[j]" : "strides";
  7852. this.userCode = "\n " + r + " strides = " + r + "(" + this.strides + ");\n void main() {\n " + o + " coords = getOutputCoords();\n int flattenIndex = 0;\n for (int j = 0; j < " + this.sliceDim + "; j++) {\n int index = round(getIndices(coords[0], j));\n flattenIndex += index * " + a + ";\n }\n setOutput(getX(flattenIndex, coords[1]));\n }\n ";
  7853. };
  7854. }();
  7855. function oi(t, e) {
  7856. var n = Ko();
  7857. return Jt(t, e, n.version + "\n precision highp float;\n " + n.attribute + " vec3 clipSpacePos;\n " + n.attribute + " vec2 uv;\n " + n.varyingVs + " vec2 resultUV;\n\n void main() {\n gl_Position = vec4(clipSpacePos, 1);\n resultUV = uv;\n }");
  7858. }
  7859. function ai(t, e) {
  7860. return ie(t, e, new Float32Array([-1, 1, 0, 0, 1, -1, -1, 0, 0, 0, 1, 1, 0, 1, 1, 1, -1, 0, 1, 0]));
  7861. }
  7862. function ii(t, e) {
  7863. return ue(t, e, new Uint16Array([0, 1, 2, 2, 1, 3]));
  7864. }
  7865. function ui(t, e, n, r, o, a, i) {
  7866. ce(n, r);
  7867. var u = se(t, e),
  7868. s = t.TEXTURE_2D;
  7869. return Kt(t, e, function () {
  7870. return t.bindTexture(s, u);
  7871. }), Kt(t, e, function () {
  7872. return t.texParameteri(s, t.TEXTURE_WRAP_S, t.CLAMP_TO_EDGE);
  7873. }), Kt(t, e, function () {
  7874. return t.texParameteri(s, t.TEXTURE_WRAP_T, t.CLAMP_TO_EDGE);
  7875. }), Kt(t, e, function () {
  7876. return t.texParameteri(s, t.TEXTURE_MIN_FILTER, t.NEAREST);
  7877. }), Kt(t, e, function () {
  7878. return t.texParameteri(s, t.TEXTURE_MAG_FILTER, t.NEAREST);
  7879. }), Kt(t, e, function () {
  7880. return t.texImage2D(s, 0, o, n, r, 0, a, i, null);
  7881. }), Kt(t, e, function () {
  7882. return t.bindTexture(t.TEXTURE_2D, null);
  7883. }), u;
  7884. }
  7885. function si(t, e, n, r, o) {
  7886. var a = zt(n, r);
  7887. return ui(t, e, a[0], a[1], o.internalFormatFloat, o.textureFormatFloat, t.FLOAT);
  7888. }
  7889. function ci(t, e, n, r, o) {
  7890. var a = zt(n, r);
  7891. return ui(t, e, a[0], a[1], o.internalFormatHalfFloat, o.textureFormatFloat, o.textureTypeHalfFloat);
  7892. }
  7893. function li(t, e, n, r, o) {
  7894. var a = zt(n, r);
  7895. return ui(t, e, a[0], a[1], t.RGBA, t.RGBA, t.UNSIGNED_BYTE);
  7896. }
  7897. function hi(t, e, n, r, o) {
  7898. var a = Ht(n, r);
  7899. return ui(t, e, a[0], a[1], o.internalFormatPackedFloat, t.RGBA, t.FLOAT);
  7900. }
  7901. function fi(t, e, n, r, o) {
  7902. var a = Ht(n, r);
  7903. return ui(t, e, a[0], a[1], o.internalFormatPackedHalfFloat, t.RGBA, o.textureTypeHalfFloat);
  7904. }
  7905. function pi(t, e, n, r) {
  7906. return Kt(t, e, function () {
  7907. return t.bindBuffer(t.ARRAY_BUFFER, r);
  7908. }), he(t, e, n, "clipSpacePos", r, 3, 20, 0) && he(t, e, n, "uv", r, 2, 20, 12);
  7909. }
  7910. function di(t, e, n, r, o, a, i) {
  7911. var u, s, c;
  7912. Kt(t, e, function () {
  7913. return t.bindTexture(t.TEXTURE_2D, n);
  7914. }), a instanceof Uint8Array ? (u = new Uint8Array(r * o * 4), s = t.UNSIGNED_BYTE, c = t.RGBA) : (u = new Float32Array(r * o * 4), s = t.FLOAT, c = i.internalFormatPackedFloat), u.set(a), Kt(t, e, function () {
  7915. return t.texImage2D(t.TEXTURE_2D, 0, c, r, o, 0, t.RGBA, s, u);
  7916. }), Kt(t, e, function () {
  7917. return t.bindTexture(t.TEXTURE_2D, null);
  7918. });
  7919. }
  7920. function vi(t, e, n, r) {
  7921. Kt(t, e, function () {
  7922. return t.bindTexture(t.TEXTURE_2D, n);
  7923. }), r.data instanceof Uint8Array ? Kt(t, e, function () {
  7924. return t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, r.width, r.height, 0, t.RGBA, t.UNSIGNED_BYTE, r.data);
  7925. }) : Kt(t, e, function () {
  7926. return t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, r);
  7927. }), Kt(t, e, function () {
  7928. return t.bindTexture(t.TEXTURE_2D, null);
  7929. });
  7930. }
  7931. function mi(t, e, n, r, o) {
  7932. var a = t.createBuffer();
  7933. Kt(t, e, function () {
  7934. return t.bindBuffer(t.PIXEL_PACK_BUFFER, a);
  7935. });
  7936. var i = 16 * n * r;
  7937. return Kt(t, e, function () {
  7938. return t.bufferData(t.PIXEL_PACK_BUFFER, i, t.STREAM_READ);
  7939. }), Kt(t, e, function () {
  7940. return t.readPixels(0, 0, r, n, t.RGBA, t.FLOAT, 0);
  7941. }), Kt(t, e, function () {
  7942. return t.bindBuffer(t.PIXEL_PACK_BUFFER, null);
  7943. }), a;
  7944. }
  7945. function gi(t, e, n) {
  7946. var r = t,
  7947. o = new Float32Array(n);
  7948. return r.bindBuffer(r.PIXEL_PACK_BUFFER, e), r.getBufferSubData(r.PIXEL_PACK_BUFFER, 0, o), r.bindBuffer(r.PIXEL_PACK_BUFFER, null), o;
  7949. }
  7950. function yi(t, e, n, r, o) {
  7951. var a = zt(n, r),
  7952. i = a[0],
  7953. u = a[1],
  7954. s = new Uint8Array(n * r * 4);
  7955. return Kt(t, e, function () {
  7956. return t.readPixels(0, 0, i, u, o.downloadTextureFormat, t.UNSIGNED_BYTE, s);
  7957. }), new Float32Array(s.buffer);
  7958. }
  7959. function xi(t, e, n, r, o, a, i, u) {
  7960. var s = t,
  7961. c = new Float32Array(function (t, e) {
  7962. var n = Ht(t, e);
  7963. return n[0] * n[1] * 4;
  7964. }(a, i));
  7965. return s.bindBuffer(s.PIXEL_PACK_BUFFER, e), s.getBufferSubData(s.PIXEL_PACK_BUFFER, 0, c), s.bindBuffer(s.PIXEL_PACK_BUFFER, null), c;
  7966. }
  7967. function bi(t, e, n, r) {
  7968. var o = new Float32Array(n * r * 4);
  7969. return Kt(t, e, function () {
  7970. return t.readPixels(0, 0, r, n, t.RGBA, t.FLOAT, o);
  7971. }), o;
  7972. }
  7973. var wi = Object.freeze({
  7974. createVertexShader: oi,
  7975. createVertexBuffer: ai,
  7976. createIndexBuffer: ii,
  7977. createFloat32MatrixTexture: si,
  7978. createFloat16MatrixTexture: ci,
  7979. createUnsignedBytesMatrixTexture: li,
  7980. createPackedMatrixTexture: hi,
  7981. createFloat16PackedMatrixTexture: fi,
  7982. bindVertexProgramAttributeStreams: pi,
  7983. uploadDenseMatrixToTexture: di,
  7984. uploadPixelDataToTexture: vi,
  7985. createBufferFromOutputTexture: mi,
  7986. downloadFloat32MatrixFromBuffer: gi,
  7987. downloadByteEncodedFloatMatrixFromOutputTexture: yi,
  7988. downloadPackedMatrixFromBuffer: xi,
  7989. downloadMatrixFromPackedOutputTexture: bi
  7990. }),
  7991. Ci = function () {
  7992. function t(t) {
  7993. this.outputTexture = null, this.program = null, this.disposed = !1, this.vertexAttrsAreBound = !1, this.itemsToPoll = [];
  7994. var e = a().getNumber("WEBGL_VERSION");
  7995. if (null != t ? (this.gl = t, Wt(e, t)) : this.gl = Ut(e), 1 === a().getNumber("WEBGL_VERSION")) this.textureFloatExtension = Qt(this.gl, this.debug, "OES_texture_float"), this.colorBufferFloatExtension = this.gl.getExtension("WEBGL_color_buffer_float"), this.textureHalfFloatExtension = Qt(this.gl, this.debug, "OES_texture_half_float"), this.colorBufferHalfFloatExtension = this.gl.getExtension("EXT_color_buffer_half_float"); else {
  7996. if (Ne(this.gl, "EXT_color_buffer_float")) this.colorBufferFloatExtension = this.gl.getExtension("EXT_color_buffer_float"); else {
  7997. if (!Ne(this.gl, "EXT_color_buffer_half_float")) throw new Error("GL context does not support color renderable floats");
  7998. this.colorBufferHalfFloatExtension = this.gl.getExtension("EXT_color_buffer_half_float");
  7999. }
  8000. }
  8001. this.vertexBuffer = ai(this.gl, this.debug), this.indexBuffer = ii(this.gl, this.debug), this.framebuffer = le(this.gl, this.debug), this.textureConfig = qt(this.gl, this.textureHalfFloatExtension);
  8002. }
  8003. return Object.defineProperty(t.prototype, "debug", {
  8004. get: function () {
  8005. return a().getBool("DEBUG");
  8006. },
  8007. enumerable: !0,
  8008. configurable: !0
  8009. }), t.prototype.dispose = function () {
  8010. var t = this;
  8011. if (!this.disposed) {
  8012. null != this.program && console.warn("Disposing a GPGPUContext that still has a bound WebGLProgram. This is probably a resource leak, delete the program with GPGPUContext.deleteProgram before disposing."), null != this.outputTexture && console.warn("Disposing a GPGPUContext that still has a bound output matrix texture. This is probably a resource leak, delete the output matrix texture with GPGPUContext.deleteMatrixTexture before disposing.");
  8013. var e = this.gl;
  8014. Kt(e, this.debug, function () {
  8015. return e.finish();
  8016. }), Kt(e, this.debug, function () {
  8017. return e.bindFramebuffer(e.FRAMEBUFFER, null);
  8018. }), Kt(e, this.debug, function () {
  8019. return e.deleteFramebuffer(t.framebuffer);
  8020. }), Kt(e, this.debug, function () {
  8021. return e.bindBuffer(e.ARRAY_BUFFER, null);
  8022. }), Kt(e, this.debug, function () {
  8023. return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, null);
  8024. }), Kt(e, this.debug, function () {
  8025. return e.deleteBuffer(t.indexBuffer);
  8026. }), this.disposed = !0;
  8027. }
  8028. }, t.prototype.createFloat32MatrixTexture = function (t, e) {
  8029. return this.throwIfDisposed(), si(this.gl, this.debug, t, e, this.textureConfig);
  8030. }, t.prototype.createFloat16MatrixTexture = function (t, e) {
  8031. return this.throwIfDisposed(), ci(this.gl, this.debug, t, e, this.textureConfig);
  8032. }, t.prototype.createUnsignedBytesMatrixTexture = function (t, e) {
  8033. return this.throwIfDisposed(), li(this.gl, this.debug, t, e, this.textureConfig);
  8034. }, t.prototype.uploadPixelDataToTexture = function (t, e) {
  8035. this.throwIfDisposed(), vi(this.gl, this.debug, t, e);
  8036. }, t.prototype.uploadDenseMatrixToTexture = function (t, e, n, r) {
  8037. this.throwIfDisposed(), di(this.gl, this.debug, t, e, n, r, this.textureConfig);
  8038. }, t.prototype.createFloat16PackedMatrixTexture = function (t, e) {
  8039. return this.throwIfDisposed(), fi(this.gl, this.debug, t, e, this.textureConfig);
  8040. }, t.prototype.createPackedMatrixTexture = function (t, e) {
  8041. return this.throwIfDisposed(), hi(this.gl, this.debug, t, e, this.textureConfig);
  8042. }, t.prototype.deleteMatrixTexture = function (t) {
  8043. var e = this;
  8044. this.throwIfDisposed(), this.outputTexture === t && (ge(this.gl, this.debug, this.framebuffer), this.outputTexture = null), Kt(this.gl, this.debug, function () {
  8045. return e.gl.deleteTexture(t);
  8046. });
  8047. }, t.prototype.downloadByteEncodedFloatMatrixFromOutputTexture = function (t, e, n) {
  8048. var r = this;
  8049. return this.downloadMatrixDriver(t, function () {
  8050. return yi(r.gl, r.debug, e, n, r.textureConfig);
  8051. });
  8052. }, t.prototype.downloadPackedMatrixFromBuffer = function (t, e, n, r, o, a) {
  8053. return xi(this.gl, t, 0, 0, 0, o, a, this.textureConfig);
  8054. }, t.prototype.downloadFloat32MatrixFromBuffer = function (t, e) {
  8055. return gi(this.gl, t, e);
  8056. }, t.prototype.createBufferFromTexture = function (t, e, n) {
  8057. this.bindTextureToFrameBuffer(t);
  8058. var r = mi(this.gl, this.debug, e, n, this.textureConfig);
  8059. return this.unbindTextureToFrameBuffer(), r;
  8060. }, t.prototype.createAndWaitForFence = function () {
  8061. var t = this.createFence(this.gl);
  8062. return this.pollFence(t);
  8063. }, t.prototype.createFence = function (t) {
  8064. var e,
  8065. n,
  8066. r = this;
  8067. if (a().getBool("WEBGL_FENCE_API_ENABLED")) {
  8068. var o = t,
  8069. i = o.fenceSync(o.SYNC_GPU_COMMANDS_COMPLETE, 0);
  8070. t.flush(), n = function () {
  8071. var t = o.clientWaitSync(i, 0, 0);
  8072. return t === o.ALREADY_SIGNALED || t === o.CONDITION_SATISFIED;
  8073. }, e = i;
  8074. } else a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") > 0 ? (e = this.beginQuery(), this.endQuery(), n = function () {
  8075. return r.isQueryAvailable(e, a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"));
  8076. }) : n = function () {
  8077. return !0;
  8078. };
  8079. return {
  8080. query: e,
  8081. isFencePassed: n
  8082. };
  8083. }, t.prototype.downloadMatrixFromPackedTexture = function (t, e, n) {
  8084. var r = this;
  8085. return this.downloadMatrixDriver(t, function () {
  8086. return bi(r.gl, r.debug, e, n);
  8087. });
  8088. }, t.prototype.createProgram = function (t) {
  8089. this.throwIfDisposed();
  8090. var e = this.gl,
  8091. n = Zt(e, this.debug, t),
  8092. r = oi(e, this.debug),
  8093. o = re(e, this.debug);
  8094. return Kt(e, this.debug, function () {
  8095. return e.attachShader(o, r);
  8096. }), Kt(e, this.debug, function () {
  8097. return e.attachShader(o, n);
  8098. }), oe(e, this.debug, o), this.debug && ae(e, this.debug, o), this.vertexAttrsAreBound || (this.setProgram(o), this.vertexAttrsAreBound = pi(e, this.debug, this.program, this.vertexBuffer)), o;
  8099. }, t.prototype.deleteProgram = function (t) {
  8100. var e = this;
  8101. this.throwIfDisposed(), t === this.program && (this.program = null), null != t && Kt(this.gl, this.debug, function () {
  8102. return e.gl.deleteProgram(t);
  8103. });
  8104. }, t.prototype.setProgram = function (t) {
  8105. var e = this;
  8106. this.throwIfDisposed(), this.program = t, null != this.program && this.debug && ae(this.gl, this.debug, this.program), Kt(this.gl, this.debug, function () {
  8107. return e.gl.useProgram(t);
  8108. });
  8109. }, t.prototype.getUniformLocation = function (t, e, n) {
  8110. return void 0 === n && (n = !0), this.throwIfDisposed(), n ? pe(this.gl, this.debug, t, e) : de(this.gl, t, e);
  8111. }, t.prototype.getAttributeLocation = function (t, e) {
  8112. var n = this;
  8113. return this.throwIfDisposed(), Kt(this.gl, this.debug, function () {
  8114. return n.gl.getAttribLocation(t, e);
  8115. });
  8116. }, t.prototype.getUniformLocationNoThrow = function (t, e) {
  8117. return this.throwIfDisposed(), this.gl.getUniformLocation(t, e);
  8118. }, t.prototype.setInputMatrixTexture = function (t, e, n) {
  8119. this.throwIfDisposed(), this.throwIfNoProgram(), ve(this.gl, this.debug, this.program, t, e, n);
  8120. }, t.prototype.setOutputMatrixTexture = function (t, e, n) {
  8121. this.setOutputMatrixTextureDriver(t, n, e);
  8122. }, t.prototype.setOutputPackedMatrixTexture = function (t, e, n) {
  8123. this.throwIfDisposed();
  8124. var r = Ht(e, n),
  8125. o = r[0],
  8126. a = r[1];
  8127. this.setOutputMatrixTextureDriver(t, o, a);
  8128. }, t.prototype.setOutputMatrixWriteRegion = function (t, e, n, r) {
  8129. this.setOutputMatrixWriteRegionDriver(n, t, r, e);
  8130. }, t.prototype.setOutputPackedMatrixWriteRegion = function (t, e, n, r) {
  8131. throw new Error("setOutputPackedMatrixWriteRegion not implemented.");
  8132. }, t.prototype.debugValidate = function () {
  8133. null != this.program && ae(this.gl, this.debug, this.program), ye(this.gl);
  8134. }, t.prototype.executeProgram = function () {
  8135. this.throwIfDisposed(), this.throwIfNoProgram();
  8136. var t = this.gl;
  8137. this.debug && this.debugValidate(), Kt(t, this.debug, function () {
  8138. return t.drawElements(t.TRIANGLES, 6, t.UNSIGNED_SHORT, 0);
  8139. });
  8140. }, t.prototype.blockUntilAllProgramsCompleted = function () {
  8141. var t = this;
  8142. this.throwIfDisposed(), Kt(this.gl, this.debug, function () {
  8143. return t.gl.finish();
  8144. });
  8145. }, t.prototype.getQueryTimerExtension = function () {
  8146. return null == this.disjointQueryTimerExtension && (this.disjointQueryTimerExtension = Qt(this.gl, this.debug, 2 === a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") ? "EXT_disjoint_timer_query_webgl2" : "EXT_disjoint_timer_query")), this.disjointQueryTimerExtension;
  8147. }, t.prototype.getQueryTimerExtensionWebGL2 = function () {
  8148. return this.getQueryTimerExtension();
  8149. }, t.prototype.getQueryTimerExtensionWebGL1 = function () {
  8150. return this.getQueryTimerExtension();
  8151. }, t.prototype.beginQuery = function () {
  8152. if (2 === a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")) {
  8153. var t = this.gl,
  8154. e = this.getQueryTimerExtensionWebGL2(),
  8155. n = t.createQuery();
  8156. return t.beginQuery(e.TIME_ELAPSED_EXT, n), n;
  8157. }
  8158. var r = this.getQueryTimerExtensionWebGL1(),
  8159. o = r.createQueryEXT();
  8160. return r.beginQueryEXT(r.TIME_ELAPSED_EXT, o), o;
  8161. }, t.prototype.endQuery = function () {
  8162. if (2 !== a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")) {
  8163. var t = this.getQueryTimerExtensionWebGL1();
  8164. t.endQueryEXT(t.TIME_ELAPSED_EXT);
  8165. } else {
  8166. var e = this.gl,
  8167. n = this.getQueryTimerExtensionWebGL2();
  8168. e.endQuery(n.TIME_ELAPSED_EXT);
  8169. }
  8170. }, t.prototype.waitForQueryAndGetTime = function (t) {
  8171. return n(this, void 0, void 0, function () {
  8172. var e = this;
  8173. return r(this, function (n) {
  8174. switch (n.label) {
  8175. case 0:
  8176. return [4, S(function () {
  8177. return e.disposed || e.isQueryAvailable(t, a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"));
  8178. })];
  8179. case 1:
  8180. return n.sent(), [2, this.getQueryTime(t, a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))];
  8181. }
  8182. });
  8183. });
  8184. }, t.prototype.getQueryTime = function (t, e) {
  8185. if (0 === e) return null;
  8186. if (2 === e) {
  8187. var n = this.gl;
  8188. return n.getQueryParameter(t, n.QUERY_RESULT) / 1e6;
  8189. }
  8190. var r = this.getQueryTimerExtensionWebGL1();
  8191. return r.getQueryObjectEXT(t, r.QUERY_RESULT_EXT) / 1e6;
  8192. }, t.prototype.isQueryAvailable = function (t, e) {
  8193. if (0 === e) return !0;
  8194. if (2 === e) {
  8195. var n = this.gl,
  8196. r = this.getQueryTimerExtensionWebGL2(),
  8197. o = n.getQueryParameter(t, n.QUERY_RESULT_AVAILABLE);
  8198. return null == this.disjoint && (this.disjoint = this.gl.getParameter(r.GPU_DISJOINT_EXT)), o && !this.disjoint;
  8199. }
  8200. o = (r = this.getQueryTimerExtensionWebGL1()).getQueryObjectEXT(t, r.QUERY_RESULT_AVAILABLE_EXT);
  8201. return null == this.disjoint && (this.disjoint = this.gl.getParameter(r.GPU_DISJOINT_EXT)), o && !this.disjoint;
  8202. }, t.prototype.pollFence = function (t) {
  8203. var e = this;
  8204. return new Promise(function (n) {
  8205. e.addItemToPoll(function () {
  8206. return t.isFencePassed();
  8207. }, function () {
  8208. return n();
  8209. });
  8210. });
  8211. }, t.prototype.pollItems = function () {
  8212. for (var t = function (t) {
  8213. for (var e = 0; e < t.length; ++e) {
  8214. var n = t[e]();
  8215. if (!n) break;
  8216. }
  8217. return e - 1;
  8218. }(this.itemsToPoll.map(function (t) {
  8219. return t.isDoneFn;
  8220. })), e = 0; e <= t; ++e) {
  8221. (0, this.itemsToPoll[e].resolveFn)();
  8222. }
  8223. this.itemsToPoll = this.itemsToPoll.slice(t + 1);
  8224. }, t.prototype.addItemToPoll = function (t, e) {
  8225. var n = this;
  8226. this.itemsToPoll.push({
  8227. isDoneFn: t,
  8228. resolveFn: e
  8229. }), this.itemsToPoll.length > 1 || S(function () {
  8230. return n.pollItems(), 0 === n.itemsToPoll.length;
  8231. });
  8232. }, t.prototype.bindTextureToFrameBuffer = function (t) {
  8233. this.throwIfDisposed(), me(this.gl, this.debug, t, this.framebuffer), this.debug && ye(this.gl);
  8234. }, t.prototype.unbindTextureToFrameBuffer = function () {
  8235. null != this.outputTexture ? (me(this.gl, this.debug, this.outputTexture, this.framebuffer), this.debug && ye(this.gl)) : ge(this.gl, this.debug, this.framebuffer);
  8236. }, t.prototype.downloadMatrixDriver = function (t, e) {
  8237. this.bindTextureToFrameBuffer(t);
  8238. var n = e();
  8239. return this.unbindTextureToFrameBuffer(), n;
  8240. }, t.prototype.setOutputMatrixTextureDriver = function (t, e, n) {
  8241. this.throwIfDisposed();
  8242. var r = this.gl;
  8243. me(r, this.debug, t, this.framebuffer), this.debug && ye(r), this.outputTexture = t, Kt(r, this.debug, function () {
  8244. return r.viewport(0, 0, e, n);
  8245. }), Kt(r, this.debug, function () {
  8246. return r.scissor(0, 0, e, n);
  8247. });
  8248. }, t.prototype.setOutputMatrixWriteRegionDriver = function (t, e, n, r) {
  8249. var o = this;
  8250. this.throwIfDisposed(), Kt(this.gl, this.debug, function () {
  8251. return o.gl.scissor(t, e, n, r);
  8252. });
  8253. }, t.prototype.throwIfDisposed = function () {
  8254. if (this.disposed) throw new Error("Attempted to use disposed GPGPUContext.");
  8255. }, t.prototype.throwIfNoProgram = function () {
  8256. if (null == this.program) throw new Error("No GPU program is currently set.");
  8257. }, t;
  8258. }();
  8259. function Ei(t, e) {
  8260. if (t.length !== e.length) throw Error("Binary was compiled with " + t.length + " inputs, but was executed with " + e.length + " inputs");
  8261. t.forEach(function (t, n) {
  8262. var r = t.logicalShape,
  8263. o = e[n],
  8264. a = o.shape;
  8265. if (!C(r, a)) throw Error("Binary was compiled with different shapes than the current args. Shapes " + r + " and " + a + " must match");
  8266. if (!t.isUniform || !o.isUniform) {
  8267. var i = t.texShape,
  8268. u = o.isUniform ? null : o.texData.texShape;
  8269. if (!C(i, u)) throw Error("Binary was compiled with different texture shapes than the current args. Shape " + i + " and " + u + " must match");
  8270. }
  8271. });
  8272. }
  8273. var Ri = function () {
  8274. return function (t, e, n) {
  8275. this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t;
  8276. for (var r = n.filterWidth, o = n.inChannels, a = n.strideWidth, i = n.strideHeight, u = n.padInfo, s = n.outWidth, c = n.dilationWidth, l = n.dilationHeight, h = n.dataFormat, f = u.left, p = u.top, d = o * r, v = Ko(), m = "channelsLast" === h, g = m ? 0 : 1, y = m ? 1 : 2, x = "", b = 0; b <= 1; b++) for (var w = 0; w <= 1; w++) x += "\n blockIndex = rc.y + " + w + ";\n pos = rc.x + " + b + ";\n\n if(blockIndex < " + t[1] + " && pos < " + t[0] + ") {\n offsetY = int(blockIndex / (" + s + ")) * " + i + " - " + p + ";\n d0 = offsetY + " + l + " * (pos / " + d + ");\n\n if(d0 < " + e[g] + " && d0 >= 0) {\n\n offsetX = int(mod(float(blockIndex), " + s + ".) * " + a + ". - " + f + ".);\n d1 = offsetX + " + c + " * (int(mod(float(pos), " + d + ".) / " + o + ".));\n\n if(d1 < " + e[y] + " && d1 >= 0) {\n\n ch = int(mod(float(pos), " + o + ".));\n\n if (" + m + ") {\n innerDims = vec2(d1, ch);\n result[" + (2 * b + w) + "] = getChannel(\n getA(d0, int(innerDims.x),\n int(innerDims.y)), innerDims);\n } else {\n innerDims = vec2(d0, d1);\n result[" + (2 * b + w) + "] = getChannel(\n getA(ch, int(innerDims.x),\n int(innerDims.y)), innerDims);\n }\n }\n }\n }\n ";
  8277. this.userCode = "\n void main() {\n ivec2 rc = getOutputCoords();\n\n vec4 result = vec4(0);\n\n int blockIndex, pos, offsetY, d0, offsetX, d1, ch;\n vec2 innerDims;\n\n " + x + "\n\n " + v.output + " = result;\n }\n ";
  8278. };
  8279. }(),
  8280. Ii = function () {
  8281. return function (t, e, n, r, o) {
  8282. this.variableNames = ["x"], this.outputShape = [];
  8283. var a,
  8284. i = e,
  8285. u = t[3] - 1;
  8286. this.outputShape = t;
  8287. var s = "float(" + n + ") + float(" + r + ") * sum";
  8288. a = .5 === o ? "inversesqrt(" + s + ")" : 1 === o ? "1.0/(" + s + ")" : "exp(log(" + s + ") * float(-" + o + "));", this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n int d = coords[3];\n float x = getX(b, r, c, d);\n float sum = 0.0;\n for (int j = -" + i + "; j <= " + i + "; j++) {\n int idx = d + j;\n if (idx >= 0 && idx <= " + u + ") {\n float z = getX(b, r, c, idx);\n sum += z * z;\n }\n }\n float val = x * " + a + ";\n setOutput(val);\n }\n ";
  8289. };
  8290. }(),
  8291. ki = function () {
  8292. return function (t, e, n, r, o) {
  8293. this.variableNames = ["inputImage", "outputImage", "dy"], this.outputShape = [], this.outputShape = t, this.depth = t[3], this.depthRadius = e, this.bias = n, this.alpha = r, this.beta = o, this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n\n float result = 0.0;\n for (int d = 0; d < " + this.depth + "; ++d) {\n int depthBegin = int(max(0.0, float(d - " + e + ")));\n int depthEnd = int(min(float(" + this.depth + "),\n float(d + " + e + " + 1)));\n\n const int MIN_DEPTH_BEGIN = 0;\n const int MAX_DEPTH_END = " + this.depth + ";\n\n float norm = 0.0;\n for (int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k) {\n if (k < depthBegin){\n continue;\n }\n else if (k >= depthBegin && k < depthEnd) {\n norm += getInputImage(b, r, c, k) * getInputImage(b, r, c, k);\n }\n else {\n break;\n }\n }\n\n norm = float(" + r + ") * norm + float(" + n + ");\n\n for(int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k){\n if (k < depthBegin){\n continue;\n }\n else if (k >= depthBegin && k < depthEnd){\n float dyi = -2.0 * float(" + r + ")\n * float(" + o + ")\n * getInputImage(b ,r ,c, k) * getOutputImage(b, r, c, d)\n / norm;\n if (k == d) {\n dyi += pow(norm, -1.0 * " + o + ");\n }\n if (k == coords[3]) {\n dyi *= getDy(b, r, c, d);\n result += dyi;\n }\n }\n else {\n break;\n }\n }\n }\n setOutput(result);\n }\n ";
  8294. };
  8295. }(),
  8296. Si = function () {
  8297. return function (t, e, n, r, o) {
  8298. this.variableNames = ["x"], this.outputShape = [], this.packedInputs = !0, this.packedOutput = !0;
  8299. var a,
  8300. i = e,
  8301. u = t[3] - 1;
  8302. this.outputShape = t;
  8303. var s = "float(" + n + ") + float(" + r + ") * sum";
  8304. a = .5 === o ? "inversesqrt(" + s + ")" : 1 === o ? "1.0/(" + s + ")" : "exp(log(" + s + ") * float(-" + o + "));", this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords.x;\n int r = coords.y;\n int c = coords.z;\n int d = coords.w;\n\n bool hasNextCol = d < " + this.outputShape[3] + ";\n bool hasNextRow = c < " + this.outputShape[2] + ";\n\n vec4 sum = vec4(0.);\n vec4 xFragAtOutputCoords = getX(b, r, c, d);\n\n vec4 xAtOutputCoords = vec4(\n getChannel(xFragAtOutputCoords, vec2(c, d)),\n hasNextCol ?\n getChannel(xFragAtOutputCoords, vec2(c, d + 1)) : 0.0,\n hasNextRow ?\n getChannel(xFragAtOutputCoords , vec2(c + 1, d)) : 0.0,\n (hasNextRow && hasNextCol) ?\n getChannel(xFragAtOutputCoords, vec2(c + 1, d + 1)) : 0.0\n );\n\n int firstChannel = d - " + i + ";\n vec2 cache = vec2(0.);\n if(firstChannel >= 0){\n vec4 firstChannelFrag = getX(b, r, c, firstChannel);\n cache.x = getChannel(firstChannelFrag, vec2(c, firstChannel));\n if(hasNextRow){\n cache.y = getChannel(firstChannelFrag, vec2(c + 1, firstChannel));\n }\n }\n\n ivec2 depth = ivec2(d, d + 1);\n for (int j = - " + i + "; j <= " + i + "; j++) {\n ivec2 idx = depth + j;\n bvec2 aboveLowerBound = greaterThanEqual(idx, ivec2(0));\n bvec2 belowUpperBound = lessThanEqual(idx, ivec2(" + u + "));\n\n bool depthInRange = aboveLowerBound.x && belowUpperBound.x;\n bool depthPlusOneInRange = aboveLowerBound.y && belowUpperBound.y;\n\n if(depthInRange || depthPlusOneInRange){\n vec4 z = vec4(0.);\n vec4 xFragAtCurrentDepth;\n z.xz = cache.xy;\n if(depthPlusOneInRange && hasNextCol){\n xFragAtCurrentDepth = idx.y != d ?\n getX(b, r, c, idx.y) : xFragAtOutputCoords;\n z.y = getChannel(xFragAtCurrentDepth, vec2(c, idx.y));\n if(hasNextRow){\n z.w = getChannel(xFragAtCurrentDepth, vec2(c + 1, idx.y));\n }\n }\n cache.xy = z.yw;\n sum += z * z;\n }\n }\n vec4 result = xAtOutputCoords * " + a + ";\n setOutput(result);\n }\n ";
  8305. };
  8306. }(),
  8307. Ai = function () {
  8308. return function (t) {
  8309. this.variableNames = ["dy", "maxPos"], this.outputShape = t.inShape;
  8310. var e = t.strideHeight,
  8311. n = t.strideWidth,
  8312. r = t.dilationHeight,
  8313. o = t.effectiveFilterHeight,
  8314. a = t.effectiveFilterWidth,
  8315. i = o - 1 - t.padInfo.top,
  8316. u = a - 1 - t.padInfo.left,
  8317. s = o * a - 1;
  8318. this.userCode = "\n const ivec2 pads = ivec2(" + i + ", " + u + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + o + ";\n wR += " + r + ") {\n float dyR = float(dyRCorner + wR) / " + e + ".0;\n\n if (dyR < 0.0 || dyR >= " + t.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < " + a + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + n + ".0;\n\n if (dyC < 0.0 || dyC >= " + t.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n int maxPosValue = " + s + " - int(getMaxPos(b, idyR, idyC, d));\n\n // Get the current value, check it against the value from the\n // position matrix.\n int curPosValue = wR * " + a + " + wC;\n float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\n\n dotProd += dyValue * mask;\n }\n }\n setOutput(dotProd);\n }\n ";
  8319. };
  8320. }(),
  8321. Di = function () {
  8322. return function (t) {
  8323. this.variableNames = ["dy", "maxPos"], this.outputShape = t.inShape;
  8324. var e = t.strideDepth,
  8325. n = t.strideHeight,
  8326. r = t.strideWidth,
  8327. o = t.dilationDepth,
  8328. a = t.dilationHeight,
  8329. i = t.dilationWidth,
  8330. u = t.effectiveFilterDepth,
  8331. s = t.effectiveFilterHeight,
  8332. c = t.effectiveFilterWidth,
  8333. l = u - 1 - t.padInfo.front,
  8334. h = s - 1 - t.padInfo.top,
  8335. f = c - 1 - t.padInfo.left,
  8336. p = u * s * c - 1;
  8337. this.userCode = "\n const ivec3 pads = ivec3(" + l + ", " + h + ", " + f + ");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int ch = coords.u;\n\n ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;\n int dyDCorner = dyCorner.x;\n int dyRCorner = dyCorner.y;\n int dyCCorner = dyCorner.z;\n\n // Convolve dy(?, ?, ?, ch) with pos mask(:, :, :, d) to get\n // dx(xD, xR, xC, ch).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n\n for (int wD = 0; wD < " + u + ";\n wD += " + o + ") {\n float dyD = float(dyDCorner + wD) / " + e + ".0;\n\n if (dyD < 0.0 || dyD >= " + t.outDepth + ".0 || fract(dyD) > 0.0) {\n continue;\n }\n int idyD = int(dyD);\n\n for (int wR = 0; wR < " + s + ";\n wR += " + a + ") {\n float dyR = float(dyRCorner + wR) / " + n + ".0;\n\n if (dyR < 0.0 || dyR >= " + t.outHeight + ".0 ||\n fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < " + c + ";\n wC += " + i + ") {\n float dyC = float(dyCCorner + wC) / " + r + ".0;\n\n if (dyC < 0.0 || dyC >= " + t.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(batch, idyD, idyR, idyC, ch);\n int maxPosValue = " + p + " -\n int(getMaxPos(batch, idyD, idyR, idyC, ch));\n\n // Get the current value, check it against the value from the\n // position matrix.\n int curPosValue =\n wD * " + s + " * " + c + " +\n wR * " + c + " + wC;\n float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\n\n dotProd += dyValue * mask;\n }\n }\n }\n setOutput(dotProd);\n }\n ";
  8338. };
  8339. }(),
  8340. Ti = function () {
  8341. return function (t, e, n, r, o, a, i) {
  8342. void 0 === n && (n = !1), void 0 === r && (r = !1), void 0 === o && (o = !1), void 0 === a && (a = null), void 0 === i && (i = !1), this.variableNames = ["matrixA", "matrixB"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = e;
  8343. var u = n ? t[1] : t[2],
  8344. s = Math.ceil(u / 2),
  8345. c = n ? "i * 2, rc.y" : "rc.y, i * 2",
  8346. l = r ? "rc.z, i * 2" : "i * 2, rc.z",
  8347. h = n ? ["a.xxyy", "a.zzww"] : ["a.xxzz", "a.yyww"],
  8348. f = r ? ["b.xzxz", "b.ywyw"] : ["b.xyxy", "b.zwzw"],
  8349. p = "",
  8350. d = "";
  8351. a && (p = i ? "vec4 activation(vec4 a) {\n vec4 b = getPreluActivationWeightsAtOutCoords();\n " + a + "\n }" : "vec4 activation(vec4 x) {\n " + a + "\n }", d = "result = activation(result);");
  8352. var v = o ? "result += getBiasAtOutCoords();" : "";
  8353. o && this.variableNames.push("bias"), i && this.variableNames.push("preluActivationWeights"), this.userCode = "\n " + p + "\n\n const float sharedDimension = " + s + ".0;\n\n vec4 dot2x2ARowBCol(ivec3 rc) {\n vec4 result = vec4(0);\n for (int i = 0; i < " + s + "; i++) {\n vec4 a = getMatrixA(rc.x, " + c + ");\n vec4 b = getMatrixB(rc.x, " + l + ");\n\n // These swizzled products need to be separately added.\n // See: https://github.com/tensorflow/tfjs/issues/1735\n result += (" + h[0] + " * " + f[0] + ");\n result += (" + h[1] + " * " + f[1] + ");\n }\n return result;\n }\n\n void main() {\n ivec3 rc = getOutputCoords();\n vec4 result = dot2x2ARowBCol(rc);\n\n " + v + "\n\n " + d + "\n\n setOutput(result);\n }\n ";
  8354. };
  8355. }(),
  8356. Ni = function () {
  8357. function t(t, e, n) {
  8358. this.variableNames = ["probs"], this.outputShape = [t, n], this.userCode = "\n uniform float seed;\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n\n float r = random(seed);\n float cdf = 0.0;\n\n for (int i = 0; i < " + (e - 1) + "; i++) {\n cdf += getProbs(batch, i);\n\n if (r < cdf) {\n setOutput(float(i));\n return;\n }\n }\n\n // If no other event happened, last event happened.\n setOutput(float(" + (e - 1) + "));\n }\n ";
  8359. }
  8360. return t.prototype.getCustomSetupFunc = function (t) {
  8361. var e = this;
  8362. return function (n, r) {
  8363. null == e.seedLoc && (e.seedLoc = n.getUniformLocation(r, "seed")), n.gl.uniform1f(e.seedLoc, t);
  8364. };
  8365. }, t;
  8366. }(),
  8367. Fi = function () {
  8368. return function (t, e, n, r) {
  8369. this.variableNames = ["indices"], this.outputShape = [t, e], this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n int index = round(getIndices(coords.x));\n setOutput(mix(float(" + r + "), float(" + n + "),\n float(index == coords.y)));\n }\n ";
  8370. };
  8371. }(),
  8372. Oi = function () {
  8373. return function (t) {
  8374. this.variableNames = ["A"], this.packedInputs = !1, this.packedOutput = !0, this.outputShape = t;
  8375. var e = t.length;
  8376. if (0 === e) this.userCode = "\n void main() {\n setOutput(vec4(getA(), 0., 0., 0.));\n }\n "; else {
  8377. var n = qo("rc", e),
  8378. r = aa(e),
  8379. o = function (t, e, n) {
  8380. if (1 === t) return "rc > " + e[0];
  8381. for (var r = "", o = t - 2; o < t; o++) r += n[o] + " >= " + e[o], o < t - 1 && (r += "||");
  8382. return r;
  8383. }(e, t, n),
  8384. a = function (t, e, n, r) {
  8385. if (1 === t) return "";
  8386. var o = r.slice(-2);
  8387. return "\n int r = " + o[0] + ";\n int c = " + o[1] + ";\n int rp1 = r + 1;\n int cp1 = c + 1;\n\n bool cEdge = cp1 >= " + e + ";\n bool rEdge = rp1 >= " + n + ";\n ";
  8388. }(e, t[t.length - 1], t[t.length - 2], n),
  8389. i = function (t, e) {
  8390. var n = t.length,
  8391. r = function (t, e) {
  8392. for (var n = [], r = 0; r <= 1; r++) for (var o = 0; o <= 1; o++) {
  8393. for (var a = (0 === r ? "r" : "rp1") + ", " + (0 === o ? "c" : "cp1"), i = 2; i < t; i++) a = e[e.length - 1 - i] + "," + a;
  8394. n.push(a);
  8395. }
  8396. return n;
  8397. }(n, e);
  8398. return 1 === n ? "getA(rc),\n rc + 1 >= " + t[0] + " ? 0. : getA(rc + 1),\n 0, 0" : "getA(" + r[0] + "),\n cEdge ? 0. : getA(" + r[1] + "),\n rEdge ? 0. : getA(" + r[2] + "),\n rEdge || cEdge ? 0. : getA(" + r[3] + ")";
  8399. }(t, n);
  8400. this.userCode = "\n void main() {\n " + r + " rc = getOutputCoords();\n\n if(" + o + ") {\n setOutput(vec4(0));\n } else {\n " + a + "\n\n setOutput(vec4(" + i + "));\n }\n }\n ";
  8401. }
  8402. };
  8403. }();
  8404. var _i = function () {
  8405. return function (t, e, n) {
  8406. this.variableNames = ["x"], this.outputShape = e.map(function (e, n) {
  8407. return e[0] + t[n] + e[1];
  8408. });
  8409. var r = t.length,
  8410. o = aa(r),
  8411. a = e.map(function (t) {
  8412. return t[0];
  8413. }).join(","),
  8414. i = e.map(function (e, n) {
  8415. return e[0] + t[n];
  8416. }).join(","),
  8417. u = ["coords[0]", "coords[1]", "coords[2]", "coords[3]"].slice(0, r);
  8418. this.userCode = 1 !== r ? "\n " + o + " start = " + o + "(" + a + ");\n " + o + " end = " + o + "(" + i + ");\n\n void main() {\n " + o + " outC = getOutputCoords();\n if (any(lessThan(outC, start)) || any(greaterThanEqual(outC, end))) {\n setOutput(float(" + n + "));\n } else {\n " + o + " coords = outC - start;\n setOutput(getX(" + u + "));\n }\n }\n " : "\n int start = " + a + ";\n int end = " + i + ";\n\n void main() {\n int outC = getOutputCoords();\n if (outC < start || outC >= end) {\n setOutput(float(" + n + "));\n } else {\n setOutput(getX(outC - start));\n }\n }\n ";
  8419. };
  8420. }(),
  8421. Mi = function () {
  8422. return function (t, e, n) {
  8423. this.variableNames = ["x"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = e.map(function (e, n) {
  8424. return e[0] + t[n] + e[1];
  8425. });
  8426. for (var r = t.length, o = aa(r), a = e.map(function (t) {
  8427. return t[0];
  8428. }).join(","), i = e.map(function (e, n) {
  8429. return e[0] + t[n];
  8430. }).join(","), u = qo("rc", r), s = qo("source", r), c = u[r - 1] + " < " + this.outputShape[r - 1], l = 1 === r ? "source" : "vec2(" + s.slice(-2).join() + ")", h = [o + " rc = outputLoc;", u[r - 1] + " += 1;\n if(" + c + ") {\n ", 1 === r ? "" : "}\n rc = outputLoc;\n " + u[r - 2] + " += 1;\n if(" + u[r - 2] + " < " + this.outputShape[r - 2] + ") {", 1 === r ? "" : " " + u[r - 1] + " += 1;\n if(" + c + ") {"], f = 1 === r ? "rc < start || rc >= end" : "any(lessThan(rc, start)) || any(greaterThanEqual(rc, end))", p = "", d = 0, v = 1 === r ? 2 : 4; d < v; d++) p += "\n " + h[d] + "\n if (" + f + ") {\n result[" + d + "] = float(" + n + ");\n } else {\n " + o + " source = rc - start;\n result[" + d + "] = getChannel(getX(" + s.join() + "), " + l + ");\n }\n ";
  8431. p += 1 === r ? "} " : "}}", this.userCode = "\n const " + o + " start = " + o + "(" + a + ");\n const " + o + " end = " + o + "(" + i + ");\n\n void main() {\n " + o + " outputLoc = getOutputCoords();\n vec4 result = vec4(0.);\n " + p + "\n setOutput(result);\n }\n ";
  8432. };
  8433. }(),
  8434. Bi = function () {
  8435. return function (t, e, n) {
  8436. if (this.variableNames = ["x"], "avg" === e && n) throw new Error("Cannot compute positions for average pool.");
  8437. var r = t.filterWidth,
  8438. o = t.strideHeight,
  8439. a = t.strideWidth,
  8440. i = t.dilationHeight,
  8441. u = t.dilationWidth,
  8442. s = t.effectiveFilterHeight,
  8443. c = t.effectiveFilterWidth,
  8444. l = t.padInfo.top,
  8445. h = t.padInfo.left;
  8446. this.outputShape = t.outShape;
  8447. var f = "avg" === e,
  8448. p = "0.0";
  8449. if (f || (p = "-1.0 / 1e-20"), n) this.userCode = "\n const ivec2 strides = ivec2(" + o + ", " + a + ");\n const ivec2 pads = ivec2(" + l + ", " + h + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n float minMaxValue = 0.0;\n float minMaxValueFound = 0.0;\n int minMaxPosition = 0;\n float avgValue = 0.0;\n\n for (int wR = 0; wR < " + s + ";\n wR += " + i + ") {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + t.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + c + ";\n wC += " + u + ") {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= " + t.inWidth + ") {\n continue;\n }\n\n float value = getX(batch, xR, xC, d);\n\n // If a min / max value has already been found, use it. If not,\n // use the current value.\n float currMinMaxValue = mix(\n value, minMaxValue, minMaxValueFound);\n if (value >= currMinMaxValue) {\n minMaxValue = value;\n minMaxValueFound = 1.0;\n minMaxPosition = wR * " + c + " + wC;\n }\n }\n }\n setOutput(float(minMaxPosition));\n }\n "; else {
  8450. var d = e + "(" + e + "(" + e + "(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";
  8451. "avg" === e && (d = "avgValue / count");
  8452. var v = 4 * Math.floor(r / 4),
  8453. m = r % 4,
  8454. g = "\n if (" + f + ") {\n avgValue += dot(values, ones);\n } else {\n minMaxValue = max(values, minMaxValue);\n }\n ";
  8455. this.userCode = "\n const ivec2 strides = ivec2(" + o + ", " + a + ");\n const ivec2 pads = ivec2(" + l + ", " + h + ");\n const float initializationValue = " + p + ";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float count = 0.0;\n\n float getValue(int batch, int xR, int xC, int d) {\n if (xC < 0 || xC >= " + t.inWidth + ") {\n return initializationValue;\n }\n count += 1.0;\n return getX(batch, xR, xC, d);\n }\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n vec4 minMaxValue = vec4(" + p + ");\n float avgValue = 0.0;\n count = 0.0;\n\n for (int wR = 0; wR < " + s + ";\n wR += " + i + ") {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + t.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + v + "; wC += 4) {\n int xC = xCCorner + wC * " + u + ";\n\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + " + u + ", d),\n getValue(batch, xR, xC + 2 * " + u + ", d),\n getValue(batch, xR, xC + 3 * " + u + ", d)\n );\n\n " + g + "\n }\n\n int xC = xCCorner + " + v + ";\n if (" + (1 === m) + ") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n " + g + "\n } else if (" + (2 === m) + ") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + " + u + ", d),\n initializationValue,\n initializationValue\n );\n\n " + g + "\n } else if (" + (3 === m) + ") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + " + u + ", d),\n getValue(batch, xR, xC + 2 * " + u + ", d),\n initializationValue\n );\n\n " + g + "\n }\n }\n setOutput(" + d + ");\n }\n ";
  8456. }
  8457. };
  8458. }(),
  8459. Pi = function () {
  8460. return function (t, e, n) {
  8461. if (this.variableNames = ["x"], "avg" === e && n) throw new Error("Cannot compute positions for average pool.");
  8462. var r = t.filterWidth,
  8463. o = t.strideDepth,
  8464. a = t.strideHeight,
  8465. i = t.strideWidth,
  8466. u = t.dilationDepth,
  8467. s = t.dilationHeight,
  8468. c = t.dilationWidth,
  8469. l = t.effectiveFilterDepth,
  8470. h = t.effectiveFilterHeight,
  8471. f = t.effectiveFilterWidth,
  8472. p = t.padInfo.front,
  8473. d = t.padInfo.top,
  8474. v = t.padInfo.left;
  8475. this.outputShape = t.outShape;
  8476. var m = "avg" === e,
  8477. g = "0.0";
  8478. if (m || (g = "-1.0 / 1e-20"), n) this.userCode = "\n const ivec3 strides =\n ivec3(" + o + ", " + a + ", " + i + ");\n const ivec3 pads = ivec3(" + p + ", " + d + ", " + v + ");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int ch = coords.u;\n\n ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;\n int xDCorner = xCorner.x;\n int xRCorner = xCorner.y;\n int xCCorner = xCorner.z;\n\n // max/min x(?, ?, ?, ch) to get y(yD, yR, yC, ch).\n // ? = to be determined\n float minMaxValue = 0.0;\n float minMaxValueFound = 0.0;\n int minMaxPosition = 0;\n\n for (int wD = 0; wD < " + l + ";\n wD += " + u + ") {\n int xD = xDCorner + wD;\n\n if (xD < 0 || xD >= " + t.inDepth + ") {\n continue;\n }\n\n for (int wR = 0; wR < " + h + ";\n wR += " + s + ") {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + t.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + f + ";\n wC += " + c + ") {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= " + t.inWidth + ") {\n continue;\n }\n\n float value = getX(batch, xD, xR, xC, ch);\n\n // If a min / max value has already been found, use it. If not,\n // use the current value.\n float currMinMaxValue = mix(\n value, minMaxValue, minMaxValueFound);\n if (value >= currMinMaxValue) {\n minMaxValue = value;\n minMaxValueFound = 1.0;\n minMaxPosition =\n wD * " + h + " * " + f + " +\n wR * " + f + " + wC;;\n }\n }\n }\n }\n setOutput(float(minMaxPosition));\n }\n "; else {
  8479. var y = e + "(" + e + "(" + e + "(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";
  8480. "avg" === e && (y = "avgValue / count");
  8481. var x = 4 * Math.floor(r / 4),
  8482. b = r % 4,
  8483. w = "\n if (" + m + ") {\n avgValue += dot(values, ones);\n } else {\n minMaxValue = max(values, minMaxValue);\n }\n ";
  8484. this.userCode = "\n const ivec3 strides =\n ivec3(" + o + ", " + a + ", " + i + ");\n const ivec3 pads = ivec3(" + p + ", " + d + ", " + v + ");\n const float initializationValue = " + g + ";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float count = 0.0;\n\n float getValue(int batch, int xD, int xR, int xC, int ch) {\n if (xC < 0 || xC >= " + t.inWidth + ") {\n return initializationValue;\n }\n count += 1.0;\n return getX(batch, xD, xR, xC, ch);\n }\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int ch = coords.u;\n\n ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;\n int xDCorner = xCorner.x;\n int xRCorner = xCorner.y;\n int xCCorner = xCorner.z;\n\n // max/min x(?, ?, ?, d) to get y(yD, yR, yC, ch).\n // ? = to be determined\n vec4 minMaxValue = vec4(" + g + ");\n float avgValue = 0.0;\n count = 0.0;\n\n for (int wD = 0; wD < " + l + ";\n wD += " + u + ") {\n int xD = xDCorner + wD;\n\n if (xD < 0 || xD >= " + t.inDepth + ") {\n continue;\n }\n\n for (int wR = 0; wR < " + h + ";\n wR += " + s + ") {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + t.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + x + "; wC += 4) {\n int xC = xCCorner + wC * " + c + ";\n\n vec4 values = vec4(\n getValue(batch, xD, xR, xC, ch),\n getValue(batch, xD, xR, xC + " + c + ", ch),\n getValue(batch, xD, xR, xC + 2 * " + c + ", ch),\n getValue(batch, xD, xR, xC + 3 * " + c + ", ch)\n );\n\n " + w + "\n }\n\n int xC = xCCorner + " + x + ";\n if (" + (1 === b) + ") {\n vec4 values = vec4(\n getValue(batch, xD, xR, xC, ch),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n " + w + "\n } else if (" + (2 === b) + ") {\n vec4 values = vec4(\n getValue(batch, xD, xR, xC, ch),\n getValue(batch, xD, xR, xC + " + c + ", ch),\n initializationValue,\n initializationValue\n );\n\n " + w + "\n } else if (" + (3 === b) + ") {\n vec4 values = vec4(\n getValue(batch, xD, xR, xC, ch),\n getValue(batch, xD, xR, xC + " + c + ", ch),\n getValue(batch, xD, xR, xC + 2 * " + c + ", ch),\n initializationValue\n );\n\n " + w + "\n }\n }\n setOutput(" + y + ");\n }\n }\n ";
  8485. }
  8486. };
  8487. }(),
  8488. Li = function () {
  8489. return function (t, e) {
  8490. this.variableNames = ["x"];
  8491. var n = t.windowSize,
  8492. r = t.batchSize,
  8493. o = t.inSize,
  8494. a = Math.ceil(o / n);
  8495. this.outputShape = [r, a];
  8496. var i = "0.0",
  8497. u = "";
  8498. "prod" === e ? i = "1.0" : "min" === e ? (i = "1.0 / 1e-20", u = "min") : "max" === e && (i = "-1.0 / 1e-20", u = "max");
  8499. var s = e + "(" + e + "(" + e + "(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";
  8500. "sum" === e ? s = "sumValue" : "prod" === e ? s = "prodValue" : "all" === e ? s = "allValue" : "any" === e && (s = "anyValue");
  8501. var c = 4 * Math.floor(n / 4),
  8502. l = n % 4,
  8503. h = "\n if (" + ("sum" === e) + ") {\n sumValue += dot(values, ones);\n } else if (" + ("prod" === e) + ") {\n vec2 tmp = vec2(values[0], values[1]) * vec2(values[2], values[3]);\n prodValue *= tmp[0] * tmp[1];\n } else {\n minMaxValue = " + u + "(values, minMaxValue);\n }\n ",
  8504. f = "vec4";
  8505. "all" === e ? (i = "1.0", h = "\n bool reducedAllValue = all(values);\n float floatedReducedAllValue = float(reducedAllValue);\n allValue = float(allValue >= 1.0 && floatedReducedAllValue >= 1.0);\n ", f = "bvec4") : "any" === e && (i = "0.0", h = "\n bool reducedAnyValue = any(values);\n float floatedReducedAnyValue = float(reducedAnyValue);\n anyValue = float(anyValue >= 1.0 || floatedReducedAnyValue >= 1.0);\n ", f = "bvec4");
  8506. var p = "";
  8507. o % n > 0 && (p = "\n if (inIdx < 0 || inIdx >= " + o + ") {\n return initializationValue;\n }\n "), this.userCode = "\n const float initializationValue = " + i + ";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float getValue(int batch, int inIdx) {\n " + p + "\n return getX(batch, inIdx);\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * " + n + ";\n\n vec4 minMaxValue = vec4(" + i + ");\n float prodValue = 1.0;\n float sumValue = 0.0;\n float allValue = 1.0;\n float anyValue = 0.0;\n\n for (int i = 0; i < " + c + "; i += 4) {\n int inIdx = inOffset + i;\n " + f + " values = " + f + "(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n getValue(batch, inIdx + 3)\n );\n\n " + h + "\n }\n\n int inIdx = inOffset + " + c + ";\n if (" + (1 === l) + ") {\n " + f + " values = " + f + "(\n getValue(batch, inIdx),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n " + h + "\n } else if (" + (2 === l) + ") {\n " + f + " values = " + f + "(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n initializationValue,\n initializationValue\n );\n\n " + h + "\n } else if (" + (3 === l) + ") {\n " + f + " values = " + f + "(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n initializationValue\n );\n\n " + h + "\n }\n setOutput(" + s + ");\n }\n ";
  8508. };
  8509. }(),
  8510. Wi = function () {
  8511. return function (t, e) {
  8512. this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t;
  8513. for (var n = "", r = 0; r < 4; r++) {
  8514. var o = "thisRC = rc;";
  8515. r % 2 == 1 && (o += "thisRC.z += 1;"), r > 1 && (o += "thisRC.y += 1;"), n += "\n " + o + "\n " + (r > 0 ? "if(thisRC.y < rows && thisRC.z < cols){" : "") + "\n int flatIndex = getFlatIndex(thisRC);\n\n ivec3 inputRC = inputCoordsFromReshapedOutCoords(flatIndex);\n vec2 inputRCInnerDims = vec2(float(inputRC.y),float(inputRC.z));\n\n result[" + r + "] =\n getChannel(getA(inputRC.x, inputRC.y, inputRC.z), inputRCInnerDims);\n " + (r > 0 ? "}" : "") + "\n ";
  8516. }
  8517. this.userCode = "\n \n ivec3 inputCoordsFromReshapedOutCoords(int index) {\n " + jo(["r", "c", "d"], e) + "\n return ivec3(r, c, d);\n }\n \n " + Xo(t) + "\n\n void main() {\n ivec3 rc = getOutputCoords();\n\n vec4 result = vec4(0.);\n\n ivec3 thisRC;\n int rows = " + t[1] + ";\n int cols = " + t[2] + ";\n\n " + n + "\n\n setOutput(result);\n }\n ";
  8518. };
  8519. }();
  8520. var Ui = function () {
  8521. return function (t, e, n) {
  8522. this.variableNames = ["dy"], this.outputShape = [], this.outputShape = e.shape;
  8523. var r = e.shape,
  8524. o = r[1],
  8525. a = r[2],
  8526. i = t.shape,
  8527. u = i[1],
  8528. s = i[2],
  8529. c = [n && u > 1 ? o - 1 : o, n && s > 1 ? a - 1 : a],
  8530. l = [n && u > 1 ? u - 1 : u, n && s > 1 ? s - 1 : s],
  8531. h = c[0] / l[0],
  8532. f = c[1] / l[1],
  8533. p = 1 / h,
  8534. d = 1 / f,
  8535. v = 2 * Math.ceil(p) + 2,
  8536. m = 2 * Math.ceil(d) + 2;
  8537. this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n int r = coords[1];\n int c = coords[2];\n\n float accumulator = 0.0;\n\n const float heightScale = float(" + h + ");\n const float widthScale = float(" + f + ");\n\n const float invHeightScale = float(" + p + ");\n const float invWidthScale = float(" + d + ");\n\n const int winHeight = int(" + v + ");\n const int winWidth = int(" + m + ");\n\n // Compute bounds for where in dy we will look\n float startRLerp = floor(float(r) * invHeightScale);\n int startDyR = int(startRLerp - float(winHeight / 2));\n\n float startCLerp = floor(float(c) * invWidthScale);\n int startDyC = int(startCLerp - float(winWidth / 2));\n\n // Loop over dy\n for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {\n int dyR = dyROffset + startDyR;\n\n // Guard against the window exceeding the bounds of dy\n if (dyR < 0 || dyR >= " + u + ") {\n continue;\n }\n\n for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {\n int dyC = dyCOffset + startDyC;\n\n // Guard against the window exceeding the bounds of dy\n if (dyC < 0 || dyC >= " + s + ") {\n continue;\n }\n\n float dxR = float(dyR) * heightScale;\n int topDxRIndex = int(floor(dxR));\n int bottomDxRIndex = int(min(ceil(dxR), " + (o - 1) + ".0));\n float dxRLerp = dxR - float(topDxRIndex);\n float inverseDxRLerp = 1.0 - dxRLerp;\n\n float dxC = float(dyC) * widthScale;\n int leftDxCIndex = int(floor(dxC));\n int rightDxCIndex = int(min(ceil(dxC), " + (a - 1) + ".0));\n float dxCLerp = dxC - float(leftDxCIndex);\n float inverseDxCLerp = 1.0 - dxCLerp;\n\n if (r == topDxRIndex && c == leftDxCIndex) {\n // topLeft\n accumulator +=\n getDy(b, dyR, dyC, d) * inverseDxRLerp * inverseDxCLerp;\n }\n\n if (r == topDxRIndex && c == rightDxCIndex) {\n // topRight\n accumulator += getDy(b, dyR, dyC, d) * inverseDxRLerp * dxCLerp;\n }\n\n if (r == bottomDxRIndex && c == leftDxCIndex) {\n // bottomLeft\n accumulator += getDy(b, dyR, dyC, d) * dxRLerp * inverseDxCLerp;\n }\n\n if (r == bottomDxRIndex && c == rightDxCIndex) {\n // bottomRight\n accumulator += getDy(b, dyR, dyC, d) * dxRLerp * dxCLerp;\n }\n }\n }\n // End loop over dy\n\n setOutput(accumulator);\n }\n ";
  8538. };
  8539. }(),
  8540. Vi = function () {
  8541. return function (t, e, n, r) {
  8542. this.variableNames = ["A"], this.outputShape = [];
  8543. var o = t[0],
  8544. a = t[1],
  8545. i = t[2],
  8546. u = t[3];
  8547. this.outputShape = [o, e, n, u];
  8548. var s = [r && e > 1 ? a - 1 : a, r && n > 1 ? i - 1 : i],
  8549. c = [r && e > 1 ? e - 1 : e, r && n > 1 ? n - 1 : n];
  8550. this.userCode = "\n const vec2 effectiveInputOverOutputRatioRC = vec2(\n " + s[0] / c[0] + ",\n " + s[1] / c[1] + ");\n const vec2 inputShapeRC = vec2(" + a + ".0, " + i + ".0);\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n ivec2 yRC = coords.yz;\n\n // Fractional source index.\n vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;\n\n // Compute the four integer indices.\n ivec2 sourceFloorRC = ivec2(sourceFracIndexRC);\n ivec2 sourceCeilRC = ivec2(\n min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));\n\n float topLeft = getA(b, sourceFloorRC.x, sourceFloorRC.y, d);\n float bottomLeft = getA(b, sourceCeilRC.x, sourceFloorRC.y, d);\n float topRight = getA(b, sourceFloorRC.x, sourceCeilRC.y, d);\n float bottomRight = getA(b, sourceCeilRC.x, sourceCeilRC.y, d);\n\n vec2 fracRC = sourceFracIndexRC - vec2(sourceFloorRC);\n\n float top = topLeft + (topRight - topLeft) * fracRC.y;\n float bottom = bottomLeft + (bottomRight - bottomLeft) * fracRC.y;\n float newValue = top + (bottom - top) * fracRC.x;\n\n setOutput(newValue);\n }\n ";
  8551. };
  8552. }(),
  8553. zi = function () {
  8554. return function (t, e, n, r) {
  8555. this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = [];
  8556. var o = t[0],
  8557. a = t[1],
  8558. i = t[2],
  8559. u = t[3];
  8560. this.outputShape = [o, e, n, u];
  8561. var s = [r && e > 1 ? a - 1 : a, r && n > 1 ? i - 1 : i],
  8562. c = [r && e > 1 ? e - 1 : e, r && n > 1 ? n - 1 : n];
  8563. this.userCode = "\n const vec3 effectiveInputOverOutputRatioRC = vec3(\n " + s[0] / c[0] + ",\n " + s[1] / c[1] + ",\n " + s[1] / c[1] + ");\n const vec3 inputShapeRC = vec3(" + a + ".0, " + i + ".0,\n " + i + ".0);\n\n float getAValue(int b, int r, int c, int d) {\n return getChannel(getA(b, r, c, d), vec2(c, d));\n }\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n // Calculate values for next column in yRC.z.\n ivec3 yRC = coords.yzz + ivec3(0, 0, 1);\n\n // Fractional source index.\n vec3 sourceFracIndexRC = vec3(yRC) * effectiveInputOverOutputRatioRC;\n\n // Compute the four integer indices.\n ivec3 sourceFloorRC = ivec3(sourceFracIndexRC);\n ivec3 sourceCeilRC = ivec3(\n min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));\n\n // Should we calculate next column and row elements in 2x2 packed cell.\n bool hasNextCol = d < " + (u - 1) + ";\n bool hasNextRow = coords.z < " + (n - 1) + ";\n\n // In parallel, construct four corners for all four components in\n // packed 2x2 cell.\n vec4 topLeft = vec4(\n getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d),\n hasNextCol ? getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d + 1)\n : 0.0,\n hasNextRow ? getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d)\n : 0.0,\n (hasNextRow && hasNextCol) ?\n getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d + 1) : 0.0);\n\n vec4 bottomLeft = vec4(\n getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d),\n hasNextCol ? getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d + 1)\n : 0.0,\n hasNextRow ? getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d)\n : 0.0,\n (hasNextRow && hasNextCol) ?\n getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d + 1) : 0.0);\n\n vec4 topRight = vec4(\n getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d),\n hasNextCol ? getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d + 1)\n : 0.0,\n hasNextRow ? getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d)\n : 0.0,\n (hasNextRow && hasNextCol) ?\n getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d + 1) : 0.0);\n\n vec4 bottomRight = vec4(\n getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d),\n hasNextCol ? getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d + 1)\n : 0.0,\n hasNextRow ? getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d)\n : 0.0,\n (hasNextRow && hasNextCol) ?\n getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d + 1) : 0.0);\n\n vec3 fracRC = sourceFracIndexRC - vec3(sourceFloorRC);\n\n vec4 top = mix(topLeft, topRight, fracRC.yyzz);\n vec4 bottom = mix(bottomLeft, bottomRight, fracRC.yyzz);\n vec4 newValue = mix(top, bottom, fracRC.x);\n\n setOutput(newValue);\n }\n ";
  8564. };
  8565. }(),
  8566. Gi = function () {
  8567. return function (t, e, n) {
  8568. this.variableNames = ["dy"], this.outputShape = [], this.outputShape = e.shape;
  8569. var r = e.shape,
  8570. o = r[1],
  8571. a = r[2],
  8572. i = t.shape,
  8573. u = i[1],
  8574. s = i[2],
  8575. c = [n && u > 1 ? o - 1 : o, n && s > 1 ? a - 1 : a],
  8576. l = [n && u > 1 ? u - 1 : u, n && s > 1 ? s - 1 : s],
  8577. h = c[0] / l[0],
  8578. f = c[1] / l[1],
  8579. p = 1 / h,
  8580. d = 1 / f,
  8581. v = 2 * Math.ceil(p) + 2,
  8582. m = 2 * Math.ceil(d) + 2;
  8583. this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n int r = coords[1];\n int c = coords[2];\n\n float accumulator = 0.0;\n\n const float heightScale = float(" + h + ");\n const float widthScale = float(" + f + ");\n\n const float invHeightScale = float(" + p + ");\n const float invWidthScale = float(" + d + ");\n\n const int winHeight = int(" + v + ");\n const int winWidth = int(" + m + ");\n\n // Compute bounds for where in dy we will look\n float startRLerp = floor(float(r) * invHeightScale);\n int startDyR = int(floor(startRLerp - float(winHeight / 2)));\n\n float startCLerp = floor(float(c) * invWidthScale);\n int startDyC = int(floor(startCLerp - float(winWidth / 2)));\n\n // Loop over dy\n for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {\n int dyR = dyROffset + startDyR;\n\n // Guard against the window exceeding the bounds of dy\n if (dyR < 0 || dyR >= " + u + ") {\n continue;\n }\n\n for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {\n int dyC = dyCOffset + startDyC;\n\n // Guard against the window exceeding the bounds of dy\n if (dyC < 0 || dyC >= " + s + ") {\n continue;\n }\n\n float sourceFracRow =\n float(" + c[0] + ") *\n (float(dyR) / float(" + l[0] + "));\n\n float sourceFracCol =\n float(" + c[1] + ") *\n (float(dyC) / float(" + l[1] + "));\n\n int sourceNearestRow = int(min(\n float(int(" + o + ") - 1),\n " + n + " ? float(round(sourceFracRow)) :\n float(floor(sourceFracRow))));\n\n int sourceNearestCol = int(min(\n float(int(" + a + ") - 1),\n " + n + " ? float(round(sourceFracCol)) :\n float(floor(sourceFracCol))));\n\n if (r == sourceNearestRow && c == sourceNearestCol) {\n accumulator += getDy(b, dyR, dyC, d);\n }\n }\n }\n // End loop over dy\n\n setOutput(accumulator);\n }\n ";
  8584. };
  8585. }(),
  8586. Hi = function () {
  8587. return function (t, e, n, r) {
  8588. this.variableNames = ["A"], this.outputShape = [];
  8589. var o = t[0],
  8590. a = t[1],
  8591. i = t[2],
  8592. u = t[3];
  8593. this.outputShape = [o, e, n, u];
  8594. var s = [r && e > 1 ? a - 1 : a, r && n > 1 ? i - 1 : i],
  8595. c = [r && e > 1 ? e - 1 : e, r && n > 1 ? n - 1 : n],
  8596. l = r ? "0.5" : "0.0";
  8597. this.userCode = "\n const vec2 effectiveInputOverOutputRatioRC = vec2(\n " + s[0] / c[0] + ",\n " + s[1] / c[1] + ");\n const vec2 inputShapeRC = vec2(" + a + ".0, " + i + ".0);\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n ivec2 yRC = coords.yz;\n\n // Fractional source index.\n vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;\n\n // Compute the coordinators of nearest neighbor point.\n ivec2 sourceNearestRC = ivec2(\n min(inputShapeRC - 1.0, floor(sourceFracIndexRC + " + l + ")));\n\n float newValue = getA(b, sourceNearestRC.x, sourceNearestRC.y, d);\n\n setOutput(newValue);\n }\n ";
  8598. };
  8599. }(),
  8600. qi = function () {
  8601. return function (t, e) {
  8602. this.variableNames = ["x"];
  8603. var n = t.length;
  8604. if (n > 4) throw new Error("WebGL backend: Reverse of rank-" + n + " tensor is not yet supported");
  8605. if (this.outputShape = t, 1 !== n) {
  8606. var r = t.map(function (n, r) {
  8607. return function (n) {
  8608. return -1 !== e.indexOf(n) && 1 !== t[n] ? t[n] + " - coords[" + n + "] - 1" : "coords[" + n + "]";
  8609. }(r);
  8610. }).join(","),
  8611. o = aa(n);
  8612. this.userCode = "\n void main() {\n " + o + " coords = getOutputCoords();\n setOutput(getX(" + r + "));\n }\n ";
  8613. } else this.userCode = "\n void main() {\n int coord = getOutputCoords();\n setOutput(getX(" + t[0] + " - coord - 1));\n }\n ";
  8614. };
  8615. }(),
  8616. Ki = function () {
  8617. return function (t, e) {
  8618. this.variableNames = ["x"], this.packedInputs = !0, this.packedOutput = !0;
  8619. var n = t.length;
  8620. if (n > 4) throw new Error("WebGL backend: Reverse of rank-" + n + " tensor is not yet supported");
  8621. this.outputShape = t;
  8622. var r = qo("rc", n),
  8623. o = r[n - 1] + " + 1 < " + this.outputShape[n - 1],
  8624. a = r[n - 2] + " + 1 < " + this.outputShape[n - 2],
  8625. i = aa(n);
  8626. function u(n) {
  8627. var r = t.map(function (r, o) {
  8628. return function (n, r) {
  8629. return -1 !== e.indexOf(n) && 1 !== t[n] ? t[n] + " - " + r[n] + " - 1" : "" + r[n];
  8630. }(o, n);
  8631. });
  8632. return "getChannel(getX(" + r.join(",") + "), vec2(" + r.slice(-2).join(",") + "))";
  8633. }
  8634. this.userCode = 1 === n ? "\n void main(){\n int rc = getOutputCoords();\n vec4 result = vec4(0.);\n result.r = getChannel(getX(" + t[0] + " - rc - 1),\n " + t[0] + " - rc - 1);\n if(" + o + "){\n result.g = getChannel(getX(" + t[0] + " - (rc + 1) - 1),\n " + t[0] + " - (rc + 1) - 1);\n }\n setOutput(result);\n }\n " : "\n void main() {\n " + i + " rc = getOutputCoords();\n vec4 result = vec4(0.);\n result.r = " + function (t) {
  8635. return u(t);
  8636. }(r.slice()) + ";\n if(" + o + "){\n result.g = " + function (t) {
  8637. return t[n - 1] = "(" + t[n - 1] + " + 1)", u(t);
  8638. }(r.slice()) + ";\n }\n if(" + a + ") {\n result.b = " + function (t) {
  8639. return t[n - 2] = "(" + t[n - 2] + " + 1)", u(t);
  8640. }(r.slice()) + ";\n if(" + o + ") {\n result.a = " + function (t) {
  8641. return t[n - 1] = "(" + t[n - 1] + " + 1)", t[n - 2] = "(" + t[n - 2] + " + 1)", u(t);
  8642. }(r.slice()) + ";\n }\n }\n setOutput(result);\n }\n ";
  8643. };
  8644. }(),
  8645. ji = function () {
  8646. return function (t, e, n, r, o, a, i) {
  8647. void 0 === i && (i = !0), this.variableNames = ["updates", "indices", "defaultValue"], this.outputShape = a;
  8648. var u = aa(o.length),
  8649. s = aa(a.length),
  8650. c = "";
  8651. 1 === n ? c = "i" : 2 === n && (c = "i, j");
  8652. var l = "getIndices(" + c + ")",
  8653. h = "";
  8654. 1 === r ? h = "i" : 2 === r && (h = "i, coords[1]");
  8655. var f = "getUpdates(" + h + ")",
  8656. p = e > 1 ? "strides[j]" : "strides";
  8657. this.userCode = "\n " + u + " strides = " + u + "(" + o + ");\n\n void main() {\n " + s + " coords = getOutputCoords();\n float sum = 0.0;\n bool found = false;\n for (int i = 0; i < " + t + "; i++) {\n int flattenedIndex = 0;\n for (int j = 0; j < " + e + "; j++) {\n int index = round(" + l + ");\n flattenedIndex += index * " + p + ";\n }\n if (flattenedIndex == coords[0]) {\n sum += " + f + ";\n found = true;\n }\n }\n setOutput(mix(getDefaultValue(), sum, float(found)));\n }\n ";
  8658. };
  8659. }(),
  8660. Xi = function () {
  8661. return function (t, e) {
  8662. this.variableNames = ["x", "segmentIds"];
  8663. var n = t.windowSize,
  8664. r = t.batchSize,
  8665. o = t.inSize,
  8666. a = t.numSegments,
  8667. i = a * Math.ceil(o / n);
  8668. this.outputShape = [r, i];
  8669. var u = 4 * Math.floor(n / 4),
  8670. s = n % 4,
  8671. c = "\n sumValue += dot(values, segFilter);\n ",
  8672. l = "";
  8673. o % n > 0 && (l = "\n if (inIdx < 0 || inIdx >= " + o + ") {\n return initializationValue;\n }\n ");
  8674. var h = "";
  8675. o % n > 0 && (h = "\n if (inIdx < 0 || inIdx >= " + o + ") {\n return -1.0;\n }\n "), this.userCode = "\n const float initializationValue = 0.0;\n\n float getValue(int batch, int inIdx) {\n " + l + "\n return getX(batch, inIdx);\n }\n\n float getSegmentIdAtIndex(int inIdx) {\n " + h + "\n return getSegmentIds(inIdx);\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = int(floor(float(outIdx) / float(\n " + a + ")) * float(" + n + "));\n int currentSeg = int(mod(float(outIdx), float(" + a + ")));\n\n float sumValue = 0.0;\n\n for (int i = 0; i < " + u + "; i += 4) {\n int inIdx = inOffset + i;\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n getValue(batch, inIdx + 3)\n );\n\n vec4 segFilter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 3)) == currentSeg ? 1 : 0\n );\n\n " + c + "\n }\n\n int inIdx = inOffset + " + u + ";\n if (" + (1 === s) + ") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n int inIdxSeg = int(getSegmentIdAtIndex(inIdx));\n\n vec4 segFilter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n 0,\n 0,\n 0\n );\n\n " + c + "\n } else if (" + (2 === s) + ") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n initializationValue,\n initializationValue\n );\n\n vec4 segFilter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,\n 0,\n 0\n );\n\n " + c + "\n } else if (" + (3 === s) + ") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n initializationValue\n );\n\n vec4 segFilter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,\n 0\n );\n\n " + c + "\n }\n setOutput(sumValue);\n }\n ";
  8676. };
  8677. }(),
  8678. $i = function () {
  8679. return function (t, e, n) {
  8680. var r, o;
  8681. if (this.variableNames = ["c", "a", "b"], this.outputShape = e, n > 4) throw Error("Where for rank " + n + " is not yet supported");
  8682. if (1 === n) o = "resRC", r = "resRC"; else {
  8683. for (var a = ["resRC.x", "resRC.y", "resRC.z", "resRC.w"], i = [], u = [], s = 0; s < e.length; s++) u.push("" + a[s]), s < t && i.push("" + a[s]);
  8684. r = i.join(), o = u.join();
  8685. }
  8686. var c = aa(n);
  8687. this.userCode = "\n void main() {\n " + c + " resRC = getOutputCoords();\n float cVal = getC(" + r + ");\n if (cVal >= 1.0) {\n setOutput(getA(" + o + "));\n } else {\n setOutput(getB(" + o + "));\n }\n }\n ";
  8688. };
  8689. }(),
  8690. Yi = function () {
  8691. function t(t) {
  8692. this.variableNames = ["source"], this.outputShape = t, this.rank = t.length;
  8693. var e,
  8694. n = aa(this.rank),
  8695. r = "uniform int start[" + this.rank + "];",
  8696. o = function (t) {
  8697. if (1 === t) return "sourceLoc";
  8698. if (t <= 6) return Qi.slice(0, t).map(function (t) {
  8699. return "sourceLoc." + t;
  8700. }).join(",");
  8701. throw Error("Slicing for rank " + t + " is not yet supported");
  8702. }(this.rank);
  8703. e = "\n " + n + " sourceLoc;\n " + n + " coords = getOutputCoords();\n " + t.map(function (t, e) {
  8704. return "sourceLoc." + Qi[e] + " = start[" + e + "] + coords." + Qi[e] + ";";
  8705. }).join("\n") + "\n ", this.userCode = "\n " + r + "\n void main() {\n " + e + "\n setOutput(getSource(" + o + "));\n }\n ";
  8706. }
  8707. return t.prototype.getCustomSetupFunc = function (t) {
  8708. var e = this;
  8709. if (t.length !== this.rank) throw Error("The rank (" + this.rank + ") of the program must match the length of start (" + t.length + ")");
  8710. return function (n, r) {
  8711. null == e.startLoc && (e.startLoc = n.getUniformLocationNoThrow(r, "start"), null == e.startLoc) || n.gl.uniform1iv(e.startLoc, t);
  8712. };
  8713. }, t;
  8714. }(),
  8715. Qi = ["x", "y", "z", "w", "u", "v"];
  8716. var Ji = function () {
  8717. function t(t) {
  8718. this.variableNames = ["source"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t, this.rank = t.length;
  8719. var e = aa(this.rank),
  8720. n = qo("coords", this.rank),
  8721. r = qo("sourceLoc", this.rank),
  8722. o = 1 === this.rank ? "sourceLoc" : "vec2(" + r.slice(-2).join() + ")",
  8723. a = "getChannel(getSource(" + r.join() + "), " + o + ")",
  8724. i = "\n result.x = " + a + ";\n if (++" + n[this.rank - 1] + " < " + t[this.rank - 1] + ") {\n ++" + r[this.rank - 1] + ";\n result.y = " + a + ";\n --" + r[this.rank - 1] + ";\n }\n ",
  8725. u = 1 === this.rank ? "" : "\n --" + n[this.rank - 1] + ";\n if (++" + n[this.rank - 2] + " < " + t[this.rank - 2] + ") {\n ++" + r[this.rank - 2] + ";\n result.z = " + a + ";\n if (++" + n[this.rank - 1] + " < " + t[this.rank - 1] + ") {\n ++" + r[this.rank - 1] + ";\n result.w = " + a + ";\n }\n }\n ",
  8726. s = this.rank <= 4 ? "sourceLoc = coords +\n " + e + "(" + t.map(function (t, e) {
  8727. return "start[" + e + "]";
  8728. }).join() + ");" : t.map(function (t, e) {
  8729. return r[e] + " = " + n[e] + " + start[" + e + "];";
  8730. }).join("\n");
  8731. this.userCode = "\n uniform int start[" + this.rank + "];\n void main() {\n " + e + " coords = getOutputCoords();\n " + e + " sourceLoc;\n " + s + "\n vec4 result = vec4(0.);\n " + i + "\n " + u + "\n setOutput(result);\n }\n ";
  8732. }
  8733. return t.prototype.getCustomSetupFunc = function (t) {
  8734. var e = this;
  8735. if (t.length !== this.rank) throw Error("The rank (" + this.rank + ") of the program must match the length of start (" + t.length + ")");
  8736. return function (n, r) {
  8737. null == e.startLoc && (e.startLoc = n.getUniformLocationNoThrow(r, "start"), null == e.startLoc) || n.gl.uniform1iv(e.startLoc, t);
  8738. };
  8739. }, t;
  8740. }(),
  8741. Zi = function () {
  8742. return function (t, e, n) {
  8743. this.variableNames = ["x"], this.outputShape = n;
  8744. var r = n.length,
  8745. o = aa(n.length),
  8746. a = aa(n.length),
  8747. i = "";
  8748. if (1 === r) i = "coords * strides + begin"; else {
  8749. var u = 0;
  8750. i = n.map(function (t, e) {
  8751. return u++, 1 === n.length ? "coords * strides[" + e + "] + begin[" + e + "]" : "coords[" + (u - 1) + "] * strides[" + e + "] + begin[" + e + "]";
  8752. }).join(",");
  8753. }
  8754. this.userCode = "\n " + o + " begin = " + o + "(" + t + ");\n " + o + " strides = " + o + "(" + e + ");\n\n void main() {\n " + a + " coords = getOutputCoords();\n setOutput(getX(" + i + "));\n }\n ";
  8755. };
  8756. }(),
  8757. tu = function () {
  8758. function t(t) {
  8759. this.gpgpu = t, this.numUsedTextures = 0, this.numFreeTextures = 0, this.freeTextures = {}, this.logEnabled = !1, this.usedTextures = {};
  8760. }
  8761. return t.prototype.acquireTexture = function (t, e, n) {
  8762. var r,
  8763. o = eu(e, n),
  8764. a = nu(t, o, n);
  8765. if (a in this.freeTextures || (this.freeTextures[a] = []), a in this.usedTextures || (this.usedTextures[a] = []), this.freeTextures[a].length > 0) {
  8766. this.numFreeTextures--, this.numUsedTextures++, this.log();
  8767. var i = this.freeTextures[a].shift();
  8768. return this.usedTextures[a].push(i), i;
  8769. }
  8770. return this.numUsedTextures++, this.log(), o === Bt.PACKED_2X2_FLOAT32 ? r = this.gpgpu.createPackedMatrixTexture(t[0], t[1]) : o === Bt.PACKED_2X2_FLOAT16 ? r = this.gpgpu.createFloat16PackedMatrixTexture(t[0], t[1]) : o === Bt.UNPACKED_FLOAT32 ? r = this.gpgpu.createFloat32MatrixTexture(t[0], t[1]) : o === Bt.UNPACKED_FLOAT16 ? r = this.gpgpu.createFloat16MatrixTexture(t[0], t[1]) : o === Bt.PACKED_4X1_UNSIGNED_BYTE && (r = this.gpgpu.createUnsignedBytesMatrixTexture(t[0], t[1])), this.usedTextures[a].push(r), r;
  8771. }, t.prototype.releaseTexture = function (t, e, n, r) {
  8772. if (null != this.freeTextures) {
  8773. var o = nu(e, eu(n, r), r);
  8774. o in this.freeTextures || (this.freeTextures[o] = []), this.freeTextures[o].push(t), this.numFreeTextures++, this.numUsedTextures--;
  8775. var a = this.usedTextures[o],
  8776. i = a.indexOf(t);
  8777. if (i < 0) throw new Error("Cannot release a texture that was never provided by this texture manager");
  8778. a.splice(i, 1), this.log();
  8779. }
  8780. }, t.prototype.log = function () {
  8781. if (this.logEnabled) {
  8782. var t = this.numFreeTextures + this.numUsedTextures;
  8783. console.log("Free/Used", this.numFreeTextures + " / " + this.numUsedTextures, "(" + t + ")");
  8784. }
  8785. }, t.prototype.getNumUsedTextures = function () {
  8786. return this.numUsedTextures;
  8787. }, t.prototype.getNumFreeTextures = function () {
  8788. return this.numFreeTextures;
  8789. }, t.prototype.dispose = function () {
  8790. var t = this;
  8791. if (null != this.freeTextures) {
  8792. for (var e in this.freeTextures) this.freeTextures[e].forEach(function (e) {
  8793. t.gpgpu.deleteMatrixTexture(e);
  8794. });
  8795. for (var e in this.usedTextures) this.usedTextures[e].forEach(function (e) {
  8796. t.gpgpu.deleteMatrixTexture(e);
  8797. });
  8798. this.freeTextures = null, this.usedTextures = null, this.numUsedTextures = 0, this.numFreeTextures = 0;
  8799. }
  8800. }, t;
  8801. }();
  8802. function eu(t, e) {
  8803. if (t === Mt.UPLOAD) return Bt.PACKED_2X2_FLOAT32;
  8804. if (t === Mt.RENDER || null == t) return function (t) {
  8805. return a().getBool("WEBGL_RENDER_FLOAT32_ENABLED") ? t ? Bt.PACKED_2X2_FLOAT32 : Bt.UNPACKED_FLOAT32 : t ? Bt.PACKED_2X2_FLOAT16 : Bt.UNPACKED_FLOAT16;
  8806. }(e);
  8807. if (t === Mt.DOWNLOAD || t === Mt.PIXELS) return Bt.PACKED_4X1_UNSIGNED_BYTE;
  8808. throw new Error("Unknown logical texture type " + t);
  8809. }
  8810. function nu(t, e, n) {
  8811. return t[0] + "_" + t[1] + "_" + e + "_" + n;
  8812. }
  8813. var ru = function () {
  8814. return function (t, e) {
  8815. this.variableNames = ["A"];
  8816. for (var n = new Array(t.length), r = 0; r < n.length; r++) n[r] = t[r] * e[r];
  8817. this.outputShape = n, this.rank = n.length;
  8818. var o = aa(this.rank),
  8819. a = function (t) {
  8820. var e = t.length;
  8821. if (e > 5) throw Error("Tile for rank " + e + " is not yet supported");
  8822. if (1 === e) return "imod(resRC, " + t[0] + ")";
  8823. for (var n = ["resRC.x", "resRC.y", "resRC.z", "resRC.w", "resRC.u"], r = [], o = 0; o < t.length; o++) r.push("imod(" + n[o] + ", " + t[o] + ")");
  8824. return r.join();
  8825. }(t);
  8826. this.userCode = "\n void main() {\n " + o + " resRC = getOutputCoords();\n setOutput(getA(" + a + "));\n }\n ";
  8827. };
  8828. }();
  8829. var ou = function () {
  8830. return function (t, e) {
  8831. this.variableNames = ["A"];
  8832. for (var n = new Array(t.length), r = 0; r < n.length; r++) n[r] = t[e[r]];
  8833. this.outputShape = n, this.rank = n.length;
  8834. var o = aa(this.rank),
  8835. a = function (t) {
  8836. var e = t.length;
  8837. if (e > 6) throw Error("Transpose for rank " + e + " is not yet supported");
  8838. for (var n = ["resRC.x", "resRC.y", "resRC.z", "resRC.w", "resRC.u", "resRC.v"], r = new Array(e), o = 0; o < t.length; o++) r[t[o]] = n[o];
  8839. return r.join();
  8840. }(e);
  8841. this.userCode = "\n void main() {\n " + o + " resRC = getOutputCoords();\n setOutput(getA(" + a + "));\n }\n ";
  8842. };
  8843. }();
  8844. var au = function () {
  8845. return function (t, e) {
  8846. this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0;
  8847. for (var n = new Array(t.length), r = 0; r < n.length; r++) n[r] = t[e[r]];
  8848. if (this.outputShape = n, this.rank = n.length, this.rank > 6) throw Error("Packed transpose for rank " + this.rank + " is not yet supported.");
  8849. var o = aa(this.rank),
  8850. a = Ho("rc", this.rank),
  8851. i = new Array(this.rank);
  8852. for (r = 0; r < e.length; r++) i[e[r]] = a[r];
  8853. var u = "vec2(" + i.slice(-2).join() + ")",
  8854. s = "++" + a[this.rank - 1] + " < " + n[this.rank - 1],
  8855. c = "getChannel(getA(" + i.join() + "), " + u + ")";
  8856. this.userCode = "\n void main() {\n " + o + " rc = getOutputCoords();\n vec4 result = vec4(0.);\n result[0] = " + c + ";\n if(" + s + ") {\n result[1] = " + c + ";\n }\n --" + a[this.rank - 1] + ";\n if(++" + a[this.rank - 2] + " < " + n[this.rank - 2] + ") {\n result[2] = " + c + ";\n if(" + s + ") {\n result[3] = " + c + ";\n }\n }\n setOutput(result);\n }\n ";
  8857. };
  8858. }(),
  8859. iu = 1.7580993408473768,
  8860. uu = 1.0507009873554805,
  8861. su = function () {
  8862. return function (t, e) {
  8863. this.variableNames = ["A"], this.outputShape = t, this.userCode = "\n float unaryOperation(float x) {\n " + e + "\n }\n\n void main() {\n float x = getAAtOutCoords();\n float y = unaryOperation(x);\n\n setOutput(y);\n }\n ";
  8864. };
  8865. }(),
  8866. cu = "if (isnan(x)) return x;",
  8867. lu = "return x;",
  8868. hu = "return abs(x);",
  8869. fu = cu + "\n return (x < 0.0) ? 0.0 : x;\n",
  8870. pu = cu + "\n return (x < 0.0) ? 0.0 : min(6.0, x);\n",
  8871. du = "return (x >= 0.0) ? x : (exp(x) - 1.0);",
  8872. vu = "\n // Stable and Attracting Fixed Point (0, 1) for Normalized Weights.\n // see: https://arxiv.org/abs/1706.02515\n float scaleAlpha = " + iu + ";\n float scale = " + uu + ";\n return (x >= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);\n";
  8873. var mu = "return -x;",
  8874. gu = "return ceil(x);",
  8875. yu = "return floor(x);",
  8876. xu = "return exp(x);",
  8877. bu = "return exp(x) - 1.0;",
  8878. wu = cu + "\n return sin(x);\n",
  8879. Cu = cu + "\n return cos(x);\n",
  8880. Eu = cu + "\n if (abs(x) > 1.) {\n return NAN;\n }\n return asin(x);\n",
  8881. Ru = cu + "\n if (abs(x) > 1.) {\n return NAN;\n }\n return acos(x);\n",
  8882. Iu = cu + "\n return atan(x);\n",
  8883. ku = cu + "return log(x + sqrt(x * x + 1.0));",
  8884. Su = cu + "\n if (x < 1.0) return NAN;\n return log(x + sqrt(x * x - 1.0));",
  8885. Au = cu + "\n if ((x < -1.0) || (x > 1.0)) return NAN;\n return (log(1.0 + x) - log(1.0 - x)) / 2.0;",
  8886. Du = "return x;",
  8887. Tu = "return x;",
  8888. Nu = "\n vec4 result = x * vec4(greaterThanEqual(x, vec4(0.0)));\n bvec4 isNaN = isnan(x);\n\n result.r = isNaN.r ? x.r : result.r;\n result.g = isNaN.g ? x.g : result.g;\n result.b = isNaN.b ? x.b : result.b;\n result.a = isNaN.a ? x.a : result.a;\n\n return result;\n",
  8889. Fu = "\n vec4 result = min(x, vec4(6.)) * vec4(greaterThanEqual(x, vec4(0.0)));\n bvec4 isNaN = isnan(x);\n\n result.r = isNaN.r ? x.r : result.r;\n result.g = isNaN.g ? x.g : result.g;\n result.b = isNaN.b ? x.b : result.b;\n result.a = isNaN.a ? x.a : result.a;\n\n return result;\n",
  8890. Ou = "\n vec4 result;\n\n result.r = (x.r >= 0.0) ? x.r : (exp(x.r) - 1.0);\n result.g = (x.g >= 0.0) ? x.g : (exp(x.g) - 1.0);\n result.b = (x.b >= 0.0) ? x.b : (exp(x.b) - 1.0);\n result.a = (x.a >= 0.0) ? x.a : (exp(x.a) - 1.0);\n\n return result;\n",
  8891. _u = function () {
  8892. return function (t, e) {
  8893. this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t, this.userCode = "\n vec4 unaryOperation(vec4 x) {\n " + e + "\n }\n\n void main() {\n vec4 x = getAAtOutCoords();\n vec4 y = unaryOperation(x);\n\n setOutput(y);\n }\n ";
  8894. };
  8895. }(),
  8896. Mu = function () {
  8897. return function (t) {
  8898. this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !1, this.outputShape = t;
  8899. var e = t.length,
  8900. n = qo("rc", e),
  8901. r = aa(e),
  8902. o = function (t, e) {
  8903. if (1 === t) return "rc";
  8904. for (var n = "", r = 0; r < t; r++) n += e[r], r < t - 1 && (n += ",");
  8905. return n;
  8906. }(e, n),
  8907. a = n.slice(-2),
  8908. i = e <= 1 ? "rc" : "vec2(" + a.join(",") + ")";
  8909. this.userCode = "\n void main() {\n " + r + " rc = getOutputCoords();\n vec4 packedInput = getA(" + o + ");\n\n setOutput(getChannel(packedInput, " + i + "));\n }\n ";
  8910. };
  8911. }(),
  8912. Bu = {};
  8913. function Pu(t, e) {
  8914. if (void 0 === e && (e = !1), "linear" === t) return e ? Tu : lu;
  8915. if ("relu" === t) return e ? Nu : fu;
  8916. if ("elu" === t) return e ? Ou : du;
  8917. if ("relu6" === t) return e ? Fu : pu;
  8918. if ("prelu" === t) return e ? wa : xa;
  8919. throw new Error("Activation " + t + " has not been implemented for the WebGL backend.");
  8920. }
  8921. var Lu = 600;
  8922. var Wu = function (t) {
  8923. function o(e) {
  8924. var n,
  8925. r = t.call(this) || this;
  8926. if (r.gpgpu = e, r.pendingRead = new WeakMap(), r.pendingDisposal = new WeakSet(), r.dataRefCount = new WeakMap(), r.numBytesInGPU = 0, r.uploadWaitMs = 0, r.downloadWaitMs = 0, r.warnedAboutMemory = !1, r.pendingDeletes = 0, r.disposed = !1, !a().getBool("HAS_WEBGL")) throw new Error("WebGL is not supported on this device");
  8927. if (null == e) {
  8928. var o = Ut(a().getNumber("WEBGL_VERSION"));
  8929. r.binaryCache = (n = a().getNumber("WEBGL_VERSION")) in Bu ? Bu[n] : (Bu[n] = {}, Bu[n]), r.gpgpu = new Ci(o), r.canvas = o.canvas, r.gpgpuCreatedLocally = !0;
  8930. } else r.binaryCache = {}, r.gpgpuCreatedLocally = !1, r.canvas = e.gl.canvas;
  8931. return r.textureManager = new tu(r.gpgpu), r.numMBBeforeWarning = null == a().global.screen ? 1024 : a().global.screen.height * a().global.screen.width * window.devicePixelRatio * Lu / 1024 / 1024, r.texData = new so(r, Nt), r;
  8932. }
  8933. return e(o, t), o.prototype.numDataIds = function () {
  8934. return this.texData.numDataIds() + (this.cpuBackend ? this.cpuBackend.numDataIds() : 0) - this.pendingDeletes;
  8935. }, o.prototype.fromPixels = function (t, e) {
  8936. if (null == t) throw new Error("pixels passed to tf.browser.fromPixels() can not be null");
  8937. var n = "undefined" != typeof OffscreenCanvas && t instanceof OffscreenCanvas || "undefined" != typeof HTMLCanvasElement && t instanceof HTMLCanvasElement,
  8938. r = t.data instanceof Uint8Array,
  8939. o = "undefined" != typeof ImageData && t instanceof ImageData,
  8940. i = "undefined" != typeof HTMLVideoElement && t instanceof HTMLVideoElement,
  8941. u = "undefined" != typeof HTMLImageElement && t instanceof HTMLImageElement,
  8942. s = i ? [t.videoWidth, t.videoHeight] : [t.width, t.height],
  8943. c = s[0],
  8944. l = s[1],
  8945. h = [l, c],
  8946. f = [l, c, e];
  8947. if (!(n || r || o || i || u)) throw new Error("pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData in browser, or OffscreenCanvas, ImageData in webworker or {data: Uint32Array, width: number, height: number}, but was " + t.constructor.name);
  8948. (u || i) && (null == this.fromPixels2DContext && (this.fromPixels2DContext = Vt(a().getNumber("WEBGL_VERSION")).getContext("2d")), this.fromPixels2DContext.canvas.width = c, this.fromPixels2DContext.canvas.height = l, this.fromPixels2DContext.drawImage(t, 0, 0, c, l), t = this.fromPixels2DContext.canvas);
  8949. var p,
  8950. d,
  8951. v = this.makeTensorInfo(h, "int32");
  8952. return this.texData.get(v.dataId).usage = Mt.PIXELS, this.gpgpu.uploadPixelDataToTexture(this.getTexture(v.dataId), t), a().getBool("WEBGL_PACK") ? (p = new ei(f), d = this.compileAndRun(p, [v])) : (p = new ti(f), d = this.compileAndRun(p, [v])), this.disposeData(v.dataId), d;
  8953. }, o.prototype.write = function (t, e, n) {
  8954. if (a().getBool("DEBUG") && this.checkNumericalProblems(t), "complex64" === n && null != t) throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");
  8955. var r = {};
  8956. return this.texData.set(r, {
  8957. shape: e,
  8958. dtype: n,
  8959. values: t,
  8960. usage: Mt.UPLOAD
  8961. }), r;
  8962. }, o.prototype.move = function (t, e, n, r) {
  8963. if (a().getBool("DEBUG") && this.checkNumericalProblems(e), "complex64" === r) throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");
  8964. this.texData.set(t, {
  8965. shape: n,
  8966. dtype: r,
  8967. values: e,
  8968. usage: Mt.UPLOAD
  8969. });
  8970. }, o.prototype.readSync = function (t) {
  8971. var e = this.texData.get(t),
  8972. n = e.values,
  8973. r = e.dtype,
  8974. o = e.complexTensors,
  8975. a = e.slice,
  8976. i = e.shape,
  8977. u = e.isPacked;
  8978. if (null != a) {
  8979. var s = void 0;
  8980. s = u ? new _u(i, Du) : new su(i, Du);
  8981. var c = this.runWebGLProgram(s, [{
  8982. dataId: t,
  8983. shape: i,
  8984. dtype: r
  8985. }], r),
  8986. l = this.readSync(c.dataId);
  8987. return this.disposeData(c.dataId), l;
  8988. }
  8989. if (null != n) return this.convertAndCacheOnCPU(t);
  8990. if ("string" === r) return n;
  8991. var h,
  8992. f,
  8993. p = null != this.activeTimers;
  8994. (p && (h = Y()), "complex64" === r) ? f = No(o.real.dataSync(), o.imag.dataSync()) : f = this.getValuesFromTexture(t);
  8995. return p && (this.downloadWaitMs += Y() - h), this.convertAndCacheOnCPU(t, f);
  8996. }, o.prototype.read = function (t) {
  8997. return n(this, void 0, void 0, function () {
  8998. var e, n, o, i, u, s, c, l, h, f, p, d, v, m, g, y, x, b, C, E, R, I;
  8999. return r(this, function (r) {
  9000. switch (r.label) {
  9001. case 0:
  9002. if (this.pendingRead.has(t)) return e = this.pendingRead.get(t), [2, new Promise(function (t) {
  9003. return e.push(t);
  9004. })];
  9005. if (n = this.texData.get(t), o = n.values, i = n.shape, u = n.slice, s = n.dtype, c = n.complexTensors, l = n.isPacked, null != u) return h = void 0, h = l ? new _u(i, Du) : new su(i, Du), f = this.runWebGLProgram(h, [{
  9006. dataId: t,
  9007. shape: i,
  9008. dtype: s
  9009. }], s), p = this.read(f.dataId), this.disposeData(f.dataId), [2, p];
  9010. if (null != o) return [2, this.convertAndCacheOnCPU(t)];
  9011. if (!a().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED") && 2 === a().getNumber("WEBGL_VERSION")) throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported.");
  9012. return d = null, "complex64" !== s && a().get("WEBGL_BUFFER_SUPPORTED") && (v = this.decode(t), m = this.texData.get(v.dataId), d = (I = this.gpgpu).createBufferFromTexture.apply(I, [m.texture].concat(Gt(i)))), this.pendingRead.set(t, []), "complex64" === s ? [3, 2] : [4, this.gpgpu.createAndWaitForFence()];
  9013. case 1:
  9014. r.sent(), r.label = 2;
  9015. case 2:
  9016. return "complex64" !== s ? [3, 4] : [4, Promise.all([c.real.data(), c.imag.data()])];
  9017. case 3:
  9018. return y = r.sent(), x = y[0], b = y[1], g = No(x, b), [3, 5];
  9019. case 4:
  9020. null == d ? g = this.getValuesFromTexture(t) : (C = w(i), g = this.gpgpu.downloadFloat32MatrixFromBuffer(d, C)), r.label = 5;
  9021. case 5:
  9022. return null != v && this.disposeData(v.dataId), E = this.convertAndCacheOnCPU(t, g), R = this.pendingRead.get(t), this.pendingRead.delete(t), R.forEach(function (t) {
  9023. return t(E);
  9024. }), this.pendingDisposal.has(t) && (this.pendingDisposal.delete(t), this.disposeData(t), this.pendingDeletes--), [2, E];
  9025. }
  9026. });
  9027. });
  9028. }, o.prototype.checkNumericalProblems = function (t) {
  9029. if (null != t) for (var e = 0; e < t.length; e++) {
  9030. var n = t[e];
  9031. if (!$t(n)) {
  9032. if (a().getBool("WEBGL_RENDER_FLOAT32_CAPABLE")) throw Error("The value " + n + " cannot be represented with your current settings. Consider enabling float32 rendering: 'tf.env().set('WEBGL_RENDER_FLOAT32_ENABLED', true);'");
  9033. throw Error("The value " + n + " cannot be represented on this device.");
  9034. }
  9035. }
  9036. }, o.prototype.getValuesFromTexture = function (t) {
  9037. var e,
  9038. n = this.texData.get(t),
  9039. r = n.shape,
  9040. o = n.dtype,
  9041. i = n.isPacked,
  9042. u = w(r);
  9043. if (a().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")) {
  9044. var s = this.decode(t),
  9045. c = this.texData.get(s.dataId),
  9046. l = (e = this.gpgpu).downloadMatrixFromPackedTexture.apply(e, [c.texture].concat(Gt(r))).subarray(0, u);
  9047. return this.disposeData(s.dataId), l;
  9048. }
  9049. var h = a().getBool("WEBGL_PACK") && !0 === i,
  9050. f = h ? Re(r) : r,
  9051. p = h ? new ja(f) : new Ka(f),
  9052. d = this.runWebGLProgram(p, [{
  9053. shape: f,
  9054. dtype: o,
  9055. dataId: t
  9056. }], "float32"),
  9057. v = this.texData.get(d.dataId),
  9058. m = this.gpgpu.downloadByteEncodedFloatMatrixFromOutputTexture(v.texture, v.texShape[0], v.texShape[1]).subarray(0, u);
  9059. return this.disposeData(d.dataId), m;
  9060. }, o.prototype.time = function (t) {
  9061. return n(this, void 0, void 0, function () {
  9062. var e, n, o, a, i, u, s;
  9063. return r(this, function (r) {
  9064. switch (r.label) {
  9065. case 0:
  9066. return e = this.activeTimers, n = [], o = !1, null == this.programTimersStack ? (this.programTimersStack = n, o = !0) : this.activeTimers.push(n), this.activeTimers = n, t(), a = b(this.activeTimers.map(function (t) {
  9067. return t.query;
  9068. })).filter(function (t) {
  9069. return null != t;
  9070. }), i = b(this.activeTimers.map(function (t) {
  9071. return t.name;
  9072. })).filter(function (t) {
  9073. return null != t;
  9074. }), this.activeTimers = e, o && (this.programTimersStack = null), [4, Promise.all(a)];
  9075. case 1:
  9076. return u = r.sent(), s = {
  9077. uploadWaitMs: this.uploadWaitMs,
  9078. downloadWaitMs: this.downloadWaitMs,
  9079. kernelMs: m(u),
  9080. getExtraProfileInfo: function () {
  9081. return u.map(function (t, e) {
  9082. return {
  9083. name: i[e],
  9084. ms: t
  9085. };
  9086. }).map(function (t) {
  9087. return t.name + ": " + t.ms;
  9088. }).join(", ");
  9089. },
  9090. wallMs: null
  9091. }, this.uploadWaitMs = 0, this.downloadWaitMs = 0, [2, s];
  9092. }
  9093. });
  9094. });
  9095. }, o.prototype.memory = function () {
  9096. return {
  9097. unreliable: !1,
  9098. numBytesInGPU: this.numBytesInGPU
  9099. };
  9100. }, o.prototype.startTimer = function () {
  9101. return a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") > 0 ? this.gpgpu.beginQuery() : {
  9102. startMs: Y(),
  9103. endMs: null
  9104. };
  9105. }, o.prototype.endTimer = function (t) {
  9106. return a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") > 0 ? (this.gpgpu.endQuery(), t) : (t.endMs = Y(), t);
  9107. }, o.prototype.getQueryTime = function (t) {
  9108. return n(this, void 0, void 0, function () {
  9109. var e;
  9110. return r(this, function (n) {
  9111. return a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") > 0 ? [2, this.gpgpu.waitForQueryAndGetTime(t)] : [2, (e = t).endMs - e.startMs];
  9112. });
  9113. });
  9114. }, o.prototype.disposeData = function (t) {
  9115. if (!this.pendingDisposal.has(t)) {
  9116. if (this.pendingRead.has(t)) return this.pendingDisposal.add(t), void this.pendingDeletes++;
  9117. if (this.texData.has(t)) {
  9118. this.releaseGPUData(t);
  9119. var e = this.texData.get(t).complexTensors;
  9120. null != e && (e.real.dispose(), e.imag.dispose()), this.texData.delete(t);
  9121. }
  9122. }
  9123. }, o.prototype.releaseGPUData = function (t) {
  9124. var e = this.texData.get(t),
  9125. n = e.texture,
  9126. r = e.dtype,
  9127. o = e.texShape,
  9128. a = e.usage,
  9129. i = e.isPacked,
  9130. u = e.slice,
  9131. s = u && u.origDataId || t,
  9132. c = this.dataRefCount.get(s);
  9133. c > 1 ? this.dataRefCount.set(s, c - 1) : (this.dataRefCount.delete(s), null != n && (this.numBytesInGPU -= this.computeBytes(o, r), this.textureManager.releaseTexture(n, o, a, i)));
  9134. var l = this.texData.get(t);
  9135. l.texture = null, l.texShape = null, l.isPacked = !1, l.slice = null;
  9136. }, o.prototype.getTexture = function (t) {
  9137. return this.uploadToGPU(t), this.texData.get(t).texture;
  9138. }, o.prototype.getDataInfo = function (t) {
  9139. return this.texData.get(t);
  9140. }, o.prototype.getCPUBackend = function () {
  9141. return a().getBool("WEBGL_CPU_FORWARD") ? (null == this.cpuBackend && (this.cpuBackend = Nt.findBackend("cpu")), this.cpuBackend) : null;
  9142. }, o.prototype.shouldExecuteOnCPU = function (t, e) {
  9143. var n = this;
  9144. return void 0 === e && (e = 128), null != this.getCPUBackend() && t.every(function (t) {
  9145. return null == n.texData.get(t.dataId).texture && t.size < e;
  9146. });
  9147. }, o.prototype.getGPGPUContext = function () {
  9148. return this.gpgpu;
  9149. }, o.prototype.complex = function (t, e) {
  9150. var n = this.makeOutput(t.shape, "complex64");
  9151. return this.texData.get(n.dataId).complexTensors = {
  9152. real: Nt.keep(t.clone()),
  9153. imag: Nt.keep(e.clone())
  9154. }, n;
  9155. }, o.prototype.real = function (t) {
  9156. return this.texData.get(t.dataId).complexTensors.real.clone();
  9157. }, o.prototype.imag = function (t) {
  9158. return this.texData.get(t.dataId).complexTensors.imag.clone();
  9159. }, o.prototype.slice = function (t, e, n) {
  9160. if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.slice(t, e, n);
  9161. if (0 === w(n)) return kn([], n, t.dtype);
  9162. var r = this.texData.get(t.dataId).isPacked,
  9163. o = Yr(t.shape, e, n);
  9164. if (r || !o) {
  9165. var i = a().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new Ji(n) : new Yi(n),
  9166. u = i.getCustomSetupFunc(e);
  9167. return this.compileAndRun(i, [t], null, u);
  9168. }
  9169. return this.uploadToGPU(t.dataId), this.shallowSlice(t, e, n);
  9170. }, o.prototype.shallowSlice = function (t, e, n) {
  9171. var r = this.texData.get(t.dataId),
  9172. o = this.makeOutput(n, t.dtype),
  9173. a = this.texData.get(o.dataId);
  9174. Object.assign(a, r), a.shape = n, a.dtype = t.dtype;
  9175. var i = Qr(e, t.strides);
  9176. r.slice && (i += r.slice.flatOffset), a.slice = {
  9177. flatOffset: i,
  9178. origDataId: r.slice && r.slice.origDataId || t.dataId
  9179. };
  9180. var u = this.dataRefCount.get(a.slice.origDataId) || 1;
  9181. return this.dataRefCount.set(a.slice.origDataId, u + 1), o;
  9182. }, o.prototype.stridedSlice = function (t, e, n, r) {
  9183. if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.stridedSlice(t, e, n, r);
  9184. var o = jr(e, n, r);
  9185. if (o.some(function (t) {
  9186. return 0 === t;
  9187. })) return kn([], o);
  9188. var a = new Zi(e, r, o);
  9189. return this.compileAndRun(a, [t]);
  9190. }, o.prototype.reverse = function (t, e) {
  9191. var n = a().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new Ki(t.shape, e) : new qi(t.shape, e);
  9192. return this.compileAndRun(n, [t]);
  9193. }, o.prototype.concat = function (t, e) {
  9194. if ("complex64" === t[0].dtype) {
  9195. var n = t.map(function (t) {
  9196. return Rn(t);
  9197. }),
  9198. r = t.map(function (t) {
  9199. return In(t);
  9200. });
  9201. return En(this.concat(n, e), this.concat(r, e));
  9202. }
  9203. if (this.shouldExecuteOnCPU(t)) return this.cpuBackend.concat(t, e);
  9204. if (1 === t.length) return t[0];
  9205. if (t.length > a().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER")) {
  9206. var o = Math.floor(t.length / 2),
  9207. i = this.concat(t.slice(0, o), e),
  9208. u = this.concat(t.slice(o), e);
  9209. return this.concat([i, u], e);
  9210. }
  9211. if (a().getBool("WEBGL_PACK_ARRAY_OPERATIONS") && t[0].rank > 1) {
  9212. var s = new Sa(t.map(function (t) {
  9213. return t.shape;
  9214. }), e);
  9215. return this.compileAndRun(s, t);
  9216. }
  9217. var c = wn(t.map(function (t) {
  9218. return t.shape;
  9219. }), e),
  9220. l = t.map(function (t) {
  9221. return t.as2D(-1, w(t.shape.slice(e)));
  9222. }),
  9223. h = new ka(l.map(function (t) {
  9224. return t.shape;
  9225. }));
  9226. return this.compileAndRun(h, l).reshape(c);
  9227. }, o.prototype.neg = function (t) {
  9228. if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.neg(t);
  9229. if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, mu, t.dtype);
  9230. var e = new su(t.shape, mu);
  9231. return this.compileAndRun(e, [t]);
  9232. }, o.prototype.batchMatMul = function (t, e, n, r) {
  9233. var o = n ? t.shape[2] : t.shape[1],
  9234. a = r ? e.shape[1] : e.shape[2],
  9235. i = n ? t.shape[1] : t.shape[2],
  9236. u = t.shape[0];
  9237. if ((1 === o || 1 === a) && i > 1e3) {
  9238. n && (t = t.transpose([0, 2, 1])), r && (e = e.transpose([0, 2, 1]));
  9239. var s = 1 === a ? t : t.as3D(u, i, 1),
  9240. c = 1 === a ? 2 : 1,
  9241. l = 1 === a ? e.as3D(u, 1, i) : e;
  9242. return this.multiply(s, l).sum(c, !0);
  9243. }
  9244. var h = Ct(t.dtype, e.dtype),
  9245. f = new Ti(t.shape, [u, o, a], n, r);
  9246. return this.compileAndRun(f, [t, e], h);
  9247. }, o.prototype.fusedBatchMatMul = function (t) {
  9248. var e = t.a,
  9249. n = t.b,
  9250. r = t.transposeA,
  9251. o = t.transposeB,
  9252. a = t.bias,
  9253. i = t.activation,
  9254. u = t.preluActivationWeights,
  9255. s = r ? e.shape[2] : e.shape[1],
  9256. c = o ? n.shape[1] : n.shape[2],
  9257. l = e.shape[0],
  9258. h = Ct(e.dtype, n.dtype),
  9259. f = null != a,
  9260. p = null != u,
  9261. d = i ? Pu(i, !0) : null,
  9262. v = new Ti(e.shape, [l, s, c], r, o, f, d, p),
  9263. m = [e, n];
  9264. return a && m.push(a), u && m.push(u), this.compileAndRun(v, m, h);
  9265. }, o.prototype.multiply = function (t, e) {
  9266. if ("complex64" === t.dtype) {
  9267. var n = this.texData.get(t.dataId),
  9268. r = this.texData.get(e.dataId),
  9269. o = new va(pa, t.shape, e.shape),
  9270. i = new va(da, t.shape, e.shape),
  9271. u = [this.makeComplexComponentTensorInfo(t, n.complexTensors.real), this.makeComplexComponentTensorInfo(t, n.complexTensors.imag), this.makeComplexComponentTensorInfo(e, r.complexTensors.real), this.makeComplexComponentTensorInfo(e, r.complexTensors.imag)],
  9272. s = this.compileAndRun(o, u),
  9273. c = this.compileAndRun(i, u),
  9274. l = this.complex(s, c);
  9275. return s.dispose(), c.dispose(), l;
  9276. }
  9277. if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.multiply(t, e);
  9278. if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, ya, t.dtype);
  9279. var h = new ba(ya, t.shape, e.shape);
  9280. return this.compileAndRun(h, [t, e], t.dtype);
  9281. }, o.prototype.batchNormalization = function (t, e, n, r, o, i) {
  9282. var u = [t, e, n],
  9283. s = null;
  9284. null != i && (s = i.shape, u.push(i));
  9285. var c = null;
  9286. if (null != o && (c = o.shape, u.push(o)), a().getBool("WEBGL_PACK_NORMALIZATION")) {
  9287. var l = new fa(t.shape, e.shape, n.shape, s, c, r);
  9288. return this.compileAndRun(l, u);
  9289. }
  9290. var h = new ha(t.shape, e.shape, n.shape, s, c, r);
  9291. return this.compileAndRun(h, u);
  9292. }, o.prototype.localResponseNormalization4D = function (t, e, n, r, o) {
  9293. var i = a().getBool("WEBGL_PACK_NORMALIZATION") ? new Si(t.shape, e, n, r, o) : new Ii(t.shape, e, n, r, o);
  9294. return this.compileAndRun(i, [t]);
  9295. }, o.prototype.LRNGrad = function (t, e, n, r, o, a, i) {
  9296. var u = new ki(e.shape, r, o, a, i);
  9297. return this.compileAndRun(u, [e, n, t]);
  9298. }, o.prototype.tile = function (t, e) {
  9299. if ("string" === t.dtype) {
  9300. var n = this.readSync(t.dataId).map(function (t) {
  9301. return Z(t);
  9302. });
  9303. return Lo(ur(t.shape, t.dtype, n), e);
  9304. }
  9305. var r = new ru(t.shape, e);
  9306. return this.compileAndRun(r, [t]);
  9307. }, o.prototype.pad = function (t, e, n) {
  9308. var r = a().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new Mi(t.shape, e, n) : new _i(t.shape, e, n);
  9309. return this.compileAndRun(r, [t]);
  9310. }, o.prototype.transpose = function (t, e) {
  9311. if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.transpose(t, e);
  9312. var n = a().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new au(t.shape, e) : new ou(t.shape, e);
  9313. return this.compileAndRun(n, [t]);
  9314. }, o.prototype.gather = function (t, e, n) {
  9315. if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.gather(t, e, n);
  9316. var r = new ni(t.shape, e.size, n);
  9317. return this.compileAndRun(r, [t, e]);
  9318. }, o.prototype.batchToSpaceND = function (t, e, n) {
  9319. g(t.rank <= 4, function () {
  9320. return "batchToSpaceND for rank > 4 with a WebGL backend not implemented yet";
  9321. });
  9322. var r = e.reduce(function (t, e) {
  9323. return t * e;
  9324. }),
  9325. o = Mr(t.shape, e, r),
  9326. a = Br(o.length, e.length),
  9327. i = Pr(t.shape, e, r),
  9328. u = Lr(n, e.length),
  9329. s = Wr(i, n, e.length);
  9330. return t.reshape(o).transpose(a).reshape(i).slice(u, s);
  9331. }, o.prototype.spaceToBatchND = function (t, e, n) {
  9332. g(t.rank <= 4, function () {
  9333. return "spaceToBatchND for rank > 4 with a WebGL backend not implemented yet";
  9334. });
  9335. var r = e.reduce(function (t, e) {
  9336. return t * e;
  9337. }),
  9338. o = [[0, 0]];
  9339. o.push.apply(o, n);
  9340. for (var a = 1 + e.length; a < t.shape.length; ++a) o.push([0, 0]);
  9341. var i = t.pad(o),
  9342. u = Mr(i.shape, e, r, !1),
  9343. s = Br(u.length, e.length, !1),
  9344. c = Pr(i.shape, e, r, !1);
  9345. return i.reshape(u).transpose(s).reshape(c);
  9346. }, o.prototype.reduce = function (t, e, n) {
  9347. var r = t.shape[0],
  9348. o = t.shape[1],
  9349. a = zr(o),
  9350. i = new Li({
  9351. windowSize: a,
  9352. inSize: o,
  9353. batchSize: r
  9354. }, e),
  9355. u = this.compileAndRun(i, [t], n);
  9356. return 1 === u.shape[1] ? u : this.reduce(u, e, n);
  9357. }, o.prototype.argReduce = function (t, e, n) {
  9358. void 0 === n && (n = null);
  9359. var r = t.shape[0],
  9360. o = t.shape[1];
  9361. null != n && (r = n.shape[0], o = n.shape[1]);
  9362. var a = zr(o),
  9363. i = new Go({
  9364. windowSize: a,
  9365. inSize: o,
  9366. batchSize: r
  9367. }, e, null == n),
  9368. u = [t];
  9369. null != n && u.push(n);
  9370. var s = this.compileAndRun(i, u, "int32");
  9371. return 1 === s.shape[1] ? s : this.argReduce(t, e, s);
  9372. }, o.prototype.argReducePacked = function (t, e, n) {
  9373. void 0 === n && (n = null);
  9374. var r = null != n ? n.shape : t.shape,
  9375. o = zr(r[r.length - 1]),
  9376. a = new sa(r, o, e, null == n),
  9377. i = null == n ? [t] : [t, n],
  9378. u = this.compileAndRun(a, i, "int32");
  9379. return u.rank === t.rank ? this.argReducePacked(t, e, u) : u;
  9380. }, o.prototype.sum = function (t, e) {
  9381. mn("sum", e, t.rank);
  9382. var n = dn(t.shape, e),
  9383. r = n[0],
  9384. o = w(n[1]),
  9385. a = t.as2D(-1, o),
  9386. i = Et(t.dtype);
  9387. return this.reduce(a, "sum", i).reshape(r);
  9388. }, o.prototype.prod = function (t, e) {
  9389. if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.prod(t, e);
  9390. var n = dn(t.shape, e),
  9391. r = n[0],
  9392. o = w(n[1]),
  9393. a = t.as2D(-1, o),
  9394. i = Et(t.dtype);
  9395. return this.reduce(a, "prod", i).reshape(r);
  9396. }, o.prototype.unsortedSegmentSum = function (t, e, n) {
  9397. var r = 0,
  9398. o = gn([r], t.rank),
  9399. a = t;
  9400. null != o && (a = t.transpose(o), r = xn(1, t.rank)[0]);
  9401. var i = function (t, e, n) {
  9402. for (var r = [], o = t.length, a = 0; a < o; a++) a !== e ? r.push(t[a]) : r.push(n);
  9403. return r;
  9404. }(a.shape, r, n),
  9405. u = w([a.shape[r]]),
  9406. s = a.as2D(-1, u),
  9407. c = Et(t.dtype),
  9408. l = this.segOpCompute(s, "unsortedSegmentSum", e, c, n).reshape(i);
  9409. return null != o && (l = l.transpose(yn(o))), l;
  9410. }, o.prototype.segOpCompute = function (t, e, n, r, o) {
  9411. var a = t.shape[0],
  9412. i = t.shape[1],
  9413. u = function (t, e) {
  9414. var n,
  9415. r = !1;
  9416. for (t <= Vr ? (n = t, r = !0) : n = H(t, Math.floor(Math.sqrt(t))); !r;) n > e || n === t ? r = !0 : n = H(t, n + 1);
  9417. return n;
  9418. }(i, o),
  9419. s = new Xi({
  9420. windowSize: u,
  9421. inSize: i,
  9422. batchSize: a,
  9423. numSegments: o
  9424. }, e),
  9425. c = this.compileAndRun(s, [t, n], r);
  9426. return c.shape[1] === o ? c : (n = Un(0, o).tile([i / u]), this.segOpCompute(c, e, n, r, o));
  9427. }, o.prototype.argMinMaxReduce = function (t, e, n) {
  9428. var r = [e];
  9429. if (mn("arg" + n.charAt(0).toUpperCase() + n.slice(1), r, t.rank), !a().getBool("WEBGL_PACK_REDUCE") || t.rank <= 2) {
  9430. var o = dn(t.shape, r),
  9431. i = o[0],
  9432. u = w(o[1]),
  9433. s = t.as2D(-1, u);
  9434. return this.argReduce(s, n).reshape(i);
  9435. }
  9436. return this.argReducePacked(t, n);
  9437. }, o.prototype.argMin = function (t, e) {
  9438. return this.argMinMaxReduce(t, e, "min");
  9439. }, o.prototype.argMax = function (t, e) {
  9440. return this.argMinMaxReduce(t, e, "max");
  9441. }, o.prototype.cumsum = function (t, e, n, r) {
  9442. if (e !== t.rank - 1) throw new Error("WebGL cumsum shader expects an inner-most axis=" + (t.rank - 1) + " but got axis=" + e);
  9443. var o = new Ua(t.shape, n, r);
  9444. return this.compileAndRun(o, [t]);
  9445. }, o.prototype.equal = function (t, e) {
  9446. if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n return vec4(equal(a, b));\n", "bool");
  9447. var n = new ba("return float(a == b);", t.shape, e.shape);
  9448. return this.compileAndRun(n, [t, e], "bool");
  9449. }, o.prototype.notEqual = function (t, e) {
  9450. if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n return vec4(notEqual(a, b));\n", "bool");
  9451. var n = new ba("return float(a != b);", t.shape, e.shape);
  9452. return this.compileAndRun(n, [t, e], "bool");
  9453. }, o.prototype.less = function (t, e) {
  9454. if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.less(t, e);
  9455. if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n return vec4(lessThan(a, b));\n", "bool");
  9456. var n = new ba("return float(a < b);", t.shape, e.shape);
  9457. return this.compileAndRun(n, [t, e], "bool");
  9458. }, o.prototype.lessEqual = function (t, e) {
  9459. if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n return vec4(lessThanEqual(a, b));\n", "bool");
  9460. var n = new ba("return float(a <= b);", t.shape, e.shape);
  9461. return this.compileAndRun(n, [t, e], "bool");
  9462. }, o.prototype.greater = function (t, e) {
  9463. if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.greater(t, e);
  9464. if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n return vec4(greaterThan(a, b));\n", "bool");
  9465. var n = new ba("return float(a > b);", t.shape, e.shape);
  9466. return this.compileAndRun(n, [t, e], "bool");
  9467. }, o.prototype.greaterEqual = function (t, e) {
  9468. if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n return vec4(greaterThanEqual(a, b));\n", "bool");
  9469. var n = new ba("return float(a >= b);", t.shape, e.shape);
  9470. return this.compileAndRun(n, [t, e], "bool");
  9471. }, o.prototype.logicalNot = function (t) {
  9472. var e = new su(t.shape, "return float(!(x >= 1.0));");
  9473. return this.compileAndRun(e, [t]);
  9474. }, o.prototype.logicalAnd = function (t, e) {
  9475. if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n return vec4(\n vec4(greaterThanEqual(a, vec4(1.0))) *\n vec4(greaterThanEqual(b, vec4(1.0))));\n", "bool");
  9476. var n = new ba("return float(a >= 1.0 && b >= 1.0);", t.shape, e.shape);
  9477. return this.compileAndRun(n, [t, e], "bool");
  9478. }, o.prototype.logicalOr = function (t, e) {
  9479. if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n return min(\n vec4(greaterThanEqual(a, vec4(1.0))) +\n vec4(greaterThanEqual(b, vec4(1.0))),\n vec4(1.0));\n", "bool");
  9480. var n = new ba("return float(a >= 1.0 || b >= 1.0);", t.shape, e.shape);
  9481. return this.compileAndRun(n, [t, e], "bool");
  9482. }, o.prototype.select = function (t, e, n) {
  9483. var r = new $i(t.rank, e.shape, e.rank);
  9484. return this.compileAndRun(r, [t, e, n], Ct(e.dtype, n.dtype));
  9485. }, o.prototype.where = function (t) {
  9486. un("tf.where() in webgl locks the UI thread. Call tf.whereAsync() instead");
  9487. var e = t.dataSync();
  9488. return Uo(t.shape, e);
  9489. }, o.prototype.topk = function (t, e, n) {
  9490. return Wo(t.dataSync(), t.shape, t.dtype, e);
  9491. }, o.prototype.min = function (t, e) {
  9492. mn("min", e, t.rank);
  9493. var n = dn(t.shape, e),
  9494. r = n[0],
  9495. o = w(n[1]),
  9496. a = t.as2D(-1, o);
  9497. return this.reduce(a, "min", a.dtype).reshape(r);
  9498. }, o.prototype.minimum = function (t, e) {
  9499. if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.minimum(t, e);
  9500. var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca("\n vec4 result = vec4(min(a, b));\n vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n", t.shape, e.shape) : new ba("\n if (isnan(a)) return a;\n if (isnan(b)) return b;\n\n return min(a, b);\n", t.shape, e.shape);
  9501. return this.compileAndRun(n, [t, e]);
  9502. }, o.prototype.mod = function (t, e) {
  9503. var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca("\n vec4 result = mod(a, b);\n vec4 isNaN = vec4(equal(b, vec4(0.0)));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n", t.shape, e.shape) : new ba("if (b == 0.0) return NAN;\n return mod(a, b);", t.shape, e.shape);
  9504. return this.compileAndRun(n, [t, e]);
  9505. }, o.prototype.max = function (t, e) {
  9506. if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.max(t, e);
  9507. mn("max", e, t.rank);
  9508. var n = dn(t.shape, e),
  9509. r = n[0],
  9510. o = w(n[1]),
  9511. a = t.as2D(-1, o);
  9512. return this.reduce(a, "max", a.dtype).reshape(r);
  9513. }, o.prototype.maximum = function (t, e) {
  9514. if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.maximum(t, e);
  9515. var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca("\n vec4 result = vec4(max(a, b));\n vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n", t.shape, e.shape) : new ba("\n if (isnan(a)) return a;\n if (isnan(b)) return b;\n\n return max(a, b);\n", t.shape, e.shape);
  9516. return this.compileAndRun(n, [t, e]);
  9517. }, o.prototype.all = function (t, e) {
  9518. mn("all", e, t.rank);
  9519. var n = dn(t.shape, e),
  9520. r = n[0],
  9521. o = w(n[1]),
  9522. a = t.as2D(-1, o);
  9523. return this.reduce(a, "all", a.dtype).reshape(r);
  9524. }, o.prototype.any = function (t, e) {
  9525. mn("any", e, t.rank);
  9526. var n = dn(t.shape, e),
  9527. r = n[0],
  9528. o = w(n[1]),
  9529. a = t.as2D(-1, o);
  9530. return this.reduce(a, "any", a.dtype).reshape(r);
  9531. }, o.prototype.squaredDifference = function (t, e) {
  9532. var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca("return (a - b) * (a - b);", t.shape, e.shape) : new ba("return (a - b) * (a - b);", t.shape, e.shape);
  9533. return this.compileAndRun(n, [t, e]);
  9534. }, o.prototype.realDivide = function (t, e) {
  9535. if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) {
  9536. return this.packedBinaryOp(t, e, "\n // vec4 one = vec4(equal(a, b));\n // return one + (vec4(1.0) - one) * a / b;\n vec4 result = a / b;\n if(a.x == b.x) {\n result.x = 1.;\n }\n if(a.y == b.y) {\n result.y = 1.;\n }\n if(a.z == b.z) {\n result.z = 1.;\n }\n if(a.w == b.w) {\n result.w = 1.;\n }\n\n return result;\n", "float32", !0);
  9537. }
  9538. var n = new ba("\nif (a == b) {\n return 1.0;\n};\nreturn a / b;", t.shape, e.shape);
  9539. return this.compileAndRun(n, [t, e], "float32");
  9540. }, o.prototype.floorDiv = function (t, e) {
  9541. if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n ivec4 ia = round(a);\n ivec4 ib = round(b);\n bvec4 cond = notEqual(ib, ivec4(0));\n ivec4 result = ivec4(0);\n vec4 s = sign(a) * sign(b);\n\n // Windows (D3D) wants guaranteed non-zero int division at compile-time.\n if (cond[0]) {\n result[0] = idiv(ia[0], ib[0], s[0]);\n }\n if (cond[1]) {\n result[1] = idiv(ia[1], ib[1], s[1]);\n }\n if (cond[2]) {\n result[2] = idiv(ia[2], ib[2], s[2]);\n }\n if (cond[3]) {\n result[3] = idiv(ia[3], ib[3], s[3]);\n }\n return vec4(result);\n", "int32");
  9542. var n = new ba("\n float s = sign(a) * sign(b);\n int ia = round(a);\n int ib = round(b);\n if (ib != 0) {\n // Windows (D3D) wants guaranteed non-zero int division at compile-time.\n return float(idiv(ia, ib, s));\n } else {\n return NAN;\n }\n", t.shape, e.shape);
  9543. return this.compileAndRun(n, [t, e], "int32");
  9544. }, o.prototype.add = function (t, e) {
  9545. if ("complex64" === t.dtype && "complex64" === e.dtype) return this.complexSeparableBinaryOp(t, e, ma);
  9546. if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.add(t, e);
  9547. var n = Ct(t.dtype, e.dtype);
  9548. if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, ma, n);
  9549. var r = new ba(ma, t.shape, e.shape);
  9550. return this.compileAndRun(r, [t, e], n);
  9551. }, o.prototype.packedUnaryOp = function (t, e, n) {
  9552. var r = new _u(t.shape, e);
  9553. return this.compileAndRun(r, [t], n);
  9554. }, o.prototype.packedBinaryOp = function (t, e, n, r, o) {
  9555. void 0 === o && (o = !1);
  9556. var a = new Ca(n, t.shape, e.shape, o);
  9557. return this.compileAndRun(a, [t, e], r);
  9558. }, o.prototype.complexSeparableBinaryOp = function (t, e, n) {
  9559. var r = this,
  9560. o = this.texData.get(t.dataId),
  9561. a = this.texData.get(e.dataId),
  9562. i = [[o.complexTensors.real, a.complexTensors.real], [o.complexTensors.imag, a.complexTensors.imag]].map(function (o) {
  9563. var a = o[0],
  9564. i = o[1],
  9565. u = r.makeComplexComponentTensorInfo(t, a),
  9566. s = r.makeComplexComponentTensorInfo(e, i),
  9567. c = new ba(n, t.shape, e.shape);
  9568. return r.compileAndRun(c, [u, s], Ct(a.dtype, i.dtype));
  9569. }),
  9570. u = i[0],
  9571. s = i[1],
  9572. c = this.complex(u, s);
  9573. return u.dispose(), s.dispose(), c;
  9574. }, o.prototype.makeComplexComponentTensorInfo = function (t, e) {
  9575. return {
  9576. dataId: e.dataId,
  9577. dtype: e.dtype,
  9578. shape: t.shape
  9579. };
  9580. }, o.prototype.addN = function (t) {
  9581. if (1 === t.length) return t[0];
  9582. if (t.length > a().get("WEBGL_MAX_TEXTURES_IN_SHADER")) {
  9583. var e = Math.floor(t.length / 2),
  9584. n = this.addN(t.slice(0, e)),
  9585. r = this.addN(t.slice(e));
  9586. return this.addN([n, r]);
  9587. }
  9588. var o = t.map(function (t) {
  9589. return t.dtype;
  9590. }).reduce(function (t, e) {
  9591. return Ct(t, e);
  9592. }),
  9593. i = t.map(function (t) {
  9594. return t.shape;
  9595. }),
  9596. u = a().getBool("WEBGL_PACK") ? new zo(t[0].shape, i) : new Vo(t[0].shape, i);
  9597. return this.compileAndRun(u, t, o);
  9598. }, o.prototype.subtract = function (t, e) {
  9599. if ("complex64" === t.dtype && "complex64" === e.dtype) return this.complexSeparableBinaryOp(t, e, ga);
  9600. if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.subtract(t, e);
  9601. var n = Ct(t.dtype, e.dtype);
  9602. if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, ga, t.dtype);
  9603. var r = new ba(ga, t.shape, e.shape);
  9604. return this.compileAndRun(r, [t, e], n);
  9605. }, o.prototype.pow = function (t, e) {
  9606. var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca("\n // isModRound1 has 1 for components with round(mod(b, 2.0)) == 1, 0 otherwise.\n vec4 isModRound1 = vec4(equal(round(mod(b, 2.0)), ivec4(1)));\n vec4 multiplier = sign(a) * isModRound1 + (vec4(1.0) - isModRound1);\n vec4 result = multiplier * pow(abs(a), b);\n\n // Ensure that a^0 = 1, including 0^0 = 1 as this correspond to TF and JS\n bvec4 isExpZero = equal(b, vec4(0.0));\n result.r = isExpZero.r ? 1.0 : result.r;\n result.g = isExpZero.g ? 1.0 : result.g;\n result.b = isExpZero.b ? 1.0 : result.b;\n result.a = isExpZero.a ? 1.0 : result.a;\n\n vec4 isNaN = vec4(lessThan(a, vec4(0.0))) * vec4(lessThan(floor(b), b));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n", t.shape, e.shape) : new ba("\nif(a < 0.0 && floor(b) < b){\n return NAN;\n}\nif (b == 0.0) {\n return 1.0;\n}\nreturn (round(mod(b, 2.0)) != 1) ?\n pow(abs(a), b) : sign(a) * pow(abs(a), b);\n", t.shape, e.shape),
  9607. r = Ct(t.dtype, e.dtype);
  9608. return this.compileAndRun(n, [t, e], r);
  9609. }, o.prototype.ceil = function (t) {
  9610. if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.ceil(t);
  9611. if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, gu, t.dtype);
  9612. var e = new su(t.shape, gu);
  9613. return this.compileAndRun(e, [t]);
  9614. }, o.prototype.floor = function (t) {
  9615. if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.floor(t);
  9616. if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, yu, t.dtype);
  9617. var e = new su(t.shape, yu);
  9618. return this.compileAndRun(e, [t]);
  9619. }, o.prototype.sign = function (t) {
  9620. var e = new su(t.shape, "\n if (isnan(x)) { return 0.0; }\n return sign(x);\n");
  9621. return this.compileAndRun(e, [t]);
  9622. }, o.prototype.isNaN = function (t) {
  9623. var e = new su(t.shape, "return float(isnan(x));");
  9624. return this.compileAndRun(e, [t], "bool");
  9625. }, o.prototype.isInf = function (t) {
  9626. var e = new su(t.shape, "return float(isinf(x));");
  9627. return this.compileAndRun(e, [t], "bool");
  9628. }, o.prototype.isFinite = function (t) {
  9629. var e = new su(t.shape, "return float(!isnan(x) && !isinf(x));");
  9630. return this.compileAndRun(e, [t], "bool");
  9631. }, o.prototype.round = function (t) {
  9632. var e = new su(t.shape, "\n // OpenGL ES does not support round function.\n // The algorithm is based on banker's rounding.\n float base = floor(x);\n if ((x - base) < 0.5) {\n return floor(x);\n } else if ((x - base) > 0.5) {\n return ceil(x);\n } else {\n if (mod(base, 2.0) == 0.0) {\n return base;\n } else {\n return base + 1.0;\n }\n }\n");
  9633. return this.compileAndRun(e, [t]);
  9634. }, o.prototype.exp = function (t) {
  9635. if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.exp(t);
  9636. if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, xu, t.dtype);
  9637. var e = new su(t.shape, xu);
  9638. return this.compileAndRun(e, [t]);
  9639. }, o.prototype.expm1 = function (t) {
  9640. if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.expm1(t);
  9641. if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, bu, t.dtype);
  9642. var e = new su(t.shape, bu);
  9643. return this.compileAndRun(e, [t]);
  9644. }, o.prototype.log = function (t) {
  9645. if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.log(t);
  9646. if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, "\n vec4 result = log(x);\n vec4 isNaN = vec4(lessThan(x, vec4(0.0)));\n result.r = isNaN.r == 1.0 ? NAN : result.r;\n result.g = isNaN.g == 1.0 ? NAN : result.g;\n result.b = isNaN.b == 1.0 ? NAN : result.b;\n result.a = isNaN.a == 1.0 ? NAN : result.a;\n\n return result;\n", t.dtype);
  9647. var e = new su(t.shape, "if (x < 0.0) return NAN;\n return log(x);");
  9648. return this.compileAndRun(e, [t]);
  9649. }, o.prototype.log1p = function (t) {
  9650. var e = new su(t.shape, "return log(1.0 + x);");
  9651. return this.compileAndRun(e, [t]);
  9652. }, o.prototype.sqrt = function (t) {
  9653. var e = new su(t.shape, "return sqrt(x);");
  9654. return this.compileAndRun(e, [t]);
  9655. }, o.prototype.rsqrt = function (t) {
  9656. if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.rsqrt(t);
  9657. var e = new su(t.shape, "return inversesqrt(x);");
  9658. return this.compileAndRun(e, [t]);
  9659. }, o.prototype.reciprocal = function (t) {
  9660. var e = new su(t.shape, "return 1.0 / x;");
  9661. return this.compileAndRun(e, [t]);
  9662. }, o.prototype.relu = function (t) {
  9663. var e;
  9664. return e = a().getBool("WEBGL_PACK") ? new _u(t.shape, Nu) : new su(t.shape, fu), this.compileAndRun(e, [t]);
  9665. }, o.prototype.relu6 = function (t) {
  9666. var e;
  9667. return e = a().getBool("WEBGL_PACK") ? new _u(t.shape, Fu) : new su(t.shape, pu), this.compileAndRun(e, [t]);
  9668. }, o.prototype.prelu = function (t, e) {
  9669. var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca(wa, t.shape, e.shape) : new ba(xa, t.shape, e.shape);
  9670. return this.compileAndRun(n, [t, e]);
  9671. }, o.prototype.elu = function (t) {
  9672. if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, Ou, t.dtype);
  9673. var e = new su(t.shape, du);
  9674. return this.compileAndRun(e, [t]);
  9675. }, o.prototype.eluDer = function (t, e) {
  9676. var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca("\n vec4 bGTEZero = vec4(greaterThanEqual(b, vec4(0.)));\n return (bGTEZero * a) + ((vec4(1.0) - bGTEZero) * (a * (b + vec4(1.0))));\n", t.shape, e.shape) : new ba("return (b >= 1.0) ? a : a * (b + 1.0);", t.shape, e.shape);
  9677. return this.compileAndRun(n, [t, e]);
  9678. }, o.prototype.selu = function (t) {
  9679. var e = new su(t.shape, vu);
  9680. return this.compileAndRun(e, [t]);
  9681. }, o.prototype.int = function (t) {
  9682. var e = new su(t.shape, "return float(int(x));");
  9683. return this.compileAndRun(e, [t], "int32");
  9684. }, o.prototype.clip = function (t, e, n) {
  9685. var r,
  9686. o = (r = a().getBool("WEBGL_PACK_CLIP") ? new Ra(t.shape) : new Ea(t.shape)).getCustomSetupFunc(e, n);
  9687. return this.compileAndRun(r, [t], null, o);
  9688. }, o.prototype.abs = function (t) {
  9689. if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.abs(t);
  9690. if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, hu, t.dtype);
  9691. var e = new su(t.shape, hu);
  9692. return this.compileAndRun(e, [t]);
  9693. }, o.prototype.complexAbs = function (t) {
  9694. var e = this.texData.get(t.dataId),
  9695. n = new Ia(t.shape),
  9696. r = [this.makeComplexComponentTensorInfo(t, e.complexTensors.real), this.makeComplexComponentTensorInfo(t, e.complexTensors.imag)];
  9697. return this.compileAndRun(n, r);
  9698. }, o.prototype.sigmoid = function (t) {
  9699. var e = new su(t.shape, "return 1.0 / (1.0 + exp(-1.0 * x));");
  9700. return this.compileAndRun(e, [t]);
  9701. }, o.prototype.softplus = function (t) {
  9702. var e = new su(t.shape, "\n float epsilon = 1.1920928955078125e-7;\n float threshold = log(epsilon) + 2.0;\n\n bool too_large = x > -threshold;\n bool too_small = x < threshold;\n\n float result;\n float exp_x = exp(x);\n\n if (too_large){\n result = x;\n }\n else if (too_small){\n result = exp_x;\n }\n else{\n result = log(exp_x + 1.0);\n }\n return result;\n");
  9703. return this.compileAndRun(e, [t]);
  9704. }, o.prototype.sin = function (t) {
  9705. var e = new su(t.shape, wu);
  9706. return this.compileAndRun(e, [t]);
  9707. }, o.prototype.cos = function (t) {
  9708. var e = new su(t.shape, Cu);
  9709. return this.compileAndRun(e, [t]);
  9710. }, o.prototype.tan = function (t) {
  9711. var e = new su(t.shape, "return tan(x);");
  9712. return this.compileAndRun(e, [t]);
  9713. }, o.prototype.asin = function (t) {
  9714. var e = new su(t.shape, Eu);
  9715. return this.compileAndRun(e, [t]);
  9716. }, o.prototype.acos = function (t) {
  9717. var e = new su(t.shape, Ru);
  9718. return this.compileAndRun(e, [t]);
  9719. }, o.prototype.atan = function (t) {
  9720. var e = new su(t.shape, Iu);
  9721. return this.compileAndRun(e, [t]);
  9722. }, o.prototype.atan2 = function (t, e) {
  9723. var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca("\n vec4 result = atan(a, b);\n vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n", t.shape, e.shape) : new ba("\n if (isnan(a)) return a;\n if (isnan(b)) return b;\n\n return atan(a, b);\n", t.shape, e.shape);
  9724. return this.compileAndRun(n, [t, e]);
  9725. }, o.prototype.sinh = function (t) {
  9726. var e = new su(t.shape, "\n float e2x = exp(x);\n return (e2x - 1.0 / e2x) / 2.0;\n");
  9727. return this.compileAndRun(e, [t]);
  9728. }, o.prototype.cosh = function (t) {
  9729. var e = new su(t.shape, "\n float e2x = exp(-x);\n return (e2x + 1.0 / e2x) / 2.0;\n");
  9730. return this.compileAndRun(e, [t]);
  9731. }, o.prototype.tanh = function (t) {
  9732. var e = new su(t.shape, "\n float e2x = exp(-2.0 * abs(x));\n return sign(x) * (1.0 - e2x) / (1.0 + e2x);\n");
  9733. return this.compileAndRun(e, [t]);
  9734. }, o.prototype.asinh = function (t) {
  9735. var e = new su(t.shape, ku);
  9736. return this.compileAndRun(e, [t]);
  9737. }, o.prototype.acosh = function (t) {
  9738. var e = new su(t.shape, Su);
  9739. return this.compileAndRun(e, [t]);
  9740. }, o.prototype.atanh = function (t) {
  9741. var e = new su(t.shape, Au);
  9742. return this.compileAndRun(e, [t]);
  9743. }, o.prototype.erf = function (t) {
  9744. var e = new su(t.shape, '\n // Error function is calculated approximately with elementary function.\n // See "Handbook of Mathematical Functions with Formulas,\n // Graphs, and Mathematical Tables", Abramowitz and Stegun.\n float p = 0.3275911;\n float a1 = 0.254829592;\n float a2 = -0.284496736;\n float a3 = 1.421413741;\n float a4 = -1.453152027;\n float a5 = 1.061405429;\n\n float sign = sign(x);\n x = abs(x);\n float t = 1.0 / (1.0 + p * x);\n return sign * (1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x));\n');
  9745. return this.compileAndRun(e, [t]);
  9746. }, o.prototype.step = function (t, e) {
  9747. var n = new su(t.shape, function (t) {
  9748. return void 0 === t && (t = 0), cu + "\n return x > 0.0 ? 1.0 : float(" + t + ");\n ";
  9749. }(e));
  9750. return this.compileAndRun(n, [t]);
  9751. }, o.prototype.conv2dByMatMul = function (t, e, n, r, o, i) {
  9752. var u = t.shape,
  9753. s = this.texData.get(t.dataId),
  9754. c = n.inChannels,
  9755. l = u[0] * u[1] * u[2],
  9756. h = n.outChannels,
  9757. f = "channelsLast" === n.dataFormat,
  9758. p = (1 === l || 1 === h) && c > 1e3,
  9759. d = u[2] % 2 != 0 && !!s.isPacked;
  9760. if (p || !a().getBool("WEBGL_LAZILY_UNPACK") || !a().getBool("WEBGL_PACK_BINARY_OPERATIONS") || !d) {
  9761. var v = f ? u[0] * u[1] * u[2] : u[0] * u[2] * u[3],
  9762. m = this.reshape(t, [1, v, n.inChannels]),
  9763. y = this.reshape(e, [1, n.inChannels, n.outChannels]);
  9764. return this.reshape(this.fusedBatchMatMul({
  9765. a: m,
  9766. b: y,
  9767. transposeA: !1,
  9768. transposeB: !1,
  9769. bias: r,
  9770. activation: o,
  9771. preluActivationWeights: i
  9772. }), n.outShape);
  9773. }
  9774. var x = f ? u[0] * u[1] * (u[2] + 1) : u[0] * u[2] * (u[3] + 1),
  9775. b = {
  9776. dataId: t.dataId,
  9777. shape: [1, x, n.inChannels],
  9778. dtype: t.dtype
  9779. },
  9780. w = s.shape;
  9781. s.shape = s.shape.slice(), s.shape[s.shape.length - 2]++, g(Se(s.shape, b.shape), function () {
  9782. return "packed reshape " + s.shape + " to " + b.shape + " isn't free";
  9783. });
  9784. var C = this.reshape(e, [1, n.inChannels, n.outChannels]),
  9785. E = this.fusedBatchMatMul({
  9786. a: b,
  9787. b: C,
  9788. transposeA: !1,
  9789. transposeB: !1,
  9790. bias: r,
  9791. activation: o,
  9792. preluActivationWeights: i
  9793. }),
  9794. R = this.texData.get(E.dataId);
  9795. return g(R.isPacked, function () {
  9796. return "batchMatMul result is expected to be packed";
  9797. }), s.shape = w, R.shape = n.outShape, Nt.makeTensorFromDataId(E.dataId, n.outShape, E.dtype);
  9798. }, o.prototype.conv2dWithIm2Row = function (t, e, n, r, o, a) {
  9799. var i = n.filterWidth,
  9800. u = n.filterHeight,
  9801. s = n.inChannels,
  9802. c = n.outWidth,
  9803. l = n.outHeight,
  9804. h = "channelsLast" === n.dataFormat,
  9805. f = i * u * s,
  9806. p = l * c,
  9807. d = [f, p],
  9808. v = t.squeeze([0]),
  9809. m = e.reshape([1, f, -1]),
  9810. g = new Ri(d, v.shape, n),
  9811. y = this.compileAndRun(g, [v]).reshape([1, d[0], d[1]]),
  9812. x = null != r,
  9813. b = null != a,
  9814. w = o ? Pu(o, !0) : null,
  9815. C = new Ti(y.shape, [1, p, n.outChannels], !0, !1, x, w, b),
  9816. E = [y, m];
  9817. r && E.push(r), b && E.push(a);
  9818. var R = this.compileAndRun(C, E);
  9819. return h ? R.reshape([1, l, c, n.outChannels]) : R.reshape([1, n.outChannels, l, c]);
  9820. }, o.prototype.fusedConv2d = function (t) {
  9821. var e = t.input,
  9822. n = t.filter,
  9823. r = t.convInfo,
  9824. o = t.bias,
  9825. i = t.activation,
  9826. u = t.preluActivationWeights;
  9827. if (1 === r.filterHeight && 1 === r.filterWidth && 1 === r.dilationHeight && 1 === r.dilationWidth && 1 === r.strideHeight && 1 === r.strideWidth && ("SAME" === r.padInfo.type || "VALID" === r.padInfo.type)) return this.conv2dByMatMul(e, n, r, o, i, u);
  9828. if (a().getBool("WEBGL_CONV_IM2COL") && 1 === e.shape[0]) return this.conv2dWithIm2Row(e, n, r, o, i, u);
  9829. var s = null != o,
  9830. c = null != u,
  9831. l = i ? Pu(i, !1) : null,
  9832. h = new Ma(r, s, l, c),
  9833. f = [e, n];
  9834. return o && f.push(o), u && f.push(u), this.compileAndRun(h, f);
  9835. }, o.prototype.conv2d = function (t, e, n) {
  9836. if (1 === n.filterHeight && 1 === n.filterWidth && 1 === n.dilationHeight && 1 === n.dilationWidth && 1 === n.strideHeight && 1 === n.strideWidth && ("SAME" === n.padInfo.type || "VALID" === n.padInfo.type)) return this.conv2dByMatMul(t, e, n);
  9837. if (a().getBool("WEBGL_CONV_IM2COL") && 1 === t.shape[0]) return this.conv2dWithIm2Row(t, e, n);
  9838. var r = new Ma(n);
  9839. return this.compileAndRun(r, [t, e]);
  9840. }, o.prototype.conv2dDerInput = function (t, e, n) {
  9841. var r = new Ta(n);
  9842. return this.compileAndRun(r, [t, e]);
  9843. }, o.prototype.conv2dDerFilter = function (t, e, n) {
  9844. var r = new Da(n);
  9845. return this.compileAndRun(r, [t, e]);
  9846. }, o.prototype.fusedDepthwiseConv2D = function (t) {
  9847. var e,
  9848. n = t.input,
  9849. r = t.filter,
  9850. o = t.convInfo,
  9851. i = t.bias,
  9852. u = t.activation,
  9853. s = t.preluActivationWeights,
  9854. c = a().getBool("WEBGL_PACK_DEPTHWISECONV") && o.strideWidth <= 2 && o.outChannels / o.inChannels == 1,
  9855. l = u ? Pu(u, c) : null,
  9856. h = [n, r],
  9857. f = null != i,
  9858. p = null != s;
  9859. return f && h.push(i), p && h.push(s), c ? (e = new La(o, f, l, p), this.compileAndRun(e, h)) : (e = new Pa(o, f, l, p), this.compileAndRun(e, h));
  9860. }, o.prototype.depthwiseConv2D = function (t, e, n) {
  9861. var r;
  9862. return a().getBool("WEBGL_PACK_DEPTHWISECONV") && n.strideWidth <= 2 && n.outChannels / n.inChannels == 1 ? (r = new La(n), this.compileAndRun(r, [t, e])) : (r = new Pa(n), this.compileAndRun(r, [t, e]));
  9863. }, o.prototype.depthwiseConv2DDerInput = function (t, e, n) {
  9864. var r = new _a(n);
  9865. return this.compileAndRun(r, [t, e]);
  9866. }, o.prototype.depthwiseConv2DDerFilter = function (t, e, n) {
  9867. var r = new Oa(n);
  9868. return this.compileAndRun(r, [t, e]);
  9869. }, o.prototype.conv3d = function (t, e, n) {
  9870. var r = new Ba(n);
  9871. return this.compileAndRun(r, [t, e]);
  9872. }, o.prototype.conv3dDerInput = function (t, e, n) {
  9873. var r = new Fa(n);
  9874. return this.compileAndRun(r, [t, e]);
  9875. }, o.prototype.conv3dDerFilter = function (t, e, n) {
  9876. var r = new Na(n);
  9877. return this.compileAndRun(r, [t, e]);
  9878. }, o.prototype.maxPool = function (t, e) {
  9879. var n = new Bi(e, "max", !1);
  9880. return this.compileAndRun(n, [t]);
  9881. }, o.prototype.avgPool = function (t, e) {
  9882. var n = new Bi(e, "avg", !1);
  9883. return this.compileAndRun(n, [t], "float32");
  9884. }, o.prototype.maxPoolBackprop = function (t, e, n, r) {
  9885. var o = new Bi(r, "max", !0),
  9886. a = this.compileAndRun(o, [e]),
  9887. i = new Ai(r),
  9888. u = this.compileAndRun(i, [t, a], e.dtype);
  9889. return a.dispose(), u;
  9890. }, o.prototype.avgPoolBackprop = function (t, e, n) {
  9891. var r = new ca(n);
  9892. return this.compileAndRun(r, [t], e.dtype);
  9893. }, o.prototype.cast = function (t, e) {
  9894. return So(t, e, this);
  9895. }, o.prototype.unstack = function (t, e) {
  9896. for (var n = t.shape[e], r = new Array(t.rank - 1), o = 0, a = 0; a < t.rank; a++) a !== e && (r[o++] = t.shape[a]);
  9897. var i = new Array(t.rank).fill(0),
  9898. u = t.shape.slice();
  9899. u[e] = 1;
  9900. var s = new Array(n);
  9901. for (a = 0; a < s.length; a++) i[e] = a, s[a] = this.slice(t, i, u).reshape(r);
  9902. return s;
  9903. }, o.prototype.avgPool3d = function (t, e) {
  9904. var n = new Pi(e, "avg", !1);
  9905. return this.compileAndRun(n, [t], "float32");
  9906. }, o.prototype.avgPool3dBackprop = function (t, e, n) {
  9907. var r = new la(n);
  9908. return this.compileAndRun(r, [t], e.dtype);
  9909. }, o.prototype.maxPool3d = function (t, e) {
  9910. var n = new Pi(e, "max", !1);
  9911. return this.compileAndRun(n, [t], "float32");
  9912. }, o.prototype.maxPool3dBackprop = function (t, e, n, r) {
  9913. var o = new Pi(r, "max", !0),
  9914. a = this.compileAndRun(o, [e]),
  9915. i = new Di(r),
  9916. u = this.compileAndRun(i, [t, a], e.dtype);
  9917. return a.dispose(), u;
  9918. }, o.prototype.reshape = function (t, e) {
  9919. var n = this.texData.get(t.dataId);
  9920. if (n.isPacked && !Se(t.shape, e) && (null === n.texture || !Se(n.shape, e))) {
  9921. var r = this.packedReshape(t, e);
  9922. return Nt.makeTensorFromDataId(r.dataId, r.shape, r.dtype);
  9923. }
  9924. return Ao(t, e);
  9925. }, o.prototype.resizeBilinear = function (t, e, n, r) {
  9926. var o = a().getBool("WEBGL_PACK_IMAGE_OPERATIONS") ? new zi(t.shape, e, n, r) : new Vi(t.shape, e, n, r);
  9927. return this.compileAndRun(o, [t]);
  9928. }, o.prototype.resizeBilinearBackprop = function (t, e, n) {
  9929. var r = new Ui(t, e, n);
  9930. return this.compileAndRun(r, [t]);
  9931. }, o.prototype.resizeNearestNeighbor = function (t, e, n, r) {
  9932. var o = new Hi(t.shape, e, n, r);
  9933. return this.compileAndRun(o, [t]);
  9934. }, o.prototype.resizeNearestNeighborBackprop = function (t, e, n) {
  9935. var r = new Gi(t, e, n);
  9936. return this.compileAndRun(r, [t]);
  9937. }, o.prototype.multinomial = function (t, e, n, r) {
  9938. var o = e ? t : io(t),
  9939. a = o.shape[0],
  9940. i = o.shape[1],
  9941. u = new Ni(a, i, n),
  9942. s = u.getCustomSetupFunc(r);
  9943. return this.compileAndRun(u, [o], "int32", s);
  9944. }, o.prototype.oneHot = function (t, e, n, r) {
  9945. var o = new Fi(t.size, e, n, r);
  9946. return this.compileAndRun(o, [t]);
  9947. }, o.prototype.diag = function (t) {
  9948. var e = new qa(t.size);
  9949. return this.compileAndRun(e, [t]);
  9950. }, o.prototype.nonMaxSuppression = function (t, e, n, r, o) {
  9951. return un("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead"), Mo(t.dataSync(), e.dataSync(), n, r, o);
  9952. }, o.prototype.cropAndResize = function (t, e, n, r, o, a) {
  9953. var i = new Wa(t.shape, e.shape, r, o, a);
  9954. return this.compileAndRun(i, [t, e, n]);
  9955. }, o.prototype.depthToSpace = function (t, e, n) {
  9956. g(e > 1, function () {
  9957. return "blockSize should be > 1 for depthToSpace, but was: " + e;
  9958. });
  9959. var r = t.shape[0],
  9960. o = "NHWC" === n ? t.shape[1] : t.shape[2],
  9961. a = "NHWC" === n ? t.shape[2] : t.shape[3],
  9962. i = "NHWC" === n ? t.shape[3] : t.shape[1],
  9963. u = o * e,
  9964. s = a * e,
  9965. c = i / (e * e),
  9966. l = new Ha("NHWC" === n ? [r, u, s, c] : [r, c, u, s], e, n);
  9967. return this.compileAndRun(l, [t]);
  9968. }, o.prototype.split = function (t, e, n) {
  9969. return Po(t, e, n);
  9970. }, o.prototype.scatterND = function (t, e, n) {
  9971. var r = Hr(0, t, n),
  9972. o = r.sliceRank,
  9973. a = r.numUpdates,
  9974. i = r.sliceSize,
  9975. u = r.strides,
  9976. s = r.outputSize,
  9977. c = [s / i, i],
  9978. l = t.reshape([a, o]),
  9979. h = e.reshape([a, i]);
  9980. if (0 === s) return Ao(kn([]), n);
  9981. var f = An(0),
  9982. p = new ji(a, o, l.rank, h.rank, u, c);
  9983. return this.compileAndRun(p, [h, l, f]).reshape(n);
  9984. }, o.prototype.sparseToDense = function (t, e, n, r) {
  9985. var o = Hr(0, t, n),
  9986. a = o.sliceRank,
  9987. i = o.numUpdates,
  9988. u = o.strides,
  9989. s = o.outputSize,
  9990. c = new ji(i, a, t.rank, e.rank, u, [s, 1], !1);
  9991. return this.compileAndRun(c, [e, t, r]).reshape(n);
  9992. }, o.prototype.fft = function (t) {
  9993. return this.fftImpl(t, !1);
  9994. }, o.prototype.ifft = function (t) {
  9995. return this.fftImpl(t, !0);
  9996. }, o.prototype.fftImpl = function (t, e) {
  9997. var n = this.texData.get(t.dataId),
  9998. r = new Ja(Ya, t.shape, e),
  9999. o = new Ja(Qa, t.shape, e),
  10000. a = [this.makeComplexComponentTensorInfo(t, n.complexTensors.real), this.makeComplexComponentTensorInfo(t, n.complexTensors.imag)],
  10001. i = this.compileAndRun(r, a),
  10002. u = this.compileAndRun(o, a),
  10003. s = this.complex(i, u).as2D(t.shape[0], t.shape[1]);
  10004. return i.dispose(), u.dispose(), s;
  10005. }, o.prototype.gatherND = function (t, e) {
  10006. var n = e.shape,
  10007. r = n[n.length - 1],
  10008. o = Ur(t, e),
  10009. a = o[0],
  10010. i = o[1],
  10011. u = o[2],
  10012. s = o[3],
  10013. c = e.reshape([i, r]),
  10014. l = t.reshape([t.size / u, u]),
  10015. h = new ri(r, s, [i, u]);
  10016. return this.compileAndRun(h, [l, c]).reshape(a);
  10017. }, o.prototype.fill = function (t, e, n) {
  10018. if ("string" === (n = n || z(e))) {
  10019. var r = F(n, w(t));
  10020. return r.fill(e), Nt.makeTensor(r, t, n, this);
  10021. }
  10022. var o = new Za(t, e),
  10023. a = o.getCustomSetupFunc(e);
  10024. return this.compileAndRun(o, [], n, a);
  10025. }, o.prototype.onesLike = function (t) {
  10026. if ("string" === t.dtype) throw new Error("onesLike is not supported under string dtype");
  10027. return this.fill(t.shape, 1, t.dtype);
  10028. }, o.prototype.zerosLike = function (t) {
  10029. return this.fill(t.shape, "string" === t.dtype ? "" : 0, t.dtype);
  10030. }, o.prototype.linspace = function (t, e, n) {
  10031. return Do(t, e, n);
  10032. }, o.prototype.makeTensorInfo = function (t, e) {
  10033. var n = this.write(null, t, e);
  10034. return this.texData.get(n).usage = null, {
  10035. dataId: n,
  10036. shape: t,
  10037. dtype: e
  10038. };
  10039. }, o.prototype.makeOutput = function (t, e) {
  10040. var n = this.makeTensorInfo(t, e).dataId;
  10041. return Nt.makeTensorFromDataId(n, t, e, this);
  10042. }, o.prototype.unpackTensor = function (t) {
  10043. var e = new Mu(t.shape);
  10044. return this.runWebGLProgram(e, [t], t.dtype);
  10045. }, o.prototype.packTensor = function (t) {
  10046. var e = new Oi(t.shape);
  10047. return this.runWebGLProgram(e, [t], t.dtype, null, !0);
  10048. }, o.prototype.packedReshape = function (t, e) {
  10049. var n = [Ce(t.shape)].concat(Ee(t.shape)),
  10050. r = {
  10051. dtype: t.dtype,
  10052. shape: n,
  10053. dataId: t.dataId
  10054. },
  10055. o = [Ce(e)].concat(Ee(e)),
  10056. a = new Wi(o, n),
  10057. i = this.runWebGLProgram(a, [r], t.dtype, null, !0);
  10058. return {
  10059. dataId: i.dataId,
  10060. shape: e,
  10061. dtype: i.dtype
  10062. };
  10063. }, o.prototype.decode = function (t) {
  10064. var e,
  10065. n = this.texData.get(t),
  10066. r = n.isPacked,
  10067. o = n.shape,
  10068. a = n.dtype,
  10069. i = Re(o);
  10070. e = r ? new Ga(i) : new za(i);
  10071. return {
  10072. dtype: a,
  10073. shape: o,
  10074. dataId: this.runWebGLProgram(e, [{
  10075. shape: i,
  10076. dtype: a,
  10077. dataId: t
  10078. }], a, null, !0).dataId
  10079. };
  10080. }, o.prototype.runWebGLProgram = function (t, e, n, r, o) {
  10081. var i = this;
  10082. void 0 === o && (o = !1);
  10083. var u = this.makeTensorInfo(t.outputShape, n),
  10084. s = this.texData.get(u.dataId);
  10085. if (t.packedOutput && (s.isPacked = !0), t.outPackingScheme === _t.DENSE) {
  10086. var c = Gt(t.outputShape);
  10087. s.texShape = c.map(function (t) {
  10088. return 2 * t;
  10089. });
  10090. }
  10091. if (null != t.outTexUsage && (s.usage = t.outTexUsage), 0 === w(u.shape)) return s.values = N(u.dtype, 0), u;
  10092. var l = [],
  10093. h = e.map(function (e) {
  10094. if ("complex64" === e.dtype) throw new Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts.");
  10095. var n = i.texData.get(e.dataId);
  10096. if (null == n.texture) {
  10097. if (!t.packedInputs && w(e.shape) <= a().getNumber("WEBGL_SIZE_UPLOAD_UNIFORM")) return {
  10098. shape: e.shape,
  10099. texData: null,
  10100. isUniform: !0,
  10101. uniformValues: n.values
  10102. };
  10103. t.packedInputs && (n.isPacked = !0, n.shape = e.shape);
  10104. } else if (!!n.isPacked != !!t.packedInputs) e = n.isPacked ? i.unpackTensor(e) : i.packTensor(e), l.push(e), n = i.texData.get(e.dataId); else if (n.isPacked && !Se(n.shape, e.shape)) {
  10105. var r = e,
  10106. o = e.shape;
  10107. e.shape = n.shape, e = i.packedReshape(e, o), l.push(e), n = i.texData.get(e.dataId), r.shape = o;
  10108. }
  10109. return i.uploadToGPU(e.dataId), {
  10110. shape: e.shape,
  10111. texData: n,
  10112. isUniform: !1
  10113. };
  10114. });
  10115. this.uploadToGPU(u.dataId);
  10116. var f,
  10117. p = {
  10118. shape: u.shape,
  10119. texData: s,
  10120. isUniform: !1
  10121. },
  10122. d = function (t, e, n) {
  10123. var r = "";
  10124. e.concat(n).forEach(function (t) {
  10125. var e = null != t.texData && null != t.texData.slice && t.texData.slice.flatOffset > 0,
  10126. n = t.isUniform ? "uniform" : t.texData.texShape;
  10127. r += t.shape + "_" + n + "_" + e;
  10128. });
  10129. var o = t.userCode,
  10130. a = t.constructor.name;
  10131. return a += "_" + r + "_" + o;
  10132. }(t, h, p),
  10133. v = this.getAndSaveBinary(d, function () {
  10134. return function (t, e, n, r) {
  10135. var o = e.userCode,
  10136. i = n.map(function (t, n) {
  10137. var r = {
  10138. logicalShape: t.shape,
  10139. texShape: t.isUniform ? null : t.texData.texShape,
  10140. isUniform: t.isUniform,
  10141. isPacked: !t.isUniform && t.texData.isPacked,
  10142. flatOffset: null
  10143. };
  10144. return null != t.texData && null != t.texData.slice && t.texData.slice.flatOffset > 0 && (r.flatOffset = t.texData.slice.flatOffset), {
  10145. name: e.variableNames[n],
  10146. shapeInfo: r
  10147. };
  10148. }),
  10149. u = i.map(function (t) {
  10150. return t.shapeInfo;
  10151. }),
  10152. s = {
  10153. logicalShape: r.shape,
  10154. texShape: r.texData.texShape,
  10155. isUniform: !1,
  10156. isPacked: r.texData.isPacked,
  10157. flatOffset: null
  10158. },
  10159. c = Yo(i, s, o, e.packedInputs),
  10160. l = t.createProgram(c),
  10161. h = null,
  10162. f = t.getUniformLocation(l, "NAN", !1);
  10163. 1 === a().getNumber("WEBGL_VERSION") && (h = t.getUniformLocation(l, "INFINITY", !1));
  10164. for (var p = {}, d = 0; d < e.variableNames.length; d++) {
  10165. var v = e.variableNames[d];
  10166. p[v] = t.getUniformLocation(l, v, !1), p["offset" + v] = t.getUniformLocation(l, "offset" + v, !1);
  10167. }
  10168. return {
  10169. program: e,
  10170. source: c,
  10171. webGLProgram: l,
  10172. uniformLocations: p,
  10173. inShapeInfos: u,
  10174. outShapeInfo: s,
  10175. infLoc: h,
  10176. nanLoc: f
  10177. };
  10178. }(i.gpgpu, t, h, p);
  10179. }),
  10180. m = null != this.activeTimers;
  10181. if (m && (f = this.startTimer()), function (t, e, n, r, o) {
  10182. Ei(e.inShapeInfos, n), Ei([e.outShapeInfo], [r]);
  10183. var i = r.texData.texture,
  10184. u = r.texData.texShape;
  10185. r.texData.isPacked ? t.setOutputPackedMatrixTexture(i, u[0], u[1]) : t.setOutputMatrixTexture(i, u[0], u[1]), t.setProgram(e.webGLProgram), 1 === a().getNumber("WEBGL_VERSION") && null !== e.infLoc && t.gl.uniform1f(e.infLoc, 1 / 0), null !== e.nanLoc && t.gl.uniform1f(e.nanLoc, NaN), n.forEach(function (n, r) {
  10186. var o = e.program.variableNames[r],
  10187. a = e.uniformLocations[o],
  10188. i = e.uniformLocations["offset" + o];
  10189. if (null != a) if (n.isUniform) {
  10190. if (w(n.shape) < 2) t.gl.uniform1f(a, n.uniformValues[0]); else {
  10191. var u = n.uniformValues;
  10192. u instanceof Float32Array || (u = new Float32Array(u)), t.gl.uniform1fv(a, u);
  10193. }
  10194. } else null != n.texData.slice && null != i && t.gl.uniform1i(i, n.texData.slice.flatOffset), t.setInputMatrixTexture(n.texData.texture, a, r);
  10195. }), null != o && o(t, e.webGLProgram), t.executeProgram();
  10196. }(this.gpgpu, v, h, p, r), l.forEach(function (t) {
  10197. return i.disposeData(t.dataId);
  10198. }), m && (f = this.endTimer(f), this.activeTimers.push({
  10199. name: t.constructor.name,
  10200. query: this.getQueryTime(f)
  10201. })), !a().getBool("WEBGL_LAZILY_UNPACK") && s.isPacked && !1 === o) {
  10202. var g = this.unpackTensor(u);
  10203. return this.disposeData(u.dataId), g;
  10204. }
  10205. return u;
  10206. }, o.prototype.compileAndRun = function (t, e, n, r, o) {
  10207. void 0 === o && (o = !1), n = n || e[0].dtype;
  10208. var a = this.runWebGLProgram(t, e, n, r, o);
  10209. return Nt.makeTensorFromDataId(a.dataId, a.shape, a.dtype);
  10210. }, o.prototype.getAndSaveBinary = function (t, e) {
  10211. return t in this.binaryCache || (this.binaryCache[t] = e()), this.binaryCache[t];
  10212. }, o.prototype.getTextureManager = function () {
  10213. return this.textureManager;
  10214. }, o.prototype.dispose = function () {
  10215. this.disposed || (this.textureManager.dispose(), null != this.canvas && "undefined" != typeof HTMLCanvasElement && this.canvas instanceof HTMLCanvasElement ? this.canvas.remove() : this.canvas = null, null != this.fromPixels2DContext && this.fromPixels2DContext.canvas.remove && this.fromPixels2DContext.canvas.remove(), this.gpgpuCreatedLocally && (this.gpgpu.program = null, this.gpgpu.dispose()), this.disposed = !0);
  10216. }, o.prototype.floatPrecision = function () {
  10217. var t = this;
  10218. return null == this.floatPrecisionValue && (this.floatPrecisionValue = je(function () {
  10219. if (!a().get("WEBGL_RENDER_FLOAT32_ENABLED")) {
  10220. var e = a().getBool("DEBUG");
  10221. a().set("DEBUG", !1);
  10222. var n = t.abs(An(1e-8)).dataSync()[0];
  10223. if (a().set("DEBUG", e), n > 0) return 32;
  10224. }
  10225. return 16;
  10226. })), this.floatPrecisionValue;
  10227. }, o.prototype.epsilon = function () {
  10228. return 32 === this.floatPrecision() ? 1e-7 : 1e-4;
  10229. }, o.prototype.uploadToGPU = function (t) {
  10230. var e,
  10231. n = this.texData.get(t),
  10232. r = n.shape,
  10233. o = n.dtype,
  10234. a = n.values,
  10235. i = n.texture,
  10236. u = n.usage,
  10237. s = n.isPacked;
  10238. if (null == i) {
  10239. var c,
  10240. l = null != this.activeTimers;
  10241. l && (c = Y());
  10242. var h = n.texShape;
  10243. if (null == h && (h = Ie(r, s), n.texShape = h), null != a) {
  10244. var f = Re(r),
  10245. p = void 0,
  10246. d = h[1],
  10247. v = h[0],
  10248. m = a instanceof Uint8Array;
  10249. s ? (d = (e = Ht(h[0], h[1]))[0], v = e[1], p = new $a(f, [v, d], m)) : p = new Xa(f, [v, d], m);
  10250. var g = this.makeTensorInfo([v, d], o);
  10251. this.texData.get(g.dataId).usage = m ? Mt.PIXELS : Mt.UPLOAD, this.gpgpu.uploadDenseMatrixToTexture(this.getTexture(g.dataId), d, v, a);
  10252. var y = this.runWebGLProgram(p, [g], o, null, !0),
  10253. x = this.texData.get(y.dataId);
  10254. n.texture = x.texture, n.texShape = x.texShape, n.isPacked = x.isPacked, n.usage = x.usage, this.disposeData(g.dataId), this.texData.delete(y.dataId), n.values = null, l && (this.uploadWaitMs += Y() - c);
  10255. } else {
  10256. var b = this.acquireTexture(h, u, o, s);
  10257. n.texture = b;
  10258. }
  10259. }
  10260. }, o.prototype.convertAndCacheOnCPU = function (t, e) {
  10261. var n = this.texData.get(t),
  10262. r = n.dtype;
  10263. return this.releaseGPUData(t), null != e && (n.values = function (t, e) {
  10264. if ("float32" === e || "complex64" === e) return t;
  10265. if ("int32" === e || "bool" === e) {
  10266. for (var n = "int32" === e ? new Int32Array(t.length) : new Uint8Array(t.length), r = 0; r < n.length; ++r) n[r] = Math.round(t[r]);
  10267. return n;
  10268. }
  10269. throw new Error("Unknown dtype " + e);
  10270. }(e, r)), n.values;
  10271. }, o.prototype.acquireTexture = function (t, e, n, r) {
  10272. if (this.numBytesInGPU += this.computeBytes(t, n), !this.warnedAboutMemory && this.numBytesInGPU > 1024 * this.numMBBeforeWarning * 1024) {
  10273. var o = (this.numBytesInGPU / 1024 / 1024).toFixed(2);
  10274. this.warnedAboutMemory = !0, console.warn("High memory usage in GPU: " + o + " MB, most likely due to a memory leak");
  10275. }
  10276. return this.textureManager.acquireTexture(t, e, r);
  10277. }, o.prototype.computeBytes = function (t, e) {
  10278. return t[0] * t[1] * P(e);
  10279. }, o;
  10280. }(co);
  10281. Ft() && Nt.registerBackend("webgl", function () {
  10282. return new Wu();
  10283. }, 2);
  10284. var Uu = Cn({
  10285. square_: function (t) {
  10286. var e = ln(t, "x", "square"),
  10287. n = [e];
  10288. return Nt.runKernelFunc(function (t, n) {
  10289. return n([e]), t.square(e);
  10290. }, {
  10291. x: e
  10292. }, function (t, e) {
  10293. var n = e[0];
  10294. return {
  10295. x: function () {
  10296. return t.mul(n.toFloat().mul(2));
  10297. }
  10298. };
  10299. }, "Square", {}, n, []);
  10300. }
  10301. });
  10302. exports.square = Uu;
  10303. var Vu = Cn({
  10304. abs_: function (t) {
  10305. var e = ln(t, "x", "abs");
  10306. return "complex64" === e.dtype ? Nt.runKernelFunc(function (t) {
  10307. return t.complexAbs(e);
  10308. }, {
  10309. $x: e
  10310. }) : Nt.runKernelFunc(function (t, n) {
  10311. var r = t.abs(e);
  10312. return n([e]), r;
  10313. }, {
  10314. x: e
  10315. }, function (t, e) {
  10316. var n = e[0];
  10317. return {
  10318. x: function () {
  10319. return t.mul(n.toFloat().step(-1));
  10320. }
  10321. };
  10322. }, "Abs");
  10323. }
  10324. }),
  10325. zu = Cn({
  10326. acos_: function (t) {
  10327. var e = ln(t, "x", "acos");
  10328. return Nt.runKernelFunc(function (t, n) {
  10329. var r = t.acos(e);
  10330. return n([e]), r;
  10331. }, {
  10332. $x: e
  10333. }, function (t, e) {
  10334. var n = e[0];
  10335. return {
  10336. $x: function () {
  10337. return t.divStrict(An(1).sub(n.toFloat().square()).sqrt()).neg();
  10338. }
  10339. };
  10340. });
  10341. }
  10342. }),
  10343. Gu = Cn({
  10344. acosh_: function (t) {
  10345. var e = ln(t, "x", "acosh");
  10346. return Nt.runKernelFunc(function (t, n) {
  10347. var r = t.acosh(e);
  10348. return n([e]), r;
  10349. }, {
  10350. $x: e
  10351. }, function (t, e) {
  10352. var n = e[0];
  10353. return {
  10354. $x: function () {
  10355. return t.divStrict(n.toFloat().square().sub(1).sqrt());
  10356. }
  10357. };
  10358. });
  10359. }
  10360. }),
  10361. Hu = Cn({
  10362. asin_: function (t) {
  10363. var e = ln(t, "x", "asin");
  10364. return Nt.runKernelFunc(function (t, n) {
  10365. var r = t.asin(e);
  10366. return n([e]), r;
  10367. }, {
  10368. $x: e
  10369. }, function (t, e) {
  10370. var n = e[0];
  10371. return {
  10372. $x: function () {
  10373. return t.divStrict(An(1).sub(n.toFloat().square()).sqrt());
  10374. }
  10375. };
  10376. });
  10377. }
  10378. }),
  10379. qu = Cn({
  10380. asinh_: function (t) {
  10381. var e = ln(t, "x", "asinh");
  10382. return Nt.runKernelFunc(function (t, n) {
  10383. var r = t.asinh(e);
  10384. return n([e]), r;
  10385. }, {
  10386. $x: e
  10387. }, function (t, e) {
  10388. var n = e[0];
  10389. return {
  10390. $x: function () {
  10391. return t.divStrict(An(1).add(n.toFloat().square()).sqrt());
  10392. }
  10393. };
  10394. });
  10395. }
  10396. }),
  10397. Ku = Cn({
  10398. atan_: function (t) {
  10399. var e = ln(t, "x", "atan");
  10400. return Nt.runKernelFunc(function (t, n) {
  10401. var r = t.atan(e);
  10402. return n([e]), r;
  10403. }, {
  10404. $x: e
  10405. }, function (t, e) {
  10406. var n = e[0];
  10407. return {
  10408. $x: function () {
  10409. return t.div(n.toFloat().square().add(1));
  10410. }
  10411. };
  10412. });
  10413. }
  10414. }),
  10415. ju = Cn({
  10416. atanh_: function (t) {
  10417. var e = ln(t, "x", "atanh");
  10418. return Nt.runKernelFunc(function (t, n) {
  10419. var r = t.atanh(e);
  10420. return n([e]), r;
  10421. }, {
  10422. $x: e
  10423. }, function (t, e) {
  10424. var n = e[0];
  10425. return {
  10426. $x: function () {
  10427. return t.div(An(1).sub(n.toFloat().square()));
  10428. }
  10429. };
  10430. });
  10431. }
  10432. }),
  10433. Xu = Cn({
  10434. ceil_: function (t) {
  10435. var e = ln(t, "x", "ceil");
  10436. return Nt.runKernelFunc(function (t) {
  10437. return t.ceil(e);
  10438. }, {
  10439. $x: e
  10440. }, function (t) {
  10441. return {
  10442. $x: function () {
  10443. return zn(t);
  10444. }
  10445. };
  10446. });
  10447. }
  10448. }),
  10449. $u = Cn({
  10450. clipByValue_: function (t, e, n) {
  10451. var r = ln(t, "x", "clipByValue");
  10452. return g(e <= n, function () {
  10453. return "Error in clip: min (" + e + ") must be less than or equal to max (" + n + ").";
  10454. }), Nt.runKernelFunc(function (t, o) {
  10455. var a = t.clip(r, e, n);
  10456. return o([r]), a;
  10457. }, {
  10458. $x: r
  10459. }, function (t, r) {
  10460. var o = r[0];
  10461. return {
  10462. $x: function () {
  10463. return t.where(o.greaterEqual(e).logicalAnd(o.lessEqual(n)), zn(t));
  10464. }
  10465. };
  10466. });
  10467. }
  10468. }),
  10469. Yu = Cn({
  10470. cos_: function (t) {
  10471. var e = ln(t, "x", "cos");
  10472. return Nt.runKernelFunc(function (t, n) {
  10473. var r = t.cos(e);
  10474. return n([e]), r;
  10475. }, {
  10476. $x: e
  10477. }, function (t, e) {
  10478. var n = e[0];
  10479. return {
  10480. $x: function () {
  10481. return n.toFloat().sin().neg().mul(t);
  10482. }
  10483. };
  10484. });
  10485. }
  10486. }),
  10487. Qu = Cn({
  10488. cosh_: function (t) {
  10489. var e = ln(t, "x", "cosh");
  10490. return Nt.runKernelFunc(function (t, n) {
  10491. var r = t.cosh(e);
  10492. return n([e]), r;
  10493. }, {
  10494. $x: e
  10495. }, function (t, e) {
  10496. var n = e[0];
  10497. return {
  10498. $x: function () {
  10499. return n.toFloat().sinh().mulStrict(t);
  10500. }
  10501. };
  10502. });
  10503. }
  10504. }),
  10505. Ju = Cn({
  10506. erf_: function (t) {
  10507. var e = ln(t, "x", "erf");
  10508. return g("int32" === e.dtype || "float32" === e.dtype, function () {
  10509. return "Input dtype must be `int32` or `float32`.";
  10510. }), "int32" === e.dtype && (e = e.toFloat()), Nt.runKernelFunc(function (t, n) {
  10511. var r = t.erf(e);
  10512. return n([e]), r;
  10513. }, {
  10514. $x: e
  10515. }, function (t, e) {
  10516. var n = e[0];
  10517. return {
  10518. $x: function () {
  10519. return t.mul(n.square().neg().exp().mul(2 / Math.sqrt(Math.PI)));
  10520. }
  10521. };
  10522. });
  10523. }
  10524. }),
  10525. Zu = Cn({
  10526. exp_: function (t) {
  10527. var e = ln(t, "x", "exp");
  10528. return Nt.runKernelFunc(function (t, n) {
  10529. var r = t.exp(e);
  10530. return n([r]), r;
  10531. }, {
  10532. $x: e
  10533. }, function (t, e) {
  10534. return {
  10535. $x: function () {
  10536. return t.mulStrict(e[0]);
  10537. }
  10538. };
  10539. });
  10540. }
  10541. }),
  10542. ts = Cn({
  10543. expm1_: function (t) {
  10544. var e = ln(t, "x", "expm1");
  10545. return Nt.runKernelFunc(function (t, n) {
  10546. var r = t.expm1(e);
  10547. return n([e]), r;
  10548. }, {
  10549. $x: e
  10550. }, function (t, e) {
  10551. var n = e[0];
  10552. return {
  10553. $x: function () {
  10554. return t.mul(n.exp());
  10555. }
  10556. };
  10557. });
  10558. }
  10559. }),
  10560. es = Cn({
  10561. floor_: function (t) {
  10562. var e = ln(t, "x", "floor");
  10563. return Nt.runKernelFunc(function (t) {
  10564. return t.floor(e);
  10565. }, {
  10566. $x: e
  10567. }, function (t) {
  10568. return {
  10569. $x: function () {
  10570. return zn(t);
  10571. }
  10572. };
  10573. });
  10574. }
  10575. }),
  10576. ns = Cn({
  10577. log_: function (t) {
  10578. var e = ln(t, "x", "log");
  10579. return Nt.runKernelFunc(function (t, n) {
  10580. var r = t.log(e);
  10581. return n([e]), r;
  10582. }, {
  10583. $x: e
  10584. }, function (t, e) {
  10585. var n = e[0];
  10586. return {
  10587. $x: function () {
  10588. return t.div(n.toFloat());
  10589. }
  10590. };
  10591. });
  10592. }
  10593. }),
  10594. rs = Cn({
  10595. log1p_: function (t) {
  10596. var e = ln(t, "x", "log1p");
  10597. return Nt.runKernelFunc(function (t, n) {
  10598. var r = t.log1p(e);
  10599. return n([e]), r;
  10600. }, {
  10601. $x: e
  10602. }, function (t, e) {
  10603. var n = e[0];
  10604. return {
  10605. $x: function () {
  10606. return t.div(n.add(1));
  10607. }
  10608. };
  10609. });
  10610. }
  10611. }),
  10612. os = Cn({
  10613. logSigmoid_: function (t) {
  10614. var e = ln(t, "x", "logSigmoid");
  10615. return Nt.runKernelFunc(function (t, n) {
  10616. var r = t.softplus(e.neg()).neg();
  10617. return n([e]), r;
  10618. }, {
  10619. $x: e
  10620. }, function (t, e) {
  10621. var n = e[0];
  10622. return {
  10623. $x: function () {
  10624. return t.mul(n.neg().sigmoid());
  10625. }
  10626. };
  10627. });
  10628. }
  10629. }),
  10630. as = Cn({
  10631. neg_: function (t) {
  10632. var e = ln(t, "x", "neg");
  10633. return Nt.runKernelFunc(function (t) {
  10634. return t.neg(e);
  10635. }, {
  10636. $x: e
  10637. }, function (t) {
  10638. return {
  10639. $x: function () {
  10640. return t.neg();
  10641. }
  10642. };
  10643. });
  10644. }
  10645. }),
  10646. is = Cn({
  10647. reciprocal_: function (t) {
  10648. var e = ln(t, "x", "reciprocal");
  10649. return Nt.runKernelFunc(function (t, n) {
  10650. var r = t.reciprocal(e);
  10651. return n([e]), r;
  10652. }, {
  10653. $x: e
  10654. }, function (t, e) {
  10655. var n = e[0];
  10656. return {
  10657. $x: function () {
  10658. return t.div(n.square().neg());
  10659. }
  10660. };
  10661. });
  10662. }
  10663. }),
  10664. us = Cn({
  10665. round_: function (t) {
  10666. var e = ln(t, "x", "round");
  10667. return Nt.runKernelFunc(function (t) {
  10668. return t.round(e);
  10669. }, {
  10670. $x: e
  10671. }, function (t) {
  10672. return {
  10673. $x: function () {
  10674. return zn(t);
  10675. }
  10676. };
  10677. });
  10678. }
  10679. }),
  10680. ss = Cn({
  10681. rsqrt_: function (t) {
  10682. var e = ln(t, "x", "rsqrt");
  10683. return Nt.runKernelFunc(function (t, n) {
  10684. var r = t.rsqrt(e);
  10685. return n([e]), r;
  10686. }, {
  10687. $x: e
  10688. }, function (t, e) {
  10689. var n = e[0];
  10690. return {
  10691. $x: function () {
  10692. return t.div(n.pow(1.5).mul(2)).neg();
  10693. }
  10694. };
  10695. });
  10696. }
  10697. }),
  10698. cs = Cn({
  10699. sigmoid_: function (t) {
  10700. var e = ln(t, "x", "sigmoid");
  10701. return Nt.runKernelFunc(function (t, n) {
  10702. var r = t.sigmoid(e);
  10703. return n([r]), r;
  10704. }, {
  10705. x: e
  10706. }, function (t, e) {
  10707. var n = e[0];
  10708. return {
  10709. x: function () {
  10710. return t.mul(n.mul(An(1).sub(n)));
  10711. }
  10712. };
  10713. }, "Sigmoid");
  10714. }
  10715. }),
  10716. ls = Cn({
  10717. sign_: function (t) {
  10718. var e = ln(t, "x", "sign");
  10719. return Nt.runKernelFunc(function (t) {
  10720. return t.sign(e);
  10721. }, {
  10722. $x: e
  10723. }, function (t) {
  10724. return {
  10725. $x: function () {
  10726. return zn(t);
  10727. }
  10728. };
  10729. });
  10730. }
  10731. }),
  10732. hs = Cn({
  10733. isNaN_: function (t) {
  10734. var e = ln(t, "x", "isNaN");
  10735. return Nt.runKernelFunc(function (t) {
  10736. return t.isNaN(e);
  10737. }, {
  10738. $x: e
  10739. }, function (t) {
  10740. return {
  10741. $x: function () {
  10742. return zn(t);
  10743. }
  10744. };
  10745. });
  10746. }
  10747. }),
  10748. fs = Cn({
  10749. isInf_: function (t) {
  10750. var e = ln(t, "x", "isInf");
  10751. return Nt.runKernelFunc(function (t) {
  10752. return t.isInf(e);
  10753. }, {
  10754. $x: e
  10755. }, function (t) {
  10756. return {
  10757. $x: function () {
  10758. return zn(t);
  10759. }
  10760. };
  10761. });
  10762. }
  10763. }),
  10764. ps = Cn({
  10765. isFinite_: function (t) {
  10766. var e = ln(t, "x", "isFinite");
  10767. return Nt.runKernelFunc(function (t) {
  10768. return t.isFinite(e);
  10769. }, {
  10770. $x: e
  10771. }, function (t) {
  10772. return {
  10773. $x: function () {
  10774. return zn(t);
  10775. }
  10776. };
  10777. });
  10778. }
  10779. }),
  10780. ds = Cn({
  10781. sin_: function (t) {
  10782. var e = ln(t, "x", "sin");
  10783. return Nt.runKernelFunc(function (t, n) {
  10784. var r = t.sin(e);
  10785. return n([e]), r;
  10786. }, {
  10787. $x: e
  10788. }, function (t, e) {
  10789. var n = e[0];
  10790. return {
  10791. $x: function () {
  10792. return n.toFloat().cos().mul(t);
  10793. }
  10794. };
  10795. });
  10796. }
  10797. }),
  10798. vs = Cn({
  10799. sinh_: function (t) {
  10800. var e = ln(t, "x", "sinh");
  10801. return Nt.runKernelFunc(function (t, n) {
  10802. var r = t.sinh(e);
  10803. return n([e]), r;
  10804. }, {
  10805. $x: e
  10806. }, function (t, e) {
  10807. var n = e[0];
  10808. return {
  10809. $x: function () {
  10810. return n.toFloat().cosh().mulStrict(t);
  10811. }
  10812. };
  10813. });
  10814. }
  10815. }),
  10816. ms = Cn({
  10817. softplus_: function (t) {
  10818. var e = ln(t, "x", "softplus");
  10819. return Nt.runKernelFunc(function (t, n) {
  10820. var r = t.softplus(e);
  10821. return n([e]), r;
  10822. }, {
  10823. $x: e
  10824. }, function (t, e) {
  10825. var n = e[0];
  10826. return {
  10827. $x: function () {
  10828. return t.mul(n.sigmoid());
  10829. }
  10830. };
  10831. });
  10832. }
  10833. }),
  10834. gs = Cn({
  10835. sqrt_: function (t) {
  10836. var e = ln(t, "x", "sqrt");
  10837. return Nt.runKernelFunc(function (t, n) {
  10838. var r = t.sqrt(e);
  10839. return n([e]), r;
  10840. }, {
  10841. $x: e
  10842. }, function (t, e) {
  10843. var n = e[0];
  10844. return {
  10845. $x: function () {
  10846. return t.div(n.toFloat().sqrt().mul(2));
  10847. }
  10848. };
  10849. });
  10850. }
  10851. }),
  10852. ys = Cn({
  10853. step_: function (t, e) {
  10854. void 0 === e && (e = 0);
  10855. var n = ln(t, "x", "step");
  10856. return Nt.runKernelFunc(function (t) {
  10857. return t.step(n, e);
  10858. }, {
  10859. $x: n
  10860. }, function (t) {
  10861. return {
  10862. $x: function () {
  10863. return zn(t);
  10864. }
  10865. };
  10866. });
  10867. }
  10868. }),
  10869. xs = Cn({
  10870. tan_: function (t) {
  10871. var e = ln(t, "x", "tan");
  10872. return Nt.runKernelFunc(function (t, n) {
  10873. var r = t.tan(e);
  10874. return n([e]), r;
  10875. }, {
  10876. $x: e
  10877. }, function (t, e) {
  10878. var n = e[0];
  10879. return {
  10880. $x: function () {
  10881. return t.div(n.cos().square());
  10882. }
  10883. };
  10884. });
  10885. }
  10886. }),
  10887. bs = Cn({
  10888. tanh_: function (t) {
  10889. var e = ln(t, "x", "tanh");
  10890. return Nt.runKernelFunc(function (t, n) {
  10891. var r = t.tanh(e);
  10892. return n([r]), r;
  10893. }, {
  10894. $x: e
  10895. }, function (t, e) {
  10896. var n = e[0];
  10897. return {
  10898. $x: function () {
  10899. return An(1).sub(n.square()).mulStrict(t);
  10900. }
  10901. };
  10902. });
  10903. }
  10904. });
  10905. exports.tanh = bs;
  10906. exports.tan = xs;
  10907. exports.step = ys;
  10908. exports.sqrt = gs;
  10909. exports.softplus = ms;
  10910. exports.sinh = vs;
  10911. exports.sin = ds;
  10912. exports.isFinite = ps;
  10913. exports.isInf = fs;
  10914. exports.isNaN = hs;
  10915. exports.sign = ls;
  10916. exports.sigmoid = cs;
  10917. exports.rsqrt = ss;
  10918. exports.round = us;
  10919. exports.reciprocal = is;
  10920. exports.neg = as;
  10921. exports.logSigmoid = os;
  10922. exports.log1p = rs;
  10923. exports.log = ns;
  10924. exports.floor = es;
  10925. exports.expm1 = ts;
  10926. exports.exp = Zu;
  10927. exports.erf = Ju;
  10928. exports.cosh = Qu;
  10929. exports.cos = Yu;
  10930. exports.clipByValue = $u;
  10931. exports.ceil = Xu;
  10932. exports.atanh = ju;
  10933. exports.atan = Ku;
  10934. exports.asinh = qu;
  10935. exports.asin = Hu;
  10936. exports.acosh = Gu;
  10937. exports.acos = zu;
  10938. exports.abs = Vu;
  10939. function ws(t, e, n, r, o, a) {
  10940. var i,
  10941. u,
  10942. s = ln(t, "x", "batchNorm"),
  10943. c = ln(e, "mean", "batchNorm"),
  10944. l = ln(n, "variance", "batchNorm");
  10945. return null != o && (i = ln(o, "scale", "batchNorm")), null != r && (u = ln(r, "offset", "batchNorm")), g(2 === s.rank, function () {
  10946. return "Error in batchNorm3D: x must be rank 3 but got rank " + s.rank + ".";
  10947. }), g(2 === c.rank || 1 === c.rank, function () {
  10948. return "Error in batchNorm2D: mean must be rank 2 or rank 1 but got rank " + c.rank + ".";
  10949. }), g(2 === l.rank || 1 === l.rank, function () {
  10950. return "Error in batchNorm2D: variance must be rank 2 or rank 1 but got rank " + l.rank + ".";
  10951. }), null != i && g(2 === i.rank || 1 === i.rank, function () {
  10952. return "Error in batchNorm2D: scale must be rank 2 or rank 1 but got rank " + i.rank + ".";
  10953. }), null != u && g(2 === u.rank || 1 === u.rank, function () {
  10954. return "Error in batchNorm2D: offset must be rank 2 or rank 1 but got rank " + u.rank + ".";
  10955. }), Rs(s, c, l, u, i, a);
  10956. }
  10957. function Cs(t, e, n, r, o, a) {
  10958. var i,
  10959. u,
  10960. s = ln(t, "x", "batchNorm"),
  10961. c = ln(e, "mean", "batchNorm"),
  10962. l = ln(n, "variance", "batchNorm");
  10963. return null != o && (i = ln(o, "scale", "batchNorm")), null != r && (u = ln(r, "offset", "batchNorm")), g(3 === s.rank, function () {
  10964. return "Error in batchNorm3D: x must be rank 3 but got rank " + s.rank + ".";
  10965. }), g(3 === c.rank || 1 === c.rank, function () {
  10966. return "Error in batchNorm3D: mean must be rank 3 or rank 1 but got rank " + c.rank + ".";
  10967. }), g(3 === l.rank || 1 === l.rank, function () {
  10968. return "Error in batchNorm3D: variance must be rank 3 or rank 1 but got rank " + l.rank + ".";
  10969. }), null != i && g(3 === i.rank || 1 === i.rank, function () {
  10970. return "Error in batchNorm3D: scale must be rank 3 or rank 1 but got rank " + i.rank + ".";
  10971. }), null != u && g(3 === u.rank || 1 === u.rank, function () {
  10972. return "Error in batchNorm3D: offset must be rank 3 or rank 1 but got rank " + u.rank + ".";
  10973. }), Rs(s, c, l, u, i, a);
  10974. }
  10975. function Es(t, e, n, r, o, a) {
  10976. var i,
  10977. u,
  10978. s = ln(t, "x", "batchNorm"),
  10979. c = ln(e, "mean", "batchNorm"),
  10980. l = ln(n, "variance", "batchNorm");
  10981. return null != o && (i = ln(o, "scale", "batchNorm")), null != r && (u = ln(r, "offset", "batchNorm")), g(4 === s.rank, function () {
  10982. return "Error in batchNorm4D: x must be rank 4 but got rank " + s.rank + ".";
  10983. }), g(4 === c.rank || 1 === c.rank, function () {
  10984. return "Error in batchNorm4D: mean must be rank 4 or rank 1 but got rank " + c.rank + ".";
  10985. }), g(4 === l.rank || 1 === l.rank, function () {
  10986. return "Error in batchNorm4D: variance must be rank 4 or rank 1 but got rank " + l.rank + ".";
  10987. }), null != i && g(4 === i.rank || 1 === i.rank, function () {
  10988. return "Error in batchNorm4D: scale must be rank 4 or rank 1 but got rank " + i.rank + ".";
  10989. }), null != u && g(4 === u.rank || 1 === u.rank, function () {
  10990. return "Error in batchNorm4D: offset must be rank 4 or rank 1 but got rank " + u.rank + ".";
  10991. }), Rs(s, c, l, u, i, a);
  10992. }
  10993. function Rs(t, e, n, r, o, a) {
  10994. null == a && (a = .001);
  10995. var i,
  10996. u,
  10997. s,
  10998. c = ln(t, "x", "batchNorm"),
  10999. l = ln(e, "mean", "batchNorm"),
  11000. h = ln(n, "variance", "batchNorm");
  11001. null != o && (i = ln(o, "scale", "batchNorm")), null != r && (u = ln(r, "offset", "batchNorm")), g(l.rank === h.rank, function () {
  11002. return "Batch normalization gradient requires mean and variance to have equal ranks.";
  11003. }), g(null == u || l.rank === u.rank, function () {
  11004. return "Batch normalization gradient requires mean and offset to have equal ranks.";
  11005. }), g(null == i || l.rank === i.rank, function () {
  11006. return "Batch normalization gradient requires mean and scale to have equal ranks.";
  11007. }), s = 0 === c.rank || 1 === c.rank ? c.as4D(1, 1, 1, c.size) : 2 === c.rank ? c.as4D(1, 1, c.shape[0], c.shape[1]) : 3 === c.rank ? c.as4D(1, c.shape[0], c.shape[1], c.shape[2]) : c;
  11008. var f = [c, l, h, i];
  11009. return Nt.runKernelFunc(function (t, e) {
  11010. var n = t.batchNormalization(s, Is(l), Is(h), a, Is(i), Is(u));
  11011. return e([c, l, h, i]), n;
  11012. }, {
  11013. x: c,
  11014. mean: l,
  11015. variance: h,
  11016. scale: i,
  11017. offset: u
  11018. }, function (t, e) {
  11019. var n = e,
  11020. r = n[0],
  11021. o = n[1],
  11022. i = n[2],
  11023. u = n[3],
  11024. c = null == u ? An(1) : u,
  11025. l = fo(o.shape, s.shape),
  11026. h = [];
  11027. if (1 === o.rank) {
  11028. for (var f = 0; f < s.shape.length - 1; ++f) h.push(s.shape[f]);
  11029. h.push(1);
  11030. }
  11031. var p = r.sub(o),
  11032. d = t.mul(c),
  11033. v = ss(i.add(An(a))),
  11034. m = v.mul(v).mul(v).mul(An(-.5));
  11035. return {
  11036. x: function () {
  11037. return 1 === o.rank ? t.mul(Nr(v.as4D(1, 1, 1, o.shape[0]), h)).mul(c).reshape(r.shape) : t.mul(v).mul(c).reshape(r.shape);
  11038. },
  11039. mean: function () {
  11040. var t = v.mul(An(-1)).mul(d);
  11041. return 1 === o.rank && (t = t.sum(l)), t.reshape(o.shape);
  11042. },
  11043. variance: function () {
  11044. var t = m.mul(p).mul(d);
  11045. return 1 === o.rank && (t = t.sum(l)), t.reshape(o.shape);
  11046. },
  11047. scale: function () {
  11048. var e = p.mul(v),
  11049. n = t.mul(e);
  11050. return 1 === o.rank && (n = n.sum(l)), n.reshape(o.shape);
  11051. },
  11052. offset: function () {
  11053. var e = t;
  11054. return 1 === o.rank && (e = e.sum(l)), e.reshape(o.shape);
  11055. }
  11056. };
  11057. }, "BatchNormalization", {
  11058. varianceEpsilon: a
  11059. }, f).reshape(c.shape);
  11060. }
  11061. function Is(t) {
  11062. return null == t ? null : 0 === t.rank ? t.as1D() : 1 === t.rank ? t : 2 === t.rank ? t.as4D(1, 1, t.shape[0], t.shape[1]) : 3 === t.rank ? t.as4D(1, t.shape[0], t.shape[1], t.shape[2]) : t;
  11063. }
  11064. function ks() {
  11065. ze("tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon");
  11066. }
  11067. var Ss = Cn({
  11068. batchNormalization2d_: function (t, e, n, r, o, a) {
  11069. return void 0 === r && (r = .001), ks(), ws(t, e, n, a, o, r);
  11070. }
  11071. }),
  11072. As = Cn({
  11073. batchNormalization3d_: function (t, e, n, r, o, a) {
  11074. return void 0 === r && (r = .001), ks(), Cs(t, e, n, a, o, r);
  11075. }
  11076. }),
  11077. Ds = Cn({
  11078. batchNormalization4d_: function (t, e, n, r, o, a) {
  11079. return void 0 === r && (r = .001), ks(), Es(t, e, n, a, o, r);
  11080. }
  11081. }),
  11082. Ts = Cn({
  11083. batchNormalization_: function (t, e, n, r, o, a) {
  11084. return void 0 === r && (r = .001), ks(), Rs(t, e, n, a, o, r);
  11085. }
  11086. }),
  11087. Ns = Cn({
  11088. batchNorm_: Rs
  11089. }),
  11090. Fs = Cn({
  11091. batchNorm2d_: ws
  11092. }),
  11093. Os = Cn({
  11094. batchNorm3d_: Cs
  11095. }),
  11096. _s = Cn({
  11097. batchNorm4d_: Es
  11098. });
  11099. exports.batchNorm4d = _s;
  11100. exports.batchNorm3d = Os;
  11101. exports.batchNorm2d = Fs;
  11102. exports.batchNorm = Ns;
  11103. exports.batchNormalization = Ts;
  11104. exports.batchNormalization4d = Ds;
  11105. exports.batchNormalization3d = As;
  11106. exports.batchNormalization2d = Ss;
  11107. var Ms = Cn({
  11108. logicalAnd_: function (t, e) {
  11109. var n = ln(t, "a", "logicalAnd", "bool"),
  11110. r = ln(e, "b", "logicalAnd", "bool");
  11111. return po(n.shape, r.shape), Nt.runKernelFunc(function (t) {
  11112. return t.logicalAnd(n, r);
  11113. }, {
  11114. $a: n,
  11115. $b: r
  11116. });
  11117. }
  11118. }),
  11119. Bs = Cn({
  11120. logicalNot_: function (t) {
  11121. var e = ln(t, "x", "logicalNot", "bool");
  11122. return Nt.runKernelFunc(function (t) {
  11123. return t.logicalNot(e);
  11124. }, {
  11125. $x: e
  11126. });
  11127. }
  11128. }),
  11129. Ps = Cn({
  11130. logicalOr_: function (t, e) {
  11131. var n = ln(t, "a", "logicalOr", "bool"),
  11132. r = ln(e, "b", "logicalOr", "bool");
  11133. return po(n.shape, r.shape), Nt.runKernelFunc(function (t) {
  11134. return t.logicalOr(n, r);
  11135. }, {
  11136. $a: n,
  11137. $b: r
  11138. });
  11139. }
  11140. }),
  11141. Ls = Cn({
  11142. logicalXor_: function (t, e) {
  11143. var n = ln(t, "a", "logicalXor", "bool"),
  11144. r = ln(e, "b", "logicalXor", "bool");
  11145. return po(n.shape, r.shape), Ps(t, e).logicalAnd(Ms(t, e).logicalNot());
  11146. }
  11147. }),
  11148. Ws = Cn({
  11149. where_: function (t, e, n) {
  11150. var r = ln(e, "a", "where"),
  11151. o = ln(n, "b", "where"),
  11152. a = ln(t, "condition", "where", "bool");
  11153. return y(r.shape, o.shape, "Error in where: "), 1 === a.rank ? g(a.shape[0] === r.shape[0], function () {
  11154. return "The first dimension of `a` must match the size of `condition`.";
  11155. }) : y(a.shape, o.shape, "Error in where: "), Nt.runKernelFunc(function (t, e) {
  11156. var n = t.select(a, r, o);
  11157. return e([a]), n;
  11158. }, {
  11159. $condition: a,
  11160. $a: r,
  11161. $b: o
  11162. }, function (t, e) {
  11163. var n = e[0];
  11164. return {
  11165. $condition: function () {
  11166. return zn(n).toFloat();
  11167. },
  11168. $a: function () {
  11169. return t.mul(n.cast(t.dtype));
  11170. },
  11171. $b: function () {
  11172. return t.mul(n.logicalNot().cast(t.dtype));
  11173. }
  11174. };
  11175. });
  11176. }
  11177. }),
  11178. Us = function (t) {
  11179. return n(this, void 0, void 0, function () {
  11180. var e, n, o;
  11181. return r(this, function (r) {
  11182. switch (r.label) {
  11183. case 0:
  11184. return [4, (e = ln(t, "condition", "whereAsync", "bool")).data()];
  11185. case 1:
  11186. return n = r.sent(), o = Uo(e.shape, n), t !== e && e.dispose(), [2, o];
  11187. }
  11188. });
  11189. });
  11190. };
  11191. exports.whereAsync = Us;
  11192. exports.where = Ws;
  11193. exports.logicalXor = Ls;
  11194. exports.logicalOr = Ps;
  11195. exports.logicalNot = Bs;
  11196. exports.logicalAnd = Ms;
  11197. var Vs = Cn({
  11198. add_: function (t, e) {
  11199. var n,
  11200. r = ln(t, "a", "add"),
  11201. o = ln(e, "b", "add");
  11202. n = Rt(r, o), r = n[0], o = n[1];
  11203. var a = po(r.shape, o.shape);
  11204. return Nt.runKernelFunc(function (t) {
  11205. return t.add(r, o);
  11206. }, {
  11207. a: r,
  11208. b: o
  11209. }, function (t) {
  11210. return {
  11211. a: function () {
  11212. var e = t,
  11213. n = fo(r.shape, a);
  11214. return n.length > 0 && (e = e.sum(n)), e.reshape(r.shape);
  11215. },
  11216. b: function () {
  11217. var e = t,
  11218. n = fo(o.shape, a);
  11219. return n.length > 0 && (e = e.sum(n)), e.reshape(o.shape);
  11220. }
  11221. };
  11222. }, "Add");
  11223. }
  11224. }),
  11225. zs = Cn({
  11226. addN_: function (t) {
  11227. g(Array.isArray(t), function () {
  11228. return "The argument passed to tf.addN() must be a list of tensors";
  11229. }), g(t.length >= 1, function () {
  11230. return "Must pass at least one tensor to tf.addN(), but got " + t.length;
  11231. });
  11232. var e = t.map(function (t, e) {
  11233. return ln(t, "tensors" + e, "addN");
  11234. }),
  11235. n = e[0];
  11236. e.forEach(function (t) {
  11237. if (t.dtype !== n.dtype) throw new Error("All tensors passed to tf.addN() must have the same dtype");
  11238. }), e.forEach(function (t) {
  11239. if (!C(t.shape, n.shape)) throw new Error("All tensors passed to tf.addN() must have the same shape");
  11240. });
  11241. var r = e;
  11242. return Nt.runKernelFunc(function (t) {
  11243. return t.addN(e);
  11244. }, r, function (t) {
  11245. var n = {};
  11246. return e.forEach(function (e, r) {
  11247. n[r] = function () {
  11248. return t.clone();
  11249. };
  11250. }), n;
  11251. });
  11252. }
  11253. }),
  11254. Gs = Cn({
  11255. addStrict_: function (t, e) {
  11256. var n = ln(t, "a", "addStrict"),
  11257. r = ln(e, "b", "addStrict");
  11258. return y(n.shape, r.shape, "Error in addStrict: "), n.add(r);
  11259. }
  11260. }),
  11261. Hs = Cn({
  11262. atan2_: function (t, e) {
  11263. var n,
  11264. r = ln(t, "a", "atan2"),
  11265. o = ln(e, "b", "atan2");
  11266. n = Rt(r, o), r = n[0], o = n[1];
  11267. var a = po(r.shape, o.shape);
  11268. return Nt.runKernelFunc(function (t, e) {
  11269. var n = t.atan2(r, o);
  11270. return e([r, o]), n;
  11271. }, {
  11272. $a: r,
  11273. $b: o
  11274. }, function (t, e) {
  11275. var n = e[0],
  11276. r = e[1];
  11277. return {
  11278. $a: function () {
  11279. var e = Vs(n.square(), r.square()),
  11280. o = t.mul(r.div(e)),
  11281. i = fo(n.shape, a);
  11282. return i.length > 0 && (o = o.sum(i)), o.reshape(n.shape);
  11283. },
  11284. $b: function () {
  11285. var e = Vs(n.square(), r.square()),
  11286. o = as(t.mul(n.div(e))),
  11287. i = fo(r.shape, a);
  11288. return i.length > 0 && (o = o.sum(i)), o.reshape(r.shape);
  11289. }
  11290. };
  11291. });
  11292. }
  11293. }),
  11294. qs = Cn({
  11295. div_: function (t, e) {
  11296. var n,
  11297. r = ln(t, "a", "div"),
  11298. o = ln(e, "b", "div");
  11299. if (n = Rt(r, o), r = n[0], o = n[1], "int32" === r.dtype && "int32" === o.dtype) return js(r, o);
  11300. var a = po(r.shape, o.shape);
  11301. return Nt.runKernelFunc(function (t, e) {
  11302. var n = t.realDivide(r, o);
  11303. return e([r, o]), n;
  11304. }, {
  11305. a: r,
  11306. b: o
  11307. }, function (t, e) {
  11308. var n = e[0],
  11309. r = e[1];
  11310. return {
  11311. a: function () {
  11312. var e = t.div(r.toFloat()),
  11313. o = fo(n.shape, a);
  11314. return o.length > 0 ? e.sum(o).reshape(n.shape) : e;
  11315. },
  11316. b: function () {
  11317. var e = t.mul(n.toFloat()),
  11318. o = fo(r.shape, a);
  11319. o.length > 0 && (e = e.sum(o).reshape(r.shape));
  11320. var i = r.square();
  11321. return e.div(i.toFloat()).neg();
  11322. }
  11323. };
  11324. }, "Div");
  11325. }
  11326. }),
  11327. Ks = Cn({
  11328. divStrict_: function (t, e) {
  11329. var n = ln(t, "a", "div"),
  11330. r = ln(e, "b", "div");
  11331. return y(n.shape, r.shape, "Error in divideStrict: "), n.div(r);
  11332. }
  11333. }),
  11334. js = Cn({
  11335. floorDiv_: function (t, e) {
  11336. var n,
  11337. r = ln(t, "a", "floorDiv"),
  11338. o = ln(e, "b", "floorDiv");
  11339. n = Rt(r, o), r = n[0], o = n[1];
  11340. var a = po(r.shape, o.shape);
  11341. return Nt.runKernelFunc(function (t, e) {
  11342. var n = t.floorDiv(r, o);
  11343. return e([r, o]), n;
  11344. }, {
  11345. $a: r,
  11346. $b: o
  11347. }, function (t, e) {
  11348. var n = e[0],
  11349. r = e[1];
  11350. return {
  11351. $a: function () {
  11352. var e = t.div(r.toFloat()),
  11353. o = fo(n.shape, a);
  11354. return o.length > 0 ? e.sum(o).reshape(n.shape) : e;
  11355. },
  11356. $b: function () {
  11357. var e = t.mul(n.toFloat()),
  11358. o = fo(r.shape, a);
  11359. o.length > 0 && (e = e.sum(o).reshape(r.shape));
  11360. var i = r.square();
  11361. return e.div(i.toFloat()).neg();
  11362. }
  11363. };
  11364. });
  11365. }
  11366. }),
  11367. Xs = Cn({
  11368. maximum_: function (t, e) {
  11369. var n,
  11370. r = ln(t, "a", "maximum"),
  11371. o = ln(e, "b", "maximum");
  11372. return n = Rt(r, o), r = n[0], o = n[1], "bool" === r.dtype && (r = r.toInt(), o = o.toInt()), po(r.shape, o.shape), Nt.runKernelFunc(function (t, e) {
  11373. var n = t.maximum(r, o);
  11374. return e([r, o]), n;
  11375. }, {
  11376. $a: r,
  11377. $b: o
  11378. }, function (t, e) {
  11379. var n = e[0],
  11380. r = e[1];
  11381. return {
  11382. $a: function () {
  11383. return t.mul(n.greaterEqual(r).toFloat());
  11384. },
  11385. $b: function () {
  11386. return t.mul(n.less(r).toFloat());
  11387. }
  11388. };
  11389. });
  11390. }
  11391. }),
  11392. $s = Cn({
  11393. maximumStrict_: function (t, e) {
  11394. var n = ln(t, "a", "maximumStrict"),
  11395. r = ln(e, "b", "maximumStrict");
  11396. return y(n.shape, r.shape, "Error in maximumStrict: "), n.maximum(r);
  11397. }
  11398. }),
  11399. Ys = Cn({
  11400. minimum_: function (t, e) {
  11401. var n,
  11402. r = ln(t, "a", "minimum"),
  11403. o = ln(e, "b", "minimum");
  11404. return n = Rt(r, o), r = n[0], o = n[1], "bool" === r.dtype && (r = r.toInt(), o = o.toInt()), po(r.shape, o.shape), Nt.runKernelFunc(function (t, e) {
  11405. var n = t.minimum(r, o);
  11406. return e([r, o]), n;
  11407. }, {
  11408. $a: r,
  11409. $b: o
  11410. }, function (t, e) {
  11411. var n = e[0],
  11412. r = e[1];
  11413. return {
  11414. $a: function () {
  11415. return t.mul(n.lessEqual(r).toFloat());
  11416. },
  11417. $b: function () {
  11418. return t.mul(n.greater(r).toFloat());
  11419. }
  11420. };
  11421. });
  11422. }
  11423. }),
  11424. Qs = Cn({
  11425. minimumStrict_: function (t, e) {
  11426. var n = ln(t, "a", "minimumStrict"),
  11427. r = ln(e, "b", "minimumStrict");
  11428. return y(n.shape, r.shape, "Error in minimumStrict: "), n.minimum(r);
  11429. }
  11430. }),
  11431. Js = Cn({
  11432. mod_: function (t, e) {
  11433. var n,
  11434. r = ln(t, "a", "mod"),
  11435. o = ln(e, "b", "mod");
  11436. n = Rt(r, o), r = n[0], o = n[1];
  11437. var a = po(r.shape, o.shape);
  11438. return Nt.runKernelFunc(function (t, e) {
  11439. var n = t.mod(r, o);
  11440. return e([r, o]), n;
  11441. }, {
  11442. $a: r,
  11443. $b: o
  11444. }, function (t, e) {
  11445. var n = e[0],
  11446. r = e[1];
  11447. return {
  11448. $a: function () {
  11449. var e = fo(n.shape, a);
  11450. return e.length > 0 ? t.sum(e).reshape(n.shape) : t;
  11451. },
  11452. $b: function () {
  11453. var e = t.mul(n.div(r).floor().neg()),
  11454. o = fo(r.shape, a);
  11455. return o.length > 0 ? e.sum(o).reshape(r.shape) : e;
  11456. }
  11457. };
  11458. });
  11459. }
  11460. }),
  11461. Zs = Cn({
  11462. modStrict_: function (t, e) {
  11463. var n = ln(t, "a", "modStrict"),
  11464. r = ln(e, "b", "modStrict");
  11465. return y(n.shape, r.shape, "Error in modStrict: "), n.mod(r);
  11466. }
  11467. }),
  11468. tc = Cn({
  11469. mul_: function (t, e) {
  11470. var n,
  11471. r = ln(t, "a", "mul"),
  11472. o = ln(e, "b", "mul");
  11473. n = Rt(r, o), r = n[0], o = n[1];
  11474. var a = po(r.shape, o.shape);
  11475. return Nt.runKernelFunc(function (t, e) {
  11476. var n = t.multiply(r, o);
  11477. return e([r, o]), n;
  11478. }, {
  11479. a: r,
  11480. b: o
  11481. }, function (t, e) {
  11482. var n = e[0],
  11483. r = e[1];
  11484. return {
  11485. a: function () {
  11486. var e = t.mul(r.toFloat()),
  11487. o = fo(n.shape, a);
  11488. return o.length > 0 ? e.sum(o).reshape(n.shape) : e;
  11489. },
  11490. b: function () {
  11491. var e = t.mul(n.toFloat()),
  11492. o = fo(r.shape, a);
  11493. return o.length > 0 ? e.sum(o).reshape(r.shape) : e;
  11494. }
  11495. };
  11496. }, "Mul");
  11497. }
  11498. }),
  11499. ec = Cn({
  11500. mulStrict_: function (t, e) {
  11501. var n = ln(t, "a", "mul"),
  11502. r = ln(e, "b", "mul");
  11503. return y(n.shape, r.shape, "Error in multiplyStrict: "), n.mul(r);
  11504. }
  11505. }),
  11506. nc = Cn({
  11507. pow_: function (t, e) {
  11508. var n = ln(t, "base", "pow"),
  11509. r = ln(e, "exp", "pow"),
  11510. o = po(n.shape, r.shape);
  11511. return t = n.cast(Ct(n.dtype, r.dtype)), e = r.cast(Ct(n.dtype, r.dtype)), Nt.runKernelFunc(function (t, e) {
  11512. var o = t.pow(n, r);
  11513. return e([n, r, o]), o;
  11514. }, {
  11515. $base: n,
  11516. $exp: r
  11517. }, function (t, e) {
  11518. var n = e[0],
  11519. r = e[1],
  11520. a = e[2];
  11521. return {
  11522. $base: function () {
  11523. var e = r.toFloat(),
  11524. a = t.mul(e.mul(n.pow(e.sub(An(1))))),
  11525. i = fo(n.shape, o);
  11526. return i.length > 0 && (a = a.sum(i)), a.reshape(n.shape);
  11527. },
  11528. $exp: function () {
  11529. var e = n.greater(0),
  11530. i = n.log().where(e, zn(n)),
  11531. u = t.mul(a.mul(i)),
  11532. s = fo(r.shape, o);
  11533. return s.length > 0 && (u = u.sum(s)), u.reshape(r.shape);
  11534. }
  11535. };
  11536. });
  11537. }
  11538. }),
  11539. rc = Cn({
  11540. powStrict_: function (t, e) {
  11541. return y(t.shape, e.shape, "Error in powStrict: "), t.pow(e);
  11542. }
  11543. }),
  11544. oc = Cn({
  11545. squaredDifference_: function (t, e) {
  11546. var n,
  11547. r = ln(t, "a", "squaredDifference"),
  11548. o = ln(e, "b", "squaredDifference");
  11549. return n = Rt(r, o), r = n[0], o = n[1], po(r.shape, o.shape), Nt.runKernelFunc(function (t, e) {
  11550. var n = t.squaredDifference(r, o);
  11551. return e([r, o]), n;
  11552. }, {
  11553. $a: r,
  11554. $b: o
  11555. }, function (t, e) {
  11556. var n = e[0],
  11557. r = e[1],
  11558. o = An(2);
  11559. return {
  11560. $a: function () {
  11561. return t.mul(n.sub(r).mul(o));
  11562. },
  11563. $b: function () {
  11564. return t.mul(r.sub(n).mul(o));
  11565. }
  11566. };
  11567. });
  11568. }
  11569. }),
  11570. ac = Cn({
  11571. squaredDifferenceStrict_: function (t, e) {
  11572. var n = ln(t, "a", "squaredDifferenceStrict"),
  11573. r = ln(e, "b", "squaredDifferenceStrict");
  11574. return y(n.shape, r.shape, "Error in squaredDifferenceStrict: "), n.squaredDifference(r);
  11575. }
  11576. }),
  11577. ic = Cn({
  11578. sub_: function (t, e) {
  11579. var n,
  11580. r = ln(t, "a", "sub"),
  11581. o = ln(e, "b", "sub");
  11582. n = Rt(r, o), r = n[0], o = n[1];
  11583. var a = po(r.shape, o.shape);
  11584. return Nt.runKernelFunc(function (t) {
  11585. return t.subtract(r, o);
  11586. }, {
  11587. a: r,
  11588. b: o
  11589. }, function (t) {
  11590. return {
  11591. a: function () {
  11592. var e = t,
  11593. n = fo(r.shape, a);
  11594. return n.length > 0 && (e = e.sum(n)), e.reshape(r.shape);
  11595. },
  11596. b: function () {
  11597. var e = t,
  11598. n = fo(o.shape, a);
  11599. return n.length > 0 && (e = e.sum(n)), e.neg().reshape(o.shape);
  11600. }
  11601. };
  11602. }, "Sub");
  11603. }
  11604. }),
  11605. uc = Cn({
  11606. subStrict_: function (t, e) {
  11607. var n = ln(t, "a", "subStrict"),
  11608. r = ln(e, "b", "subStrict");
  11609. return y(n.shape, r.shape, "Error in subStrict: "), n.sub(r);
  11610. }
  11611. });
  11612. exports.subStrict = uc;
  11613. exports.sub = ic;
  11614. exports.squaredDifferenceStrict = ac;
  11615. exports.squaredDifference = oc;
  11616. exports.powStrict = rc;
  11617. exports.pow = nc;
  11618. exports.mulStrict = ec;
  11619. exports.mul = tc;
  11620. exports.modStrict = Zs;
  11621. exports.mod = Js;
  11622. exports.minimumStrict = Qs;
  11623. exports.minimum = Ys;
  11624. exports.maximumStrict = $s;
  11625. exports.maximum = Xs;
  11626. exports.floorDiv = js;
  11627. exports.divStrict = Ks;
  11628. exports.div = qs;
  11629. exports.atan2 = Hs;
  11630. exports.addStrict = Gs;
  11631. exports.addN = zs;
  11632. exports.add = Vs;
  11633. var sc = Cn({
  11634. equal_: function (t, e) {
  11635. var n,
  11636. r = ln(t, "a", "equal"),
  11637. o = ln(e, "b", "equal");
  11638. return n = Rt(r, o), r = n[0], o = n[1], po(r.shape, o.shape), Nt.runKernelFunc(function (t) {
  11639. return t.equal(r, o);
  11640. }, {
  11641. $a: r,
  11642. $b: o
  11643. });
  11644. }
  11645. }),
  11646. cc = Cn({
  11647. equalStrict_: function (t, e) {
  11648. var n = ln(t, "a", "equalStrict"),
  11649. r = ln(e, "b", "equalStrict");
  11650. return y(n.shape, r.shape, "Error in equalStrict: "), n.equal(r);
  11651. }
  11652. }),
  11653. lc = Cn({
  11654. greater_: function (t, e) {
  11655. var n,
  11656. r = ln(t, "a", "greater"),
  11657. o = ln(e, "b", "greater");
  11658. return n = Rt(r, o), r = n[0], o = n[1], po(r.shape, o.shape), Nt.runKernelFunc(function (t) {
  11659. return t.greater(r, o);
  11660. }, {
  11661. $a: r,
  11662. $b: o
  11663. });
  11664. }
  11665. }),
  11666. hc = Cn({
  11667. greaterEqual_: function (t, e) {
  11668. var n,
  11669. r = ln(t, "a", "greaterEqual"),
  11670. o = ln(e, "b", "greaterEqual");
  11671. return n = Rt(r, o), r = n[0], o = n[1], po(r.shape, o.shape), Nt.runKernelFunc(function (t, e) {
  11672. var n = t.greaterEqual(r, o);
  11673. return e([r, o]), n;
  11674. }, {
  11675. $a: r,
  11676. $b: o
  11677. }, function (t, e) {
  11678. var n = e[0],
  11679. r = e[1];
  11680. return {
  11681. $a: function () {
  11682. return zn(n);
  11683. },
  11684. $b: function () {
  11685. return zn(r);
  11686. }
  11687. };
  11688. });
  11689. }
  11690. }),
  11691. fc = Cn({
  11692. greaterEqualStrict_: function (t, e) {
  11693. var n = ln(t, "a", "greaterEqualStrict"),
  11694. r = ln(e, "b", "greaterEqualStrict");
  11695. return y(n.shape, r.shape, "Error in greaterEqualStrict: "), n.greaterEqual(r);
  11696. }
  11697. }),
  11698. pc = Cn({
  11699. greaterStrict_: function (t, e) {
  11700. var n = ln(t, "a", "greaterStrict"),
  11701. r = ln(e, "b", "greaterStrict");
  11702. return y(n.shape, r.shape, "Error in greaterStrict: "), n.greater(r);
  11703. }
  11704. }),
  11705. dc = Cn({
  11706. less_: function (t, e) {
  11707. var n,
  11708. r = ln(t, "a", "less"),
  11709. o = ln(e, "b", "less");
  11710. return n = Rt(r, o), r = n[0], o = n[1], po(r.shape, o.shape), Nt.runKernelFunc(function (t) {
  11711. return t.less(r, o);
  11712. }, {
  11713. $a: r,
  11714. $b: o
  11715. });
  11716. }
  11717. }),
  11718. vc = Cn({
  11719. lessEqual_: function (t, e) {
  11720. var n,
  11721. r = ln(t, "a", "lessEqual"),
  11722. o = ln(e, "b", "lessEqual");
  11723. return n = Rt(r, o), r = n[0], o = n[1], po(r.shape, o.shape), Nt.runKernelFunc(function (t) {
  11724. return t.lessEqual(r, o);
  11725. }, {
  11726. $a: r,
  11727. $b: o
  11728. });
  11729. }
  11730. }),
  11731. mc = Cn({
  11732. lessEqualStrict_: function (t, e) {
  11733. var n = ln(t, "a", "lessEqualStrict"),
  11734. r = ln(e, "b", "lessEqualStrict");
  11735. return y(n.shape, r.shape, "Error in lessEqualStrict: "), n.lessEqual(r);
  11736. }
  11737. }),
  11738. gc = Cn({
  11739. lessStrict_: function (t, e) {
  11740. var n = ln(t, "a", "lessStrict"),
  11741. r = ln(e, "b", "lessStrict");
  11742. return y(n.shape, r.shape, "Error in lessStrict: "), n.less(r);
  11743. }
  11744. }),
  11745. yc = Cn({
  11746. notEqual_: function (t, e) {
  11747. var n,
  11748. r = ln(t, "a", "notEqual"),
  11749. o = ln(e, "b", "notEqual");
  11750. return n = Rt(r, o), r = n[0], o = n[1], po(r.shape, o.shape), Nt.runKernelFunc(function (t) {
  11751. return t.notEqual(r, o);
  11752. }, {
  11753. $a: r,
  11754. $b: o
  11755. });
  11756. }
  11757. }),
  11758. xc = Cn({
  11759. notEqualStrict_: function (t, e) {
  11760. var n = ln(t, "a", "notEqualStrict"),
  11761. r = ln(e, "b", "notEqualStrict");
  11762. return y(n.shape, r.shape, "Error in notEqualStrict: "), n.notEqual(r);
  11763. }
  11764. });
  11765. exports.notEqualStrict = xc;
  11766. exports.notEqual = yc;
  11767. exports.lessStrict = gc;
  11768. exports.lessEqualStrict = mc;
  11769. exports.lessEqual = vc;
  11770. exports.less = dc;
  11771. exports.greaterStrict = pc;
  11772. exports.greaterEqualStrict = fc;
  11773. exports.greaterEqual = hc;
  11774. exports.greater = lc;
  11775. exports.equalStrict = cc;
  11776. exports.equal = sc;
  11777. function bc(t, e) {
  11778. for (var n = [], r = t; r < e; ++r) n.push(r);
  11779. return n;
  11780. }
  11781. function wc(t) {
  11782. for (var e = [], n = 0; n < t.length; ++n) for (var r = 0; r < t[n].length; ++r) e.push(t[n][r]);
  11783. return e;
  11784. }
  11785. var Cc = Cn({
  11786. gather_: function (t, e, n) {
  11787. void 0 === n && (n = 0);
  11788. var r = ln(t, "x", "gather"),
  11789. o = ln(e, "indices", "gather", "int32");
  11790. n = D(n, r.shape)[0];
  11791. var a = function (t, e, n) {
  11792. for (var r = t.shape[n], o = [], a = 1, i = 1, u = 0; u < n; u++) o.push(t.shape[u]), a *= t.shape[u];
  11793. for (u = 0; u < e.rank; u++) o.push(e.shape[u]);
  11794. for (u = n + 1; u < t.rank; u++) o.push(t.shape[u]), i *= t.shape[u];
  11795. return {
  11796. batchSize: a,
  11797. sliceSize: i,
  11798. dimSize: r,
  11799. outputShape: o
  11800. };
  11801. }(r, o, n);
  11802. return Nt.runKernelFunc(function (t, e) {
  11803. var a = t.gather(r, o.flatten(), n);
  11804. return e([o]), a;
  11805. }, {
  11806. $x: r
  11807. }, function (t, e) {
  11808. var o = e[0];
  11809. return {
  11810. $x: function () {
  11811. var e = r.shape,
  11812. a = o.size,
  11813. i = e.slice(0, n),
  11814. u = i.length,
  11815. s = e.slice(n, e.length).slice(1),
  11816. c = s.length,
  11817. l = bc(0, u),
  11818. h = bc(u + 1, u + 1 + c),
  11819. f = wc([i, [a], s]),
  11820. p = t.reshape(f),
  11821. d = o.reshape([a]),
  11822. v = wc([[u], l, h]),
  11823. m = p.transpose(v),
  11824. g = Ec(m, d, r.shape[n]),
  11825. y = yn(v);
  11826. return g = g.transpose(y);
  11827. }
  11828. };
  11829. }).reshape(a.outputShape);
  11830. }
  11831. }),
  11832. Ec = Cn({
  11833. unsortedSegmentSum_: function (t, e, n) {
  11834. var r = ln(t, "x", "unsortedSegmentSum"),
  11835. o = ln(e, "segmentIds", "unsortedSegmentSum", "int32");
  11836. return g(E(n), function () {
  11837. return "numSegments must be of dtype int";
  11838. }), Nt.runKernelFunc(function (t, e) {
  11839. var a = t.unsortedSegmentSum(r, o, n);
  11840. return e([o]), a;
  11841. }, {
  11842. $x: r
  11843. }, function (t, e) {
  11844. var n = e[0];
  11845. return {
  11846. $x: function () {
  11847. return function (t, e) {
  11848. for (var n = Xs(e, zn(e)), r = Cc(t, n), o = hc(e, An(0, "int32")), a = r.rank - o.rank, i = 0; i < a; ++i) o = dr(o, i + 1);
  11849. o = Ms(o, Bn(r.shape, "bool"));
  11850. var u = zn(r);
  11851. return Ws(o, r, u);
  11852. }(t, n);
  11853. }
  11854. };
  11855. });
  11856. }
  11857. });
  11858. exports.unsortedSegmentSum = Ec;
  11859. exports.gather = Cc;
  11860. var Rc = function (t, e, o) {
  11861. return n(this, void 0, void 0, function () {
  11862. var n, a, i, u, s, c, l, h, f, p, d, v, m;
  11863. return r(this, function (r) {
  11864. switch (r.label) {
  11865. case 0:
  11866. for (n = ln(t, "tensor", "boolMask"), a = ln(e, "mask", "boolMask", "bool"), i = null == o ? 0 : o, u = a.rank, s = n.shape, g(u > 0, function () {
  11867. return "mask cannot be scalar";
  11868. }), y(s.slice(i, i + u), a.shape, "mask's shape must match the first K dimensions of tensor's shape,"), c = 1, l = i; l < i + u; l++) c *= s[l];
  11869. return h = s.slice(0, i).concat([c], s.slice(i + u)), f = n.reshape(h), p = a.reshape([-1]), [4, Us(p)];
  11870. case 1:
  11871. return d = r.sent(), v = d.squeeze([1]), m = Cc(f, v, i), t !== n && n.dispose(), e !== a && a.dispose(), v.dispose(), f.dispose(), p.dispose(), d.dispose(), [2, m];
  11872. }
  11873. });
  11874. });
  11875. };
  11876. exports.booleanMaskAsync = Rc;
  11877. function Ic(t, e, n, r, o, a, i) {
  11878. void 0 === a && (a = "NHWC"), g(t.length === e.rank, function () {
  11879. return "Length of inShape (" + t.length + ") and rank of dy (" + e.rank + ") must match";
  11880. });
  11881. var u = t,
  11882. s = e,
  11883. c = !1;
  11884. 3 === e.rank && (c = !0, s = e.as4D(1, e.shape[0], e.shape[1], e.shape[2]), u = [1, t[0], t[1], t[2]]), g(4 === u.length, function () {
  11885. return "Error in conv2dDerInput: inShape must be length 4, but got length " + u.length + ".";
  11886. }), g(4 === s.rank, function () {
  11887. return "Error in conv2dDerInput: dy must be rank 4, but got rank " + s.rank;
  11888. }), g(4 === n.rank, function () {
  11889. return "Error in conv2dDerInput: filter must be rank 4, but got rank " + n.rank;
  11890. });
  11891. var l = "NHWC" === a ? u[3] : u[1],
  11892. h = "NHWC" === a ? s.shape[3] : s.shape[1];
  11893. g(l === n.shape[2], function () {
  11894. return "Error in conv2dDerInput: depth of input (" + l + ") must match input depth for filter " + n.shape[2] + ".";
  11895. }), g(h === n.shape[3], function () {
  11896. return "Error in conv2dDerInput: depth of output (" + h + ") must match output depth for filter " + n.shape[3] + ".";
  11897. }), null != i && g(E(o), function () {
  11898. return "Error in conv2dDerInput: pad must be an integer when using, dimRoundingMode " + i + " but got pad " + o + ".";
  11899. });
  11900. var f = ko(a),
  11901. p = go(u, n.shape, r, 1, o, i, !1, f),
  11902. d = Nt.runKernelFunc(function (t, e) {
  11903. var r = t.conv2dDerInput(s, n, p);
  11904. return e([n, s]), r;
  11905. }, {
  11906. dy4D: s,
  11907. filter: n
  11908. }, function (t, e) {
  11909. var n = e[0],
  11910. u = e[1];
  11911. return {
  11912. dy4D: function () {
  11913. return Dc(t, n, r, o, a, 1, i);
  11914. },
  11915. filter: function () {
  11916. return Nc(t, u, n.shape, r, o, a, i);
  11917. }
  11918. };
  11919. });
  11920. return c ? d.as3D(d.shape[1], d.shape[2], d.shape[3]) : d;
  11921. }
  11922. function kc(t) {
  11923. var e = function (t) {
  11924. return "number" == typeof t ? [t, t, t] : 2 === t.length ? [t[0], t[1], 1] : t;
  11925. }(t),
  11926. n = e[0],
  11927. r = e[1],
  11928. o = e[2];
  11929. return 1 === n && 1 === r && 1 === o;
  11930. }
  11931. function Sc(t, e, n, r, o) {
  11932. g(t.length === e.rank, function () {
  11933. return "Length of inShape (" + t.length + ") and rank of dy (" + e.rank + ") must match";
  11934. });
  11935. var a = t,
  11936. i = e,
  11937. u = !1;
  11938. 4 === e.rank && (u = !0, i = e.as5D(1, e.shape[0], e.shape[1], e.shape[2], e.shape[3]), a = [1, t[0], t[1], t[2], t[3]]);
  11939. var s = a[4],
  11940. c = i.shape[4];
  11941. g(5 === a.length, function () {
  11942. return "Error in conv3dDerInput: inShape must be length 5, but got length " + a.length + ".";
  11943. }), g(5 === i.rank, function () {
  11944. return "Error in conv3dDerInput: dy must be rank 5, but got rank " + i.rank;
  11945. }), g(5 === n.rank, function () {
  11946. return "Error in conv3dDerInput: filter must be rank 5, but got rank " + n.rank;
  11947. }), g(s === n.shape[3], function () {
  11948. return "Error in conv3dDerInput: depth of input (" + s + ") must match input depth for filter " + n.shape[3] + ".";
  11949. }), g(c === n.shape[4], function () {
  11950. return "Error in conv3dDerInput: depth of output (" + c + ") must match output depth for filter " + n.shape[4] + ".";
  11951. });
  11952. var l = yo(a, n.shape, r, 1, o),
  11953. h = Nt.runKernelFunc(function (t) {
  11954. return t.conv3dDerInput(i, n, l);
  11955. }, {
  11956. dy5D: i
  11957. });
  11958. return u ? h.as4D(h.shape[1], h.shape[2], h.shape[3], h.shape[4]) : h;
  11959. }
  11960. var Ac = Cn({
  11961. conv1d_: function (t, e, n, r, o, a, i) {
  11962. void 0 === o && (o = "NWC"), void 0 === a && (a = 1);
  11963. var u = ln(t, "x", "conv1d"),
  11964. s = ln(e, "filter", "conv1d"),
  11965. c = u,
  11966. l = !1;
  11967. 2 === u.rank && (l = !0, c = u.as3D(1, u.shape[0], u.shape[1])), g(3 === c.rank, function () {
  11968. return "Error in conv1d: input must be rank 3, but got rank " + c.rank + ".";
  11969. }), g(3 === s.rank, function () {
  11970. return "Error in conv1d: filter must be rank 3, but got rank " + s.rank + ".";
  11971. }), null != i && g(E(r), function () {
  11972. return "Error in conv1d: pad must be an integer when using, dimRoundingMode " + i + " but got pad " + r + ".";
  11973. }), g(c.shape[2] === s.shape[1], function () {
  11974. return "Error in conv1d: depth of input (" + c.shape[2] + ") must match input depth for filter " + s.shape[1] + ".";
  11975. }), g(Io(n, a), function () {
  11976. return "Error in conv1D: Either stride or dilation must be 1. Got stride " + n + " and dilation '" + a + "'";
  11977. }), g("NWC" === o, function () {
  11978. return "Error in conv1d: got dataFormat of " + o + " but only NWC is currently supported.";
  11979. });
  11980. var h = s.as4D(1, s.shape[0], s.shape[1], s.shape[2]),
  11981. f = c.as4D(c.shape[0], 1, c.shape[1], c.shape[2]),
  11982. p = Dc(f, h, [1, n], r, "NHWC", [1, a], i);
  11983. return l ? p.as2D(p.shape[2], p.shape[3]) : p.as3D(p.shape[0], p.shape[2], p.shape[3]);
  11984. }
  11985. }),
  11986. Dc = Cn({
  11987. conv2d_: function (t, e, n, r, o, a, i) {
  11988. void 0 === o && (o = "NHWC"), void 0 === a && (a = [1, 1]);
  11989. var u = ln(t, "x", "conv2d"),
  11990. s = ln(e, "filter", "conv2d"),
  11991. c = u,
  11992. l = !1;
  11993. 3 === u.rank && (l = !0, c = u.as4D(1, u.shape[0], u.shape[1], u.shape[2])), g(4 === c.rank, function () {
  11994. return "Error in conv2d: input must be rank 4, but got rank " + c.rank + ".";
  11995. }), g(4 === s.rank, function () {
  11996. return "Error in conv2d: filter must be rank 4, but got rank " + s.rank + ".";
  11997. }), null != i && g(E(r), function () {
  11998. return "Error in conv2d: pad must be an integer when using, dimRoundingMode " + i + " but got pad " + r + ".";
  11999. });
  12000. var h = "NHWC" === o ? c.shape[3] : c.shape[1];
  12001. g(h === s.shape[2], function () {
  12002. return "Error in conv2d: depth of input (" + h + ") must match input depth for filter " + s.shape[2] + ".";
  12003. }), g(Io(n, a), function () {
  12004. return "Error in conv2D: Either strides or dilations must be 1. Got strides " + n + " and dilations '" + a + "'";
  12005. });
  12006. var f = ko(o),
  12007. p = go(c.shape, s.shape, n, a, r, i, !1, f),
  12008. d = Nt.runKernelFunc(function (t, e) {
  12009. var n = t.conv2d(c, s, p);
  12010. return e([s, c]), n;
  12011. }, {
  12012. x: c,
  12013. $filter: s
  12014. }, function (t, e) {
  12015. var i = e,
  12016. u = i[0],
  12017. s = i[1];
  12018. return g(Ro(a), function () {
  12019. return "Error in gradient of conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '" + a + "'";
  12020. }), {
  12021. x: function () {
  12022. return Fc(s.shape, t, u, n, r, o);
  12023. },
  12024. $filter: function () {
  12025. return Nc(s, t, u.shape, n, r, o);
  12026. }
  12027. };
  12028. });
  12029. return l ? d.as3D(d.shape[1], d.shape[2], d.shape[3]) : d;
  12030. }
  12031. }),
  12032. Tc = Cn({
  12033. conv3d_: function (t, e, n, r, o, a) {
  12034. void 0 === o && (o = "NDHWC"), void 0 === a && (a = [1, 1, 1]);
  12035. var i = ln(t, "x", "conv3d"),
  12036. u = ln(e, "filter", "conv3d"),
  12037. s = i,
  12038. c = !1;
  12039. 4 === i.rank && (c = !0, s = i.as5D(1, i.shape[0], i.shape[1], i.shape[2], i.shape[3])), g(5 === s.rank, function () {
  12040. return "Error in conv3d: input must be rank 5, but got rank " + s.rank + ".";
  12041. }), g(5 === u.rank, function () {
  12042. return "Error in conv3d: filter must be rank 5, but got rank " + u.rank + ".";
  12043. }), g(s.shape[4] === u.shape[3], function () {
  12044. return "Error in conv3d: depth of input (" + s.shape[4] + ") must match input depth for filter " + u.shape[3] + ".";
  12045. }), g(function (t, e) {
  12046. return kc(t) || kc(e);
  12047. }(n, a), function () {
  12048. return "Error in conv3D: Either strides or dilations must be 1. Got strides " + n + " and dilations '" + a + "'";
  12049. }), g("NDHWC" === o, function () {
  12050. return "Error in conv3d: got dataFormat of " + o + " but only NDHWC is currently supported.";
  12051. });
  12052. var l = yo(s.shape, u.shape, n, a, r),
  12053. h = Nt.runKernelFunc(function (t, e) {
  12054. var n = t.conv3d(s, u, l);
  12055. return e([s, u]), n;
  12056. }, {
  12057. x: s,
  12058. $filter: u
  12059. }, function (t, e) {
  12060. g(kc(a), function () {
  12061. return "Error in gradient of conv3D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '" + a + "'";
  12062. });
  12063. var o = e[0],
  12064. i = e[1];
  12065. return {
  12066. x: function () {
  12067. return Sc(o.shape, t, i, n, r);
  12068. },
  12069. $filter: function () {
  12070. return function (t, e, n, r, o) {
  12071. var a = t;
  12072. 4 === t.rank && (a = t.as5D(1, t.shape[0], t.shape[1], t.shape[2], t.shape[3]));
  12073. var i = e;
  12074. 4 === i.rank && (i = e.as5D(1, e.shape[0], e.shape[1], e.shape[2], e.shape[3])), g(5 === a.rank, function () {
  12075. return "Error in conv3dDerFilter: input must be rank 5, but got shape " + a.shape + ".";
  12076. }), g(5 === i.rank, function () {
  12077. return "Error in conv3dDerFilter: dy must be rank 5, but got shape " + i.shape + ".";
  12078. }), g(5 === n.length, function () {
  12079. return "Error in conv3dDerFilter: filterShape must be length 5, but got " + n + ".";
  12080. }), g(a.shape[4] === n[3], function () {
  12081. return "Error in conv3dDerFilter: depth of input " + a.shape[4] + ") must match input depth in filter (" + n[3] + ".";
  12082. }), g(i.shape[4] === n[4], function () {
  12083. return "Error in conv3dDerFilter: depth of dy (" + i.shape[4] + ") must match output depth for filter (" + n[4] + ").";
  12084. });
  12085. var u = yo(a.shape, n, r, 1, o);
  12086. return Nt.runKernelFunc(function (t) {
  12087. return t.conv3dDerFilter(a, i, u);
  12088. }, {
  12089. x5D: a,
  12090. dy5D: i
  12091. });
  12092. }(o, t, i.shape, n, r);
  12093. }
  12094. };
  12095. });
  12096. return c ? h.as4D(h.shape[1], h.shape[2], h.shape[3], h.shape[4]) : h;
  12097. }
  12098. }),
  12099. Nc = Cn({
  12100. conv2dDerFilter_: function (t, e, n, r, o, a, i) {
  12101. void 0 === a && (a = "NHWC");
  12102. var u = t;
  12103. 3 === t.rank && (u = t.as4D(1, t.shape[0], t.shape[1], t.shape[2]));
  12104. var s = e;
  12105. 3 === s.rank && (s = e.as4D(1, e.shape[0], e.shape[1], e.shape[2])), g(4 === u.rank, function () {
  12106. return "Error in conv2dDerFilter: input must be rank 4, but got shape " + u.shape + ".";
  12107. }), g(4 === s.rank, function () {
  12108. return "Error in conv2dDerFilter: dy must be rank 4, but got shape " + s.shape + ".";
  12109. }), g(4 === n.length, function () {
  12110. return "Error in conv2dDerFilter: filterShape must be length 4, but got " + n + ".";
  12111. });
  12112. var c = "NHWC" === a ? u.shape[3] : u.shape[1],
  12113. l = "NHWC" === a ? s.shape[3] : s.shape[1];
  12114. g(c === n[2], function () {
  12115. return "Error in conv2dDerFilter: depth of input " + c + ") must match input depth in filter (" + n[2] + ".";
  12116. }), g(l === n[3], function () {
  12117. return "Error in conv2dDerFilter: depth of dy (" + l + ") must match output depth for filter (" + n[3] + ").";
  12118. }), null != i && g(E(o), function () {
  12119. return "Error in conv2dDerFilter: pad must be an integer when using, dimRoundingMode " + i + " but got pad " + o + ".";
  12120. });
  12121. var h = ko(a),
  12122. f = go(u.shape, n, r, 1, o, i, !1, h);
  12123. return Nt.runKernelFunc(function (t) {
  12124. return t.conv2dDerFilter(u, s, f);
  12125. }, {
  12126. x4D: u,
  12127. dy4D: s
  12128. });
  12129. }
  12130. }),
  12131. Fc = Cn({
  12132. conv2dDerInput_: Ic
  12133. }),
  12134. Oc = Cn({
  12135. depthwiseConv2d_: function (t, e, n, r, o, a, i) {
  12136. void 0 === o && (o = "NHWC"), void 0 === a && (a = [1, 1]);
  12137. var u = ln(t, "x", "depthwiseConv2d"),
  12138. s = ln(e, "filter", "depthwiseConv2d"),
  12139. c = u,
  12140. l = !1;
  12141. 3 === u.rank && (l = !0, c = u.as4D(1, u.shape[0], u.shape[1], u.shape[2])), g(4 === c.rank, function () {
  12142. return "Error in depthwiseConv2d: input must be rank 4, but got rank " + c.rank + ".";
  12143. }), g(4 === s.rank, function () {
  12144. return "Error in depthwiseConv2d: filter must be rank 4, but got rank " + s.rank + ".";
  12145. }), g(c.shape[3] === s.shape[2], function () {
  12146. return "Error in depthwiseConv2d: number of input channels (" + c.shape[3] + ") must match the inChannels dimension in filter " + s.shape[2] + ".";
  12147. }), null == a && (a = [1, 1]), g(Io(n, a), function () {
  12148. return "Error in depthwiseConv2d: Either strides or dilations must be 1. Got strides " + n + " and dilations '" + a + "'";
  12149. }), null != i && g(E(r), function () {
  12150. return "Error in depthwiseConv2d: pad must be an integer when using, dimRoundingMode " + i + " but got pad " + r + ".";
  12151. });
  12152. var h = go(c.shape, s.shape, n, a, r, i, !0),
  12153. f = Nt.runKernelFunc(function (t, e) {
  12154. var n = t.depthwiseConv2D(c, s, h);
  12155. return e([c, s]), n;
  12156. }, {
  12157. x: c,
  12158. $filter: s
  12159. }, function (t, e) {
  12160. g(Ro(a), function () {
  12161. return "Error in gradient of depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '" + a + "'";
  12162. });
  12163. var n = e[0],
  12164. r = e[1];
  12165. return {
  12166. x: function () {
  12167. return _c(n.shape, t, r, h);
  12168. },
  12169. $filter: function () {
  12170. return Mc(n, t, r.shape, h);
  12171. }
  12172. };
  12173. });
  12174. return l ? f.as3D(f.shape[1], f.shape[2], f.shape[3]) : f;
  12175. }
  12176. }),
  12177. _c = Cn({
  12178. depthwiseConv2dDerInput_: function (t, e, n, r) {
  12179. var o = e,
  12180. a = !1;
  12181. 3 === e.rank && (a = !0, o = e.as4D(1, e.shape[0], e.shape[1], e.shape[2]));
  12182. var i = Nt.runKernelFunc(function (t) {
  12183. return t.depthwiseConv2DDerInput(o, n, r);
  12184. }, {
  12185. dy4D: o
  12186. });
  12187. return a ? i.as3D(i.shape[1], i.shape[2], i.shape[3]) : i;
  12188. }
  12189. }),
  12190. Mc = Cn({
  12191. depthwiseConv2dDerFilter_: function (t, e, n, r) {
  12192. var o = t;
  12193. 3 === t.rank && (o = t.as4D(1, t.shape[0], t.shape[1], t.shape[2]));
  12194. var a = e;
  12195. return 3 === a.rank && (a = e.as4D(1, e.shape[0], e.shape[1], e.shape[2])), Nt.runKernelFunc(function (t) {
  12196. return t.depthwiseConv2DDerFilter(o, a, r);
  12197. }, {
  12198. x4D: o,
  12199. dy4D: a
  12200. });
  12201. }
  12202. }),
  12203. Bc = Cn({
  12204. separableConv2d_: function (t, e, n, r, o, a, i) {
  12205. void 0 === a && (a = [1, 1]), void 0 === i && (i = "NHWC");
  12206. var u = ln(t, "x", "separableConv2d"),
  12207. s = ln(e, "depthwiseFilter", "separableConv2d"),
  12208. c = ln(n, "pointwiseFilter", "separableConv2d"),
  12209. l = u,
  12210. h = !1;
  12211. if (3 === u.rank && (h = !0, l = u.as4D(1, u.shape[0], u.shape[1], u.shape[2])), "NCHW" === i) throw new Error("separableConv2d currently does not support dataFormat NCHW; only NHWC is supported");
  12212. g(4 === l.rank, function () {
  12213. return "Error in separableConv2d: input must be rank 4, but got rank " + l.rank + ".";
  12214. }), g(4 === s.rank, function () {
  12215. return "Error in separableConv2d: depthwise filter must be rank 4, but got rank " + s.rank + ".";
  12216. }), g(4 === c.rank, function () {
  12217. return "Error in separableConv2d: pointwise filter must be rank 4, but got rank " + s.rank + ".";
  12218. }), g(1 === c.shape[0], function () {
  12219. return "Error in separableConv2d: the first dimension of pointwise filter must be 1, but got " + c.shape[0] + ".";
  12220. }), g(1 === c.shape[1], function () {
  12221. return "Error in separableConv2d: the second dimension of pointwise filter must be 1, but got " + c.shape[1] + ".";
  12222. });
  12223. var f = s.shape[2],
  12224. p = s.shape[3];
  12225. g(c.shape[2] === f * p, function () {
  12226. return "Error in separableConv2d: the third dimension of pointwise filter must be " + f * p + ", but got " + c.shape[2] + ".";
  12227. });
  12228. var d = Oc(l, s, r, o, i, a),
  12229. v = Dc(d, c, 1, "valid", i);
  12230. return h ? v.as3D(v.shape[1], v.shape[2], v.shape[3]) : v;
  12231. }
  12232. }),
  12233. Pc = Cn({
  12234. conv2dTranspose_: function (t, e, n, r, o, a) {
  12235. return Ic(n, ln(t, "x", "conv2dTranspose"), ln(e, "filter", "conv2dTranspose"), r, o, "NHWC", a);
  12236. }
  12237. }),
  12238. Lc = Cn({
  12239. conv3dTranspose_: function (t, e, n, r, o) {
  12240. return Sc(n, ln(t, "x", "conv3dTranspose"), ln(e, "filter", "conv3dTranspose"), r, o);
  12241. }
  12242. });
  12243. exports.conv3dTranspose = Lc;
  12244. exports.conv2dTranspose = Pc;
  12245. exports.separableConv2d = Bc;
  12246. exports.depthwiseConv2d = Oc;
  12247. exports.conv3d = Tc;
  12248. exports.conv2d = Dc;
  12249. exports.conv1d = Ac;
  12250. var Wc = Cn({
  12251. matMul_: function (t, e, n, r) {
  12252. var o;
  12253. void 0 === n && (n = !1), void 0 === r && (r = !1);
  12254. var a = ln(t, "a", "matMul"),
  12255. i = ln(e, "b", "matMul");
  12256. o = Rt(a, i), a = o[0], i = o[1];
  12257. var u = n ? a.shape[a.rank - 2] : a.shape[a.rank - 1],
  12258. s = r ? i.shape[i.rank - 1] : i.shape[i.rank - 2],
  12259. c = n ? a.shape[a.rank - 1] : a.shape[a.rank - 2],
  12260. l = r ? i.shape[i.rank - 2] : i.shape[i.rank - 1],
  12261. h = a.shape.slice(0, -2),
  12262. f = i.shape.slice(0, -2),
  12263. p = w(h),
  12264. d = w(f);
  12265. g(a.rank >= 2 && i.rank >= 2 && a.rank === i.rank, function () {
  12266. return "Error in matMul: inputs must have the same rank of at least 2, got ranks " + a.rank + " and " + i.rank + ".";
  12267. }), g(C(h, f), function () {
  12268. return "Error in matMul: outer dimensions (" + h + ") and (" + f + ") of Tensors with shapes " + a.shape + " and " + i.shape + " must match.";
  12269. }), g(u === s, function () {
  12270. return "Error in matMul: inner shapes (" + u + ") and (" + s + ") of Tensors with shapes " + a.shape + " and " + i.shape + " and transposeA=" + n + " and transposeB=" + r + " must match.";
  12271. });
  12272. var v = a.shape.slice(0, -2).concat([c, l]),
  12273. m = n ? a.as3D(p, u, c) : a.as3D(p, c, u),
  12274. y = r ? i.as3D(d, l, s) : i.as3D(d, s, l),
  12275. x = {
  12276. transposeA: n,
  12277. transposeB: r
  12278. };
  12279. return Nt.runKernelFunc(function (t, e) {
  12280. var o = t.batchMatMul(m, y, n, r);
  12281. return e([m, y]), o;
  12282. }, {
  12283. a: m,
  12284. b: y
  12285. }, function (t, e) {
  12286. var o = e,
  12287. a = o[0],
  12288. i = o[1];
  12289. return n || r ? !n && r ? {
  12290. a: function () {
  12291. return t.matMul(i, !1, !1);
  12292. },
  12293. b: function () {
  12294. return t.matMul(a, !0, !1);
  12295. }
  12296. } : n && !r ? {
  12297. a: function () {
  12298. return i.matMul(t, !1, !0);
  12299. },
  12300. b: function () {
  12301. return a.matMul(t, !1, !1);
  12302. }
  12303. } : {
  12304. a: function () {
  12305. return i.matMul(t, !0, !0);
  12306. },
  12307. b: function () {
  12308. return t.matMul(a, !0, !0);
  12309. }
  12310. } : {
  12311. a: function () {
  12312. return t.matMul(i, !1, !0);
  12313. },
  12314. b: function () {
  12315. return a.matMul(t, !0, !1);
  12316. }
  12317. };
  12318. }, "BatchMatMul", x).reshape(v);
  12319. }
  12320. }),
  12321. Uc = Cn({
  12322. dot_: function (t, e) {
  12323. var n = ln(t, "t1", "dot"),
  12324. r = ln(e, "t2", "dot");
  12325. g(!(1 !== n.rank && 2 !== n.rank || 1 !== r.rank && 2 !== r.rank), function () {
  12326. return "Error in dot: inputs must all be rank 1 or 2, but got ranks " + n.rank + " and " + r.rank + ".";
  12327. });
  12328. var o = 1 === n.rank ? n.size : n.shape[1],
  12329. a = 1 === r.rank ? r.size : r.shape[0];
  12330. return g(o === a, function () {
  12331. return "Error in dot: inner dimensions of inputs must match, but got " + o + " and " + a + ".";
  12332. }), 1 === n.rank && 1 === r.rank ? n.as2D(1, -1).matMul(r.as2D(-1, 1)).asScalar() : 1 === n.rank && 2 === r.rank ? n.as2D(1, -1).matMul(r.as2D(r.shape[0], r.shape[1])).as1D() : 2 === n.rank && 1 === r.rank ? n.matMul(r.as2D(-1, 1)).as1D() : n.matMul(r.as2D(r.shape[0], r.shape[1]));
  12333. }
  12334. }),
  12335. Vc = Cn({
  12336. outerProduct_: function (t, e) {
  12337. var n = ln(t, "v1", "outerProduct"),
  12338. r = ln(e, "v2", "outerProduct");
  12339. return g(1 === n.rank && 1 === r.rank, function () {
  12340. return "Error in outerProduct: inputs must be rank 1, but got ranks " + n.rank + " and " + r.rank + ".";
  12341. }), n.as2D(-1, 1).matMul(r.as2D(1, -1));
  12342. }
  12343. });
  12344. exports.outerProduct = Vc;
  12345. exports.dot = Uc;
  12346. exports.matMul = Wc;
  12347. var zc = Cn({
  12348. reverse_: function (t, e) {
  12349. var n = ln(t, "x", "reverse");
  12350. if (0 === n.rank) return n.clone();
  12351. var r = D(e, n.shape);
  12352. return Nt.runKernelFunc(function (t) {
  12353. return t.reverse(n, r);
  12354. }, {
  12355. $x: n
  12356. }, function (t) {
  12357. return {
  12358. $x: function () {
  12359. return t.reverse(r);
  12360. }
  12361. };
  12362. }).reshapeAs(n);
  12363. }
  12364. }),
  12365. Gc = Cn({
  12366. reverse1d_: function (t) {
  12367. var e = ln(t, "x", "reverse");
  12368. return g(1 === e.rank, function () {
  12369. return "Error in reverse1D: x must be rank 1 but got rank " + e.rank + ".";
  12370. }), zc(e, 0);
  12371. }
  12372. }),
  12373. Hc = Cn({
  12374. reverse2d_: function (t, e) {
  12375. var n = ln(t, "x", "reverse");
  12376. return g(2 === n.rank, function () {
  12377. return "Error in reverse2D: x must be rank 2 but got rank " + n.rank + ".";
  12378. }), zc(n, e);
  12379. }
  12380. }),
  12381. qc = Cn({
  12382. reverse3d_: function (t, e) {
  12383. var n = ln(t, "x", "reverse");
  12384. return g(3 === n.rank, function () {
  12385. return "Error in reverse3D: x must be rank 3 but got rank " + n.rank + ".";
  12386. }), zc(n, e);
  12387. }
  12388. }),
  12389. Kc = Cn({
  12390. reverse4d_: function (t, e) {
  12391. var n = ln(t, "x", "reverse");
  12392. return g(4 === n.rank, function () {
  12393. return "Error in reverse4D: x must be rank 4 but got rank " + n.rank + ".";
  12394. }), zc(n, e);
  12395. }
  12396. });
  12397. exports.reverse4d = Kc;
  12398. exports.reverse3d = qc;
  12399. exports.reverse2d = Hc;
  12400. exports.reverse1d = Gc;
  12401. exports.reverse = zc;
  12402. function jc(t, e, n, r, o, a) {
  12403. var i = ln(t, "x", "maxPool"),
  12404. u = i,
  12405. s = !1;
  12406. 3 === i.rank && (s = !0, u = i.as4D(1, i.shape[0], i.shape[1], i.shape[2])), null == r && (r = [1, 1]), g(4 === u.rank, function () {
  12407. return "Error in maxPool: input must be rank 4 but got rank " + u.rank + ".";
  12408. }), g(Io(n, r), function () {
  12409. return "Error in maxPool: Either strides or dilations must be 1. Got strides " + n + " and dilations '" + r + "'";
  12410. }), null != a && g(E(o), function () {
  12411. return "Error in maxPool: pad must be an integer when using, dimRoundingMode " + a + " but got pad " + o + ".";
  12412. });
  12413. var c = vo(u.shape, e, n, r, o, a),
  12414. l = Nt.runKernelFunc(function (t, e) {
  12415. var n = t.maxPool(u, c);
  12416. return e([u, n]), n;
  12417. }, {
  12418. x: u
  12419. }, function (t, a) {
  12420. var i = a[0],
  12421. u = a[1];
  12422. return {
  12423. x: function () {
  12424. return function (t, e, n, r, o, a, i, u) {
  12425. var s = ln(t, "dy", "maxPoolBackprop"),
  12426. c = ln(e, "input", "maxPoolBackprop"),
  12427. l = ln(n, "output", "maxPoolBackprop");
  12428. g(c.rank === s.rank, function () {
  12429. return "Rank of input (" + c.rank + ") does not match rank of dy (" + s.rank + ")";
  12430. }), null == a && (a = [1, 1]), g(Io(o, a), function () {
  12431. return "Error in maxPoolBackProp: Either strides or dilations must be 1. Got strides " + o + " and dilations '" + a + "'";
  12432. }), g(4 === s.rank, function () {
  12433. return "Error in maxPoolBackprop: dy must be rank 4 but got rank " + s.rank + ".";
  12434. }), g(4 === c.rank, function () {
  12435. return "Error in maxPoolBackprop: input must be rank 4 but got rank " + c.rank + ".";
  12436. }), null != u && g(E(i), function () {
  12437. return "Error in maxPoolBackprop: pad must be an integer when using, dimRoundingMode " + u + " but got pad " + i + ".";
  12438. });
  12439. var h = vo(c.shape, r, o, a, i, u);
  12440. return Nt.runKernelFunc(function (t) {
  12441. return t.maxPoolBackprop(s, c, l, h);
  12442. }, {
  12443. $dy: s,
  12444. $input: c
  12445. });
  12446. }(t, i, u, e, n, r, o);
  12447. }
  12448. };
  12449. });
  12450. return s ? l.as3D(l.shape[1], l.shape[2], l.shape[3]) : l;
  12451. }
  12452. function Xc(t, e, n, r, o, a) {
  12453. var i = ln(t, "x", "avgPool", "float32");
  12454. null == r && (r = [1, 1]), g(Io(n, r), function () {
  12455. return "Error in avgPool: Either strides or dilations must be 1. Got strides " + n + " and dilations '" + r + "'";
  12456. });
  12457. var u = i,
  12458. s = !1;
  12459. 3 === i.rank && (s = !0, u = i.as4D(1, i.shape[0], i.shape[1], i.shape[2])), g(4 === u.rank, function () {
  12460. return "Error in avgPool: x must be rank 4 but got rank " + u.rank + ".";
  12461. }), null != a && g(E(o), function () {
  12462. return "Error in avgPool: pad must be an integer when using, dimRoundingMode " + a + " but got pad " + o + ".";
  12463. });
  12464. var c = vo(u.shape, e, n, r, o, a),
  12465. l = Nt.runKernelFunc(function (t) {
  12466. return t.avgPool(u, c);
  12467. }, {
  12468. x: u
  12469. }, function (t) {
  12470. return {
  12471. x: function () {
  12472. return function (t, e, n, r, o, a) {
  12473. var i = ln(t, "dy", "avgPoolBackprop"),
  12474. u = ln(e, "input", "avgPoolBackprop");
  12475. g(u.rank === i.rank, function () {
  12476. return "Rank of input (" + u.rank + ") does not match rank of dy (" + i.rank + ")";
  12477. }), null == o && (o = [1, 1]), g(Io(r, o), function () {
  12478. return "Error in avgPoolBackprop: Either strides or dilations must be 1. Got strides " + r + " and dilations '" + o + "'";
  12479. });
  12480. var s = u,
  12481. c = i,
  12482. l = !1;
  12483. 3 === u.rank && (l = !0, s = u.as4D(1, u.shape[0], u.shape[1], u.shape[2]), c = i.as4D(1, i.shape[0], i.shape[1], i.shape[2])), g(4 === c.rank, function () {
  12484. return "Error in avgPoolBackprop: dy must be rank 4 but got rank " + c.rank + ".";
  12485. }), g(4 === s.rank, function () {
  12486. return "Error in avgPoolBackprop: input must be rank 4 but got rank " + s.rank + ".";
  12487. });
  12488. var h = vo(s.shape, n, r, o, a),
  12489. f = Nt.runKernelFunc(function (t) {
  12490. return t.avgPoolBackprop(c, s, h);
  12491. }, {
  12492. dy4D: c,
  12493. input4D: s
  12494. });
  12495. return l ? f.as3D(f.shape[1], f.shape[2], f.shape[3]) : f;
  12496. }(t, u, e, n, r, o);
  12497. }
  12498. };
  12499. });
  12500. return l = l.cast(i.dtype), s ? l.as3D(l.shape[1], l.shape[2], l.shape[3]) : l;
  12501. }
  12502. var $c = Cn({
  12503. maxPool_: function (t, e, n, r, o) {
  12504. return jc(t, e, n, 1, r, o);
  12505. }
  12506. }),
  12507. Yc = Cn({
  12508. avgPool_: function (t, e, n, r, o) {
  12509. return Xc(t, e, n, 1, r, o);
  12510. }
  12511. }),
  12512. Qc = Cn({
  12513. pool_: function (t, e, n, r, o, a) {
  12514. null == o && (o = [1, 1]), null == a && (a = 1), 0 === r && (r = "valid");
  12515. var i = ln(t, "x", "maxPool"),
  12516. u = i,
  12517. s = !1;
  12518. 3 === i.rank && (s = !0, u = i.as4D(1, i.shape[0], i.shape[1], i.shape[2])), g(Io(a, o), function () {
  12519. return "Error in pool: Either strides or dilations must be 1. Got strides " + a + " and dilations '" + o + "'";
  12520. });
  12521. var c,
  12522. l = vo(u.shape, e, a, o, r),
  12523. h = [l.dilationHeight, l.dilationWidth];
  12524. c = "same" === r ? function (t, e) {
  12525. var n = t.map(function (t, n) {
  12526. return t + (t - 1) * (e[n] - 1);
  12527. }).map(function (t) {
  12528. return t - 1;
  12529. }),
  12530. r = n.map(function (t) {
  12531. return Math.floor(t / 2);
  12532. }),
  12533. o = n.map(function (t, e) {
  12534. return t - r[e];
  12535. });
  12536. return n.map(function (t, e) {
  12537. return [r[e], o[e]];
  12538. });
  12539. }([l.filterHeight, l.filterWidth], h) : [[0, 0], [0, 0]];
  12540. var f = 1 === h[0] && 1 === h[1],
  12541. p = function (t, e, n) {
  12542. var r = n.map(function (t) {
  12543. return t[0];
  12544. }),
  12545. o = n.map(function (t) {
  12546. return t[1];
  12547. }),
  12548. a = t.concat(r, o),
  12549. i = e.map(function (t, e) {
  12550. return (t - a[e] % t) % t;
  12551. }),
  12552. u = o.map(function (t, e) {
  12553. return t + i[e];
  12554. }),
  12555. s = e.map(function (t, e) {
  12556. return [r[e], u[e]];
  12557. }),
  12558. c = e.map(function (t, e) {
  12559. return [0, i[e]];
  12560. });
  12561. return [s, c];
  12562. }([l.inHeight, l.inWidth], h, c),
  12563. d = p[0],
  12564. v = p[1],
  12565. m = f ? r : "valid",
  12566. y = f ? u : Ar(u, h, d),
  12567. x = ("avg" === n ? function () {
  12568. return Xc(y, e, a, 1, m);
  12569. } : function () {
  12570. return jc(y, e, a, 1, m);
  12571. })(),
  12572. b = f ? x : cr(x, h, v);
  12573. return s ? b.as3D(b.shape[1], b.shape[2], b.shape[3]) : b;
  12574. }
  12575. }),
  12576. Jc = Cn({
  12577. maxPool3d_: function (t, e, n, r, o, a, i) {
  12578. void 0 === a && (a = "NDHWC");
  12579. var u = ln(t, "x", "maxPool3d"),
  12580. s = u,
  12581. c = !1;
  12582. 4 === u.rank && (c = !0, s = u.as5D(1, u.shape[0], u.shape[1], u.shape[2], u.shape[3])), null == i && (i = [1, 1, 1]), g(5 === s.rank, function () {
  12583. return "Error in maxPool3d: x must be rank 5 but got rank " + s.rank + ".";
  12584. }), g("NDHWC" === a, function () {
  12585. return "Error in maxPool3d: Only NDHWC is currently supported, but got dataFormat of " + a;
  12586. }), g(Io(n, i), function () {
  12587. return "Error in maxPool3d: Either strides or dilations must be 1. Got strides " + n + " and dilations '" + i + "'";
  12588. }), null != o && g(E(r), function () {
  12589. return "Error in maxPool3d: pad must be an integer when using, dimRoundingMode " + o + " but got pad " + r + ".";
  12590. });
  12591. var l = mo(s.shape, e, n, i, r, o, a),
  12592. h = Nt.runKernelFunc(function (t, e) {
  12593. var n = t.maxPool3d(s, l);
  12594. return e([s, n]), n;
  12595. }, {
  12596. x: s
  12597. }, function (t, a) {
  12598. var u = a[0],
  12599. s = a[1];
  12600. return {
  12601. x: function () {
  12602. return function (t, e, n, r, o, a, i, u) {
  12603. var s = ln(t, "dy", "maxPool3dBackprop"),
  12604. c = ln(e, "input", "maxPool3dBackprop"),
  12605. l = ln(n, "output", "maxPool3dBackprop"),
  12606. h = s,
  12607. f = c,
  12608. p = l,
  12609. d = !1;
  12610. 4 === c.rank && (d = !0, h = s.as5D(1, s.shape[0], s.shape[1], s.shape[2], s.shape[3]), f = c.as5D(1, c.shape[0], c.shape[1], c.shape[2], c.shape[3]), p = l.as5D(1, l.shape[0], l.shape[1], l.shape[2], l.shape[3])), g(5 === h.rank, function () {
  12611. return "Error in maxPool3dBackprop: dy must be rank 5 but got rank " + h.rank + ".";
  12612. }), g(5 === f.rank, function () {
  12613. return "Error in maxPool3dBackprop: input must be rank 5 but got rank " + f.rank + ".";
  12614. }), g(5 === p.rank, function () {
  12615. return "Error in maxPool3dBackprop: output must be rank 5 but got rank " + p.rank + ".";
  12616. }), null == a && (a = [1, 1, 1]), g(Io(o, a), function () {
  12617. return "Error in maxPool3dBackprop: Either strides or dilations must be 1. Got strides " + o + " and dilations '" + a + "'";
  12618. }), null != u && g(E(i), function () {
  12619. return "Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode " + u + " but got pad " + i + ".";
  12620. });
  12621. var v = mo(f.shape, r, o, a, i, u),
  12622. m = Nt.runKernelFunc(function (t) {
  12623. return t.maxPool3dBackprop(h, f, p, v);
  12624. }, {
  12625. dy5D: h,
  12626. input5D: f
  12627. });
  12628. return d ? m.as4D(m.shape[1], m.shape[2], m.shape[3], m.shape[4]) : m;
  12629. }(t, u, s, e, n, i, r, o);
  12630. }
  12631. };
  12632. });
  12633. return c ? h.as4D(h.shape[1], h.shape[2], h.shape[3], h.shape[4]) : h;
  12634. }
  12635. }),
  12636. Zc = Cn({
  12637. avgPool3d_: function (t, e, n, r, o, a, i) {
  12638. void 0 === a && (a = "NDHWC");
  12639. var u = ln(t, "x", "avgPool3d", "float32"),
  12640. s = u,
  12641. c = !1;
  12642. 4 === u.rank && (c = !0, s = u.as5D(1, u.shape[0], u.shape[1], u.shape[2], u.shape[3])), null == i && (i = [1, 1, 1]), g(5 === s.rank, function () {
  12643. return "Error in avgPool3d: x must be rank 5 but got rank " + s.rank + ".";
  12644. }), g("NDHWC" === a, function () {
  12645. return "Error in avgPool3d: Only NDHWC is currently supported, but got dataFormat of " + a;
  12646. }), g(Io(n, i), function () {
  12647. return "Error in avgPool3d: Either strides or dilations must be 1. Got strides " + n + " and dilations '" + i + "'";
  12648. }), null != o && g(E(r), function () {
  12649. return "Error in avgPool3d: pad must be an integer when using, dimRoundingMode " + o + " but got pad " + r + ".";
  12650. });
  12651. var l = mo(s.shape, e, n, i, r, o, a),
  12652. h = Nt.runKernelFunc(function (t) {
  12653. return t.avgPool3d(s, l);
  12654. }, {
  12655. x: s
  12656. }, function (t) {
  12657. return {
  12658. x: function () {
  12659. return function (t, e, n, r, o, a, i) {
  12660. var u = ln(t, "dy", "avgPool3dBackprop"),
  12661. s = ln(e, "input", "avgPool3dBackprop"),
  12662. c = u,
  12663. l = s,
  12664. h = !1;
  12665. 4 === s.rank && (h = !0, c = u.as5D(1, u.shape[0], u.shape[1], u.shape[2], u.shape[3]), l = s.as5D(1, s.shape[0], s.shape[1], s.shape[2], s.shape[3])), g(5 === c.rank, function () {
  12666. return "Error in avgPool3dBackprop: dy must be rank 5 but got rank " + c.rank + ".";
  12667. }), g(5 === l.rank, function () {
  12668. return "Error in avgPool3dBackprop: input must be rank 5 but got rank " + l.rank + ".";
  12669. }), null == o && (o = [1, 1, 1]), g(Io(r, o), function () {
  12670. return "Error in avgPool3dBackprop: Either strides or dilations must be 1. Got strides " + r + " and dilations '" + o + "'";
  12671. }), null != i && g(E(a), function () {
  12672. return "Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode " + i + " but got pad " + a + ".";
  12673. });
  12674. var f = mo(l.shape, n, r, o, a, i),
  12675. p = Nt.runKernelFunc(function (t) {
  12676. return t.avgPool3dBackprop(c, l, f);
  12677. }, {
  12678. dy5D: c,
  12679. input5D: l
  12680. });
  12681. return h ? p.as4D(p.shape[1], p.shape[2], p.shape[3], p.shape[4]) : p;
  12682. }(t, s, e, n, i, r, o);
  12683. }
  12684. };
  12685. });
  12686. return h = h.cast(s.dtype), c ? h.as4D(h.shape[1], h.shape[2], h.shape[3], h.shape[4]) : h;
  12687. }
  12688. });
  12689. exports.avgPool3d = Zc;
  12690. exports.maxPool3d = Jc;
  12691. exports.pool = Qc;
  12692. exports.avgPool = Yc;
  12693. exports.maxPool = $c;
  12694. var tl = Cn({
  12695. slice_: function (t, e, n) {
  12696. var r,
  12697. o,
  12698. a = ln(t, "x", "slice");
  12699. if (0 === a.rank) throw new Error("Slicing scalar is not possible");
  12700. (r = "number" == typeof e ? [e].concat(new Array(a.rank - 1).fill(0)) : e.length < a.rank ? e.concat(new Array(a.rank - e.length).fill(0)) : e.slice()).forEach(function (t) {
  12701. g(-1 !== t, function () {
  12702. return "slice() does not support negative begin indexing.";
  12703. });
  12704. }), o = (o = null == n ? new Array(a.rank).fill(-1) : "number" == typeof n ? [n].concat(new Array(a.rank - 1).fill(-1)) : n.length < a.rank ? n.concat(new Array(a.rank - n.length).fill(-1)) : n).map(function (t, e) {
  12705. return t >= 0 ? t : (g(-1 === t, function () {
  12706. return "Negative size values should be exactly -1 but got " + t + " for the slice() size at index " + e + ".";
  12707. }), a.shape[e] - r[e]);
  12708. }), qr(a, r, o);
  12709. var i = a.shape,
  12710. u = {
  12711. begin: r,
  12712. size: o
  12713. };
  12714. return Nt.runKernelFunc(function (t) {
  12715. return t.slice(a, r, o);
  12716. }, {
  12717. x: a
  12718. }, function (t) {
  12719. for (var e = [], n = 0; n < t.rank; n++) e.push([r[n], i[n] - r[n] - o[n]]);
  12720. return {
  12721. x: function () {
  12722. return t.pad(e);
  12723. }
  12724. };
  12725. }, "Slice", u);
  12726. }
  12727. }),
  12728. el = Cn({
  12729. slice1d_: function (t, e, n) {
  12730. var r = ln(t, "x", "slice1d");
  12731. return g(1 === r.rank, function () {
  12732. return "slice1d expects a rank-1 tensor, but got a rank-" + r.rank + " tensor";
  12733. }), tl(r, [e], [n]);
  12734. }
  12735. }),
  12736. nl = Cn({
  12737. slice2d_: function (t, e, n) {
  12738. var r = ln(t, "x", "slice2d");
  12739. return g(2 === r.rank, function () {
  12740. return "slice2d expects a rank-2 tensor, but got a rank-" + r.rank + " tensor";
  12741. }), tl(r, e, n);
  12742. }
  12743. }),
  12744. rl = Cn({
  12745. slice3d_: function (t, e, n) {
  12746. var r = ln(t, "x", "slice3d");
  12747. return g(3 === r.rank, function () {
  12748. return "slice3d expects a rank-3 tensor, but got a rank-" + r.rank + " tensor";
  12749. }), tl(r, e, n);
  12750. }
  12751. }),
  12752. ol = Cn({
  12753. slice4d_: function (t, e, n) {
  12754. var r = ln(t, "x", "slice4d");
  12755. return g(4 === r.rank, function () {
  12756. return "slice4d expects a rank-4 tensor, but got a rank-" + r.rank + " tensor";
  12757. }), tl(r, e, n);
  12758. }
  12759. });
  12760. exports.slice4d = ol;
  12761. exports.slice3d = rl;
  12762. exports.slice2d = nl;
  12763. exports.slice1d = el;
  12764. exports.slice = tl;
  12765. function al(t, e, n, r, o) {
  12766. return e.rank < n.rank && (e = e.reshape(vn(e.shape, r))), t.rank < n.rank && (t = t.reshape(vn(t.shape, r))), {
  12767. $x: function () {
  12768. var r = t.mul(n.equal(e).cast(t.dtype));
  12769. return null == o ? r : r.transpose(o);
  12770. }
  12771. };
  12772. }
  12773. var il = Cn({
  12774. all_: function (t, e, n) {
  12775. void 0 === e && (e = null), void 0 === n && (n = !1);
  12776. var r = ln(t, "x", "all", "bool"),
  12777. o = D(e, r.shape),
  12778. a = o,
  12779. i = gn(a, r.rank);
  12780. null != i && (r = r.transpose(i), a = xn(a.length, r.rank));
  12781. var u = Nt.runKernelFunc(function (t) {
  12782. return t.all(r, a);
  12783. }, {
  12784. $x: r
  12785. });
  12786. if (n) {
  12787. var s = vn(u.shape, o);
  12788. return u.reshape(s);
  12789. }
  12790. return u;
  12791. }
  12792. }),
  12793. ul = Cn({
  12794. any_: function (t, e, n) {
  12795. void 0 === e && (e = null), void 0 === n && (n = !1);
  12796. var r = ln(t, "x", "any", "bool"),
  12797. o = D(e, r.shape),
  12798. a = o,
  12799. i = gn(a, r.rank);
  12800. null != i && (r = r.transpose(i), a = xn(a.length, r.rank));
  12801. var u = Nt.runKernelFunc(function (t) {
  12802. return t.any(r, a);
  12803. }, {
  12804. $x: r
  12805. });
  12806. if (n) {
  12807. var s = vn(u.shape, o);
  12808. return u.reshape(s);
  12809. }
  12810. return u;
  12811. }
  12812. }),
  12813. sl = Cn({
  12814. argMax_: function (t, e) {
  12815. void 0 === e && (e = 0);
  12816. var n = ln(t, "x", "argMax");
  12817. null == e && (e = 0);
  12818. var r = D(e, n.shape),
  12819. o = gn(r, n.rank);
  12820. return null != o && (n = n.transpose(o), r = xn(r.length, n.rank)), Nt.runKernelFunc(function (t, e) {
  12821. var o = t.argMax(n, r[0]);
  12822. return e([n]), o;
  12823. }, {
  12824. $x: n
  12825. }, function (t, e) {
  12826. var n = e[0];
  12827. return {
  12828. $x: function () {
  12829. return zn(n);
  12830. }
  12831. };
  12832. });
  12833. }
  12834. }),
  12835. cl = Cn({
  12836. argMin_: function (t, e) {
  12837. void 0 === e && (e = 0);
  12838. var n = ln(t, "x", "argMin");
  12839. null == e && (e = 0);
  12840. var r = D(e, n.shape),
  12841. o = gn(r, n.rank);
  12842. return null != o && (n = n.transpose(o), r = xn(r.length, n.rank)), Nt.runKernelFunc(function (t, e) {
  12843. var o = t.argMin(n, r[0]);
  12844. return e([n]), o;
  12845. }, {
  12846. $x: n
  12847. }, function (t, e) {
  12848. var n = e[0];
  12849. return {
  12850. $x: function () {
  12851. return zn(n);
  12852. }
  12853. };
  12854. });
  12855. }
  12856. }),
  12857. ll = Cn({
  12858. logSumExp_: function (t, e, n) {
  12859. void 0 === e && (e = null), void 0 === n && (n = !1);
  12860. var r = ln(t, "x", "logSumExp"),
  12861. o = D(e, r.shape),
  12862. a = r.max(o, !0),
  12863. i = r.sub(a).exp().sum(o).log(),
  12864. u = a.reshape(i.shape).add(i);
  12865. if (n) {
  12866. var s = vn(u.shape, o);
  12867. return u.reshape(s);
  12868. }
  12869. return u;
  12870. }
  12871. }),
  12872. hl = Cn({
  12873. max_: function (t, e, n) {
  12874. void 0 === e && (e = null), void 0 === n && (n = !1);
  12875. var r = ln(t, "x", "max"),
  12876. o = r,
  12877. a = D(e, r.shape),
  12878. i = a,
  12879. u = gn(i, r.rank);
  12880. null != u && (r = r.transpose(u), i = xn(i.length, r.rank));
  12881. var s = Nt.runKernelFunc(function (t, e) {
  12882. var n = t.max(r, i);
  12883. return e([o, n]), n;
  12884. }, {
  12885. $x: r
  12886. }, function (t, e) {
  12887. return al(t, e[1], e[0], a, u);
  12888. });
  12889. if (n) {
  12890. var c = vn(s.shape, a);
  12891. s = s.reshape(c);
  12892. }
  12893. return s;
  12894. }
  12895. }),
  12896. fl = Cn({
  12897. mean_: function (t, e, n) {
  12898. void 0 === e && (e = null), void 0 === n && (n = !1);
  12899. var r = ln(t, "x", "mean"),
  12900. o = D(e, r.shape),
  12901. a = w(dn(r.shape, o)[1]);
  12902. return oo(function (t) {
  12903. var r = An(a);
  12904. return {
  12905. value: (r.dtype === t.dtype ? t : t.cast(r.dtype)).div(r).sum(e, n),
  12906. gradFunc: function (e) {
  12907. var n = t.shape.slice();
  12908. return o.forEach(function (t) {
  12909. n[t] = 1;
  12910. }), e.reshape(n).mul(Bn(t.shape, "float32")).div(a);
  12911. }
  12912. };
  12913. })(r);
  12914. }
  12915. }),
  12916. pl = Cn({
  12917. min_: function (t, e, n) {
  12918. void 0 === e && (e = null), void 0 === n && (n = !1);
  12919. var r = ln(t, "x", "min"),
  12920. o = r,
  12921. a = D(e, r.shape),
  12922. i = a,
  12923. u = gn(i, r.rank);
  12924. null != u && (r = r.transpose(u), i = xn(i.length, r.rank));
  12925. var s = Nt.runKernelFunc(function (t, e) {
  12926. var n = t.min(r, i);
  12927. return e([o, n]), n;
  12928. }, {
  12929. $x: r
  12930. }, function (t, e) {
  12931. return al(t, e[1], e[0], a, u);
  12932. });
  12933. if (n) {
  12934. var c = vn(s.shape, a);
  12935. s = s.reshape(c);
  12936. }
  12937. return s;
  12938. }
  12939. }),
  12940. dl = Cn({
  12941. moments_: function (t, e, n) {
  12942. void 0 === e && (e = null), void 0 === n && (n = !1);
  12943. var r = D(e, (t = ln(t, "x", "moments")).shape),
  12944. o = t.mean(r, n),
  12945. a = o.shape;
  12946. n || (a = vn(o.shape, r));
  12947. var i = t.toFloat().sub(o.reshape(a)).square();
  12948. return {
  12949. mean: o,
  12950. variance: i.mean(r, n)
  12951. };
  12952. }
  12953. }),
  12954. vl = Cn({
  12955. sum_: function (t, e, n) {
  12956. void 0 === e && (e = null), void 0 === n && (n = !1);
  12957. var r = ln(t, "x", "sum");
  12958. "bool" === r.dtype && (r = r.toInt());
  12959. var o = D(e, r.shape);
  12960. return oo(function (t) {
  12961. var e = gn(o, t.rank),
  12962. r = o,
  12963. a = t;
  12964. null != e && (a = t.transpose(e), r = xn(r.length, t.rank));
  12965. var i = Nt.runKernelFunc(function (t) {
  12966. return t.sum(a, r);
  12967. }, {
  12968. permutedX: a
  12969. });
  12970. if (n) {
  12971. var u = vn(i.shape, o);
  12972. i = i.reshape(u);
  12973. }
  12974. return {
  12975. value: i,
  12976. gradFunc: function (e) {
  12977. var n = t.shape.slice();
  12978. return o.forEach(function (t) {
  12979. n[t] = 1;
  12980. }), e.reshape(n).mul(Bn(t.shape, "float32"));
  12981. }
  12982. };
  12983. })(r);
  12984. }
  12985. }),
  12986. ml = Cn({
  12987. prod_: function (t, e, n) {
  12988. void 0 === e && (e = null), void 0 === n && (n = !1);
  12989. var r = ln(t, "x", "prod");
  12990. "bool" === r.dtype && (r = r.toInt());
  12991. var o = D(e, r.shape),
  12992. a = gn(o, r.rank),
  12993. i = o,
  12994. u = r;
  12995. null != a && (u = r.transpose(a), i = xn(i.length, r.rank));
  12996. var s = Nt.runKernelFunc(function (t) {
  12997. return t.prod(u, i);
  12998. }, {
  12999. permutedX: u
  13000. });
  13001. if (n) {
  13002. var c = vn(s.shape, o);
  13003. s = s.reshape(c);
  13004. }
  13005. return s;
  13006. }
  13007. });
  13008. exports.prod = ml;
  13009. exports.sum = vl;
  13010. exports.moments = dl;
  13011. exports.min = pl;
  13012. exports.mean = fl;
  13013. exports.max = hl;
  13014. exports.logSumExp = ll;
  13015. exports.argMin = cl;
  13016. exports.argMax = sl;
  13017. exports.any = ul;
  13018. exports.all = il;
  13019. var gl = Cn({
  13020. elu_: function (t) {
  13021. var e = ln(t, "x", "elu");
  13022. return Nt.runKernelFunc(function (t, n) {
  13023. var r = t.elu(e);
  13024. return n([r]), r;
  13025. }, {
  13026. $x: e
  13027. }, function (t, e) {
  13028. var n = e[0];
  13029. return {
  13030. $x: function () {
  13031. return Nt.runKernelFunc(function (e) {
  13032. return e.eluDer(t, n);
  13033. }, {
  13034. dy: t,
  13035. y: n
  13036. });
  13037. }
  13038. };
  13039. });
  13040. }
  13041. }),
  13042. yl = Cn({
  13043. leakyRelu_: function (t, e) {
  13044. void 0 === e && (e = .2);
  13045. var n = ln(t, "x", "leakyRelu");
  13046. return Xs(An(e).mul(n), n);
  13047. }
  13048. }),
  13049. xl = Cn({
  13050. prelu_: function (t, e) {
  13051. var n = ln(t, "x", "prelu"),
  13052. r = ln(e, "alpha", "prelu");
  13053. return Nt.runKernelFunc(function (t, e) {
  13054. var o = t.prelu(n, r);
  13055. return e([n, r]), o;
  13056. }, {
  13057. x: n,
  13058. alpha: r
  13059. }, function (t, e) {
  13060. var n = e[0],
  13061. r = e[1],
  13062. o = n.greater(0);
  13063. return {
  13064. x: function () {
  13065. return Ws(o, t, t.mul(r));
  13066. },
  13067. alpha: function () {
  13068. var e = Ws(o, zn(t), t.mul(n)),
  13069. a = fo(r.shape, t.shape);
  13070. return a.length > 0 && (e = e.sum(a)), e.reshape(r.shape);
  13071. }
  13072. };
  13073. }, "Prelu");
  13074. }
  13075. }),
  13076. bl = Cn({
  13077. relu_: function (t) {
  13078. var e = ln(t, "x", "relu");
  13079. return "bool" === e.dtype ? e.toInt() : Nt.runKernelFunc(function (t, n) {
  13080. var r = t.relu(e);
  13081. return n([e]), r;
  13082. }, {
  13083. $x: e
  13084. }, function (t, e) {
  13085. var n = e[0];
  13086. return {
  13087. $x: function () {
  13088. return t.mulStrict(n.step().toFloat());
  13089. }
  13090. };
  13091. });
  13092. }
  13093. }),
  13094. wl = Cn({
  13095. relu6_: function (t) {
  13096. var e = ln(t, "x", "relu6");
  13097. return "bool" === e.dtype ? e.toInt() : Nt.runKernelFunc(function (t, n) {
  13098. var r = t.relu6(e);
  13099. return n([e]), r;
  13100. }, {
  13101. $x: e
  13102. }, function (t, e) {
  13103. var n = e[0],
  13104. r = n.lessEqual(6).mul(n.step());
  13105. return {
  13106. $x: function () {
  13107. return t.mulStrict(r.toFloat());
  13108. }
  13109. };
  13110. });
  13111. }
  13112. }),
  13113. Cl = Cn({
  13114. selu_: function (t) {
  13115. var e = ln(t, "x", "selu");
  13116. return Nt.runKernelFunc(function (t, n) {
  13117. var r = t.selu(e);
  13118. return n([e]), r;
  13119. }, {
  13120. $x: e
  13121. }, function (t, e) {
  13122. var n = e[0];
  13123. return {
  13124. $x: function () {
  13125. var e = n.greater(An(0)),
  13126. r = An(iu),
  13127. o = An(uu),
  13128. a = t.mul(o),
  13129. i = t.mul(r).mul(n.toFloat().exp());
  13130. return Ws(e, a, i);
  13131. }
  13132. };
  13133. });
  13134. }
  13135. });
  13136. exports.selu = Cl;
  13137. exports.relu6 = wl;
  13138. exports.relu = bl;
  13139. exports.prelu = xl;
  13140. exports.leakyRelu = yl;
  13141. exports.elu = gl;
  13142. var El = Cn({
  13143. transpose_: function (t, e) {
  13144. var n = ln(t, "x", "transpose");
  13145. return null == e && (e = n.shape.map(function (t, e) {
  13146. return e;
  13147. }).reverse()), g(n.rank === e.length, function () {
  13148. return "Error in transpose: rank of input " + n.rank + " must match length of perm " + e + ".";
  13149. }), e.forEach(function (t) {
  13150. g(t >= 0 && t < n.rank, function () {
  13151. return "All entries in 'perm' must be between 0 and " + (n.rank - 1) + " but got " + e;
  13152. });
  13153. }), n.rank <= 1 ? n.clone() : Nt.runKernelFunc(function (t) {
  13154. return t.transpose(n, e);
  13155. }, {
  13156. $x: n
  13157. }, function (t) {
  13158. var n = yn(e);
  13159. return {
  13160. $x: function () {
  13161. return t.transpose(n);
  13162. }
  13163. };
  13164. });
  13165. }
  13166. });
  13167. exports.transpose = El;
  13168. var Rl = Cn({
  13169. localResponseNormalization_: function (t, e, n, r, o) {
  13170. void 0 === e && (e = 5), void 0 === n && (n = 1), void 0 === r && (r = 1), void 0 === o && (o = .5);
  13171. var a = ln(t, "x", "localResponseNormalization");
  13172. g(4 === a.rank || 3 === a.rank, function () {
  13173. return "Error in localResponseNormalization: x must be rank 3 or 4 but got\n rank " + a.rank + ".";
  13174. }), g(E(e), function () {
  13175. return "Error in localResponseNormalization: depthRadius must be an integer but got depthRadius " + e + ".";
  13176. });
  13177. var i = a,
  13178. u = !1;
  13179. 3 === a.rank && (u = !0, i = a.as4D(1, a.shape[0], a.shape[1], a.shape[2]));
  13180. var s = Nt.runKernelFunc(function (t, a) {
  13181. var u = t.localResponseNormalization4D(i, e, n, r, o);
  13182. return a([i, u]), u;
  13183. }, {
  13184. x4D: i
  13185. }, function (t, a) {
  13186. var i = a[0],
  13187. u = a[1];
  13188. return {
  13189. x4D: function () {
  13190. return Nt.runKernelFunc(function (a) {
  13191. return a.LRNGrad(t, i, u, e, n, r, o);
  13192. }, {});
  13193. }
  13194. };
  13195. });
  13196. return u ? s.as3D(s.shape[1], s.shape[2], s.shape[3]) : s;
  13197. }
  13198. });
  13199. exports.localResponseNormalization = Rl;
  13200. var Il = Cn({
  13201. norm_: function (t, e, n, r) {
  13202. void 0 === e && (e = "euclidean"), void 0 === n && (n = null), void 0 === r && (r = !1);
  13203. var o = function t(e, n, r) {
  13204. if (void 0 === r && (r = null), 0 === e.rank) return e.abs();
  13205. if (1 !== e.rank && null === r) return t(e.reshape([-1]), n, r);
  13206. if (1 === e.rank || "number" == typeof r || Array.isArray(r) && 1 === r.length) {
  13207. if (1 === n) return e.abs().sum(r);
  13208. if (n === 1 / 0) return e.abs().max(r);
  13209. if (n === -1 / 0) return e.abs().min(r);
  13210. if ("euclidean" === n || 2 === n) return e.abs().pow(An(2, "int32")).sum(r).sqrt();
  13211. throw new Error("Error in norm: invalid ord value: " + n);
  13212. }
  13213. if (Array.isArray(r) && 2 === r.length) {
  13214. if (1 === n) return e.abs().sum(r[0]).max(r[1] - 1);
  13215. if (n === 1 / 0) return e.abs().sum(r[1]).max(r[0]);
  13216. if (n === -1 / 0) return e.abs().sum(r[1]).min(r[0]);
  13217. if ("fro" === n || "euclidean" === n) return e.square().sum(r).sqrt();
  13218. throw new Error("Error in norm: invalid ord value: " + n);
  13219. }
  13220. throw new Error("Error in norm: invalid axis: " + r);
  13221. }(t = ln(t, "x", "norm"), e, n),
  13222. a = o.shape;
  13223. if (r) {
  13224. var i = D(n, t.shape);
  13225. a = vn(o.shape, i);
  13226. }
  13227. return o.reshape(a);
  13228. }
  13229. });
  13230. exports.norm = Il;
  13231. var kl = Cn({
  13232. basicLSTMCell_: function (t, e, n, r, o, a) {
  13233. var i = ln(t, "forgetBias", "basicLSTMCell"),
  13234. u = ln(e, "lstmKernel", "basicLSTMCell"),
  13235. s = ln(n, "lstmBias", "basicLSTMCell"),
  13236. c = ln(r, "data", "basicLSTMCell"),
  13237. l = ln(o, "c", "basicLSTMCell"),
  13238. h = ln(a, "h", "basicLSTMCell"),
  13239. f = c.concat(h, 1).matMul(u).add(s),
  13240. p = f.shape[0],
  13241. d = f.shape[1] / 4,
  13242. v = [p, d],
  13243. m = f.slice([0, 0], v),
  13244. g = f.slice([0, d], v),
  13245. y = f.slice([0, 2 * d], v),
  13246. x = f.slice([0, 3 * d], v),
  13247. b = m.sigmoid().mulStrict(g.tanh()).addStrict(l.mulStrict(i.add(y).sigmoid())),
  13248. w = b.tanh().mulStrict(x.sigmoid());
  13249. return [b, w];
  13250. }
  13251. }),
  13252. Sl = Cn({
  13253. multiRNNCell_: function (t, e, n, r) {
  13254. for (var o = ln(e, "data", "multiRNNCell"), a = hn(n, "c", "multiRNNCell"), i = hn(r, "h", "multiRNNCell"), u = o, s = [], c = 0; c < t.length; c++) {
  13255. var l = t[c](u, a[c], i[c]);
  13256. s.push(l[0]), s.push(l[1]), u = l[1];
  13257. }
  13258. var h = [],
  13259. f = [];
  13260. for (c = 0; c < s.length; c += 2) h.push(s[c]), f.push(s[c + 1]);
  13261. return [h, f];
  13262. }
  13263. });
  13264. exports.multiRNNCell = Sl;
  13265. exports.basicLSTMCell = kl;
  13266. var Al = Cn({
  13267. movingAverage_: function (t, e, n, r, o) {
  13268. void 0 === o && (o = !0);
  13269. var a = ln(t, "v", "movingAverage"),
  13270. i = ln(e, "x", "movingAverage"),
  13271. u = ln(n, "decay", "movingAverage");
  13272. It(a, i), g(C(a.shape, i.shape), function () {
  13273. return "Shape mismatch in v and x";
  13274. });
  13275. var s = An(1),
  13276. c = s.sub(u),
  13277. l = i.sub(a).mul(c);
  13278. if (o) {
  13279. g(null != r, function () {
  13280. return "When using zeroDebias: true, step is required.";
  13281. });
  13282. var h = ln(r, "step", "movingAverage");
  13283. l = l.div(s.sub(nc(u, h)));
  13284. }
  13285. return a.add(l);
  13286. }
  13287. });
  13288. exports.movingAverage = Al;
  13289. var Dl = Cn({
  13290. stridedSlice_: function (t, e, n, r, o, a, i, u, s) {
  13291. if (void 0 === o && (o = 0), void 0 === a && (a = 0), void 0 === i && (i = 0), void 0 === u && (u = 0), void 0 === s && (s = 0), null == r && (r = new Array(e.length)), 0 !== i) throw new Error("ellipsis mask is not yet supported");
  13292. var c = ln(t, "x", "stridedSlice"),
  13293. l = Kr(u),
  13294. h = c.shape.slice();
  13295. l.forEach(function (t) {
  13296. e[t] = 0, n[t] = 1, h.splice(t, 0, 1);
  13297. }), c = c.reshape(h);
  13298. for (var f = 0; f < c.rank; f++) e[f] = Xr(o, e, r, c.shape, f), n[f] = $r(a, n, r, c.shape, f), r[f] = r[f] || 1;
  13299. var p = Kr(s);
  13300. p.forEach(function (t) {
  13301. n[t] = e[t] + 1, r[t] = 1;
  13302. });
  13303. var d = jr(e, n, r),
  13304. v = d.filter(function (t, e) {
  13305. return -1 === p.indexOf(e);
  13306. });
  13307. return r.every(function (t) {
  13308. return 1 === t;
  13309. }) ? tl(c, e, d).reshape(v) : Nt.runKernelFunc(function (t) {
  13310. return t.stridedSlice(c, e, n, r);
  13311. }, {
  13312. $x: c
  13313. }).reshape(v);
  13314. }
  13315. });
  13316. exports.stridedSlice = Dl;
  13317. var Tl = Cn({
  13318. topk_: function (t, e, n) {
  13319. void 0 === e && (e = 1), void 0 === n && (n = !0);
  13320. var r = ln(t, "x", "topk");
  13321. if (0 === r.rank) throw new Error("topk() expects the input to be of rank 1 or higher");
  13322. var o = r.shape[r.shape.length - 1];
  13323. if (e > o) throw new Error("'k' passed to topk() must be <= the last dimension (" + o + ") but got " + e);
  13324. var a = Nt.runKernelFunc(function (t) {
  13325. return t.topk(r, e, n);
  13326. }, {
  13327. $x: r
  13328. });
  13329. return {
  13330. values: a[0],
  13331. indices: a[1]
  13332. };
  13333. }
  13334. });
  13335. exports.topk = Tl;
  13336. var Nl = Cn({
  13337. scatterND_: function (t, e, n) {
  13338. var r = ln(t, "indices", "scatterND", "int32"),
  13339. o = ln(e, "updates", "scatterND");
  13340. return Gr(o, r, n), Nt.runKernelFunc(function (t) {
  13341. return t.scatterND(r, o, n);
  13342. }, {
  13343. $indices: r,
  13344. $updates: o
  13345. });
  13346. }
  13347. });
  13348. exports.scatterND = Nl;
  13349. var Fl = Cn({
  13350. fft_: function (t) {
  13351. g("complex64" === t.dtype, function () {
  13352. return "The dtype for tf.spectral.fft() must be complex64 but got " + t.dtype + ".";
  13353. });
  13354. var e = t.shape[t.shape.length - 1],
  13355. n = t.size / e,
  13356. r = t.as2D(n, e);
  13357. return Nt.runKernelFunc(function (t) {
  13358. return t.fft(r);
  13359. }, {
  13360. input: t
  13361. }).reshape(t.shape);
  13362. }
  13363. }),
  13364. Ol = Cn({
  13365. ifft_: function (t) {
  13366. g("complex64" === t.dtype, function () {
  13367. return "The dtype for tf.spectral.ifft() must be complex64 but got " + t.dtype + ".";
  13368. });
  13369. var e = t.shape[t.shape.length - 1],
  13370. n = t.size / e,
  13371. r = t.as2D(n, e);
  13372. return Nt.runKernelFunc(function (t) {
  13373. return t.ifft(r);
  13374. }, {
  13375. input: t
  13376. }).reshape(t.shape);
  13377. }
  13378. }),
  13379. _l = Cn({
  13380. rfft_: function (t, e) {
  13381. g("float32" === t.dtype, function () {
  13382. return "The dtype for rfft() must be real value but got " + t.dtype;
  13383. });
  13384. var n,
  13385. r = t.shape[t.shape.length - 1],
  13386. o = t.size / r;
  13387. if (null != e && e < r) {
  13388. var a = t.shape.map(function (t) {
  13389. return 0;
  13390. }),
  13391. i = t.shape.map(function (t) {
  13392. return t;
  13393. });
  13394. i[t.shape.length - 1] = e, n = t.slice(a, i), r = e;
  13395. } else if (null != e && e > r) {
  13396. var u = t.shape.map(function (t) {
  13397. return t;
  13398. });
  13399. u[t.shape.length - 1] = e - r, n = t.concat(Pn(u), t.shape.length - 1), r = e;
  13400. } else n = t;
  13401. var s = n.zerosLike(),
  13402. c = En(n, s).as2D(o, r),
  13403. l = Fl(c),
  13404. h = Math.floor(r / 2) + 1,
  13405. f = Rn(l),
  13406. p = In(l),
  13407. d = f.split([h, r - h], f.shape.length - 1),
  13408. v = p.split([h, r - h], p.shape.length - 1),
  13409. m = n.shape.slice();
  13410. return m[n.shape.length - 1] = h, En(d[0], v[0]).reshape(m);
  13411. }
  13412. }),
  13413. Ml = Cn({
  13414. irfft_: function (t) {
  13415. var e = t.shape[t.shape.length - 1],
  13416. n = t.size / e;
  13417. if (e <= 2) {
  13418. var r = t.as2D(n, e),
  13419. o = Ol(r);
  13420. return Rn(o);
  13421. }
  13422. var a = [n, 2 * (e - 1)],
  13423. i = Rn(t).as2D(n, e),
  13424. u = In(t).as2D(n, e),
  13425. s = i.slice([0, 1], [n, e - 2]).reverse(1),
  13426. c = u.slice([0, 1], [n, e - 2]).reverse(1).mul(An(-1)),
  13427. l = i.concat(s, 1),
  13428. h = u.concat(c, 1);
  13429. return r = En(l, h).as2D(a[0], a[1]), o = Ol(r), Rn(o);
  13430. }
  13431. }),
  13432. Bl = Object.freeze({
  13433. fft: Fl,
  13434. ifft: Ol,
  13435. rfft: _l,
  13436. irfft: Ml
  13437. });
  13438. exports.spectral = Bl;
  13439. exports.irfft = Ml;
  13440. exports.rfft = _l;
  13441. exports.ifft = Ol;
  13442. exports.fft = Fl;
  13443. var Pl = Cn({
  13444. sparseToDense_: function (t, e, n, r) {
  13445. void 0 === r && (r = 0);
  13446. var o = ln(t, "sparseIndices", "sparseToDense", "int32"),
  13447. a = ln(e, "sparseValues", "sparseToDense"),
  13448. i = ln(r, "defaultValue", "sparseToDense", a.dtype);
  13449. return function (t, e, n, r) {
  13450. if ("int32" !== t.dtype) throw new Error("tf.sparseToDense() expects the indices to be int32 type, but the dtype was " + t.dtype + ".");
  13451. if (t.rank > 2) throw new Error("sparseIndices should be a scalar, vector, or matrix, but got shape " + t.shape + ".");
  13452. var o = t.rank > 0 ? t.shape[0] : 1,
  13453. a = t.rank > 1 ? t.shape[1] : 1;
  13454. if (n.length !== a) throw new Error("outputShape has incorrect number of elements:, " + n.length + ", should be: " + a + ".");
  13455. var i = e.size;
  13456. if (0 !== e.rank && (1 !== e.rank || i !== o)) throw new Error("sparseValues has incorrect shape " + e.shape + ", should be [] or [" + o + "]");
  13457. if (e.dtype !== r.dtype) throw new Error("sparseValues.dtype must match defaultValues.dtype");
  13458. }(o, a, n, i), Nt.runKernelFunc(function (t) {
  13459. return t.sparseToDense(o, a, n, i);
  13460. }, {
  13461. $sparseIndices: o,
  13462. $sparseValues: a,
  13463. $defaultValue: i
  13464. });
  13465. }
  13466. });
  13467. exports.sparseToDense = Pl;
  13468. var Ll = Cn({
  13469. gatherND_: function (t, e) {
  13470. var n = ln(e, "indices", "gatherND", "int32"),
  13471. r = ln(t, "x", "gatherND");
  13472. return Nt.runKernelFunc(function (t) {
  13473. return t.gatherND(r, n);
  13474. }, {
  13475. $x: r,
  13476. $indices: n
  13477. });
  13478. }
  13479. });
  13480. exports.gatherND = Ll;
  13481. var Wl = Cn({
  13482. diag_: function (t) {
  13483. var e = ln(t, "x", "diag").flatten(),
  13484. n = t.shape.concat(t.shape);
  13485. return Nt.runKernelFunc(function (t) {
  13486. return t.diag(e);
  13487. }, {
  13488. $x: e
  13489. }).reshape(n);
  13490. }
  13491. });
  13492. exports.diag = Wl;
  13493. var Ul = Cn({
  13494. dropout_: function (t, e, n, r) {
  13495. var o = ln(t, "x", "dropout");
  13496. if (g("float32" === o.dtype, function () {
  13497. return "x has to be a floating point tensor since it's going to be scaled, but got a " + o.dtype + " tensor instead.";
  13498. }), g(e >= 0 && e < 1, function () {
  13499. return "rate must be a float in the range [0, 1), but got " + e + ".";
  13500. }), 0 === e) return t instanceof dt ? o.clone() : o;
  13501. var a = function (t, e) {
  13502. if (null == e) return t.shape.slice();
  13503. if (C(t.shape, e)) return e;
  13504. if (t.shape.length === e.length) {
  13505. for (var n = [], r = 0; r < t.shape.length; r++) null == e[r] && null != t.shape[r] ? n.push(t.shape[r]) : n.push(e[r]);
  13506. return n;
  13507. }
  13508. return e;
  13509. }(o, n),
  13510. i = 1 - e,
  13511. u = kr(a, 0, 1, "float32", r).add(i).floor().div(i);
  13512. return o.mul(u);
  13513. }
  13514. });
  13515. exports.dropout = Ul;
  13516. function Vl(t, e, n) {
  13517. for (var r = 1 - t % 2, o = new Float32Array(t), a = 0; a < t; ++a) {
  13518. var i = 2 * Math.PI * a / (t + r - 1);
  13519. o[a] = e - n * Math.cos(i);
  13520. }
  13521. return Dn(o, "float32");
  13522. }
  13523. var zl = Cn({
  13524. hannWindow_: function (t) {
  13525. return Vl(t, .5, .5);
  13526. }
  13527. }),
  13528. Gl = Cn({
  13529. hammingWindow_: function (t) {
  13530. return Vl(t, .54, .46);
  13531. }
  13532. }),
  13533. Hl = Cn({
  13534. frame_: function (t, e, n, r, o) {
  13535. void 0 === r && (r = !1), void 0 === o && (o = 0);
  13536. for (var a = 0, i = []; a + e <= t.size;) i.push(tl(t, a, e)), a += n;
  13537. if (r) for (; a < t.size;) {
  13538. var u = a + e - t.size,
  13539. s = Gn([tl(t, a, e - u), Ln([u], o)]);
  13540. i.push(s), a += n;
  13541. }
  13542. return 0 === i.length ? Tn([], [0, e]) : Gn(i).as2D(i.length, e);
  13543. }
  13544. }),
  13545. ql = Cn({
  13546. stft_: function (t, e, n, r, o) {
  13547. var a;
  13548. void 0 === o && (o = zl), null == r && (a = e, r = Math.floor(Math.pow(2, Math.ceil(Math.log(a) / Math.log(2)))));
  13549. for (var i = Hl(t, e, n), u = tc(i, o(e)), s = [], c = 0; c < i.shape[0]; c++) s.push(_l(u.slice([c, 0], [1, e]), r));
  13550. return Gn(s);
  13551. }
  13552. }),
  13553. Kl = Object.freeze({
  13554. hannWindow: zl,
  13555. hammingWindow: Gl,
  13556. frame: Hl,
  13557. stft: ql
  13558. });
  13559. exports.signal = Kl;
  13560. exports.stft = ql;
  13561. exports.frame = Hl;
  13562. exports.hammingWindow = Gl;
  13563. exports.hannWindow = zl;
  13564. var jl,
  13565. Xl = function (t, e, o) {
  13566. return void 0 === o && (o = 1), n(this, void 0, void 0, function () {
  13567. var n, a, i, u, s, c, l, h, f, p, d, v, m, x;
  13568. return r(this, function (r) {
  13569. switch (r.label) {
  13570. case 0:
  13571. return n = ln(t, "predictions", "inTopK"), a = ln(e, "targets", "inTopK"), g(n.rank > 1, function () {
  13572. return "inTopK() expects the predictions to be of rank 2 or higher, but got " + n.rank;
  13573. }), g(n.rank - 1 === a.rank, function () {
  13574. return "predictions rank should be 1 larger than targets rank, but got predictions rank " + n.rank + " and targets rank " + a.rank;
  13575. }), y(n.shape.slice(0, n.shape.length - 1), a.shape, "predictions's shape should be align with the targets' shape, except the last dimension."), i = n.shape[n.shape.length - 1], g(o > 0 && o <= i, function () {
  13576. return "'k' passed to inTopK() must be > 0 && <= the predictions last dimension (" + i + "), but got " + o;
  13577. }), [4, n.data()];
  13578. case 1:
  13579. return u = r.sent(), [4, a.data()];
  13580. case 2:
  13581. for (s = r.sent(), c = [u.length / i, i], h = c[1], f = N("bool", l = c[0]), p = 0; p < l; p++) {
  13582. for (d = p * h, v = u.subarray(d, d + h), m = [], x = 0; x < v.length; x++) m.push({
  13583. value: v[x],
  13584. index: x
  13585. });
  13586. for (m.sort(function (t, e) {
  13587. return e.value - t.value;
  13588. }), f[p] = 0, x = 0; x < o; x++) if (m[x].index === s[p]) {
  13589. f[p] = 1;
  13590. break;
  13591. }
  13592. }
  13593. return t !== n && n.dispose(), e !== a && a.dispose(), [2, kn(f, a.shape, "bool")];
  13594. }
  13595. });
  13596. });
  13597. };
  13598. exports.inTopKAsync = Xl;
  13599. exports.Reduction = jl;
  13600. !function (t) {
  13601. t[t.NONE = 0] = "NONE", t[t.MEAN = 1] = "MEAN", t[t.SUM = 2] = "SUM", t[t.SUM_BY_NONZERO_WEIGHTS = 3] = "SUM_BY_NONZERO_WEIGHTS";
  13602. }(jl || (exports.Reduction = jl = {}));
  13603. var $l = Cn({
  13604. absoluteDifference_: function (t, e, n, r) {
  13605. void 0 === r && (r = jl.SUM_BY_NONZERO_WEIGHTS);
  13606. var o = ln(t, "labels", "absoluteDifference"),
  13607. a = ln(e, "predictions", "absoluteDifference"),
  13608. i = null;
  13609. null != n && (i = ln(n, "weights", "absoluteDifference")), y(o.shape, a.shape, "Error in absoluteDifference: ");
  13610. var u = o.sub(a).abs();
  13611. return Yl(u, i, r);
  13612. }
  13613. }),
  13614. Yl = Cn({
  13615. computeWeightedLoss_: function (t, e, n) {
  13616. void 0 === n && (n = jl.SUM_BY_NONZERO_WEIGHTS);
  13617. var r = ln(t, "losses", "computeWeightedLoss"),
  13618. o = null;
  13619. null != e && (o = ln(e, "weights", "computeWeightedLoss"));
  13620. var a = null == o ? r : r.mul(o);
  13621. if (n === jl.NONE) return a;
  13622. if (n === jl.SUM) return a.sum();
  13623. if (n === jl.MEAN) {
  13624. if (null == o) return a.mean();
  13625. var i = r.size / o.size,
  13626. u = a.sum().div(o.sum());
  13627. return i > 1 ? u.div(An(i)) : u;
  13628. }
  13629. if (n === jl.SUM_BY_NONZERO_WEIGHTS) {
  13630. if (null == o) return a.sum().div(An(r.size));
  13631. var s = o.mul(Bn(r.shape)).notEqual(An(0)).sum().toFloat();
  13632. return a.sum().div(s);
  13633. }
  13634. throw Error("Unknown reduction: " + n);
  13635. }
  13636. }),
  13637. Ql = Cn({
  13638. cosineDistance_: function (t, e, n, r, o) {
  13639. void 0 === o && (o = jl.SUM_BY_NONZERO_WEIGHTS);
  13640. var a = ln(t, "labels", "cosineDistance"),
  13641. i = ln(e, "predictions", "cosineDistance"),
  13642. u = null;
  13643. null != r && (u = ln(r, "weights", "cosineDistance")), y(a.shape, i.shape, "Error in cosineDistance: ");
  13644. var s = An(1).sub(a.mul(i).sum(n, !0));
  13645. return Yl(s, u, o);
  13646. }
  13647. }),
  13648. Jl = Cn({
  13649. hingeLoss_: function (t, e, n, r) {
  13650. void 0 === r && (r = jl.SUM_BY_NONZERO_WEIGHTS);
  13651. var o = ln(t, "labels", "hingeLoss"),
  13652. a = ln(e, "predictions", "hingeLoss"),
  13653. i = null;
  13654. null != n && (i = ln(n, "weights", "hingeLoss")), y(o.shape, a.shape, "Error in hingeLoss: ");
  13655. var u = An(1);
  13656. o = An(2).mul(o).sub(u);
  13657. var s = u.sub(o.mul(a)).relu();
  13658. return Yl(s, i, r);
  13659. }
  13660. }),
  13661. Zl = Cn({
  13662. huberLoss_: function (t, e, n, r, o) {
  13663. void 0 === r && (r = 1), void 0 === o && (o = jl.SUM_BY_NONZERO_WEIGHTS);
  13664. var a = ln(t, "labels", "huberLoss"),
  13665. i = ln(e, "predictions", "huberLoss"),
  13666. u = null;
  13667. null != n && (u = ln(n, "weights", "huberLoss")), y(a.shape, i.shape, "Error in huberLoss: ");
  13668. var s = An(r),
  13669. c = i.sub(a).abs(),
  13670. l = Ys(c, s),
  13671. h = c.sub(l),
  13672. f = An(.5).mul(l.square()).add(s.mul(h));
  13673. return Yl(f, u, o);
  13674. }
  13675. }),
  13676. th = Cn({
  13677. logLoss_: function (t, e, n, r, o) {
  13678. void 0 === r && (r = 1e-7), void 0 === o && (o = jl.SUM_BY_NONZERO_WEIGHTS);
  13679. var a = ln(t, "labels", "logLoss"),
  13680. i = ln(e, "predictions", "logLoss"),
  13681. u = null;
  13682. null != n && (u = ln(n, "weights", "logLoss")), y(a.shape, i.shape, "Error in logLoss: ");
  13683. var s = An(1),
  13684. c = An(r),
  13685. l = a.mul(i.add(c).log()).neg().sub(s.sub(a).mul(s.sub(i).add(c).log()));
  13686. return Yl(l, u, o);
  13687. }
  13688. }),
  13689. eh = Cn({
  13690. meanSquaredError_: function (t, e, n, r) {
  13691. void 0 === r && (r = jl.SUM_BY_NONZERO_WEIGHTS);
  13692. var o = ln(t, "labels", "meanSquaredError"),
  13693. a = ln(e, "predictions", "meanSquaredError"),
  13694. i = null;
  13695. null != n && (i = ln(n, "weights", "meanSquaredError")), y(o.shape, a.shape, "Error in meanSquaredError: ");
  13696. var u = o.squaredDifference(a);
  13697. return Yl(u, i, r);
  13698. }
  13699. }),
  13700. nh = Cn({
  13701. sigmoidCrossEntropy_: function (t, e, n, r, o) {
  13702. void 0 === r && (r = 0), void 0 === o && (o = jl.SUM_BY_NONZERO_WEIGHTS);
  13703. var a = ln(t, "multiClassLabels", "sigmoidCrossEntropy"),
  13704. i = ln(e, "logits", "sigmoidCrossEntropy"),
  13705. u = null;
  13706. if (null != n && (u = ln(n, "weights", "sigmoidCrossEntropy")), y(a.shape, i.shape, "Error in sigmoidCrossEntropy: "), r > 0) {
  13707. var s = An(r),
  13708. c = An(1),
  13709. l = An(.5);
  13710. a = a.mul(c.sub(s)).add(l.mul(s));
  13711. }
  13712. var h = function (t, e) {
  13713. var n = ln(t, "labels", "sigmoidCrossEntropyWithLogits"),
  13714. r = ln(e, "logits", "sigmoidCrossEntropyWithLogits");
  13715. y(n.shape, r.shape, "Error in sigmoidCrossEntropyWithLogits: ");
  13716. var o = r.relu(),
  13717. a = r.mul(n),
  13718. i = r.abs().neg().exp().log1p();
  13719. return o.sub(a).add(i);
  13720. }(a, i);
  13721. return Yl(h, u, o);
  13722. }
  13723. }),
  13724. rh = Cn({
  13725. softmaxCrossEntropy_: function (t, e, n, r, o) {
  13726. void 0 === r && (r = 0), void 0 === o && (o = jl.SUM_BY_NONZERO_WEIGHTS);
  13727. var a = ln(t, "onehotLabels", "softmaxCrossEntropy"),
  13728. i = ln(e, "logits", "softmaxCrossEntropy"),
  13729. u = null;
  13730. if (null != n && (u = ln(n, "weights", "softmaxCrossEntropy")), y(a.shape, i.shape, "Error in softmaxCrossEntropy: "), r > 0) {
  13731. var s = An(r),
  13732. c = An(1),
  13733. l = An(a.shape[1]);
  13734. a = a.mul(c.sub(s)).add(s.div(l));
  13735. }
  13736. var h = function (t, e, n) {
  13737. if (void 0 === n && (n = -1), -1 === n && (n = e.rank - 1), n !== e.rank - 1) throw Error("Softmax cross entropy along a non-last dimension is not yet supported. Labels / logits was rank " + e.rank + " and dim was " + n);
  13738. return oo(function (t, e, r) {
  13739. var o = e.logSumExp([n], !0),
  13740. a = e.toFloat().sub(o);
  13741. return r([t, a]), {
  13742. value: a.mul(t).neg().sum([n]),
  13743. gradFunc: function (t, e) {
  13744. var r = e[0],
  13745. o = e[1],
  13746. a = vn(t.shape, [n]);
  13747. return [t.reshape(a).mul(r.toFloat().sub(o.exp())), t.reshape(a).mul(o.exp().sub(r.toFloat()))];
  13748. }
  13749. };
  13750. })(t, e);
  13751. }(a, i);
  13752. return Yl(h, u, o);
  13753. }
  13754. }),
  13755. oh = Object.freeze({
  13756. get Reduction() {
  13757. return jl;
  13758. },
  13759. absoluteDifference: $l,
  13760. computeWeightedLoss: Yl,
  13761. cosineDistance: Ql,
  13762. hingeLoss: Jl,
  13763. huberLoss: Zl,
  13764. logLoss: th,
  13765. meanSquaredError: eh,
  13766. sigmoidCrossEntropy: nh,
  13767. softmaxCrossEntropy: rh
  13768. });
  13769. exports.losses = oh;
  13770. function ah(t, e) {
  13771. return void 0 === e && (e = !1), Nt.tidy(function () {
  13772. if (2 !== t.shape.length) throw new Error("qr2d() requires a 2D Tensor, but got a " + t.shape.length + "D Tensor.");
  13773. for (var n = t.shape[0], r = t.shape[1], o = vr(n), a = t.clone(), i = Tn([[1]], [1, 1]), u = i.clone(), s = n >= r ? r : n, c = function (t) {
  13774. var e,
  13775. s = a,
  13776. c = u,
  13777. l = o;
  13778. e = Nt.tidy(function () {
  13779. var e = a.slice([t, t], [n - t, 1]),
  13780. s = e.norm(),
  13781. c = a.slice([t, t], [1, 1]),
  13782. l = Tn([[-1]]).where(c.greater(0), Tn([[1]])),
  13783. h = c.sub(l.mul(s)),
  13784. f = e.div(h);
  13785. u = 1 === f.shape[0] ? i.clone() : i.concat(f.slice([1, 0], [f.shape[0] - 1, f.shape[1]]), 0);
  13786. var p = l.matMul(h).div(s).neg(),
  13787. d = a.slice([t, 0], [n - t, r]),
  13788. v = p.mul(u);
  13789. if (0 === t) a = d.sub(v.matMul(u.transpose().matMul(d))); else {
  13790. var m = d.sub(v.matMul(u.transpose().matMul(d)));
  13791. a = a.slice([0, 0], [t, r]).concat(m, 0);
  13792. }
  13793. var g = o.slice([0, t], [n, o.shape[1] - t]);
  13794. if (0 === t) o = g.sub(g.matMul(u).matMul(v.transpose())); else {
  13795. var y = g.sub(g.matMul(u).matMul(v.transpose()));
  13796. o = o.slice([0, 0], [n, t]).concat(y, 1);
  13797. }
  13798. return [u, a, o];
  13799. }), u = e[0], a = e[1], o = e[2], Xe([s, c, l]);
  13800. }, l = 0; l < s; ++l) c(l);
  13801. return !e && n > r && (o = o.slice([0, 0], [n, r]), a = a.slice([0, 0], [r, r])), [o, a];
  13802. });
  13803. }
  13804. var ih = Cn({
  13805. gramSchmidt_: function (t) {
  13806. var e;
  13807. if (Array.isArray(t)) {
  13808. e = !1, g(null != t && t.length > 0, function () {
  13809. return "Gram-Schmidt process: input must not be null, undefined, or empty";
  13810. });
  13811. for (var n = t[0].shape[0], r = function (e) {
  13812. g(t[e].shape[0] === n, function () {
  13813. return "Gram-Schmidt: Non-unique lengths found in the input vectors: (" + t[e].shape[0] + " vs. " + n + ")";
  13814. });
  13815. }, o = 1; o < t.length; ++o) r(o);
  13816. } else e = !0, t = Xn(t, t.shape[0], 0).map(function (t) {
  13817. return Dr(t, [0]);
  13818. });
  13819. g(t.length <= t[0].shape[0], function () {
  13820. return "Gram-Schmidt: Number of vectors (" + t.length + ") exceeds number of dimensions (" + t[0].shape[0] + ").";
  13821. });
  13822. var a = [],
  13823. i = t,
  13824. u = function (t) {
  13825. a.push(Nt.tidy(function () {
  13826. var e = i[t];
  13827. if (t > 0) for (var n = 0; n < t; ++n) {
  13828. var r = vl(a[n].mulStrict(e)).mul(a[n]);
  13829. e = e.sub(r);
  13830. }
  13831. return e.div(Il(e, "euclidean"));
  13832. }));
  13833. };
  13834. for (o = 0; o < t.length; ++o) u(o);
  13835. return e ? Tr(a, 0) : a;
  13836. }
  13837. }),
  13838. uh = Cn({
  13839. qr_: function (t, e) {
  13840. if (void 0 === e && (e = !1), t.rank < 2) throw new Error("qr() requires input tensor to have a rank >= 2, but got rank " + t.rank);
  13841. if (2 === t.rank) return ah(t, e);
  13842. var n = t.shape.slice(0, t.shape.length - 2).reduce(function (t, e) {
  13843. return t * e;
  13844. }),
  13845. r = Or(t.reshape([n, t.shape[t.shape.length - 2], t.shape[t.shape.length - 1]]), 0),
  13846. o = [],
  13847. a = [];
  13848. return r.forEach(function (t) {
  13849. var n = ah(t, e),
  13850. r = n[0],
  13851. i = n[1];
  13852. o.push(r), a.push(i);
  13853. }), [Tr(o, 0).reshape(t.shape), Tr(a, 0).reshape(t.shape)];
  13854. }
  13855. }),
  13856. sh = Object.freeze({
  13857. gramSchmidt: ih,
  13858. qr: uh
  13859. });
  13860. exports.linalg = sh;
  13861. function ch(t, e, n, r, o) {
  13862. null == r && (r = .5), null == o && (o = Number.NEGATIVE_INFINITY);
  13863. var a = t.shape[0];
  13864. return n = Math.min(n, a), g(0 <= r && r <= 1, function () {
  13865. return "iouThreshold must be in [0, 1], but was '" + r + "'";
  13866. }), g(2 === t.rank, function () {
  13867. return "boxes must be a 2D tensor, but was of rank '" + t.rank + "'";
  13868. }), g(4 === t.shape[1], function () {
  13869. return "boxes must have 4 columns, but 2nd dimension was " + t.shape[1];
  13870. }), g(1 === e.rank, function () {
  13871. return "scores must be a 1D tensor";
  13872. }), g(e.shape[0] === a, function () {
  13873. return "scores has incompatible shape with boxes. Expected " + a + ", but was " + e.shape[0];
  13874. }), {
  13875. maxOutputSize: n,
  13876. iouThreshold: r,
  13877. scoreThreshold: o
  13878. };
  13879. }
  13880. var lh = Cn({
  13881. resizeBilinear_: function (t, e, n) {
  13882. void 0 === n && (n = !1);
  13883. var r = ln(t, "images", "resizeBilinear");
  13884. g(3 === r.rank || 4 === r.rank, function () {
  13885. return "Error in resizeBilinear: x must be rank 3 or 4, but got rank " + r.rank + ".";
  13886. }), g(2 === e.length, function () {
  13887. return "Error in resizeBilinear: new shape must 2D, but got shape " + e + ".";
  13888. });
  13889. var o = r,
  13890. a = !1;
  13891. 3 === r.rank && (a = !0, o = r.as4D(1, r.shape[0], r.shape[1], r.shape[2]));
  13892. var i = e[0],
  13893. u = e[1],
  13894. s = Nt.runKernelFunc(function (t, e) {
  13895. return e([o]), t.resizeBilinear(o, i, u, n);
  13896. }, {
  13897. batchImages: o
  13898. }, function (t, e) {
  13899. return {
  13900. batchImages: function () {
  13901. return Nt.runKernelFunc(function (r) {
  13902. return r.resizeBilinearBackprop(t, e[0], n);
  13903. }, {});
  13904. }
  13905. };
  13906. });
  13907. return a ? s.as3D(s.shape[1], s.shape[2], s.shape[3]) : s;
  13908. }
  13909. }),
  13910. hh = Cn({
  13911. resizeNearestNeighbor_: function (t, e, n) {
  13912. void 0 === n && (n = !1);
  13913. var r = ln(t, "images", "resizeNearestNeighbor");
  13914. g(3 === r.rank || 4 === r.rank, function () {
  13915. return "Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank " + r.rank + ".";
  13916. }), g(2 === e.length, function () {
  13917. return "Error in resizeNearestNeighbor: new shape must 2D, but got shape " + e + ".";
  13918. }), g("float32" === r.dtype || "int32" === r.dtype, function () {
  13919. return "`images` must have `int32` or `float32` as dtype";
  13920. });
  13921. var o = r,
  13922. a = !1;
  13923. 3 === r.rank && (a = !0, o = r.as4D(1, r.shape[0], r.shape[1], r.shape[2]));
  13924. var i = e[0],
  13925. u = e[1],
  13926. s = Nt.runKernelFunc(function (t, e) {
  13927. return e([o]), t.resizeNearestNeighbor(o, i, u, n);
  13928. }, {
  13929. batchImages: o
  13930. }, function (t, e) {
  13931. return {
  13932. batchImages: function () {
  13933. return Nt.runKernelFunc(function (r) {
  13934. return r.resizeNearestNeighborBackprop(t, e[0], n);
  13935. }, {});
  13936. }
  13937. };
  13938. });
  13939. return a ? s.as3D(s.shape[1], s.shape[2], s.shape[3]) : s;
  13940. }
  13941. }),
  13942. fh = Cn({
  13943. nonMaxSuppression_: function (t, e, n, r, o) {
  13944. void 0 === r && (r = .5), void 0 === o && (o = Number.NEGATIVE_INFINITY);
  13945. var a = ln(t, "boxes", "nonMaxSuppression"),
  13946. i = ln(e, "scores", "nonMaxSuppression"),
  13947. u = ch(a, i, n, r, o);
  13948. return n = u.maxOutputSize, r = u.iouThreshold, o = u.scoreThreshold, Nt.runKernelFunc(function (t) {
  13949. return t.nonMaxSuppression(a, i, n, r, o);
  13950. }, {
  13951. $boxes: a
  13952. });
  13953. }
  13954. }),
  13955. ph = function (t, e, o, a, i) {
  13956. return void 0 === a && (a = .5), void 0 === i && (i = Number.NEGATIVE_INFINITY), n(this, void 0, void 0, function () {
  13957. var n, u, s, c, l, h, f;
  13958. return r(this, function (r) {
  13959. switch (r.label) {
  13960. case 0:
  13961. return n = ln(t, "boxes", "nonMaxSuppressionAsync"), u = ln(e, "scores", "nonMaxSuppressionAsync"), s = ch(n, u, o, a, i), o = s.maxOutputSize, a = s.iouThreshold, i = s.scoreThreshold, [4, Promise.all([n.data(), u.data()])];
  13962. case 1:
  13963. return c = r.sent(), l = c[0], h = c[1], f = Mo(l, h, o, a, i), n !== t && n.dispose(), u !== e && u.dispose(), [2, f];
  13964. }
  13965. });
  13966. });
  13967. },
  13968. dh = Cn({
  13969. cropAndResize_: function (t, e, n, r, o, a) {
  13970. var i = ln(t, "image", "cropAndResize", "float32"),
  13971. u = ln(e, "boxes", "cropAndResize", "float32"),
  13972. s = ln(n, "boxInd", "cropAndResize", "int32");
  13973. o = o || "bilinear", a = a || 0;
  13974. var c = u.shape[0];
  13975. return g(4 === i.rank, function () {
  13976. return "Error in cropAndResize: image must be rank 4,but got rank " + i.rank + ".";
  13977. }), g(2 === u.rank && 4 === u.shape[1], function () {
  13978. return "Error in cropAndResize: boxes must be have size [" + c + ",4] but had shape " + u.shape + ".";
  13979. }), g(1 === s.rank && s.shape[0] === c, function () {
  13980. return "Error in cropAndResize: boxInd must be have size [" + c + "] but had shape " + u.shape + ".";
  13981. }), g(2 === r.length, function () {
  13982. return "Error in cropAndResize: cropSize must be of length 2, but got length " + r.length + ".";
  13983. }), g(r[0] >= 1 && r[1] >= 1, function () {
  13984. return "cropSize must be atleast [1,1], but was " + r;
  13985. }), g("bilinear" === o || "nearest" === o, function () {
  13986. return "method must be bilinear or nearest, but was " + o;
  13987. }), Nt.runKernelFunc(function (t, e) {
  13988. return t.cropAndResize(i, u, s, r, o, a);
  13989. }, {
  13990. $image: i,
  13991. $boxes: u
  13992. });
  13993. }
  13994. }),
  13995. vh = Object.freeze({
  13996. resizeBilinear: lh,
  13997. resizeNearestNeighbor: hh,
  13998. nonMaxSuppression: fh,
  13999. nonMaxSuppressionAsync: ph,
  14000. cropAndResize: dh
  14001. }),
  14002. mh = function (t, e) {
  14003. return !(t > 0) && ("linear" === e || "relu" === e);
  14004. },
  14005. gh = function (t, e, n) {
  14006. if (null == n || "linear" === n) return t;
  14007. if ("relu" === n) return t.mul(e.step());
  14008. throw new Error("Gradient for activation " + n + " has not been implemented yet.");
  14009. },
  14010. yh = function (t, e) {
  14011. var n = e,
  14012. r = fo(t.shape, e.shape);
  14013. return r.length > 0 && (n = n.sum(r)), n.reshape(t.shape);
  14014. },
  14015. xh = function (t, e, n) {
  14016. if ("linear" === e) return t;
  14017. if ("relu" === e) return bl(t);
  14018. if ("elu" === e) return gl(t);
  14019. if ("relu6" === e) return wl(t);
  14020. if ("prelu" === e) return xl(t, n);
  14021. throw new Error("Unknown fused activation " + e + ".");
  14022. };
  14023. exports.image = vh;
  14024. var bh = Cn({
  14025. matMul_: function (t) {
  14026. var e,
  14027. n = t.a,
  14028. r = t.b,
  14029. o = t.transposeA,
  14030. a = void 0 !== o && o,
  14031. i = t.transposeB,
  14032. u = void 0 !== i && i,
  14033. s = t.bias,
  14034. c = t.activation,
  14035. l = void 0 === c ? "linear" : c,
  14036. h = t.preluActivationWeights;
  14037. if (!1 === mh(Nt.state.gradientDepth, l)) {
  14038. var f = Wc(n, r, a, u);
  14039. return null != s && (f = Vs(f, s)), xh(f, l, h);
  14040. }
  14041. var p = ln(n, "a", "fused matMul"),
  14042. d = ln(r, "b", "fused matMul");
  14043. e = Rt(p, d), p = e[0], d = e[1];
  14044. var v = a ? p.shape[p.rank - 2] : p.shape[p.rank - 1],
  14045. m = u ? d.shape[d.rank - 1] : d.shape[d.rank - 2],
  14046. y = a ? p.shape[p.rank - 1] : p.shape[p.rank - 2],
  14047. x = u ? d.shape[d.rank - 2] : d.shape[d.rank - 1],
  14048. b = p.shape.slice(0, -2),
  14049. E = d.shape.slice(0, -2),
  14050. R = w(b),
  14051. I = w(E);
  14052. g(p.rank >= 2 && d.rank >= 2 && p.rank === d.rank, function () {
  14053. return "Error in fused matMul: inputs must have the same rank of at least 2, got ranks " + p.rank + " and " + d.rank + ".";
  14054. }), g(C(b, E), function () {
  14055. return "Error in fused matMul: outer dimensions (" + b + ") and (" + E + ") of Tensors with shapes " + p.shape + " and " + d.shape + " must match.";
  14056. }), g(v === m, function () {
  14057. return "Error in fused matMul: inner shapes (" + v + ") and (" + m + ") of Tensors with shapes " + p.shape + " and " + d.shape + " and transposeA=" + a + " and transposeB=" + u + " must match.";
  14058. });
  14059. var k,
  14060. S,
  14061. A = p.shape.slice(0, -2).concat([y, x]),
  14062. D = a ? p.as3D(R, v, y) : p.as3D(R, y, v),
  14063. T = u ? d.as3D(I, x, m) : d.as3D(I, m, x);
  14064. null != s && po(A, (k = Rt(k = ln(s, "bias", "fused matMul"), p)[0]).shape), null != h && (S = ln(h, "prelu weights", "fused matMul"));
  14065. var N = {
  14066. $a: D,
  14067. $b: T
  14068. };
  14069. return null != s && (N.$bias = k), null != h && (N.$preluActivationWeights = S), Nt.runKernelFunc(function (t, e) {
  14070. var n = t.fusedBatchMatMul({
  14071. a: D,
  14072. b: T,
  14073. transposeA: a,
  14074. transposeB: u,
  14075. bias: k,
  14076. activation: l,
  14077. preluActivationWeights: S
  14078. });
  14079. return e([D, T, n]), n;
  14080. }, N, function (t, e) {
  14081. var n = e[0],
  14082. r = e[1],
  14083. o = e[2],
  14084. i = gh(t, o, l),
  14085. c = {};
  14086. return null != s && (c = {
  14087. $bias: function () {
  14088. return yh(k, i);
  14089. }
  14090. }), a || u ? !a && u ? Object.assign({
  14091. $a: function () {
  14092. return i.matMul(r, !1, !1);
  14093. },
  14094. $b: function () {
  14095. return i.matMul(n, !0, !1);
  14096. }
  14097. }, c) : a && !u ? Object.assign({
  14098. $a: function () {
  14099. return r.matMul(i, !1, !0);
  14100. },
  14101. $b: function () {
  14102. return n.matMul(i, !1, !1);
  14103. }
  14104. }, c) : Object.assign({
  14105. $a: function () {
  14106. return r.matMul(i, !0, !0);
  14107. },
  14108. $b: function () {
  14109. return i.matMul(n, !0, !0);
  14110. }
  14111. }, c) : Object.assign({
  14112. $a: function () {
  14113. return i.matMul(r, !1, !0);
  14114. },
  14115. $b: function () {
  14116. return n.matMul(i, !0, !1);
  14117. }
  14118. }, c);
  14119. }).reshape(A);
  14120. }
  14121. }),
  14122. wh = Cn({
  14123. conv2d_: function (t) {
  14124. var e = t.x,
  14125. n = t.filter,
  14126. r = t.strides,
  14127. o = t.pad,
  14128. a = t.dataFormat,
  14129. i = void 0 === a ? "NHWC" : a,
  14130. u = t.dilations,
  14131. s = void 0 === u ? [1, 1] : u,
  14132. c = t.dimRoundingMode,
  14133. l = t.bias,
  14134. h = t.activation,
  14135. f = void 0 === h ? "linear" : h,
  14136. p = t.preluActivationWeights;
  14137. if (f = f || "linear", !1 === mh(Nt.state.gradientDepth, f)) {
  14138. var d = Dc(e, n, r, o, i, s, c);
  14139. return null != l && (d = Vs(d, l)), xh(d, f, p);
  14140. }
  14141. var v = ln(e, "x", "conv2d"),
  14142. m = ln(n, "filter", "conv2d"),
  14143. y = v,
  14144. x = !1;
  14145. 3 === v.rank && (x = !0, y = v.as4D(1, v.shape[0], v.shape[1], v.shape[2])), g(4 === y.rank, function () {
  14146. return "Error in fused conv2d: input must be rank 4, but got rank " + y.rank + ".";
  14147. }), g(4 === m.rank, function () {
  14148. return "Error in fused conv2d: filter must be rank 4, but got rank " + m.rank + ".";
  14149. }), null != c && g(E(o), function () {
  14150. return "Error in fused conv2d: pad must be an integer when using, dimRoundingMode " + c + " but got pad " + o + ".";
  14151. }), g(y.shape[3] === m.shape[2], function () {
  14152. return "Error in conv2d: depth of input (" + y.shape[3] + ") must match input depth for filter " + m.shape[2] + ".";
  14153. }), g(Io(r, s), function () {
  14154. return "Error in conv2D: Either strides or dilations must be 1. Got strides " + r + " and dilations '" + s + "'";
  14155. }), g("NHWC" === i, function () {
  14156. return "Error in conv2d: got dataFormat of " + i + " but only NHWC is currently supported.";
  14157. });
  14158. var b,
  14159. w,
  14160. C = go(y.shape, m.shape, r, s, o, c);
  14161. null != l && (b = Rt(b = ln(l, "bias", "fused conv2d"), v)[0], po(C.outShape, b.shape)), null != p && (w = ln(p, "prelu weights", "fused conv2d"));
  14162. var R = {
  14163. x: y,
  14164. $filter: m
  14165. };
  14166. null != l && (R.$bias = b), null != p && (R.$preluActivationWeights = w);
  14167. var I = Nt.runKernelFunc(function (t, e) {
  14168. var n = t.fusedConv2d({
  14169. input: y,
  14170. filter: m,
  14171. convInfo: C,
  14172. bias: b,
  14173. activation: f,
  14174. preluActivationWeights: w
  14175. });
  14176. return e([m, y, n]), n;
  14177. }, R, function (t, e) {
  14178. var n = e,
  14179. a = n[0],
  14180. i = n[1],
  14181. u = n[2],
  14182. c = gh(t, u, f);
  14183. g(Ro(s), function () {
  14184. return "Error in gradient of fused conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '" + s + "'";
  14185. });
  14186. var h = {};
  14187. return null != l && (h = {
  14188. $bias: function () {
  14189. return yh(b, c);
  14190. }
  14191. }), Object.assign({
  14192. x: function () {
  14193. return Fc(i.shape, c, a, r, o);
  14194. },
  14195. $filter: function () {
  14196. return Nc(i, c, a.shape, r, o);
  14197. }
  14198. }, h);
  14199. });
  14200. return x ? I.as3D(I.shape[1], I.shape[2], I.shape[3]) : I;
  14201. }
  14202. }),
  14203. Ch = Cn({
  14204. depthwiseConv2d_: function (t) {
  14205. var e = t.x,
  14206. n = t.filter,
  14207. r = t.strides,
  14208. o = t.pad,
  14209. a = t.dataFormat,
  14210. i = void 0 === a ? "NHWC" : a,
  14211. u = t.dilations,
  14212. s = void 0 === u ? [1, 1] : u,
  14213. c = t.dimRoundingMode,
  14214. l = t.bias,
  14215. h = t.activation,
  14216. f = void 0 === h ? "linear" : h,
  14217. p = t.preluActivationWeights;
  14218. if (!1 === mh(Nt.state.gradientDepth, f)) {
  14219. var d = Oc(e, n, r, o, i, s, c);
  14220. return null != l && (d = Vs(d, l)), xh(d, f, p);
  14221. }
  14222. var v = ln(e, "x", "depthwiseConv2d"),
  14223. m = ln(n, "filter", "depthwiseConv2d"),
  14224. y = v,
  14225. x = !1;
  14226. 3 === v.rank && (x = !0, y = v.as4D(1, v.shape[0], v.shape[1], v.shape[2])), g(4 === y.rank, function () {
  14227. return "Error in fused depthwiseConv2d: input must be rank 4, but got rank " + y.rank + ".";
  14228. }), g(4 === m.rank, function () {
  14229. return "Error in fused depthwiseConv2d: filter must be rank 4, but got rank " + m.rank + ".";
  14230. }), g(y.shape[3] === m.shape[2], function () {
  14231. return "Error in fused depthwiseConv2d: number of input channels (" + y.shape[3] + ") must match the inChannels dimension in filter " + m.shape[2] + ".";
  14232. }), null == s && (s = [1, 1]), g(Io(r, s), function () {
  14233. return "Error in fused depthwiseConv2d: Either strides or dilations must be 1. Got strides " + r + " and dilations '" + s + "'";
  14234. }), null != c && g(E(o), function () {
  14235. return "Error in fused depthwiseConv2d: pad must be an integer when using dimRoundingMode " + c + " but got pad " + o + ".";
  14236. });
  14237. var b,
  14238. w,
  14239. C = go(y.shape, m.shape, r, s, o, c, !0);
  14240. null != l && (b = Rt(b = ln(l, "bias", "fused conv2d"), v)[0], po(C.outShape, b.shape)), null != p && (w = ln(p, "prelu weights", "fused depthwiseConv2d"));
  14241. var R = {
  14242. x: y,
  14243. $filter: m
  14244. };
  14245. null != l && (R.$bias = b), null != p && (R.$preluActivationWeights = w);
  14246. var I = Nt.runKernelFunc(function (t, e) {
  14247. var n = t.fusedDepthwiseConv2D({
  14248. input: y,
  14249. filter: m,
  14250. convInfo: C,
  14251. bias: b,
  14252. activation: f,
  14253. preluActivationWeights: w
  14254. });
  14255. return e([y, m, n]), n;
  14256. }, R, function (t, e) {
  14257. g(Ro(s), function () {
  14258. return "Error in gradient of fused depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '" + s + "'";
  14259. });
  14260. var n = e[0],
  14261. r = e[1],
  14262. o = e[2],
  14263. a = gh(t, o, f),
  14264. i = {};
  14265. return null != l && (i = {
  14266. $bias: function () {
  14267. return yh(b, a);
  14268. }
  14269. }), Object.assign({
  14270. x: function () {
  14271. return _c(n.shape, a, r, C);
  14272. },
  14273. $filter: function () {
  14274. return Mc(n, a, r.shape, C);
  14275. }
  14276. }, i);
  14277. });
  14278. return x ? I.as3D(I.shape[1], I.shape[2], I.shape[3]) : I;
  14279. }
  14280. }),
  14281. Eh = Object.freeze({
  14282. matMul: bh,
  14283. conv2d: wh,
  14284. depthwiseConv2d: Ch
  14285. }),
  14286. Rh = Object.freeze({
  14287. image: vh,
  14288. linalg: sh,
  14289. losses: oh,
  14290. spectral: Bl,
  14291. fused: Eh,
  14292. signal: Kl,
  14293. square: Uu,
  14294. conv1d: Ac,
  14295. conv2d: Dc,
  14296. conv3d: Tc,
  14297. depthwiseConv2d: Oc,
  14298. separableConv2d: Bc,
  14299. conv2dTranspose: Pc,
  14300. conv3dTranspose: Lc,
  14301. op: Cn,
  14302. batchNormalization2d: Ss,
  14303. batchNormalization3d: As,
  14304. batchNormalization4d: Ds,
  14305. batchNormalization: Ts,
  14306. batchNorm: Ns,
  14307. batchNorm2d: Fs,
  14308. batchNorm3d: Os,
  14309. batchNorm4d: _s,
  14310. booleanMaskAsync: Rc,
  14311. complex: En,
  14312. real: Rn,
  14313. imag: In,
  14314. concat: Gn,
  14315. concat1d: Hn,
  14316. concat2d: qn,
  14317. concat3d: Kn,
  14318. concat4d: jn,
  14319. split: Xn,
  14320. matMul: Wc,
  14321. dot: Uc,
  14322. outerProduct: Vc,
  14323. reverse: zc,
  14324. reverse1d: Gc,
  14325. reverse2d: Hc,
  14326. reverse3d: qc,
  14327. reverse4d: Kc,
  14328. maxPool: $c,
  14329. avgPool: Yc,
  14330. pool: Qc,
  14331. maxPool3d: Jc,
  14332. avgPool3d: Zc,
  14333. slice: tl,
  14334. slice1d: el,
  14335. slice2d: nl,
  14336. slice3d: rl,
  14337. slice4d: ol,
  14338. abs: Vu,
  14339. acos: zu,
  14340. acosh: Gu,
  14341. asin: Hu,
  14342. asinh: qu,
  14343. atan: Ku,
  14344. atanh: ju,
  14345. ceil: Xu,
  14346. clipByValue: $u,
  14347. cos: Yu,
  14348. cosh: Qu,
  14349. erf: Ju,
  14350. exp: Zu,
  14351. expm1: ts,
  14352. floor: es,
  14353. log: ns,
  14354. log1p: rs,
  14355. logSigmoid: os,
  14356. neg: as,
  14357. reciprocal: is,
  14358. round: us,
  14359. rsqrt: ss,
  14360. sigmoid: cs,
  14361. sign: ls,
  14362. isNaN: hs,
  14363. isInf: fs,
  14364. isFinite: ps,
  14365. sin: ds,
  14366. sinh: vs,
  14367. softplus: ms,
  14368. sqrt: gs,
  14369. step: ys,
  14370. tan: xs,
  14371. tanh: bs,
  14372. all: il,
  14373. any: ul,
  14374. argMax: sl,
  14375. argMin: cl,
  14376. logSumExp: ll,
  14377. max: hl,
  14378. mean: fl,
  14379. min: pl,
  14380. moments: dl,
  14381. sum: vl,
  14382. prod: ml,
  14383. equal: sc,
  14384. equalStrict: cc,
  14385. greater: lc,
  14386. greaterEqual: hc,
  14387. greaterEqualStrict: fc,
  14388. greaterStrict: pc,
  14389. less: dc,
  14390. lessEqual: vc,
  14391. lessEqualStrict: mc,
  14392. lessStrict: gc,
  14393. notEqual: yc,
  14394. notEqualStrict: xc,
  14395. add: Vs,
  14396. addN: zs,
  14397. addStrict: Gs,
  14398. atan2: Hs,
  14399. div: qs,
  14400. divStrict: Ks,
  14401. floorDiv: js,
  14402. maximum: Xs,
  14403. maximumStrict: $s,
  14404. minimum: Ys,
  14405. minimumStrict: Qs,
  14406. mod: Js,
  14407. modStrict: Zs,
  14408. mul: tc,
  14409. mulStrict: ec,
  14410. pow: nc,
  14411. powStrict: rc,
  14412. squaredDifference: oc,
  14413. squaredDifferenceStrict: ac,
  14414. sub: ic,
  14415. subStrict: uc,
  14416. elu: gl,
  14417. leakyRelu: yl,
  14418. prelu: xl,
  14419. relu: bl,
  14420. relu6: wl,
  14421. selu: Cl,
  14422. logicalAnd: Ms,
  14423. logicalNot: Bs,
  14424. logicalOr: Ps,
  14425. logicalXor: Ls,
  14426. where: Ws,
  14427. whereAsync: Us,
  14428. buffer: ur,
  14429. print: sr,
  14430. batchToSpaceND: cr,
  14431. cast: lr,
  14432. clone: hr,
  14433. cumsum: fr,
  14434. depthToSpace: pr,
  14435. expandDims: dr,
  14436. eye: vr,
  14437. multinomial: mr,
  14438. oneHot: gr,
  14439. pad: yr,
  14440. pad1d: xr,
  14441. pad2d: br,
  14442. pad3d: wr,
  14443. pad4d: Cr,
  14444. rand: Er,
  14445. randomNormal: Rr,
  14446. randomGamma: Ir,
  14447. randomUniform: kr,
  14448. reshape: Sr,
  14449. spaceToBatchND: Ar,
  14450. squeeze: Dr,
  14451. stack: Tr,
  14452. tile: Nr,
  14453. truncatedNormal: Fr,
  14454. unstack: Or,
  14455. setdiff1dAsync: _r,
  14456. fill: Ln,
  14457. linspace: Wn,
  14458. ones: Bn,
  14459. range: Un,
  14460. scalar: An,
  14461. tensor: kn,
  14462. tensor1d: Dn,
  14463. tensor2d: Tn,
  14464. tensor3d: Nn,
  14465. tensor4d: Fn,
  14466. tensor5d: On,
  14467. tensor6d: _n,
  14468. variable: Mn,
  14469. zeros: Pn,
  14470. onesLike: Vn,
  14471. zerosLike: zn,
  14472. transpose: El,
  14473. softmax: io,
  14474. logSoftmax: uo,
  14475. localResponseNormalization: Rl,
  14476. norm: Il,
  14477. gather: Cc,
  14478. unsortedSegmentSum: Ec,
  14479. basicLSTMCell: kl,
  14480. multiRNNCell: Sl,
  14481. movingAverage: Al,
  14482. stridedSlice: Dl,
  14483. topk: Tl,
  14484. scatterND: Nl,
  14485. fft: Fl,
  14486. ifft: Ol,
  14487. rfft: _l,
  14488. irfft: Ml,
  14489. sparseToDense: Pl,
  14490. gatherND: Ll,
  14491. diag: Wl,
  14492. dropout: Ul,
  14493. hannWindow: zl,
  14494. hammingWindow: Gl,
  14495. frame: Hl,
  14496. stft: ql,
  14497. inTopKAsync: Xl
  14498. });
  14499. exports.fused = Eh;
  14500. function Ih(t, e) {
  14501. Array.isArray(t) || (t = [t]), t.forEach(function (t) {
  14502. null != t && g("complex64" !== t.dtype, function () {
  14503. return e + " does not support complex64 tensors.";
  14504. });
  14505. });
  14506. }
  14507. function kh(t, e, n, r) {
  14508. if ("linear" === n) return t.linear(e);
  14509. if ("relu" === n) return t.relu(e);
  14510. if ("elu" === n) return t.elu(e);
  14511. if ("relu6" === n) return t.relu6(e);
  14512. if ("prelu" === n) return t.prelu(e, r);
  14513. throw new Error("Activation " + n + " has not been implemented for the CPU backend.");
  14514. }
  14515. var Sh = function (t) {
  14516. function o() {
  14517. var e = t.call(this) || this;
  14518. if (e.blockSize = 48, e.firstUse = !0, a().get("IS_BROWSER")) {
  14519. var n = "undefined" != typeof OffscreenCanvas ? new OffscreenCanvas(300, 150) : "undefined" != typeof document ? document.createElement("canvas") : null;
  14520. null !== n && (e.fromPixels2DContext = n.getContext("2d"));
  14521. }
  14522. return e.data = new so(e, Nt), e;
  14523. }
  14524. return e(o, t), o.prototype.write = function (t, e, n) {
  14525. this.firstUse && (this.firstUse = !1, a().get("IS_NODE") && un("\n============================\nHi there 👋. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node, or npm i @tensorflow/tfjs-node-gpu if you have CUDA. Then call require('@tensorflow/tfjs-node'); (-gpu suffix for CUDA) at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details.\n============================\n"));
  14526. var r = {};
  14527. return this.data.set(r, {
  14528. values: t,
  14529. dtype: n
  14530. }), r;
  14531. }, o.prototype.move = function (t, e, n, r) {
  14532. this.data.set(t, {
  14533. values: e,
  14534. dtype: r
  14535. });
  14536. }, o.prototype.numDataIds = function () {
  14537. return this.data.numDataIds();
  14538. }, o.prototype.fromPixels = function (t, e) {
  14539. if (null == t) throw new Error("pixels passed to tf.browser.fromPixels() can not be null");
  14540. var n,
  14541. r,
  14542. o = t.data instanceof Uint8Array,
  14543. i = "undefined" != typeof ImageData && t instanceof ImageData,
  14544. u = "undefined" != typeof HTMLVideoElement && t instanceof HTMLVideoElement,
  14545. s = "undefined" != typeof HTMLImageElement && t instanceof HTMLImageElement,
  14546. c = u ? [t.videoWidth, t.videoHeight] : [t.width, t.height],
  14547. l = c[0],
  14548. h = c[1];
  14549. if (a().get("IS_NODE") && null == t.getContext) throw new Error("When running in node, pixels must be an HTMLCanvasElement like the one returned by the `canvas` npm package");
  14550. if (null != t.getContext) n = t.getContext("2d").getImageData(0, 0, l, h).data; else if (i || o) n = t.data; else {
  14551. if (!s && !u) throw new Error("pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData or {data: Uint32Array, width: number, height: number}, but was " + t.constructor.name);
  14552. if (null == this.fromPixels2DContext) throw new Error("Can't read pixels from HTMLImageElement outside the browser.");
  14553. this.fromPixels2DContext.canvas.width = l, this.fromPixels2DContext.canvas.height = h, this.fromPixels2DContext.drawImage(t, 0, 0, l, h), n = this.fromPixels2DContext.getImageData(0, 0, l, h).data;
  14554. }
  14555. if (4 === e) r = new Int32Array(n); else {
  14556. var f = l * h;
  14557. r = new Int32Array(f * e);
  14558. for (var p = 0; p < f; p++) for (var d = 0; d < e; ++d) r[p * e + d] = n[4 * p + d];
  14559. }
  14560. return Nn(r, [h, l, e], "int32");
  14561. }, o.prototype.read = function (t) {
  14562. return n(this, void 0, void 0, function () {
  14563. return r(this, function (e) {
  14564. return [2, this.readSync(t)];
  14565. });
  14566. });
  14567. }, o.prototype.readSync = function (t) {
  14568. var e = this.data.get(t),
  14569. n = e.dtype,
  14570. r = e.complexTensors;
  14571. return "complex64" === n ? No(this.readSync(r.real.dataId), this.readSync(r.imag.dataId)) : this.data.get(t).values;
  14572. }, o.prototype.bufferSync = function (t) {
  14573. var e = this.readSync(t.dataId),
  14574. n = e;
  14575. if ("string" === t.dtype) try {
  14576. n = e.map(function (t) {
  14577. return Z(t);
  14578. });
  14579. } catch (t) {
  14580. throw new Error("Failed to decode encoded string bytes into utf-8");
  14581. }
  14582. return ur(t.shape, t.dtype, n);
  14583. }, o.prototype.makeOutput = function (t, e, n) {
  14584. var r = this.write(t, e, n);
  14585. return Nt.makeTensorFromDataId(r, e, n, this);
  14586. }, o.prototype.disposeData = function (t) {
  14587. if (this.data.has(t)) {
  14588. var e = this.data.get(t).complexTensors;
  14589. null != e && (e.real.dispose(), e.imag.dispose()), this.data.delete(t);
  14590. }
  14591. }, o.prototype.time = function (t) {
  14592. return n(this, void 0, void 0, function () {
  14593. var e;
  14594. return r(this, function (n) {
  14595. return e = Y(), t(), [2, {
  14596. kernelMs: Y() - e
  14597. }];
  14598. });
  14599. });
  14600. }, o.prototype.memory = function () {
  14601. return {
  14602. unreliable: !0,
  14603. reasons: ["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]
  14604. };
  14605. }, o.prototype.complex = function (t, e) {
  14606. var n = this.makeOutput(null, t.shape, "complex64");
  14607. return this.data.get(n.dataId).complexTensors = {
  14608. real: Nt.keep(t.clone()),
  14609. imag: Nt.keep(e.clone())
  14610. }, n;
  14611. }, o.prototype.real = function (t) {
  14612. return this.data.get(t.dataId).complexTensors.real.clone();
  14613. }, o.prototype.imag = function (t) {
  14614. return this.data.get(t.dataId).complexTensors.imag.clone();
  14615. }, o.prototype.slice = function (t, e, n) {
  14616. if (Ih(t, "slice"), Yr(t.shape, e, n)) {
  14617. var r = Qr(e, t.strides),
  14618. o = w(n);
  14619. return kn(this.readSync(t.dataId).subarray(r, r + o), n, t.dtype);
  14620. }
  14621. for (var a = ur(n, t.dtype), i = this.bufferSync(t), u = 0; u < a.size; ++u) {
  14622. var s = a.indexToLoc(u).map(function (t, n) {
  14623. return t + e[n];
  14624. });
  14625. a.values[u] = i.get.apply(i, s);
  14626. }
  14627. return a.toTensor();
  14628. }, o.prototype.stridedSlice = function (t, e, n, r) {
  14629. Ih(t, "stridedSlice");
  14630. var o = jr(e, n, r);
  14631. if (o.some(function (t) {
  14632. return 0 === t;
  14633. })) return kn([], o);
  14634. for (var a = ur(o, t.dtype), i = this.bufferSync(t), u = 0; u < a.size; u++) {
  14635. for (var s = a.indexToLoc(u), c = new Array(s.length), l = 0; l < c.length; l++) c[l] = s[l] * r[l] + e[l];
  14636. a.set.apply(a, [i.get.apply(i, c)].concat(s));
  14637. }
  14638. return a.toTensor();
  14639. }, o.prototype.diag = function (t) {
  14640. for (var e = this.readSync(t.dataId), n = ur([t.size, t.size], t.dtype), r = n.values, o = 0; o < e.length; o++) r[o * t.size + o] = e[o];
  14641. return n.toTensor();
  14642. }, o.prototype.unstack = function (t, e) {
  14643. for (var n = t.shape[e], r = new Array(t.rank - 1), o = 0, a = 0; a < t.rank; a++) a !== e && (r[o++] = t.shape[a]);
  14644. var i = new Array(t.rank).fill(0),
  14645. u = t.shape.slice();
  14646. u[e] = 1;
  14647. var s = new Array(n);
  14648. for (a = 0; a < s.length; a++) i[e] = a, s[a] = this.slice(t, i, u).reshape(r);
  14649. return s;
  14650. }, o.prototype.reverse = function (t, e) {
  14651. Ih(t, "reverse");
  14652. for (var n = ur(t.shape, t.dtype), r = this.bufferSync(t), o = function (o) {
  14653. var a = n.indexToLoc(o),
  14654. i = a.slice();
  14655. e.forEach(function (e) {
  14656. return i[e] = t.shape[e] - 1 - i[e];
  14657. }), n.set.apply(n, [r.get.apply(r, i)].concat(a));
  14658. }, a = 0; a < n.size; a++) o(a);
  14659. return n.toTensor();
  14660. }, o.prototype.concat = function (t, e) {
  14661. var n = this;
  14662. if ("complex64" === t[0].dtype) {
  14663. var r = t.map(function (t) {
  14664. return Rn(t);
  14665. }),
  14666. o = t.map(function (t) {
  14667. return In(t);
  14668. });
  14669. return En(this.concat(r, e), this.concat(o, e));
  14670. }
  14671. var a = t.map(function (t) {
  14672. var n = w(t.shape.slice(e));
  14673. return t.as2D(-1, n);
  14674. }),
  14675. i = wn(a.map(function (t) {
  14676. return t.shape;
  14677. }), 1),
  14678. u = ur(i, t[0].dtype).values;
  14679. if (1 === a[0].shape[0]) {
  14680. var s = 0;
  14681. a.forEach(function (t) {
  14682. u.set(n.readSync(t.dataId), s), s += t.size;
  14683. });
  14684. } else {
  14685. var c = 0;
  14686. a.forEach(function (t) {
  14687. for (var e = n.readSync(t.dataId), r = 0, o = 0; o < t.shape[0]; ++o) for (var a = o * i[1] + c, s = 0; s < t.shape[1]; ++s) u[a + s] = e[r++];
  14688. c += t.shape[1];
  14689. });
  14690. }
  14691. var l = wn(t.map(function (t) {
  14692. return t.shape;
  14693. }), e);
  14694. return kn(u, l, t[0].dtype);
  14695. }, o.prototype.neg = function (t) {
  14696. return Ih(t, "neg"), this.multiply(An(-1), t);
  14697. }, o.prototype.add = function (t, e) {
  14698. return "complex64" === t.dtype || "complex64" === e.dtype ? this.broadcastedBinaryComplexOp(t.cast("complex64"), e.cast("complex64"), function (t, e, n, r) {
  14699. return {
  14700. real: t + n,
  14701. imag: e + r
  14702. };
  14703. }) : this.broadcastedBinaryOp(t, e, Ct(t.dtype, e.dtype), function (t, e) {
  14704. return t + e;
  14705. });
  14706. }, o.prototype.addN = function (t) {
  14707. var e = this;
  14708. Ih(t, "addN");
  14709. for (var n = t.map(function (t) {
  14710. return e.readSync(t.dataId);
  14711. }), r = ur(t[0].shape, t[0].dtype), o = r.values, a = 0; a < t.length; a++) for (var i = n[a], u = 0; u < o.length; u++) o[u] += i[u];
  14712. return r.toTensor();
  14713. }, o.prototype.subtract = function (t, e) {
  14714. return "complex64" === t.dtype || "complex64" === e.dtype ? this.broadcastedBinaryComplexOp(t.cast("complex64"), e.cast("complex64"), function (t, e, n, r) {
  14715. return {
  14716. real: t - n,
  14717. imag: e - r
  14718. };
  14719. }) : this.broadcastedBinaryOp(t, e, Ct(t.dtype, e.dtype), function (t, e) {
  14720. return t - e;
  14721. });
  14722. }, o.prototype.pow = function (t, e) {
  14723. return Ih([t, e], "pow"), this.broadcastedBinaryOp(t, e, t.dtype, function (t, e) {
  14724. return Math.pow(t, e);
  14725. });
  14726. }, o.prototype.batchMatMul = function (t, e, n, r) {
  14727. Ih([t, e], "matMul");
  14728. for (var o = n ? t.shape[1] : t.shape[2], a = n ? t.shape[2] : t.shape[1], i = r ? e.shape[1] : e.shape[2], u = t.shape[0], s = this.readSync(t.dataId), c = this.readSync(e.dataId), l = n ? [t.strides[0], 1, t.strides[1]] : [t.strides[0], t.strides[1], 1], h = l[0], f = l[1], p = l[2], d = r ? [1, e.strides[1], e.strides[0]] : [e.strides[1], 1, e.strides[0]], v = d[0], m = d[1], g = d[2], y = a * i, x = ur([u, a, i], t.dtype), b = x.values, w = this.blockSize, C = 0; C < u; C++) for (var E = 0; E < a; E += w) for (var R = 0; R < i; R += w) for (var I = 0; I < o; I += w) for (var k = Math.min(E + w, a), S = Math.min(R + w, i), A = Math.min(I + w, o), D = E; D < k; D++) for (var T = R; T < S; T++) {
  14729. for (var N = 0, F = I; F < A; F++) N += s[C * h + D * f + F * p] * c[F * v + T * m + C * g];
  14730. b[C * y + (D * i + T)] += N;
  14731. }
  14732. return x.toTensor();
  14733. }, o.prototype.fusedBatchMatMul = function (t) {
  14734. var e = t.a,
  14735. n = t.b,
  14736. r = t.transposeA,
  14737. o = t.transposeB,
  14738. a = t.bias,
  14739. i = t.activation,
  14740. u = t.preluActivationWeights,
  14741. s = this.batchMatMul(e, n, r, o);
  14742. return a && (s = this.add(s, a)), i && (s = kh(this, s, i, u)), s;
  14743. }, o.prototype.multiply = function (t, e) {
  14744. return "complex64" === t.dtype || "complex64" === e.dtype ? this.broadcastedBinaryComplexOp(t.cast("complex64"), e.cast("complex64"), function (t, e, n, r) {
  14745. return {
  14746. real: t * n - e * r,
  14747. imag: t * r + e * n
  14748. };
  14749. }) : this.broadcastedBinaryOp(t, e, Ct(t.dtype, e.dtype), function (t, e) {
  14750. return t * e;
  14751. });
  14752. }, o.prototype.realDivide = function (t, e) {
  14753. Ih([t, e], "realDivide");
  14754. return this.broadcastedBinaryOp(t, e, "float32", function (t, e) {
  14755. return t / e;
  14756. });
  14757. }, o.prototype.floorDiv = function (t, e) {
  14758. Ih([t, e], "floorDiv");
  14759. return this.broadcastedBinaryOp(t, e, "int32", function (t, e) {
  14760. return Math.floor(t / e);
  14761. });
  14762. }, o.prototype.sum = function (t, e) {
  14763. Ih(t, "sum"), mn("sum", e, t.rank);
  14764. for (var n = dn(t.shape, e), r = n[0], o = n[1], a = Pn(r, Ct(t.dtype, "int32")), i = w(o), u = this.readSync(a.dataId), s = this.readSync(t.dataId), c = 0; c < u.length; ++c) {
  14765. for (var l = c * i, h = 0, f = 0; f < i; ++f) h += s[l + f];
  14766. u[c] = h;
  14767. }
  14768. return a;
  14769. }, o.prototype.prod = function (t, e) {
  14770. Ih(t, "sum");
  14771. for (var n = dn(t.shape, e), r = n[0], o = n[1], a = Pn(r, Ct(t.dtype, "int32")), i = w(o), u = this.readSync(a.dataId), s = this.readSync(t.dataId), c = 0; c < u.length; ++c) {
  14772. for (var l = c * i, h = 1, f = 0; f < i; ++f) h *= s[l + f];
  14773. u[c] = h;
  14774. }
  14775. return a;
  14776. }, o.prototype.unsortedSegmentSum = function (t, e, n) {
  14777. Ih(t, "unsortedSegmentSum");
  14778. for (var r = [], o = t.rank - e.rank, a = 0; a < o; ++a) e = e.expandDims(a + 1);
  14779. for (a = 0; a < n; ++a) {
  14780. var i = An(a, "int32"),
  14781. u = sc(i, e).asType("float32").mul(t).sum(0);
  14782. r.push(u);
  14783. }
  14784. return Tr(r);
  14785. }, o.prototype.argMin = function (t, e) {
  14786. Ih(t, "argMin");
  14787. var n = [e];
  14788. mn("argMin", n, t.rank);
  14789. for (var r = dn(t.shape, n), o = r[0], a = r[1], i = Pn(o, "int32"), u = w(a), s = this.readSync(i.dataId), c = this.readSync(t.dataId), l = 0; l < s.length; ++l) {
  14790. for (var h = l * u, f = c[h], p = 0, d = 0; d < u; ++d) {
  14791. var v = c[h + d];
  14792. v < f && (f = v, p = d);
  14793. }
  14794. s[l] = p;
  14795. }
  14796. return i;
  14797. }, o.prototype.argMax = function (t, e) {
  14798. Ih(t, "argMax");
  14799. var n = [e];
  14800. mn("argMax", n, t.rank);
  14801. for (var r = dn(t.shape, n), o = r[0], a = r[1], i = Pn(o, "int32"), u = w(a), s = this.readSync(i.dataId), c = this.readSync(t.dataId), l = 0; l < s.length; ++l) {
  14802. for (var h = l * u, f = c[h], p = 0, d = 0; d < u; ++d) {
  14803. var v = c[h + d];
  14804. v > f && (f = v, p = d);
  14805. }
  14806. s[l] = p;
  14807. }
  14808. return i;
  14809. }, o.prototype.cumsum = function (t, e, n, r) {
  14810. if (Ih(t, "cumsum"), e !== t.rank - 1) throw new Error("backend.cumsum in CPU expects an inner-most axis=" + (t.rank - 1) + " but got axis=" + e);
  14811. for (var o = Ct(t.dtype, "int32"), a = Pn(t.shape, o), i = this.readSync(a.dataId), u = this.readSync(t.dataId), s = t.shape[t.rank - 1], c = r ? function (t, e) {
  14812. return t + s - e - 1;
  14813. } : function (t, e) {
  14814. return t + e;
  14815. }, l = 0; l < u.length; l += s) for (var h = 0; h < s; h++) {
  14816. var f = c(l, h);
  14817. if (0 === h) i[f] = n ? 0 : u[f]; else {
  14818. var p = c(l, h - 1);
  14819. i[f] = n ? u[p] + i[p] : u[f] + i[p];
  14820. }
  14821. }
  14822. return a;
  14823. }, o.prototype.equal = function (t, e) {
  14824. return Ih([t, e], "equal"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
  14825. return t === e ? 1 : 0;
  14826. });
  14827. }, o.prototype.notEqual = function (t, e) {
  14828. return Ih([t, e], "notEqual"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
  14829. return t !== e ? 1 : 0;
  14830. });
  14831. }, o.prototype.less = function (t, e) {
  14832. return Ih([t, e], "less"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
  14833. return t < e ? 1 : 0;
  14834. });
  14835. }, o.prototype.lessEqual = function (t, e) {
  14836. return Ih([t, e], "lessEqual"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
  14837. return t <= e ? 1 : 0;
  14838. });
  14839. }, o.prototype.greater = function (t, e) {
  14840. return Ih([t, e], "greater"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
  14841. return t > e ? 1 : 0;
  14842. });
  14843. }, o.prototype.greaterEqual = function (t, e) {
  14844. return Ih([t, e], "greaterEqual"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
  14845. return t >= e ? 1 : 0;
  14846. });
  14847. }, o.prototype.logicalNot = function (t) {
  14848. Ih(t, "logicalNot");
  14849. for (var e = this.readSync(t.dataId), n = new Uint8Array(e.length), r = 0; r < e.length; ++r) n[r] = e[r] ? 0 : 1;
  14850. return this.makeOutput(n, t.shape, "bool");
  14851. }, o.prototype.logicalAnd = function (t, e) {
  14852. return Ih([t, e], "logicalAnd"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
  14853. return t && e;
  14854. });
  14855. }, o.prototype.logicalOr = function (t, e) {
  14856. return Ih([t, e], "logicalOr"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
  14857. return t || e;
  14858. });
  14859. }, o.prototype.select = function (t, e, n) {
  14860. Ih([t, e, n], "select");
  14861. for (var r = this.readSync(t.dataId), o = this.readSync(e.dataId), a = this.readSync(n.dataId), i = Pn(e.shape, Ct(e.dtype, n.dtype)), u = this.readSync(i.dataId), s = 0, c = 0 === t.rank || t.rank > 1 || 1 === e.rank ? 1 : w(e.shape.slice(1)), l = 0; l < r.length; l++) for (var h = 0; h < c; h++) 1 === r[l] ? u[s++] = o[l] : u[s++] = a[l];
  14862. return i;
  14863. }, o.prototype.where = function (t) {
  14864. Ih([t], "where");
  14865. var e = this.readSync(t.dataId);
  14866. return Uo(t.shape, e);
  14867. }, o.prototype.topk = function (t, e, n) {
  14868. return Ih(t, "topk"), Wo(this.readSync(t.dataId), t.shape, t.dtype, e);
  14869. }, o.prototype.min = function (t, e) {
  14870. Ih(t, "min"), mn("min", e, t.rank);
  14871. for (var n = dn(t.shape, e), r = n[0], o = n[1], a = Pn(r, t.dtype), i = w(o), u = this.readSync(a.dataId), s = this.readSync(t.dataId), c = 0; c < u.length; ++c) {
  14872. for (var l = c * i, h = s[l], f = 0; f < i; ++f) {
  14873. var p = s[l + f];
  14874. p < h && (h = p);
  14875. }
  14876. u[c] = h;
  14877. }
  14878. return a;
  14879. }, o.prototype.minimum = function (t, e) {
  14880. return Ih([t, e], "minimum"), this.broadcastedBinaryOp(t, e, t.dtype, function (t, e) {
  14881. return Math.min(t, e);
  14882. });
  14883. }, o.prototype.mod = function (t, e) {
  14884. return Ih([t, e], "mod"), this.broadcastedBinaryOp(t, e, t.dtype, function (t, e) {
  14885. var n = t % e;
  14886. return t < 0 && e < 0 || t >= 0 && e >= 0 ? n : (n + e) % e;
  14887. });
  14888. }, o.prototype.max = function (t, e) {
  14889. Ih(t, "max"), mn("max", e, t.rank);
  14890. for (var n = dn(t.shape, e), r = n[0], o = n[1], a = Pn(r, t.dtype), i = w(o), u = this.readSync(a.dataId), s = this.readSync(t.dataId), c = 0; c < u.length; ++c) {
  14891. for (var l = c * i, h = s[l], f = 0; f < i; ++f) {
  14892. var p = s[l + f];
  14893. p > h && (h = p);
  14894. }
  14895. u[c] = h;
  14896. }
  14897. return a;
  14898. }, o.prototype.maximum = function (t, e) {
  14899. return Ih([t, e], "maximum"), this.broadcastedBinaryOp(t, e, t.dtype, function (t, e) {
  14900. return Math.max(t, e);
  14901. });
  14902. }, o.prototype.all = function (t, e) {
  14903. Ih(t, "all"), mn("all", e, t.rank);
  14904. for (var n = dn(t.shape, e), r = n[0], o = n[1], a = Pn(r, t.dtype), i = w(o), u = this.readSync(a.dataId), s = this.readSync(t.dataId), c = 0; c < u.length; ++c) {
  14905. for (var l = c * i, h = s[l], f = 0; f < i; ++f) {
  14906. var p = s[l + f];
  14907. h = h && p;
  14908. }
  14909. u[c] = h;
  14910. }
  14911. return a;
  14912. }, o.prototype.any = function (t, e) {
  14913. Ih(t, "any"), mn("any", e, t.rank);
  14914. for (var n = dn(t.shape, e), r = n[0], o = n[1], a = Pn(r, t.dtype), i = w(o), u = this.readSync(a.dataId), s = this.readSync(t.dataId), c = 0; c < u.length; ++c) {
  14915. for (var l = c * i, h = s[l], f = 0; f < i; ++f) {
  14916. var p = s[l + f];
  14917. h = h || p;
  14918. }
  14919. u[c] = h;
  14920. }
  14921. return a;
  14922. }, o.prototype.squaredDifference = function (t, e) {
  14923. return Ih([t, e], "squaredDifference"), this.broadcastedBinaryOp(t, e, t.dtype, function (t, e) {
  14924. var n = t - e;
  14925. return n * n;
  14926. });
  14927. }, o.prototype.ceil = function (t) {
  14928. Ih(t, "ceil");
  14929. for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) n[r] = Math.ceil(e[r]);
  14930. return this.makeOutput(n, t.shape, "float32");
  14931. }, o.prototype.floor = function (t) {
  14932. Ih(t, "floor");
  14933. for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) n[r] = Math.floor(e[r]);
  14934. return this.makeOutput(n, t.shape, "float32");
  14935. }, o.prototype.sign = function (t) {
  14936. Ih(t, "x");
  14937. for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) e[r] < 0 ? n[r] = -1 : e[r] > 0 ? n[r] = 1 : n[r] = 0;
  14938. return this.makeOutput(n, t.shape, "float32");
  14939. }, o.prototype.isNaN = function (t) {
  14940. Ih(t, "x");
  14941. for (var e = this.readSync(t.dataId), n = new Uint8Array(e.length), r = 0; r < e.length; ++r) Number.isNaN(e[r]) && (n[r] = 1);
  14942. return this.makeOutput(n, t.shape, "bool");
  14943. }, o.prototype.isInf = function (t) {
  14944. Ih(t, "x");
  14945. for (var e = this.readSync(t.dataId), n = new Uint8Array(e.length), r = 0; r < e.length; ++r) Math.abs(e[r]) === 1 / 0 && (n[r] = 1);
  14946. return this.makeOutput(n, t.shape, "bool");
  14947. }, o.prototype.isFinite = function (t) {
  14948. Ih(t, "x");
  14949. for (var e = this.readSync(t.dataId), n = new Uint8Array(e.length), r = 0; r < e.length; ++r) Number.isFinite(e[r]) && (n[r] = 1);
  14950. return this.makeOutput(n, t.shape, "bool");
  14951. }, o.prototype.round = function (t) {
  14952. Ih(t, "round");
  14953. for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) {
  14954. var o = Math.floor(e[r]);
  14955. e[r] - o < .5 ? n[r] = Math.floor(e[r]) : e[r] - o > .5 ? n[r] = Math.ceil(e[r]) : n[r] = o % 2 == 0 ? o : o + 1;
  14956. }
  14957. return this.makeOutput(n, t.shape, "float32");
  14958. }, o.prototype.exp = function (t) {
  14959. Ih(t, "exp");
  14960. for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) n[r] = Math.exp(e[r]);
  14961. return this.makeOutput(n, t.shape, "float32");
  14962. }, o.prototype.expm1 = function (t) {
  14963. Ih(t, "expm1");
  14964. for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) n[r] = Math.expm1(e[r]);
  14965. return this.makeOutput(n, t.shape, "float32");
  14966. }, o.prototype.log = function (t) {
  14967. Ih(t, "log");
  14968. for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) {
  14969. var o = e[r];
  14970. n[r] = Math.log(o);
  14971. }
  14972. return this.makeOutput(n, t.shape, "float32");
  14973. }, o.prototype.log1p = function (t) {
  14974. Ih(t, "log1p");
  14975. for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) {
  14976. var o = e[r];
  14977. n[r] = Math.log1p(o);
  14978. }
  14979. return this.makeOutput(n, t.shape, "float32");
  14980. }, o.prototype.sqrt = function (t) {
  14981. Ih(t, "sqrt");
  14982. for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) {
  14983. var o = e[r];
  14984. n[r] = Math.sqrt(o);
  14985. }
  14986. return this.makeOutput(n, t.shape, "float32");
  14987. }, o.prototype.rsqrt = function (t) {
  14988. Ih(t, "rsqrt");
  14989. for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) {
  14990. var o = e[r];
  14991. n[r] = 1 / Math.sqrt(o);
  14992. }
  14993. return this.makeOutput(n, t.shape, "float32");
  14994. }, o.prototype.reciprocal = function (t) {
  14995. Ih(t, "reciprocal");
  14996. for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) n[r] = 1 / e[r];
  14997. return this.makeOutput(n, t.shape, "float32");
  14998. }, o.prototype.linear = function (t) {
  14999. return t;
  15000. }, o.prototype.relu = function (t) {
  15001. Ih(t, "relu");
  15002. for (var e = Pn(t.shape, t.dtype), n = this.readSync(e.dataId), r = this.readSync(t.dataId), o = 0; o < r.length; ++o) n[o] = Math.max(0, r[o]);
  15003. return e;
  15004. }, o.prototype.relu6 = function (t) {
  15005. Ih(t, "relu");
  15006. for (var e = Pn(t.shape, t.dtype), n = this.readSync(e.dataId), r = this.readSync(t.dataId), o = 0; o < r.length; ++o) n[o] = Math.min(Math.max(0, r[o]), 6);
  15007. return e;
  15008. }, o.prototype.prelu = function (t, e) {
  15009. return Ih([t, e], "prelu"), this.broadcastedBinaryOp(t, e, t.dtype, function (t, e) {
  15010. return t < 0 ? e * t : t;
  15011. });
  15012. }, o.prototype.elu = function (t) {
  15013. Ih(t, "elu");
  15014. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) {
  15015. var o = n[r];
  15016. e[r] = o >= 0 ? o : Math.exp(o) - 1;
  15017. }
  15018. return this.makeOutput(e, t.shape, "float32");
  15019. }, o.prototype.eluDer = function (t, e) {
  15020. Ih([t, e], "eluDer");
  15021. for (var n = new Float32Array(e.size), r = this.readSync(e.dataId), o = this.readSync(t.dataId), a = 0; a < r.length; ++a) {
  15022. var i = r[a];
  15023. n[a] = i >= 1 ? o[a] : o[a] * (i + 1);
  15024. }
  15025. return this.makeOutput(n, e.shape, "float32");
  15026. }, o.prototype.selu = function (t) {
  15027. Ih(t, "selu");
  15028. for (var e = iu, n = uu, r = new Float32Array(t.size), o = this.readSync(t.dataId), a = 0; a < o.length; ++a) {
  15029. var i = o[a];
  15030. r[a] = i >= 0 ? n * i : e * (Math.exp(i) - 1);
  15031. }
  15032. return this.makeOutput(r, t.shape, "float32");
  15033. }, o.prototype.clip = function (t, e, n) {
  15034. Ih(t, "clip");
  15035. for (var r = new Float32Array(t.size), o = this.readSync(t.dataId), a = 0; a < o.length; ++a) {
  15036. var i = o[a];
  15037. r[a] = i > n ? n : i < e ? e : i;
  15038. }
  15039. return this.makeOutput(r, t.shape, "float32");
  15040. }, o.prototype.abs = function (t) {
  15041. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.abs(n[r]);
  15042. return this.makeOutput(e, t.shape, "float32");
  15043. }, o.prototype.complexAbs = function (t) {
  15044. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < t.size; ++r) {
  15045. var o = n[2 * r],
  15046. a = n[2 * r + 1];
  15047. e[r] = Math.hypot(o, a);
  15048. }
  15049. return this.makeOutput(e, t.shape, "float32");
  15050. }, o.prototype.int = function (t) {
  15051. Ih(t, "int");
  15052. for (var e = new Int32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = n[r];
  15053. return this.makeOutput(e, t.shape, "int32");
  15054. }, o.prototype.sigmoid = function (t) {
  15055. Ih(t, "sigmoid");
  15056. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = 1 / (1 + Math.exp(-n[r]));
  15057. return this.makeOutput(e, t.shape, "float32");
  15058. }, o.prototype.softplus = function (t) {
  15059. Ih(t, "softplus");
  15060. for (var e = Math.log(1.1920928955078125e-7) + 2, n = new Float32Array(t.size), r = this.readSync(t.dataId), o = 0; o < r.length; ++o) {
  15061. var a = r[o] > -e,
  15062. i = r[o] < e,
  15063. u = Math.exp(r[o]),
  15064. s = void 0;
  15065. s = i ? u : a ? r[o] : Math.log(1 + u), n[o] = s;
  15066. }
  15067. return this.makeOutput(n, t.shape, "float32");
  15068. }, o.prototype.sin = function (t) {
  15069. Ih(t, "sin");
  15070. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.sin(n[r]);
  15071. return this.makeOutput(e, t.shape, "float32");
  15072. }, o.prototype.cos = function (t) {
  15073. Ih(t, "cos");
  15074. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.cos(n[r]);
  15075. return this.makeOutput(e, t.shape, "float32");
  15076. }, o.prototype.tan = function (t) {
  15077. Ih(t, "tan");
  15078. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.tan(n[r]);
  15079. return this.makeOutput(e, t.shape, "float32");
  15080. }, o.prototype.asin = function (t) {
  15081. Ih(t, "asin");
  15082. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.asin(n[r]);
  15083. return this.makeOutput(e, t.shape, "float32");
  15084. }, o.prototype.acos = function (t) {
  15085. Ih(t, "acos");
  15086. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.acos(n[r]);
  15087. return this.makeOutput(e, t.shape, "float32");
  15088. }, o.prototype.atan = function (t) {
  15089. Ih(t, "atan");
  15090. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.atan(n[r]);
  15091. return this.makeOutput(e, t.shape, "float32");
  15092. }, o.prototype.atan2 = function (t, e) {
  15093. return Ih([t, e], "atan2"), this.broadcastedBinaryOp(t, e, t.dtype, function (t, e) {
  15094. return Math.atan2(t, e);
  15095. });
  15096. }, o.prototype.sinh = function (t) {
  15097. Ih(t, "sinh");
  15098. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.sinh(n[r]);
  15099. return this.makeOutput(e, t.shape, "float32");
  15100. }, o.prototype.cosh = function (t) {
  15101. Ih(t, "cosh");
  15102. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.cosh(n[r]);
  15103. return this.makeOutput(e, t.shape, "float32");
  15104. }, o.prototype.tanh = function (t) {
  15105. Ih(t, "tanh");
  15106. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = R(n[r]);
  15107. return this.makeOutput(e, t.shape, "float32");
  15108. }, o.prototype.asinh = function (t) {
  15109. Ih(t, "asinh");
  15110. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.asinh(n[r]);
  15111. return this.makeOutput(e, t.shape, "float32");
  15112. }, o.prototype.acosh = function (t) {
  15113. Ih(t, "acosh");
  15114. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.acosh(n[r]);
  15115. return this.makeOutput(e, t.shape, "float32");
  15116. }, o.prototype.atanh = function (t) {
  15117. Ih(t, "atanh");
  15118. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.atanh(n[r]);
  15119. return this.makeOutput(e, t.shape, "float32");
  15120. }, o.prototype.erf = function (t) {
  15121. Ih(t, "erf");
  15122. for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) {
  15123. var o = Math.sign(n[r]),
  15124. a = Math.abs(n[r]),
  15125. i = 1 / (1 + .3275911 * a);
  15126. e[r] = o * (1 - ((((1.061405429 * i - 1.453152027) * i + 1.421413741) * i - .284496736) * i + .254829592) * i * Math.exp(-a * a));
  15127. }
  15128. return this.makeOutput(e, t.shape, "float32");
  15129. }, o.prototype.step = function (t, e) {
  15130. void 0 === e && (e = 0), Ih(t, "step");
  15131. for (var n = new Float32Array(t.size), r = this.readSync(t.dataId), o = 0; o < r.length; ++o) {
  15132. var a = r[o];
  15133. isNaN(a) ? n[o] = NaN : n[o] = a > 0 ? 1 : e;
  15134. }
  15135. return this.makeOutput(n, t.shape, "float32");
  15136. }, o.prototype.fusedConv2d = function (t) {
  15137. var e = t.input,
  15138. n = t.filter,
  15139. r = t.convInfo,
  15140. o = t.bias,
  15141. a = t.activation,
  15142. i = t.preluActivationWeights,
  15143. u = this.conv2d(e, n, r);
  15144. return o && (u = this.add(u, o)), a && (u = kh(this, u, a, i)), u;
  15145. }, o.prototype.conv2d = function (t, e, n) {
  15146. Ih([t, e], "conv2d");
  15147. for (var r = n.filterHeight, o = n.filterWidth, a = n.dilationHeight, i = n.dilationWidth, u = n.padInfo.left, s = n.padInfo.top, c = "channelsLast" === n.dataFormat, l = ur(n.outShape, t.dtype), h = t.strides[0], f = c ? t.strides[1] : t.strides[2], p = c ? t.strides[2] : 1, d = c ? 1 : t.strides[1], v = l.strides[0], m = c ? l.strides[1] : l.strides[2], g = c ? l.strides[2] : 1, y = c ? 1 : l.strides[1], x = this.readSync(t.dataId), b = this.readSync(e.dataId), w = l.values, C = 0; C < n.batchSize; ++C) for (var E = C * h, R = C * v, I = 0; I < n.outHeight; ++I) for (var k = R + I * m, S = I * n.strideHeight - s, A = 0; A < r; A++) {
  15148. var D = S + A * a;
  15149. if (!(D < 0 || D >= n.inHeight)) for (var T = A * e.strides[0], N = E + D * f, F = 0; F < n.outWidth; ++F) for (var O = k + F * g, _ = F * n.strideWidth - u, M = 0; M < o; M++) {
  15150. var B = _ + M * i;
  15151. if (!(B < 0 || B >= n.inWidth)) for (var P = N + B * p, L = T + M * e.strides[1], W = 0; W < n.inChannels; ++W) {
  15152. for (var U = x[P + W * d], V = 0; V < n.outChannels; ++V) w[O + V * y] += U * b[L + V];
  15153. L += n.outChannels;
  15154. }
  15155. }
  15156. }
  15157. return l.toTensor();
  15158. }, o.prototype.conv3d = function (t, e, n) {
  15159. for (var r = n.filterDepth, o = n.filterHeight, a = n.filterWidth, i = n.dilationDepth, u = n.dilationHeight, s = n.dilationWidth, c = n.padInfo.front, l = n.padInfo.left, h = n.padInfo.top, f = ur(n.outShape, t.dtype), p = this.readSync(t.dataId), d = this.readSync(e.dataId), v = f.values, m = 0; m < n.batchSize; ++m) for (var g = m * t.strides[0], y = m * f.strides[0], x = 0; x < n.outDepth; ++x) for (var b = y + x * f.strides[1], w = x * n.strideDepth - c, C = 0; C < r; C++) {
  15160. var E = w + C * i;
  15161. if (!(E < 0 || E >= n.inDepth)) for (var R = C * e.strides[0], I = g + E * t.strides[1], k = 0; k < n.outHeight; ++k) for (var S = b + k * f.strides[2], A = k * n.strideHeight - h, D = 0; D < o; D++) {
  15162. var T = A + D * u;
  15163. if (!(T < 0 || T >= n.inHeight)) for (var N = R + D * e.strides[1], F = I + T * t.strides[2], O = 0; O < n.outWidth; ++O) for (var _ = S + O * n.outChannels, M = O * n.strideWidth - l, B = 0; B < a; B++) {
  15164. var P = M + B * s;
  15165. if (!(P < 0 || P >= n.inWidth)) for (var L = N + B * e.strides[2], W = F + P * n.inChannels, U = L, V = 0; V < n.inChannels; ++V) {
  15166. for (var z = p[W + V], G = 0; G < n.outChannels; ++G) v[_ + G] += z * d[U + G];
  15167. U += n.outChannels;
  15168. }
  15169. }
  15170. }
  15171. }
  15172. return f.toTensor();
  15173. }, o.prototype.conv2dDerInput = function (t, e, n) {
  15174. Ih([t, e], "conv2dDerInput");
  15175. for (var r = ur(n.inShape, "float32"), o = r.values, a = this.readSync(t.dataId), i = this.readSync(e.dataId), u = e.strides, s = u[0], c = u[1], l = u[2], h = n.batchSize, f = n.filterHeight, p = n.filterWidth, d = n.inChannels, v = n.inHeight, m = n.inWidth, g = n.outChannels, y = n.outHeight, x = n.outWidth, b = n.strideHeight, w = n.strideWidth, C = n.dataFormat, E = f - 1 - n.padInfo.top, R = p - 1 - n.padInfo.left, I = "channelsLast" === C, k = r.strides[0], S = I ? r.strides[1] : r.strides[2], A = I ? r.strides[2] : 1, D = I ? 1 : r.strides[1], T = t.strides[0], N = I ? t.strides[1] : t.strides[2], F = I ? t.strides[2] : 1, O = I ? 1 : t.strides[1], _ = 0; _ < h; ++_) for (var M = 0; M < d; ++M) for (var B = 0; B < v; ++B) for (var P = B - E, L = Math.max(0, Math.ceil(P / b)), W = Math.min(y, (f + P) / b), U = 0; U < m; ++U) {
  15176. for (var V = U - R, z = Math.max(0, Math.ceil(V / w)), G = Math.min(x, (p + V) / w), H = 0, q = L; q < W; ++q) for (var K = q * b - P, j = z; j < G; ++j) for (var X = T * _ + N * q + F * j, $ = s * (f - 1 - K) + c * (p - 1 - (j * w - V)) + l * M, Y = 0; Y < g; ++Y) {
  15177. H += a[X + O * Y] * i[$ + Y];
  15178. }
  15179. o[k * _ + S * B + A * U + D * M] = H;
  15180. }
  15181. return r.toTensor();
  15182. }, o.prototype.conv3dDerInput = function (t, e, n) {
  15183. for (var r = ur(n.inShape, "float32"), o = r.values, a = r.strides, i = a[0], u = a[1], s = a[2], c = a[3], l = this.readSync(t.dataId), h = t.strides, f = h[0], p = h[1], d = h[2], v = h[3], m = this.readSync(e.dataId), g = e.strides, y = g[0], x = g[1], b = g[2], w = g[3], C = n.batchSize, E = n.filterDepth, R = n.filterHeight, I = n.filterWidth, k = n.inChannels, S = n.inDepth, A = n.inHeight, D = n.inWidth, T = n.outChannels, N = n.outDepth, F = n.outHeight, O = n.outWidth, _ = n.strideDepth, M = n.strideHeight, B = n.strideWidth, P = E - 1 - n.padInfo.front, L = R - 1 - n.padInfo.top, W = I - 1 - n.padInfo.left, U = 0; U < C; ++U) for (var V = 0; V < k; ++V) for (var z = 0; z < S; ++z) for (var G = z - P, H = Math.max(0, Math.ceil(G / _)), q = Math.min(N, (E + G) / _), K = 0; K < A; ++K) for (var j = K - L, X = Math.max(0, Math.ceil(j / M)), $ = Math.min(F, (R + j) / M), Y = 0; Y < D; ++Y) {
  15184. for (var Q = Y - W, J = Math.max(0, Math.ceil(Q / B)), Z = Math.min(O, (I + Q) / B), tt = 0, et = H; et < q; ++et) for (var nt = et * _ - G, rt = X; rt < $; ++rt) for (var ot = rt * M - j, at = J; at < Z; ++at) for (var it = f * U + p * et + d * rt + v * at, ut = y * (E - 1 - nt) + x * (R - 1 - ot) + b * (I - 1 - (at * B - Q)) + w * V, st = 0; st < T; ++st) {
  15185. tt += l[it + st] * m[ut + st];
  15186. }
  15187. o[i * U + u * z + s * K + c * Y + V] = tt;
  15188. }
  15189. return r.toTensor();
  15190. }, o.prototype.conv2dDerFilter = function (t, e, n) {
  15191. Ih([t, e], "conv2dDerFilter");
  15192. for (var r = n.strideHeight, o = n.strideWidth, a = n.filterHeight, i = n.filterWidth, u = "channelsLast" === n.dataFormat, s = ur(n.filterShape, "float32"), c = n.padInfo.left, l = n.padInfo.top, h = this.bufferSync(t), f = this.bufferSync(e), p = 0; p < a; ++p) for (var d = Math.max(0, Math.ceil((l - p) / r)), v = Math.min(n.outHeight, (n.inHeight + l - p) / r), m = 0; m < i; ++m) for (var g = Math.max(0, Math.ceil((c - m) / o)), y = Math.min(n.outWidth, (n.inWidth + c - m) / o), x = 0; x < n.inChannels; ++x) for (var b = 0; b < n.outChannels; ++b) {
  15193. for (var w = 0, C = 0; C < n.batchSize; ++C) for (var E = d; E < v; ++E) for (var R = p + E * r - l, I = g; I < y; ++I) {
  15194. var k = m + I * o - c;
  15195. w += u ? h.get(C, R, k, x) * f.get(C, E, I, b) : h.get(C, x, R, k) * f.get(C, b, E, I);
  15196. }
  15197. s.set(w, p, m, x, b);
  15198. }
  15199. return s.toTensor();
  15200. }, o.prototype.conv3dDerFilter = function (t, e, n) {
  15201. for (var r = n.strideDepth, o = n.strideHeight, a = n.strideWidth, i = n.filterDepth, u = n.filterHeight, s = n.filterWidth, c = ur(n.filterShape, "float32"), l = c.values, h = c.strides, f = h[0], p = h[1], d = h[2], v = h[3], m = this.readSync(e.dataId), g = e.strides, y = g[0], x = g[1], b = g[2], w = g[3], C = this.readSync(t.dataId), E = t.strides, R = E[0], I = E[1], k = E[2], S = E[3], A = n.padInfo.front, D = n.padInfo.left, T = n.padInfo.top, N = 0; N < i; ++N) for (var F = Math.max(0, Math.ceil((A - N) / r)), O = Math.min(n.outDepth, (n.inDepth + A - N) / r), _ = N * f, M = 0; M < u; ++M) for (var B = Math.max(0, Math.ceil((T - M) / o)), P = Math.min(n.outHeight, (n.inHeight + T - M) / o), L = M * p + _, W = 0; W < s; ++W) for (var U = Math.max(0, Math.ceil((D - W) / a)), V = Math.min(n.outWidth, (n.inWidth + D - W) / a), z = W * d + L, G = 0; G < n.inChannels; ++G) for (var H = G * v + z, q = 0; q < n.outChannels; ++q) {
  15202. for (var K = 0, j = 0; j < n.batchSize; ++j) for (var X = j * R, $ = j * y, Y = F; Y < O; ++Y) for (var Q = (N + Y * r - A) * I + X, J = Y * x + $, Z = B; Z < P; ++Z) for (var tt = (M + Z * o - T) * k + Q, et = Z * b + J, nt = U; nt < V; ++nt) {
  15203. var rt = nt * w + et;
  15204. K += C[(W + nt * a - D) * S + tt + G] * m[rt + q];
  15205. }
  15206. l[H + q] = K;
  15207. }
  15208. return c.toTensor();
  15209. }, o.prototype.fusedDepthwiseConv2D = function (t) {
  15210. var e = t.input,
  15211. n = t.filter,
  15212. r = t.convInfo,
  15213. o = t.bias,
  15214. a = t.activation,
  15215. i = t.preluActivationWeights,
  15216. u = this.depthwiseConv2D(e, n, r);
  15217. return o && (u = this.add(u, o)), a && (u = kh(this, u, a, i)), u;
  15218. }, o.prototype.depthwiseConv2D = function (t, e, n) {
  15219. Ih([t, e], "depthwiseConv2D");
  15220. for (var r = n.filterHeight, o = n.filterWidth, a = n.dilationHeight, i = n.dilationWidth, u = n.padInfo.left, s = n.padInfo.top, c = n.outChannels / n.inChannels, l = ur(n.outShape, t.dtype), h = this.readSync(t.dataId), f = this.readSync(e.dataId), p = l.values, d = 0; d < n.batchSize; ++d) for (var v = d * t.strides[0], m = d * l.strides[0], g = 0; g < n.outHeight; ++g) for (var y = m + g * l.strides[1], x = g * n.strideHeight - u, b = 0; b < r; ++b) {
  15221. var w = x + b * a;
  15222. if (!(w < 0 || w >= n.inHeight)) for (var C = b * e.strides[0], E = v + w * t.strides[1], R = 0; R < n.outWidth; ++R) for (var I = y + R * l.strides[2], k = R * n.strideWidth - s, S = 0; S < o; ++S) {
  15223. var A = k + S * i;
  15224. if (!(A < 0 || A >= n.inWidth)) for (var D = C + S * e.strides[1], T = E + A * n.inChannels, N = I, F = D, O = 0; O < n.inChannels; ++O) {
  15225. for (var _ = h[T + O], M = 0; M < c; ++M) p[N + M] += _ * f[F + M];
  15226. N += c, F += c;
  15227. }
  15228. }
  15229. }
  15230. return l.toTensor();
  15231. }, o.prototype.depthwiseConv2DDerInput = function (t, e, n) {
  15232. Ih([t, e], "depthwiseConv2DDerInput");
  15233. for (var r = ur(n.inShape, "float32"), o = r.values, a = r.strides, i = a[0], u = a[1], s = a[2], c = this.readSync(t.dataId), l = t.strides, h = l[0], f = l[1], p = l[2], d = this.readSync(e.dataId), v = e.strides, m = v[0], g = v[1], y = v[2], x = n.batchSize, b = n.filterHeight, w = n.filterWidth, C = n.inChannels, E = n.inHeight, R = n.inWidth, I = n.outChannels, k = n.outHeight, S = n.outWidth, A = n.strideHeight, D = n.strideWidth, T = b - 1 - n.padInfo.top, N = w - 1 - n.padInfo.left, F = I / C, O = 0; O < x; ++O) for (var _ = 0; _ < C; ++_) for (var M = 0; M < E; ++M) for (var B = M - T, P = Math.max(0, Math.ceil(B / A)), L = Math.min(k, (b + B) / A), W = 0; W < R; ++W) {
  15234. for (var U = W - N, V = Math.max(0, Math.ceil(U / D)), z = Math.min(S, (w + U) / D), G = 0, H = P; H < L; ++H) for (var q = H * A - B, K = V; K < z; ++K) for (var j = h * O + f * H + p * K, X = m * (b - 1 - q) + g * (w - 1 - (K * D - U)) + y * _, $ = 0; $ < F; ++$) {
  15235. G += c[j + (_ * F + $)] * d[X + $];
  15236. }
  15237. o[i * O + u * M + s * W + _] = G;
  15238. }
  15239. return r.toTensor();
  15240. }, o.prototype.depthwiseConv2DDerFilter = function (t, e, n) {
  15241. Ih([t, e], "depthwiseConv2DDerFilter");
  15242. for (var r = n.strideHeight, o = n.strideWidth, a = n.filterHeight, i = n.filterWidth, u = ur(n.filterShape, "float32"), s = n.padInfo.left, c = n.padInfo.top, l = n.outChannels / n.inChannels, h = this.bufferSync(t), f = this.bufferSync(e), p = 0; p < a; ++p) for (var d = Math.max(0, Math.ceil((c - p) / r)), v = Math.min(n.outHeight, (n.inHeight + c - p) / r), m = 0; m < i; ++m) for (var g = Math.max(0, Math.ceil((s - m) / o)), y = Math.min(n.outWidth, (n.inWidth + s - m) / o), x = 0; x < n.outChannels; ++x) {
  15243. for (var b = Math.trunc(x / l), w = x % l, C = 0, E = 0; E < n.batchSize; ++E) for (var R = d; R < v; ++R) for (var I = p + R * r - c, k = g; k < y; ++k) {
  15244. var S = m + k * o - s;
  15245. C += h.get(E, I, S, b) * f.get(E, R, k, x);
  15246. }
  15247. u.set(C, p, m, b, w);
  15248. }
  15249. return u.toTensor();
  15250. }, o.prototype.tile = function (t, e) {
  15251. return Ih(t, "tile"), Lo(this.bufferSync(t), e);
  15252. }, o.prototype.pad = function (t, e, n) {
  15253. Ih(t, "pad");
  15254. var r = e.map(function (e, n) {
  15255. return e[0] + t.shape[n] + e[1];
  15256. }),
  15257. o = e.map(function (t) {
  15258. return t[0];
  15259. }),
  15260. a = this.bufferSync(t),
  15261. i = ur(r, t.dtype);
  15262. 0 !== n && i.values.fill(n);
  15263. for (var u = 0; u < t.size; u++) {
  15264. var s = a.indexToLoc(u),
  15265. c = s.map(function (t, e) {
  15266. return t + o[e];
  15267. });
  15268. i.set.apply(i, [a.get.apply(a, s)].concat(c));
  15269. }
  15270. return i.toTensor();
  15271. }, o.prototype.transpose = function (t, e) {
  15272. Ih(t, "transpose");
  15273. for (var n = new Array(t.rank), r = 0; r < n.length; r++) n[r] = t.shape[e[r]];
  15274. var o = this.readSync(t.dataId),
  15275. a = ur(n, t.dtype),
  15276. i = this.bufferSync(t);
  15277. for (r = 0; r < t.size; ++r) {
  15278. for (var u = i.indexToLoc(r), s = new Array(u.length), c = 0; c < s.length; c++) s[c] = u[e[c]];
  15279. var l = a.locToIndex(s);
  15280. a.values[l] = o[r];
  15281. }
  15282. return a.toTensor();
  15283. }, o.prototype.gather = function (t, e, n) {
  15284. Ih([t, e], "gather");
  15285. var r = t.shape.slice(),
  15286. o = this.readSync(e.dataId);
  15287. r[n] = o.length;
  15288. for (var a = ur(r, t.dtype), i = this.bufferSync(t), u = 0; u < a.size; ++u) {
  15289. var s = a.indexToLoc(u),
  15290. c = s.slice();
  15291. c[n] = o[s[n]];
  15292. var l = i.locToIndex(c);
  15293. a.values[u] = i.values[l];
  15294. }
  15295. return a.toTensor();
  15296. }, o.prototype.batchToSpaceND = function (t, e, n) {
  15297. Ih([t], "batchToSpaceND");
  15298. var r = e.reduce(function (t, e) {
  15299. return t * e;
  15300. }),
  15301. o = Mr(t.shape, e, r),
  15302. a = Br(o.length, e.length),
  15303. i = Pr(t.shape, e, r),
  15304. u = Lr(n, e.length),
  15305. s = Wr(i, n, e.length);
  15306. return t.reshape(o).transpose(a).reshape(i).slice(u, s);
  15307. }, o.prototype.spaceToBatchND = function (t, e, n) {
  15308. Ih([t], "spaceToBatchND");
  15309. var r = e.reduce(function (t, e) {
  15310. return t * e;
  15311. }),
  15312. o = [[0, 0]];
  15313. o.push.apply(o, n);
  15314. for (var a = 1 + e.length; a < t.shape.length; ++a) o.push([0, 0]);
  15315. var i = t.pad(o),
  15316. u = Mr(i.shape, e, r, !1),
  15317. s = Br(u.length, e.length, !1),
  15318. c = Pr(i.shape, e, r, !1);
  15319. return i.reshape(u).transpose(s).reshape(c);
  15320. }, o.prototype.pool = function (t, e, n) {
  15321. Ih(t, "pool");
  15322. for (var r = e.strideHeight, o = e.strideWidth, a = e.dilationHeight, i = e.dilationWidth, u = e.effectiveFilterHeight, s = e.effectiveFilterWidth, c = e.padInfo.top, l = e.padInfo.left, h = "max" === n ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY, f = this.readSync(t.dataId), p = ur(e.outShape, t.dtype), d = p.values, v = e.outShape[1] * e.outShape[2] * e.outShape[3], m = e.outShape[2] * e.outShape[3], g = e.outShape[3], y = 0; y < e.batchSize; ++y) for (var x = y * v, b = y * t.strides[0], w = 0; w < e.inChannels; ++w) for (var C = 0; C < e.outHeight; ++C) for (var E = C * r - c, R = Math.max(0, E), I = Math.min(e.inHeight, u + E), k = x + C * m, S = 0; S < e.outWidth; ++S) {
  15323. for (var A = S * o - l, D = Math.max(0, A), T = Math.min(e.inWidth, s + A), N = h, F = 0, O = 0, _ = R; _ < I; _ += a) {
  15324. for (var M = b + _ * t.strides[1], B = D; B < T; B += i) {
  15325. var P = f[M + B * t.strides[2] + w];
  15326. "max" === n && P > N ? N = P : "avg" === n && (F += P, O++);
  15327. }
  15328. if (isNaN(N)) break;
  15329. }
  15330. d[k + S * g + w] = "avg" === n ? F / O : N;
  15331. }
  15332. return p.toTensor();
  15333. }, o.prototype.maxPool = function (t, e) {
  15334. return this.pool(t, e, "max");
  15335. }, o.prototype.maxPoolPositions = function (t, e) {
  15336. for (var n = ur(e.outShape, "int32"), r = e.strideHeight, o = e.strideWidth, a = e.dilationHeight, i = e.dilationWidth, u = e.effectiveFilterHeight, s = e.effectiveFilterWidth, c = e.padInfo.top, l = e.padInfo.left, h = this.bufferSync(t), f = 0; f < e.batchSize; ++f) for (var p = 0; p < e.inChannels; ++p) for (var d = 0; d < e.outHeight; ++d) {
  15337. for (var v = d * r - c, m = v; m < 0;) m += a;
  15338. for (var g = Math.min(e.inHeight, u + v), y = 0; y < e.outWidth; ++y) {
  15339. for (var x = y * o - l, b = x; b < 0;) b += i;
  15340. for (var w = Math.min(e.inWidth, s + x), C = Number.NEGATIVE_INFINITY, E = -1, R = m; R < g; R += a) for (var I = R - v, k = b; k < w; k += i) {
  15341. var S = k - x,
  15342. A = h.get(f, R, k, p);
  15343. A > C && (C = A, E = I * s + S);
  15344. }
  15345. n.set(E, f, d, y, p);
  15346. }
  15347. }
  15348. return n.toTensor();
  15349. }, o.prototype.maxPoolBackprop = function (t, e, n, r) {
  15350. Ih([e, n], "maxPoolBackprop");
  15351. for (var o = this.maxPoolPositions(e, r), a = r.strideHeight, i = r.strideWidth, u = r.dilationHeight, s = r.dilationWidth, c = r.effectiveFilterHeight, l = r.effectiveFilterWidth, h = l - 1 - r.padInfo.left, f = c - 1 - r.padInfo.top, p = ur(e.shape, "float32"), d = this.bufferSync(o), v = this.bufferSync(t), m = 0; m < r.batchSize; ++m) for (var g = 0; g < r.inChannels; ++g) for (var y = 0; y < r.inHeight; ++y) for (var x = 0; x < r.inWidth; ++x) {
  15352. for (var b = y - f, w = x - h, C = 0, E = 0; E < c; E += u) {
  15353. var R = (b + E) / a;
  15354. if (!(R < 0 || R >= r.outHeight || Math.floor(R) !== R)) for (var I = 0; I < l; I += s) {
  15355. var k = (w + I) / i;
  15356. if (!(k < 0 || k >= r.outWidth || Math.floor(k) !== k)) {
  15357. var S = c * l - 1 - d.get(m, R, k, g) === E * l + I ? 1 : 0;
  15358. if (0 !== S) C += v.get(m, R, k, g) * S;
  15359. }
  15360. }
  15361. }
  15362. p.set(C, m, y, x, g);
  15363. }
  15364. return p.toTensor();
  15365. }, o.prototype.avgPoolBackprop = function (t, e, n) {
  15366. Ih([t, e], "avgPoolBackprop");
  15367. for (var r = n.strideHeight, o = n.strideWidth, a = n.filterHeight, i = n.filterWidth, u = n.dilationHeight, s = n.dilationWidth, c = n.effectiveFilterHeight, l = n.effectiveFilterWidth, h = l - 1 - n.padInfo.left, f = c - 1 - n.padInfo.top, p = ur(e.shape, "float32"), d = 1 / (a * i), v = this.bufferSync(t), m = 0; m < n.batchSize; ++m) for (var g = 0; g < n.inChannels; ++g) for (var y = 0; y < n.inHeight; ++y) for (var x = 0; x < n.inWidth; ++x) {
  15368. for (var b = y - f, w = x - h, C = 0, E = 0; E < c; E += u) {
  15369. var R = (b + E) / r;
  15370. if (!(R < 0 || R >= n.outHeight || Math.floor(R) !== R)) for (var I = 0; I < l; I += s) {
  15371. var k = (w + I) / o;
  15372. if (!(k < 0 || k >= n.outWidth || Math.floor(k) !== k)) C += v.get(m, R, k, g);
  15373. }
  15374. }
  15375. p.set(C * d, m, y, x, g);
  15376. }
  15377. return p.toTensor();
  15378. }, o.prototype.pool3d = function (t, e, n) {
  15379. Ih(t, "pool3d");
  15380. for (var r = e.strideDepth, o = e.strideHeight, a = e.strideWidth, i = e.dilationDepth, u = e.dilationHeight, s = e.dilationWidth, c = e.effectiveFilterDepth, l = e.effectiveFilterHeight, h = e.effectiveFilterWidth, f = e.padInfo.front, p = e.padInfo.top, d = e.padInfo.left, v = "max" === n ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY, m = this.readSync(t.dataId), g = ur(e.outShape, t.dtype), y = g.values, x = e.outShape[1] * e.outShape[2] * e.outShape[3] * e.outShape[4], b = e.outShape[2] * e.outShape[3] * e.outShape[4], w = e.outShape[3] * e.outShape[4], C = e.outShape[4], E = 0; E < e.batchSize; ++E) for (var R = E * x, I = E * t.strides[0], k = 0; k < e.inChannels; ++k) for (var S = 0; S < e.outDepth; ++S) {
  15381. for (var A = S * r - f, D = A; D < 0;) D += i;
  15382. for (var T = Math.min(e.inDepth, c + A), N = R + S * b, F = 0; F < e.outHeight; ++F) {
  15383. for (var O = F * o - p, _ = O; _ < 0;) _ += u;
  15384. for (var M = Math.min(e.inHeight, l + O), B = N + F * w, P = 0; P < e.outWidth; ++P) {
  15385. for (var L = P * a - d, W = L; W < 0;) W += s;
  15386. for (var U = Math.min(e.inWidth, h + L), V = B + P * C, z = v, G = 0, H = 0, q = D; q < T; q += i) {
  15387. for (var K = I + q * t.strides[1], j = _; j < M; j += u) {
  15388. for (var X = K + j * t.strides[2], $ = W; $ < U; $ += s) {
  15389. var Y = m[X + $ * t.strides[3] + k];
  15390. if ("max" === n && Y > z ? z = Y : "avg" === n && (G += Y, H++), isNaN(z)) break;
  15391. }
  15392. if (isNaN(z)) break;
  15393. }
  15394. if (isNaN(z)) break;
  15395. }
  15396. y[V + k] = "avg" === n ? G / H : z;
  15397. }
  15398. }
  15399. }
  15400. return g.toTensor();
  15401. }, o.prototype.avgPool3d = function (t, e) {
  15402. return Ih(t, "avgPool3d"), this.pool3d(t, e, "avg").toFloat();
  15403. }, o.prototype.avgPool3dBackprop = function (t, e, n) {
  15404. Ih([t, e], "avgPool3dBackprop");
  15405. for (var r = n.strideDepth, o = n.strideHeight, a = n.strideWidth, i = n.filterDepth, u = n.filterHeight, s = n.filterWidth, c = n.dilationDepth, l = n.dilationHeight, h = n.dilationWidth, f = n.effectiveFilterDepth, p = n.effectiveFilterHeight, d = n.effectiveFilterWidth, v = f - 1 - n.padInfo.front, m = d - 1 - n.padInfo.left, g = p - 1 - n.padInfo.top, y = ur(e.shape, "float32"), x = 1 / (i * u * s), b = this.bufferSync(t), w = 0; w < n.batchSize; ++w) for (var C = 0; C < n.inChannels; ++C) for (var E = 0; E < n.inDepth; ++E) for (var R = 0; R < n.inHeight; ++R) for (var I = 0; I < n.inWidth; ++I) {
  15406. for (var k = E - v, S = R - g, A = I - m, D = 0, T = 0; T < f; T += c) {
  15407. var N = (k + T) / r;
  15408. if (!(N < 0 || N >= n.outDepth || Math.floor(N) !== N)) for (var F = 0; F < p; F += l) {
  15409. var O = (S + F) / o;
  15410. if (!(O < 0 || O >= n.outHeight || Math.floor(O) !== O)) for (var _ = 0; _ < d; _ += h) {
  15411. var M = (A + _) / a;
  15412. if (!(M < 0 || M >= n.outWidth || Math.floor(M) !== M)) D += b.get(w, N, O, M, C);
  15413. }
  15414. }
  15415. }
  15416. y.set(D * x, w, E, R, I, C);
  15417. }
  15418. return y.toTensor();
  15419. }, o.prototype.maxPool3d = function (t, e) {
  15420. return Ih(t, "maxPool3d"), this.pool3d(t, e, "max").toFloat();
  15421. }, o.prototype.maxPool3dPositions = function (t, e) {
  15422. for (var n = ur(e.outShape, "int32"), r = e.strideDepth, o = e.strideHeight, a = e.strideWidth, i = e.dilationDepth, u = e.dilationHeight, s = e.dilationWidth, c = e.effectiveFilterDepth, l = e.effectiveFilterHeight, h = e.effectiveFilterWidth, f = e.padInfo.front, p = e.padInfo.top, d = e.padInfo.left, v = this.bufferSync(t), m = 0; m < e.batchSize; ++m) for (var g = 0; g < e.inChannels; ++g) for (var y = 0; y < e.outDepth; ++y) {
  15423. for (var x = y * r - f, b = x; b < 0;) b += i;
  15424. for (var w = Math.min(e.inDepth, c + x), C = 0; C < e.outHeight; ++C) {
  15425. for (var E = C * o - p, R = E; R < 0;) R += u;
  15426. for (var I = Math.min(e.inHeight, l + E), k = 0; k < e.outWidth; ++k) {
  15427. for (var S = k * a - d, A = S; A < 0;) A += s;
  15428. for (var D = Math.min(e.inWidth, h + S), T = Number.NEGATIVE_INFINITY, N = -1, F = b; F < w; F += i) for (var O = F - x, _ = R; _ < I; _ += u) for (var M = _ - E, B = A; B < D; B += s) {
  15429. var P = B - S,
  15430. L = v.get(m, F, _, B, g);
  15431. L >= T && (T = L, N = O * l * h + M * l + P);
  15432. }
  15433. n.set(N, m, y, C, k, g);
  15434. }
  15435. }
  15436. }
  15437. return n.toTensor();
  15438. }, o.prototype.maxPool3dBackprop = function (t, e, n, r) {
  15439. Ih([e, n], "maxPool3dBackprop");
  15440. for (var o = this.maxPool3dPositions(e, r), a = r.strideDepth, i = r.strideHeight, u = r.strideWidth, s = r.dilationDepth, c = r.dilationHeight, l = r.dilationWidth, h = r.effectiveFilterDepth, f = r.effectiveFilterHeight, p = r.effectiveFilterWidth, d = h - 1 - r.padInfo.front, v = p - 1 - r.padInfo.left, m = f - 1 - r.padInfo.top, g = ur(e.shape, "float32"), y = this.bufferSync(o), x = this.bufferSync(t), b = 0; b < r.batchSize; ++b) for (var w = 0; w < r.inChannels; ++w) for (var C = 0; C < r.inDepth; ++C) for (var E = 0; E < r.inHeight; ++E) for (var R = 0; R < r.inWidth; ++R) {
  15441. for (var I = C - d, k = E - m, S = R - v, A = 0, D = 0; D < h; D += s) {
  15442. var T = (I + D) / a;
  15443. if (!(T < 0 || T >= r.outDepth || Math.floor(T) !== T)) for (var N = 0; N < f; N += c) {
  15444. var F = (k + N) / i;
  15445. if (!(F < 0 || F >= r.outHeight || Math.floor(F) !== F)) for (var O = 0; O < p; O += l) {
  15446. var _ = (S + O) / u;
  15447. if (!(_ < 0 || _ >= r.outWidth || Math.floor(_) !== _)) {
  15448. var M = h * f * p - 1 - y.get(b, T, F, _, w) === D * f * p + N * p + O ? 1 : 0;
  15449. if (0 !== M) A += x.get(b, T, F, _, w) * M;
  15450. }
  15451. }
  15452. }
  15453. }
  15454. g.set(A, b, C, E, R, w);
  15455. }
  15456. return g.toTensor();
  15457. }, o.prototype.cast = function (t, e) {
  15458. return So(t, e, this);
  15459. }, o.prototype.reshape = function (t, e) {
  15460. return Ao(t, e);
  15461. }, o.prototype.avgPool = function (t, e) {
  15462. return Ih(t, "avgPool"), this.pool(t, e, "avg").toFloat();
  15463. }, o.prototype.resizeBilinear = function (t, e, n, r) {
  15464. Ih(t, "resizeBilinear");
  15465. for (var o = t.shape, a = o[0], i = o[1], u = o[2], s = o[3], c = this.readSync(t.dataId), l = new Float32Array(w([a, e, n, s])), h = [r && e > 1 ? i - 1 : i, r && n > 1 ? u - 1 : u], f = [r && e > 1 ? e - 1 : e, r && n > 1 ? n - 1 : n], p = 0, d = h[0] / f[0], v = h[1] / f[1], m = 0; m < a; m++) for (var g = 0; g < e; g++) for (var y = d * g, x = Math.floor(y), b = y - x, C = Math.min(i - 1, Math.ceil(y)), E = m * t.strides[0] + x * t.strides[1], R = m * t.strides[0] + C * t.strides[1], I = 0; I < n; I++) for (var k = v * I, S = Math.floor(k), A = k - S, D = Math.min(u - 1, Math.ceil(k)), T = E + S * t.strides[2], N = R + S * t.strides[2], F = E + +D * t.strides[2], O = R + D * t.strides[2], _ = 0; _ < s; _++) {
  15466. var M = c[T + _],
  15467. B = c[N + _],
  15468. P = M + (c[F + _] - M) * A,
  15469. L = P + (B + (c[O + _] - B) * A - P) * b;
  15470. l[p++] = L;
  15471. }
  15472. return kn(l, [a, e, n, s]);
  15473. }, o.prototype.resizeBilinearBackprop = function (t, e, n) {
  15474. Ih([t, e], "resizeBilinearBackprop");
  15475. for (var r = e.shape, o = r[0], a = r[1], i = r[2], u = r[3], s = t.shape, c = s[1], l = s[2], h = new Float32Array(o * a * i * u), f = [n && c > 1 ? a - 1 : a, n && l > 1 ? i - 1 : i], p = [n && c > 1 ? c - 1 : c, n && l > 1 ? l - 1 : l], d = f[0] / p[0], v = f[1] / p[1], m = this.readSync(t.dataId), g = 0, y = 0; y < o; y++) for (var x = y * e.strides[0], b = 0; b < c; b++) for (var w = b * d, C = Math.floor(w), E = Math.min(Math.ceil(w), a - 1), R = x + C * e.strides[1], I = x + E * e.strides[1], k = w - C, S = 1 - k, A = 0; A < l; A++) for (var D = A * v, T = Math.floor(D), N = Math.min(Math.ceil(D), i - 1), F = D - T, O = 1 - F, _ = R + T * e.strides[2], M = R + N * e.strides[2], B = I + T * e.strides[2], P = I + N * e.strides[2], L = S * O, W = S * F, U = k * O, V = k * F, z = 0; z < u; z++) {
  15476. var G = m[g++];
  15477. h[_ + z] += G * L, h[M + z] += G * W, h[B + z] += G * U, h[P + z] += G * V;
  15478. }
  15479. return Fn(h, [o, i, a, u], e.dtype);
  15480. }, o.prototype.resizeNearestNeighbor = function (t, e, n, r) {
  15481. Ih(t, "resizeNearestNeighbor");
  15482. for (var o = t.shape, a = o[0], i = o[1], u = o[2], s = o[3], c = this.readSync(t.dataId), l = new Float32Array(a * e * n * s), h = [r && e > 1 ? i - 1 : i, r && n > 1 ? u - 1 : u], f = [r && e > 1 ? e - 1 : e, r && n > 1 ? n - 1 : n], p = h[0] / f[0], d = h[1] / f[1], v = 0, m = 0; m < a; m++) for (var g = m * t.strides[0], y = 0; y < e; y++) for (var x = p * y, b = g + Math.min(i - 1, r ? Math.round(x) : Math.floor(x)) * t.strides[1], w = 0; w < n; w++) for (var C = d * w, E = b + Math.min(u - 1, r ? Math.round(C) : Math.floor(C)) * t.strides[2], R = 0; R < s; R++) {
  15483. var I = c[E + R];
  15484. l[v++] = I;
  15485. }
  15486. return kn(l, [a, e, n, s], t.dtype);
  15487. }, o.prototype.resizeNearestNeighborBackprop = function (t, e, n) {
  15488. Ih([t, e], "resizeNearestNeighborBackprop");
  15489. for (var r = e.shape, o = r[0], a = r[1], i = r[2], u = r[3], s = t.shape, c = s[1], l = s[2], h = new Float32Array(o * a * i * u), f = this.readSync(t.dataId), p = [n && c > 1 ? a - 1 : a, n && l > 1 ? i - 1 : i], d = [n && c > 1 ? c - 1 : c, n && l > 1 ? l - 1 : l], v = p[0] / d[0], m = p[1] / d[1], g = 1 / v, y = 1 / m, x = 2 * Math.ceil(g) + 2, b = 2 * Math.ceil(y) + 2, w = 0; w < o; w++) for (var C = w * e.strides[0], E = 0; E < a; E++) for (var R = C + E * e.strides[1], I = Math.floor(E * g), k = Math.floor(I - x / 2), S = 0; S < i; S++) for (var A = R + S * e.strides[2], D = Math.floor(S * y), T = Math.floor(D - b / 2), N = 0; N < u; N++) {
  15490. for (var F = 0, O = 0; O < x; O++) {
  15491. var _ = O + k;
  15492. if (!(_ < 0 || _ >= c)) {
  15493. var M = C + _ * t.strides[1],
  15494. B = _ * v;
  15495. if (E === Math.min(a - 1, n ? Math.round(B) : Math.floor(B))) for (var P = 0; P < b; P++) {
  15496. var L = P + T;
  15497. if (!(L < 0 || L >= l)) {
  15498. var W = M + L * t.strides[2],
  15499. U = L * m;
  15500. S === Math.min(i - 1, n ? Math.round(U) : Math.floor(U)) && (F += f[W + N]);
  15501. }
  15502. }
  15503. }
  15504. }
  15505. h[A + N] = F;
  15506. }
  15507. return Fn(h, e.shape, e.dtype);
  15508. }, o.prototype.batchNormalization = function (t, e, n, r, o, a) {
  15509. Ih([t, e, n, o, a], "batchNorm");
  15510. for (var i = this.readSync(t.dataId), u = this.readSync(e.dataId), s = this.readSync(n.dataId), c = o ? this.readSync(o.dataId) : new Float32Array([1]), l = a ? this.readSync(a.dataId) : new Float32Array([0]), h = new Float32Array(i.length), f = l.length, p = c.length, d = s.length, v = u.length, m = 0, g = 0, y = 0, x = 0, b = 0; b < i.length; ++b) h[b] = l[m++] + (i[b] - u[g++]) * c[y++] / Math.sqrt(s[x++] + r), m >= f && (m = 0), g >= v && (g = 0), y >= p && (y = 0), x >= d && (x = 0);
  15511. return Fn(h, t.shape);
  15512. }, o.prototype.localResponseNormalization4D = function (t, e, n, r, o) {
  15513. Ih(t, "localResponseNormalization4D");
  15514. var a = t.shape[3],
  15515. i = a - 1,
  15516. u = this.readSync(t.dataId),
  15517. s = t.size,
  15518. c = new Float32Array(s);
  15519. function l(t) {
  15520. for (var n = t % a, r = t - n + Math.max(0, n - e), o = t - n + Math.min(n + e, i), s = 0; r <= o; r++) {
  15521. var c = u[r];
  15522. s += c * c;
  15523. }
  15524. return s;
  15525. }
  15526. for (var h = 0; h < s; h++) {
  15527. var f = l(h),
  15528. p = u[h] * Math.pow(n + r * f, -o);
  15529. c[h] = p;
  15530. }
  15531. return Fn(c, t.shape);
  15532. }, o.prototype.LRNGrad = function (t, e, n, r, o, a, i) {
  15533. Ih(t, "LRNGrad");
  15534. for (var u = t.shape[3], s = this.readSync(t.dataId), c = this.readSync(e.dataId), l = this.readSync(n.dataId), h = new Float32Array(t.size), f = t.size, p = 0; p < f; p++) {
  15535. for (var d = p % u, v = p - d + Math.max(0, d - r), m = p - d + Math.min(u, d + r + 1), g = 0, y = v; y < m; y++) g += Math.pow(c[y], 2);
  15536. g = a * g + o;
  15537. for (y = v; y < m; y++) {
  15538. var x = -2 * a * i * c[y] * l[p] / g;
  15539. p === y && (x += Math.pow(g, -i)), x *= s[p], h[y] += x;
  15540. }
  15541. }
  15542. return Fn(h, t.shape);
  15543. }, o.prototype.multinomial = function (t, e, n, r) {
  15544. Ih(t, "multinomial");
  15545. for (var o = e ? t : io(t), a = o.shape[0], i = o.shape[1], u = Pn([a, n], "int32"), s = this.readSync(u.dataId), c = this.readSync(o.dataId), l = 0; l < a; ++l) {
  15546. var h = l * i,
  15547. f = new Float32Array(i - 1);
  15548. f[0] = c[h];
  15549. for (var p = 1; p < f.length; ++p) f[p] = f[p - 1] + c[h + p];
  15550. for (var d = rr(r.toString()), v = l * n, m = 0; m < n; ++m) {
  15551. var g = d();
  15552. s[v + m] = f.length;
  15553. for (var y = 0; y < f.length; y++) if (g < f[y]) {
  15554. s[v + m] = y;
  15555. break;
  15556. }
  15557. }
  15558. }
  15559. return u;
  15560. }, o.prototype.oneHot = function (t, e, n, r) {
  15561. Ih(t, "oneHot");
  15562. var o = new Float32Array(t.size * e);
  15563. o.fill(r);
  15564. for (var a = this.readSync(t.dataId), i = 0; i < t.size; ++i) a[i] >= 0 && a[i] < e && (o[i * e + a[i]] = n);
  15565. return Tn(o, [t.size, e], "int32");
  15566. }, o.prototype.nonMaxSuppression = function (t, e, n, r, o) {
  15567. return Ih(t, "nonMaxSuppression"), Mo(this.readSync(t.dataId), this.readSync(e.dataId), n, r, o);
  15568. }, o.prototype.fft = function (t) {
  15569. return this.fftBatch(t, !1);
  15570. }, o.prototype.ifft = function (t) {
  15571. return this.fftBatch(t, !0);
  15572. }, o.prototype.fftBatch = function (t, e) {
  15573. for (var n = t.shape[0], r = t.shape[1], o = ur(t.shape, "float32"), a = ur(t.shape, "float32"), i = Rn(t).as2D(n, r), u = In(t).as2D(n, r), s = 0; s < n; s++) for (var c = i.slice([s, 0], [1, r]), l = u.slice([s, 0], [1, r]), h = En(c, l), f = this.readSync(this.fftImpl(h, e).dataId), p = 0; p < r; p++) {
  15574. var d = Fo(f, p);
  15575. o.values[s * r + p] = d.real, a.values[s * r + p] = d.imag;
  15576. }
  15577. return En(o.toTensor(), a.toTensor()).as2D(n, r);
  15578. }, o.prototype.fftImpl = function (t, e) {
  15579. var n = t.as1D(),
  15580. r = n.size;
  15581. if (this.isExponentOf2(r)) {
  15582. var o = this.fftRadix2(n, r, e).as2D(t.shape[0], t.shape[1]);
  15583. return e && (o = En(Rn(o).div(An(r)), In(o).div(An(r)))), o;
  15584. }
  15585. var a = this.readSync(t.dataId),
  15586. i = function (t) {
  15587. for (var e = new Float32Array(t.length / 2), n = new Float32Array(t.length / 2), r = 0; r < t.length; r += 2) e[r / 2] = t[r], n[r / 2] = t[r + 1];
  15588. return {
  15589. real: e,
  15590. imag: n
  15591. };
  15592. }(this.fourierTransformByMatmul(a, r, e));
  15593. return En(i.real, i.imag).as2D(t.shape[0], t.shape[1]);
  15594. }, o.prototype.isExponentOf2 = function (t) {
  15595. return 0 == (t & t - 1);
  15596. }, o.prototype.fftRadix2 = function (t, e, n) {
  15597. if (1 === e) return t;
  15598. var r = this.readSync(t.dataId),
  15599. o = e / 2,
  15600. a = function (t) {
  15601. for (var e = Math.ceil(t.length / 4), n = new Float32Array(e), r = new Float32Array(e), o = 0; o < t.length; o += 4) n[Math.floor(o / 4)] = t[o], r[Math.floor(o / 4)] = t[o + 1];
  15602. return {
  15603. real: n,
  15604. imag: r
  15605. };
  15606. }(r),
  15607. i = En(a.real, a.imag).as1D(),
  15608. u = function (t) {
  15609. for (var e = Math.floor(t.length / 4), n = new Float32Array(e), r = new Float32Array(e), o = 2; o < t.length; o += 4) n[Math.floor(o / 4)] = t[o], r[Math.floor(o / 4)] = t[o + 1];
  15610. return {
  15611. real: n,
  15612. imag: r
  15613. };
  15614. }(r),
  15615. s = En(u.real, u.imag).as1D();
  15616. i = this.fftRadix2(i, o, n), s = this.fftRadix2(s, o, n);
  15617. var c = function (t, e) {
  15618. for (var n = new Float32Array(t / 2), r = new Float32Array(t / 2), o = 0; o < Math.ceil(t / 2); o++) {
  15619. var a = (e ? 2 : -2) * Math.PI * (o / t);
  15620. n[o] = Math.cos(a), r[o] = Math.sin(a);
  15621. }
  15622. return {
  15623. real: n,
  15624. imag: r
  15625. };
  15626. }(e, n),
  15627. l = En(c.real, c.imag).mul(s),
  15628. h = i.add(l),
  15629. f = i.sub(l),
  15630. p = Rn(h).concat(Rn(f)),
  15631. d = In(h).concat(In(f));
  15632. return En(p, d).as1D();
  15633. }, o.prototype.fourierTransformByMatmul = function (t, e, n) {
  15634. for (var r = new Float32Array(2 * e), o = 0; o < e; o++) {
  15635. for (var a = 0, i = 0, u = 0; u < e; u++) {
  15636. var s = _o(o * u, e, n),
  15637. c = Fo(t, u);
  15638. a += c.real * s.real - c.imag * s.imag, i += c.real * s.imag + c.imag * s.real;
  15639. }
  15640. n && (a /= e, i /= e), Oo(r, a, i, o);
  15641. }
  15642. return r;
  15643. }, o.prototype.depthToSpace = function (t, e, n) {
  15644. g("NHWC" === n, function () {
  15645. return "Only NHWC dataFormat supported on CPU for depthToSpace. Got " + n;
  15646. }), g(e > 1, function () {
  15647. return "blockSize should be > 1 for depthToSpace, but was: " + e;
  15648. });
  15649. for (var r = t.shape[0], o = t.shape[1], a = t.shape[2], i = t.shape[3], u = o * e, s = a * e, c = i / (e * e), l = this.readSync(t.dataId), h = new Float32Array(r * u * s * c), f = 0, p = 0; p < r; ++p) for (var d = 0; d < u; ++d) for (var v = Math.floor(d / e), m = d % e, y = 0; y < s; ++y) for (var x = Math.floor(y / e), b = (m * e + y % e) * c, w = 0; w < c; ++w) {
  15650. var C = w + b + i * (x + a * (v + o * p));
  15651. h[f++] = l[C];
  15652. }
  15653. return Fn(h, [r, u, s, c]);
  15654. }, o.prototype.broadcastedBinaryOp = function (t, e, n, r) {
  15655. var o = po(t.shape, e.shape),
  15656. a = ur(o, n),
  15657. i = this.readSync(t.dataId),
  15658. u = this.readSync(e.dataId),
  15659. s = ho(t.shape, o),
  15660. c = ho(e.shape, o),
  15661. l = a.values;
  15662. if (s.length + c.length === 0) for (var h = 0; h < l.length; ++h) l[h] = r(i[h % i.length], u[h % u.length]); else {
  15663. var f = this.bufferSync(t),
  15664. p = this.bufferSync(e),
  15665. d = function (n) {
  15666. var o = a.indexToLoc(n),
  15667. h = o.slice(-t.rank);
  15668. s.forEach(function (t) {
  15669. return h[t] = 0;
  15670. });
  15671. var d = f.locToIndex(h),
  15672. v = o.slice(-e.rank);
  15673. c.forEach(function (t) {
  15674. return v[t] = 0;
  15675. });
  15676. var m = p.locToIndex(v);
  15677. l[n] = r(i[d], u[m]);
  15678. };
  15679. for (h = 0; h < l.length; ++h) d(h);
  15680. }
  15681. return a.toTensor();
  15682. }, o.prototype.broadcastedBinaryComplexOp = function (t, e, n) {
  15683. var r = po(t.shape, e.shape),
  15684. o = ur(r, "float32"),
  15685. a = ur(r, "float32"),
  15686. i = this.readSync(t.dataId),
  15687. u = this.readSync(e.dataId),
  15688. s = ho(t.shape, r),
  15689. c = ho(e.shape, r),
  15690. l = o.values,
  15691. h = a.values;
  15692. if (s.length + c.length === 0) for (var f = 0; f < l.length; f++) {
  15693. var p = f % i.length,
  15694. d = f % u.length,
  15695. v = n(i[2 * p], i[2 * p + 1], u[2 * d], u[2 * d + 1]);
  15696. l[f] = v.real, h[f] = v.imag;
  15697. } else {
  15698. var m = this.bufferSync(this.data.get(t.dataId).complexTensors.real),
  15699. g = this.bufferSync(this.data.get(e.dataId).complexTensors.real),
  15700. y = function (r) {
  15701. var a = o.indexToLoc(r),
  15702. f = a.slice(-t.rank);
  15703. s.forEach(function (t) {
  15704. return f[t] = 0;
  15705. });
  15706. var p = m.locToIndex(f),
  15707. d = a.slice(-e.rank);
  15708. c.forEach(function (t) {
  15709. return d[t] = 0;
  15710. });
  15711. var v = g.locToIndex(d),
  15712. y = n(i[2 * p], i[2 * p + 1], u[2 * v], u[2 * v + 1]);
  15713. l[r] = y.real, h[r] = y.imag;
  15714. };
  15715. for (f = 0; f < l.length; f++) y(f);
  15716. }
  15717. return this.complex(o.toTensor(), a.toTensor());
  15718. }, o.prototype.split = function (t, e, n) {
  15719. return Po(t, e, n);
  15720. }, o.prototype.dispose = function () { }, o.prototype.floatPrecision = function () {
  15721. return 32;
  15722. }, o.prototype.epsilon = function () {
  15723. return 1e-7;
  15724. }, o.prototype.cropAndResize = function (t, e, n, r, o, a) {
  15725. for (var i = t.shape, u = i[0], s = i[1], c = i[2], l = i[3], h = e.shape[0], f = r[0], p = r[1], d = ur([h, f, p, l], t.dtype), v = this.readSync(e.dataId), m = this.readSync(n.dataId), g = this.readSync(t.dataId), y = t.strides, x = d.strides, b = 0; b < h; b++) {
  15726. var w = 4 * b,
  15727. C = v[w],
  15728. E = v[w + 1],
  15729. R = v[w + 2],
  15730. I = v[w + 3],
  15731. k = m[b];
  15732. if (!(k >= u)) for (var S = f > 1 ? (R - C) * (s - 1) / (f - 1) : 0, A = p > 1 ? (I - E) * (c - 1) / (p - 1) : 0, D = 0; D < f; D++) {
  15733. var T = f > 1 ? C * (s - 1) + D * S : .5 * (C + R) * (s - 1);
  15734. if (T < 0 || T > s - 1) for (var N = 0; N < p; N++) for (var F = 0; F < l; F++) {
  15735. var O = F + N * x[2] + D * x[1] + b * x[0];
  15736. d.values[O] = a;
  15737. } else if ("bilinear" === o) {
  15738. var _ = Math.floor(T),
  15739. M = Math.ceil(T),
  15740. B = T - _;
  15741. for (N = 0; N < p; N++) {
  15742. if ((q = p > 1 ? E * (c - 1) + N * A : .5 * (E + I) * (c - 1)) < 0 || q > c - 1) for (F = 0; F < l; F++) {
  15743. O = F + N * x[2] + D * x[1] + b * x[0];
  15744. d.values[O] = a;
  15745. } else {
  15746. var P = Math.floor(q),
  15747. L = Math.ceil(q),
  15748. W = q - P;
  15749. for (F = 0; F < l; F++) {
  15750. var U = g[O = F + P * y[2] + _ * y[1] + k * y[0]],
  15751. V = g[O = F + L * y[2] + _ * y[1] + k * y[0]],
  15752. z = g[O = F + P * y[2] + M * y[1] + k * y[0]],
  15753. G = U + (V - U) * W,
  15754. H = z + (g[O = F + L * y[2] + M * y[1] + k * y[0]] - z) * W;
  15755. O = F + N * x[2] + D * x[1] + b * x[0], d.values[O] = G + (H - G) * B;
  15756. }
  15757. }
  15758. }
  15759. } else for (N = 0; N < p; ++N) {
  15760. var q;
  15761. if ((q = p > 1 ? E * (c - 1) + N * A : .5 * (E + I) * (c - 1)) < 0 || q > c - 1) for (F = 0; F < l; F++) {
  15762. O = F + N * x[2] + D * x[1] + b * x[0];
  15763. d.values[O] = a;
  15764. } else {
  15765. var K = Math.round(q),
  15766. j = Math.round(T);
  15767. for (F = 0; F < l; F++) {
  15768. var X = F + K * y[2] + j * y[1] + k * y[0],
  15769. $ = F + N * x[2] + D * x[1] + b * x[0];
  15770. d.values[$] = g[X];
  15771. }
  15772. }
  15773. }
  15774. }
  15775. }
  15776. return d.toTensor();
  15777. }, o.prototype.sparseToDense = function (t, e, n, r) {
  15778. var o = Hr(0, t, n),
  15779. a = o.sliceRank,
  15780. i = o.numUpdates,
  15781. u = o.sliceSize,
  15782. s = o.strides,
  15783. c = o.outputSize;
  15784. return this.scatter(t, e, n, c, u, i, a, s, r, !1);
  15785. }, o.prototype.gatherND = function (t, e) {
  15786. var n = e.shape,
  15787. r = n[n.length - 1],
  15788. o = Ur(t, e),
  15789. a = o[0],
  15790. i = o[1],
  15791. u = o[2],
  15792. s = o[3];
  15793. if (0 === i) return kn([], a, t.dtype);
  15794. for (var c = new lt([i, u], t.dtype), l = this.readSync(e.dataId), h = this.readSync(t.dataId), f = 0; f < i; f++) {
  15795. for (var p = [], d = 0, v = 0; v < r; v++) {
  15796. var m = l[f * r + v];
  15797. d += m * s[v], p.push(m);
  15798. }
  15799. if (d < 0 || d >= t.size / u) throw new Error("Invalid indices: " + p + " does not index into " + t.shape);
  15800. for (var g = 0; g < u; g++) c.values[f * u + g] = h[d * u + g];
  15801. }
  15802. return c.toTensor().reshape(a);
  15803. }, o.prototype.scatterND = function (t, e, n) {
  15804. var r = Hr(0, t, n),
  15805. o = r.sliceRank,
  15806. a = r.numUpdates,
  15807. i = r.sliceSize,
  15808. u = r.strides,
  15809. s = r.outputSize,
  15810. c = An(0);
  15811. return this.scatter(t, e, n, s, i, a, o, u, c, !0);
  15812. }, o.prototype.fill = function (t, e, n) {
  15813. var r = F(n = n || z(e), w(t));
  15814. return r.fill(e), Nt.makeTensor(r, t, n, this);
  15815. }, o.prototype.onesLike = function (t) {
  15816. if ("string" === t.dtype) throw new Error("onesLike is not supported for string tensors");
  15817. return this.fill(t.shape, 1, t.dtype);
  15818. }, o.prototype.zerosLike = function (t) {
  15819. var e = F(t.dtype, w(t.shape));
  15820. return this.makeOutput(e, t.shape, t.dtype);
  15821. }, o.prototype.linspace = function (t, e, n) {
  15822. return Do(t, e, n);
  15823. }, o.prototype.scatter = function (t, e, n, r, o, a, i, u, s, c) {
  15824. var l = [r / o, o],
  15825. h = this.readSync(t.dataId),
  15826. f = this.readSync(e.dataId);
  15827. if (0 === r) return kn([], n, e.dtype);
  15828. var p = new lt(l, e.dtype);
  15829. p.values.fill(this.readSync(s.dataId)[0]);
  15830. for (var d = 0; d < a; d++) {
  15831. for (var v = [], m = 0, g = 0; g < i; g++) {
  15832. var y = h[d * i + g];
  15833. v.push(y), m += y * u[g];
  15834. }
  15835. if (m < 0 || m >= r / o) throw new Error("Invalid indices: " + v + " does not index into " + n);
  15836. for (var x = 0; x < o; x++) c ? p.values[m * o + x] += f[d * o + x] : p.values[m * o + x] = 0 === e.rank ? f[0] : f[d * o + x];
  15837. }
  15838. return p.toTensor().reshape(n);
  15839. }, o;
  15840. }(co);
  15841. Nt.registerBackend("cpu", function () {
  15842. return new Sh();
  15843. }, 1), l({
  15844. kernelName: "Square",
  15845. backendName: "cpu",
  15846. kernelFunc: function (t) {
  15847. var e = t.inputs,
  15848. n = t.backend,
  15849. r = e.x,
  15850. o = n;
  15851. Ih(r, "square");
  15852. for (var a = o.data.get(r.dataId).values, i = new Float32Array(a.length), u = 0; u < a.length; ++u) {
  15853. var s = a[u];
  15854. i[u] = s * s;
  15855. }
  15856. return {
  15857. dataId: o.write(i, r.shape, r.dtype),
  15858. shape: r.shape,
  15859. dtype: r.dtype
  15860. };
  15861. }
  15862. }), l({
  15863. kernelName: "Square",
  15864. backendName: "webgl",
  15865. kernelFunc: function (t) {
  15866. var e = t.inputs,
  15867. n = t.backend,
  15868. r = e.x,
  15869. o = n,
  15870. a = new su(r.shape, "return x * x;");
  15871. return o.runWebGLProgram(a, [r], r.dtype);
  15872. }
  15873. });
  15874. var Ah = function () {
  15875. function t() { }
  15876. return t.prototype.fetch = function (t, e) {
  15877. return fetch(t, e);
  15878. }, t.prototype.now = function () {
  15879. return performance.now();
  15880. }, t.prototype.encode = function (t, e) {
  15881. if ("utf-8" !== e && "utf8" !== e) throw new Error("Browser's encoder only supports utf-8, but got " + e);
  15882. return null == this.textEncoder && (this.textEncoder = new TextEncoder()), this.textEncoder.encode(t);
  15883. }, t.prototype.decode = function (t, e) {
  15884. return new TextDecoder(e).decode(t);
  15885. }, t;
  15886. }();
  15887. a().get("IS_BROWSER") && a().setPlatform("browser", new Ah());
  15888. var Dh,
  15889. Th = function () {
  15890. return require("node-fetch");
  15891. },
  15892. Nh = function () {
  15893. function t() {
  15894. this.util = require("util"), this.textEncoder = new this.util.TextEncoder();
  15895. }
  15896. return t.prototype.fetch = function (t, e) {
  15897. return null != a().global.fetch ? a().global.fetch(t, e) : (null == Dh && (Dh = Th()), Dh(t, e));
  15898. }, t.prototype.now = function () {
  15899. var t = process.hrtime();
  15900. return 1e3 * t[0] + t[1] / 1e6;
  15901. }, t.prototype.encode = function (t, e) {
  15902. if ("utf-8" !== e && "utf8" !== e) throw new Error("Node built-in encoder only supports utf-8, but got " + e);
  15903. return this.textEncoder.encode(t);
  15904. }, t.prototype.decode = function (t, e) {
  15905. return 0 === t.length ? "" : new this.util.TextDecoder(e).decode(t);
  15906. }, t;
  15907. }();
  15908. a().get("IS_NODE") && a().setPlatform("node", new Nh());
  15909. var Fh = {
  15910. float32: 4,
  15911. int32: 4,
  15912. uint16: 2,
  15913. uint8: 1,
  15914. bool: 1
  15915. },
  15916. Oh = 4;
  15917. function _h(t, e) {
  15918. for (var n = {}, r = 0, o = function (e) {
  15919. var o = e.name,
  15920. a = e.dtype,
  15921. i = e.shape,
  15922. u = w(i),
  15923. s = void 0;
  15924. if (("quantization" in e)) {
  15925. var c = e.quantization;
  15926. if ("uint8" !== c.dtype && "uint16" !== c.dtype) throw new Error("Weight " + e.name + " has unknown quantization dtype " + c.dtype + ". Supported quantization dtypes are: 'uint8' and 'uint16'.");
  15927. var l = Fh[c.dtype],
  15928. h = t.slice(r, r + u * l),
  15929. f = "uint8" === c.dtype ? new Uint8Array(h) : new Uint16Array(h);
  15930. if ("float32" === a) s = Float32Array.from(f, function (t) {
  15931. return t * c.scale + c.min;
  15932. }); else {
  15933. if ("int32" !== a) throw new Error("Unsupported dtype in weight '" + o + "': " + a);
  15934. s = Int32Array.from(f, function (t) {
  15935. return Math.round(t * c.scale + c.min);
  15936. });
  15937. }
  15938. r += u * l;
  15939. } else if ("string" === a) {
  15940. var p = w(e.shape);
  15941. s = [];
  15942. for (var d = 0; d < p; d++) {
  15943. var v = new Uint32Array(t.slice(r, r + Oh))[0];
  15944. r += Oh;
  15945. var m = new Uint8Array(t.slice(r, r + v));
  15946. s.push(m), r += v;
  15947. }
  15948. } else {
  15949. var g = Fh[a];
  15950. h = t.slice(r, r + u * g);
  15951. if ("float32" === a) s = new Float32Array(h); else if ("int32" === a) s = new Int32Array(h); else {
  15952. if ("bool" !== a) throw new Error("Unsupported dtype in weight '" + o + "': " + a);
  15953. s = new Uint8Array(h);
  15954. }
  15955. r += u * g;
  15956. }
  15957. n[o] = kn(s, i, a);
  15958. }, a = 0, i = e; a < i.length; a++) {
  15959. o(i[a]);
  15960. }
  15961. return n;
  15962. }
  15963. function Mh(t) {
  15964. if (null === t) throw new Error("Invalid input value: " + JSON.stringify(t));
  15965. var e = 0,
  15966. n = [];
  15967. t.forEach(function (t) {
  15968. if (e += t.byteLength, n.push(t.byteLength === t.buffer.byteLength ? t : new t.constructor(t)), !(t instanceof Float32Array || t instanceof Int32Array || t instanceof Uint8Array)) throw new Error("Unsupported TypedArray subtype: " + t.constructor.name);
  15969. });
  15970. var r = new Uint8Array(e),
  15971. o = 0;
  15972. return n.forEach(function (t) {
  15973. r.set(new Uint8Array(t.buffer), o), o += t.byteLength;
  15974. }), r.buffer;
  15975. }
  15976. var Bh = "undefined" != typeof Buffer && ("undefined" == typeof Blob || "undefined" == typeof atob || "undefined" == typeof btoa);
  15977. function Ph(t) {
  15978. return Bh ? Buffer.byteLength(t) : new Blob([t]).size;
  15979. }
  15980. function Lh(t) {
  15981. var e = 0;
  15982. t.forEach(function (t) {
  15983. e += t.byteLength;
  15984. });
  15985. var n = new Uint8Array(e),
  15986. r = 0;
  15987. return t.forEach(function (t) {
  15988. n.set(new Uint8Array(t), r), r += t.byteLength;
  15989. }), n.buffer;
  15990. }
  15991. function Wh(t) {
  15992. for (t = t.trim(); t.endsWith("/");) t = t.slice(0, t.length - 1);
  15993. var e = t.split("/");
  15994. return e[e.length - 1];
  15995. }
  15996. function Uh(t) {
  15997. if (t.modelTopology instanceof ArrayBuffer) throw new Error("Expected JSON model topology, received ArrayBuffer.");
  15998. return {
  15999. dateSaved: new Date(),
  16000. modelTopologyType: "JSON",
  16001. modelTopologyBytes: null == t.modelTopology ? 0 : Ph(JSON.stringify(t.modelTopology)),
  16002. weightSpecsBytes: null == t.weightSpecs ? 0 : Ph(JSON.stringify(t.weightSpecs)),
  16003. weightDataBytes: null == t.weightData ? 0 : t.weightData.byteLength
  16004. };
  16005. }
  16006. var Vh = function () {
  16007. function t() {
  16008. this.saveRouters = [], this.loadRouters = [];
  16009. }
  16010. return t.getInstance = function () {
  16011. return null == t.instance && (t.instance = new t()), t.instance;
  16012. }, t.registerSaveRouter = function (e) {
  16013. t.getInstance().saveRouters.push(e);
  16014. }, t.registerLoadRouter = function (e) {
  16015. t.getInstance().loadRouters.push(e);
  16016. }, t.getSaveHandlers = function (e) {
  16017. return t.getHandlers(e, "save");
  16018. }, t.getLoadHandlers = function (e, n) {
  16019. return t.getHandlers(e, "load", n);
  16020. }, t.getHandlers = function (e, n, r) {
  16021. var o = [];
  16022. return ("load" === n ? t.getInstance().loadRouters : t.getInstance().saveRouters).forEach(function (t) {
  16023. var n = t(e, r);
  16024. null !== n && o.push(n);
  16025. }), o;
  16026. }, t;
  16027. }(),
  16028. zh = "://",
  16029. Gh = function () {
  16030. function t() {
  16031. this.managers = {};
  16032. }
  16033. return t.getInstance = function () {
  16034. return null == t.instance && (t.instance = new t()), t.instance;
  16035. }, t.registerManager = function (e, n) {
  16036. g(null != e, function () {
  16037. return "scheme must not be undefined or null.";
  16038. }), e.endsWith(zh) && (e = e.slice(0, e.indexOf(zh))), g(e.length > 0, function () {
  16039. return "scheme must not be an empty string.";
  16040. });
  16041. var r = t.getInstance();
  16042. g(null == r.managers[e], function () {
  16043. return "A model store manager is already registered for scheme '" + e + "'.";
  16044. }), r.managers[e] = n;
  16045. }, t.getManager = function (t) {
  16046. var e = this.getInstance().managers[t];
  16047. if (null == e) throw new Error("Cannot find model manager for scheme '" + t + "'");
  16048. return e;
  16049. }, t.getSchemes = function () {
  16050. return Object.keys(this.getInstance().managers);
  16051. }, t;
  16052. }();
  16053. function Hh(t) {
  16054. if (-1 === t.indexOf(zh)) throw new Error("The url string provided does not contain a scheme. Supported schemes are: " + Gh.getSchemes().join(","));
  16055. return {
  16056. scheme: t.split(zh)[0],
  16057. path: t.split(zh)[1]
  16058. };
  16059. }
  16060. function qh(t, e, o) {
  16061. return void 0 === o && (o = !1), n(this, void 0, void 0, function () {
  16062. var n, a, i, u, s, c, l, h, f;
  16063. return r(this, function (r) {
  16064. switch (r.label) {
  16065. case 0:
  16066. return g(t !== e, function () {
  16067. return "Old path and new path are the same: '" + t + "'";
  16068. }), g((n = Vh.getLoadHandlers(t)).length > 0, function () {
  16069. return "Copying failed because no load handler is found for source URL " + t + ".";
  16070. }), g(n.length < 2, function () {
  16071. return "Copying failed because more than one (" + n.length + ") load handlers for source URL " + t + ".";
  16072. }), a = n[0], g((i = Vh.getSaveHandlers(e)).length > 0, function () {
  16073. return "Copying failed because no save handler is found for destination URL " + e + ".";
  16074. }), g(i.length < 2, function () {
  16075. return "Copying failed because more than one (" + n.length + ") save handlers for destination URL " + e + ".";
  16076. }), u = i[0], s = Hh(t).scheme, c = Hh(t).path, l = s === Hh(t).scheme, [4, a.load()];
  16077. case 1:
  16078. return h = r.sent(), o && l ? [4, Gh.getManager(s).removeModel(c)] : [3, 3];
  16079. case 2:
  16080. r.sent(), r.label = 3;
  16081. case 3:
  16082. return [4, u.save(h)];
  16083. case 4:
  16084. return f = r.sent(), !o || l ? [3, 6] : [4, Gh.getManager(s).removeModel(c)];
  16085. case 5:
  16086. r.sent(), r.label = 6;
  16087. case 6:
  16088. return [2, f.modelArtifactsInfo];
  16089. }
  16090. });
  16091. });
  16092. }
  16093. var Kh = "models_store",
  16094. jh = "model_info_store";
  16095. function Xh() {
  16096. if (!a().getBool("IS_BROWSER")) throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser.");
  16097. var t = window,
  16098. e = t.indexedDB || t.mozIndexedDB || t.webkitIndexedDB || t.msIndexedDB || t.shimIndexedDB;
  16099. if (null == e) throw new Error("The current browser does not appear to support IndexedDB.");
  16100. return e;
  16101. }
  16102. function $h(t) {
  16103. var e = t.result;
  16104. e.createObjectStore(Kh, {
  16105. keyPath: "modelPath"
  16106. }), e.createObjectStore(jh, {
  16107. keyPath: "modelPath"
  16108. });
  16109. }
  16110. var Yh = function () {
  16111. function t(t) {
  16112. if (this.indexedDB = Xh(), null == t || !t) throw new Error("For IndexedDB, modelPath must not be null, undefined or empty.");
  16113. this.modelPath = t;
  16114. }
  16115. return t.prototype.save = function (t) {
  16116. return n(this, void 0, void 0, function () {
  16117. return r(this, function (e) {
  16118. if (t.modelTopology instanceof ArrayBuffer) throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");
  16119. return [2, this.databaseAction(this.modelPath, t)];
  16120. });
  16121. });
  16122. }, t.prototype.load = function () {
  16123. return n(this, void 0, void 0, function () {
  16124. return r(this, function (t) {
  16125. return [2, this.databaseAction(this.modelPath)];
  16126. });
  16127. });
  16128. }, t.prototype.databaseAction = function (t, e) {
  16129. var n = this;
  16130. return new Promise(function (t, r) {
  16131. var o = n.indexedDB.open("tensorflowjs", 1);
  16132. o.onupgradeneeded = function () {
  16133. return $h(o);
  16134. }, o.onsuccess = function () {
  16135. var a = o.result;
  16136. if (null == e) {
  16137. var i = a.transaction(Kh, "readonly"),
  16138. u = i.objectStore(Kh).get(n.modelPath);
  16139. u.onsuccess = function () {
  16140. if (null == u.result) return a.close(), r(new Error("Cannot find model with path '" + n.modelPath + "' in IndexedDB."));
  16141. t(u.result.modelArtifacts);
  16142. }, u.onerror = function (t) {
  16143. return a.close(), r(u.error);
  16144. }, i.oncomplete = function () {
  16145. return a.close();
  16146. };
  16147. } else {
  16148. var s,
  16149. c = Uh(e),
  16150. l = a.transaction(jh, "readwrite"),
  16151. h = l.objectStore(jh),
  16152. f = h.put({
  16153. modelPath: n.modelPath,
  16154. modelArtifactsInfo: c
  16155. });
  16156. f.onsuccess = function () {
  16157. var o = (s = a.transaction(Kh, "readwrite")).objectStore(Kh).put({
  16158. modelPath: n.modelPath,
  16159. modelArtifacts: e,
  16160. modelArtifactsInfo: c
  16161. });
  16162. o.onsuccess = function () {
  16163. return t({
  16164. modelArtifactsInfo: c
  16165. });
  16166. }, o.onerror = function (t) {
  16167. var e = (h = l.objectStore(jh)).delete(n.modelPath);
  16168. e.onsuccess = function () {
  16169. return a.close(), r(o.error);
  16170. }, e.onerror = function (t) {
  16171. return a.close(), r(o.error);
  16172. };
  16173. };
  16174. }, f.onerror = function (t) {
  16175. return a.close(), r(f.error);
  16176. }, l.oncomplete = function () {
  16177. null == s ? a.close() : s.oncomplete = function () {
  16178. return a.close();
  16179. };
  16180. };
  16181. }
  16182. }, o.onerror = function (t) {
  16183. return r(o.error);
  16184. };
  16185. });
  16186. }, t.URL_SCHEME = "indexeddb://", t;
  16187. }(),
  16188. Qh = function (t) {
  16189. return a().getBool("IS_BROWSER") && !Array.isArray(t) && t.startsWith(Yh.URL_SCHEME) ? (e = t.slice(Yh.URL_SCHEME.length), new Yh(e)) : null;
  16190. var e;
  16191. };
  16192. Vh.registerSaveRouter(Qh), Vh.registerLoadRouter(Qh);
  16193. var Jh = function () {
  16194. function t() {
  16195. this.indexedDB = Xh();
  16196. }
  16197. return t.prototype.listModels = function () {
  16198. return n(this, void 0, void 0, function () {
  16199. var t = this;
  16200. return r(this, function (e) {
  16201. return [2, new Promise(function (e, n) {
  16202. var r = t.indexedDB.open("tensorflowjs", 1);
  16203. r.onupgradeneeded = function () {
  16204. return $h(r);
  16205. }, r.onsuccess = function () {
  16206. var t = r.result,
  16207. o = t.transaction(jh, "readonly"),
  16208. a = o.objectStore(jh).getAll();
  16209. a.onsuccess = function () {
  16210. for (var t = {}, n = 0, r = a.result; n < r.length; n++) {
  16211. var o = r[n];
  16212. t[o.modelPath] = o.modelArtifactsInfo;
  16213. }
  16214. e(t);
  16215. }, a.onerror = function (e) {
  16216. return t.close(), n(a.error);
  16217. }, o.oncomplete = function () {
  16218. return t.close();
  16219. };
  16220. }, r.onerror = function (t) {
  16221. return n(r.error);
  16222. };
  16223. })];
  16224. });
  16225. });
  16226. }, t.prototype.removeModel = function (t) {
  16227. return n(this, void 0, void 0, function () {
  16228. var e = this;
  16229. return r(this, function (n) {
  16230. var r;
  16231. return t = (r = t).startsWith(Yh.URL_SCHEME) ? r.slice(Yh.URL_SCHEME.length) : r, [2, new Promise(function (n, r) {
  16232. var o = e.indexedDB.open("tensorflowjs", 1);
  16233. o.onupgradeneeded = function () {
  16234. return $h(o);
  16235. }, o.onsuccess = function () {
  16236. var e,
  16237. a = o.result,
  16238. i = a.transaction(jh, "readwrite"),
  16239. u = i.objectStore(jh),
  16240. s = u.get(t);
  16241. s.onsuccess = function () {
  16242. if (null == s.result) return a.close(), r(new Error("Cannot find model with path '" + t + "' in IndexedDB."));
  16243. var o = u.delete(t),
  16244. i = function () {
  16245. var o = (e = a.transaction(Kh, "readwrite")).objectStore(Kh).delete(t);
  16246. o.onsuccess = function () {
  16247. return n(s.result.modelArtifactsInfo);
  16248. }, o.onerror = function (t) {
  16249. return r(s.error);
  16250. };
  16251. };
  16252. o.onsuccess = i, o.onerror = function (t) {
  16253. return i(), a.close(), r(s.error);
  16254. };
  16255. }, s.onerror = function (t) {
  16256. return a.close(), r(s.error);
  16257. }, i.oncomplete = function () {
  16258. null == e ? a.close() : e.oncomplete = function () {
  16259. return a.close();
  16260. };
  16261. };
  16262. }, o.onerror = function (t) {
  16263. return r(o.error);
  16264. };
  16265. })];
  16266. });
  16267. });
  16268. }, t;
  16269. }();
  16270. if (a().getBool("IS_BROWSER")) try {
  16271. Gh.registerManager(Yh.URL_SCHEME, new Jh());
  16272. } catch (t) { }
  16273. var Zh = "/",
  16274. tf = "tensorflowjs_models",
  16275. ef = "info",
  16276. nf = "model_topology",
  16277. rf = "weight_specs",
  16278. of = "weight_data",
  16279. af = "model_metadata";
  16280. function uf(t) {
  16281. return {
  16282. info: [tf, t, ef].join(Zh),
  16283. topology: [tf, t, nf].join(Zh),
  16284. weightSpecs: [tf, t, rf].join(Zh),
  16285. weightData: [tf, t, of].join(Zh),
  16286. modelMetadata: [tf, t, af].join(Zh)
  16287. };
  16288. }
  16289. function sf(t) {
  16290. var e = t.split(Zh);
  16291. if (e.length < 3) throw new Error("Invalid key format: " + t);
  16292. return e.slice(1, e.length - 1).join(Zh);
  16293. }
  16294. var cf = function () {
  16295. function t(t) {
  16296. if (!a().getBool("IS_BROWSER") || void 0 === window.localStorage) throw new Error("The current environment does not support local storage.");
  16297. if (this.LS = window.localStorage, null == t || !t) throw new Error("For local storage, modelPath must not be null, undefined or empty.");
  16298. this.modelPath = t, this.keys = uf(this.modelPath);
  16299. }
  16300. return t.prototype.save = function (t) {
  16301. return n(this, void 0, void 0, function () {
  16302. var e, n, o;
  16303. return r(this, function (r) {
  16304. if (t.modelTopology instanceof ArrayBuffer) throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");
  16305. e = JSON.stringify(t.modelTopology), n = JSON.stringify(t.weightSpecs), o = Uh(t);
  16306. try {
  16307. return this.LS.setItem(this.keys.info, JSON.stringify(o)), this.LS.setItem(this.keys.topology, e), this.LS.setItem(this.keys.weightSpecs, n), this.LS.setItem(this.keys.weightData, (a = t.weightData, Bh ? Buffer.from(a).toString("base64") : btoa(String.fromCharCode.apply(null, new Uint8Array(a))))), this.LS.setItem(this.keys.modelMetadata, JSON.stringify({
  16308. format: t.format,
  16309. generatedBy: t.generatedBy,
  16310. convertedBy: t.convertedBy
  16311. })), [2, {
  16312. modelArtifactsInfo: o
  16313. }];
  16314. } catch (t) {
  16315. throw this.LS.removeItem(this.keys.info), this.LS.removeItem(this.keys.topology), this.LS.removeItem(this.keys.weightSpecs), this.LS.removeItem(this.keys.weightData), this.LS.removeItem(this.keys.modelMetadata), new Error("Failed to save model '" + this.modelPath + "' to local storage: size quota being exceeded is a possible cause of this failure: modelTopologyBytes=" + o.modelTopologyBytes + ", weightSpecsBytes=" + o.weightSpecsBytes + ", weightDataBytes=" + o.weightDataBytes + ".");
  16316. }
  16317. var a;
  16318. return [2];
  16319. });
  16320. });
  16321. }, t.prototype.load = function () {
  16322. return n(this, void 0, void 0, function () {
  16323. var t, e, n, o, a, i, u;
  16324. return r(this, function (r) {
  16325. if (null == (t = JSON.parse(this.LS.getItem(this.keys.info)))) throw new Error("In local storage, there is no model with name '" + this.modelPath + "'");
  16326. if ("JSON" !== t.modelTopologyType) throw new Error("BrowserLocalStorage does not support loading non-JSON model topology yet.");
  16327. if (e = {}, null == (n = JSON.parse(this.LS.getItem(this.keys.topology)))) throw new Error("In local storage, the topology of model '" + this.modelPath + "' is missing.");
  16328. if (e.modelTopology = n, null == (o = JSON.parse(this.LS.getItem(this.keys.weightSpecs)))) throw new Error("In local storage, the weight specs of model '" + this.modelPath + "' are missing.");
  16329. if (e.weightSpecs = o, null != (a = this.LS.getItem(this.keys.modelMetadata)) && (i = JSON.parse(a), e.format = i.format, e.generatedBy = i.generatedBy, e.convertedBy = i.convertedBy), null == (u = this.LS.getItem(this.keys.weightData))) throw new Error("In local storage, the binary weight values of model '" + this.modelPath + "' are missing.");
  16330. return e.weightData = function (t) {
  16331. if (Bh) {
  16332. var e = Buffer.from(t, "base64");
  16333. return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
  16334. }
  16335. for (var n = atob(t), r = new Uint8Array(n.length), o = 0; o < n.length; ++o) r.set([n.charCodeAt(o)], o);
  16336. return r.buffer;
  16337. }(u), [2, e];
  16338. });
  16339. });
  16340. }, t.URL_SCHEME = "localstorage://", t;
  16341. }(),
  16342. lf = function (t) {
  16343. return a().getBool("IS_BROWSER") && !Array.isArray(t) && t.startsWith(cf.URL_SCHEME) ? (e = t.slice(cf.URL_SCHEME.length), new cf(e)) : null;
  16344. var e;
  16345. };
  16346. Vh.registerSaveRouter(lf), Vh.registerLoadRouter(lf);
  16347. var hf = function () {
  16348. function t() {
  16349. g(a().getBool("IS_BROWSER"), function () {
  16350. return "Current environment is not a web browser";
  16351. }), g(void 0 !== window.localStorage, function () {
  16352. return "Current browser does not appear to support localStorage";
  16353. }), this.LS = window.localStorage;
  16354. }
  16355. return t.prototype.listModels = function () {
  16356. return n(this, void 0, void 0, function () {
  16357. var t, e, n, o, a, i;
  16358. return r(this, function (r) {
  16359. for (t = {}, e = tf + Zh, n = Zh + ef, o = 0; o < this.LS.length; ++o) (a = this.LS.key(o)).startsWith(e) && a.endsWith(n) && (i = sf(a), t[i] = JSON.parse(this.LS.getItem(a)));
  16360. return [2, t];
  16361. });
  16362. });
  16363. }, t.prototype.removeModel = function (t) {
  16364. return n(this, void 0, void 0, function () {
  16365. var e, n;
  16366. return r(this, function (r) {
  16367. var o;
  16368. if (t = (o = t).startsWith(cf.URL_SCHEME) ? o.slice(cf.URL_SCHEME.length) : o, e = uf(t), null == this.LS.getItem(e.info)) throw new Error("Cannot find model at path '" + t + "'");
  16369. return n = JSON.parse(this.LS.getItem(e.info)), this.LS.removeItem(e.info), this.LS.removeItem(e.topology), this.LS.removeItem(e.weightSpecs), this.LS.removeItem(e.weightData), [2, n];
  16370. });
  16371. });
  16372. }, t;
  16373. }();
  16374. if (a().getBool("IS_BROWSER")) try {
  16375. Gh.registerManager(cf.URL_SCHEME, new hf());
  16376. } catch (t) { }
  16377. var ff = "model",
  16378. pf = ".json",
  16379. df = ".weights.bin";
  16380. function vf(t) {
  16381. return new Promise(function (t) {
  16382. return setTimeout(t);
  16383. }).then(t);
  16384. }
  16385. var mf = function () {
  16386. function t(e) {
  16387. if (!a().getBool("IS_BROWSER")) throw new Error("browserDownloads() cannot proceed because the current environment is not a browser.");
  16388. e.startsWith(t.URL_SCHEME) && (e = e.slice(t.URL_SCHEME.length)), null != e && 0 !== e.length || (e = ff), this.modelTopologyFileName = e + pf, this.weightDataFileName = e + df;
  16389. }
  16390. return t.prototype.save = function (t) {
  16391. return n(this, void 0, void 0, function () {
  16392. var e, n, o, a, i, u;
  16393. return r(this, function (r) {
  16394. switch (r.label) {
  16395. case 0:
  16396. if ("undefined" == typeof document) throw new Error("Browser downloads are not supported in this environment since `document` is not present");
  16397. if (e = window.URL.createObjectURL(new Blob([t.weightData], {
  16398. type: "application/octet-stream"
  16399. })), !(t.modelTopology instanceof ArrayBuffer)) return [3, 1];
  16400. throw new Error("BrowserDownloads.save() does not support saving model topology in binary formats yet.");
  16401. case 1:
  16402. return n = [{
  16403. paths: ["./" + this.weightDataFileName],
  16404. weights: t.weightSpecs
  16405. }], o = {
  16406. modelTopology: t.modelTopology,
  16407. format: t.format,
  16408. generatedBy: t.generatedBy,
  16409. convertedBy: t.convertedBy,
  16410. weightsManifest: n
  16411. }, a = window.URL.createObjectURL(new Blob([JSON.stringify(o)], {
  16412. type: "application/json"
  16413. })), (i = null == this.jsonAnchor ? document.createElement("a") : this.jsonAnchor).download = this.modelTopologyFileName, i.href = a, [4, vf(function () {
  16414. return i.dispatchEvent(new MouseEvent("click"));
  16415. })];
  16416. case 2:
  16417. return r.sent(), null == t.weightData ? [3, 4] : ((u = null == this.weightDataAnchor ? document.createElement("a") : this.weightDataAnchor).download = this.weightDataFileName, u.href = e, [4, vf(function () {
  16418. return u.dispatchEvent(new MouseEvent("click"));
  16419. })]);
  16420. case 3:
  16421. r.sent(), r.label = 4;
  16422. case 4:
  16423. return [2, {
  16424. modelArtifactsInfo: Uh(t)
  16425. }];
  16426. }
  16427. });
  16428. });
  16429. }, t.URL_SCHEME = "downloads://", t;
  16430. }(),
  16431. gf = function () {
  16432. function t(t) {
  16433. if (null == t || t.length < 1) throw new Error("When calling browserFiles, at least 1 file is required, but received " + t);
  16434. this.files = t;
  16435. }
  16436. return t.prototype.load = function () {
  16437. return n(this, void 0, void 0, function () {
  16438. var t,
  16439. e,
  16440. n = this;
  16441. return r(this, function (r) {
  16442. return t = this.files[0], e = this.files.slice(1), [2, new Promise(function (r, o) {
  16443. var a = new FileReader();
  16444. a.onload = function (a) {
  16445. var i = JSON.parse(a.target.result),
  16446. u = i.modelTopology;
  16447. if (null != u) {
  16448. 0 === e.length && r({
  16449. modelTopology: u
  16450. });
  16451. var s = i.weightsManifest;
  16452. if (null != s) {
  16453. var c;
  16454. try {
  16455. c = n.checkManifestAndWeightFiles(s, e);
  16456. } catch (t) {
  16457. return void o(t);
  16458. }
  16459. var l = [],
  16460. h = [],
  16461. f = [];
  16462. s.forEach(function (t) {
  16463. t.paths.forEach(function (t) {
  16464. h.push(t), f.push(null);
  16465. }), l.push.apply(l, t.weights);
  16466. }), s.forEach(function (t) {
  16467. t.paths.forEach(function (t) {
  16468. var e = new FileReader();
  16469. e.onload = function (e) {
  16470. var n = e.target.result,
  16471. o = h.indexOf(t);
  16472. f[o] = n, -1 === f.indexOf(null) && r({
  16473. modelTopology: u,
  16474. weightSpecs: l,
  16475. weightData: Lh(f)
  16476. });
  16477. }, e.onerror = function (e) {
  16478. return o("Failed to weights data from file of path '" + t + "'.");
  16479. }, e.readAsArrayBuffer(c[t]);
  16480. });
  16481. });
  16482. } else o(new Error("weightManifest field is missing from file " + t.name));
  16483. } else o(new Error("modelTopology field is missing from file " + t.name));
  16484. }, a.onerror = function (e) {
  16485. return o("Failed to read model topology and weights manifest JSON from file '" + t.name + "'. BrowserFiles supports loading Keras-style tf.Model artifacts only.");
  16486. }, a.readAsText(t);
  16487. })];
  16488. });
  16489. });
  16490. }, t.prototype.checkManifestAndWeightFiles = function (t, e) {
  16491. for (var n = [], r = e.map(function (t) {
  16492. return Wh(t.name);
  16493. }), o = {}, a = 0, i = t; a < i.length; a++) {
  16494. i[a].paths.forEach(function (t) {
  16495. var a = Wh(t);
  16496. if (-1 !== n.indexOf(a)) throw new Error("Duplicate file basename found in weights manifest: '" + a + "'");
  16497. if (n.push(a), -1 === r.indexOf(a)) throw new Error("Weight file with basename '" + a + "' is not provided.");
  16498. o[t] = e[r.indexOf(a)];
  16499. });
  16500. }
  16501. if (n.length !== e.length) throw new Error("Mismatch in the number of files in weights manifest (" + n.length + ") and the number of weight files provided (" + e.length + ").");
  16502. return o;
  16503. }, t;
  16504. }();
  16505. function yf(t, e, n, r) {
  16506. !function (t) {
  16507. g(null != t && Array.isArray(t) && t.length > 0, function () {
  16508. return "promises must be a none empty array";
  16509. });
  16510. }(t), function (t, e) {
  16511. g(t >= 0 && t <= 1, function () {
  16512. return "Progress fraction must be in range [0, 1], but got startFraction " + t;
  16513. }), g(e >= 0 && e <= 1, function () {
  16514. return "Progress fraction must be in range [0, 1], but got endFraction " + e;
  16515. }), g(e >= t, function () {
  16516. return "startFraction must be no more than endFraction, but got startFraction " + t + " and endFraction " + e;
  16517. });
  16518. }(n = null == n ? 0 : n, r = null == r ? 1 : r);
  16519. var o = 0;
  16520. return Promise.all(t.map(function (a) {
  16521. return a.then(function (a) {
  16522. var i = n + ++o / t.length * (r - n);
  16523. return e(i), a;
  16524. }), a;
  16525. }));
  16526. }
  16527. function xf(t, e) {
  16528. return n(this, void 0, void 0, function () {
  16529. var n, o, i, u, s, c, l, h, f;
  16530. return r(this, function (r) {
  16531. switch (r.label) {
  16532. case 0:
  16533. return null == e && (e = {}), n = null == e.fetchFunc ? a().platform.fetch : e.fetchFunc, o = t.map(function (t) {
  16534. return n(t, e.requestInit, {
  16535. isBinary: !0
  16536. });
  16537. }), i = 0, u = .5, null != e.onProgress ? [3, 2] : [4, Promise.all(o)];
  16538. case 1:
  16539. return s = r.sent(), [3, 4];
  16540. case 2:
  16541. return [4, yf(o, e.onProgress, i, u)];
  16542. case 3:
  16543. s = r.sent(), r.label = 4;
  16544. case 4:
  16545. return c = s.map(function (t) {
  16546. return t.arrayBuffer();
  16547. }), l = .5, h = 1, null != e.onProgress ? [3, 6] : [4, Promise.all(c)];
  16548. case 5:
  16549. return f = r.sent(), [3, 8];
  16550. case 6:
  16551. return [4, yf(c, e.onProgress, l, h)];
  16552. case 7:
  16553. f = r.sent(), r.label = 8;
  16554. case 8:
  16555. return [2, f];
  16556. }
  16557. });
  16558. });
  16559. }
  16560. function bf(t) {
  16561. var e = this;
  16562. return function (o, a, i) {
  16563. return void 0 === a && (a = ""), n(e, void 0, void 0, function () {
  16564. var e, n, u, s, c, l, h, f, p, d;
  16565. return r(this, function (r) {
  16566. switch (r.label) {
  16567. case 0:
  16568. if (e = o.map(function () {
  16569. return !1;
  16570. }), n = {}, u = null != i ? i.map(function () {
  16571. return !1;
  16572. }) : [], s = [], o.forEach(function (t, r) {
  16573. var o = 0;
  16574. t.weights.forEach(function (t) {
  16575. var a = "quantization" in t ? t.quantization.dtype : t.dtype,
  16576. c = Fh[a] * w(t.shape),
  16577. l = function () {
  16578. e[r] = !0, null == n[r] && (n[r] = []), n[r].push({
  16579. manifestEntry: t,
  16580. groupOffset: o,
  16581. sizeBytes: c
  16582. });
  16583. };
  16584. null != i ? i.forEach(function (e, n) {
  16585. e === t.name && (l(), u[n] = !0);
  16586. }) : l(), s.push(t.name), o += c;
  16587. });
  16588. }), !u.every(function (t) {
  16589. return t;
  16590. })) throw c = i.filter(function (t, e) {
  16591. return !u[e];
  16592. }), new Error("Could not find weights in manifest with names: " + c.join(", ") + ". \nManifest JSON has weights with names: " + s.join(", ") + ".");
  16593. return l = e.reduce(function (t, e, n) {
  16594. return e && t.push(n), t;
  16595. }, []), h = [], l.forEach(function (t) {
  16596. o[t].paths.forEach(function (t) {
  16597. var e = a + (a.endsWith("/") ? "" : "/") + t;
  16598. h.push(e);
  16599. });
  16600. }), [4, t(h)];
  16601. case 1:
  16602. return f = r.sent(), p = {}, d = 0, l.forEach(function (t) {
  16603. for (var e = o[t].paths.length, r = 0, a = 0; a < e; a++) r += f[d + a].byteLength;
  16604. for (var i = new ArrayBuffer(r), u = new Uint8Array(i), s = 0, c = 0; c < e; c++) {
  16605. var l = new Uint8Array(f[d + c]);
  16606. u.set(l, s), s += l.byteLength;
  16607. }
  16608. n[t].forEach(function (t) {
  16609. var e = _h(i.slice(t.groupOffset, t.groupOffset + t.sizeBytes), [t.manifestEntry]);
  16610. for (var n in e) p[n] = e[n];
  16611. }), d += e;
  16612. }), [2, p];
  16613. }
  16614. });
  16615. });
  16616. };
  16617. }
  16618. Vh.registerSaveRouter(function (t) {
  16619. return a().getBool("IS_BROWSER") && !Array.isArray(t) && t.startsWith(mf.URL_SCHEME) ? (e = t.slice(mf.URL_SCHEME.length), void 0 === e && (e = "model"), new mf(e)) : null;
  16620. var e;
  16621. });
  16622. var wf = function () {
  16623. function t(t, e) {
  16624. if (this.DEFAULT_METHOD = "POST", null == e && (e = {}), this.weightPathPrefix = e.weightPathPrefix, this.onProgress = e.onProgress, null != e.fetchFunc ? (g("function" == typeof e.fetchFunc, function () {
  16625. return "Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)";
  16626. }), this.fetch = e.fetchFunc) : this.fetch = a().platform.fetch, g(null != t && t.length > 0, function () {
  16627. return "URL path for http must not be null, undefined or empty.";
  16628. }), Array.isArray(t) && g(2 === t.length, function () {
  16629. return "URL paths for http must have a length of 2, (actual length is " + t.length + ").";
  16630. }), this.path = t, null != e.requestInit && null != e.requestInit.body) throw new Error("requestInit is expected to have no pre-existing body, but has one.");
  16631. this.requestInit = e.requestInit || {};
  16632. }
  16633. return t.prototype.save = function (t) {
  16634. return n(this, void 0, void 0, function () {
  16635. var e, n, o, a;
  16636. return r(this, function (r) {
  16637. switch (r.label) {
  16638. case 0:
  16639. if (t.modelTopology instanceof ArrayBuffer) throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");
  16640. return (e = Object.assign({
  16641. method: this.DEFAULT_METHOD
  16642. }, this.requestInit)).body = new FormData(), n = [{
  16643. paths: ["./model.weights.bin"],
  16644. weights: t.weightSpecs
  16645. }], o = {
  16646. modelTopology: t.modelTopology,
  16647. format: t.format,
  16648. generatedBy: t.generatedBy,
  16649. convertedBy: t.convertedBy,
  16650. userDefinedMetadata: t.userDefinedMetadata,
  16651. weightsManifest: n
  16652. }, e.body.append("model.json", new Blob([JSON.stringify(o)], {
  16653. type: "application/json"
  16654. }), "model.json"), null != t.weightData && e.body.append("model.weights.bin", new Blob([t.weightData], {
  16655. type: "application/octet-stream"
  16656. }), "model.weights.bin"), [4, this.fetch(this.path, e)];
  16657. case 1:
  16658. if ((a = r.sent()).ok) return [2, {
  16659. modelArtifactsInfo: Uh(t),
  16660. responses: [a]
  16661. }];
  16662. throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status " + a.status + ".");
  16663. }
  16664. });
  16665. });
  16666. }, t.prototype.load = function () {
  16667. return n(this, void 0, void 0, function () {
  16668. var t, e, n, o, a, i, u, s;
  16669. return r(this, function (r) {
  16670. switch (r.label) {
  16671. case 0:
  16672. return [4, this.fetch(this.path, this.requestInit)];
  16673. case 1:
  16674. if (!(t = r.sent()).ok) throw new Error("Request to " + this.path + " failed with status code " + t.status + ". Please verify this URL points to the model JSON of the model to load.");
  16675. r.label = 2;
  16676. case 2:
  16677. return r.trys.push([2, 4, , 5]), [4, t.json()];
  16678. case 3:
  16679. return e = r.sent(), [3, 5];
  16680. case 4:
  16681. throw r.sent(), n = "Failed to parse model JSON of response from " + this.path + ".", this.path.endsWith(".pb") ? n += " Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository." : n += " Please make sure the server is serving valid JSON for this request.", new Error(n);
  16682. case 5:
  16683. if (o = e.modelTopology, a = e.weightsManifest, null == o && null == a) throw new Error("The JSON from HTTP path " + this.path + " contains neither model topology or manifest for weights.");
  16684. return null == a ? [3, 7] : [4, this.loadWeights(a)];
  16685. case 6:
  16686. s = r.sent(), i = s[0], u = s[1], r.label = 7;
  16687. case 7:
  16688. return [2, {
  16689. modelTopology: o,
  16690. weightSpecs: i,
  16691. weightData: u
  16692. }];
  16693. }
  16694. });
  16695. });
  16696. }, t.prototype.loadWeights = function (t) {
  16697. return n(this, void 0, void 0, function () {
  16698. var e, n, o, a, i, u, s, c, l, h, f;
  16699. return r(this, function (r) {
  16700. switch (r.label) {
  16701. case 0:
  16702. for (e = Array.isArray(this.path) ? this.path[1] : this.path, n = function (t) {
  16703. var e = t.lastIndexOf("/"),
  16704. n = t.lastIndexOf("?"),
  16705. r = t.substring(0, e),
  16706. o = n > e ? t.substring(n) : "";
  16707. return [r + "/", o];
  16708. }(e), o = n[0], a = n[1], i = this.weightPathPrefix || o, u = [], s = 0, c = t; s < c.length; s++) l = c[s], u.push.apply(u, l.weights);
  16709. return h = [], t.forEach(function (t) {
  16710. t.paths.forEach(function (t) {
  16711. h.push(i + t + a);
  16712. });
  16713. }), [4, xf(h, {
  16714. requestInit: this.requestInit,
  16715. fetchFunc: this.fetch,
  16716. onProgress: this.onProgress
  16717. })];
  16718. case 1:
  16719. return f = r.sent(), [2, [u, Lh(f)]];
  16720. }
  16721. });
  16722. });
  16723. }, t.URL_SCHEME_REGEX = /^https?:\/\//, t;
  16724. }();
  16725. function Cf(t) {
  16726. return null != t.match(wf.URL_SCHEME_REGEX);
  16727. }
  16728. var Ef = function (t, e) {
  16729. if ("undefined" == typeof fetch) return null;
  16730. return (Array.isArray(t) ? t.every(function (t) {
  16731. return Cf(t);
  16732. }) : Cf(t)) ? Rf(t, {
  16733. onProgress: e
  16734. }) : null;
  16735. };
  16736. function Rf(t, e) {
  16737. return new wf(t, e);
  16738. }
  16739. Vh.registerSaveRouter(Ef), Vh.registerLoadRouter(Ef);
  16740. var If = function () {
  16741. function t(t) {
  16742. this.modelArtifacts = t;
  16743. }
  16744. return t.prototype.load = function () {
  16745. return n(this, void 0, void 0, function () {
  16746. return r(this, function (t) {
  16747. return [2, this.modelArtifacts];
  16748. });
  16749. });
  16750. }, t;
  16751. }(),
  16752. kf = function () {
  16753. function t(t) {
  16754. this.saveHandler = t;
  16755. }
  16756. return t.prototype.save = function (t) {
  16757. return n(this, void 0, void 0, function () {
  16758. return r(this, function (e) {
  16759. return [2, this.saveHandler(t)];
  16760. });
  16761. });
  16762. }, t;
  16763. }();
  16764. var Sf = Object.freeze({
  16765. browserFiles: function (t) {
  16766. return new gf(t);
  16767. },
  16768. browserHTTPRequest: function (t, e) {
  16769. return Rf(t, e);
  16770. },
  16771. concatenateArrayBuffers: Lh,
  16772. decodeWeights: _h,
  16773. encodeWeights: function (t, e) {
  16774. return n(this, void 0, void 0, function () {
  16775. var o,
  16776. a,
  16777. i,
  16778. u,
  16779. s,
  16780. c = this;
  16781. return r(this, function (l) {
  16782. switch (l.label) {
  16783. case 0:
  16784. for (o = [], a = [], i = Array.isArray(t) ? t.map(function (t) {
  16785. return t.name;
  16786. }) : Object.keys(t), u = function (u) {
  16787. var s = i[u],
  16788. l = Array.isArray(t) ? t[u].tensor : t[s];
  16789. if ("float32" !== l.dtype && "int32" !== l.dtype && "bool" !== l.dtype && "string" !== l.dtype) throw new Error("Unsupported dtype in weight '" + s + "': " + l.dtype);
  16790. var h = {
  16791. name: s,
  16792. shape: l.shape,
  16793. dtype: l.dtype
  16794. };
  16795. if ("string" === l.dtype) {
  16796. var f = new Promise(function (t) {
  16797. return n(c, void 0, void 0, function () {
  16798. var e, n, o, a, i, u, s;
  16799. return r(this, function (r) {
  16800. switch (r.label) {
  16801. case 0:
  16802. return [4, l.bytes()];
  16803. case 1:
  16804. for (e = r.sent(), n = e.reduce(function (t, e) {
  16805. return t + e.length;
  16806. }, 0) + Oh * e.length, o = new Uint8Array(n), a = 0, i = 0; i < e.length; i++) u = e[i], s = new Uint8Array(new Uint32Array([u.length]).buffer), o.set(s, a), a += Oh, o.set(u, a), a += u.length;
  16807. return t(o), [2];
  16808. }
  16809. });
  16810. });
  16811. });
  16812. a.push(f);
  16813. } else a.push(l.data());
  16814. null != e && (h.group = e), o.push(h);
  16815. }, s = 0; s < i.length; ++s) u(s);
  16816. return [4, Promise.all(a)];
  16817. case 1:
  16818. return [2, {
  16819. data: Mh(l.sent()),
  16820. specs: o
  16821. }];
  16822. }
  16823. });
  16824. });
  16825. },
  16826. fromMemory: function (t, e, n, r) {
  16827. return 1 === arguments.length ? null != t.modelTopology || null != t.weightSpecs ? new If(t) : (console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."), new If({
  16828. modelTopology: t
  16829. })) : (console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."), new If({
  16830. modelTopology: t,
  16831. weightSpecs: e,
  16832. weightData: n,
  16833. trainingConfig: r
  16834. }));
  16835. },
  16836. getLoadHandlers: function (t, e) {
  16837. return Vh.getLoadHandlers(t, e);
  16838. },
  16839. getModelArtifactsInfoForJSON: Uh,
  16840. getSaveHandlers: function (t) {
  16841. return Vh.getSaveHandlers(t);
  16842. },
  16843. http: Rf,
  16844. isHTTPScheme: Cf,
  16845. loadWeights: function (t, e, o, a) {
  16846. return void 0 === e && (e = ""), n(this, void 0, void 0, function () {
  16847. return r(this, function (n) {
  16848. return [2, bf(function (t) {
  16849. return xf(t, {
  16850. requestInit: a
  16851. });
  16852. })(t, e, o)];
  16853. });
  16854. });
  16855. },
  16856. registerLoadRouter: function (t) {
  16857. return Vh.registerLoadRouter(t);
  16858. },
  16859. registerSaveRouter: function (t) {
  16860. return Vh.registerSaveRouter(t);
  16861. },
  16862. weightsLoaderFactory: bf,
  16863. withSaveHandler: function (t) {
  16864. return new kf(t);
  16865. },
  16866. copyModel: function (t, e) {
  16867. return n(this, void 0, void 0, function () {
  16868. return r(this, function (n) {
  16869. return [2, qh(t, e, !1)];
  16870. });
  16871. });
  16872. },
  16873. listModels: function () {
  16874. return n(this, void 0, void 0, function () {
  16875. var t, e, n, o, a, i, u;
  16876. return r(this, function (r) {
  16877. switch (r.label) {
  16878. case 0:
  16879. t = Gh.getSchemes(), e = {}, n = 0, o = t, r.label = 1;
  16880. case 1:
  16881. return n < o.length ? (a = o[n], [4, Gh.getManager(a).listModels()]) : [3, 4];
  16882. case 2:
  16883. for (u in i = r.sent()) e[a + zh + u] = i[u];
  16884. r.label = 3;
  16885. case 3:
  16886. return n++, [3, 1];
  16887. case 4:
  16888. return [2, e];
  16889. }
  16890. });
  16891. });
  16892. },
  16893. moveModel: function (t, e) {
  16894. return n(this, void 0, void 0, function () {
  16895. return r(this, function (n) {
  16896. return [2, qh(t, e, !0)];
  16897. });
  16898. });
  16899. },
  16900. removeModel: function (t) {
  16901. return n(this, void 0, void 0, function () {
  16902. var e;
  16903. return r(this, function (n) {
  16904. return e = Hh(t), [2, Gh.getManager(e.scheme).removeModel(e.path)];
  16905. });
  16906. });
  16907. }
  16908. });
  16909. exports.io = Sf;
  16910. var Af = Cn({
  16911. confusionMatrix_: function (t, e, n) {
  16912. var r = ln(t, "labels", "confusionMatrix"),
  16913. o = ln(e, "predictions", "confusionMatrix");
  16914. g(null == n || n > 0 && Number.isInteger(n), function () {
  16915. return "If provided, numClasses must be a positive integer, but got " + n;
  16916. }), g(1 === r.rank, function () {
  16917. return "Expected the rank of labels to be 1, but got " + r.rank;
  16918. }), g(1 === o.rank, function () {
  16919. return "Expected the rank of predictions to be 1, but got " + o.rank;
  16920. }), g(r.shape[0] === o.shape[0], function () {
  16921. return "Mismatch in the number of examples: " + r.shape[0] + " vs. " + o.shape[0] + ". Labels and predictions should have the same number of elements.";
  16922. }), g(n > 0 && Number.isInteger(n), function () {
  16923. return "numClasses is required to be a positive integer, but got " + n;
  16924. });
  16925. var a = gr(r.asType("int32"), n),
  16926. i = gr(o.asType("int32"), n);
  16927. return a.transpose().matMul(i).asType("int32");
  16928. }
  16929. }),
  16930. Df = Object.freeze({
  16931. confusionMatrix: Af
  16932. });
  16933. exports.math = Df;
  16934. var Tf = Cn({
  16935. fromPixels_: function (t, e) {
  16936. if (void 0 === e && (e = 3), e > 4) throw new Error("Cannot construct Tensor with more than 4 channels from pixels.");
  16937. var n = "undefined" != typeof HTMLVideoElement && t instanceof HTMLVideoElement;
  16938. if (n && n && t.readyState < 2) throw new Error("The video element has not loaded data yet. Please wait for `loadeddata` event on the <video> element.");
  16939. return Nt.fromPixels(t, e);
  16940. }
  16941. }),
  16942. Nf = Object.freeze({
  16943. toPixels: function (t, e) {
  16944. return n(this, void 0, void 0, function () {
  16945. var n, o, a, i, u, s, c, l, h, f, p, d, v, m, g, y, x, b, w, C, E, R, I;
  16946. return r(this, function (r) {
  16947. switch (r.label) {
  16948. case 0:
  16949. if (n = ln(t, "img", "toPixels"), t instanceof dt || (n = n.toInt()), 2 !== n.rank && 3 !== n.rank) throw new Error("toPixels only supports rank 2 or 3 tensors, got rank " + n.rank + ".");
  16950. if (o = n.shape.slice(0, 2), a = o[0], i = o[1], (u = 2 === n.rank ? 1 : n.shape[2]) > 4 || 2 === u) throw new Error("toPixels only supports depth of size 1, 3 or 4 but got " + u);
  16951. return [4, n.data()];
  16952. case 1:
  16953. return s = r.sent(), c = n.min(), l = n.max(), [4, Promise.all([c.data(), l.data()])];
  16954. case 2:
  16955. if (h = r.sent(), f = h[0], p = h[1], d = f[0], v = p[0], c.dispose(), l.dispose(), "float32" === n.dtype) {
  16956. if (d < 0 || v > 1) throw new Error("Tensor values for a float32 Tensor must be in the range [0 - 1] but got range [" + d + " - " + v + "].");
  16957. } else {
  16958. if ("int32" !== n.dtype) throw new Error("Unsupported type for toPixels: " + n.dtype + ". Please use float32 or int32 tensors.");
  16959. if (d < 0 || v > 255) throw new Error("Tensor values for a int32 Tensor must be in the range [0 - 255] but got range [" + d + " - " + v + "].");
  16960. }
  16961. for (m = "float32" === n.dtype ? 255 : 1, g = new Uint8ClampedArray(i * a * 4), y = 0; y < a * i; ++y) x = void 0, b = void 0, w = void 0, C = void 0, 1 === u ? (x = s[y] * m, b = s[y] * m, w = s[y] * m, C = 255) : 3 === u ? (x = s[3 * y] * m, b = s[3 * y + 1] * m, w = s[3 * y + 2] * m, C = 255) : 4 === u && (x = s[4 * y] * m, b = s[4 * y + 1] * m, w = s[4 * y + 2] * m, C = s[4 * y + 3] * m), g[0 + (E = 4 * y)] = Math.round(x), g[E + 1] = Math.round(b), g[E + 2] = Math.round(w), g[E + 3] = Math.round(C);
  16962. return null != e && (e.width = i, e.height = a, R = e.getContext("2d"), I = new ImageData(g, i, a), R.putImageData(I, 0, 0)), n !== t && n.dispose(), [2, g];
  16963. }
  16964. });
  16965. });
  16966. },
  16967. fromPixels: Tf
  16968. }),
  16969. Ff = function () {
  16970. function t() { }
  16971. return t.prototype.getClassName = function () {
  16972. return this.constructor.className;
  16973. }, t.fromConfig = function (t, e) {
  16974. return new t(e);
  16975. }, t;
  16976. }(),
  16977. Of = function () {
  16978. function t() {
  16979. this.classNameMap = {};
  16980. }
  16981. return t.getMap = function () {
  16982. return null == t.instance && (t.instance = new t()), t.instance;
  16983. }, t.register = function (e) {
  16984. t.getMap().classNameMap[e.className] = [e, e.fromConfig];
  16985. }, t;
  16986. }();
  16987. exports.browser = Nf;
  16988. function _f(t) {
  16989. g(null != t.className, function () {
  16990. return "Class being registered does not have the static className property defined.";
  16991. }), g("string" == typeof t.className, function () {
  16992. return "className is required to be a string, but got type " + typeof t.className;
  16993. }), g(t.className.length > 0, function () {
  16994. return "Class being registered has an empty-string as its className, which is disallowed.";
  16995. }), Of.register(t);
  16996. }
  16997. var Mf = Object.freeze({
  16998. Serializable: Ff,
  16999. SerializationMap: Of,
  17000. registerClass: _f
  17001. }),
  17002. Bf = .001,
  17003. Pf = .1;
  17004. exports.serialization = Mf;
  17005. function Lf() {
  17006. return 32 === Nt.backend.floatPrecision() ? Bf : Pf;
  17007. }
  17008. function Wf(t, e, n) {
  17009. var r = !0;
  17010. if ((B(t) || B(e)) && (r = !1), B(t) && B(e) && (r = !0), r) {
  17011. var o = t.constructor.name,
  17012. a = e.constructor.name;
  17013. if (o !== a) throw new Error("Arrays are of different type. Actual: " + o + ". Expected: " + a);
  17014. }
  17015. if (Array.isArray(t) && Array.isArray(e)) {
  17016. var i = sn(t),
  17017. u = sn(e);
  17018. if (!C(i, u)) throw new Error("Arrays have different shapes. Actual: [" + i + "]. Expected: [" + u + "]");
  17019. }
  17020. var s = B(t) ? t : b(t),
  17021. c = B(e) ? e : b(e);
  17022. if (s.length !== c.length) throw new Error("Arrays have different lengths actual: " + s.length + " vs expected: " + c.length + ".\nActual: " + s + ".\nExpected: " + c + ".");
  17023. for (var l = 0; l < c.length; ++l) {
  17024. var h = s[l],
  17025. f = c[l];
  17026. if (!n(h, f)) throw new Error("Arrays differ: actual[" + l + "] = " + h + ", expected[" + l + "] = " + f + ".\nActual: " + s + ".\nExpected: " + c + ".");
  17027. }
  17028. }
  17029. function Uf(t, e, n) {
  17030. return !isFinite(t) && !isFinite(e) || !(isNaN(t) || isNaN(e) || Math.abs(t - e) > n);
  17031. }
  17032. var Vf = Object.freeze({
  17033. TEST_EPSILON_FLOAT16: Pf,
  17034. expectArraysClose: function (t, e, n) {
  17035. return null == n && (n = Lf()), Wf(t, e, function (t, e) {
  17036. return Uf(t, e, n);
  17037. });
  17038. },
  17039. testEpsilon: Lf,
  17040. expectPromiseToFail: function (t, e) {
  17041. t().then(function () {
  17042. return e.fail();
  17043. }, function () {
  17044. return e();
  17045. });
  17046. },
  17047. expectArraysEqual: function (t, e) {
  17048. var n = "string" == typeof e || "number" == typeof e || "boolean" == typeof e ? [e] : e;
  17049. return W(t) || W(t[0]) || W(e) || W(e[0]) ? Wf(t, n, function (t, e) {
  17050. return t == e;
  17051. }) : Wf(t, e, function (t, e) {
  17052. return Uf(t, e, 0);
  17053. });
  17054. },
  17055. expectNumbersClose: function (t, e, n) {
  17056. if (null == n && (n = Lf()), !Uf(t, e, n)) throw new Error("Numbers differ: actual === " + t + ", expected === " + e);
  17057. },
  17058. expectValuesInRange: function (t, e, n) {
  17059. for (var r = 0; r < t.length; r++) if (t[r] < e || t[r] > n) throw new Error("Value out of range:" + t[r] + " low: " + e + ", high: " + n);
  17060. },
  17061. expectArrayBuffersEqual: function (t, e) {
  17062. expect(new Float32Array(t)).toEqual(new Float32Array(e));
  17063. }
  17064. }),
  17065. zf = "1.3.1";
  17066. exports.version_core = zf;
  17067. exports.test_util = Vf;
  17068. var Gf = Object.freeze({
  17069. gpgpu_util: wi,
  17070. webgl_util: Pe,
  17071. forceHalfFloat: function () {
  17072. a().set("WEBGL_FORCE_F16_TEXTURES", !0);
  17073. },
  17074. MathBackendWebGL: Wu,
  17075. setWebGLContext: Wt,
  17076. GPGPUContext: Ci
  17077. }),
  17078. Hf = function (t) {
  17079. function o() {
  17080. return null !== t && t.apply(this, arguments) || this;
  17081. }
  17082. return e(o, t), o.prototype.minimize = function (t, e, n) {
  17083. void 0 === e && (e = !1);
  17084. var r = this.computeGradients(t, n),
  17085. o = r.value,
  17086. a = r.grads;
  17087. if (null != n) {
  17088. var i = n.map(function (t) {
  17089. return {
  17090. name: t.name,
  17091. tensor: a[t.name]
  17092. };
  17093. });
  17094. this.applyGradients(i);
  17095. } else this.applyGradients(a);
  17096. return Xe(a), e ? o : (o.dispose(), null);
  17097. }, Object.defineProperty(o.prototype, "iterations", {
  17098. get: function () {
  17099. return null == this.iterations_ && (this.iterations_ = 0), this.iterations_;
  17100. },
  17101. enumerable: !0,
  17102. configurable: !0
  17103. }), o.prototype.incrementIterations = function () {
  17104. this.iterations_ = this.iterations + 1;
  17105. }, o.prototype.computeGradients = function (t, e) {
  17106. return ro(t, e);
  17107. }, o.prototype.dispose = function () {
  17108. null != this.iterations_ && Xe(this.iterations_);
  17109. }, o.prototype.saveIterations = function () {
  17110. return n(this, void 0, void 0, function () {
  17111. return r(this, function (t) {
  17112. return null == this.iterations_ && (this.iterations_ = 0), [2, {
  17113. name: "iter",
  17114. tensor: An(this.iterations_, "int32")
  17115. }];
  17116. });
  17117. });
  17118. }, o.prototype.getWeights = function () {
  17119. return n(this, void 0, void 0, function () {
  17120. return r(this, function (t) {
  17121. throw new Error("getWeights() is not implemented for this optimizer yet.");
  17122. });
  17123. });
  17124. }, o.prototype.setWeights = function (t) {
  17125. return n(this, void 0, void 0, function () {
  17126. return r(this, function (t) {
  17127. throw new Error("setWeights() is not implemented for this optimizer class " + this.getClassName());
  17128. });
  17129. });
  17130. }, o.prototype.extractIterations = function (t) {
  17131. return n(this, void 0, void 0, function () {
  17132. var e;
  17133. return r(this, function (n) {
  17134. switch (n.label) {
  17135. case 0:
  17136. return e = this, [4, t[0].tensor.data()];
  17137. case 1:
  17138. return e.iterations_ = n.sent()[0], [2, t.slice(1)];
  17139. }
  17140. });
  17141. });
  17142. }, o;
  17143. }(Ff);
  17144. exports.Optimizer = Hf;
  17145. exports.webgl = Gf;
  17146. Object.defineProperty(Hf, Symbol.hasInstance, {
  17147. value: function (t) {
  17148. return null != t.minimize && null != t.computeGradients && null != t.applyGradients;
  17149. }
  17150. });
  17151. var qf = function (t) {
  17152. function o(e, n, r) {
  17153. void 0 === r && (r = null);
  17154. var o = t.call(this) || this;
  17155. return o.learningRate = e, o.rho = n, o.epsilon = r, o.accumulatedGrads = [], o.accumulatedUpdates = [], null == r && (o.epsilon = Nt.backend.epsilon()), o;
  17156. }
  17157. return e(o, t), o.prototype.applyGradients = function (t) {
  17158. var e = this;
  17159. (Array.isArray(t) ? t.map(function (t) {
  17160. return t.name;
  17161. }) : Object.keys(t)).forEach(function (n, r) {
  17162. var o = Nt.registeredVariables[n];
  17163. null == e.accumulatedGrads[r] && (e.accumulatedGrads[r] = {
  17164. originalName: n + "/accum_grad",
  17165. variable: je(function () {
  17166. return zn(o).variable(!1);
  17167. })
  17168. }), null == e.accumulatedUpdates[r] && (e.accumulatedUpdates[r] = {
  17169. originalName: n + "/accum_var",
  17170. variable: je(function () {
  17171. return zn(o).variable(!1);
  17172. })
  17173. });
  17174. var a = Array.isArray(t) ? t[r].tensor : t[n];
  17175. if (null != a) {
  17176. var i = e.accumulatedGrads[r].variable,
  17177. u = e.accumulatedUpdates[r].variable;
  17178. je(function () {
  17179. var t = i.mul(e.rho).add(a.square().mul(1 - e.rho)),
  17180. n = u.add(e.epsilon).sqrt().div(i.add(e.epsilon).sqrt()).mul(a),
  17181. r = u.mul(e.rho).add(n.square().mul(1 - e.rho));
  17182. i.assign(t), u.assign(r);
  17183. var s = n.mul(-e.learningRate).add(o);
  17184. o.assign(s);
  17185. });
  17186. }
  17187. }), this.incrementIterations();
  17188. }, o.prototype.dispose = function () {
  17189. null != this.accumulatedUpdates && (Xe(this.accumulatedGrads.map(function (t) {
  17190. return t.variable;
  17191. })), Xe(this.accumulatedUpdates.map(function (t) {
  17192. return t.variable;
  17193. })));
  17194. }, o.prototype.getWeights = function () {
  17195. return n(this, void 0, void 0, function () {
  17196. var t;
  17197. return r(this, function (e) {
  17198. switch (e.label) {
  17199. case 0:
  17200. return t = this.accumulatedGrads.concat(this.accumulatedUpdates), [4, this.saveIterations()];
  17201. case 1:
  17202. return [2, [e.sent()].concat(t.map(function (t) {
  17203. return {
  17204. name: t.originalName,
  17205. tensor: t.variable
  17206. };
  17207. }))];
  17208. }
  17209. });
  17210. });
  17211. }, o.prototype.setWeights = function (t) {
  17212. return n(this, void 0, void 0, function () {
  17213. var e;
  17214. return r(this, function (n) {
  17215. switch (n.label) {
  17216. case 0:
  17217. return [4, this.extractIterations(t)];
  17218. case 1:
  17219. return t = n.sent(), e = t.length / 2, !1, this.accumulatedGrads = t.slice(0, e).map(function (t) {
  17220. return {
  17221. originalName: t.name,
  17222. variable: t.tensor.variable(!1)
  17223. };
  17224. }), this.accumulatedUpdates = t.slice(e, 2 * e).map(function (t) {
  17225. return {
  17226. originalName: t.name,
  17227. variable: t.tensor.variable(!1)
  17228. };
  17229. }), [2];
  17230. }
  17231. });
  17232. });
  17233. }, o.prototype.getConfig = function () {
  17234. return {
  17235. learningRate: this.learningRate,
  17236. rho: this.rho,
  17237. epsilon: this.epsilon
  17238. };
  17239. }, o.fromConfig = function (t, e) {
  17240. return new t(e.learningRate, e.rho, e.epsilon);
  17241. }, o.className = "Adadelta", o;
  17242. }(Hf);
  17243. exports.AdadeltaOptimizer = qf;
  17244. _f(qf);
  17245. var Kf = function (t) {
  17246. function o(e, n) {
  17247. void 0 === n && (n = .1);
  17248. var r = t.call(this) || this;
  17249. return r.learningRate = e, r.initialAccumulatorValue = n, r.accumulatedGrads = [], r;
  17250. }
  17251. return e(o, t), o.prototype.applyGradients = function (t) {
  17252. var e = this;
  17253. (Array.isArray(t) ? t.map(function (t) {
  17254. return t.name;
  17255. }) : Object.keys(t)).forEach(function (n, r) {
  17256. var o = Nt.registeredVariables[n];
  17257. if (null == e.accumulatedGrads[r]) {
  17258. e.accumulatedGrads[r] = {
  17259. originalName: n + "/accumulator",
  17260. variable: je(function () {
  17261. return Ln(o.shape, e.initialAccumulatorValue).variable(!1);
  17262. })
  17263. };
  17264. }
  17265. var a = Array.isArray(t) ? t[r].tensor : t[n];
  17266. if (null != a) {
  17267. var i = e.accumulatedGrads[r].variable;
  17268. je(function () {
  17269. var t = i.add(a.square());
  17270. i.assign(t);
  17271. var n = a.div(t.add(Nt.backend.epsilon()).sqrt()).mul(-e.learningRate).add(o);
  17272. o.assign(n);
  17273. });
  17274. }
  17275. }), this.incrementIterations();
  17276. }, o.prototype.dispose = function () {
  17277. null != this.accumulatedGrads && Xe(this.accumulatedGrads.map(function (t) {
  17278. return t.variable;
  17279. }));
  17280. }, o.prototype.getWeights = function () {
  17281. return n(this, void 0, void 0, function () {
  17282. return r(this, function (t) {
  17283. switch (t.label) {
  17284. case 0:
  17285. return [4, this.saveIterations()];
  17286. case 1:
  17287. return [2, [t.sent()].concat(this.accumulatedGrads.map(function (t) {
  17288. return {
  17289. name: t.originalName,
  17290. tensor: t.variable
  17291. };
  17292. }))];
  17293. }
  17294. });
  17295. });
  17296. }, o.prototype.setWeights = function (t) {
  17297. return n(this, void 0, void 0, function () {
  17298. return r(this, function (e) {
  17299. switch (e.label) {
  17300. case 0:
  17301. return [4, this.extractIterations(t)];
  17302. case 1:
  17303. return t = e.sent(), !1, this.accumulatedGrads = t.map(function (t) {
  17304. return {
  17305. originalName: t.name,
  17306. variable: t.tensor.variable(!1)
  17307. };
  17308. }), [2];
  17309. }
  17310. });
  17311. });
  17312. }, o.prototype.getConfig = function () {
  17313. return {
  17314. learningRate: this.learningRate,
  17315. initialAccumulatorValue: this.initialAccumulatorValue
  17316. };
  17317. }, o.fromConfig = function (t, e) {
  17318. return new t(e.learningRate, e.initialAccumulatorValue);
  17319. }, o.className = "Adagrad", o;
  17320. }(Hf);
  17321. exports.AdagradOptimizer = Kf;
  17322. _f(Kf);
  17323. var jf = function (t) {
  17324. function o(e, n, r, o) {
  17325. void 0 === o && (o = null);
  17326. var a = t.call(this) || this;
  17327. return a.learningRate = e, a.beta1 = n, a.beta2 = r, a.epsilon = o, a.accumulatedFirstMoment = [], a.accumulatedSecondMoment = [], je(function () {
  17328. a.accBeta1 = An(n).variable(), a.accBeta2 = An(r).variable();
  17329. }), null == o && (a.epsilon = Nt.backend.epsilon()), a;
  17330. }
  17331. return e(o, t), o.prototype.applyGradients = function (t) {
  17332. var e = this,
  17333. n = Array.isArray(t) ? t.map(function (t) {
  17334. return t.name;
  17335. }) : Object.keys(t);
  17336. je(function () {
  17337. var r = ic(1, e.accBeta1),
  17338. o = ic(1, e.accBeta2);
  17339. n.forEach(function (n, a) {
  17340. var i = Nt.registeredVariables[n];
  17341. null == e.accumulatedFirstMoment[a] && (e.accumulatedFirstMoment[a] = {
  17342. originalName: n + "/m",
  17343. variable: je(function () {
  17344. return zn(i).variable(!1);
  17345. })
  17346. }), null == e.accumulatedSecondMoment[a] && (e.accumulatedSecondMoment[a] = {
  17347. originalName: n + "/v",
  17348. variable: je(function () {
  17349. return zn(i).variable(!1);
  17350. })
  17351. });
  17352. var u = Array.isArray(t) ? t[a].tensor : t[n];
  17353. if (null != u) {
  17354. var s = e.accumulatedFirstMoment[a].variable,
  17355. c = e.accumulatedSecondMoment[a].variable,
  17356. l = s.mul(e.beta1).add(u.mul(1 - e.beta1)),
  17357. h = c.mul(e.beta2).add(u.square().mul(1 - e.beta2)),
  17358. f = l.div(r),
  17359. p = h.div(o);
  17360. s.assign(l), c.assign(h);
  17361. var d = f.div(p.sqrt().add(e.epsilon)).mul(-e.learningRate).add(i);
  17362. i.assign(d);
  17363. }
  17364. }), e.accBeta1.assign(e.accBeta1.mul(e.beta1)), e.accBeta2.assign(e.accBeta2.mul(e.beta2));
  17365. }), this.incrementIterations();
  17366. }, o.prototype.dispose = function () {
  17367. this.accBeta1.dispose(), this.accBeta2.dispose(), null != this.accumulatedFirstMoment && Xe(this.accumulatedFirstMoment.map(function (t) {
  17368. return t.variable;
  17369. })), null != this.accumulatedSecondMoment && Xe(this.accumulatedSecondMoment.map(function (t) {
  17370. return t.variable;
  17371. }));
  17372. }, o.prototype.getWeights = function () {
  17373. return n(this, void 0, void 0, function () {
  17374. var t;
  17375. return r(this, function (e) {
  17376. switch (e.label) {
  17377. case 0:
  17378. return t = this.accumulatedFirstMoment.concat(this.accumulatedSecondMoment), [4, this.saveIterations()];
  17379. case 1:
  17380. return [2, [e.sent()].concat(t.map(function (t) {
  17381. return {
  17382. name: t.originalName,
  17383. tensor: t.variable
  17384. };
  17385. }))];
  17386. }
  17387. });
  17388. });
  17389. }, o.prototype.setWeights = function (t) {
  17390. return n(this, void 0, void 0, function () {
  17391. var e,
  17392. n = this;
  17393. return r(this, function (r) {
  17394. switch (r.label) {
  17395. case 0:
  17396. return [4, this.extractIterations(t)];
  17397. case 1:
  17398. return t = r.sent(), je(function () {
  17399. n.accBeta1.assign(nc(n.beta1, n.iterations_ + 1)), n.accBeta2.assign(nc(n.beta2, n.iterations_ + 1));
  17400. }), e = t.length / 2, !1, this.accumulatedFirstMoment = t.slice(0, e).map(function (t) {
  17401. return {
  17402. originalName: t.name,
  17403. variable: t.tensor.variable(!1)
  17404. };
  17405. }), this.accumulatedSecondMoment = t.slice(e, 2 * e).map(function (t) {
  17406. return {
  17407. originalName: t.name,
  17408. variable: t.tensor.variable(!1)
  17409. };
  17410. }), [2];
  17411. }
  17412. });
  17413. });
  17414. }, o.prototype.getConfig = function () {
  17415. return {
  17416. learningRate: this.learningRate,
  17417. beta1: this.beta1,
  17418. beta2: this.beta2,
  17419. epsilon: this.epsilon
  17420. };
  17421. }, o.fromConfig = function (t, e) {
  17422. return new t(e.learningRate, e.beta1, e.beta2, e.epsilon);
  17423. }, o.className = "Adam", o;
  17424. }(Hf);
  17425. exports.AdamOptimizer = jf;
  17426. _f(jf);
  17427. var Xf = function (t) {
  17428. function o(e, n, r, o, a) {
  17429. void 0 === o && (o = null), void 0 === a && (a = 0);
  17430. var i = t.call(this) || this;
  17431. return i.learningRate = e, i.beta1 = n, i.beta2 = r, i.epsilon = o, i.decay = a, i.accumulatedFirstMoment = [], i.accumulatedWeightedInfNorm = [], je(function () {
  17432. i.iteration = An(0).variable(), i.accBeta1 = An(n).variable();
  17433. }), null == o && (i.epsilon = Nt.backend.epsilon()), i;
  17434. }
  17435. return e(o, t), o.prototype.applyGradients = function (t) {
  17436. var e = this,
  17437. n = Array.isArray(t) ? t.map(function (t) {
  17438. return t.name;
  17439. }) : Object.keys(t);
  17440. je(function () {
  17441. var r = ic(1, e.accBeta1),
  17442. o = qs(-e.learningRate, e.iteration.mul(e.decay).add(1));
  17443. n.forEach(function (n, a) {
  17444. var i = Nt.registeredVariables[n];
  17445. null == e.accumulatedFirstMoment[a] && (e.accumulatedFirstMoment[a] = {
  17446. originalName: n + "/m",
  17447. variable: zn(i).variable(!1)
  17448. }), null == e.accumulatedWeightedInfNorm[a] && (e.accumulatedWeightedInfNorm[a] = {
  17449. originalName: n + "/v",
  17450. variable: zn(i).variable(!1)
  17451. });
  17452. var u = Array.isArray(t) ? t[a].tensor : t[n];
  17453. if (null != u) {
  17454. var s = e.accumulatedFirstMoment[a].variable,
  17455. c = e.accumulatedWeightedInfNorm[a].variable,
  17456. l = s.mul(e.beta1).add(u.mul(1 - e.beta1)),
  17457. h = c.mul(e.beta2),
  17458. f = u.abs(),
  17459. p = h.maximum(f);
  17460. s.assign(l), c.assign(p);
  17461. var d = o.div(r).mul(l.div(p.add(e.epsilon))).add(i);
  17462. i.assign(d);
  17463. }
  17464. }), e.iteration.assign(e.iteration.add(1)), e.accBeta1.assign(e.accBeta1.mul(e.beta1));
  17465. }), this.incrementIterations();
  17466. }, o.prototype.dispose = function () {
  17467. this.accBeta1.dispose(), this.iteration.dispose(), null != this.accumulatedFirstMoment && Xe(this.accumulatedFirstMoment.map(function (t) {
  17468. return t.variable;
  17469. })), null != this.accumulatedWeightedInfNorm && Xe(this.accumulatedWeightedInfNorm.map(function (t) {
  17470. return t.variable;
  17471. }));
  17472. }, o.prototype.getWeights = function () {
  17473. return n(this, void 0, void 0, function () {
  17474. return r(this, function (t) {
  17475. throw new Error("getWeights() is not implemented for Adamax yet.");
  17476. });
  17477. });
  17478. }, o.prototype.setWeights = function (t) {
  17479. return n(this, void 0, void 0, function () {
  17480. return r(this, function (t) {
  17481. throw new Error("setWeights() is not implemented for Adamax yet.");
  17482. });
  17483. });
  17484. }, o.prototype.getConfig = function () {
  17485. return {
  17486. learningRate: this.learningRate,
  17487. beta1: this.beta1,
  17488. beta2: this.beta2,
  17489. epsilon: this.epsilon,
  17490. decay: this.decay
  17491. };
  17492. }, o.fromConfig = function (t, e) {
  17493. return new t(e.learningRate, e.beta1, e.beta2, e.epsilon, e.decay);
  17494. }, o.className = "Adamax", o;
  17495. }(Hf);
  17496. exports.AdamaxOptimizer = Xf;
  17497. _f(Xf);
  17498. var $f = function (t) {
  17499. function o(e) {
  17500. var n = t.call(this) || this;
  17501. return n.learningRate = e, n.setLearningRate(e), n;
  17502. }
  17503. return e(o, t), o.prototype.applyGradients = function (t) {
  17504. var e = this;
  17505. (Array.isArray(t) ? t.map(function (t) {
  17506. return t.name;
  17507. }) : Object.keys(t)).forEach(function (n, r) {
  17508. var o = Array.isArray(t) ? t[r].tensor : t[n];
  17509. if (null != o) {
  17510. var a = Nt.registeredVariables[n];
  17511. je(function () {
  17512. var t = e.c.mul(o).add(a);
  17513. a.assign(t);
  17514. });
  17515. }
  17516. }), this.incrementIterations();
  17517. }, o.prototype.setLearningRate = function (t) {
  17518. this.learningRate = t, null != this.c && this.c.dispose(), this.c = $e(An(-t));
  17519. }, o.prototype.dispose = function () {
  17520. this.c.dispose();
  17521. }, o.prototype.getWeights = function () {
  17522. return n(this, void 0, void 0, function () {
  17523. return r(this, function (t) {
  17524. switch (t.label) {
  17525. case 0:
  17526. return [4, this.saveIterations()];
  17527. case 1:
  17528. return [2, [t.sent()]];
  17529. }
  17530. });
  17531. });
  17532. }, o.prototype.setWeights = function (t) {
  17533. return n(this, void 0, void 0, function () {
  17534. return r(this, function (e) {
  17535. switch (e.label) {
  17536. case 0:
  17537. return [4, this.extractIterations(t)];
  17538. case 1:
  17539. if (0 !== (t = e.sent()).length) throw new Error("SGD optimizer does not have settable weights.");
  17540. return [2];
  17541. }
  17542. });
  17543. });
  17544. }, o.prototype.getConfig = function () {
  17545. return {
  17546. learningRate: this.learningRate
  17547. };
  17548. }, o.fromConfig = function (t, e) {
  17549. return new t(e.learningRate);
  17550. }, o.className = "SGD", o;
  17551. }(Hf);
  17552. exports.SGDOptimizer = $f;
  17553. _f($f);
  17554. var Yf = function (t) {
  17555. function o(e, n, r) {
  17556. void 0 === r && (r = !1);
  17557. var o = t.call(this, e) || this;
  17558. return o.learningRate = e, o.momentum = n, o.useNesterov = r, o.accumulations = [], o.m = An(o.momentum), o;
  17559. }
  17560. return e(o, t), o.prototype.applyGradients = function (t) {
  17561. var e = this;
  17562. (Array.isArray(t) ? t.map(function (t) {
  17563. return t.name;
  17564. }) : Object.keys(t)).forEach(function (n, r) {
  17565. var o = Nt.registeredVariables[n];
  17566. if (null == e.accumulations[r]) {
  17567. e.accumulations[r] = {
  17568. originalName: n + "/momentum",
  17569. variable: je(function () {
  17570. return zn(o).variable(!1);
  17571. })
  17572. };
  17573. }
  17574. var a = e.accumulations[r].variable,
  17575. i = Array.isArray(t) ? t[r].tensor : t[n];
  17576. null != i && je(function () {
  17577. var t,
  17578. n = e.m.mul(a).add(i);
  17579. t = e.useNesterov ? e.c.mul(i.add(n.mul(e.m))).add(o) : e.c.mul(n).add(o), a.assign(n), o.assign(t);
  17580. });
  17581. }), this.incrementIterations();
  17582. }, o.prototype.dispose = function () {
  17583. this.m.dispose(), null != this.accumulations && Xe(this.accumulations.map(function (t) {
  17584. return t.variable;
  17585. }));
  17586. }, o.prototype.setMomentum = function (t) {
  17587. this.momentum = t;
  17588. }, o.prototype.getWeights = function () {
  17589. return n(this, void 0, void 0, function () {
  17590. return r(this, function (t) {
  17591. switch (t.label) {
  17592. case 0:
  17593. return [4, this.saveIterations()];
  17594. case 1:
  17595. return [2, [t.sent()].concat(this.accumulations.map(function (t) {
  17596. return {
  17597. name: t.originalName,
  17598. tensor: t.variable
  17599. };
  17600. }))];
  17601. }
  17602. });
  17603. });
  17604. }, o.prototype.setWeights = function (t) {
  17605. return n(this, void 0, void 0, function () {
  17606. return r(this, function (e) {
  17607. switch (e.label) {
  17608. case 0:
  17609. return [4, this.extractIterations(t)];
  17610. case 1:
  17611. return t = e.sent(), !1, this.accumulations = t.map(function (t) {
  17612. return {
  17613. originalName: t.name,
  17614. variable: t.tensor.variable(!1)
  17615. };
  17616. }), [2];
  17617. }
  17618. });
  17619. });
  17620. }, o.prototype.getConfig = function () {
  17621. return {
  17622. learningRate: this.learningRate,
  17623. momentum: this.momentum,
  17624. useNesterov: this.useNesterov
  17625. };
  17626. }, o.fromConfig = function (t, e) {
  17627. return new t(e.learningRate, e.momentum, e.useNesterov);
  17628. }, o.className = "Momentum", o;
  17629. }($f);
  17630. exports.MomentumOptimizer = Yf;
  17631. _f(Yf);
  17632. var Qf = function (t) {
  17633. function o(e, n, r, o, a) {
  17634. void 0 === n && (n = .9), void 0 === r && (r = 0), void 0 === o && (o = null), void 0 === a && (a = !1);
  17635. var i = t.call(this) || this;
  17636. return i.learningRate = e, i.decay = n, i.momentum = r, i.epsilon = o, i.accumulatedMeanSquares = [], i.accumulatedMoments = [], i.accumulatedMeanGrads = [], i.centered = a, null == o && (i.epsilon = Nt.backend.epsilon()), i;
  17637. }
  17638. return e(o, t), o.prototype.applyGradients = function (t) {
  17639. var e = this;
  17640. (Array.isArray(t) ? t.map(function (t) {
  17641. return t.name;
  17642. }) : Object.keys(t)).forEach(function (n, r) {
  17643. var o = Nt.registeredVariables[n];
  17644. null == e.accumulatedMeanSquares[r] && (e.accumulatedMeanSquares[r] = {
  17645. originalName: n + "/rms",
  17646. variable: je(function () {
  17647. return zn(o).variable(!1);
  17648. })
  17649. }), null == e.accumulatedMoments[r] && (e.accumulatedMoments[r] = {
  17650. originalName: n + "/momentum",
  17651. variable: je(function () {
  17652. return zn(o).variable(!1);
  17653. })
  17654. }), null == e.accumulatedMeanGrads[r] && e.centered && (e.accumulatedMeanGrads[r] = {
  17655. originalName: n + "/mg",
  17656. variable: je(function () {
  17657. return zn(o).variable(!1);
  17658. })
  17659. });
  17660. var a = Array.isArray(t) ? t[r].tensor : t[n];
  17661. if (null != a) {
  17662. var i = e.accumulatedMeanSquares[r].variable,
  17663. u = e.accumulatedMoments[r].variable;
  17664. je(function () {
  17665. var t = i.mul(e.decay).add(a.square().mul(1 - e.decay));
  17666. if (e.centered) {
  17667. var n = e.accumulatedMeanGrads[r].variable,
  17668. s = n.mul(e.decay).add(a.mul(1 - e.decay)),
  17669. c = u.mul(e.momentum).add(a.mul(e.learningRate).div(t.sub(s.square().add(e.epsilon)).sqrt()));
  17670. i.assign(t), n.assign(s), u.assign(c);
  17671. var l = o.sub(c);
  17672. o.assign(l);
  17673. } else {
  17674. var h = i.mul(e.decay).add(a.square().mul(1 - e.decay));
  17675. c = u.mul(e.momentum).add(a.mul(e.learningRate).div(h.add(e.epsilon).sqrt()));
  17676. i.assign(h), u.assign(c);
  17677. l = o.sub(c);
  17678. o.assign(l);
  17679. }
  17680. });
  17681. }
  17682. }), this.incrementIterations();
  17683. }, o.prototype.dispose = function () {
  17684. null != this.accumulatedMeanSquares && Xe(this.accumulatedMeanSquares.map(function (t) {
  17685. return t.variable;
  17686. })), null != this.accumulatedMeanGrads && this.centered && Xe(this.accumulatedMeanGrads.map(function (t) {
  17687. return t.variable;
  17688. })), null != this.accumulatedMoments && Xe(this.accumulatedMoments.map(function (t) {
  17689. return t.variable;
  17690. }));
  17691. }, o.prototype.getWeights = function () {
  17692. return n(this, void 0, void 0, function () {
  17693. var t;
  17694. return r(this, function (e) {
  17695. switch (e.label) {
  17696. case 0:
  17697. return t = this.accumulatedMeanSquares.concat(this.accumulatedMoments), this.centered && t.push.apply(t, this.accumulatedMeanGrads), [4, this.saveIterations()];
  17698. case 1:
  17699. return [2, [e.sent()].concat(t.map(function (t) {
  17700. return {
  17701. name: t.originalName,
  17702. tensor: t.variable
  17703. };
  17704. }))];
  17705. }
  17706. });
  17707. });
  17708. }, o.prototype.setWeights = function (t) {
  17709. return n(this, void 0, void 0, function () {
  17710. var e;
  17711. return r(this, function (n) {
  17712. switch (n.label) {
  17713. case 0:
  17714. return [4, this.extractIterations(t)];
  17715. case 1:
  17716. return t = n.sent(), e = this.centered ? t.length / 3 : t.length / 2, !1, this.accumulatedMeanSquares = t.slice(0, e).map(function (t) {
  17717. return {
  17718. originalName: t.name,
  17719. variable: t.tensor.variable(!1)
  17720. };
  17721. }), this.accumulatedMoments = t.slice(e, 2 * e).map(function (t) {
  17722. return {
  17723. originalName: t.name,
  17724. variable: t.tensor.variable(!1)
  17725. };
  17726. }), this.centered && (this.accumulatedMeanGrads = t.slice(2 * e, 3 * e).map(function (t) {
  17727. return {
  17728. originalName: t.name,
  17729. variable: t.tensor.variable(!1)
  17730. };
  17731. })), [2];
  17732. }
  17733. });
  17734. });
  17735. }, o.prototype.getConfig = function () {
  17736. return {
  17737. learningRate: this.learningRate,
  17738. decay: this.decay,
  17739. momentum: this.momentum,
  17740. epsilon: this.epsilon,
  17741. centered: this.centered
  17742. };
  17743. }, o.fromConfig = function (t, e) {
  17744. return new t(e.learningRate, e.decay, e.momentum, e.epsilon, e.centered);
  17745. }, o.className = "RMSProp", o;
  17746. }(Hf);
  17747. exports.RMSPropOptimizer = Qf;
  17748. _f(Qf);
  17749. var Jf = function () {
  17750. function t() { }
  17751. return t.sgd = function (t) {
  17752. return new $f(t);
  17753. }, t.momentum = function (t, e, n) {
  17754. return void 0 === n && (n = !1), new Yf(t, e, n);
  17755. }, t.rmsprop = function (t, e, n, r, o) {
  17756. return void 0 === e && (e = .9), void 0 === n && (n = 0), void 0 === r && (r = null), void 0 === o && (o = !1), new Qf(t, e, n, r, o);
  17757. }, t.adam = function (t, e, n, r) {
  17758. return void 0 === t && (t = .001), void 0 === e && (e = .9), void 0 === n && (n = .999), void 0 === r && (r = null), new jf(t, e, n, r);
  17759. }, t.adadelta = function (t, e, n) {
  17760. return void 0 === t && (t = .001), void 0 === e && (e = .95), void 0 === n && (n = null), new qf(t, e, n);
  17761. }, t.adamax = function (t, e, n, r, o) {
  17762. return void 0 === t && (t = .002), void 0 === e && (e = .9), void 0 === n && (n = .999), void 0 === r && (r = null), void 0 === o && (o = 0), new Xf(t, e, n, r, o);
  17763. }, t.adagrad = function (t, e) {
  17764. return void 0 === e && (e = .1), new Kf(t, e);
  17765. }, t;
  17766. }(),
  17767. Zf = {
  17768. sgd: Jf.sgd,
  17769. momentum: Jf.momentum,
  17770. adadelta: Jf.adadelta,
  17771. adagrad: Jf.adagrad,
  17772. rmsprop: Jf.rmsprop,
  17773. adamax: Jf.adamax,
  17774. adam: Jf.adam
  17775. },
  17776. tp = "undefined" != typeof requestAnimationFrame ? requestAnimationFrame : "undefined" != typeof setImmediate ? setImmediate : function (t) {
  17777. return t();
  17778. };
  17779. exports.train = Zf;
  17780. function ep() {
  17781. return new Promise(function (t) {
  17782. return tp(function () {
  17783. return t();
  17784. });
  17785. });
  17786. }
  17787. ft = Rh;
  17788. }, { "crypto": "node_modules/parcel-bundler/src/builtins/_empty.js", "node-fetch": "node_modules/parcel-bundler/src/builtins/_empty.js", "util": "node_modules/parcel-bundler/src/builtins/_empty.js", "process": "node_modules/process/browser.js", "buffer": "node_modules/buffer/index.js" }], "node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js": [function (require, module, exports) {
  17789. var Buffer = require("buffer").Buffer;
  17790. "use strict";
  17791. Object.defineProperty(exports, "__esModule", {
  17792. value: true
  17793. });
  17794. exports.loadGraphModel = loadGraphModel;
  17795. exports.deregisterOp = deregisterOp;
  17796. exports.registerOp = registerOp;
  17797. exports.version_converter = exports.GraphModel = void 0;
  17798. var _tfjsCore = require("@tensorflow/tfjs-core");
  17799. /**
  17800. * @license
  17801. * Copyright 2019 Google LLC. All Rights Reserved.
  17802. * Licensed under the Apache License, Version 2.0 (the "License");
  17803. * you may not use this file except in compliance with the License.
  17804. * You may obtain a copy of the License at
  17805. *
  17806. * http://www.apache.org/licenses/LICENSE-2.0
  17807. *
  17808. * Unless required by applicable law or agreed to in writing, software
  17809. * distributed under the License is distributed on an "AS IS" BASIS,
  17810. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17811. * See the License for the specific language governing permissions and
  17812. * limitations under the License.
  17813. * =============================================================================
  17814. */
  17815. var DataType,
  17816. SaverDef,
  17817. __assign = function () {
  17818. return (__assign = Object.assign || function (e) {
  17819. for (var t, a = 1, r = arguments.length; a < r; a++) for (var n in t = arguments[a]) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
  17820. return e;
  17821. }).apply(this, arguments);
  17822. };
  17823. function __awaiter(e, t, a, r) {
  17824. return new (a || (a = Promise))(function (n, s) {
  17825. function o(e) {
  17826. try {
  17827. u(r.next(e));
  17828. } catch (e) {
  17829. s(e);
  17830. }
  17831. }
  17832. function p(e) {
  17833. try {
  17834. u(r.throw(e));
  17835. } catch (e) {
  17836. s(e);
  17837. }
  17838. }
  17839. function u(e) {
  17840. e.done ? n(e.value) : new a(function (t) {
  17841. t(e.value);
  17842. }).then(o, p);
  17843. }
  17844. u((r = r.apply(e, t || [])).next());
  17845. });
  17846. }
  17847. function __generator(e, t) {
  17848. var a,
  17849. r,
  17850. n,
  17851. s,
  17852. o = {
  17853. label: 0,
  17854. sent: function () {
  17855. if (1 & n[0]) throw n[1];
  17856. return n[1];
  17857. },
  17858. trys: [],
  17859. ops: []
  17860. };
  17861. return s = {
  17862. next: p(0),
  17863. throw: p(1),
  17864. return: p(2)
  17865. }, "function" == typeof Symbol && (s[Symbol.iterator] = function () {
  17866. return this;
  17867. }), s;
  17868. function p(s) {
  17869. return function (p) {
  17870. return function (s) {
  17871. if (a) throw new TypeError("Generator is already executing.");
  17872. for (; o;) try {
  17873. if (a = 1, r && (n = 2 & s[0] ? r.return : s[0] ? r.throw || ((n = r.return) && n.call(r), 0) : r.next) && !(n = n.call(r, s[1])).done) return n;
  17874. switch (r = 0, n && (s = [2 & s[0], n.value]), s[0]) {
  17875. case 0:
  17876. case 1:
  17877. n = s;
  17878. break;
  17879. case 4:
  17880. return o.label++, {
  17881. value: s[1],
  17882. done: !1
  17883. };
  17884. case 5:
  17885. o.label++, r = s[1], s = [0];
  17886. continue;
  17887. case 7:
  17888. s = o.ops.pop(), o.trys.pop();
  17889. continue;
  17890. default:
  17891. if (!(n = (n = o.trys).length > 0 && n[n.length - 1]) && (6 === s[0] || 2 === s[0])) {
  17892. o = 0;
  17893. continue;
  17894. }
  17895. if (3 === s[0] && (!n || s[1] > n[0] && s[1] < n[3])) {
  17896. o.label = s[1];
  17897. break;
  17898. }
  17899. if (6 === s[0] && o.label < n[1]) {
  17900. o.label = n[1], n = s;
  17901. break;
  17902. }
  17903. if (n && o.label < n[2]) {
  17904. o.label = n[2], o.ops.push(s);
  17905. break;
  17906. }
  17907. n[2] && o.ops.pop(), o.trys.pop();
  17908. continue;
  17909. }
  17910. s = t.call(e, o);
  17911. } catch (e) {
  17912. s = [6, e], r = 0;
  17913. } finally {
  17914. a = n = 0;
  17915. }
  17916. if (5 & s[0]) throw s[1];
  17917. return {
  17918. value: s[0] ? s[1] : void 0,
  17919. done: !0
  17920. };
  17921. }([s, p]);
  17922. };
  17923. }
  17924. }
  17925. !function (e) {
  17926. e[e.DT_INVALID = 0] = "DT_INVALID", e[e.DT_FLOAT = 1] = "DT_FLOAT", e[e.DT_DOUBLE = 2] = "DT_DOUBLE", e[e.DT_INT32 = 3] = "DT_INT32", e[e.DT_UINT8 = 4] = "DT_UINT8", e[e.DT_INT16 = 5] = "DT_INT16", e[e.DT_INT8 = 6] = "DT_INT8", e[e.DT_STRING = 7] = "DT_STRING", e[e.DT_COMPLEX64 = 8] = "DT_COMPLEX64", e[e.DT_INT64 = 9] = "DT_INT64", e[e.DT_BOOL = 10] = "DT_BOOL", e[e.DT_QINT8 = 11] = "DT_QINT8", e[e.DT_QUINT8 = 12] = "DT_QUINT8", e[e.DT_QINT32 = 13] = "DT_QINT32", e[e.DT_BFLOAT16 = 14] = "DT_BFLOAT16", e[e.DT_FLOAT_REF = 101] = "DT_FLOAT_REF", e[e.DT_DOUBLE_REF = 102] = "DT_DOUBLE_REF", e[e.DT_INT32_REF = 103] = "DT_INT32_REF", e[e.DT_UINT8_REF = 104] = "DT_UINT8_REF", e[e.DT_INT16_REF = 105] = "DT_INT16_REF", e[e.DT_INT8_REF = 106] = "DT_INT8_REF", e[e.DT_STRING_REF = 107] = "DT_STRING_REF", e[e.DT_COMPLEX64_REF = 108] = "DT_COMPLEX64_REF", e[e.DT_INT64_REF = 109] = "DT_INT64_REF", e[e.DT_BOOL_REF = 110] = "DT_BOOL_REF", e[e.DT_QINT8_REF = 111] = "DT_QINT8_REF", e[e.DT_QUINT8_REF = 112] = "DT_QUINT8_REF", e[e.DT_QINT32_REF = 113] = "DT_QINT32_REF", e[e.DT_BFLOAT16_REF = 114] = "DT_BFLOAT16_REF";
  17927. }(DataType || (DataType = {})), function (e) {
  17928. !function (e) {
  17929. e[e.LEGACY = 0] = "LEGACY", e[e.V1 = 1] = "V1", e[e.V2 = 2] = "V2";
  17930. }(e.CheckpointFormatVersion || (e.CheckpointFormatVersion = {}));
  17931. }(SaverDef || (SaverDef = {}));
  17932. var CUSTOM_OPS = {};
  17933. function registerOp(e, t) {
  17934. var a = {
  17935. tfOpName: e,
  17936. category: "custom",
  17937. inputs: [],
  17938. attrs: [],
  17939. customExecutor: t
  17940. };
  17941. CUSTOM_OPS[e] = a;
  17942. }
  17943. function getRegisteredOp(e) {
  17944. return CUSTOM_OPS[e];
  17945. }
  17946. function deregisterOp(e) {
  17947. delete CUSTOM_OPS[e];
  17948. }
  17949. function getParamValue(e, t, a, r) {
  17950. var n = t.inputParams[e];
  17951. if (n && void 0 !== n.inputIndexStart) {
  17952. var s = n.inputIndexStart,
  17953. o = 0 === n.inputIndexEnd ? void 0 : void 0 === n.inputIndexEnd ? s + 1 : n.inputIndexEnd;
  17954. if ("tensor" === n.type) return getTensor(t.inputNames[n.inputIndexStart], a, r);
  17955. if ("tensors" === n.type) return t.inputNames.slice(s, o).map(function (e) {
  17956. return getTensor(e, a, r);
  17957. });
  17958. var p = Array.prototype.slice.call(getTensor(t.inputNames.slice(s)[0], a, r).dataSync());
  17959. return "number" === n.type ? p[0] : p;
  17960. }
  17961. var u = t.attrParams[e];
  17962. return u && u.value;
  17963. }
  17964. function getTensor(e, t, a) {
  17965. var r = parseNodeName(e),
  17966. n = r[0],
  17967. s = r[1],
  17968. o = a.currentContextIds.find(function (e) {
  17969. return !!t[getNodeNameWithContextId(n, e)];
  17970. });
  17971. return void 0 !== o ? t[getNodeNameWithContextId(n, o)][s] : void 0;
  17972. }
  17973. function getTensorsForCurrentContenxt(e, t, a) {
  17974. return t[getNodeNameWithContextId(e, a.currentContextId)];
  17975. }
  17976. function getNodeNameAndIndex(e, t) {
  17977. var a = parseNodeName(e),
  17978. r = a[0],
  17979. n = a[1];
  17980. return [getNodeNameWithContextId(r, t && t.currentContextId), n];
  17981. }
  17982. function getNodeNameWithContextId(e, t) {
  17983. return t ? e + "-" + t : e;
  17984. }
  17985. function parseNodeName(e) {
  17986. var t = e.lastIndexOf(":");
  17987. return -1 === t ? [e, 0] : [e.substring(0, t), Number(e.substring(t + 1))];
  17988. }
  17989. function split$1(e, t) {
  17990. for (var a = [], r = 0; r < e.length; r += t) a.push(e.slice(r, r + t));
  17991. return a;
  17992. }
  17993. var json = [{
  17994. tfOpName: "Add",
  17995. category: "arithmetic",
  17996. inputs: [{
  17997. start: 0,
  17998. name: "a",
  17999. type: "tensor"
  18000. }, {
  18001. start: 1,
  18002. name: "b",
  18003. type: "tensor"
  18004. }],
  18005. attrs: [{
  18006. tfName: "T",
  18007. name: "dtype",
  18008. type: "dtype",
  18009. notSupported: !0
  18010. }]
  18011. }, {
  18012. tfOpName: "AddV2",
  18013. category: "arithmetic",
  18014. inputs: [{
  18015. start: 0,
  18016. name: "a",
  18017. type: "tensor"
  18018. }, {
  18019. start: 1,
  18020. name: "b",
  18021. type: "tensor"
  18022. }],
  18023. attrs: [{
  18024. tfName: "T",
  18025. name: "dtype",
  18026. type: "dtype",
  18027. notSupported: !0
  18028. }]
  18029. }, {
  18030. tfOpName: "AddN",
  18031. category: "arithmetic",
  18032. inputs: [{
  18033. start: 0,
  18034. end: 0,
  18035. name: "tensors",
  18036. type: "tensors"
  18037. }]
  18038. }, {
  18039. tfOpName: "BiasAdd",
  18040. category: "arithmetic",
  18041. inputs: [{
  18042. start: 0,
  18043. name: "a",
  18044. type: "tensor"
  18045. }, {
  18046. start: 1,
  18047. name: "b",
  18048. type: "tensor"
  18049. }],
  18050. attrs: [{
  18051. tfName: "T",
  18052. name: "dtype",
  18053. type: "dtype",
  18054. notSupported: !0
  18055. }]
  18056. }, {
  18057. tfOpName: "Sub",
  18058. category: "arithmetic",
  18059. inputs: [{
  18060. start: 0,
  18061. name: "a",
  18062. type: "tensor"
  18063. }, {
  18064. start: 1,
  18065. name: "b",
  18066. type: "tensor"
  18067. }],
  18068. attrs: [{
  18069. tfName: "T",
  18070. name: "dtype",
  18071. type: "dtype",
  18072. notSupported: !0
  18073. }]
  18074. }, {
  18075. tfOpName: "RealDiv",
  18076. category: "arithmetic",
  18077. inputs: [{
  18078. start: 0,
  18079. name: "a",
  18080. type: "tensor"
  18081. }, {
  18082. start: 1,
  18083. name: "b",
  18084. type: "tensor"
  18085. }],
  18086. attrs: [{
  18087. tfName: "T",
  18088. name: "dtype",
  18089. type: "dtype",
  18090. notSupported: !0
  18091. }]
  18092. }, {
  18093. tfOpName: "Div",
  18094. category: "arithmetic",
  18095. inputs: [{
  18096. start: 0,
  18097. name: "a",
  18098. type: "tensor"
  18099. }, {
  18100. start: 1,
  18101. name: "b",
  18102. type: "tensor"
  18103. }],
  18104. attrs: [{
  18105. tfName: "T",
  18106. name: "dtype",
  18107. type: "dtype",
  18108. notSupported: !0
  18109. }]
  18110. }, {
  18111. tfOpName: "FloorDiv",
  18112. category: "arithmetic",
  18113. inputs: [{
  18114. start: 0,
  18115. name: "a",
  18116. type: "tensor"
  18117. }, {
  18118. start: 1,
  18119. name: "b",
  18120. type: "tensor"
  18121. }],
  18122. attrs: [{
  18123. tfName: "T",
  18124. name: "dtype",
  18125. type: "dtype",
  18126. notSupported: !0
  18127. }]
  18128. }, {
  18129. tfOpName: "Mul",
  18130. category: "arithmetic",
  18131. inputs: [{
  18132. start: 0,
  18133. name: "a",
  18134. type: "tensor"
  18135. }, {
  18136. start: 1,
  18137. name: "b",
  18138. type: "tensor"
  18139. }],
  18140. attrs: [{
  18141. tfName: "T",
  18142. name: "dtype",
  18143. type: "dtype",
  18144. notSupported: !0
  18145. }]
  18146. }, {
  18147. tfOpName: "Maximum",
  18148. category: "arithmetic",
  18149. inputs: [{
  18150. start: 0,
  18151. name: "a",
  18152. type: "tensor"
  18153. }, {
  18154. start: 1,
  18155. name: "b",
  18156. type: "tensor"
  18157. }]
  18158. }, {
  18159. tfOpName: "Minimum",
  18160. category: "arithmetic",
  18161. inputs: [{
  18162. start: 0,
  18163. name: "a",
  18164. type: "tensor"
  18165. }, {
  18166. start: 1,
  18167. name: "b",
  18168. type: "tensor"
  18169. }]
  18170. }, {
  18171. tfOpName: "Pow",
  18172. category: "arithmetic",
  18173. inputs: [{
  18174. start: 0,
  18175. name: "a",
  18176. type: "tensor"
  18177. }, {
  18178. start: 1,
  18179. name: "b",
  18180. type: "tensor"
  18181. }],
  18182. attrs: [{
  18183. tfName: "T",
  18184. name: "dtype",
  18185. type: "dtype",
  18186. notSupported: !0
  18187. }]
  18188. }, {
  18189. tfOpName: "SquaredDifference",
  18190. category: "arithmetic",
  18191. inputs: [{
  18192. start: 0,
  18193. name: "a",
  18194. type: "tensor"
  18195. }, {
  18196. start: 1,
  18197. name: "b",
  18198. type: "tensor"
  18199. }],
  18200. attrs: [{
  18201. tfName: "T",
  18202. name: "dtype",
  18203. type: "dtype",
  18204. notSupported: !0
  18205. }]
  18206. }, {
  18207. tfOpName: "Mod",
  18208. category: "arithmetic",
  18209. inputs: [{
  18210. start: 0,
  18211. name: "a",
  18212. type: "tensor"
  18213. }, {
  18214. start: 1,
  18215. name: "b",
  18216. type: "tensor"
  18217. }],
  18218. attrs: [{
  18219. tfName: "T",
  18220. name: "dtype",
  18221. type: "dtype",
  18222. notSupported: !0
  18223. }]
  18224. }, {
  18225. tfOpName: "FloorMod",
  18226. category: "arithmetic",
  18227. inputs: [{
  18228. start: 0,
  18229. name: "a",
  18230. type: "tensor"
  18231. }, {
  18232. start: 1,
  18233. name: "b",
  18234. type: "tensor"
  18235. }],
  18236. attrs: [{
  18237. tfName: "T",
  18238. name: "dtype",
  18239. type: "dtype",
  18240. notSupported: !0
  18241. }]
  18242. }],
  18243. arithmetic = Object.freeze({
  18244. json: json
  18245. }),
  18246. json$1 = [{
  18247. tfOpName: "Abs",
  18248. category: "basic_math",
  18249. inputs: [{
  18250. start: 0,
  18251. name: "x",
  18252. type: "tensor"
  18253. }],
  18254. attrs: [{
  18255. tfName: "T",
  18256. name: "dtype",
  18257. type: "dtype",
  18258. notSupported: !0
  18259. }]
  18260. }, {
  18261. tfOpName: "Acos",
  18262. category: "basic_math",
  18263. inputs: [{
  18264. start: 0,
  18265. name: "x",
  18266. type: "tensor"
  18267. }],
  18268. attrs: [{
  18269. tfName: "T",
  18270. name: "dtype",
  18271. type: "dtype",
  18272. notSupported: !0
  18273. }]
  18274. }, {
  18275. tfOpName: "Asin",
  18276. category: "basic_math",
  18277. inputs: [{
  18278. start: 0,
  18279. name: "x",
  18280. type: "tensor"
  18281. }],
  18282. attrs: [{
  18283. tfName: "T",
  18284. name: "dtype",
  18285. type: "dtype",
  18286. notSupported: !0
  18287. }]
  18288. }, {
  18289. tfOpName: "Atan",
  18290. category: "basic_math",
  18291. inputs: [{
  18292. start: 0,
  18293. name: "x",
  18294. type: "tensor"
  18295. }],
  18296. attrs: [{
  18297. tfName: "T",
  18298. name: "dtype",
  18299. type: "dtype",
  18300. notSupported: !0
  18301. }]
  18302. }, {
  18303. tfOpName: "Atan2",
  18304. category: "basic_math",
  18305. inputs: [{
  18306. start: 0,
  18307. name: "x",
  18308. type: "tensor"
  18309. }, {
  18310. start: 1,
  18311. name: "y",
  18312. type: "tensor"
  18313. }],
  18314. attrs: [{
  18315. tfName: "T",
  18316. name: "dtype",
  18317. type: "dtype",
  18318. notSupported: !0
  18319. }]
  18320. }, {
  18321. tfOpName: "Ceil",
  18322. category: "basic_math",
  18323. inputs: [{
  18324. start: 0,
  18325. name: "x",
  18326. type: "tensor"
  18327. }],
  18328. attrs: [{
  18329. tfName: "T",
  18330. name: "dtype",
  18331. type: "dtype",
  18332. notSupported: !0
  18333. }]
  18334. }, {
  18335. tfOpName: "ClipByValue",
  18336. category: "basic_math",
  18337. inputs: [{
  18338. start: 0,
  18339. name: "x",
  18340. type: "tensor"
  18341. }],
  18342. attrs: [{
  18343. tfName: "clip_value_min",
  18344. name: "clipValueMin",
  18345. type: "number"
  18346. }, {
  18347. tfName: "clip_value_max",
  18348. name: "clipValueMax",
  18349. type: "number"
  18350. }]
  18351. }, {
  18352. tfOpName: "Complex",
  18353. category: "basic_math",
  18354. inputs: [{
  18355. start: 0,
  18356. name: "real",
  18357. type: "tensor"
  18358. }, {
  18359. start: 1,
  18360. name: "imag",
  18361. type: "tensor"
  18362. }],
  18363. attrs: [{
  18364. tfName: "T",
  18365. name: "dtype",
  18366. type: "dtype",
  18367. notSupported: !0
  18368. }]
  18369. }, {
  18370. tfOpName: "ComplexAbs",
  18371. category: "basic_math",
  18372. inputs: [{
  18373. start: 0,
  18374. name: "x",
  18375. type: "tensor"
  18376. }],
  18377. attrs: [{
  18378. tfName: "T",
  18379. name: "dtype",
  18380. type: "dtype",
  18381. notSupported: !0
  18382. }]
  18383. }, {
  18384. tfOpName: "Cos",
  18385. category: "basic_math",
  18386. inputs: [{
  18387. start: 0,
  18388. name: "x",
  18389. type: "tensor"
  18390. }],
  18391. attrs: [{
  18392. tfName: "T",
  18393. name: "dtype",
  18394. type: "dtype",
  18395. notSupported: !0
  18396. }]
  18397. }, {
  18398. tfOpName: "Cosh",
  18399. category: "basic_math",
  18400. inputs: [{
  18401. start: 0,
  18402. name: "x",
  18403. type: "tensor"
  18404. }],
  18405. attrs: [{
  18406. tfName: "T",
  18407. name: "dtype",
  18408. type: "dtype",
  18409. notSupported: !0
  18410. }]
  18411. }, {
  18412. tfOpName: "Elu",
  18413. category: "basic_math",
  18414. inputs: [{
  18415. start: 0,
  18416. name: "x",
  18417. type: "tensor"
  18418. }],
  18419. attrs: [{
  18420. tfName: "T",
  18421. name: "dtype",
  18422. type: "dtype",
  18423. notSupported: !0
  18424. }]
  18425. }, {
  18426. tfOpName: "Exp",
  18427. category: "basic_math",
  18428. inputs: [{
  18429. start: 0,
  18430. name: "x",
  18431. type: "tensor"
  18432. }],
  18433. attrs: [{
  18434. tfName: "T",
  18435. name: "dtype",
  18436. type: "dtype",
  18437. notSupported: !0
  18438. }]
  18439. }, {
  18440. tfOpName: "Floor",
  18441. category: "basic_math",
  18442. inputs: [{
  18443. start: 0,
  18444. name: "x",
  18445. type: "tensor"
  18446. }],
  18447. attrs: [{
  18448. tfName: "T",
  18449. name: "dtype",
  18450. type: "dtype",
  18451. notSupported: !0
  18452. }]
  18453. }, {
  18454. tfOpName: "Log",
  18455. category: "basic_math",
  18456. inputs: [{
  18457. start: 0,
  18458. name: "x",
  18459. type: "tensor"
  18460. }],
  18461. attrs: [{
  18462. tfName: "T",
  18463. name: "dtype",
  18464. type: "dtype",
  18465. notSupported: !0
  18466. }]
  18467. }, {
  18468. tfOpName: "Imag",
  18469. category: "basic_math",
  18470. inputs: [{
  18471. start: 0,
  18472. name: "x",
  18473. type: "tensor"
  18474. }],
  18475. attrs: [{
  18476. tfName: "T",
  18477. name: "dtype",
  18478. type: "dtype",
  18479. notSupported: !0
  18480. }, {
  18481. tfName: "Tout",
  18482. name: "outputType",
  18483. type: "dtype",
  18484. notSupported: !0
  18485. }]
  18486. }, {
  18487. tfOpName: "Neg",
  18488. category: "basic_math",
  18489. inputs: [{
  18490. start: 0,
  18491. name: "x",
  18492. type: "tensor"
  18493. }],
  18494. attrs: [{
  18495. tfName: "T",
  18496. name: "dtype",
  18497. type: "dtype",
  18498. notSupported: !0
  18499. }]
  18500. }, {
  18501. tfOpName: "Real",
  18502. category: "basic_math",
  18503. inputs: [{
  18504. start: 0,
  18505. name: "x",
  18506. type: "tensor"
  18507. }],
  18508. attrs: [{
  18509. tfName: "T",
  18510. name: "dtype",
  18511. type: "dtype",
  18512. notSupported: !0
  18513. }, {
  18514. tfName: "Tout",
  18515. name: "outputType",
  18516. type: "dtype",
  18517. notSupported: !0
  18518. }]
  18519. }, {
  18520. tfOpName: "Prelu",
  18521. category: "basic_math",
  18522. inputs: [{
  18523. start: 0,
  18524. name: "x",
  18525. type: "tensor"
  18526. }, {
  18527. start: 1,
  18528. name: "alpha",
  18529. type: "tensor"
  18530. }],
  18531. attrs: [{
  18532. tfName: "T",
  18533. name: "dtype",
  18534. type: "dtype",
  18535. notSupported: !0
  18536. }]
  18537. }, {
  18538. tfOpName: "Relu",
  18539. category: "basic_math",
  18540. inputs: [{
  18541. start: 0,
  18542. name: "x",
  18543. type: "tensor"
  18544. }],
  18545. attrs: [{
  18546. tfName: "T",
  18547. name: "dtype",
  18548. type: "dtype",
  18549. notSupported: !0
  18550. }]
  18551. }, {
  18552. tfOpName: "Relu6",
  18553. category: "basic_math",
  18554. inputs: [{
  18555. start: 0,
  18556. name: "x",
  18557. type: "tensor"
  18558. }],
  18559. attrs: [{
  18560. tfName: "T",
  18561. name: "dtype",
  18562. type: "dtype",
  18563. notSupported: !0
  18564. }, {
  18565. tfName: "clipValueMin",
  18566. name: "clipValueMin",
  18567. type: "number",
  18568. defaultValue: 0
  18569. }, {
  18570. tfName: "clipValueMax",
  18571. name: "clipValueMax",
  18572. type: "number",
  18573. defaultValue: 6
  18574. }]
  18575. }, {
  18576. tfOpName: "Selu",
  18577. category: "basic_math",
  18578. inputs: [{
  18579. start: 0,
  18580. name: "x",
  18581. type: "tensor"
  18582. }],
  18583. attrs: [{
  18584. tfName: "T",
  18585. name: "dtype",
  18586. type: "dtype",
  18587. notSupported: !0
  18588. }]
  18589. }, {
  18590. tfOpName: "Sigmoid",
  18591. category: "basic_math",
  18592. inputs: [{
  18593. start: 0,
  18594. name: "x",
  18595. type: "tensor"
  18596. }],
  18597. attrs: [{
  18598. tfName: "T",
  18599. name: "dtype",
  18600. type: "dtype",
  18601. notSupported: !0
  18602. }]
  18603. }, {
  18604. tfOpName: "Sin",
  18605. category: "basic_math",
  18606. inputs: [{
  18607. start: 0,
  18608. name: "x",
  18609. type: "tensor"
  18610. }],
  18611. attrs: [{
  18612. tfName: "T",
  18613. name: "dtype",
  18614. type: "dtype",
  18615. notSupported: !0
  18616. }]
  18617. }, {
  18618. tfOpName: "Sinh",
  18619. category: "basic_math",
  18620. inputs: [{
  18621. start: 0,
  18622. name: "x",
  18623. type: "tensor"
  18624. }],
  18625. attrs: [{
  18626. tfName: "T",
  18627. name: "dtype",
  18628. type: "dtype",
  18629. notSupported: !0
  18630. }]
  18631. }, {
  18632. tfOpName: "Sqrt",
  18633. category: "basic_math",
  18634. inputs: [{
  18635. start: 0,
  18636. name: "x",
  18637. type: "tensor"
  18638. }],
  18639. attrs: [{
  18640. tfName: "T",
  18641. name: "dtype",
  18642. type: "dtype",
  18643. notSupported: !0
  18644. }]
  18645. }, {
  18646. tfOpName: "Rsqrt",
  18647. category: "basic_math",
  18648. inputs: [{
  18649. start: 0,
  18650. name: "x",
  18651. type: "tensor"
  18652. }],
  18653. attrs: [{
  18654. tfName: "T",
  18655. name: "dtype",
  18656. type: "dtype",
  18657. notSupported: !0
  18658. }]
  18659. }, {
  18660. tfOpName: "Square",
  18661. category: "basic_math",
  18662. inputs: [{
  18663. start: 0,
  18664. name: "x",
  18665. type: "tensor"
  18666. }],
  18667. attrs: [{
  18668. tfName: "T",
  18669. name: "dtype",
  18670. type: "dtype",
  18671. notSupported: !0
  18672. }]
  18673. }, {
  18674. tfOpName: "Tan",
  18675. category: "basic_math",
  18676. inputs: [{
  18677. start: 0,
  18678. name: "x",
  18679. type: "tensor"
  18680. }],
  18681. attrs: [{
  18682. tfName: "T",
  18683. name: "dtype",
  18684. type: "dtype",
  18685. notSupported: !0
  18686. }]
  18687. }, {
  18688. tfOpName: "Tanh",
  18689. category: "basic_math",
  18690. inputs: [{
  18691. start: 0,
  18692. name: "x",
  18693. type: "tensor"
  18694. }],
  18695. attrs: [{
  18696. tfName: "T",
  18697. name: "dtype",
  18698. type: "dtype",
  18699. notSupported: !0
  18700. }]
  18701. }, {
  18702. tfOpName: "Sign",
  18703. category: "basic_math",
  18704. inputs: [{
  18705. start: 0,
  18706. name: "x",
  18707. type: "tensor"
  18708. }],
  18709. attrs: [{
  18710. tfName: "T",
  18711. name: "dtype",
  18712. type: "dtype",
  18713. notSupported: !0
  18714. }]
  18715. }, {
  18716. tfOpName: "Round",
  18717. category: "basic_math",
  18718. inputs: [{
  18719. start: 0,
  18720. name: "x",
  18721. type: "tensor"
  18722. }],
  18723. attrs: [{
  18724. tfName: "T",
  18725. name: "dtype",
  18726. type: "dtype",
  18727. notSupported: !0
  18728. }]
  18729. }, {
  18730. tfOpName: "Expm1",
  18731. category: "basic_math",
  18732. inputs: [{
  18733. start: 0,
  18734. name: "x",
  18735. type: "tensor"
  18736. }],
  18737. attrs: [{
  18738. tfName: "T",
  18739. name: "dtype",
  18740. type: "dtype",
  18741. notSupported: !0
  18742. }]
  18743. }, {
  18744. tfOpName: "Log1p",
  18745. category: "basic_math",
  18746. inputs: [{
  18747. start: 0,
  18748. name: "x",
  18749. type: "tensor"
  18750. }],
  18751. attrs: [{
  18752. tfName: "T",
  18753. name: "dtype",
  18754. type: "dtype",
  18755. notSupported: !0
  18756. }]
  18757. }, {
  18758. tfOpName: "Reciprocal",
  18759. category: "basic_math",
  18760. inputs: [{
  18761. start: 0,
  18762. name: "x",
  18763. type: "tensor"
  18764. }],
  18765. attrs: [{
  18766. tfName: "T",
  18767. name: "dtype",
  18768. type: "dtype",
  18769. notSupported: !0
  18770. }]
  18771. }, {
  18772. tfOpName: "Softplus",
  18773. category: "basic_math",
  18774. inputs: [{
  18775. start: 0,
  18776. name: "x",
  18777. type: "tensor"
  18778. }],
  18779. attrs: [{
  18780. tfName: "T",
  18781. name: "dtype",
  18782. type: "dtype",
  18783. notSupported: !0
  18784. }]
  18785. }, {
  18786. tfOpName: "Asinh",
  18787. category: "basic_math",
  18788. inputs: [{
  18789. start: 0,
  18790. name: "x",
  18791. type: "tensor"
  18792. }],
  18793. attrs: [{
  18794. tfName: "T",
  18795. name: "dtype",
  18796. type: "dtype",
  18797. notSupported: !0
  18798. }]
  18799. }, {
  18800. tfOpName: "Acosh",
  18801. category: "basic_math",
  18802. inputs: [{
  18803. start: 0,
  18804. name: "x",
  18805. type: "tensor"
  18806. }],
  18807. attrs: [{
  18808. tfName: "T",
  18809. name: "dtype",
  18810. type: "dtype",
  18811. notSupported: !0
  18812. }]
  18813. }, {
  18814. tfOpName: "Atanh",
  18815. category: "basic_math",
  18816. inputs: [{
  18817. start: 0,
  18818. name: "x",
  18819. type: "tensor"
  18820. }],
  18821. attrs: [{
  18822. tfName: "T",
  18823. name: "dtype",
  18824. type: "dtype",
  18825. notSupported: !0
  18826. }]
  18827. }, {
  18828. tfOpName: "Erf",
  18829. category: "basic_math",
  18830. inputs: [{
  18831. start: 0,
  18832. name: "x",
  18833. type: "tensor"
  18834. }],
  18835. attrs: [{
  18836. tfName: "T",
  18837. name: "dtype",
  18838. type: "dtype",
  18839. notSupported: !0
  18840. }]
  18841. }, {
  18842. tfOpName: "Prod",
  18843. category: "basic_math",
  18844. inputs: [{
  18845. start: 0,
  18846. name: "x",
  18847. type: "tensor"
  18848. }, {
  18849. start: 1,
  18850. name: "axes",
  18851. type: "number[]"
  18852. }],
  18853. attrs: [{
  18854. tfName: "keep_dims",
  18855. name: "keepDims",
  18856. type: "bool",
  18857. notSupported: !0
  18858. }, {
  18859. tfName: "T",
  18860. name: "dtype",
  18861. type: "dtype",
  18862. notSupported: !0
  18863. }]
  18864. }, {
  18865. tfOpName: "LeakyRelu",
  18866. category: "basic_math",
  18867. inputs: [{
  18868. start: 0,
  18869. name: "x",
  18870. type: "tensor"
  18871. }],
  18872. attrs: [{
  18873. tfName: "alpha",
  18874. name: "alpha",
  18875. type: "number",
  18876. defaultValue: .2
  18877. }, {
  18878. tfName: "T",
  18879. name: "dtype",
  18880. type: "dtype",
  18881. notSupported: !0
  18882. }]
  18883. }],
  18884. basicMath = Object.freeze({
  18885. json: json$1
  18886. }),
  18887. json$2 = [{
  18888. tfOpName: "LoopCond",
  18889. category: "control",
  18890. inputs: [{
  18891. start: 0,
  18892. name: "pred",
  18893. type: "tensor"
  18894. }]
  18895. }, {
  18896. tfOpName: "Switch",
  18897. category: "control",
  18898. inputs: [{
  18899. start: 0,
  18900. name: "data",
  18901. type: "tensor"
  18902. }, {
  18903. start: 1,
  18904. name: "pred",
  18905. type: "tensor"
  18906. }]
  18907. }, {
  18908. tfOpName: "Merge",
  18909. category: "control",
  18910. inputs: [{
  18911. start: 0,
  18912. end: 0,
  18913. name: "tensors",
  18914. type: "tensors"
  18915. }]
  18916. }, {
  18917. tfOpName: "Enter",
  18918. category: "control",
  18919. inputs: [{
  18920. start: 0,
  18921. name: "tensor",
  18922. type: "tensor"
  18923. }],
  18924. attrs: [{
  18925. tfName: "T",
  18926. name: "dtype",
  18927. type: "dtype",
  18928. notSupported: !0
  18929. }, {
  18930. tfName: "frame_name",
  18931. name: "frameName",
  18932. type: "string"
  18933. }, {
  18934. tfName: "is_constant",
  18935. name: "isConstant",
  18936. type: "bool"
  18937. }]
  18938. }, {
  18939. tfOpName: "Exit",
  18940. category: "control",
  18941. inputs: [{
  18942. start: 0,
  18943. name: "tensor",
  18944. type: "tensor"
  18945. }],
  18946. attrs: [{
  18947. tfName: "T",
  18948. name: "dtype",
  18949. type: "dtype",
  18950. notSupported: !0
  18951. }]
  18952. }, {
  18953. tfOpName: "NextIteration",
  18954. category: "control",
  18955. inputs: [{
  18956. start: 0,
  18957. name: "tensor",
  18958. type: "tensor"
  18959. }],
  18960. attrs: [{
  18961. tfName: "T",
  18962. name: "dtype",
  18963. type: "dtype",
  18964. notSupported: !0
  18965. }]
  18966. }, {
  18967. tfOpName: "TensorArrayV3",
  18968. category: "control",
  18969. inputs: [{
  18970. start: 0,
  18971. name: "size",
  18972. type: "number"
  18973. }],
  18974. attrs: [{
  18975. tfName: "dtype",
  18976. name: "dtype",
  18977. type: "dtype"
  18978. }, {
  18979. tfName: "element_shape",
  18980. name: "elementShape",
  18981. type: "shape"
  18982. }, {
  18983. tfName: "dynamic_size",
  18984. name: "dynamicSize",
  18985. type: "bool"
  18986. }, {
  18987. tfName: "clear_after_read",
  18988. name: "clearAfterRead",
  18989. type: "bool"
  18990. }, {
  18991. tfName: "identical_element_shapes",
  18992. name: "identicalElementShapes",
  18993. type: "bool"
  18994. }, {
  18995. tfName: "tensor_array_name",
  18996. name: "name",
  18997. type: "string"
  18998. }]
  18999. }, {
  19000. tfOpName: "TensorArrayWriteV3",
  19001. category: "control",
  19002. inputs: [{
  19003. start: 0,
  19004. name: "tensorArrayId",
  19005. type: "number"
  19006. }, {
  19007. start: 1,
  19008. name: "index",
  19009. type: "number"
  19010. }, {
  19011. start: 2,
  19012. name: "tensor",
  19013. type: "tensor"
  19014. }, {
  19015. start: 3,
  19016. name: "flowIn",
  19017. type: "number"
  19018. }],
  19019. attrs: [{
  19020. tfName: "T",
  19021. name: "dtype",
  19022. type: "dtype",
  19023. notSupported: !0
  19024. }]
  19025. }, {
  19026. tfOpName: "TensorArrayReadV3",
  19027. category: "control",
  19028. inputs: [{
  19029. start: 0,
  19030. name: "tensorArrayId",
  19031. type: "number"
  19032. }, {
  19033. start: 1,
  19034. name: "index",
  19035. type: "number"
  19036. }, {
  19037. start: 2,
  19038. name: "flowIn",
  19039. type: "number"
  19040. }],
  19041. attrs: [{
  19042. tfName: "dtype",
  19043. name: "dtype",
  19044. type: "dtype",
  19045. notSupported: !0
  19046. }]
  19047. }, {
  19048. tfOpName: "TensorArrayGatherV3",
  19049. category: "control",
  19050. inputs: [{
  19051. start: 0,
  19052. name: "tensorArrayId",
  19053. type: "number"
  19054. }, {
  19055. start: 1,
  19056. name: "indices",
  19057. type: "number[]"
  19058. }, {
  19059. start: 2,
  19060. name: "flowIn",
  19061. type: "number"
  19062. }],
  19063. attrs: [{
  19064. tfName: "dtype",
  19065. name: "dtype",
  19066. type: "dtype"
  19067. }, {
  19068. tfName: "element_shape",
  19069. name: "elementShape",
  19070. type: "shape"
  19071. }]
  19072. }, {
  19073. tfOpName: "TensorArrayScatterV3",
  19074. category: "control",
  19075. inputs: [{
  19076. start: 0,
  19077. name: "tensorArrayId",
  19078. type: "number"
  19079. }, {
  19080. start: 1,
  19081. name: "indices",
  19082. type: "number[]"
  19083. }, {
  19084. start: 2,
  19085. name: "tensor",
  19086. type: "tensor"
  19087. }, {
  19088. start: 3,
  19089. name: "flowIn",
  19090. type: "number"
  19091. }],
  19092. attrs: [{
  19093. tfName: "T",
  19094. name: "dtype",
  19095. type: "dtype"
  19096. }]
  19097. }, {
  19098. tfOpName: "TensorArrayConcatV3",
  19099. category: "control",
  19100. inputs: [{
  19101. start: 0,
  19102. name: "tensorArrayId",
  19103. type: "number"
  19104. }, {
  19105. start: 1,
  19106. name: "flowIn",
  19107. type: "number"
  19108. }],
  19109. attrs: [{
  19110. tfName: "dtype",
  19111. name: "dtype",
  19112. type: "dtype"
  19113. }, {
  19114. tfName: "element_shape_except0",
  19115. name: "elementShapeExcept0",
  19116. type: "shape",
  19117. notSupported: !0
  19118. }]
  19119. }, {
  19120. tfOpName: "TensorArraySplitV3",
  19121. category: "control",
  19122. inputs: [{
  19123. start: 0,
  19124. name: "tensorArrayId",
  19125. type: "number"
  19126. }, {
  19127. start: 1,
  19128. name: "tensor",
  19129. type: "tensor"
  19130. }, {
  19131. start: 2,
  19132. name: "lengths",
  19133. type: "number[]"
  19134. }, {
  19135. start: 3,
  19136. name: "flowIn",
  19137. type: "number"
  19138. }],
  19139. attrs: [{
  19140. tfName: "T",
  19141. name: "dtype",
  19142. type: "dtype"
  19143. }]
  19144. }, {
  19145. tfOpName: "TensorArraySizeV3",
  19146. category: "control",
  19147. inputs: [{
  19148. start: 0,
  19149. name: "tensorArrayId",
  19150. type: "number"
  19151. }, {
  19152. start: 1,
  19153. name: "flowIn",
  19154. type: "number"
  19155. }]
  19156. }, {
  19157. tfOpName: "TensorArrayCloseV3",
  19158. category: "control",
  19159. inputs: [{
  19160. start: 0,
  19161. name: "tensorArrayId",
  19162. type: "number"
  19163. }]
  19164. }],
  19165. control = Object.freeze({
  19166. json: json$2
  19167. }),
  19168. json$3 = [{
  19169. tfOpName: "AvgPool",
  19170. category: "convolution",
  19171. inputs: [{
  19172. start: 0,
  19173. name: "x",
  19174. type: "tensor"
  19175. }],
  19176. attrs: [{
  19177. tfName: "strides",
  19178. name: "strides",
  19179. type: "number[]"
  19180. }, {
  19181. tfName: "padding",
  19182. name: "pad",
  19183. type: "string"
  19184. }, {
  19185. tfName: "data_format",
  19186. name: "dataFormat",
  19187. type: "string",
  19188. notSupported: !0
  19189. }, {
  19190. tfName: "ksize",
  19191. name: "kernelSize",
  19192. type: "number[]"
  19193. }, {
  19194. tfName: "T",
  19195. name: "dtype",
  19196. type: "dtype",
  19197. notSupported: !0
  19198. }]
  19199. }, {
  19200. tfOpName: "MaxPool",
  19201. category: "convolution",
  19202. inputs: [{
  19203. start: 0,
  19204. name: "x",
  19205. type: "tensor"
  19206. }],
  19207. attrs: [{
  19208. tfName: "strides",
  19209. name: "strides",
  19210. type: "number[]"
  19211. }, {
  19212. tfName: "padding",
  19213. name: "pad",
  19214. type: "string"
  19215. }, {
  19216. tfName: "data_format",
  19217. name: "dataFormat",
  19218. type: "string",
  19219. notSupported: !0
  19220. }, {
  19221. tfName: "ksize",
  19222. name: "kernelSize",
  19223. type: "number[]"
  19224. }, {
  19225. tfName: "T",
  19226. name: "dtype",
  19227. type: "dtype",
  19228. notSupported: !0
  19229. }]
  19230. }, {
  19231. tfOpName: "AvgPool3D",
  19232. category: "convolution",
  19233. inputs: [{
  19234. start: 0,
  19235. name: "x",
  19236. type: "tensor"
  19237. }],
  19238. attrs: [{
  19239. tfName: "strides",
  19240. name: "strides",
  19241. type: "number[]"
  19242. }, {
  19243. tfName: "padding",
  19244. name: "pad",
  19245. type: "string"
  19246. }, {
  19247. tfName: "data_format",
  19248. name: "dataFormat",
  19249. type: "string",
  19250. notSupported: !0
  19251. }, {
  19252. tfName: "ksize",
  19253. name: "kernelSize",
  19254. type: "number[]"
  19255. }, {
  19256. tfName: "T",
  19257. name: "dtype",
  19258. type: "dtype",
  19259. notSupported: !0
  19260. }]
  19261. }, {
  19262. tfOpName: "MaxPool3D",
  19263. category: "convolution",
  19264. inputs: [{
  19265. start: 0,
  19266. name: "x",
  19267. type: "tensor"
  19268. }],
  19269. attrs: [{
  19270. tfName: "strides",
  19271. name: "strides",
  19272. type: "number[]"
  19273. }, {
  19274. tfName: "padding",
  19275. name: "pad",
  19276. type: "string"
  19277. }, {
  19278. tfName: "data_format",
  19279. name: "dataFormat",
  19280. type: "string",
  19281. notSupported: !0
  19282. }, {
  19283. tfName: "ksize",
  19284. name: "kernelSize",
  19285. type: "number[]"
  19286. }, {
  19287. tfName: "T",
  19288. name: "dtype",
  19289. type: "dtype",
  19290. notSupported: !0
  19291. }]
  19292. }, {
  19293. tfOpName: "Conv1D",
  19294. category: "convolution",
  19295. inputs: [{
  19296. start: 0,
  19297. name: "x",
  19298. type: "tensor"
  19299. }, {
  19300. start: 1,
  19301. name: "filter",
  19302. type: "tensor"
  19303. }],
  19304. attrs: [{
  19305. tfName: "stride",
  19306. name: "stride",
  19307. type: "number"
  19308. }, {
  19309. tfName: "padding",
  19310. name: "pad",
  19311. type: "string"
  19312. }, {
  19313. tfName: "data_format",
  19314. name: "dataFormat",
  19315. type: "string",
  19316. defaultValue: "NWC"
  19317. }, {
  19318. tfName: "T",
  19319. name: "dtype",
  19320. type: "dtype",
  19321. notSupported: !0
  19322. }, {
  19323. tfName: "dilation",
  19324. name: "dilation",
  19325. type: "number",
  19326. defaultValue: 1
  19327. }]
  19328. }, {
  19329. tfOpName: "Conv2D",
  19330. category: "convolution",
  19331. inputs: [{
  19332. start: 0,
  19333. name: "x",
  19334. type: "tensor"
  19335. }, {
  19336. start: 1,
  19337. name: "filter",
  19338. type: "tensor"
  19339. }],
  19340. attrs: [{
  19341. tfName: "T",
  19342. name: "dtype",
  19343. type: "dtype",
  19344. notSupported: !0
  19345. }, {
  19346. tfName: "strides",
  19347. name: "strides",
  19348. type: "number[]"
  19349. }, {
  19350. tfName: "padding",
  19351. name: "pad",
  19352. type: "string"
  19353. }, {
  19354. tfName: "useCudnnOnGpu",
  19355. name: "useCudnnOnGpu",
  19356. type: "bool"
  19357. }, {
  19358. tfName: "data_format",
  19359. name: "dataFormat",
  19360. type: "string",
  19361. defaultValue: "NHWC"
  19362. }, {
  19363. tfName: "dilations",
  19364. name: "dilations",
  19365. type: "number[]"
  19366. }]
  19367. }, {
  19368. tfOpName: "_FusedConv2D",
  19369. category: "convolution",
  19370. inputs: [{
  19371. start: 0,
  19372. name: "x",
  19373. type: "tensor"
  19374. }, {
  19375. start: 1,
  19376. name: "filter",
  19377. type: "tensor"
  19378. }, {
  19379. start: 2,
  19380. end: 0,
  19381. name: "args",
  19382. type: "tensors"
  19383. }],
  19384. attrs: [{
  19385. tfName: "num_args",
  19386. name: "numArgs",
  19387. type: "number"
  19388. }, {
  19389. tfName: "T",
  19390. name: "dtype",
  19391. type: "dtype",
  19392. notSupported: !0
  19393. }, {
  19394. tfName: "strides",
  19395. name: "strides",
  19396. type: "number[]"
  19397. }, {
  19398. tfName: "padding",
  19399. name: "pad",
  19400. type: "string"
  19401. }, {
  19402. tfName: "explicit_paddings",
  19403. name: "explicitPaddings",
  19404. type: "number[]",
  19405. defaultValue: []
  19406. }, {
  19407. tfName: "use_cudnn_on_gpu",
  19408. name: "useCudnnOnGpu",
  19409. type: "bool",
  19410. defaultValue: !0
  19411. }, {
  19412. tfName: "data_format",
  19413. name: "dataFormat",
  19414. type: "string",
  19415. defaultValue: "NHWC"
  19416. }, {
  19417. tfName: "dilations",
  19418. name: "dilations",
  19419. type: "number[]",
  19420. defaultValue: [1, 1, 1, 1]
  19421. }, {
  19422. tfName: "fused_ops",
  19423. name: "fusedOps",
  19424. type: "string[]",
  19425. defaultValue: []
  19426. }, {
  19427. tfName: "epsilon",
  19428. name: "epsilon",
  19429. type: "number",
  19430. defaultValue: 1e-4
  19431. }]
  19432. }, {
  19433. tfOpName: "Conv2DBackpropInput",
  19434. category: "convolution",
  19435. inputs: [{
  19436. start: 2,
  19437. name: "x",
  19438. type: "tensor"
  19439. }, {
  19440. start: 1,
  19441. name: "filter",
  19442. type: "tensor"
  19443. }, {
  19444. start: 0,
  19445. name: "outputShape",
  19446. type: "number[]"
  19447. }],
  19448. attrs: [{
  19449. tfName: "strides",
  19450. name: "strides",
  19451. type: "number[]"
  19452. }, {
  19453. tfName: "padding",
  19454. name: "pad",
  19455. type: "string"
  19456. }, {
  19457. tfName: "data_format",
  19458. name: "dataFormat",
  19459. type: "string",
  19460. notSupported: !0
  19461. }]
  19462. }, {
  19463. tfOpName: "DepthwiseConv2d",
  19464. category: "convolution",
  19465. inputs: [{
  19466. start: 0,
  19467. name: "input",
  19468. type: "tensor"
  19469. }, {
  19470. start: 1,
  19471. name: "filter",
  19472. type: "tensor"
  19473. }],
  19474. attrs: [{
  19475. tfName: "strides",
  19476. name: "strides",
  19477. type: "number[]"
  19478. }, {
  19479. tfName: "padding",
  19480. name: "pad",
  19481. type: "string"
  19482. }, {
  19483. tfName: "data_format",
  19484. name: "dataFormat",
  19485. type: "string",
  19486. defaultValue: "NHWC"
  19487. }, {
  19488. tfName: "dilations",
  19489. name: "dilations",
  19490. type: "number[]"
  19491. }]
  19492. }, {
  19493. tfOpName: "DepthwiseConv2dNative",
  19494. category: "convolution",
  19495. inputs: [{
  19496. start: 0,
  19497. name: "input",
  19498. type: "tensor"
  19499. }, {
  19500. start: 1,
  19501. name: "filter",
  19502. type: "tensor"
  19503. }],
  19504. attrs: [{
  19505. tfName: "strides",
  19506. name: "strides",
  19507. type: "number[]"
  19508. }, {
  19509. tfName: "padding",
  19510. name: "pad",
  19511. type: "string"
  19512. }, {
  19513. tfName: "data_format",
  19514. name: "dataFormat",
  19515. type: "string",
  19516. defaultValue: "NHWC"
  19517. }, {
  19518. tfName: "dilations",
  19519. name: "dilations",
  19520. type: "number[]"
  19521. }]
  19522. }, {
  19523. tfOpName: "Conv3D",
  19524. category: "convolution",
  19525. inputs: [{
  19526. start: 0,
  19527. name: "x",
  19528. type: "tensor"
  19529. }, {
  19530. start: 1,
  19531. name: "filter",
  19532. type: "tensor"
  19533. }],
  19534. attrs: [{
  19535. tfName: "strides",
  19536. name: "strides",
  19537. type: "number[]"
  19538. }, {
  19539. tfName: "padding",
  19540. name: "pad",
  19541. type: "string"
  19542. }, {
  19543. tfName: "data_format",
  19544. name: "dataFormat",
  19545. type: "string",
  19546. defaultValue: "NHWC"
  19547. }, {
  19548. tfName: "dilations",
  19549. name: "dilations",
  19550. type: "number[]"
  19551. }]
  19552. }],
  19553. convolution = Object.freeze({
  19554. json: json$3
  19555. }),
  19556. json$4 = [{
  19557. tfOpName: "Fill",
  19558. category: "creation",
  19559. inputs: [{
  19560. start: 0,
  19561. name: "shape",
  19562. type: "number[]"
  19563. }, {
  19564. start: 1,
  19565. name: "value",
  19566. type: "number"
  19567. }],
  19568. attrs: [{
  19569. tfName: "T",
  19570. name: "dtype",
  19571. type: "dtype"
  19572. }]
  19573. }, {
  19574. tfOpName: "LinSpace",
  19575. category: "creation",
  19576. inputs: [{
  19577. start: 0,
  19578. name: "start",
  19579. type: "number"
  19580. }, {
  19581. start: 1,
  19582. name: "stop",
  19583. type: "number"
  19584. }, {
  19585. start: 2,
  19586. name: "num",
  19587. type: "number"
  19588. }],
  19589. attrs: [{
  19590. tfName: "T",
  19591. name: "dtype",
  19592. type: "dtype",
  19593. notSupported: !0
  19594. }]
  19595. }, {
  19596. tfOpName: "OneHot",
  19597. category: "creation",
  19598. inputs: [{
  19599. start: 0,
  19600. name: "indices",
  19601. type: "tensor"
  19602. }, {
  19603. start: 1,
  19604. name: "depth",
  19605. type: "number"
  19606. }, {
  19607. start: 2,
  19608. name: "onValue",
  19609. type: "number",
  19610. defaultValue: 1
  19611. }, {
  19612. start: 3,
  19613. name: "offValue",
  19614. type: "number",
  19615. defaultValue: 0
  19616. }],
  19617. attrs: [{
  19618. tfName: "axis",
  19619. name: "axis",
  19620. type: "number",
  19621. notSupported: !0
  19622. }, {
  19623. tfName: "T",
  19624. name: "dtype",
  19625. type: "dtype",
  19626. notSupported: !0
  19627. }]
  19628. }, {
  19629. tfOpName: "Ones",
  19630. category: "creation",
  19631. inputs: [{
  19632. start: 0,
  19633. name: "shape",
  19634. type: "number[]"
  19635. }],
  19636. attrs: [{
  19637. tfName: "T",
  19638. name: "dtype",
  19639. type: "dtype"
  19640. }]
  19641. }, {
  19642. tfOpName: "OnesLike",
  19643. category: "creation",
  19644. inputs: [{
  19645. start: 0,
  19646. name: "x",
  19647. type: "tensor"
  19648. }],
  19649. attrs: [{
  19650. tfName: "dtype",
  19651. name: "dtype",
  19652. type: "dtype"
  19653. }]
  19654. }, {
  19655. tfOpName: "RandomUniform",
  19656. category: "creation",
  19657. inputs: [{
  19658. start: 0,
  19659. name: "shape",
  19660. type: "number[]"
  19661. }],
  19662. attrs: [{
  19663. tfName: "minval",
  19664. name: "minval",
  19665. type: "number",
  19666. defaultValue: 0
  19667. }, {
  19668. tfName: "maxval",
  19669. name: "maxval",
  19670. type: "number",
  19671. defaultValue: 1
  19672. }, {
  19673. tfName: "dtype",
  19674. name: "dtype",
  19675. type: "dtype"
  19676. }, {
  19677. tfName: "seed",
  19678. name: "seed",
  19679. type: "number",
  19680. defaultValue: 0
  19681. }, {
  19682. tfName: "seed2",
  19683. name: "seed2",
  19684. type: "number",
  19685. defaultValue: 0,
  19686. notSupported: !0
  19687. }, {
  19688. tfName: "T",
  19689. name: "T",
  19690. type: "number",
  19691. notSupported: !0
  19692. }]
  19693. }, {
  19694. tfOpName: "Range",
  19695. category: "creation",
  19696. inputs: [{
  19697. start: 0,
  19698. name: "start",
  19699. type: "number"
  19700. }, {
  19701. start: 1,
  19702. name: "stop",
  19703. type: "number"
  19704. }, {
  19705. start: 2,
  19706. name: "step",
  19707. type: "number",
  19708. defaultValue: 0
  19709. }],
  19710. attrs: [{
  19711. tfName: "Tidx",
  19712. name: "dtype",
  19713. type: "dtype"
  19714. }]
  19715. }, {
  19716. tfOpName: "TruncatedNormal",
  19717. category: "creation",
  19718. inputs: [{
  19719. start: 0,
  19720. name: "shape",
  19721. type: "number[]"
  19722. }],
  19723. attrs: [{
  19724. tfName: "means",
  19725. name: "mean",
  19726. type: "number",
  19727. defaultValue: 0
  19728. }, {
  19729. tfName: "stddev",
  19730. name: "stdDev",
  19731. type: "number",
  19732. defaultValue: 1
  19733. }, {
  19734. tfName: "seed",
  19735. name: "seed",
  19736. type: "number"
  19737. }, {
  19738. tfName: "seed2",
  19739. name: "seed2",
  19740. type: "number",
  19741. defaultValue: 0,
  19742. notSupported: !0
  19743. }, {
  19744. tfName: "dtype",
  19745. name: "dtype",
  19746. type: "dtype"
  19747. }, {
  19748. tfName: "T",
  19749. name: "T",
  19750. type: "number",
  19751. notSupported: !0
  19752. }]
  19753. }, {
  19754. tfOpName: "Zeros",
  19755. category: "creation",
  19756. inputs: [{
  19757. start: 0,
  19758. name: "shape",
  19759. type: "number[]"
  19760. }],
  19761. attrs: [{
  19762. tfName: "T",
  19763. name: "dtype",
  19764. type: "dtype"
  19765. }]
  19766. }, {
  19767. tfOpName: "ZerosLike",
  19768. category: "creation",
  19769. inputs: [{
  19770. start: 0,
  19771. name: "x",
  19772. type: "tensor"
  19773. }],
  19774. attrs: [{
  19775. tfName: "T",
  19776. name: "dtype",
  19777. type: "dtype"
  19778. }]
  19779. }, {
  19780. tfOpName: "Multinomial",
  19781. category: "creation",
  19782. inputs: [{
  19783. start: 0,
  19784. name: "logits",
  19785. type: "tensor"
  19786. }, {
  19787. start: 1,
  19788. name: "numSamples",
  19789. type: "number"
  19790. }],
  19791. attrs: [{
  19792. tfName: "seed",
  19793. name: "seed",
  19794. type: "number"
  19795. }, {
  19796. tfName: "seed2",
  19797. name: "seed2",
  19798. type: "number"
  19799. }, {
  19800. tfName: "T",
  19801. name: "dtype",
  19802. type: "dtype"
  19803. }, {
  19804. tfName: "output_dtype",
  19805. name: "output_dtype",
  19806. type: "dtype"
  19807. }]
  19808. }],
  19809. creation = Object.freeze({
  19810. json: json$4
  19811. }),
  19812. json$5 = [{
  19813. tfOpName: "NonMaxSuppressionV2",
  19814. category: "dynamic",
  19815. inputs: [{
  19816. start: 0,
  19817. name: "boxes",
  19818. type: "tensor"
  19819. }, {
  19820. start: 1,
  19821. name: "scores",
  19822. type: "tensor"
  19823. }, {
  19824. start: 2,
  19825. name: "maxOutputSize",
  19826. type: "number"
  19827. }, {
  19828. start: 3,
  19829. name: "iouThreshold",
  19830. type: "number"
  19831. }]
  19832. }, {
  19833. tfOpName: "NonMaxSuppressionV3",
  19834. category: "dynamic",
  19835. inputs: [{
  19836. start: 0,
  19837. name: "boxes",
  19838. type: "tensor"
  19839. }, {
  19840. start: 1,
  19841. name: "scores",
  19842. type: "tensor"
  19843. }, {
  19844. start: 2,
  19845. name: "maxOutputSize",
  19846. type: "number"
  19847. }, {
  19848. start: 3,
  19849. name: "iouThreshold",
  19850. type: "number"
  19851. }, {
  19852. start: 4,
  19853. name: "scoreThreshold",
  19854. type: "number"
  19855. }]
  19856. }, {
  19857. tfOpName: "Where",
  19858. category: "dynamic",
  19859. inputs: [{
  19860. start: 0,
  19861. name: "condition",
  19862. type: "tensor"
  19863. }],
  19864. attrs: [{
  19865. tfName: "T",
  19866. name: "dtype",
  19867. type: "dtype",
  19868. notSupported: !0
  19869. }]
  19870. }, {
  19871. tfOpName: "ListDiff",
  19872. category: "dynamic",
  19873. inputs: [{
  19874. start: 0,
  19875. name: "x",
  19876. type: "tensor"
  19877. }, {
  19878. start: 1,
  19879. name: "y",
  19880. type: "tensor"
  19881. }],
  19882. attrs: [{
  19883. tfName: "T",
  19884. name: "dtype",
  19885. type: "dtype",
  19886. notSupported: !0
  19887. }]
  19888. }],
  19889. dynamic = Object.freeze({
  19890. json: json$5
  19891. }),
  19892. json$6 = [{
  19893. tfOpName: "TopKV2",
  19894. category: "evaluation",
  19895. inputs: [{
  19896. start: 0,
  19897. name: "x",
  19898. type: "tensor"
  19899. }, {
  19900. start: 1,
  19901. name: "k",
  19902. type: "number"
  19903. }],
  19904. attrs: [{
  19905. tfName: "sorted",
  19906. name: "sorted",
  19907. type: "bool"
  19908. }]
  19909. }],
  19910. evaluation = Object.freeze({
  19911. json: json$6
  19912. }),
  19913. json$7 = [{
  19914. tfOpName: "PlaceholderWithDefault",
  19915. category: "graph",
  19916. inputs: [{
  19917. start: 0,
  19918. name: "default",
  19919. type: "tensor"
  19920. }],
  19921. attrs: [{
  19922. tfName: "shape",
  19923. name: "shape",
  19924. type: "shape"
  19925. }, {
  19926. tfName: "dtype",
  19927. name: "dtype",
  19928. type: "dtype"
  19929. }]
  19930. }, {
  19931. tfOpName: "Placeholder",
  19932. category: "graph",
  19933. attrs: [{
  19934. tfName: "shape",
  19935. name: "shape",
  19936. type: "shape"
  19937. }, {
  19938. tfName: "dtype",
  19939. name: "dtype",
  19940. type: "dtype"
  19941. }]
  19942. }, {
  19943. tfOpName: "Const",
  19944. category: "graph"
  19945. }, {
  19946. tfOpName: "Identity",
  19947. category: "graph",
  19948. inputs: [{
  19949. start: 0,
  19950. name: "x",
  19951. type: "tensor"
  19952. }]
  19953. }, {
  19954. tfOpName: "IdentityN",
  19955. category: "graph",
  19956. inputs: [{
  19957. start: 0,
  19958. end: 0,
  19959. name: "x",
  19960. type: "tensors"
  19961. }]
  19962. }, {
  19963. tfOpName: "Snapshot",
  19964. category: "graph",
  19965. inputs: [{
  19966. start: 0,
  19967. name: "x",
  19968. type: "tensor"
  19969. }]
  19970. }, {
  19971. tfOpName: "Rank",
  19972. category: "graph",
  19973. inputs: [{
  19974. start: 0,
  19975. name: "x",
  19976. type: "tensor"
  19977. }]
  19978. }, {
  19979. tfOpName: "Size",
  19980. category: "graph",
  19981. inputs: [{
  19982. start: 0,
  19983. name: "x",
  19984. type: "tensor"
  19985. }]
  19986. }, {
  19987. tfOpName: "Shape",
  19988. category: "graph",
  19989. inputs: [{
  19990. start: 0,
  19991. name: "x",
  19992. type: "tensor"
  19993. }]
  19994. }, {
  19995. tfOpName: "ShapeN",
  19996. category: "graph",
  19997. inputs: [{
  19998. start: 0,
  19999. end: 0,
  20000. name: "x",
  20001. type: "tensors"
  20002. }]
  20003. }, {
  20004. tfOpName: "Print",
  20005. category: "graph",
  20006. inputs: [{
  20007. start: 0,
  20008. name: "x",
  20009. type: "tensor"
  20010. }, {
  20011. start: 1,
  20012. name: "data",
  20013. type: "tensors"
  20014. }],
  20015. attrs: [{
  20016. tfName: "message",
  20017. name: "message",
  20018. type: "string"
  20019. }, {
  20020. tfName: "first_n",
  20021. name: "firstN",
  20022. type: "number",
  20023. notSupported: !0
  20024. }, {
  20025. tfName: "summarize",
  20026. name: "summarize",
  20027. type: "number",
  20028. defaultValue: 3
  20029. }]
  20030. }, {
  20031. tfOpName: "NoOp",
  20032. category: "graph",
  20033. inputs: []
  20034. }, {
  20035. tfOpName: "StopGradient",
  20036. category: "graph",
  20037. inputs: [{
  20038. start: 0,
  20039. name: "x",
  20040. type: "tensor"
  20041. }]
  20042. }, {
  20043. tfOpName: "FakeQuantWithMinMaxVars",
  20044. category: "graph",
  20045. inputs: [{
  20046. start: 0,
  20047. name: "x",
  20048. type: "tensor"
  20049. }],
  20050. attrs: [{
  20051. tfName: "min",
  20052. name: "min",
  20053. type: "number"
  20054. }, {
  20055. tfName: "max",
  20056. name: "max",
  20057. type: "number"
  20058. }]
  20059. }],
  20060. graph = Object.freeze({
  20061. json: json$7
  20062. }),
  20063. json$8 = [{
  20064. tfOpName: "ResizeBilinear",
  20065. category: "image",
  20066. inputs: [{
  20067. start: 0,
  20068. name: "images",
  20069. type: "tensor"
  20070. }, {
  20071. start: 1,
  20072. name: "size",
  20073. type: "number[]"
  20074. }],
  20075. attrs: [{
  20076. tfName: "align_corners",
  20077. name: "alignCorners",
  20078. type: "bool"
  20079. }, {
  20080. tfName: "T",
  20081. name: "dtype",
  20082. type: "dtype",
  20083. notSupported: !0
  20084. }]
  20085. }, {
  20086. tfOpName: "ResizeNearestNeighbor",
  20087. category: "image",
  20088. inputs: [{
  20089. start: 0,
  20090. name: "images",
  20091. type: "tensor"
  20092. }, {
  20093. start: 1,
  20094. name: "size",
  20095. type: "number[]"
  20096. }],
  20097. attrs: [{
  20098. tfName: "align_corners",
  20099. name: "alignCorners",
  20100. type: "bool"
  20101. }, {
  20102. tfName: "T",
  20103. name: "dtype",
  20104. type: "dtype",
  20105. notSupported: !0
  20106. }]
  20107. }, {
  20108. tfOpName: "CropAndResize",
  20109. category: "image",
  20110. inputs: [{
  20111. start: 0,
  20112. name: "image",
  20113. type: "tensor"
  20114. }, {
  20115. start: 1,
  20116. name: "boxes",
  20117. type: "tensor"
  20118. }, {
  20119. start: 2,
  20120. name: "boxInd",
  20121. type: "tensor"
  20122. }, {
  20123. start: 3,
  20124. name: "cropSize",
  20125. type: "number[]"
  20126. }],
  20127. attrs: [{
  20128. tfName: "method",
  20129. name: "method",
  20130. type: "string"
  20131. }, {
  20132. tfName: "extrapolation_value",
  20133. name: "extrapolationValue",
  20134. type: "number"
  20135. }]
  20136. }],
  20137. image$1 = Object.freeze({
  20138. json: json$8
  20139. }),
  20140. json$9 = [{
  20141. tfOpName: "Equal",
  20142. category: "logical",
  20143. inputs: [{
  20144. start: 0,
  20145. name: "a",
  20146. type: "tensor"
  20147. }, {
  20148. start: 1,
  20149. name: "b",
  20150. type: "tensor"
  20151. }],
  20152. attrs: [{
  20153. tfName: "T",
  20154. name: "dtype",
  20155. type: "dtype",
  20156. notSupported: !0
  20157. }]
  20158. }, {
  20159. tfOpName: "NotEqual",
  20160. category: "logical",
  20161. inputs: [{
  20162. start: 0,
  20163. name: "a",
  20164. type: "tensor"
  20165. }, {
  20166. start: 1,
  20167. name: "b",
  20168. type: "tensor"
  20169. }],
  20170. attrs: [{
  20171. tfName: "T",
  20172. name: "dtype",
  20173. type: "dtype",
  20174. notSupported: !0
  20175. }]
  20176. }, {
  20177. tfOpName: "Greater",
  20178. category: "logical",
  20179. inputs: [{
  20180. start: 0,
  20181. name: "a",
  20182. type: "tensor"
  20183. }, {
  20184. start: 1,
  20185. name: "b",
  20186. type: "tensor"
  20187. }],
  20188. attrs: [{
  20189. tfName: "T",
  20190. name: "dtype",
  20191. type: "dtype",
  20192. notSupported: !0
  20193. }]
  20194. }, {
  20195. tfOpName: "GreaterEqual",
  20196. category: "logical",
  20197. inputs: [{
  20198. start: 0,
  20199. name: "a",
  20200. type: "tensor"
  20201. }, {
  20202. start: 1,
  20203. name: "b",
  20204. type: "tensor"
  20205. }],
  20206. attrs: [{
  20207. tfName: "T",
  20208. name: "dtype",
  20209. type: "dtype",
  20210. notSupported: !0
  20211. }]
  20212. }, {
  20213. tfOpName: "Less",
  20214. category: "logical",
  20215. inputs: [{
  20216. start: 0,
  20217. name: "a",
  20218. type: "tensor"
  20219. }, {
  20220. start: 1,
  20221. name: "b",
  20222. type: "tensor"
  20223. }],
  20224. attrs: [{
  20225. tfName: "T",
  20226. name: "dtype",
  20227. type: "dtype",
  20228. notSupported: !0
  20229. }]
  20230. }, {
  20231. tfOpName: "LessEqual",
  20232. category: "logical",
  20233. inputs: [{
  20234. start: 0,
  20235. name: "a",
  20236. type: "tensor"
  20237. }, {
  20238. start: 1,
  20239. name: "b",
  20240. type: "tensor"
  20241. }],
  20242. attrs: [{
  20243. tfName: "T",
  20244. name: "dtype",
  20245. type: "dtype",
  20246. notSupported: !0
  20247. }]
  20248. }, {
  20249. tfOpName: "LogicalAnd",
  20250. category: "logical",
  20251. inputs: [{
  20252. start: 0,
  20253. name: "a",
  20254. type: "tensor"
  20255. }, {
  20256. start: 1,
  20257. name: "b",
  20258. type: "tensor"
  20259. }],
  20260. attrs: [{
  20261. tfName: "T",
  20262. name: "dtype",
  20263. type: "dtype",
  20264. notSupported: !0
  20265. }]
  20266. }, {
  20267. tfOpName: "LogicalNot",
  20268. category: "logical",
  20269. inputs: [{
  20270. start: 0,
  20271. name: "a",
  20272. type: "tensor"
  20273. }],
  20274. attrs: [{
  20275. tfName: "T",
  20276. name: "dtype",
  20277. type: "dtype",
  20278. notSupported: !0
  20279. }]
  20280. }, {
  20281. tfOpName: "LogicalOr",
  20282. category: "logical",
  20283. inputs: [{
  20284. start: 0,
  20285. name: "a",
  20286. type: "tensor"
  20287. }, {
  20288. start: 1,
  20289. name: "b",
  20290. type: "tensor"
  20291. }],
  20292. attrs: [{
  20293. tfName: "T",
  20294. name: "dtype",
  20295. type: "dtype",
  20296. notSupported: !0
  20297. }]
  20298. }, {
  20299. tfOpName: "Select",
  20300. category: "logical",
  20301. inputs: [{
  20302. start: 0,
  20303. name: "condition",
  20304. type: "tensor"
  20305. }, {
  20306. start: 1,
  20307. name: "a",
  20308. type: "tensor"
  20309. }, {
  20310. start: 2,
  20311. name: "b",
  20312. type: "tensor"
  20313. }],
  20314. attrs: [{
  20315. tfName: "T",
  20316. name: "dtype",
  20317. type: "dtype",
  20318. notSupported: !0
  20319. }]
  20320. }],
  20321. logical = Object.freeze({
  20322. json: json$9
  20323. }),
  20324. json$10 = [{
  20325. tfOpName: "MatMul",
  20326. category: "matrices",
  20327. inputs: [{
  20328. start: 0,
  20329. name: "a",
  20330. type: "tensor"
  20331. }, {
  20332. start: 1,
  20333. name: "b",
  20334. type: "tensor"
  20335. }],
  20336. attrs: [{
  20337. tfName: "transpose_a",
  20338. name: "transposeA",
  20339. type: "bool",
  20340. defaultValue: !1
  20341. }, {
  20342. tfName: "transpose_b",
  20343. name: "transposeB",
  20344. type: "bool",
  20345. defaultValue: !1
  20346. }, {
  20347. tfName: "T",
  20348. name: "dtype",
  20349. type: "dtype",
  20350. notSupported: !0
  20351. }]
  20352. }, {
  20353. tfOpName: "BatchMatMul",
  20354. category: "matrices",
  20355. inputs: [{
  20356. start: 0,
  20357. name: "a",
  20358. type: "tensor"
  20359. }, {
  20360. start: 1,
  20361. name: "b",
  20362. type: "tensor"
  20363. }],
  20364. attrs: [{
  20365. tfName: "adj_x",
  20366. name: "transposeA",
  20367. type: "bool",
  20368. defaultValue: !1
  20369. }, {
  20370. tfName: "adj_y",
  20371. name: "transposeB",
  20372. type: "bool",
  20373. defaultValue: !1
  20374. }, {
  20375. tfName: "T",
  20376. name: "dtype",
  20377. type: "dtype",
  20378. notSupported: !0
  20379. }]
  20380. }, {
  20381. tfOpName: "BatchMatMulV2",
  20382. category: "matrices",
  20383. inputs: [{
  20384. start: 0,
  20385. name: "a",
  20386. type: "tensor"
  20387. }, {
  20388. start: 1,
  20389. name: "b",
  20390. type: "tensor"
  20391. }],
  20392. attrs: [{
  20393. tfName: "adj_x",
  20394. name: "transposeA",
  20395. type: "bool",
  20396. defaultValue: !1
  20397. }, {
  20398. tfName: "adj_y",
  20399. name: "transposeB",
  20400. type: "bool",
  20401. defaultValue: !1
  20402. }, {
  20403. tfName: "T",
  20404. name: "dtype",
  20405. type: "dtype",
  20406. notSupported: !0
  20407. }]
  20408. }, {
  20409. tfOpName: "Transpose",
  20410. category: "matrices",
  20411. inputs: [{
  20412. start: 0,
  20413. name: "x",
  20414. type: "tensor"
  20415. }, {
  20416. start: 1,
  20417. name: "perm",
  20418. type: "number[]"
  20419. }],
  20420. attrs: [{
  20421. tfName: "T",
  20422. name: "dtype",
  20423. type: "dtype",
  20424. notSupported: !0
  20425. }]
  20426. }],
  20427. matrices = Object.freeze({
  20428. json: json$10
  20429. }),
  20430. json$11 = [{
  20431. tfOpName: "FusedBatchNorm",
  20432. category: "normalization",
  20433. inputs: [{
  20434. start: 0,
  20435. name: "x",
  20436. type: "tensor"
  20437. }, {
  20438. start: 1,
  20439. name: "scale",
  20440. type: "tensor"
  20441. }, {
  20442. start: 2,
  20443. name: "offset",
  20444. type: "tensor"
  20445. }, {
  20446. start: 3,
  20447. name: "mean",
  20448. type: "tensor"
  20449. }, {
  20450. start: 4,
  20451. name: "variance",
  20452. type: "tensor"
  20453. }],
  20454. attrs: [{
  20455. tfName: "epsilon",
  20456. name: "epsilon",
  20457. type: "number",
  20458. defaultValue: .001
  20459. }, {
  20460. tfName: "data_format",
  20461. name: "dataFormat",
  20462. type: "string",
  20463. notSupported: !0
  20464. }]
  20465. }, {
  20466. tfOpName: "FusedBatchNormV2",
  20467. category: "normalization",
  20468. inputs: [{
  20469. start: 0,
  20470. name: "x",
  20471. type: "tensor"
  20472. }, {
  20473. start: 1,
  20474. name: "scale",
  20475. type: "tensor"
  20476. }, {
  20477. start: 2,
  20478. name: "offset",
  20479. type: "tensor"
  20480. }, {
  20481. start: 3,
  20482. name: "mean",
  20483. type: "tensor"
  20484. }, {
  20485. start: 4,
  20486. name: "variance",
  20487. type: "tensor"
  20488. }],
  20489. attrs: [{
  20490. tfName: "epsilon",
  20491. name: "epsilon",
  20492. type: "number",
  20493. defaultValue: .001
  20494. }, {
  20495. tfName: "data_format",
  20496. name: "dataFormat",
  20497. type: "string",
  20498. notSupported: !0
  20499. }]
  20500. }, {
  20501. tfOpName: "FusedBatchNormV3",
  20502. category: "normalization",
  20503. inputs: [{
  20504. start: 0,
  20505. name: "x",
  20506. type: "tensor"
  20507. }, {
  20508. start: 1,
  20509. name: "scale",
  20510. type: "tensor"
  20511. }, {
  20512. start: 2,
  20513. name: "offset",
  20514. type: "tensor"
  20515. }, {
  20516. start: 3,
  20517. name: "mean",
  20518. type: "tensor"
  20519. }, {
  20520. start: 4,
  20521. name: "variance",
  20522. type: "tensor"
  20523. }],
  20524. attrs: [{
  20525. tfName: "epsilon",
  20526. name: "epsilon",
  20527. type: "number",
  20528. defaultValue: .001
  20529. }, {
  20530. tfName: "data_format",
  20531. name: "dataFormat",
  20532. type: "string",
  20533. notSupported: !0
  20534. }]
  20535. }, {
  20536. tfOpName: "LRN",
  20537. category: "normalization",
  20538. inputs: [{
  20539. start: 0,
  20540. name: "x",
  20541. type: "tensor"
  20542. }],
  20543. attrs: [{
  20544. tfName: "depth_radius",
  20545. name: "radius",
  20546. type: "number",
  20547. defaultValue: 5
  20548. }, {
  20549. tfName: "bias",
  20550. name: "bias",
  20551. type: "number",
  20552. defaultValue: 1
  20553. }, {
  20554. tfName: "alpha",
  20555. name: "alpha",
  20556. type: "number",
  20557. defaultValue: 1
  20558. }, {
  20559. tfName: "beta",
  20560. name: "beta",
  20561. type: "number",
  20562. defaultValue: .5
  20563. }]
  20564. }, {
  20565. tfOpName: "Softmax",
  20566. category: "normalization",
  20567. inputs: [{
  20568. start: 0,
  20569. name: "x",
  20570. type: "tensor"
  20571. }]
  20572. }, {
  20573. tfOpName: "LogSoftmax",
  20574. category: "normalization",
  20575. inputs: [{
  20576. start: 0,
  20577. name: "x",
  20578. type: "tensor"
  20579. }]
  20580. }, {
  20581. tfOpName: "SparseToDense",
  20582. category: "normalization",
  20583. inputs: [{
  20584. start: 0,
  20585. name: "sparseIndices",
  20586. type: "tensor"
  20587. }, {
  20588. start: 1,
  20589. name: "outputShape",
  20590. type: "number[]"
  20591. }, {
  20592. start: 2,
  20593. name: "sparseValues",
  20594. type: "tensor"
  20595. }, {
  20596. start: 3,
  20597. name: "defaultValue",
  20598. type: "tensor"
  20599. }],
  20600. attrs: [{
  20601. tfName: "validate_indices",
  20602. name: "validateIndices",
  20603. type: "bool",
  20604. defaultValue: !0,
  20605. notSupported: !0
  20606. }]
  20607. }],
  20608. normalization = Object.freeze({
  20609. json: json$11
  20610. }),
  20611. json$12 = [{
  20612. tfOpName: "Max",
  20613. category: "reduction",
  20614. inputs: [{
  20615. start: 0,
  20616. name: "x",
  20617. type: "tensor"
  20618. }, {
  20619. start: 1,
  20620. name: "axis",
  20621. type: "number[]"
  20622. }],
  20623. attrs: [{
  20624. tfName: "keep_dims",
  20625. name: "keepDims",
  20626. type: "bool"
  20627. }]
  20628. }, {
  20629. tfOpName: "Mean",
  20630. category: "reduction",
  20631. inputs: [{
  20632. start: 0,
  20633. name: "x",
  20634. type: "tensor"
  20635. }, {
  20636. start: 1,
  20637. name: "axis",
  20638. type: "number[]"
  20639. }],
  20640. attrs: [{
  20641. tfName: "keep_dims",
  20642. name: "keepDims",
  20643. type: "bool"
  20644. }]
  20645. }, {
  20646. tfOpName: "Min",
  20647. category: "reduction",
  20648. inputs: [{
  20649. start: 0,
  20650. name: "x",
  20651. type: "tensor"
  20652. }, {
  20653. start: 1,
  20654. name: "axis",
  20655. type: "number[]"
  20656. }],
  20657. attrs: [{
  20658. tfName: "keep_dims",
  20659. name: "keepDims",
  20660. type: "bool"
  20661. }]
  20662. }, {
  20663. tfOpName: "Sum",
  20664. category: "reduction",
  20665. inputs: [{
  20666. start: 0,
  20667. name: "x",
  20668. type: "tensor"
  20669. }, {
  20670. start: 1,
  20671. name: "axis",
  20672. type: "number[]"
  20673. }],
  20674. attrs: [{
  20675. tfName: "keep_dims",
  20676. name: "keepDims",
  20677. type: "bool"
  20678. }]
  20679. }, {
  20680. tfOpName: "All",
  20681. category: "reduction",
  20682. inputs: [{
  20683. start: 0,
  20684. name: "x",
  20685. type: "tensor"
  20686. }, {
  20687. start: 1,
  20688. name: "axis",
  20689. type: "number[]"
  20690. }],
  20691. attrs: [{
  20692. tfName: "keep_dims",
  20693. name: "keepDims",
  20694. type: "bool"
  20695. }]
  20696. }, {
  20697. tfOpName: "Any",
  20698. category: "reduction",
  20699. inputs: [{
  20700. start: 0,
  20701. name: "x",
  20702. type: "tensor"
  20703. }, {
  20704. start: 1,
  20705. name: "axis",
  20706. type: "number[]"
  20707. }],
  20708. attrs: [{
  20709. tfName: "keep_dims",
  20710. name: "keepDims",
  20711. type: "bool"
  20712. }]
  20713. }, {
  20714. tfOpName: "ArgMax",
  20715. category: "reduction",
  20716. inputs: [{
  20717. start: 0,
  20718. name: "x",
  20719. type: "tensor"
  20720. }, {
  20721. start: 1,
  20722. name: "axis",
  20723. type: "number"
  20724. }]
  20725. }, {
  20726. tfOpName: "ArgMin",
  20727. category: "reduction",
  20728. inputs: [{
  20729. start: 0,
  20730. name: "x",
  20731. type: "tensor"
  20732. }, {
  20733. start: 1,
  20734. name: "axis",
  20735. type: "number"
  20736. }]
  20737. }, {
  20738. tfOpName: "Prod",
  20739. category: "reduction",
  20740. inputs: [{
  20741. start: 0,
  20742. name: "x",
  20743. type: "tensor"
  20744. }, {
  20745. start: 1,
  20746. name: "axis",
  20747. type: "number[]"
  20748. }],
  20749. attrs: [{
  20750. tfName: "keep_dims",
  20751. name: "keepDims",
  20752. type: "bool"
  20753. }]
  20754. }],
  20755. reduction = Object.freeze({
  20756. json: json$12
  20757. }),
  20758. json$13 = [{
  20759. tfOpName: "ConcatV2",
  20760. category: "slice_join",
  20761. inputs: [{
  20762. start: 0,
  20763. end: -1,
  20764. name: "tensors",
  20765. type: "tensors"
  20766. }, {
  20767. start: -1,
  20768. name: "axis",
  20769. type: "number"
  20770. }]
  20771. }, {
  20772. tfOpName: "Concat",
  20773. category: "slice_join",
  20774. inputs: [{
  20775. start: 1,
  20776. end: 0,
  20777. name: "tensors",
  20778. type: "tensors"
  20779. }, {
  20780. start: 0,
  20781. name: "axis",
  20782. type: "number"
  20783. }]
  20784. }, {
  20785. tfOpName: "GatherV2",
  20786. category: "slice_join",
  20787. inputs: [{
  20788. start: 0,
  20789. name: "x",
  20790. type: "tensor"
  20791. }, {
  20792. start: 1,
  20793. name: "indices",
  20794. type: "tensor"
  20795. }, {
  20796. start: 2,
  20797. name: "axis",
  20798. type: "number",
  20799. defaultValue: 0
  20800. }]
  20801. }, {
  20802. tfOpName: "Gather",
  20803. category: "slice_join",
  20804. inputs: [{
  20805. start: 0,
  20806. name: "x",
  20807. type: "tensor"
  20808. }, {
  20809. start: 1,
  20810. name: "indices",
  20811. type: "tensor"
  20812. }],
  20813. attrs: [{
  20814. tfName: "axis",
  20815. name: "axis",
  20816. type: "number",
  20817. defaultValue: 0
  20818. }, {
  20819. tfName: "validate_indices",
  20820. name: "validateIndices",
  20821. type: "bool",
  20822. notSupported: !0
  20823. }]
  20824. }, {
  20825. tfOpName: "Reverse",
  20826. category: "slice_join",
  20827. inputs: [{
  20828. start: 0,
  20829. name: "x",
  20830. type: "tensor"
  20831. }, {
  20832. start: 1,
  20833. name: "dims",
  20834. type: "bool",
  20835. notSupported: !0
  20836. }]
  20837. }, {
  20838. tfOpName: "ReverseV2",
  20839. category: "slice_join",
  20840. inputs: [{
  20841. start: 0,
  20842. name: "x",
  20843. type: "tensor"
  20844. }, {
  20845. start: 1,
  20846. name: "axis",
  20847. type: "number[]"
  20848. }]
  20849. }, {
  20850. tfOpName: "Slice",
  20851. category: "slice_join",
  20852. inputs: [{
  20853. start: 0,
  20854. name: "x",
  20855. type: "tensor"
  20856. }, {
  20857. start: 1,
  20858. name: "begin",
  20859. type: "number[]"
  20860. }, {
  20861. start: 2,
  20862. name: "size",
  20863. type: "number[]"
  20864. }]
  20865. }, {
  20866. tfOpName: "StridedSlice",
  20867. category: "slice_join",
  20868. inputs: [{
  20869. start: 0,
  20870. name: "x",
  20871. type: "tensor"
  20872. }, {
  20873. start: 1,
  20874. name: "begin",
  20875. type: "number[]"
  20876. }, {
  20877. start: 2,
  20878. name: "end",
  20879. type: "number[]"
  20880. }, {
  20881. start: 3,
  20882. name: "strides",
  20883. type: "number[]"
  20884. }],
  20885. attrs: [{
  20886. tfName: "begin_mask",
  20887. name: "beginMask",
  20888. type: "number",
  20889. defaultValue: 0
  20890. }, {
  20891. tfName: "end_mask",
  20892. name: "endMask",
  20893. type: "number",
  20894. defaultValue: 0
  20895. }, {
  20896. tfName: "new_axis_mask",
  20897. name: "newAxisMask",
  20898. type: "number",
  20899. defaultValue: 0
  20900. }, {
  20901. tfName: "ellipsis_mask",
  20902. name: "ellipsisMask",
  20903. type: "number",
  20904. defaultValue: 0
  20905. }, {
  20906. tfName: "shrink_axis_mask",
  20907. name: "shrinkAxisMask",
  20908. type: "number",
  20909. defaultValue: 0
  20910. }]
  20911. }, {
  20912. tfOpName: "Pack",
  20913. category: "slice_join",
  20914. inputs: [{
  20915. start: 0,
  20916. end: 0,
  20917. name: "tensors",
  20918. type: "tensors"
  20919. }],
  20920. attrs: [{
  20921. tfName: "axis",
  20922. name: "axis",
  20923. type: "number",
  20924. defaultValue: 0
  20925. }]
  20926. }, {
  20927. tfOpName: "Unpack",
  20928. category: "slice_join",
  20929. inputs: [{
  20930. start: 0,
  20931. name: "tensor",
  20932. type: "tensor"
  20933. }],
  20934. attrs: [{
  20935. tfName: "axis",
  20936. name: "axis",
  20937. type: "number",
  20938. defaultValue: 0
  20939. }, {
  20940. tfName: "num",
  20941. name: "num",
  20942. type: "number",
  20943. defaultValue: 0,
  20944. notSupported: !0
  20945. }]
  20946. }, {
  20947. tfOpName: "Tile",
  20948. category: "slice_join",
  20949. inputs: [{
  20950. start: 0,
  20951. name: "x",
  20952. type: "tensor"
  20953. }, {
  20954. start: 1,
  20955. name: "reps",
  20956. type: "number[]"
  20957. }]
  20958. }, {
  20959. tfOpName: "Split",
  20960. category: "slice_join",
  20961. inputs: [{
  20962. start: 0,
  20963. name: "axis",
  20964. type: "number",
  20965. defaultValue: 0
  20966. }, {
  20967. start: 1,
  20968. name: "x",
  20969. type: "tensor"
  20970. }],
  20971. attrs: [{
  20972. tfName: "num_split",
  20973. name: "numOrSizeSplits",
  20974. type: "number",
  20975. defaultValue: 1
  20976. }]
  20977. }, {
  20978. tfOpName: "SplitV",
  20979. category: "slice_join",
  20980. inputs: [{
  20981. start: 0,
  20982. name: "x",
  20983. type: "tensor"
  20984. }, {
  20985. start: 1,
  20986. name: "numOrSizeSplits",
  20987. type: "number[]"
  20988. }, {
  20989. start: 2,
  20990. name: "axis",
  20991. type: "number",
  20992. defaultValue: 0
  20993. }]
  20994. }, {
  20995. tfOpName: "ScatterNd",
  20996. category: "slice_join",
  20997. inputs: [{
  20998. start: 0,
  20999. name: "indices",
  21000. type: "tensor"
  21001. }, {
  21002. start: 1,
  21003. name: "values",
  21004. type: "tensor"
  21005. }, {
  21006. start: 2,
  21007. name: "shape",
  21008. type: "number[]"
  21009. }]
  21010. }, {
  21011. tfOpName: "GatherNd",
  21012. category: "slice_join",
  21013. inputs: [{
  21014. start: 0,
  21015. name: "x",
  21016. type: "tensor"
  21017. }, {
  21018. start: 1,
  21019. name: "indices",
  21020. type: "tensor"
  21021. }]
  21022. }, {
  21023. tfOpName: "SparseToDense",
  21024. category: "slice_join",
  21025. inputs: [{
  21026. start: 0,
  21027. name: "sparseIndices",
  21028. type: "tensor"
  21029. }, {
  21030. start: 1,
  21031. name: "outputShape",
  21032. type: "number[]"
  21033. }, {
  21034. start: 2,
  21035. name: "sparseValues",
  21036. type: "tensor"
  21037. }, {
  21038. start: 3,
  21039. name: "defaultValue",
  21040. type: "tensor"
  21041. }],
  21042. attrs: [{
  21043. tfName: "validate_indices",
  21044. name: "validateIndices",
  21045. type: "bool",
  21046. defaultValue: !1,
  21047. notSupported: !0
  21048. }]
  21049. }],
  21050. sliceJoin = Object.freeze({
  21051. json: json$13
  21052. }),
  21053. json$14 = [{
  21054. tfOpName: "FFT",
  21055. category: "spectral",
  21056. inputs: [{
  21057. start: 0,
  21058. name: "x",
  21059. type: "tensor"
  21060. }]
  21061. }, {
  21062. tfOpName: "IFFT",
  21063. category: "spectral",
  21064. inputs: [{
  21065. start: 0,
  21066. name: "x",
  21067. type: "tensor"
  21068. }]
  21069. }, {
  21070. tfOpName: "RFFT",
  21071. category: "spectral",
  21072. inputs: [{
  21073. start: 0,
  21074. name: "x",
  21075. type: "tensor"
  21076. }, {
  21077. start: 1,
  21078. name: "fft_length",
  21079. type: "number",
  21080. notSupported: !0
  21081. }]
  21082. }, {
  21083. tfOpName: "IRFFT",
  21084. category: "spectral",
  21085. inputs: [{
  21086. start: 0,
  21087. name: "x",
  21088. type: "tensor"
  21089. }, {
  21090. start: 1,
  21091. name: "fft_length",
  21092. type: "number",
  21093. notSupported: !0
  21094. }]
  21095. }],
  21096. spectral = Object.freeze({
  21097. json: json$14
  21098. }),
  21099. json$15 = [{
  21100. tfOpName: "Cast",
  21101. category: "transformation",
  21102. inputs: [{
  21103. start: 0,
  21104. name: "x",
  21105. type: "tensor"
  21106. }],
  21107. attrs: [{
  21108. tfName: "SrcT",
  21109. name: "sdtype",
  21110. type: "dtype",
  21111. notSupported: !0
  21112. }, {
  21113. tfName: "DstT",
  21114. name: "dtype",
  21115. type: "dtype"
  21116. }]
  21117. }, {
  21118. tfOpName: "ExpandDims",
  21119. category: "transformation",
  21120. inputs: [{
  21121. start: 0,
  21122. name: "x",
  21123. type: "tensor"
  21124. }, {
  21125. start: 1,
  21126. name: "axis",
  21127. type: "number"
  21128. }]
  21129. }, {
  21130. tfOpName: "Pad",
  21131. category: "transformation",
  21132. inputs: [{
  21133. start: 0,
  21134. name: "x",
  21135. type: "tensor"
  21136. }, {
  21137. start: 1,
  21138. name: "padding",
  21139. type: "number[]"
  21140. }],
  21141. attrs: [{
  21142. tfName: "constant_value",
  21143. name: "constantValue",
  21144. type: "number",
  21145. defaultValue: 0
  21146. }]
  21147. }, {
  21148. tfOpName: "PadV2",
  21149. category: "transformation",
  21150. inputs: [{
  21151. start: 0,
  21152. name: "x",
  21153. type: "tensor"
  21154. }, {
  21155. start: 1,
  21156. name: "padding",
  21157. type: "number[]"
  21158. }, {
  21159. start: 2,
  21160. name: "constantValue",
  21161. type: "number",
  21162. defaultValue: 0
  21163. }]
  21164. }, {
  21165. tfOpName: "Reshape",
  21166. category: "transformation",
  21167. inputs: [{
  21168. start: 0,
  21169. name: "x",
  21170. type: "tensor"
  21171. }, {
  21172. start: 1,
  21173. name: "shape",
  21174. type: "number[]"
  21175. }]
  21176. }, {
  21177. tfOpName: "Squeeze",
  21178. category: "transformation",
  21179. inputs: [{
  21180. start: 0,
  21181. name: "x",
  21182. type: "tensor"
  21183. }],
  21184. attrs: [{
  21185. tfName: "axis",
  21186. tfDeprecatedName: "squeeze_dims",
  21187. name: "axis",
  21188. type: "number[]"
  21189. }]
  21190. }, {
  21191. tfOpName: "SpaceToBatchND",
  21192. category: "transformation",
  21193. inputs: [{
  21194. start: 0,
  21195. name: "x",
  21196. type: "tensor"
  21197. }, {
  21198. start: 1,
  21199. name: "blockShape",
  21200. type: "number[]"
  21201. }, {
  21202. start: 2,
  21203. name: "paddings",
  21204. type: "number[]"
  21205. }]
  21206. }, {
  21207. tfOpName: "BatchToSpaceND",
  21208. category: "transformation",
  21209. inputs: [{
  21210. start: 0,
  21211. name: "x",
  21212. type: "tensor"
  21213. }, {
  21214. start: 1,
  21215. name: "blockShape",
  21216. type: "number[]"
  21217. }, {
  21218. start: 2,
  21219. name: "crops",
  21220. type: "number[]"
  21221. }]
  21222. }, {
  21223. tfOpName: "DepthToSpace",
  21224. category: "transformation",
  21225. inputs: [{
  21226. start: 0,
  21227. name: "x",
  21228. type: "tensor"
  21229. }],
  21230. attrs: [{
  21231. tfName: "block_size",
  21232. name: "blockSize",
  21233. type: "number"
  21234. }, {
  21235. tfName: "data_format",
  21236. name: "dataFormat",
  21237. type: "string"
  21238. }]
  21239. }],
  21240. transformation = Object.freeze({
  21241. json: json$15
  21242. }),
  21243. OperationMapper = function () {
  21244. function e() {
  21245. var e = [arithmetic, basicMath, control, convolution, creation, dynamic, evaluation, logical, image$1, graph, matrices, normalization, reduction, sliceJoin, spectral, transformation],
  21246. t = [].concat.apply([], e.map(function (e) {
  21247. return e.json;
  21248. }));
  21249. this.opMappers = t.reduce(function (e, t) {
  21250. return e[t.tfOpName] = t, e;
  21251. }, {});
  21252. }
  21253. return Object.defineProperty(e, "Instance", {
  21254. get: function () {
  21255. return this._instance || (this._instance = new this());
  21256. },
  21257. enumerable: !0,
  21258. configurable: !0
  21259. }), e.prototype.transformGraph = function (e) {
  21260. var t = this,
  21261. a = [],
  21262. r = [],
  21263. n = e.node.reduce(function (e, n) {
  21264. return e[n.name] = t.mapNode(n), "Placeholder" === n.op && a.push(e[n.name]), "Const" === n.op && r.push(e[n.name]), e;
  21265. }, {}),
  21266. s = [],
  21267. o = [],
  21268. p = Object.keys(n);
  21269. return p.forEach(function (e) {
  21270. var t = n[e];
  21271. t.inputNames.forEach(function (e) {
  21272. var a = getNodeNameAndIndex(e)[0];
  21273. t.inputs.push(n[a]), n[a].children.push(t);
  21274. }), 0 === t.inputs.length && s.push(t);
  21275. }), p.forEach(function (e) {
  21276. var t = n[e];
  21277. 0 === t.children.length && o.push(t);
  21278. }), {
  21279. nodes: n,
  21280. inputs: s,
  21281. outputs: o,
  21282. weights: r,
  21283. placeholders: a
  21284. };
  21285. }, e.prototype.mapNode = function (e) {
  21286. var t = getRegisteredOp(e.op) || this.opMappers[e.op] || {};
  21287. null == e.attr && (e.attr = {});
  21288. var a = {
  21289. name: e.name,
  21290. op: e.op,
  21291. category: t.category,
  21292. inputNames: (e.input || []).map(function (e) {
  21293. return e.startsWith("^") ? e.substr(1) : e;
  21294. }),
  21295. inputs: [],
  21296. children: [],
  21297. inputParams: {},
  21298. attrParams: {},
  21299. rawAttrs: e.attr
  21300. };
  21301. return null != t.inputs && (a.inputParams = t.inputs.reduce(function (e, t) {
  21302. return e[t.name] = {
  21303. type: t.type,
  21304. inputIndexStart: t.start,
  21305. inputIndexEnd: t.end
  21306. }, e;
  21307. }, {})), null != t.attrs && (a.attrParams = t.attrs.reduce(function (t, a) {
  21308. var r = a.type,
  21309. n = void 0;
  21310. switch (a.type) {
  21311. case "string":
  21312. void 0 === (n = getStringParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getStringParam(e.attr, a.tfDeprecatedName, a.defaultValue));
  21313. break;
  21314. case "string[]":
  21315. void 0 === (n = getStringArrayParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getStringArrayParam(e.attr, a.tfDeprecatedName, a.defaultValue));
  21316. break;
  21317. case "number":
  21318. void 0 === (n = getNumberParam(e.attr, a.tfName, a.defaultValue || 0)) && a.tfDeprecatedName && (n = getNumberParam(e.attr, a.tfDeprecatedName, a.defaultValue));
  21319. break;
  21320. case "number[]":
  21321. void 0 === (n = getNumericArrayParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getNumericArrayParam(e.attr, a.tfDeprecatedName, a.defaultValue));
  21322. break;
  21323. case "bool":
  21324. void 0 === (n = getBoolParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getBoolParam(e.attr, a.tfDeprecatedName, a.defaultValue));
  21325. break;
  21326. case "bool[]":
  21327. void 0 === (n = getBoolArrayParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getBoolArrayParam(e.attr, a.tfDeprecatedName, a.defaultValue));
  21328. break;
  21329. case "shape":
  21330. void 0 === (n = getTensorShapeParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getTensorShapeParam(e.attr, a.tfDeprecatedName, a.defaultValue));
  21331. break;
  21332. case "shape[]":
  21333. void 0 === (n = getTensorShapeArrayParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getTensorShapeArrayParam(e.attr, a.tfDeprecatedName, a.defaultValue));
  21334. break;
  21335. case "dtype":
  21336. void 0 === (n = getDtypeParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getDtypeParam(e.attr, a.tfDeprecatedName, a.defaultValue));
  21337. break;
  21338. case "dtype[]":
  21339. void 0 === (n = getDtypeArrayParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getDtypeArrayParam(e.attr, a.tfDeprecatedName, a.defaultValue));
  21340. break;
  21341. case "tensor":
  21342. case "tensors":
  21343. break;
  21344. default:
  21345. throw new Error("Unsupported param type: " + a.type + " for op: " + e.op);
  21346. }
  21347. return t[a.name] = {
  21348. value: n,
  21349. type: r
  21350. }, t;
  21351. }, {})), a;
  21352. }, e;
  21353. }();
  21354. function decodeBase64(e) {
  21355. var t = (0, _tfjsCore.env)().global;
  21356. if (void 0 !== t.atob) return t.atob(e);
  21357. if ("undefined" != typeof Buffer) return new Buffer(e, "base64").toString();
  21358. throw new Error("Unable to decode base64 in this environment. Missing built-in atob() or Buffer()");
  21359. }
  21360. function parseStringParam(e, t) {
  21361. var a = Array.isArray(e) ? String.fromCharCode.apply(null, e) : decodeBase64(e);
  21362. return t ? a : a.toLowerCase();
  21363. }
  21364. function getStringParam(e, t, a, r) {
  21365. void 0 === r && (r = !1);
  21366. var n = e[t];
  21367. return null != n ? parseStringParam(n.s, r) : a;
  21368. }
  21369. function getBoolParam(e, t, a) {
  21370. var r = e[t];
  21371. return r ? r.b : a;
  21372. }
  21373. function getNumberParam(e, t, a) {
  21374. var r = e[t] || {},
  21375. n = null != r.i ? r.i : null != r.f ? r.f : a;
  21376. return "number" == typeof n ? n : parseInt(n, 10);
  21377. }
  21378. function parseDtypeParam(e) {
  21379. switch ("string" == typeof e && (e = DataType[e]), e) {
  21380. case DataType.DT_FLOAT:
  21381. return "float32";
  21382. case DataType.DT_INT32:
  21383. case DataType.DT_INT64:
  21384. return "int32";
  21385. case DataType.DT_BOOL:
  21386. return "bool";
  21387. case DataType.DT_DOUBLE:
  21388. return "float32";
  21389. case DataType.DT_STRING:
  21390. return "string";
  21391. default:
  21392. return null;
  21393. }
  21394. }
  21395. function getDtypeParam(e, t, a) {
  21396. var r = e[t];
  21397. return r && r.type ? parseDtypeParam(r.type) : a;
  21398. }
  21399. function getDtypeArrayParam(e, t, a) {
  21400. var r = e[t];
  21401. return r && r.list && r.list.type ? r.list.type.map(function (e) {
  21402. return parseDtypeParam(e);
  21403. }) : a;
  21404. }
  21405. function parseTensorShapeParam(e) {
  21406. if (!e.unknownRank) return null != e.dim ? e.dim.map(function (e) {
  21407. return "number" == typeof e.size ? e.size : parseInt(e.size, 10);
  21408. }) : [];
  21409. }
  21410. function getTensorShapeParam(e, t, a) {
  21411. var r = e[t];
  21412. return r && r.shape ? parseTensorShapeParam(r.shape) : a;
  21413. }
  21414. function getNumericArrayParam(e, t, a) {
  21415. var r = e[t];
  21416. return r ? ((r.list.f && r.list.f.length ? r.list.f : r.list.i) || []).map(function (e) {
  21417. return "number" == typeof e ? e : parseInt(e, 10);
  21418. }) : a;
  21419. }
  21420. function getStringArrayParam(e, t, a, r) {
  21421. void 0 === r && (r = !1);
  21422. var n = e[t];
  21423. return n && n.list && n.list.s ? n.list.s.map(function (e) {
  21424. return parseStringParam(e, r);
  21425. }) : a;
  21426. }
  21427. function getTensorShapeArrayParam(e, t, a) {
  21428. var r = e[t];
  21429. return r && r.list && r.list.shape ? r.list.shape.map(function (e) {
  21430. return parseTensorShapeParam(e);
  21431. }) : a;
  21432. }
  21433. function getBoolArrayParam(e, t, a) {
  21434. var r = e[t];
  21435. return r && r.list && r.list.b ? r.list.b : a;
  21436. }
  21437. var NodeValueImpl = function () {
  21438. function e(e, t, a) {
  21439. var r = this;
  21440. this.node = e, this.tensorMap = t, this.context = a, this.inputs = [], this.attrs = {}, this.inputs = e.inputNames.map(function (e) {
  21441. return r.getInput(e);
  21442. }), null != e.rawAttrs && (this.attrs = Object.keys(e.rawAttrs).reduce(function (e, t) {
  21443. return e[t] = r.getAttr(t), e;
  21444. }, {}));
  21445. }
  21446. return e.prototype.getInput = function (e) {
  21447. return getTensor(e, this.tensorMap, this.context);
  21448. }, e.prototype.getAttr = function (e, t) {
  21449. var a = this.node.rawAttrs[e];
  21450. if (null != a.tensor) return getTensor(e, this.tensorMap, this.context);
  21451. if (null != a.i || null != a.f) return getNumberParam(this.node.rawAttrs, e, t);
  21452. if (null != a.s) return getStringParam(this.node.rawAttrs, e, t);
  21453. if (null != a.b) return getBoolParam(this.node.rawAttrs, e, t);
  21454. if (null != a.shape) return getTensorShapeParam(this.node.rawAttrs, e, t);
  21455. if (null != a.type) return getDtypeParam(this.node.rawAttrs, e, t);
  21456. if (null != a.list) {
  21457. if (null != a.list.i || null != a.list.f) return getNumericArrayParam(this.node.rawAttrs, e, t);
  21458. if (null != a.list.s) return getStringArrayParam(this.node.rawAttrs, e, t);
  21459. if (null != a.list.shape) return getTensorShapeArrayParam(this.node.rawAttrs, e, t);
  21460. if (null != a.list.b) return getBoolArrayParam(this.node.rawAttrs, e, t);
  21461. if (null != a.list.type) return getDtypeArrayParam(this.node.rawAttrs, e, t);
  21462. }
  21463. return t;
  21464. }, e;
  21465. }(),
  21466. executeOp = function (e, t, a) {
  21467. switch (e.op) {
  21468. case "BiasAdd":
  21469. case "AddV2":
  21470. case "Add":
  21471. return [(0, _tfjsCore.add)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21472. case "AddN":
  21473. return [(0, _tfjsCore.addN)(getParamValue("tensors", e, t, a))];
  21474. case "FloorMod":
  21475. case "Mod":
  21476. return [(0, _tfjsCore.mod)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21477. case "Mul":
  21478. return [(0, _tfjsCore.mul)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21479. case "RealDiv":
  21480. case "Div":
  21481. return [(0, _tfjsCore.div)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21482. case "FloorDiv":
  21483. return [(0, _tfjsCore.floorDiv)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21484. case "Sub":
  21485. return [(0, _tfjsCore.sub)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21486. case "Minimum":
  21487. return [(0, _tfjsCore.minimum)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21488. case "Maximum":
  21489. return [(0, _tfjsCore.maximum)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21490. case "Pow":
  21491. return [(0, _tfjsCore.pow)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21492. case "SquaredDifference":
  21493. return [(0, _tfjsCore.squaredDifference)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21494. default:
  21495. throw TypeError("Node type " + e.op + " is not implemented");
  21496. }
  21497. },
  21498. executeOp$1 = function (e, t, a) {
  21499. switch (e.op) {
  21500. case "Abs":
  21501. case "ComplexAbs":
  21502. return [(0, _tfjsCore.abs)(getParamValue("x", e, t, a))];
  21503. case "Acos":
  21504. return [(0, _tfjsCore.acos)(getParamValue("x", e, t, a))];
  21505. case "Acosh":
  21506. return [(0, _tfjsCore.acosh)(getParamValue("x", e, t, a))];
  21507. case "Asin":
  21508. return [(0, _tfjsCore.asin)(getParamValue("x", e, t, a))];
  21509. case "Asinh":
  21510. return [(0, _tfjsCore.asinh)(getParamValue("x", e, t, a))];
  21511. case "Atan":
  21512. return [(0, _tfjsCore.atan)(getParamValue("x", e, t, a))];
  21513. case "Atan2":
  21514. return [(0, _tfjsCore.atan2)(getParamValue("x", e, t, a), getParamValue("y", e, t, a))];
  21515. case "Atanh":
  21516. return [(0, _tfjsCore.atanh)(getParamValue("x", e, t, a))];
  21517. case "Ceil":
  21518. return [(0, _tfjsCore.ceil)(getParamValue("x", e, t, a))];
  21519. case "Complex":
  21520. return [(0, _tfjsCore.complex)(getParamValue("real", e, t, a), getParamValue("imag", e, t, a))];
  21521. case "Cos":
  21522. return [(0, _tfjsCore.cos)(getParamValue("x", e, t, a))];
  21523. case "Cosh":
  21524. return [(0, _tfjsCore.cosh)(getParamValue("x", e, t, a))];
  21525. case "Elu":
  21526. return [(0, _tfjsCore.elu)(getParamValue("x", e, t, a))];
  21527. case "Erf":
  21528. return [(0, _tfjsCore.erf)(getParamValue("x", e, t, a))];
  21529. case "Exp":
  21530. return [(0, _tfjsCore.exp)(getParamValue("x", e, t, a))];
  21531. case "Expm1":
  21532. return [(0, _tfjsCore.expm1)(getParamValue("x", e, t, a))];
  21533. case "Floor":
  21534. return [(0, _tfjsCore.floor)(getParamValue("x", e, t, a))];
  21535. case "Log":
  21536. return [(0, _tfjsCore.log)(getParamValue("x", e, t, a))];
  21537. case "Log1p":
  21538. return [(0, _tfjsCore.log1p)(getParamValue("x", e, t, a))];
  21539. case "Imag":
  21540. return [(0, _tfjsCore.imag)(getParamValue("x", e, t, a))];
  21541. case "Neg":
  21542. return [(0, _tfjsCore.neg)(getParamValue("x", e, t, a))];
  21543. case "Reciprocal":
  21544. return [(0, _tfjsCore.reciprocal)(getParamValue("x", e, t, a))];
  21545. case "Real":
  21546. return [(0, _tfjsCore.real)(getParamValue("x", e, t, a))];
  21547. case "Relu":
  21548. return [(0, _tfjsCore.relu)(getParamValue("x", e, t, a))];
  21549. case "Round":
  21550. return [(0, _tfjsCore.round)(getParamValue("x", e, t, a))];
  21551. case "Selu":
  21552. return [(0, _tfjsCore.selu)(getParamValue("x", e, t, a))];
  21553. case "Sigmoid":
  21554. return [(0, _tfjsCore.sigmoid)(getParamValue("x", e, t, a))];
  21555. case "Sin":
  21556. return [(0, _tfjsCore.sin)(getParamValue("x", e, t, a))];
  21557. case "Sign":
  21558. return [(0, _tfjsCore.sign)(getParamValue("x", e, t, a))];
  21559. case "Sinh":
  21560. return [(0, _tfjsCore.sinh)(getParamValue("x", e, t, a))];
  21561. case "Softplus":
  21562. return [(0, _tfjsCore.softplus)(getParamValue("x", e, t, a))];
  21563. case "Sqrt":
  21564. return [(0, _tfjsCore.sqrt)(getParamValue("x", e, t, a))];
  21565. case "Square":
  21566. return [(0, _tfjsCore.square)(getParamValue("x", e, t, a))];
  21567. case "Tanh":
  21568. return [(0, _tfjsCore.tanh)(getParamValue("x", e, t, a))];
  21569. case "Tan":
  21570. return [(0, _tfjsCore.tan)(getParamValue("x", e, t, a))];
  21571. case "Relu6":
  21572. case "ClipByValue":
  21573. return [(0, _tfjsCore.clipByValue)(getParamValue("x", e, t, a), getParamValue("clipValueMin", e, t, a), getParamValue("clipValueMax", e, t, a))];
  21574. case "Rsqrt":
  21575. return [(0, _tfjsCore.rsqrt)(getTensor(e.inputNames[0], t, a))];
  21576. case "Prod":
  21577. return [(0, _tfjsCore.prod)(getParamValue("x", e, t, a), getParamValue("axes", e, t, a))];
  21578. case "LeakyRelu":
  21579. return [(0, _tfjsCore.leakyRelu)(getParamValue("x", e, t, a), getParamValue("alpha", e, t, a))];
  21580. default:
  21581. throw TypeError("Node type " + e.op + " is not implemented");
  21582. }
  21583. },
  21584. TensorArray = function () {
  21585. function e(t, a, r, n, s, o, p) {
  21586. this.name = t, this.dtype = a, this.maxSize = r, this.elementShape = n, this.identicalElementShapes = s, this.dynamicSize = o, this.clearAfterRead = p, this.tensors = [], this.closed_ = !1, this.id = e.nextId++;
  21587. }
  21588. return Object.defineProperty(e.prototype, "closed", {
  21589. get: function () {
  21590. return this.closed_;
  21591. },
  21592. enumerable: !0,
  21593. configurable: !0
  21594. }), e.prototype.clearAndClose = function () {
  21595. this.tensors.forEach(function (e) {
  21596. return e.tensor.dispose();
  21597. }), this.tensors = [], this.closed_ = !0;
  21598. }, e.prototype.size = function () {
  21599. return this.tensors.length;
  21600. }, e.prototype.read = function (e) {
  21601. if (this.closed_) throw new Error("TensorArray " + this.name + " has already been closed.");
  21602. if (e < 0 || e >= this.tensors.length) throw new Error("Tried to read from index " + e + ", but array size is: " + this.tensors.length);
  21603. var t = this.tensors[e];
  21604. if (t.cleared) throw new Error("TensorArray " + this.name + ": Could not read index " + e + " twice because it was cleared after a previous read (perhaps try setting clear_after_read = false?).");
  21605. return this.clearAfterRead && (t.cleared = !0), t.read = !0, t.tensor;
  21606. }, e.prototype.readMany = function (e) {
  21607. var t = this;
  21608. return e.map(function (e) {
  21609. return t.read(e);
  21610. });
  21611. }, e.prototype.write = function (e, t) {
  21612. if (this.closed_) throw new Error("TensorArray " + this.name + " has already been closed.");
  21613. if (e < 0 || !this.dynamicSize && e >= this.maxSize) throw new Error("Tried to write to index " + e + ", but array is not resizeable and size is: " + this.maxSize);
  21614. var a = this.tensors[e] || {};
  21615. if (t.dtype !== this.dtype) throw new Error("TensorArray " + this.name + ": Could not write to TensorArray index " + e + ",\n because the value dtype is " + t.dtype + ", but TensorArray dtype is " + this.dtype + ".");
  21616. if (0 !== this.size() || null != this.elementShape && 0 !== this.elementShape.length || (this.elementShape = t.shape), this.assertShapesMatchAllowUndefinedSize(this.elementShape, t.shape, "TensorArray " + this.name + ": Could not write to TensorArray index " + e + "."), a && a.read) throw new Error("TensorArray " + this.name + ": Could not write to TensorArray index " + e + ", because it has already been read.");
  21617. if (a && a.written) throw new Error("TensorArray " + this.name + ": Could not write to TensorArray index " + e + ", because it has already been written.");
  21618. a.tensor = t, a.written = !0, this.tensors[e] = a;
  21619. }, e.prototype.writeMany = function (e, t) {
  21620. var a = this;
  21621. if (e.length !== t.length) throw new Error("TensorArray " + this.name + ": could not write multiple tensors,because the index size: " + e.length + " is not the same as tensors size: " + t.length + ".");
  21622. e.forEach(function (e, r) {
  21623. return a.write(e, t[r]);
  21624. });
  21625. }, e.prototype.gather = function (e, t) {
  21626. if (t && t !== this.dtype) throw new Error("TensorArray dtype is " + this.dtype + " but gather requested dtype " + t);
  21627. if (!e) {
  21628. e = [];
  21629. for (var a = 0; a < this.size(); a++) e.push(a);
  21630. }
  21631. if (0 === e.length) return (0, _tfjsCore.tensor)([], [0].concat(this.elementShape));
  21632. var r = this.readMany(e);
  21633. return this.assertShapesMatchAllowUndefinedSize(this.elementShape, r[0].shape, "TensorArray shape mismatch: "), (0, _tfjsCore.stack)(r, 0);
  21634. }, e.prototype.concat = function (e) {
  21635. if (e && e !== this.dtype) throw new Error("TensorArray dtype is " + this.dtype + " but concat requested dtype " + e);
  21636. if (0 === this.size()) return (0, _tfjsCore.tensor)([], [0].concat(this.elementShape));
  21637. for (var t = [], a = 0; a < this.size(); a++) t.push(a);
  21638. var r = this.readMany(t);
  21639. return this.assertShapesMatchAllowUndefinedSize(this.elementShape, r[0].shape, "TensorArray shape mismatch: tensor array shape (" + this.elementShape + ") vs first tensor shape (" + r[0].shape + ")"), (0, _tfjsCore.concat)(r, 0);
  21640. }, e.prototype.scatter = function (e, t) {
  21641. if (t.dtype !== this.dtype) throw new Error("TensorArray dtype is " + this.dtype + " but tensor has dtype " + t.dtype);
  21642. if (e.length !== t.shape[0]) throw new Error("Expected len(indices) == tensor.shape[0], but saw: " + e.length + " vs. " + t.shape[0]);
  21643. var a = Math.max.apply(Math, e);
  21644. if (!this.dynamicSize && a >= this.maxSize) throw new Error("Max index must be < array size (" + a + " vs. " + this.maxSize + ")");
  21645. this.writeMany(e, (0, _tfjsCore.unstack)(t, 0));
  21646. }, e.prototype.split = function (e, t) {
  21647. var a = this;
  21648. if (t.dtype !== this.dtype) throw new Error("TensorArray dtype is " + this.dtype + " but tensor has dtype " + t.dtype);
  21649. var r = 0,
  21650. n = e.map(function (e) {
  21651. return r += e;
  21652. });
  21653. if (r !== t.shape[0]) throw new Error("Expected sum of lengths to be equal to\n tensor.shape[0], but sum of lengths is\n " + r + ", and tensor's shape is: " + t.shape);
  21654. if (!this.dynamicSize && e.length !== this.maxSize) throw new Error("TensorArray's size is not equal to the size of lengths (" + this.maxSize + " vs. " + e.length + "), and the TensorArray is not marked as dynamically resizeable");
  21655. var s = 0 === r ? 0 : t.size / r,
  21656. o = [];
  21657. (0, _tfjsCore.tidy)(function () {
  21658. t = t.reshape([1, r, s]);
  21659. for (var p = 0; p < e.length; ++p) {
  21660. var u = [0, 0 === p ? 0 : n[p - 1], 0],
  21661. i = [1, e[p], s];
  21662. o[p] = (0, _tfjsCore.slice)(t, u, i).reshape(a.elementShape);
  21663. }
  21664. return o;
  21665. });
  21666. for (var p = [], u = 0; u < e.length; u++) p[u] = u;
  21667. this.writeMany(p, o);
  21668. }, e.prototype.assertShapesMatchAllowUndefinedSize = function (e, t, a) {
  21669. void 0 === a && (a = ""), _tfjsCore.util.assert(this.shapesEqualAllowUndefinedSize(e, t), function () {
  21670. return a + " Shapes " + e + " and " + t + " must match";
  21671. });
  21672. }, e.prototype.shapesEqualAllowUndefinedSize = function (e, t) {
  21673. if (e.length !== t.length) return !1;
  21674. for (var a = 0; a < e.length; a++) if (-1 !== e[a] && -1 !== t[a] && e[a] !== t[a]) return !1;
  21675. return !0;
  21676. }, e.nextId = 0, e;
  21677. }();
  21678. function executeOp$2(e, t, a) {
  21679. return __awaiter(this, void 0, void 0, function () {
  21680. var r, n, s, o, p, u, i, m, l, c, d, y, f, g, h, N, x, V, P, b, T, O, S, v, _, w, A, D, E, I, C, M, k, z, j;
  21681. return __generator(this, function (F) {
  21682. switch (F.label) {
  21683. case 0:
  21684. switch (e.op) {
  21685. case "LoopCond":
  21686. return [3, 1];
  21687. case "Switch":
  21688. return [3, 2];
  21689. case "Merge":
  21690. return [3, 4];
  21691. case "Enter":
  21692. return [3, 5];
  21693. case "Exit":
  21694. return [3, 6];
  21695. case "NextIteration":
  21696. return [3, 7];
  21697. case "TensorArrayV3":
  21698. return [3, 8];
  21699. case "TensorArrayWriteV3":
  21700. return [3, 9];
  21701. case "TensorArrayReadV3":
  21702. return [3, 10];
  21703. case "TensorArrayGatherV3":
  21704. return [3, 11];
  21705. case "TensorArrayScatterV3":
  21706. return [3, 12];
  21707. case "TensorArrayConcatV3":
  21708. return [3, 13];
  21709. case "TensorArraySplitV3":
  21710. return [3, 14];
  21711. case "TensorArraySizeV3":
  21712. return [3, 15];
  21713. case "TensorArrayCloseV3":
  21714. return [3, 16];
  21715. }
  21716. return [3, 17];
  21717. case 1:
  21718. return [2, [getParamValue("pred", e, t, a).clone()]];
  21719. case 2:
  21720. return r = getParamValue("pred", e, t, a), n = getParamValue("data", e, t, a), [4, r.data()];
  21721. case 3:
  21722. return [2, F.sent()[0] ? [void 0, n.clone()] : [n.clone(), void 0]];
  21723. case 4:
  21724. return [2, (s = e.inputNames.find(function (e) {
  21725. return void 0 !== getTensor(e, t, a);
  21726. })) ? [getTensor(s, t, a).clone()] : void 0];
  21727. case 5:
  21728. return o = getParamValue("frameName", e, t, a), p = getParamValue("tensor", e, t, a), a.enterFrame(o), [2, [p.clone()]];
  21729. case 6:
  21730. return u = getParamValue("tensor", e, t, a), a.exitFrame(), [2, [u.clone()]];
  21731. case 7:
  21732. return i = getParamValue("tensor", e, t, a), a.nextIteration(), [2, [i.clone()]];
  21733. case 8:
  21734. return m = getParamValue("size", e, t, a), l = getParamValue("dtype", e, t, a), c = getParamValue("elementShape", e, t, a), d = getParamValue("dynamicSize", e, t, a), y = getParamValue("clearAfterRead", e, t, a), f = getParamValue("identicalElementShapes", e, t, a), g = getParamValue("name", e, t, a), h = new TensorArray(g, l, m, c, f, d, y), a.addTensorArray(h), [2, [(0, _tfjsCore.scalar)(h.id), (0, _tfjsCore.scalar)(1)]];
  21735. case 9:
  21736. return N = getParamValue("tensorArrayId", e, t, a), x = getParamValue("index", e, t, a), V = getParamValue("tensor", e, t, a), a.getTensorArray(N).write(x, V), [2, [(0, _tfjsCore.scalar)(1)]];
  21737. case 10:
  21738. return P = getParamValue("tensorArrayId", e, t, a), b = getParamValue("index", e, t, a), [2, [a.getTensorArray(P).read(b)]];
  21739. case 11:
  21740. return T = getParamValue("tensorArrayId", e, t, a), O = getParamValue("indices", e, t, a), S = getParamValue("dtype", e, t, a), [2, [a.getTensorArray(T).gather(O, S)]];
  21741. case 12:
  21742. return v = getParamValue("tensorArrayId", e, t, a), _ = getParamValue("indices", e, t, a), w = getParamValue("tensor", e, t, a), a.getTensorArray(v).scatter(_, w), [2, [(0, _tfjsCore.scalar)(1)]];
  21743. case 13:
  21744. return A = getParamValue("tensorArrayId", e, t, a), D = a.getTensorArray(A), E = getParamValue("dtype", e, t, a), [2, [D.concat(E)]];
  21745. case 14:
  21746. return I = getParamValue("tensorArrayId", e, t, a), C = getParamValue("tensor", e, t, a), M = getParamValue("lengths", e, t, a), a.getTensorArray(I).split(M, C), [2, [(0, _tfjsCore.scalar)(1)]];
  21747. case 15:
  21748. return k = getParamValue("tensorArrayId", e, t, a), z = a.getTensorArray(k), [2, [(0, _tfjsCore.scalar)(z.size(), "int32")]];
  21749. case 16:
  21750. return j = getParamValue("tensorArrayId", e, t, a), a.getTensorArray(j).clearAndClose(), [2, []];
  21751. case 17:
  21752. throw TypeError("Node type " + e.op + " is not implemented");
  21753. }
  21754. });
  21755. });
  21756. }
  21757. var executeOp$3 = function (e, t, a) {
  21758. var r, n;
  21759. switch (e.op) {
  21760. case "Conv1D":
  21761. var s = getParamValue("stride", e, t, a),
  21762. o = getParamValue("pad", e, t, a),
  21763. p = getParamValue("dataFormat", e, t, a).toUpperCase(),
  21764. u = getParamValue("dilation", e, t, a);
  21765. return [(0, _tfjsCore.conv1d)(getParamValue("x", e, t, a), getParamValue("filter", e, t, a), s, o, p, u)];
  21766. case "Conv2D":
  21767. s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a), p = getParamValue("dataFormat", e, t, a).toUpperCase();
  21768. var i = getParamValue("dilations", e, t, a);
  21769. return [(0, _tfjsCore.conv2d)(getParamValue("x", e, t, a), getParamValue("filter", e, t, a), [s[1], s[2]], o, p, [i[1], i[2]])];
  21770. case "_FusedConv2D":
  21771. var m = (r = getParamValue("fusedOps", e, t, a))[0],
  21772. l = r[1],
  21773. c = "biasadd" === m,
  21774. d = "prelu" === l,
  21775. y = "fusedbatchnorm" === m,
  21776. f = getParamValue("numArgs", e, t, a);
  21777. if (c) {
  21778. if (d && 2 !== f) throw new Error("Fused Conv2d with BiasAdd and Prelu must have two extra arguments: bias and alpha.");
  21779. if (!d && 1 !== f) throw new Error("Fused Conv2d with BiasAdd must have one extra argument: bias.");
  21780. }
  21781. if (y) throw new Error("Fused Conv2d with FusedBatchNorm is not supported.");
  21782. s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a), p = getParamValue("dataFormat", e, t, a).toUpperCase(), i = getParamValue("dilations", e, t, a);
  21783. var g = (n = getParamValue("args", e, t, a))[0],
  21784. h = n[1];
  21785. return [_tfjsCore.fused.conv2d({
  21786. x: getParamValue("x", e, t, a),
  21787. filter: getParamValue("filter", e, t, a),
  21788. strides: [s[1], s[2]],
  21789. pad: o,
  21790. dataFormat: p,
  21791. dilations: [i[1], i[2]],
  21792. bias: g,
  21793. activation: l,
  21794. preluActivationWeights: h
  21795. })];
  21796. case "Conv2DBackpropInput":
  21797. case "Conv2dTranspose":
  21798. var N = getParamValue("outputShape", e, t, a);
  21799. s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a);
  21800. return [(0, _tfjsCore.conv2dTranspose)(getParamValue("x", e, t, a), getParamValue("filter", e, t, a), N, [s[1], s[2]], o)];
  21801. case "DepthwiseConv2dNative":
  21802. case "DepthwiseConv2d":
  21803. s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a), i = getParamValue("dilations", e, t, a), p = getParamValue("dataFormat", e, t, a).toUpperCase();
  21804. return [(0, _tfjsCore.depthwiseConv2d)(getParamValue("input", e, t, a), getParamValue("filter", e, t, a), [s[1], s[2]], o, p, [i[1], i[2]])];
  21805. case "Conv3D":
  21806. s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a), p = getParamValue("dataFormat", e, t, a).toUpperCase(), i = getParamValue("dilations", e, t, a);
  21807. return [(0, _tfjsCore.conv3d)(getParamValue("x", e, t, a), getParamValue("filter", e, t, a), [s[1], s[2], s[3]], o, p, [i[1], i[2], i[3]])];
  21808. case "AvgPool":
  21809. s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a);
  21810. var x = getParamValue("kernelSize", e, t, a);
  21811. return [(0, _tfjsCore.avgPool)(getParamValue("x", e, t, a), [x[1], x[2]], [s[1], s[2]], o)];
  21812. case "MaxPool":
  21813. s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a), x = getParamValue("kernelSize", e, t, a);
  21814. return [(0, _tfjsCore.maxPool)(getParamValue("x", e, t, a), [x[1], x[2]], [s[1], s[2]], o)];
  21815. case "AvgPool3D":
  21816. s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a), x = getParamValue("kernelSize", e, t, a);
  21817. return [(0, _tfjsCore.avgPool3d)(getParamValue("x", e, t, a), [x[1], x[2], x[3]], [s[1], s[2], s[3]], o)];
  21818. case "MaxPool3D":
  21819. s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a), x = getParamValue("kernelSize", e, t, a);
  21820. return [(0, _tfjsCore.maxPool3d)(getParamValue("x", e, t, a), [x[1], x[2], x[3]], [s[1], s[2], s[3]], o)];
  21821. default:
  21822. throw TypeError("Node type " + e.op + " is not implemented");
  21823. }
  21824. },
  21825. executeOp$4 = function (e, t, a) {
  21826. switch (e.op) {
  21827. case "Fill":
  21828. var r = getParamValue("shape", e, t, a),
  21829. n = getParamValue("dtype", e, t, a),
  21830. s = getParamValue("value", e, t, a);
  21831. return [(0, _tfjsCore.fill)(r, s, n)];
  21832. case "LinSpace":
  21833. var o = getParamValue("start", e, t, a),
  21834. p = getParamValue("stop", e, t, a),
  21835. u = getParamValue("num", e, t, a);
  21836. return [(0, _tfjsCore.linspace)(o, p, u)];
  21837. case "Multinomial":
  21838. var i = getParamValue("logits", e, t, a),
  21839. m = getParamValue("numSamples", e, t, a),
  21840. l = getParamValue("seed", e, t, a);
  21841. return [(0, _tfjsCore.multinomial)(i, m, l)];
  21842. case "OneHot":
  21843. var c = getParamValue("indices", e, t, a),
  21844. d = getParamValue("depth", e, t, a),
  21845. y = getParamValue("onValue", e, t, a),
  21846. f = getParamValue("offValue", e, t, a);
  21847. return [(0, _tfjsCore.oneHot)(c, d, y, f)];
  21848. case "Ones":
  21849. return [(0, _tfjsCore.ones)(getParamValue("shape", e, t, a), getParamValue("dtype", e, t, a))];
  21850. case "OnesLike":
  21851. return [(0, _tfjsCore.onesLike)(getParamValue("x", e, t, a))];
  21852. case "RandomUniform":
  21853. return [(0, _tfjsCore.randomUniform)(getParamValue("shape", e, t, a), getParamValue("minval", e, t, a), getParamValue("maxval", e, t, a), getParamValue("dtype", e, t, a))];
  21854. case "Range":
  21855. o = getParamValue("start", e, t, a);
  21856. var g = getParamValue("stop", e, t, a),
  21857. h = getParamValue("step", e, t, a);
  21858. return [(0, _tfjsCore.range)(o, g, h, getParamValue("dtype", e, t, a))];
  21859. case "TruncatedNormal":
  21860. r = getParamValue("shape", e, t, a);
  21861. var N = getParamValue("mean", e, t, a),
  21862. x = getParamValue("stdDev", e, t, a);
  21863. l = getParamValue("seed", e, t, a);
  21864. return [(0, _tfjsCore.truncatedNormal)(r, N, x, getParamValue("dtype", e, t, a), l)];
  21865. case "Zeros":
  21866. return [(0, _tfjsCore.zeros)(getParamValue("shape", e, t, a), getParamValue("dtype", e, t, a))];
  21867. case "ZerosLike":
  21868. return [(0, _tfjsCore.zerosLike)(getParamValue("x", e, t, a))];
  21869. default:
  21870. throw TypeError("Node type " + e.op + " is not implemented");
  21871. }
  21872. };
  21873. function executeOp$5(e, t, a) {
  21874. return __awaiter(this, void 0, void 0, function () {
  21875. var r, n, s, o, p;
  21876. return __generator(this, function (u) {
  21877. switch (u.label) {
  21878. case 0:
  21879. switch (e.op) {
  21880. case "NonMaxSuppressionV3":
  21881. case "NonMaxSuppressionV2":
  21882. return [3, 1];
  21883. case "Where":
  21884. return [3, 3];
  21885. case "ListDiff":
  21886. return [3, 5];
  21887. }
  21888. return [3, 6];
  21889. case 1:
  21890. return r = getParamValue("boxes", e, t, a), n = getParamValue("scores", e, t, a), s = getParamValue("maxOutputSize", e, t, a), o = getParamValue("iouThreshold", e, t, a), p = getParamValue("scoreThreshold", e, t, a), [4, _tfjsCore.image.nonMaxSuppressionAsync(r, n, s, o, p)];
  21891. case 2:
  21892. return [2, [u.sent()]];
  21893. case 3:
  21894. return [4, (0, _tfjsCore.whereAsync)(getParamValue("condition", e, t, a).asType("bool"))];
  21895. case 4:
  21896. return [2, [u.sent()]];
  21897. case 5:
  21898. return [2, (0, _tfjsCore.setdiff1dAsync)(getParamValue("x", e, t, a), getParamValue("y", e, t, a))];
  21899. case 6:
  21900. throw TypeError("Node type " + e.op + " is not implemented");
  21901. }
  21902. });
  21903. });
  21904. }
  21905. var executeOp$6 = function (e, t, a) {
  21906. switch (e.op) {
  21907. case "TopKV2":
  21908. var r = getParamValue("x", e, t, a),
  21909. n = getParamValue("k", e, t, a),
  21910. s = getParamValue("sorted", e, t, a),
  21911. o = (0, _tfjsCore.topk)(r, n, s);
  21912. return [o.values, o.indices];
  21913. default:
  21914. throw TypeError("Node type " + e.op + " is not implemented");
  21915. }
  21916. },
  21917. executeOp$7 = function (e, t, a) {
  21918. switch (e.op) {
  21919. case "Const":
  21920. return t[e.name];
  21921. case "PlaceholderWithDefault":
  21922. var r = getParamValue("default", e, t, a);
  21923. return [getTensor(e.name, t, a) || r];
  21924. case "Placeholder":
  21925. return [getTensor(e.name, t, a)];
  21926. case "Identity":
  21927. case "StopGradient":
  21928. case "FakeQuantWithMinMaxVars":
  21929. return [getParamValue("x", e, t, a).clone()];
  21930. case "IdentityN":
  21931. return getParamValue("x", e, t, a).map(function (e) {
  21932. return e.clone();
  21933. });
  21934. case "Snapshot":
  21935. return [getParamValue("x", e, t, a).clone()];
  21936. case "Shape":
  21937. return [(0, _tfjsCore.tensor1d)(getParamValue("x", e, t, a).shape, "int32")];
  21938. case "ShapeN":
  21939. return getParamValue("x", e, t, a).map(function (e) {
  21940. return (0, _tfjsCore.tensor1d)(e.shape);
  21941. });
  21942. case "Size":
  21943. return [(0, _tfjsCore.scalar)(getParamValue("x", e, t, a).size, "int32")];
  21944. case "Rank":
  21945. return [(0, _tfjsCore.scalar)(getParamValue("x", e, t, a).rank, "int32")];
  21946. case "NoOp":
  21947. return [];
  21948. case "Print":
  21949. var n = getParamValue("x", e, t, a),
  21950. s = getParamValue("data", e, t, a),
  21951. o = getParamValue("message", e, t, a),
  21952. p = getParamValue("summarize", e, t, a);
  21953. console.warn("The graph has a tf.print() operation,usually used for debugging, which slows down performance."), console.log(o);
  21954. for (var u = 0; u < s.length; u++) console.log(Array.prototype.slice.call(s[u].dataSync()).slice(0, p));
  21955. return [n];
  21956. default:
  21957. throw TypeError("Node type " + e.op + " is not implemented");
  21958. }
  21959. },
  21960. executeOp$8 = function (e, t, a) {
  21961. switch (e.op) {
  21962. case "ResizeBilinear":
  21963. var r = getParamValue("images", e, t, a),
  21964. n = getParamValue("size", e, t, a),
  21965. s = getParamValue("alignCorners", e, t, a);
  21966. return [_tfjsCore.image.resizeBilinear(r, [n[0], n[1]], s)];
  21967. case "ResizeNearestNeighbor":
  21968. r = getParamValue("images", e, t, a), n = getParamValue("size", e, t, a), s = getParamValue("alignCorners", e, t, a);
  21969. return [_tfjsCore.image.resizeNearestNeighbor(r, [n[0], n[1]], s)];
  21970. case "CropAndResize":
  21971. var o = getParamValue("image", e, t, a),
  21972. p = getParamValue("boxes", e, t, a),
  21973. u = getParamValue("boxInd", e, t, a),
  21974. i = getParamValue("cropSize", e, t, a),
  21975. m = getParamValue("method", e, t, a),
  21976. l = getParamValue("extrapolationValue", e, t, a);
  21977. return [_tfjsCore.image.cropAndResize(o, p, u, i, m, l)];
  21978. default:
  21979. throw TypeError("Node type " + e.op + " is not implemented");
  21980. }
  21981. },
  21982. executeOp$9 = function (e, t, a) {
  21983. switch (e.op) {
  21984. case "Equal":
  21985. return [(0, _tfjsCore.equal)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21986. case "NotEqual":
  21987. return [(0, _tfjsCore.notEqual)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21988. case "Greater":
  21989. return [(0, _tfjsCore.greater)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21990. case "GreaterEqual":
  21991. return [(0, _tfjsCore.greaterEqual)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21992. case "Less":
  21993. return [(0, _tfjsCore.less)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21994. case "LessEqual":
  21995. return [(0, _tfjsCore.lessEqual)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21996. case "LogicalAnd":
  21997. return [(0, _tfjsCore.logicalAnd)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  21998. case "LogicalNot":
  21999. return [(0, _tfjsCore.logicalNot)(getParamValue("a", e, t, a))];
  22000. case "LogicalOr":
  22001. return [(0, _tfjsCore.logicalOr)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  22002. case "Select":
  22003. return [(0, _tfjsCore.where)(getParamValue("condition", e, t, a), getParamValue("a", e, t, a), getParamValue("b", e, t, a))];
  22004. default:
  22005. throw TypeError("Node type " + e.op + " is not implemented");
  22006. }
  22007. },
  22008. executeOp$10 = function (e, t, a) {
  22009. switch (e.op) {
  22010. case "BatchMatMul":
  22011. case "BatchMatMulV2":
  22012. case "MatMul":
  22013. return [(0, _tfjsCore.matMul)(getParamValue("a", e, t, a), getParamValue("b", e, t, a), getParamValue("transposeA", e, t, a), getParamValue("transposeB", e, t, a))];
  22014. case "Transpose":
  22015. return [(0, _tfjsCore.transpose)(getParamValue("x", e, t, a), getParamValue("perm", e, t, a))];
  22016. default:
  22017. throw TypeError("Node type " + e.op + " is not implemented");
  22018. }
  22019. },
  22020. executeOp$11 = function (e, t, a) {
  22021. switch (e.op) {
  22022. case "FusedBatchNorm":
  22023. case "FusedBatchNormV2":
  22024. case "FusedBatchNormV3":
  22025. return [(0, _tfjsCore.batchNorm)(getParamValue("x", e, t, a), getParamValue("mean", e, t, a), getParamValue("variance", e, t, a), getParamValue("offset", e, t, a), getParamValue("scale", e, t, a), getParamValue("epsilon", e, t, a))];
  22026. case "LRN":
  22027. return [(0, _tfjsCore.localResponseNormalization)(getParamValue("x", e, t, a), getParamValue("radius", e, t, a), getParamValue("bias", e, t, a), getParamValue("alpha", e, t, a), getParamValue("beta", e, t, a))];
  22028. case "Softmax":
  22029. return [(0, _tfjsCore.softmax)(getParamValue("x", e, t, a))];
  22030. case "LogSoftmax":
  22031. return [(0, _tfjsCore.logSoftmax)(getParamValue("x", e, t, a))];
  22032. case "SparseToDense":
  22033. return [(0, _tfjsCore.sparseToDense)(getParamValue("sparseIndices", e, t, a), getParamValue("outputShape", e, t, a), getParamValue("sparseValues", e, t, a), getParamValue("defaultValue", e, t, a))];
  22034. default:
  22035. throw TypeError("Node type " + e.op + " is not implemented");
  22036. }
  22037. },
  22038. executeOp$12 = function (e, t, a) {
  22039. switch (e.op) {
  22040. case "Max":
  22041. var r = getParamValue("axis", e, t, a),
  22042. n = getParamValue("keepDims", e, t, a);
  22043. return [(0, _tfjsCore.max)(getParamValue("x", e, t, a), r, n)];
  22044. case "Mean":
  22045. r = getParamValue("axis", e, t, a), n = getParamValue("keepDims", e, t, a);
  22046. return [(0, _tfjsCore.mean)(getParamValue("x", e, t, a), r, n)];
  22047. case "Min":
  22048. r = getParamValue("axis", e, t, a), n = getParamValue("keepDims", e, t, a);
  22049. return [(0, _tfjsCore.min)(getParamValue("x", e, t, a), r, n)];
  22050. case "Sum":
  22051. r = getParamValue("axis", e, t, a), n = getParamValue("keepDims", e, t, a);
  22052. return [(0, _tfjsCore.sum)(getParamValue("x", e, t, a), r, n)];
  22053. case "All":
  22054. r = getParamValue("axis", e, t, a), n = getParamValue("keepDims", e, t, a);
  22055. return [(0, _tfjsCore.all)(getParamValue("x", e, t, a), r, n)];
  22056. case "Any":
  22057. r = getParamValue("axis", e, t, a), n = getParamValue("keepDims", e, t, a);
  22058. return [(0, _tfjsCore.any)(getParamValue("x", e, t, a), r, n)];
  22059. case "ArgMax":
  22060. r = getParamValue("axis", e, t, a);
  22061. return [(0, _tfjsCore.argMax)(getParamValue("x", e, t, a), r)];
  22062. case "ArgMin":
  22063. r = getParamValue("axis", e, t, a);
  22064. return [(0, _tfjsCore.argMin)(getParamValue("x", e, t, a), r)];
  22065. case "Prod":
  22066. r = getParamValue("axis", e, t, a), n = getParamValue("keepDims", e, t, a);
  22067. return [(0, _tfjsCore.prod)(getParamValue("x", e, t, a), r, n)];
  22068. default:
  22069. throw TypeError("Node type " + e.op + " is not implemented");
  22070. }
  22071. },
  22072. executeOp$13 = function (e, t, a) {
  22073. switch (e.op) {
  22074. case "ConcatV2":
  22075. case "Concat":
  22076. var r = getParamValue("axis", e, t, a),
  22077. n = getParamValue("tensors", e, t, a);
  22078. return [(0, _tfjsCore.concat)(n, r)];
  22079. case "GatherV2":
  22080. case "Gather":
  22081. r = getParamValue("axis", e, t, a);
  22082. var s = getParamValue("x", e, t, a),
  22083. o = getParamValue("indices", e, t, a);
  22084. return [(0, _tfjsCore.gather)(s, o.asType("int32"), r)];
  22085. case "ReverseV2":
  22086. case "Reverse":
  22087. r = getParamValue("axis", e, t, a), s = getParamValue("x", e, t, a);
  22088. return [(0, _tfjsCore.reverse)(s, r)];
  22089. case "Slice":
  22090. var p = getParamValue("begin", e, t, a),
  22091. u = getParamValue("size", e, t, a);
  22092. return [(0, _tfjsCore.slice)(getParamValue("x", e, t, a), p, u)];
  22093. case "StridedSlice":
  22094. p = getParamValue("begin", e, t, a);
  22095. var i = getParamValue("end", e, t, a),
  22096. m = getParamValue("strides", e, t, a),
  22097. l = getParamValue("beginMask", e, t, a),
  22098. c = getParamValue("endMask", e, t, a),
  22099. d = getParamValue("ellipsisMask", e, t, a),
  22100. y = getParamValue("newAxisMask", e, t, a),
  22101. f = getParamValue("shrinkAxisMask", e, t, a),
  22102. g = getParamValue("x", e, t, a);
  22103. if (1 === p.length && g.shape.length > 1) for (var h = 1; h < g.shape.length; h++) p.push(0), i.push(g.shape[h]), m.push(m[0]);
  22104. return [(0, _tfjsCore.stridedSlice)(g, p, i, m, l, c, d, y, f)];
  22105. case "Pack":
  22106. return (0, _tfjsCore.tidy)(function () {
  22107. var r = getParamValue("axis", e, t, a),
  22108. n = getParamValue("tensors", e, t, a),
  22109. s = n[0].shape,
  22110. o = n[0].squeeze().shape,
  22111. p = n.map(function (e) {
  22112. var t = _tfjsCore.util.arraysEqual(e.shape, s);
  22113. if (!t && !_tfjsCore.util.arraysEqual(e.squeeze().shape, o)) throw new Error("the input tensors shape does not match");
  22114. return t ? e : e.reshape(s);
  22115. });
  22116. return [(0, _tfjsCore.stack)(p, r)];
  22117. });
  22118. case "Unpack":
  22119. return (0, _tfjsCore.tidy)(function () {
  22120. var r = getParamValue("axis", e, t, a),
  22121. n = getParamValue("tensor", e, t, a);
  22122. return (0, _tfjsCore.unstack)(n, r);
  22123. });
  22124. case "Tile":
  22125. var N = getParamValue("reps", e, t, a);
  22126. return [(0, _tfjsCore.tile)(getParamValue("x", e, t, a), N)];
  22127. case "Split":
  22128. case "SplitV":
  22129. r = getParamValue("axis", e, t, a);
  22130. var x = getParamValue("numOrSizeSplits", e, t, a);
  22131. return (0, _tfjsCore.split)(getParamValue("x", e, t, a), x, r);
  22132. case "ScatterNd":
  22133. o = getParamValue("indices", e, t, a);
  22134. var V = getParamValue("values", e, t, a),
  22135. P = getParamValue("shape", e, t, a);
  22136. return [(0, _tfjsCore.scatterND)(o, V, P)];
  22137. case "GatherNd":
  22138. var b = getParamValue("x", e, t, a);
  22139. o = getParamValue("indices", e, t, a);
  22140. return [(0, _tfjsCore.gatherND)(b, o)];
  22141. case "SparseToDense":
  22142. o = getParamValue("sparseIndices", e, t, a), P = getParamValue("outputShape", e, t, a);
  22143. var T = getParamValue("sparseValues", e, t, a),
  22144. O = getParamValue("defaultValue", e, t, a);
  22145. return [(0, _tfjsCore.sparseToDense)(o, T, P, T.dtype === O.dtype ? O : O.asType(T.dtype))];
  22146. default:
  22147. throw TypeError("Node type " + e.op + " is not implemented");
  22148. }
  22149. },
  22150. executeOp$14 = function (e, t, a) {
  22151. switch (e.op) {
  22152. case "FFT":
  22153. return [(0, _tfjsCore.fft)(getParamValue("x", e, t, a))];
  22154. case "IFFT":
  22155. return [(0, _tfjsCore.ifft)(getParamValue("x", e, t, a))];
  22156. case "RFFT":
  22157. return [(0, _tfjsCore.rfft)(getParamValue("x", e, t, a))];
  22158. case "IRFFT":
  22159. return [(0, _tfjsCore.irfft)(getParamValue("x", e, t, a))];
  22160. default:
  22161. throw TypeError("Node type " + e.op + " is not implemented");
  22162. }
  22163. },
  22164. executeOp$15 = function (e, t, a) {
  22165. switch (e.op) {
  22166. case "Cast":
  22167. return [(0, _tfjsCore.cast)(getParamValue("x", e, t, a), getParamValue("dtype", e, t, a))];
  22168. case "ExpandDims":
  22169. var r = getParamValue("axis", e, t, a);
  22170. return [(0, _tfjsCore.expandDims)(getParamValue("x", e, t, a), r)];
  22171. case "Squeeze":
  22172. r = getParamValue("axis", e, t, a);
  22173. return [(0, _tfjsCore.squeeze)(getParamValue("x", e, t, a), r)];
  22174. case "Reshape":
  22175. return [(0, _tfjsCore.reshape)(getParamValue("x", e, t, a), getParamValue("shape", e, t, a))];
  22176. case "PadV2":
  22177. case "Pad":
  22178. return [(0, _tfjsCore.pad)(getParamValue("x", e, t, a), split$1(getParamValue("padding", e, t, a), 2), getParamValue("constantValue", e, t, a))];
  22179. case "SpaceToBatchND":
  22180. var n = getParamValue("blockShape", e, t, a),
  22181. s = split$1(getParamValue("paddings", e, t, a), 2);
  22182. return [(0, _tfjsCore.spaceToBatchND)(getParamValue("x", e, t, a), n, s)];
  22183. case "BatchToSpaceND":
  22184. n = getParamValue("blockShape", e, t, a);
  22185. var o = split$1(getParamValue("crops", e, t, a), 2);
  22186. return [(0, _tfjsCore.batchToSpaceND)(getParamValue("x", e, t, a), n, o)];
  22187. case "DepthToSpace":
  22188. var p = getParamValue("blockSize", e, t, a),
  22189. u = getParamValue("dataFormat", e, t, a).toUpperCase();
  22190. return [(0, _tfjsCore.depthToSpace)(getParamValue("x", e, t, a), p, u)];
  22191. default:
  22192. throw TypeError("Node type " + e.op + " is not implemented");
  22193. }
  22194. };
  22195. function executeOp$16(e, t, a) {
  22196. var r = function (e, t, a) {
  22197. switch (e.category) {
  22198. case "arithmetic":
  22199. return executeOp(e, t, a);
  22200. case "basic_math":
  22201. return executeOp$1(e, t, a);
  22202. case "control":
  22203. return executeOp$2(e, t, a);
  22204. case "convolution":
  22205. return executeOp$3(e, t, a);
  22206. case "creation":
  22207. return executeOp$4(e, t, a);
  22208. case "dynamic":
  22209. return executeOp$5(e, t, a);
  22210. case "evaluation":
  22211. return executeOp$6(e, t, a);
  22212. case "image":
  22213. return executeOp$8(e, t, a);
  22214. case "graph":
  22215. return executeOp$7(e, t, a);
  22216. case "logical":
  22217. return executeOp$9(e, t, a);
  22218. case "matrices":
  22219. return executeOp$10(e, t, a);
  22220. case "normalization":
  22221. return executeOp$11(e, t, a);
  22222. case "reduction":
  22223. return executeOp$12(e, t, a);
  22224. case "slice_join":
  22225. return executeOp$13(e, t, a);
  22226. case "spectral":
  22227. return executeOp$14(e, t, a);
  22228. case "transformation":
  22229. return executeOp$15(e, t, a);
  22230. case "custom":
  22231. var r = getRegisteredOp(e.op);
  22232. if (r && r.customExecutor) return r.customExecutor(new NodeValueImpl(e, t, a));
  22233. throw TypeError("Custom op " + e.op + " is not registered.");
  22234. default:
  22235. throw TypeError("Unknown op '" + e.op + "'. File an issue at https://github.com/tensorflow/tfjs/issues so we can add it, or register a custom execution with tf.registerOp()");
  22236. }
  22237. }(e, t, a);
  22238. return r instanceof Promise ? r.then(function (e) {
  22239. return [].concat(e);
  22240. }) : [].concat(r);
  22241. }
  22242. var ExecutionContext = function () {
  22243. function e(e, t) {
  22244. this.weightMap = e, this.tensorArrayMap = t, this.rootContext = {
  22245. id: 0,
  22246. frameName: "",
  22247. iterationId: 0
  22248. }, this.contexts = [this.rootContext], this.lastId = 0, this.generateCurrentContextIds();
  22249. }
  22250. return e.prototype.newFrame = function (e, t) {
  22251. return {
  22252. id: e,
  22253. frameName: t,
  22254. iterationId: 0
  22255. };
  22256. }, Object.defineProperty(e.prototype, "currentContext", {
  22257. get: function () {
  22258. return this.contexts;
  22259. },
  22260. set: function (e) {
  22261. this.contexts !== e && (this.contexts = e, this.generateCurrentContextIds());
  22262. },
  22263. enumerable: !0,
  22264. configurable: !0
  22265. }), Object.defineProperty(e.prototype, "currentContextId", {
  22266. get: function () {
  22267. return this._currentContextIds[0];
  22268. },
  22269. enumerable: !0,
  22270. configurable: !0
  22271. }), Object.defineProperty(e.prototype, "currentContextIds", {
  22272. get: function () {
  22273. return this._currentContextIds;
  22274. },
  22275. enumerable: !0,
  22276. configurable: !0
  22277. }), e.prototype.generateCurrentContextIds = function () {
  22278. for (var e = [], t = 0; t < this.contexts.length - 1; t++) {
  22279. var a = this.contexts.slice(0, this.contexts.length - t);
  22280. e.push(this.contextIdforContexts(a));
  22281. }
  22282. e.push(""), this._currentContextIds = e;
  22283. }, e.prototype.contextIdforContexts = function (e) {
  22284. return e ? e.map(function (e) {
  22285. return 0 === e.id && 0 === e.iterationId ? "" : e.frameName + "-" + e.iterationId;
  22286. }).join("/") : "";
  22287. }, e.prototype.enterFrame = function (e) {
  22288. this.contexts && (this.lastId++, this.contexts = this.contexts.slice(), this.contexts.push(this.newFrame(this.lastId, e)), this._currentContextIds.unshift(this.contextIdforContexts(this.contexts)));
  22289. }, e.prototype.exitFrame = function () {
  22290. if (!(this.contexts && this.contexts.length > 1)) throw new Error("Cannot exit frame, the context is empty");
  22291. this.contexts = this.contexts.slice(), this.contexts.splice(-1), this.currentContextIds.shift();
  22292. }, e.prototype.nextIteration = function () {
  22293. if (!(this.contexts && this.contexts.length > 0)) throw new Error("Cannot increase frame iteration, the context is empty");
  22294. this.contexts = this.contexts.slice(), this.lastId++;
  22295. var e = Object.assign({}, this.contexts[this.contexts.length - 1]);
  22296. e.iterationId += 1, e.id = this.lastId, this.contexts.splice(-1, 1, e), this._currentContextIds.splice(0, 1, this.contextIdforContexts(this.contexts));
  22297. }, e.prototype.getWeight = function (e) {
  22298. return this.weightMap[e];
  22299. }, e.prototype.addTensorArray = function (e) {
  22300. this.tensorArrayMap[e.id] = e;
  22301. }, e.prototype.getTensorArray = function (e) {
  22302. return this.tensorArrayMap[e];
  22303. }, e;
  22304. }();
  22305. function getExecutionSubgraph(e, t, a) {
  22306. for (var r = new Set(), n = [], s = null, o = null, p = new Set(), u = t.slice(); u.length > 0;) {
  22307. var i = u.pop();
  22308. (isControlFlow(i) || isDynamicShape(i)) && null == s && (o = (s = i).children.map(function (e) {
  22309. return e.name;
  22310. }).filter(function (e) {
  22311. return r.has(e);
  22312. })), r.add(i.name), null == a[i.name] && null == e[i.name] && (0 !== i.inputs.length ? i.inputs.forEach(function (e) {
  22313. p.has(e.name) || (p.add(e.name), u.push(e));
  22314. }) : n.push(i.name));
  22315. }
  22316. return {
  22317. inputs: e,
  22318. outputs: t,
  22319. usedNodes: r,
  22320. missingInputs: n,
  22321. dynamicNode: s,
  22322. syncInputs: o
  22323. };
  22324. }
  22325. function getNodesInTopologicalOrder(e, t, a) {
  22326. var r = a.usedNodes,
  22327. n = a.inputs,
  22328. s = [];
  22329. Object.keys(n).map(function (t) {
  22330. return e.nodes[t];
  22331. }).forEach(function (e) {
  22332. r.has(e.name) && s.push(e);
  22333. }), e.weights.forEach(function (e) {
  22334. r.has(e.name) && s.push(e);
  22335. });
  22336. for (var o = new Set(), p = []; s.length > 0;) {
  22337. var u = s.pop();
  22338. o.add(u.name), t[u.name] || p.push(u), u.children.forEach(function (e) {
  22339. !o.has(e.name) && r.has(e.name) && e.inputs.every(function (e) {
  22340. return o.has(e.name);
  22341. }) && s.push(e);
  22342. });
  22343. }
  22344. return p;
  22345. }
  22346. var CONTROL_FLOW_OPS = ["Switch", "Merge", "Enter", "Exit", "NextIteration"],
  22347. DYNAMIC_SHAPE_OPS = ["NonMaxSuppressionV2", "NonMaxSuppressionV3", "Where"];
  22348. function isControlFlow(e) {
  22349. return CONTROL_FLOW_OPS.indexOf(e.op) >= 0;
  22350. }
  22351. function isDynamicShape(e) {
  22352. return DYNAMIC_SHAPE_OPS.indexOf(e.op) >= 0;
  22353. }
  22354. var GraphExecutor = function () {
  22355. function e(e) {
  22356. this.graph = e, this.compiledMap = new Map(), this._weightMap = {}, this.SEPERATOR = ",", this.placeholders = e.placeholders, this._outputs = e.outputs;
  22357. }
  22358. return Object.defineProperty(e.prototype, "weightMap", {
  22359. get: function () {
  22360. return this._weightMap;
  22361. },
  22362. set: function (e) {
  22363. var t = Object.keys(e).map(function (t) {
  22364. return e[t].map(function (e) {
  22365. return e.id;
  22366. });
  22367. });
  22368. this.weightIds = [].concat.apply([], t), this._weightMap = e;
  22369. },
  22370. enumerable: !0,
  22371. configurable: !0
  22372. }), Object.defineProperty(e.prototype, "inputs", {
  22373. get: function () {
  22374. return this.placeholders.map(function (e) {
  22375. return {
  22376. name: e.name,
  22377. shape: e.attrParams.shape ? e.attrParams.shape.value : void 0,
  22378. dtype: e.attrParams.dtype ? e.attrParams.dtype.value : void 0
  22379. };
  22380. });
  22381. },
  22382. enumerable: !0,
  22383. configurable: !0
  22384. }), Object.defineProperty(e.prototype, "outputs", {
  22385. get: function () {
  22386. return this._outputs.map(function (e) {
  22387. return {
  22388. name: e.name,
  22389. shape: e.attrParams.shape ? e.attrParams.shape.value : void 0,
  22390. dtype: e.attrParams.dtype ? e.attrParams.dtype.value : void 0
  22391. };
  22392. });
  22393. },
  22394. enumerable: !0,
  22395. configurable: !0
  22396. }), Object.defineProperty(e.prototype, "inputNodes", {
  22397. get: function () {
  22398. return this.placeholders.map(function (e) {
  22399. return e.name;
  22400. });
  22401. },
  22402. enumerable: !0,
  22403. configurable: !0
  22404. }), Object.defineProperty(e.prototype, "outputNodes", {
  22405. get: function () {
  22406. return this.outputs.map(function (e) {
  22407. return e.name;
  22408. });
  22409. },
  22410. enumerable: !0,
  22411. configurable: !0
  22412. }), e.prototype.getCompilationKey = function (e, t) {
  22413. var a = e.map(function (e) {
  22414. return e.name;
  22415. }).sort(),
  22416. r = t.map(function (e) {
  22417. return e.name;
  22418. }).sort();
  22419. return a.join(this.SEPERATOR) + "--" + r.join(this.SEPERATOR);
  22420. }, e.prototype.compile = function (e, t) {
  22421. var a = getExecutionSubgraph(e, t, this.weightMap),
  22422. r = a.missingInputs,
  22423. n = a.dynamicNode,
  22424. s = a.syncInputs;
  22425. if (null != n) throw new Error("This execution contains the node '" + n.name + "', which has the dynamic op '" + n.op + "'. Please use model.executeAsync() instead. Alternatively, to avoid the dynamic ops, specify the inputs [" + s + "]");
  22426. if (r.length > 0) {
  22427. var o = t.map(function (e) {
  22428. return e.name;
  22429. }),
  22430. p = Object.keys(e);
  22431. throw new Error("Cannot compute the outputs [" + o + "] from the provided inputs [" + p + "]. Missing the following inputs: [" + r + "]");
  22432. }
  22433. return getNodesInTopologicalOrder(this.graph, this.weightMap, a);
  22434. }, e.prototype.execute = function (e, t) {
  22435. var a = this,
  22436. r = Object.keys(e).sort();
  22437. this.checkInputs(e), this.checkInputShapeAndType(e), this.checkOutputs(t);
  22438. var n = r.map(function (e) {
  22439. return a.graph.nodes[e];
  22440. }),
  22441. s = t.map(function (e) {
  22442. return a.graph.nodes[parseNodeName(e)[0]];
  22443. }),
  22444. o = this.getCompilationKey(n, s),
  22445. p = this.compiledMap.get(o);
  22446. null == p && (p = this.compile(e, s), this.compiledMap.set(o, p));
  22447. var u = {};
  22448. return (0, _tfjsCore.tidy)(function () {
  22449. var r = new ExecutionContext(a._weightMap, u),
  22450. n = __assign({}, a.weightMap);
  22451. Object.keys(e).forEach(function (t) {
  22452. n[t] = [e[t]];
  22453. });
  22454. for (var s = a.getFrozenTensorIds(n), o = {}, i = 0; i < p.length; i++) {
  22455. var m = p[i];
  22456. if (!n[m.name]) {
  22457. var l = executeOp$16(m, n, r);
  22458. if (l instanceof Promise) throw new Error("The execution of the op '" + m.op + "' returned a promise. Please use model.executeAsync() instead.");
  22459. n[m.name] = l, a.checkTensorForDisposal(m.name, m, n, r, s, t, o);
  22460. }
  22461. }
  22462. return t.map(function (e) {
  22463. return getTensor(e, n, r);
  22464. });
  22465. });
  22466. }, e.prototype.getFrozenTensorIds = function (e) {
  22467. var t = [].concat.apply([], Object.keys(e).map(function (t) {
  22468. return e[t];
  22469. }).map(function (e) {
  22470. return e.map(function (e) {
  22471. return e.id;
  22472. });
  22473. }));
  22474. return new Set(t);
  22475. }, e.prototype.checkTensorForDisposal = function (e, t, a, r, n, s, o) {
  22476. "control" !== t.category && -1 === s.indexOf(e) && (a[e].forEach(function (e) {
  22477. null != e && (o[e.id] = (o[e.id] || 0) + t.children.length);
  22478. }), t.inputs.forEach(function (e) {
  22479. if ("control" !== e.category) {
  22480. var t = getTensorsForCurrentContenxt(e.name, a, r);
  22481. null != t && t.forEach(function (e) {
  22482. if (e && !n.has(e.id)) {
  22483. var t = o[e.id];
  22484. 1 === t ? (e.dispose(), delete o[e.id]) : null != t && o[e.id]--;
  22485. }
  22486. });
  22487. }
  22488. }));
  22489. }, e.prototype.executeAsync = function (e, t) {
  22490. return __awaiter(this, void 0, void 0, function () {
  22491. var a,
  22492. r,
  22493. n,
  22494. s,
  22495. o,
  22496. p,
  22497. u = this;
  22498. return __generator(this, function (i) {
  22499. switch (i.label) {
  22500. case 0:
  22501. return this.checkInputs(e), this.checkInputShapeAndType(e), this.checkOutputs(t), a = {}, r = new ExecutionContext(this._weightMap, a), [4, this.executeWithControlFlow(e, r, t)];
  22502. case 1:
  22503. return n = i.sent(), s = t.map(function (e) {
  22504. return getTensor(e, n, r);
  22505. }), o = new Set(s.map(function (e) {
  22506. return e.id;
  22507. })), p = new Set(Object.keys(e).map(function (t) {
  22508. return e[t].id;
  22509. })), Object.keys(n).forEach(function (e) {
  22510. n[e].forEach(function (e) {
  22511. !e || e.isDisposed || o.has(e.id) || p.has(e.id) || -1 !== u.weightIds.indexOf(e.id) || e.dispose();
  22512. });
  22513. }), [2, s];
  22514. }
  22515. });
  22516. });
  22517. }, e.prototype.executeWithControlFlow = function (e, t, a) {
  22518. return __awaiter(this, void 0, void 0, function () {
  22519. var r,
  22520. n,
  22521. s,
  22522. o,
  22523. p,
  22524. u,
  22525. i,
  22526. m,
  22527. l,
  22528. c,
  22529. d,
  22530. y,
  22531. f,
  22532. g,
  22533. h,
  22534. N,
  22535. x = this;
  22536. return __generator(this, function (V) {
  22537. switch (V.label) {
  22538. case 0:
  22539. r = Object.keys(e), n = r.map(function (e) {
  22540. return x.graph.nodes[e];
  22541. }), s = a.map(function (e) {
  22542. return x.graph.nodes[parseNodeName(e)[0]];
  22543. }), o = getExecutionSubgraph(e, s, this.weightMap), p = o.usedNodes, u = o.missingInputs, i = o.dynamicNode, m = o.syncInputs, l = n.concat(this.graph.weights).map(function (e) {
  22544. return {
  22545. node: e,
  22546. contexts: t.currentContext
  22547. };
  22548. }), c = __assign({}, this.weightMap), Object.keys(e).forEach(function (t) {
  22549. c[t] = [e[t]];
  22550. }), d = {}, y = this.getFrozenTensorIds(c), f = {}, V.label = 1;
  22551. case 1:
  22552. return l.length > 0 ? (g = this.processStack(n, l, t, c, f, y, a, d, p), [4, Promise.all(g)]) : [3, 3];
  22553. case 2:
  22554. return V.sent(), [3, 1];
  22555. case 3:
  22556. if (null == i && console.warn("This model execution did not contain any nodes with control flow or dynamic output shapes. You can use model.execute() instead."), (h = s.filter(function (e) {
  22557. return !isControlFlow(e) && !getTensor(e.name, c, t);
  22558. }).map(function (e) {
  22559. return e.name;
  22560. })).length > 0) throw N = "", null != i && (N = "Alternatively, to avoid the dynamic ops, use model.execute() and specify the inputs [" + m + "]"), new Error("Cannot compute the outputs [" + h + "] from the provided inputs [" + r + "]. Consider providing the following inputs: [" + u + "]. " + N);
  22561. return [2, c];
  22562. }
  22563. });
  22564. });
  22565. }, e.prototype.processStack = function (e, t, a, r, n, s, o, p, u) {
  22566. for (var i = this, m = [], l = function () {
  22567. var l = t.pop();
  22568. a.currentContext = l.contexts;
  22569. var d = "";
  22570. if ("Enter" === l.node.op && getParamValue("isConstant", l.node, r, a) && (d = getNodeNameAndIndex(l.node.name, a)[0]), -1 === e.indexOf(l.node)) {
  22571. var y = executeOp$16(l.node, r, a);
  22572. d || (d = getNodeNameAndIndex(l.node.name, a)[0]);
  22573. var f = a.currentContext;
  22574. y instanceof Promise ? m.push(y.then(function (e) {
  22575. return r[d] = e, a.currentContext = f, i.checkTensorForDisposal(d, l.node, r, a, s, o, p), i.processChildNodes(l.node, t, a, r, n, u), e;
  22576. })) : (r[d] = y, c.checkTensorForDisposal(d, l.node, r, a, s, o, p), c.processChildNodes(l.node, t, a, r, n, u));
  22577. } else c.processChildNodes(l.node, t, a, r, n, u);
  22578. }, c = this; t.length > 0;) l();
  22579. return m;
  22580. }, e.prototype.processChildNodes = function (e, t, a, r, n, s) {
  22581. e.children.forEach(function (e) {
  22582. var o = getNodeNameAndIndex(e.name, a)[0];
  22583. !n[o] && s.has(e.name) && ("Merge" === e.op ? e.inputNames.some(function (e) {
  22584. return !!getTensor(e, r, a);
  22585. }) && (n[o] = !0, t.push({
  22586. contexts: a.currentContext,
  22587. node: e
  22588. })) : e.inputNames.every(function (e) {
  22589. return !!getTensor(e, r, a);
  22590. }) && (n[o] = !0, t.push({
  22591. contexts: a.currentContext,
  22592. node: e
  22593. })));
  22594. });
  22595. }, e.prototype.dispose = function () {
  22596. var e = this;
  22597. Object.keys(this.weightMap).forEach(function (t) {
  22598. return e.weightMap[t].forEach(function (e) {
  22599. return e.dispose();
  22600. });
  22601. });
  22602. }, e.prototype.checkInputShapeAndType = function (e) {
  22603. var t = this;
  22604. Object.keys(e).forEach(function (a) {
  22605. var r = e[a],
  22606. n = t.graph.nodes[a];
  22607. if (n.attrParams.shape && n.attrParams.shape.value) {
  22608. var s = n.attrParams.shape.value,
  22609. o = s.length === r.shape.length && r.shape.every(function (e, t) {
  22610. return -1 === s[t] || s[t] === e;
  22611. });
  22612. _tfjsCore.util.assert(o, function () {
  22613. return "The shape of dict['" + n.name + "'] provided in model.execute(dict) must be [" + s + "], but was [" + r.shape + "]";
  22614. });
  22615. }
  22616. n.attrParams.dtype && n.attrParams.dtype.value && _tfjsCore.util.assert(r.dtype === n.attrParams.dtype.value, function () {
  22617. return "The dtype of dict['" + n.name + "'] provided in model.execute(dict) must be " + n.attrParams.dtype.value + ", but was " + r.dtype;
  22618. });
  22619. });
  22620. }, e.prototype.checkInputs = function (e) {
  22621. var t = this,
  22622. a = Object.keys(e).filter(function (e) {
  22623. return !t.graph.nodes[e];
  22624. });
  22625. if (a.length > 0) throw new Error("The dict provided in model.execute(dict) has keys: [" + a + "] that are not part of graph");
  22626. }, e.prototype.checkOutputs = function (e) {
  22627. var t = this;
  22628. e.forEach(function (e) {
  22629. var a = parseNodeName(e)[0];
  22630. if (!t.graph.nodes[a]) throw new Error("The output '" + e + "' is not found in the graph");
  22631. });
  22632. }, e;
  22633. }(),
  22634. TFHUB_SEARCH_PARAM = "?tfjs-format=file",
  22635. DEFAULT_MODEL_NAME = "model.json",
  22636. GraphModel = function () {
  22637. function e(e, t) {
  22638. void 0 === t && (t = {}), this.modelUrl = e, this.loadOptions = t, this.version = "n/a", null == t && (this.loadOptions = {});
  22639. }
  22640. return Object.defineProperty(e.prototype, "modelVersion", {
  22641. get: function () {
  22642. return this.version;
  22643. },
  22644. enumerable: !0,
  22645. configurable: !0
  22646. }), Object.defineProperty(e.prototype, "inputNodes", {
  22647. get: function () {
  22648. return this.executor.inputNodes;
  22649. },
  22650. enumerable: !0,
  22651. configurable: !0
  22652. }), Object.defineProperty(e.prototype, "outputNodes", {
  22653. get: function () {
  22654. return this.executor.outputNodes;
  22655. },
  22656. enumerable: !0,
  22657. configurable: !0
  22658. }), Object.defineProperty(e.prototype, "inputs", {
  22659. get: function () {
  22660. return this.executor.inputs;
  22661. },
  22662. enumerable: !0,
  22663. configurable: !0
  22664. }), Object.defineProperty(e.prototype, "outputs", {
  22665. get: function () {
  22666. return this.executor.outputs;
  22667. },
  22668. enumerable: !0,
  22669. configurable: !0
  22670. }), Object.defineProperty(e.prototype, "weights", {
  22671. get: function () {
  22672. return this.executor.weightMap;
  22673. },
  22674. enumerable: !0,
  22675. configurable: !0
  22676. }), e.prototype.findIOHandler = function () {
  22677. var e = this.modelUrl;
  22678. if (null != e.load) this.handler = e; else if (null != this.loadOptions.requestInit) this.handler = _tfjsCore.io.browserHTTPRequest(e, this.loadOptions); else {
  22679. var t = _tfjsCore.io.getLoadHandlers(e, this.loadOptions.onProgress);
  22680. if (0 === t.length) t.push(_tfjsCore.io.browserHTTPRequest(e, this.loadOptions)); else if (t.length > 1) throw new Error("Found more than one (" + t.length + ") load handlers for URL '" + [e] + "'");
  22681. this.handler = t[0];
  22682. }
  22683. }, e.prototype.load = function () {
  22684. return __awaiter(this, void 0, void 0, function () {
  22685. var e, t, a;
  22686. return __generator(this, function (r) {
  22687. switch (r.label) {
  22688. case 0:
  22689. if (this.findIOHandler(), null == this.handler.load) throw new Error("Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.");
  22690. return [4, this.handler.load()];
  22691. case 1:
  22692. return e = r.sent(), t = e.modelTopology, this.version = t.versions.producer + "." + t.versions.minConsumer, a = _tfjsCore.io.decodeWeights(e.weightData, e.weightSpecs), this.executor = new GraphExecutor(OperationMapper.Instance.transformGraph(t)), this.executor.weightMap = this.convertTensorMapToTensorsMap(a), [2, !0];
  22693. }
  22694. });
  22695. });
  22696. }, e.prototype.predict = function (e, t) {
  22697. return this.execute(e, this.outputNodes);
  22698. }, e.prototype.normalizeInputs = function (e) {
  22699. if (!(e instanceof _tfjsCore.Tensor || Array.isArray(e))) return e;
  22700. if ((e = Array.isArray(e) ? e : [e]).length !== this.inputNodes.length) throw new Error("Input tensor count mismatch,the graph model has " + this.inputNodes.length + " placeholders, while there are " + e.length + " input tensors.");
  22701. return this.inputNodes.reduce(function (t, a, r) {
  22702. return t[a] = e[r], t;
  22703. }, {});
  22704. }, e.prototype.normalizeOutputs = function (e) {
  22705. return e = e || this.outputNodes, Array.isArray(e) ? e : [e];
  22706. }, e.prototype.execute = function (e, t) {
  22707. e = this.normalizeInputs(e), t = this.normalizeOutputs(t);
  22708. var a = this.executor.execute(e, t);
  22709. return a.length > 1 ? a : a[0];
  22710. }, e.prototype.executeAsync = function (e, t) {
  22711. return __awaiter(this, void 0, void 0, function () {
  22712. var a;
  22713. return __generator(this, function (r) {
  22714. switch (r.label) {
  22715. case 0:
  22716. return e = this.normalizeInputs(e), t = this.normalizeOutputs(t), [4, this.executor.executeAsync(e, t)];
  22717. case 1:
  22718. return [2, (a = r.sent()).length > 1 ? a : a[0]];
  22719. }
  22720. });
  22721. });
  22722. }, e.prototype.convertTensorMapToTensorsMap = function (e) {
  22723. return Object.keys(e).reduce(function (t, a) {
  22724. return t[a] = [e[a]], t;
  22725. }, {});
  22726. }, e.prototype.dispose = function () {
  22727. this.executor.dispose();
  22728. }, e;
  22729. }();
  22730. exports.GraphModel = GraphModel;
  22731. function loadGraphModel(e, t) {
  22732. return void 0 === t && (t = {}), __awaiter(this, void 0, void 0, function () {
  22733. var a;
  22734. return __generator(this, function (r) {
  22735. switch (r.label) {
  22736. case 0:
  22737. if (null == e) throw new Error("modelUrl in loadGraphModel() cannot be null. Please provide a url or an IOHandler that loads the model");
  22738. return null == t && (t = {}), t.fromTFHub && null == e.load && (e.endsWith("/") || (e += "/"), e = "" + e + DEFAULT_MODEL_NAME + TFHUB_SEARCH_PARAM), [4, (a = new GraphModel(e, t)).load()];
  22739. case 1:
  22740. return r.sent(), [2, a];
  22741. }
  22742. });
  22743. });
  22744. }
  22745. var version = "1.3.1";
  22746. exports.version_converter = version;
  22747. }, { "@tensorflow/tfjs-core": "node_modules/@tensorflow/tfjs-core/dist/tf-core.esm.js", "buffer": "node_modules/buffer/index.js" }], "node_modules/@tensorflow-models/posenet/dist/posenet.esm.js": [function (require, module, exports) {
  22748. "use strict";
  22749. Object.defineProperty(exports, "__esModule", {
  22750. value: true
  22751. });
  22752. exports.decodeMultiplePoses = decodeMultiplePoses;
  22753. exports.decodeSinglePose = decodeSinglePose;
  22754. exports.load = load;
  22755. exports.getAdjacentKeyPoints = getAdjacentKeyPoints;
  22756. exports.getBoundingBox = getBoundingBox;
  22757. exports.getBoundingBoxPoints = getBoundingBoxPoints;
  22758. exports.scaleAndFlipPoses = scaleAndFlipPoses;
  22759. exports.scalePose = scalePose;
  22760. exports.PoseNet = exports.poseChain = exports.partNames = exports.partIds = exports.partChannels = exports.MobileNet = void 0;
  22761. var tf = _interopRequireWildcard(require("@tensorflow/tfjs-core"));
  22762. var _tfjsConverter = require("@tensorflow/tfjs-converter");
  22763. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  22764. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  22765. /**
  22766. * @license
  22767. * Copyright 2019 Google LLC. All Rights Reserved.
  22768. * Licensed under the Apache License, Version 2.0 (the "License");
  22769. * you may not use this file except in compliance with the License.
  22770. * You may obtain a copy of the License at
  22771. *
  22772. * http://www.apache.org/licenses/LICENSE-2.0
  22773. *
  22774. * Unless required by applicable law or agreed to in writing, software
  22775. * distributed under the License is distributed on an "AS IS" BASIS,
  22776. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22777. * See the License for the specific language governing permissions and
  22778. * limitations under the License.
  22779. * =============================================================================
  22780. */
  22781. var extendStatics = function (e, t) {
  22782. return (extendStatics = Object.setPrototypeOf || {
  22783. __proto__: []
  22784. } instanceof Array && function (e, t) {
  22785. e.__proto__ = t;
  22786. } || function (e, t) {
  22787. for (var n in t) t.hasOwnProperty(n) && (e[n] = t[n]);
  22788. })(e, t);
  22789. };
  22790. function __extends(e, t) {
  22791. function n() {
  22792. this.constructor = e;
  22793. }
  22794. extendStatics(e, t), e.prototype = null === t ? Object.create(t) : (n.prototype = t.prototype, new n());
  22795. }
  22796. var __assign = function () {
  22797. return (__assign = Object.assign || function (e) {
  22798. for (var t, n = 1, r = arguments.length; n < r; n++) for (var o in t = arguments[n]) Object.prototype.hasOwnProperty.call(t, o) && (e[o] = t[o]);
  22799. return e;
  22800. }).apply(this, arguments);
  22801. };
  22802. function __awaiter(e, t, n, r) {
  22803. return new (n || (n = Promise))(function (o, i) {
  22804. function s(e) {
  22805. try {
  22806. a(r.next(e));
  22807. } catch (e) {
  22808. i(e);
  22809. }
  22810. }
  22811. function u(e) {
  22812. try {
  22813. a(r.throw(e));
  22814. } catch (e) {
  22815. i(e);
  22816. }
  22817. }
  22818. function a(e) {
  22819. e.done ? o(e.value) : new n(function (t) {
  22820. t(e.value);
  22821. }).then(s, u);
  22822. }
  22823. a((r = r.apply(e, t || [])).next());
  22824. });
  22825. }
  22826. function __generator(e, t) {
  22827. var n,
  22828. r,
  22829. o,
  22830. i,
  22831. s = {
  22832. label: 0,
  22833. sent: function () {
  22834. if (1 & o[0]) throw o[1];
  22835. return o[1];
  22836. },
  22837. trys: [],
  22838. ops: []
  22839. };
  22840. return i = {
  22841. next: u(0),
  22842. throw: u(1),
  22843. return: u(2)
  22844. }, "function" == typeof Symbol && (i[Symbol.iterator] = function () {
  22845. return this;
  22846. }), i;
  22847. function u(i) {
  22848. return function (u) {
  22849. return function (i) {
  22850. if (n) throw new TypeError("Generator is already executing.");
  22851. for (; s;) try {
  22852. if (n = 1, r && (o = 2 & i[0] ? r.return : i[0] ? r.throw || ((o = r.return) && o.call(r), 0) : r.next) && !(o = o.call(r, i[1])).done) return o;
  22853. switch (r = 0, o && (i = [2 & i[0], o.value]), i[0]) {
  22854. case 0:
  22855. case 1:
  22856. o = i;
  22857. break;
  22858. case 4:
  22859. return s.label++, {
  22860. value: i[1],
  22861. done: !1
  22862. };
  22863. case 5:
  22864. s.label++, r = i[1], i = [0];
  22865. continue;
  22866. case 7:
  22867. i = s.ops.pop(), s.trys.pop();
  22868. continue;
  22869. default:
  22870. if (!(o = (o = s.trys).length > 0 && o[o.length - 1]) && (6 === i[0] || 2 === i[0])) {
  22871. s = 0;
  22872. continue;
  22873. }
  22874. if (3 === i[0] && (!o || i[1] > o[0] && i[1] < o[3])) {
  22875. s.label = i[1];
  22876. break;
  22877. }
  22878. if (6 === i[0] && s.label < o[1]) {
  22879. s.label = o[1], o = i;
  22880. break;
  22881. }
  22882. if (o && s.label < o[2]) {
  22883. s.label = o[2], s.ops.push(i);
  22884. break;
  22885. }
  22886. o[2] && s.ops.pop(), s.trys.pop();
  22887. continue;
  22888. }
  22889. i = t.call(e, s);
  22890. } catch (e) {
  22891. i = [6, e], r = 0;
  22892. } finally {
  22893. n = o = 0;
  22894. }
  22895. if (5 & i[0]) throw i[1];
  22896. return {
  22897. value: i[0] ? i[1] : void 0,
  22898. done: !0
  22899. };
  22900. }([i, u]);
  22901. };
  22902. }
  22903. }
  22904. var BaseModel = function () {
  22905. function e(e, t) {
  22906. this.model = e, this.outputStride = t;
  22907. var n = this.model.inputs[0].shape;
  22908. tf.util.assert(-1 === n[1] && -1 === n[2], function () {
  22909. return "Input shape [" + n[1] + ", " + n[2] + "] must both be equal to or -1";
  22910. });
  22911. }
  22912. return e.prototype.predict = function (e) {
  22913. var t = this;
  22914. return (0, tf.tidy)(function () {
  22915. var n = t.preprocessInput(e.toFloat()).expandDims(0),
  22916. r = t.model.predict(n).map(function (e) {
  22917. return e.squeeze([0]);
  22918. }),
  22919. o = t.nameOutputResults(r);
  22920. return {
  22921. heatmapScores: o.heatmap.sigmoid(),
  22922. offsets: o.offsets,
  22923. displacementFwd: o.displacementFwd,
  22924. displacementBwd: o.displacementBwd
  22925. };
  22926. });
  22927. }, e.prototype.dispose = function () {
  22928. this.model.dispose();
  22929. }, e;
  22930. }(),
  22931. MobileNet = function (e) {
  22932. function t() {
  22933. return null !== e && e.apply(this, arguments) || this;
  22934. }
  22935. return __extends(t, e), t.prototype.preprocessInput = function (e) {
  22936. return (0, tf.tidy)(function () {
  22937. return (0, tf.div)(e, 127.5).sub(1);
  22938. });
  22939. }, t.prototype.nameOutputResults = function (e) {
  22940. return {
  22941. offsets: e[0],
  22942. heatmap: e[1],
  22943. displacementFwd: e[2],
  22944. displacementBwd: e[3]
  22945. };
  22946. }, t;
  22947. }(BaseModel);
  22948. exports.MobileNet = MobileNet;
  22949. function half(e) {
  22950. return Math.floor(e / 2);
  22951. }
  22952. var MaxHeap = function () {
  22953. function e(e, t) {
  22954. this.priorityQueue = new Array(e), this.numberOfElements = -1, this.getElementValue = t;
  22955. }
  22956. return e.prototype.enqueue = function (e) {
  22957. this.priorityQueue[++this.numberOfElements] = e, this.swim(this.numberOfElements);
  22958. }, e.prototype.dequeue = function () {
  22959. var e = this.priorityQueue[0];
  22960. return this.exchange(0, this.numberOfElements--), this.sink(0), this.priorityQueue[this.numberOfElements + 1] = null, e;
  22961. }, e.prototype.empty = function () {
  22962. return -1 === this.numberOfElements;
  22963. }, e.prototype.size = function () {
  22964. return this.numberOfElements + 1;
  22965. }, e.prototype.all = function () {
  22966. return this.priorityQueue.slice(0, this.numberOfElements + 1);
  22967. }, e.prototype.max = function () {
  22968. return this.priorityQueue[0];
  22969. }, e.prototype.swim = function (e) {
  22970. for (; e > 0 && this.less(half(e), e);) this.exchange(e, half(e)), e = half(e);
  22971. }, e.prototype.sink = function (e) {
  22972. for (; 2 * e <= this.numberOfElements;) {
  22973. var t = 2 * e;
  22974. if (t < this.numberOfElements && this.less(t, t + 1) && t++, !this.less(e, t)) break;
  22975. this.exchange(e, t), e = t;
  22976. }
  22977. }, e.prototype.getValueAt = function (e) {
  22978. return this.getElementValue(this.priorityQueue[e]);
  22979. }, e.prototype.less = function (e, t) {
  22980. return this.getValueAt(e) < this.getValueAt(t);
  22981. }, e.prototype.exchange = function (e, t) {
  22982. var n = this.priorityQueue[e];
  22983. this.priorityQueue[e] = this.priorityQueue[t], this.priorityQueue[t] = n;
  22984. }, e;
  22985. }();
  22986. function scoreIsMaximumInLocalWindow(e, t, n, r, o, i) {
  22987. for (var s = i.shape, u = s[0], a = s[1], l = !0, p = Math.max(n - o, 0), c = Math.min(n + o + 1, u), f = p; f < c; ++f) {
  22988. for (var d = Math.max(r - o, 0), h = Math.min(r + o + 1, a), m = d; m < h; ++m) if (i.get(f, m, e) > t) {
  22989. l = !1;
  22990. break;
  22991. }
  22992. if (!l) break;
  22993. }
  22994. return l;
  22995. }
  22996. function buildPartWithScoreQueue(e, t, n) {
  22997. for (var r = n.shape, o = r[0], i = r[1], s = r[2], u = new MaxHeap(o * i * s, function (e) {
  22998. return e.score;
  22999. }), a = 0; a < o; ++a) for (var l = 0; l < i; ++l) for (var p = 0; p < s; ++p) {
  23000. var c = n.get(a, l, p);
  23001. c < e || scoreIsMaximumInLocalWindow(p, c, a, l, t, n) && u.enqueue({
  23002. score: c,
  23003. part: {
  23004. heatmapY: a,
  23005. heatmapX: l,
  23006. id: p
  23007. }
  23008. });
  23009. }
  23010. return u;
  23011. }
  23012. var partNames = ["nose", "leftEye", "rightEye", "leftEar", "rightEar", "leftShoulder", "rightShoulder", "leftElbow", "rightElbow", "leftWrist", "rightWrist", "leftHip", "rightHip", "leftKnee", "rightKnee", "leftAnkle", "rightAnkle"],
  23013. NUM_KEYPOINTS = partNames.length,
  23014. partIds = partNames.reduce(function (e, t, n) {
  23015. return e[t] = n, e;
  23016. }, {}),
  23017. connectedPartNames = [["leftHip", "leftShoulder"], ["leftElbow", "leftShoulder"], ["leftElbow", "leftWrist"], ["leftHip", "leftKnee"], ["leftKnee", "leftAnkle"], ["rightHip", "rightShoulder"], ["rightElbow", "rightShoulder"], ["rightElbow", "rightWrist"], ["rightHip", "rightKnee"], ["rightKnee", "rightAnkle"], ["leftShoulder", "rightShoulder"], ["leftHip", "rightHip"]],
  23018. poseChain = [["nose", "leftEye"], ["leftEye", "leftEar"], ["nose", "rightEye"], ["rightEye", "rightEar"], ["nose", "leftShoulder"], ["leftShoulder", "leftElbow"], ["leftElbow", "leftWrist"], ["leftShoulder", "leftHip"], ["leftHip", "leftKnee"], ["leftKnee", "leftAnkle"], ["nose", "rightShoulder"], ["rightShoulder", "rightElbow"], ["rightElbow", "rightWrist"], ["rightShoulder", "rightHip"], ["rightHip", "rightKnee"], ["rightKnee", "rightAnkle"]],
  23019. connectedPartIndices = connectedPartNames.map(function (e) {
  23020. var t = e[0],
  23021. n = e[1];
  23022. return [partIds[t], partIds[n]];
  23023. }),
  23024. partChannels = ["left_face", "right_face", "right_upper_leg_front", "right_lower_leg_back", "right_upper_leg_back", "left_lower_leg_front", "left_upper_leg_front", "left_upper_leg_back", "left_lower_leg_back", "right_feet", "right_lower_leg_front", "left_feet", "torso_front", "torso_back", "right_upper_arm_front", "right_upper_arm_back", "right_lower_arm_back", "left_lower_arm_front", "left_upper_arm_front", "left_upper_arm_back", "left_lower_arm_back", "right_hand", "right_lower_arm_front", "left_hand"];
  23025. exports.partChannels = partChannels;
  23026. exports.poseChain = poseChain;
  23027. exports.partIds = partIds;
  23028. exports.partNames = partNames;
  23029. function getOffsetPoint(e, t, n, r) {
  23030. return {
  23031. y: r.get(e, t, n),
  23032. x: r.get(e, t, n + NUM_KEYPOINTS)
  23033. };
  23034. }
  23035. function getImageCoords(e, t, n) {
  23036. var r = getOffsetPoint(e.heatmapY, e.heatmapX, e.id, n),
  23037. o = r.y,
  23038. i = r.x;
  23039. return {
  23040. x: e.heatmapX * t + i,
  23041. y: e.heatmapY * t + o
  23042. };
  23043. }
  23044. function clamp(e, t, n) {
  23045. return e < t ? t : e > n ? n : e;
  23046. }
  23047. function squaredDistance(e, t, n, r) {
  23048. var o = n - e,
  23049. i = r - t;
  23050. return o * o + i * i;
  23051. }
  23052. function addVectors(e, t) {
  23053. return {
  23054. x: e.x + t.x,
  23055. y: e.y + t.y
  23056. };
  23057. }
  23058. var parentChildrenTuples = poseChain.map(function (e) {
  23059. var t = e[0],
  23060. n = e[1];
  23061. return [partIds[t], partIds[n]];
  23062. }),
  23063. parentToChildEdges = parentChildrenTuples.map(function (e) {
  23064. return e[1];
  23065. }),
  23066. childToParentEdges = parentChildrenTuples.map(function (e) {
  23067. return e[0];
  23068. });
  23069. function getDisplacement(e, t, n) {
  23070. var r = n.shape[2] / 2;
  23071. return {
  23072. y: n.get(t.y, t.x, e),
  23073. x: n.get(t.y, t.x, r + e)
  23074. };
  23075. }
  23076. function getStridedIndexNearPoint(e, t, n, r) {
  23077. return {
  23078. y: clamp(Math.round(e.y / t), 0, n - 1),
  23079. x: clamp(Math.round(e.x / t), 0, r - 1)
  23080. };
  23081. }
  23082. function traverseToTargetKeypoint(e, t, n, r, o, i, s, u) {
  23083. void 0 === u && (u = 2);
  23084. for (var a = r.shape, l = a[0], p = a[1], c = getDisplacement(e, getStridedIndexNearPoint(t.position, i, l, p), s), f = addVectors(t.position, c), d = 0; d < u; d++) {
  23085. var h = getStridedIndexNearPoint(f, i, l, p),
  23086. m = getOffsetPoint(h.y, h.x, n, o);
  23087. f = addVectors({
  23088. x: h.x * i,
  23089. y: h.y * i
  23090. }, {
  23091. x: m.x,
  23092. y: m.y
  23093. });
  23094. }
  23095. var g = getStridedIndexNearPoint(f, i, l, p),
  23096. _ = r.get(g.y, g.x, n);
  23097. return {
  23098. position: f,
  23099. part: partNames[n],
  23100. score: _
  23101. };
  23102. }
  23103. function decodePose(e, t, n, r, o, i) {
  23104. var s = t.shape[2],
  23105. u = parentToChildEdges.length,
  23106. a = new Array(s),
  23107. l = e.part,
  23108. p = e.score,
  23109. c = getImageCoords(l, r, n);
  23110. a[l.id] = {
  23111. score: p,
  23112. part: partNames[l.id],
  23113. position: c
  23114. };
  23115. for (var f = u - 1; f >= 0; --f) {
  23116. var d = parentToChildEdges[f],
  23117. h = childToParentEdges[f];
  23118. a[d] && !a[h] && (a[h] = traverseToTargetKeypoint(f, a[d], h, t, n, r, i));
  23119. }
  23120. for (f = 0; f < u; ++f) {
  23121. d = childToParentEdges[f], h = parentToChildEdges[f];
  23122. a[d] && !a[h] && (a[h] = traverseToTargetKeypoint(f, a[d], h, t, n, r, o));
  23123. }
  23124. return a;
  23125. }
  23126. function withinNmsRadiusOfCorrespondingPoint(e, t, n, r) {
  23127. var o = n.x,
  23128. i = n.y;
  23129. return e.some(function (e) {
  23130. var n = e.keypoints[r].position;
  23131. return squaredDistance(i, o, n.y, n.x) <= t;
  23132. });
  23133. }
  23134. function getInstanceScore(e, t, n) {
  23135. return n.reduce(function (n, r, o) {
  23136. var i = r.position,
  23137. s = r.score;
  23138. return withinNmsRadiusOfCorrespondingPoint(e, t, i, o) || (n += s), n;
  23139. }, 0) / n.length;
  23140. }
  23141. var kLocalMaximumRadius = 1;
  23142. function decodeMultiplePoses(e, t, n, r, o, i, s, u) {
  23143. void 0 === s && (s = .5), void 0 === u && (u = 20);
  23144. for (var a = [], l = buildPartWithScoreQueue(s, kLocalMaximumRadius, e), p = u * u; a.length < i && !l.empty();) {
  23145. var c = l.dequeue();
  23146. if (!withinNmsRadiusOfCorrespondingPoint(a, p, getImageCoords(c.part, o, t), c.part.id)) {
  23147. var f = decodePose(c, e, t, o, n, r),
  23148. d = getInstanceScore(a, p, f);
  23149. a.push({
  23150. keypoints: f,
  23151. score: d
  23152. });
  23153. }
  23154. }
  23155. return a;
  23156. }
  23157. function mod(e, t) {
  23158. return (0, tf.tidy)(function () {
  23159. var n = e.div((0, tf.scalar)(t, "int32"));
  23160. return e.sub(n.mul((0, tf.scalar)(t, "int32")));
  23161. });
  23162. }
  23163. function argmax2d(e) {
  23164. var t = e.shape,
  23165. n = t[0],
  23166. r = t[1],
  23167. o = t[2];
  23168. return (0, tf.tidy)(function () {
  23169. var t = e.reshape([n * r, o]).argMax(0),
  23170. i = t.div((0, tf.scalar)(r, "int32")).expandDims(1),
  23171. s = mod(t, r).expandDims(1);
  23172. return (0, tf.concat)([i, s], 1);
  23173. });
  23174. }
  23175. function getPointsConfidence(e, t) {
  23176. for (var n = t.shape[0], r = new Float32Array(n), o = 0; o < n; o++) {
  23177. var i = t.get(o, 0),
  23178. s = t.get(o, 1);
  23179. r[o] = e.get(i, s, o);
  23180. }
  23181. return r;
  23182. }
  23183. function getOffsetPoint$1(e, t, n, r) {
  23184. return {
  23185. y: r.get(e, t, n),
  23186. x: r.get(e, t, n + NUM_KEYPOINTS)
  23187. };
  23188. }
  23189. function getOffsetVectors(e, t) {
  23190. for (var n = [], r = 0; r < NUM_KEYPOINTS; r++) {
  23191. var o = getOffsetPoint$1(e.get(r, 0).valueOf(), e.get(r, 1).valueOf(), r, t),
  23192. i = o.x,
  23193. s = o.y;
  23194. n.push(s), n.push(i);
  23195. }
  23196. return (0, tf.tensor2d)(n, [NUM_KEYPOINTS, 2]);
  23197. }
  23198. function getOffsetPoints(e, t, n) {
  23199. return (0, tf.tidy)(function () {
  23200. var r = getOffsetVectors(e, n);
  23201. return e.toTensor().mul((0, tf.scalar)(t, "int32")).toFloat().add(r);
  23202. });
  23203. }
  23204. function decodeSinglePose(e, t, n) {
  23205. return __awaiter(this, void 0, void 0, function () {
  23206. var r, o, i, s, u, a, l, p, c, f;
  23207. return __generator(this, function (d) {
  23208. switch (d.label) {
  23209. case 0:
  23210. return r = 0, o = argmax2d(e), [4, Promise.all([e.buffer(), t.buffer(), o.buffer()])];
  23211. case 1:
  23212. return i = d.sent(), s = i[0], u = i[1], a = i[2], [4, (l = getOffsetPoints(a, n, u)).buffer()];
  23213. case 2:
  23214. return p = d.sent(), c = Array.from(getPointsConfidence(s, a)), f = c.map(function (e, t) {
  23215. return r += e, {
  23216. position: {
  23217. y: p.get(t, 0),
  23218. x: p.get(t, 1)
  23219. },
  23220. part: partNames[t],
  23221. score: e
  23222. };
  23223. }), o.dispose(), l.dispose(), [2, {
  23224. keypoints: f,
  23225. score: r / f.length
  23226. }];
  23227. }
  23228. });
  23229. });
  23230. }
  23231. // var MOBILENET_BASE_URL = "https://storage.googleapis.com/tfjs-models/savedmodel/posenet/mobilenet/",
  23232. var MOBILENET_BASE_URL = "https://cocorobo.cn/model/posenet/",
  23233. RESNET50_BASE_URL = "https://storage.googleapis.com/tfjs-models/savedmodel/posenet/resnet50/";
  23234. function resNet50Checkpoint(e, t) {
  23235. var n = "model-stride" + e + ".json";
  23236. return 4 === t ? RESNET50_BASE_URL + "float/" + n : RESNET50_BASE_URL + "quant" + t + "/" + n;
  23237. }
  23238. function mobileNetCheckpoint(e, t, n) {
  23239. var r = {
  23240. 1: "100",
  23241. .75: "075",
  23242. .5: "050"
  23243. },
  23244. o = "model-stride" + e + ".json";
  23245. return 4 === n ? MOBILENET_BASE_URL + "float/" + r[t] + "/" + o : MOBILENET_BASE_URL + o;
  23246. }
  23247. var imageNetMean = [-123.15, -115.9, -103.06],
  23248. ResNet = function (e) {
  23249. function t() {
  23250. return null !== e && e.apply(this, arguments) || this;
  23251. }
  23252. return __extends(t, e), t.prototype.preprocessInput = function (e) {
  23253. return e.add(imageNetMean);
  23254. }, t.prototype.nameOutputResults = function (e) {
  23255. var t = e[0],
  23256. n = e[1];
  23257. return {
  23258. offsets: e[2],
  23259. heatmap: e[3],
  23260. displacementFwd: t,
  23261. displacementBwd: n
  23262. };
  23263. }, t;
  23264. }(BaseModel);
  23265. function eitherPointDoesntMeetConfidence(e, t, n) {
  23266. return e < n || t < n;
  23267. }
  23268. function getAdjacentKeyPoints(e, t) {
  23269. return connectedPartIndices.reduce(function (n, r) {
  23270. var o = r[0],
  23271. i = r[1];
  23272. return eitherPointDoesntMeetConfidence(e[o].score, e[i].score, t) ? n : (n.push([e[o], e[i]]), n);
  23273. }, []);
  23274. }
  23275. var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
  23276. POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
  23277. function getBoundingBox(e) {
  23278. return e.reduce(function (e, t) {
  23279. var n = e.maxX,
  23280. r = e.maxY,
  23281. o = e.minX,
  23282. i = e.minY,
  23283. s = t.position,
  23284. u = s.x,
  23285. a = s.y;
  23286. return {
  23287. maxX: Math.max(n, u),
  23288. maxY: Math.max(r, a),
  23289. minX: Math.min(o, u),
  23290. minY: Math.min(i, a)
  23291. };
  23292. }, {
  23293. maxX: NEGATIVE_INFINITY,
  23294. maxY: NEGATIVE_INFINITY,
  23295. minX: POSITIVE_INFINITY,
  23296. minY: POSITIVE_INFINITY
  23297. });
  23298. }
  23299. function getBoundingBoxPoints(e) {
  23300. var t = getBoundingBox(e),
  23301. n = t.minX,
  23302. r = t.minY,
  23303. o = t.maxX,
  23304. i = t.maxY;
  23305. return [{
  23306. x: n,
  23307. y: r
  23308. }, {
  23309. x: o,
  23310. y: r
  23311. }, {
  23312. x: o,
  23313. y: i
  23314. }, {
  23315. x: n,
  23316. y: i
  23317. }];
  23318. }
  23319. function toTensorBuffers3D(e) {
  23320. return __awaiter(this, void 0, void 0, function () {
  23321. return __generator(this, function (t) {
  23322. return [2, Promise.all(e.map(function (e) {
  23323. return e.buffer();
  23324. }))];
  23325. });
  23326. });
  23327. }
  23328. function scalePose(e, t, n, r, o) {
  23329. return void 0 === r && (r = 0), void 0 === o && (o = 0), {
  23330. score: e.score,
  23331. keypoints: e.keypoints.map(function (e) {
  23332. var i = e.score,
  23333. s = e.part,
  23334. u = e.position;
  23335. return {
  23336. score: i,
  23337. part: s,
  23338. position: {
  23339. x: u.x * n + o,
  23340. y: u.y * t + r
  23341. }
  23342. };
  23343. })
  23344. };
  23345. }
  23346. function scalePoses(e, t, n, r, o) {
  23347. return void 0 === r && (r = 0), void 0 === o && (o = 0), 1 === n && 1 === t && 0 === r && 0 === o ? e : e.map(function (e) {
  23348. return scalePose(e, t, n, r, o);
  23349. });
  23350. }
  23351. function flipPoseHorizontal(e, t) {
  23352. return {
  23353. score: e.score,
  23354. keypoints: e.keypoints.map(function (e) {
  23355. var n = e.score,
  23356. r = e.part,
  23357. o = e.position;
  23358. return {
  23359. score: n,
  23360. part: r,
  23361. position: {
  23362. x: t - 1 - o.x,
  23363. y: o.y
  23364. }
  23365. };
  23366. })
  23367. };
  23368. }
  23369. function flipPosesHorizontal(e, t) {
  23370. return t <= 0 ? e : e.map(function (e) {
  23371. return flipPoseHorizontal(e, t);
  23372. });
  23373. }
  23374. function toValidInputResolution(e, t) {
  23375. return isValidInputResolution(e, t) ? e : Math.floor(e / t) * t + 1;
  23376. }
  23377. function validateInputResolution(e) {
  23378. tf.util.assert("number" == typeof e || "object" == typeof e, function () {
  23379. return "Invalid inputResolution " + e + ". Should be a number or an object with width and height";
  23380. }), "object" == typeof e && (tf.util.assert("number" == typeof e.width, function () {
  23381. return "inputResolution.width has a value of " + e.width + " which is invalid; it must be a number";
  23382. }), tf.util.assert("number" == typeof e.height, function () {
  23383. return "inputResolution.height has a value of " + e.height + " which is invalid; it must be a number";
  23384. }));
  23385. }
  23386. function getValidInputResolutionDimensions(e, t) {
  23387. return validateInputResolution(e), "object" == typeof e ? [toValidInputResolution(e.height, t), toValidInputResolution(e.width, t)] : [toValidInputResolution(e, t), toValidInputResolution(e, t)];
  23388. }
  23389. var VALID_OUTPUT_STRIDES = [8, 16, 32];
  23390. function assertValidOutputStride(e) {
  23391. tf.util.assert("number" == typeof e, function () {
  23392. return "outputStride is not a number";
  23393. }), tf.util.assert(VALID_OUTPUT_STRIDES.indexOf(e) >= 0, function () {
  23394. return "outputStride of " + e + " is invalid. It must be either 8, 16, or 32";
  23395. });
  23396. }
  23397. function isValidInputResolution(e, t) {
  23398. return (e - 1) % t == 0;
  23399. }
  23400. function assertValidResolution(e, t) {
  23401. tf.util.assert("number" == typeof e[0] && "number" == typeof e[1], function () {
  23402. return "both resolution values must be a number but had values " + e;
  23403. }), tf.util.assert(isValidInputResolution(e[0], t), function () {
  23404. return "height of " + e[0] + " is invalid for output stride " + t + ".";
  23405. }), tf.util.assert(isValidInputResolution(e[1], t), function () {
  23406. return "width of " + e[1] + " is invalid for output stride " + t + ".";
  23407. });
  23408. }
  23409. function getInputTensorDimensions(e) {
  23410. return e instanceof tf.Tensor ? [e.shape[0], e.shape[1]] : [e.height, e.width];
  23411. }
  23412. function toInputTensor(e) {
  23413. return e instanceof tf.Tensor ? e : tf.browser.fromPixels(e);
  23414. }
  23415. function padAndResizeTo(e, t) {
  23416. var n = t[0],
  23417. r = t[1],
  23418. o = getInputTensorDimensions(e),
  23419. i = o[0],
  23420. s = o[1],
  23421. u = r / n,
  23422. a = [0, 0, 0, 0],
  23423. l = a[0],
  23424. p = a[1],
  23425. c = a[2],
  23426. f = a[3];
  23427. return s / i < u ? (l = 0, p = 0, c = Math.round(.5 * (u * i - s)), f = Math.round(.5 * (u * i - s))) : (l = Math.round(.5 * (1 / u * s - i)), p = Math.round(.5 * (1 / u * s - i)), c = 0, f = 0), {
  23428. resized: (0, tf.tidy)(function () {
  23429. var t = toInputTensor(e);
  23430. return (t = (0, tf.pad3d)(t, [[l, p], [c, f], [0, 0]])).resizeBilinear([n, r]);
  23431. }),
  23432. padding: {
  23433. top: l,
  23434. left: c,
  23435. right: f,
  23436. bottom: p
  23437. }
  23438. };
  23439. }
  23440. function scaleAndFlipPoses(e, t, n, r, o) {
  23441. var i = t[0],
  23442. s = t[1],
  23443. u = n[0],
  23444. a = n[1],
  23445. l = scalePoses(e, (i + r.top + r.bottom) / u, (s + r.left + r.right) / a, -r.top, -r.left);
  23446. return o ? flipPosesHorizontal(l, s) : l;
  23447. }
  23448. var MOBILENET_V1_CONFIG = {
  23449. architecture: "MobileNetV1",
  23450. outputStride: 16,
  23451. multiplier: .75,
  23452. inputResolution: 257
  23453. },
  23454. VALID_ARCHITECTURE = ["MobileNetV1", "ResNet50"],
  23455. VALID_STRIDE = {
  23456. MobileNetV1: [8, 16, 32],
  23457. ResNet50: [32, 16]
  23458. },
  23459. VALID_MULTIPLIER = {
  23460. MobileNetV1: [.5, .75, 1],
  23461. ResNet50: [1]
  23462. },
  23463. VALID_QUANT_BYTES = [1, 2, 4];
  23464. function validateModelConfig(e) {
  23465. if (null == (e = e || MOBILENET_V1_CONFIG).architecture && (e.architecture = "MobileNetV1"), VALID_ARCHITECTURE.indexOf(e.architecture) < 0) throw new Error("Invalid architecture " + e.architecture + ". Should be one of " + VALID_ARCHITECTURE);
  23466. if (null == e.inputResolution && (e.inputResolution = 257), validateInputResolution(e.inputResolution), null == e.outputStride && (e.outputStride = 16), VALID_STRIDE[e.architecture].indexOf(e.outputStride) < 0) throw new Error("Invalid outputStride " + e.outputStride + ". Should be one of " + VALID_STRIDE[e.architecture] + " for architecutre " + e.architecture + ".");
  23467. if (null == e.multiplier && (e.multiplier = 1), VALID_MULTIPLIER[e.architecture].indexOf(e.multiplier) < 0) throw new Error("Invalid multiplier " + e.multiplier + ". Should be one of " + VALID_MULTIPLIER[e.architecture] + " for architecutre " + e.architecture + ".");
  23468. if (null == e.quantBytes && (e.quantBytes = 4), VALID_QUANT_BYTES.indexOf(e.quantBytes) < 0) throw new Error("Invalid quantBytes " + e.quantBytes + ". Should be one of " + VALID_QUANT_BYTES + " for architecutre " + e.architecture + ".");
  23469. return e;
  23470. }
  23471. var SINGLE_PERSON_INFERENCE_CONFIG = {
  23472. flipHorizontal: !1
  23473. },
  23474. MULTI_PERSON_INFERENCE_CONFIG = {
  23475. flipHorizontal: !1,
  23476. maxDetections: 5,
  23477. scoreThreshold: .5,
  23478. nmsRadius: 20
  23479. };
  23480. function validateMultiPersonInputConfig(e) {
  23481. var t = e.maxDetections,
  23482. n = e.scoreThreshold,
  23483. r = e.nmsRadius;
  23484. if (t <= 0) throw new Error("Invalid maxDetections " + t + ". Should be > 0");
  23485. if (n < 0 || n > 1) throw new Error("Invalid scoreThreshold " + n + ". Should be in range [0.0, 1.0]");
  23486. if (r <= 0) throw new Error("Invalid nmsRadius " + r + ".");
  23487. }
  23488. var PoseNet = function () {
  23489. function e(e, t) {
  23490. assertValidOutputStride(e.outputStride), assertValidResolution(t, e.outputStride), this.baseModel = e, this.inputResolution = t;
  23491. }
  23492. return e.prototype.estimateMultiplePoses = function (e, t) {
  23493. return void 0 === t && (t = MULTI_PERSON_INFERENCE_CONFIG), __awaiter(this, void 0, void 0, function () {
  23494. var n, r, o, i, s, u, a, l, p, c, f, d, h, m, g, _, I, v, y, E, b;
  23495. return __generator(this, function (N) {
  23496. switch (N.label) {
  23497. case 0:
  23498. return n = __assign({}, MULTI_PERSON_INFERENCE_CONFIG, t), validateMultiPersonInputConfig(t), r = this.baseModel.outputStride, o = this.inputResolution, i = getInputTensorDimensions(e), s = i[0], u = i[1], a = padAndResizeTo(e, o), l = a.resized, p = a.padding, c = this.baseModel.predict(l), f = c.heatmapScores, d = c.offsets, h = c.displacementFwd, m = c.displacementBwd, [4, toTensorBuffers3D([f, d, h, m])];
  23499. case 1:
  23500. return g = N.sent(), _ = g[0], I = g[1], v = g[2], y = g[3], [4, decodeMultiplePoses(_, I, v, y, r, n.maxDetections, n.scoreThreshold, n.nmsRadius)];
  23501. case 2:
  23502. return E = N.sent(), b = scaleAndFlipPoses(E, [s, u], o, p, n.flipHorizontal), f.dispose(), d.dispose(), h.dispose(), m.dispose(), l.dispose(), [2, b];
  23503. }
  23504. });
  23505. });
  23506. }, e.prototype.estimateSinglePose = function (e, t) {
  23507. return void 0 === t && (t = SINGLE_PERSON_INFERENCE_CONFIG), __awaiter(this, void 0, void 0, function () {
  23508. var n, r, o, i, s, u, a, l, p, c, f, d, h, m, g, _;
  23509. return __generator(this, function (I) {
  23510. switch (I.label) {
  23511. case 0:
  23512. return n = __assign({}, SINGLE_PERSON_INFERENCE_CONFIG, t), r = this.baseModel.outputStride, o = this.inputResolution, i = getInputTensorDimensions(e), s = i[0], u = i[1], a = padAndResizeTo(e, o), l = a.resized, p = a.padding, c = this.baseModel.predict(l), f = c.heatmapScores, d = c.offsets, h = c.displacementFwd, m = c.displacementBwd, [4, decodeSinglePose(f, d, r)];
  23513. case 1:
  23514. return g = I.sent(), _ = scaleAndFlipPoses([g], [s, u], o, p, n.flipHorizontal), f.dispose(), d.dispose(), h.dispose(), m.dispose(), l.dispose(), [2, _[0]];
  23515. }
  23516. });
  23517. });
  23518. }, e.prototype.estimatePoses = function (e, t) {
  23519. return __awaiter(this, void 0, void 0, function () {
  23520. return __generator(this, function (n) {
  23521. switch (n.label) {
  23522. case 0:
  23523. return "single-person" !== t.decodingMethod ? [3, 2] : [4, this.estimateSinglePose(e, t)];
  23524. case 1:
  23525. return [2, [n.sent()]];
  23526. case 2:
  23527. return [2, this.estimateMultiplePoses(e, t)];
  23528. }
  23529. });
  23530. });
  23531. }, e.prototype.dispose = function () {
  23532. this.baseModel.dispose();
  23533. }, e;
  23534. }();
  23535. exports.PoseNet = PoseNet;
  23536. function loadMobileNet(e) {
  23537. return __awaiter(this, void 0, void 0, function () {
  23538. var t, n, r, o, i, s, u;
  23539. return __generator(this, function (a) {
  23540. switch (a.label) {
  23541. case 0:
  23542. if (t = e.outputStride, n = e.quantBytes, r = e.multiplier, null == tf) throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this\n model.");
  23543. return o = mobileNetCheckpoint(t, r, n), [4, (0, _tfjsConverter.loadGraphModel)(e.modelUrl || o)];
  23544. case 1:
  23545. return i = a.sent(), s = new MobileNet(i, t), u = getValidInputResolutionDimensions(e.inputResolution, s.outputStride), [2, new PoseNet(s, u)];
  23546. }
  23547. });
  23548. });
  23549. }
  23550. function loadResNet(e) {
  23551. return __awaiter(this, void 0, void 0, function () {
  23552. var t, n, r, o, i, s;
  23553. return __generator(this, function (u) {
  23554. switch (u.label) {
  23555. case 0:
  23556. if (t = e.outputStride, n = e.quantBytes, null == tf) throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this\n model.");
  23557. return r = resNet50Checkpoint(t, n), [4, (0, _tfjsConverter.loadGraphModel)(e.modelUrl || r)];
  23558. case 1:
  23559. return o = u.sent(), i = new ResNet(o, t), s = getValidInputResolutionDimensions(e.inputResolution, i.outputStride), [2, new PoseNet(i, s)];
  23560. }
  23561. });
  23562. });
  23563. }
  23564. function load(e) {
  23565. return void 0 === e && (e = MOBILENET_V1_CONFIG), __awaiter(this, void 0, void 0, function () {
  23566. return __generator(this, function (t) {
  23567. return "ResNet50" === (e = validateModelConfig(e)).architecture ? [2, loadResNet(e)] : "MobileNetV1" === e.architecture ? [2, loadMobileNet(e)] : [2, null];
  23568. });
  23569. });
  23570. }
  23571. }, { "@tensorflow/tfjs-core": "node_modules/@tensorflow/tfjs-core/dist/tf-core.esm.js", "@tensorflow/tfjs-converter": "node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js" }], "node_modules/dat.gui/build/dat.gui.module.js": [function (require, module, exports) {
  23572. "use strict";
  23573. Object.defineProperty(exports, "__esModule", {
  23574. value: true
  23575. });
  23576. exports.default = exports.GUI = exports.gui = exports.dom = exports.controllers = exports.color = void 0;
  23577. /**
  23578. * dat-gui JavaScript Controller Library
  23579. * http://code.google.com/p/dat-gui
  23580. *
  23581. * Copyright 2011 Data Arts Team, Google Creative Lab
  23582. *
  23583. * Licensed under the Apache License, Version 2.0 (the "License");
  23584. * you may not use this file except in compliance with the License.
  23585. * You may obtain a copy of the License at
  23586. *
  23587. * http://www.apache.org/licenses/LICENSE-2.0
  23588. */
  23589. function ___$insertStyle(css) {
  23590. if (!css) {
  23591. return;
  23592. }
  23593. if (typeof window === 'undefined') {
  23594. return;
  23595. }
  23596. var style = document.createElement('style');
  23597. style.setAttribute('type', 'text/css');
  23598. style.innerHTML = css;
  23599. document.head.appendChild(style);
  23600. return css;
  23601. }
  23602. function colorToString(color, forceCSSHex) {
  23603. var colorFormat = color.__state.conversionName.toString();
  23604. var r = Math.round(color.r);
  23605. var g = Math.round(color.g);
  23606. var b = Math.round(color.b);
  23607. var a = color.a;
  23608. var h = Math.round(color.h);
  23609. var s = color.s.toFixed(1);
  23610. var v = color.v.toFixed(1);
  23611. if (forceCSSHex || colorFormat === 'THREE_CHAR_HEX' || colorFormat === 'SIX_CHAR_HEX') {
  23612. var str = color.hex.toString(16);
  23613. while (str.length < 6) {
  23614. str = '0' + str;
  23615. }
  23616. return '#' + str;
  23617. } else if (colorFormat === 'CSS_RGB') {
  23618. return 'rgb(' + r + ',' + g + ',' + b + ')';
  23619. } else if (colorFormat === 'CSS_RGBA') {
  23620. return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
  23621. } else if (colorFormat === 'HEX') {
  23622. return '0x' + color.hex.toString(16);
  23623. } else if (colorFormat === 'RGB_ARRAY') {
  23624. return '[' + r + ',' + g + ',' + b + ']';
  23625. } else if (colorFormat === 'RGBA_ARRAY') {
  23626. return '[' + r + ',' + g + ',' + b + ',' + a + ']';
  23627. } else if (colorFormat === 'RGB_OBJ') {
  23628. return '{r:' + r + ',g:' + g + ',b:' + b + '}';
  23629. } else if (colorFormat === 'RGBA_OBJ') {
  23630. return '{r:' + r + ',g:' + g + ',b:' + b + ',a:' + a + '}';
  23631. } else if (colorFormat === 'HSV_OBJ') {
  23632. return '{h:' + h + ',s:' + s + ',v:' + v + '}';
  23633. } else if (colorFormat === 'HSVA_OBJ') {
  23634. return '{h:' + h + ',s:' + s + ',v:' + v + ',a:' + a + '}';
  23635. }
  23636. return 'unknown format';
  23637. }
  23638. var ARR_EACH = Array.prototype.forEach;
  23639. var ARR_SLICE = Array.prototype.slice;
  23640. var Common = {
  23641. BREAK: {},
  23642. extend: function extend(target) {
  23643. this.each(ARR_SLICE.call(arguments, 1), function (obj) {
  23644. var keys = this.isObject(obj) ? Object.keys(obj) : [];
  23645. keys.forEach(function (key) {
  23646. if (!this.isUndefined(obj[key])) {
  23647. target[key] = obj[key];
  23648. }
  23649. }.bind(this));
  23650. }, this);
  23651. return target;
  23652. },
  23653. defaults: function defaults(target) {
  23654. this.each(ARR_SLICE.call(arguments, 1), function (obj) {
  23655. var keys = this.isObject(obj) ? Object.keys(obj) : [];
  23656. keys.forEach(function (key) {
  23657. if (this.isUndefined(target[key])) {
  23658. target[key] = obj[key];
  23659. }
  23660. }.bind(this));
  23661. }, this);
  23662. return target;
  23663. },
  23664. compose: function compose() {
  23665. var toCall = ARR_SLICE.call(arguments);
  23666. return function () {
  23667. var args = ARR_SLICE.call(arguments);
  23668. for (var i = toCall.length - 1; i >= 0; i--) {
  23669. args = [toCall[i].apply(this, args)];
  23670. }
  23671. return args[0];
  23672. };
  23673. },
  23674. each: function each(obj, itr, scope) {
  23675. if (!obj) {
  23676. return;
  23677. }
  23678. if (ARR_EACH && obj.forEach && obj.forEach === ARR_EACH) {
  23679. obj.forEach(itr, scope);
  23680. } else if (obj.length === obj.length + 0) {
  23681. var key = void 0;
  23682. var l = void 0;
  23683. for (key = 0, l = obj.length; key < l; key++) {
  23684. if (key in obj && itr.call(scope, obj[key], key) === this.BREAK) {
  23685. return;
  23686. }
  23687. }
  23688. } else {
  23689. for (var _key in obj) {
  23690. if (itr.call(scope, obj[_key], _key) === this.BREAK) {
  23691. return;
  23692. }
  23693. }
  23694. }
  23695. },
  23696. defer: function defer(fnc) {
  23697. setTimeout(fnc, 0);
  23698. },
  23699. debounce: function debounce(func, threshold, callImmediately) {
  23700. var timeout = void 0;
  23701. return function () {
  23702. var obj = this;
  23703. var args = arguments;
  23704. function delayed() {
  23705. timeout = null;
  23706. if (!callImmediately) func.apply(obj, args);
  23707. }
  23708. var callNow = callImmediately || !timeout;
  23709. clearTimeout(timeout);
  23710. timeout = setTimeout(delayed, threshold);
  23711. if (callNow) {
  23712. func.apply(obj, args);
  23713. }
  23714. };
  23715. },
  23716. toArray: function toArray(obj) {
  23717. if (obj.toArray) return obj.toArray();
  23718. return ARR_SLICE.call(obj);
  23719. },
  23720. isUndefined: function isUndefined(obj) {
  23721. return obj === undefined;
  23722. },
  23723. isNull: function isNull(obj) {
  23724. return obj === null;
  23725. },
  23726. isNaN: function (_isNaN) {
  23727. function isNaN(_x) {
  23728. return _isNaN.apply(this, arguments);
  23729. }
  23730. isNaN.toString = function () {
  23731. return _isNaN.toString();
  23732. };
  23733. return isNaN;
  23734. }(function (obj) {
  23735. return isNaN(obj);
  23736. }),
  23737. isArray: Array.isArray || function (obj) {
  23738. return obj.constructor === Array;
  23739. },
  23740. isObject: function isObject(obj) {
  23741. return obj === Object(obj);
  23742. },
  23743. isNumber: function isNumber(obj) {
  23744. return obj === obj + 0;
  23745. },
  23746. isString: function isString(obj) {
  23747. return obj === obj + '';
  23748. },
  23749. isBoolean: function isBoolean(obj) {
  23750. return obj === false || obj === true;
  23751. },
  23752. isFunction: function isFunction(obj) {
  23753. return Object.prototype.toString.call(obj) === '[object Function]';
  23754. }
  23755. };
  23756. var INTERPRETATIONS = [{
  23757. litmus: Common.isString,
  23758. conversions: {
  23759. THREE_CHAR_HEX: {
  23760. read: function read(original) {
  23761. var test = original.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i);
  23762. if (test === null) {
  23763. return false;
  23764. }
  23765. return {
  23766. space: 'HEX',
  23767. hex: parseInt('0x' + test[1].toString() + test[1].toString() + test[2].toString() + test[2].toString() + test[3].toString() + test[3].toString(), 0)
  23768. };
  23769. },
  23770. write: colorToString
  23771. },
  23772. SIX_CHAR_HEX: {
  23773. read: function read(original) {
  23774. var test = original.match(/^#([A-F0-9]{6})$/i);
  23775. if (test === null) {
  23776. return false;
  23777. }
  23778. return {
  23779. space: 'HEX',
  23780. hex: parseInt('0x' + test[1].toString(), 0)
  23781. };
  23782. },
  23783. write: colorToString
  23784. },
  23785. CSS_RGB: {
  23786. read: function read(original) {
  23787. var test = original.match(/^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/);
  23788. if (test === null) {
  23789. return false;
  23790. }
  23791. return {
  23792. space: 'RGB',
  23793. r: parseFloat(test[1]),
  23794. g: parseFloat(test[2]),
  23795. b: parseFloat(test[3])
  23796. };
  23797. },
  23798. write: colorToString
  23799. },
  23800. CSS_RGBA: {
  23801. read: function read(original) {
  23802. var test = original.match(/^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/);
  23803. if (test === null) {
  23804. return false;
  23805. }
  23806. return {
  23807. space: 'RGB',
  23808. r: parseFloat(test[1]),
  23809. g: parseFloat(test[2]),
  23810. b: parseFloat(test[3]),
  23811. a: parseFloat(test[4])
  23812. };
  23813. },
  23814. write: colorToString
  23815. }
  23816. }
  23817. }, {
  23818. litmus: Common.isNumber,
  23819. conversions: {
  23820. HEX: {
  23821. read: function read(original) {
  23822. return {
  23823. space: 'HEX',
  23824. hex: original,
  23825. conversionName: 'HEX'
  23826. };
  23827. },
  23828. write: function write(color) {
  23829. return color.hex;
  23830. }
  23831. }
  23832. }
  23833. }, {
  23834. litmus: Common.isArray,
  23835. conversions: {
  23836. RGB_ARRAY: {
  23837. read: function read(original) {
  23838. if (original.length !== 3) {
  23839. return false;
  23840. }
  23841. return {
  23842. space: 'RGB',
  23843. r: original[0],
  23844. g: original[1],
  23845. b: original[2]
  23846. };
  23847. },
  23848. write: function write(color) {
  23849. return [color.r, color.g, color.b];
  23850. }
  23851. },
  23852. RGBA_ARRAY: {
  23853. read: function read(original) {
  23854. if (original.length !== 4) return false;
  23855. return {
  23856. space: 'RGB',
  23857. r: original[0],
  23858. g: original[1],
  23859. b: original[2],
  23860. a: original[3]
  23861. };
  23862. },
  23863. write: function write(color) {
  23864. return [color.r, color.g, color.b, color.a];
  23865. }
  23866. }
  23867. }
  23868. }, {
  23869. litmus: Common.isObject,
  23870. conversions: {
  23871. RGBA_OBJ: {
  23872. read: function read(original) {
  23873. if (Common.isNumber(original.r) && Common.isNumber(original.g) && Common.isNumber(original.b) && Common.isNumber(original.a)) {
  23874. return {
  23875. space: 'RGB',
  23876. r: original.r,
  23877. g: original.g,
  23878. b: original.b,
  23879. a: original.a
  23880. };
  23881. }
  23882. return false;
  23883. },
  23884. write: function write(color) {
  23885. return {
  23886. r: color.r,
  23887. g: color.g,
  23888. b: color.b,
  23889. a: color.a
  23890. };
  23891. }
  23892. },
  23893. RGB_OBJ: {
  23894. read: function read(original) {
  23895. if (Common.isNumber(original.r) && Common.isNumber(original.g) && Common.isNumber(original.b)) {
  23896. return {
  23897. space: 'RGB',
  23898. r: original.r,
  23899. g: original.g,
  23900. b: original.b
  23901. };
  23902. }
  23903. return false;
  23904. },
  23905. write: function write(color) {
  23906. return {
  23907. r: color.r,
  23908. g: color.g,
  23909. b: color.b
  23910. };
  23911. }
  23912. },
  23913. HSVA_OBJ: {
  23914. read: function read(original) {
  23915. if (Common.isNumber(original.h) && Common.isNumber(original.s) && Common.isNumber(original.v) && Common.isNumber(original.a)) {
  23916. return {
  23917. space: 'HSV',
  23918. h: original.h,
  23919. s: original.s,
  23920. v: original.v,
  23921. a: original.a
  23922. };
  23923. }
  23924. return false;
  23925. },
  23926. write: function write(color) {
  23927. return {
  23928. h: color.h,
  23929. s: color.s,
  23930. v: color.v,
  23931. a: color.a
  23932. };
  23933. }
  23934. },
  23935. HSV_OBJ: {
  23936. read: function read(original) {
  23937. if (Common.isNumber(original.h) && Common.isNumber(original.s) && Common.isNumber(original.v)) {
  23938. return {
  23939. space: 'HSV',
  23940. h: original.h,
  23941. s: original.s,
  23942. v: original.v
  23943. };
  23944. }
  23945. return false;
  23946. },
  23947. write: function write(color) {
  23948. return {
  23949. h: color.h,
  23950. s: color.s,
  23951. v: color.v
  23952. };
  23953. }
  23954. }
  23955. }
  23956. }];
  23957. var result = void 0;
  23958. var toReturn = void 0;
  23959. var interpret = function interpret() {
  23960. toReturn = false;
  23961. var original = arguments.length > 1 ? Common.toArray(arguments) : arguments[0];
  23962. Common.each(INTERPRETATIONS, function (family) {
  23963. if (family.litmus(original)) {
  23964. Common.each(family.conversions, function (conversion, conversionName) {
  23965. result = conversion.read(original);
  23966. if (toReturn === false && result !== false) {
  23967. toReturn = result;
  23968. result.conversionName = conversionName;
  23969. result.conversion = conversion;
  23970. return Common.BREAK;
  23971. }
  23972. });
  23973. return Common.BREAK;
  23974. }
  23975. });
  23976. return toReturn;
  23977. };
  23978. var tmpComponent = void 0;
  23979. var ColorMath = {
  23980. hsv_to_rgb: function hsv_to_rgb(h, s, v) {
  23981. var hi = Math.floor(h / 60) % 6;
  23982. var f = h / 60 - Math.floor(h / 60);
  23983. var p = v * (1.0 - s);
  23984. var q = v * (1.0 - f * s);
  23985. var t = v * (1.0 - (1.0 - f) * s);
  23986. var c = [[v, t, p], [q, v, p], [p, v, t], [p, q, v], [t, p, v], [v, p, q]][hi];
  23987. return {
  23988. r: c[0] * 255,
  23989. g: c[1] * 255,
  23990. b: c[2] * 255
  23991. };
  23992. },
  23993. rgb_to_hsv: function rgb_to_hsv(r, g, b) {
  23994. var min = Math.min(r, g, b);
  23995. var max = Math.max(r, g, b);
  23996. var delta = max - min;
  23997. var h = void 0;
  23998. var s = void 0;
  23999. if (max !== 0) {
  24000. s = delta / max;
  24001. } else {
  24002. return {
  24003. h: NaN,
  24004. s: 0,
  24005. v: 0
  24006. };
  24007. }
  24008. if (r === max) {
  24009. h = (g - b) / delta;
  24010. } else if (g === max) {
  24011. h = 2 + (b - r) / delta;
  24012. } else {
  24013. h = 4 + (r - g) / delta;
  24014. }
  24015. h /= 6;
  24016. if (h < 0) {
  24017. h += 1;
  24018. }
  24019. return {
  24020. h: h * 360,
  24021. s: s,
  24022. v: max / 255
  24023. };
  24024. },
  24025. rgb_to_hex: function rgb_to_hex(r, g, b) {
  24026. var hex = this.hex_with_component(0, 2, r);
  24027. hex = this.hex_with_component(hex, 1, g);
  24028. hex = this.hex_with_component(hex, 0, b);
  24029. return hex;
  24030. },
  24031. component_from_hex: function component_from_hex(hex, componentIndex) {
  24032. return hex >> componentIndex * 8 & 0xFF;
  24033. },
  24034. hex_with_component: function hex_with_component(hex, componentIndex, value) {
  24035. return value << (tmpComponent = componentIndex * 8) | hex & ~(0xFF << tmpComponent);
  24036. }
  24037. };
  24038. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  24039. return typeof obj;
  24040. } : function (obj) {
  24041. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  24042. };
  24043. var classCallCheck = function (instance, Constructor) {
  24044. if (!(instance instanceof Constructor)) {
  24045. throw new TypeError("Cannot call a class as a function");
  24046. }
  24047. };
  24048. var createClass = function () {
  24049. function defineProperties(target, props) {
  24050. for (var i = 0; i < props.length; i++) {
  24051. var descriptor = props[i];
  24052. descriptor.enumerable = descriptor.enumerable || false;
  24053. descriptor.configurable = true;
  24054. if ("value" in descriptor) descriptor.writable = true;
  24055. Object.defineProperty(target, descriptor.key, descriptor);
  24056. }
  24057. }
  24058. return function (Constructor, protoProps, staticProps) {
  24059. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  24060. if (staticProps) defineProperties(Constructor, staticProps);
  24061. return Constructor;
  24062. };
  24063. }();
  24064. var get = function get(object, property, receiver) {
  24065. if (object === null) object = Function.prototype;
  24066. var desc = Object.getOwnPropertyDescriptor(object, property);
  24067. if (desc === undefined) {
  24068. var parent = Object.getPrototypeOf(object);
  24069. if (parent === null) {
  24070. return undefined;
  24071. } else {
  24072. return get(parent, property, receiver);
  24073. }
  24074. } else if ("value" in desc) {
  24075. return desc.value;
  24076. } else {
  24077. var getter = desc.get;
  24078. if (getter === undefined) {
  24079. return undefined;
  24080. }
  24081. return getter.call(receiver);
  24082. }
  24083. };
  24084. var inherits = function (subClass, superClass) {
  24085. if (typeof superClass !== "function" && superClass !== null) {
  24086. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  24087. }
  24088. subClass.prototype = Object.create(superClass && superClass.prototype, {
  24089. constructor: {
  24090. value: subClass,
  24091. enumerable: false,
  24092. writable: true,
  24093. configurable: true
  24094. }
  24095. });
  24096. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  24097. };
  24098. var possibleConstructorReturn = function (self, call) {
  24099. if (!self) {
  24100. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  24101. }
  24102. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  24103. };
  24104. var Color = function () {
  24105. function Color() {
  24106. classCallCheck(this, Color);
  24107. this.__state = interpret.apply(this, arguments);
  24108. if (this.__state === false) {
  24109. throw new Error('Failed to interpret color arguments');
  24110. }
  24111. this.__state.a = this.__state.a || 1;
  24112. }
  24113. createClass(Color, [{
  24114. key: 'toString',
  24115. value: function toString() {
  24116. return colorToString(this);
  24117. }
  24118. }, {
  24119. key: 'toHexString',
  24120. value: function toHexString() {
  24121. return colorToString(this, true);
  24122. }
  24123. }, {
  24124. key: 'toOriginal',
  24125. value: function toOriginal() {
  24126. return this.__state.conversion.write(this);
  24127. }
  24128. }]);
  24129. return Color;
  24130. }();
  24131. function defineRGBComponent(target, component, componentHexIndex) {
  24132. Object.defineProperty(target, component, {
  24133. get: function get$$1() {
  24134. if (this.__state.space === 'RGB') {
  24135. return this.__state[component];
  24136. }
  24137. Color.recalculateRGB(this, component, componentHexIndex);
  24138. return this.__state[component];
  24139. },
  24140. set: function set$$1(v) {
  24141. if (this.__state.space !== 'RGB') {
  24142. Color.recalculateRGB(this, component, componentHexIndex);
  24143. this.__state.space = 'RGB';
  24144. }
  24145. this.__state[component] = v;
  24146. }
  24147. });
  24148. }
  24149. function defineHSVComponent(target, component) {
  24150. Object.defineProperty(target, component, {
  24151. get: function get$$1() {
  24152. if (this.__state.space === 'HSV') {
  24153. return this.__state[component];
  24154. }
  24155. Color.recalculateHSV(this);
  24156. return this.__state[component];
  24157. },
  24158. set: function set$$1(v) {
  24159. if (this.__state.space !== 'HSV') {
  24160. Color.recalculateHSV(this);
  24161. this.__state.space = 'HSV';
  24162. }
  24163. this.__state[component] = v;
  24164. }
  24165. });
  24166. }
  24167. Color.recalculateRGB = function (color, component, componentHexIndex) {
  24168. if (color.__state.space === 'HEX') {
  24169. color.__state[component] = ColorMath.component_from_hex(color.__state.hex, componentHexIndex);
  24170. } else if (color.__state.space === 'HSV') {
  24171. Common.extend(color.__state, ColorMath.hsv_to_rgb(color.__state.h, color.__state.s, color.__state.v));
  24172. } else {
  24173. throw new Error('Corrupted color state');
  24174. }
  24175. };
  24176. Color.recalculateHSV = function (color) {
  24177. var result = ColorMath.rgb_to_hsv(color.r, color.g, color.b);
  24178. Common.extend(color.__state, {
  24179. s: result.s,
  24180. v: result.v
  24181. });
  24182. if (!Common.isNaN(result.h)) {
  24183. color.__state.h = result.h;
  24184. } else if (Common.isUndefined(color.__state.h)) {
  24185. color.__state.h = 0;
  24186. }
  24187. };
  24188. Color.COMPONENTS = ['r', 'g', 'b', 'h', 's', 'v', 'hex', 'a'];
  24189. defineRGBComponent(Color.prototype, 'r', 2);
  24190. defineRGBComponent(Color.prototype, 'g', 1);
  24191. defineRGBComponent(Color.prototype, 'b', 0);
  24192. defineHSVComponent(Color.prototype, 'h');
  24193. defineHSVComponent(Color.prototype, 's');
  24194. defineHSVComponent(Color.prototype, 'v');
  24195. Object.defineProperty(Color.prototype, 'a', {
  24196. get: function get$$1() {
  24197. return this.__state.a;
  24198. },
  24199. set: function set$$1(v) {
  24200. this.__state.a = v;
  24201. }
  24202. });
  24203. Object.defineProperty(Color.prototype, 'hex', {
  24204. get: function get$$1() {
  24205. if (!this.__state.space !== 'HEX') {
  24206. this.__state.hex = ColorMath.rgb_to_hex(this.r, this.g, this.b);
  24207. }
  24208. return this.__state.hex;
  24209. },
  24210. set: function set$$1(v) {
  24211. this.__state.space = 'HEX';
  24212. this.__state.hex = v;
  24213. }
  24214. });
  24215. var Controller = function () {
  24216. function Controller(object, property) {
  24217. classCallCheck(this, Controller);
  24218. this.initialValue = object[property];
  24219. this.domElement = document.createElement('div');
  24220. this.object = object;
  24221. this.property = property;
  24222. this.__onChange = undefined;
  24223. this.__onFinishChange = undefined;
  24224. }
  24225. createClass(Controller, [{
  24226. key: 'onChange',
  24227. value: function onChange(fnc) {
  24228. this.__onChange = fnc;
  24229. return this;
  24230. }
  24231. }, {
  24232. key: 'onFinishChange',
  24233. value: function onFinishChange(fnc) {
  24234. this.__onFinishChange = fnc;
  24235. return this;
  24236. }
  24237. }, {
  24238. key: 'setValue',
  24239. value: function setValue(newValue) {
  24240. this.object[this.property] = newValue;
  24241. if (this.__onChange) {
  24242. this.__onChange.call(this, newValue);
  24243. }
  24244. this.updateDisplay();
  24245. return this;
  24246. }
  24247. }, {
  24248. key: 'getValue',
  24249. value: function getValue() {
  24250. return this.object[this.property];
  24251. }
  24252. }, {
  24253. key: 'updateDisplay',
  24254. value: function updateDisplay() {
  24255. return this;
  24256. }
  24257. }, {
  24258. key: 'isModified',
  24259. value: function isModified() {
  24260. return this.initialValue !== this.getValue();
  24261. }
  24262. }]);
  24263. return Controller;
  24264. }();
  24265. var EVENT_MAP = {
  24266. HTMLEvents: ['change'],
  24267. MouseEvents: ['click', 'mousemove', 'mousedown', 'mouseup', 'mouseover'],
  24268. KeyboardEvents: ['keydown']
  24269. };
  24270. var EVENT_MAP_INV = {};
  24271. Common.each(EVENT_MAP, function (v, k) {
  24272. Common.each(v, function (e) {
  24273. EVENT_MAP_INV[e] = k;
  24274. });
  24275. });
  24276. var CSS_VALUE_PIXELS = /(\d+(\.\d+)?)px/;
  24277. function cssValueToPixels(val) {
  24278. if (val === '0' || Common.isUndefined(val)) {
  24279. return 0;
  24280. }
  24281. var match = val.match(CSS_VALUE_PIXELS);
  24282. if (!Common.isNull(match)) {
  24283. return parseFloat(match[1]);
  24284. }
  24285. return 0;
  24286. }
  24287. var dom = {
  24288. makeSelectable: function makeSelectable(elem, selectable) {
  24289. if (elem === undefined || elem.style === undefined) return;
  24290. elem.onselectstart = selectable ? function () {
  24291. return false;
  24292. } : function () { };
  24293. elem.style.MozUserSelect = selectable ? 'auto' : 'none';
  24294. elem.style.KhtmlUserSelect = selectable ? 'auto' : 'none';
  24295. elem.unselectable = selectable ? 'on' : 'off';
  24296. },
  24297. makeFullscreen: function makeFullscreen(elem, hor, vert) {
  24298. var vertical = vert;
  24299. var horizontal = hor;
  24300. if (Common.isUndefined(horizontal)) {
  24301. horizontal = true;
  24302. }
  24303. if (Common.isUndefined(vertical)) {
  24304. vertical = true;
  24305. }
  24306. elem.style.position = 'absolute';
  24307. if (horizontal) {
  24308. elem.style.left = 0;
  24309. elem.style.right = 0;
  24310. }
  24311. if (vertical) {
  24312. elem.style.top = 0;
  24313. elem.style.bottom = 0;
  24314. }
  24315. },
  24316. fakeEvent: function fakeEvent(elem, eventType, pars, aux) {
  24317. var params = pars || {};
  24318. var className = EVENT_MAP_INV[eventType];
  24319. if (!className) {
  24320. throw new Error('Event type ' + eventType + ' not supported.');
  24321. }
  24322. var evt = document.createEvent(className);
  24323. switch (className) {
  24324. case 'MouseEvents':
  24325. {
  24326. var clientX = params.x || params.clientX || 0;
  24327. var clientY = params.y || params.clientY || 0;
  24328. evt.initMouseEvent(eventType, params.bubbles || false, params.cancelable || true, window, params.clickCount || 1, 0, 0, clientX, clientY, false, false, false, false, 0, null);
  24329. break;
  24330. }
  24331. case 'KeyboardEvents':
  24332. {
  24333. var init = evt.initKeyboardEvent || evt.initKeyEvent;
  24334. Common.defaults(params, {
  24335. cancelable: true,
  24336. ctrlKey: false,
  24337. altKey: false,
  24338. shiftKey: false,
  24339. metaKey: false,
  24340. keyCode: undefined,
  24341. charCode: undefined
  24342. });
  24343. init(eventType, params.bubbles || false, params.cancelable, window, params.ctrlKey, params.altKey, params.shiftKey, params.metaKey, params.keyCode, params.charCode);
  24344. break;
  24345. }
  24346. default:
  24347. {
  24348. evt.initEvent(eventType, params.bubbles || false, params.cancelable || true);
  24349. break;
  24350. }
  24351. }
  24352. Common.defaults(evt, aux);
  24353. elem.dispatchEvent(evt);
  24354. },
  24355. bind: function bind(elem, event, func, newBool) {
  24356. var bool = newBool || false;
  24357. if (elem.addEventListener) {
  24358. elem.addEventListener(event, func, bool);
  24359. } else if (elem.attachEvent) {
  24360. elem.attachEvent('on' + event, func);
  24361. }
  24362. return dom;
  24363. },
  24364. unbind: function unbind(elem, event, func, newBool) {
  24365. var bool = newBool || false;
  24366. if (elem.removeEventListener) {
  24367. elem.removeEventListener(event, func, bool);
  24368. } else if (elem.detachEvent) {
  24369. elem.detachEvent('on' + event, func);
  24370. }
  24371. return dom;
  24372. },
  24373. addClass: function addClass(elem, className) {
  24374. if (elem.className === undefined) {
  24375. elem.className = className;
  24376. } else if (elem.className !== className) {
  24377. var classes = elem.className.split(/ +/);
  24378. if (classes.indexOf(className) === -1) {
  24379. classes.push(className);
  24380. elem.className = classes.join(' ').replace(/^\s+/, '').replace(/\s+$/, '');
  24381. }
  24382. }
  24383. return dom;
  24384. },
  24385. removeClass: function removeClass(elem, className) {
  24386. if (className) {
  24387. if (elem.className === className) {
  24388. elem.removeAttribute('class');
  24389. } else {
  24390. var classes = elem.className.split(/ +/);
  24391. var index = classes.indexOf(className);
  24392. if (index !== -1) {
  24393. classes.splice(index, 1);
  24394. elem.className = classes.join(' ');
  24395. }
  24396. }
  24397. } else {
  24398. elem.className = undefined;
  24399. }
  24400. return dom;
  24401. },
  24402. hasClass: function hasClass(elem, className) {
  24403. return new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)').test(elem.className) || false;
  24404. },
  24405. getWidth: function getWidth(elem) {
  24406. var style = getComputedStyle(elem);
  24407. return cssValueToPixels(style['border-left-width']) + cssValueToPixels(style['border-right-width']) + cssValueToPixels(style['padding-left']) + cssValueToPixels(style['padding-right']) + cssValueToPixels(style.width);
  24408. },
  24409. getHeight: function getHeight(elem) {
  24410. var style = getComputedStyle(elem);
  24411. return cssValueToPixels(style['border-top-width']) + cssValueToPixels(style['border-bottom-width']) + cssValueToPixels(style['padding-top']) + cssValueToPixels(style['padding-bottom']) + cssValueToPixels(style.height);
  24412. },
  24413. getOffset: function getOffset(el) {
  24414. var elem = el;
  24415. var offset = {
  24416. left: 0,
  24417. top: 0
  24418. };
  24419. if (elem.offsetParent) {
  24420. do {
  24421. offset.left += elem.offsetLeft;
  24422. offset.top += elem.offsetTop;
  24423. elem = elem.offsetParent;
  24424. } while (elem);
  24425. }
  24426. return offset;
  24427. },
  24428. isActive: function isActive(elem) {
  24429. return elem === document.activeElement && (elem.type || elem.href);
  24430. }
  24431. };
  24432. var BooleanController = function (_Controller) {
  24433. inherits(BooleanController, _Controller);
  24434. function BooleanController(object, property) {
  24435. classCallCheck(this, BooleanController);
  24436. var _this2 = possibleConstructorReturn(this, (BooleanController.__proto__ || Object.getPrototypeOf(BooleanController)).call(this, object, property));
  24437. var _this = _this2;
  24438. _this2.__prev = _this2.getValue();
  24439. _this2.__checkbox = document.createElement('input');
  24440. _this2.__checkbox.setAttribute('type', 'checkbox');
  24441. function onChange() {
  24442. _this.setValue(!_this.__prev);
  24443. }
  24444. dom.bind(_this2.__checkbox, 'change', onChange, false);
  24445. _this2.domElement.appendChild(_this2.__checkbox);
  24446. _this2.updateDisplay();
  24447. return _this2;
  24448. }
  24449. createClass(BooleanController, [{
  24450. key: 'setValue',
  24451. value: function setValue(v) {
  24452. var toReturn = get(BooleanController.prototype.__proto__ || Object.getPrototypeOf(BooleanController.prototype), 'setValue', this).call(this, v);
  24453. if (this.__onFinishChange) {
  24454. this.__onFinishChange.call(this, this.getValue());
  24455. }
  24456. this.__prev = this.getValue();
  24457. return toReturn;
  24458. }
  24459. }, {
  24460. key: 'updateDisplay',
  24461. value: function updateDisplay() {
  24462. if (this.getValue() === true) {
  24463. this.__checkbox.setAttribute('checked', 'checked');
  24464. this.__checkbox.checked = true;
  24465. this.__prev = true;
  24466. } else {
  24467. this.__checkbox.checked = false;
  24468. this.__prev = false;
  24469. }
  24470. return get(BooleanController.prototype.__proto__ || Object.getPrototypeOf(BooleanController.prototype), 'updateDisplay', this).call(this);
  24471. }
  24472. }]);
  24473. return BooleanController;
  24474. }(Controller);
  24475. var OptionController = function (_Controller) {
  24476. inherits(OptionController, _Controller);
  24477. function OptionController(object, property, opts) {
  24478. classCallCheck(this, OptionController);
  24479. var _this2 = possibleConstructorReturn(this, (OptionController.__proto__ || Object.getPrototypeOf(OptionController)).call(this, object, property));
  24480. var options = opts;
  24481. var _this = _this2;
  24482. _this2.__select = document.createElement('select');
  24483. if (Common.isArray(options)) {
  24484. var map = {};
  24485. Common.each(options, function (element) {
  24486. map[element] = element;
  24487. });
  24488. options = map;
  24489. }
  24490. Common.each(options, function (value, key) {
  24491. var opt = document.createElement('option');
  24492. opt.innerHTML = key;
  24493. opt.setAttribute('value', value);
  24494. _this.__select.appendChild(opt);
  24495. });
  24496. _this2.updateDisplay();
  24497. dom.bind(_this2.__select, 'change', function () {
  24498. var desiredValue = this.options[this.selectedIndex].value;
  24499. _this.setValue(desiredValue);
  24500. });
  24501. _this2.domElement.appendChild(_this2.__select);
  24502. return _this2;
  24503. }
  24504. createClass(OptionController, [{
  24505. key: 'setValue',
  24506. value: function setValue(v) {
  24507. var toReturn = get(OptionController.prototype.__proto__ || Object.getPrototypeOf(OptionController.prototype), 'setValue', this).call(this, v);
  24508. if (this.__onFinishChange) {
  24509. this.__onFinishChange.call(this, this.getValue());
  24510. }
  24511. return toReturn;
  24512. }
  24513. }, {
  24514. key: 'updateDisplay',
  24515. value: function updateDisplay() {
  24516. if (dom.isActive(this.__select)) return this;
  24517. this.__select.value = this.getValue();
  24518. return get(OptionController.prototype.__proto__ || Object.getPrototypeOf(OptionController.prototype), 'updateDisplay', this).call(this);
  24519. }
  24520. }]);
  24521. return OptionController;
  24522. }(Controller);
  24523. var StringController = function (_Controller) {
  24524. inherits(StringController, _Controller);
  24525. function StringController(object, property) {
  24526. classCallCheck(this, StringController);
  24527. var _this2 = possibleConstructorReturn(this, (StringController.__proto__ || Object.getPrototypeOf(StringController)).call(this, object, property));
  24528. var _this = _this2;
  24529. function onChange() {
  24530. _this.setValue(_this.__input.value);
  24531. }
  24532. function onBlur() {
  24533. if (_this.__onFinishChange) {
  24534. _this.__onFinishChange.call(_this, _this.getValue());
  24535. }
  24536. }
  24537. _this2.__input = document.createElement('input');
  24538. _this2.__input.setAttribute('type', 'text');
  24539. dom.bind(_this2.__input, 'keyup', onChange);
  24540. dom.bind(_this2.__input, 'change', onChange);
  24541. dom.bind(_this2.__input, 'blur', onBlur);
  24542. dom.bind(_this2.__input, 'keydown', function (e) {
  24543. if (e.keyCode === 13) {
  24544. this.blur();
  24545. }
  24546. });
  24547. _this2.updateDisplay();
  24548. _this2.domElement.appendChild(_this2.__input);
  24549. return _this2;
  24550. }
  24551. createClass(StringController, [{
  24552. key: 'updateDisplay',
  24553. value: function updateDisplay() {
  24554. if (!dom.isActive(this.__input)) {
  24555. this.__input.value = this.getValue();
  24556. }
  24557. return get(StringController.prototype.__proto__ || Object.getPrototypeOf(StringController.prototype), 'updateDisplay', this).call(this);
  24558. }
  24559. }]);
  24560. return StringController;
  24561. }(Controller);
  24562. function numDecimals(x) {
  24563. var _x = x.toString();
  24564. if (_x.indexOf('.') > -1) {
  24565. return _x.length - _x.indexOf('.') - 1;
  24566. }
  24567. return 0;
  24568. }
  24569. var NumberController = function (_Controller) {
  24570. inherits(NumberController, _Controller);
  24571. function NumberController(object, property, params) {
  24572. classCallCheck(this, NumberController);
  24573. var _this = possibleConstructorReturn(this, (NumberController.__proto__ || Object.getPrototypeOf(NumberController)).call(this, object, property));
  24574. var _params = params || {};
  24575. _this.__min = _params.min;
  24576. _this.__max = _params.max;
  24577. _this.__step = _params.step;
  24578. if (Common.isUndefined(_this.__step)) {
  24579. if (_this.initialValue === 0) {
  24580. _this.__impliedStep = 1;
  24581. } else {
  24582. _this.__impliedStep = Math.pow(10, Math.floor(Math.log(Math.abs(_this.initialValue)) / Math.LN10)) / 10;
  24583. }
  24584. } else {
  24585. _this.__impliedStep = _this.__step;
  24586. }
  24587. _this.__precision = numDecimals(_this.__impliedStep);
  24588. return _this;
  24589. }
  24590. createClass(NumberController, [{
  24591. key: 'setValue',
  24592. value: function setValue(v) {
  24593. var _v = v;
  24594. if (this.__min !== undefined && _v < this.__min) {
  24595. _v = this.__min;
  24596. } else if (this.__max !== undefined && _v > this.__max) {
  24597. _v = this.__max;
  24598. }
  24599. if (this.__step !== undefined && _v % this.__step !== 0) {
  24600. _v = Math.round(_v / this.__step) * this.__step;
  24601. }
  24602. return get(NumberController.prototype.__proto__ || Object.getPrototypeOf(NumberController.prototype), 'setValue', this).call(this, _v);
  24603. }
  24604. }, {
  24605. key: 'min',
  24606. value: function min(minValue) {
  24607. this.__min = minValue;
  24608. return this;
  24609. }
  24610. }, {
  24611. key: 'max',
  24612. value: function max(maxValue) {
  24613. this.__max = maxValue;
  24614. return this;
  24615. }
  24616. }, {
  24617. key: 'step',
  24618. value: function step(stepValue) {
  24619. this.__step = stepValue;
  24620. this.__impliedStep = stepValue;
  24621. this.__precision = numDecimals(stepValue);
  24622. return this;
  24623. }
  24624. }]);
  24625. return NumberController;
  24626. }(Controller);
  24627. function roundToDecimal(value, decimals) {
  24628. var tenTo = Math.pow(10, decimals);
  24629. return Math.round(value * tenTo) / tenTo;
  24630. }
  24631. var NumberControllerBox = function (_NumberController) {
  24632. inherits(NumberControllerBox, _NumberController);
  24633. function NumberControllerBox(object, property, params) {
  24634. classCallCheck(this, NumberControllerBox);
  24635. var _this2 = possibleConstructorReturn(this, (NumberControllerBox.__proto__ || Object.getPrototypeOf(NumberControllerBox)).call(this, object, property, params));
  24636. _this2.__truncationSuspended = false;
  24637. var _this = _this2;
  24638. var prevY = void 0;
  24639. function onChange() {
  24640. var attempted = parseFloat(_this.__input.value);
  24641. if (!Common.isNaN(attempted)) {
  24642. _this.setValue(attempted);
  24643. }
  24644. }
  24645. function onFinish() {
  24646. if (_this.__onFinishChange) {
  24647. _this.__onFinishChange.call(_this, _this.getValue());
  24648. }
  24649. }
  24650. function onBlur() {
  24651. onFinish();
  24652. }
  24653. function onMouseDrag(e) {
  24654. var diff = prevY - e.clientY;
  24655. _this.setValue(_this.getValue() + diff * _this.__impliedStep);
  24656. prevY = e.clientY;
  24657. }
  24658. function onMouseUp() {
  24659. dom.unbind(window, 'mousemove', onMouseDrag);
  24660. dom.unbind(window, 'mouseup', onMouseUp);
  24661. onFinish();
  24662. }
  24663. function onMouseDown(e) {
  24664. dom.bind(window, 'mousemove', onMouseDrag);
  24665. dom.bind(window, 'mouseup', onMouseUp);
  24666. prevY = e.clientY;
  24667. }
  24668. _this2.__input = document.createElement('input');
  24669. _this2.__input.setAttribute('type', 'text');
  24670. dom.bind(_this2.__input, 'change', onChange);
  24671. dom.bind(_this2.__input, 'blur', onBlur);
  24672. dom.bind(_this2.__input, 'mousedown', onMouseDown);
  24673. dom.bind(_this2.__input, 'keydown', function (e) {
  24674. if (e.keyCode === 13) {
  24675. _this.__truncationSuspended = true;
  24676. this.blur();
  24677. _this.__truncationSuspended = false;
  24678. onFinish();
  24679. }
  24680. });
  24681. _this2.updateDisplay();
  24682. _this2.domElement.appendChild(_this2.__input);
  24683. return _this2;
  24684. }
  24685. createClass(NumberControllerBox, [{
  24686. key: 'updateDisplay',
  24687. value: function updateDisplay() {
  24688. this.__input.value = this.__truncationSuspended ? this.getValue() : roundToDecimal(this.getValue(), this.__precision);
  24689. return get(NumberControllerBox.prototype.__proto__ || Object.getPrototypeOf(NumberControllerBox.prototype), 'updateDisplay', this).call(this);
  24690. }
  24691. }]);
  24692. return NumberControllerBox;
  24693. }(NumberController);
  24694. function map(v, i1, i2, o1, o2) {
  24695. return o1 + (o2 - o1) * ((v - i1) / (i2 - i1));
  24696. }
  24697. var NumberControllerSlider = function (_NumberController) {
  24698. inherits(NumberControllerSlider, _NumberController);
  24699. function NumberControllerSlider(object, property, min, max, step) {
  24700. classCallCheck(this, NumberControllerSlider);
  24701. var _this2 = possibleConstructorReturn(this, (NumberControllerSlider.__proto__ || Object.getPrototypeOf(NumberControllerSlider)).call(this, object, property, {
  24702. min: min,
  24703. max: max,
  24704. step: step
  24705. }));
  24706. var _this = _this2;
  24707. _this2.__background = document.createElement('div');
  24708. _this2.__foreground = document.createElement('div');
  24709. dom.bind(_this2.__background, 'mousedown', onMouseDown);
  24710. dom.bind(_this2.__background, 'touchstart', onTouchStart);
  24711. dom.addClass(_this2.__background, 'slider');
  24712. dom.addClass(_this2.__foreground, 'slider-fg');
  24713. function onMouseDown(e) {
  24714. document.activeElement.blur();
  24715. dom.bind(window, 'mousemove', onMouseDrag);
  24716. dom.bind(window, 'mouseup', onMouseUp);
  24717. onMouseDrag(e);
  24718. }
  24719. function onMouseDrag(e) {
  24720. e.preventDefault();
  24721. var bgRect = _this.__background.getBoundingClientRect();
  24722. _this.setValue(map(e.clientX, bgRect.left, bgRect.right, _this.__min, _this.__max));
  24723. return false;
  24724. }
  24725. function onMouseUp() {
  24726. dom.unbind(window, 'mousemove', onMouseDrag);
  24727. dom.unbind(window, 'mouseup', onMouseUp);
  24728. if (_this.__onFinishChange) {
  24729. _this.__onFinishChange.call(_this, _this.getValue());
  24730. }
  24731. }
  24732. function onTouchStart(e) {
  24733. if (e.touches.length !== 1) {
  24734. return;
  24735. }
  24736. dom.bind(window, 'touchmove', onTouchMove);
  24737. dom.bind(window, 'touchend', onTouchEnd);
  24738. onTouchMove(e);
  24739. }
  24740. function onTouchMove(e) {
  24741. var clientX = e.touches[0].clientX;
  24742. var bgRect = _this.__background.getBoundingClientRect();
  24743. _this.setValue(map(clientX, bgRect.left, bgRect.right, _this.__min, _this.__max));
  24744. }
  24745. function onTouchEnd() {
  24746. dom.unbind(window, 'touchmove', onTouchMove);
  24747. dom.unbind(window, 'touchend', onTouchEnd);
  24748. if (_this.__onFinishChange) {
  24749. _this.__onFinishChange.call(_this, _this.getValue());
  24750. }
  24751. }
  24752. _this2.updateDisplay();
  24753. _this2.__background.appendChild(_this2.__foreground);
  24754. _this2.domElement.appendChild(_this2.__background);
  24755. return _this2;
  24756. }
  24757. createClass(NumberControllerSlider, [{
  24758. key: 'updateDisplay',
  24759. value: function updateDisplay() {
  24760. var pct = (this.getValue() - this.__min) / (this.__max - this.__min);
  24761. this.__foreground.style.width = pct * 100 + '%';
  24762. return get(NumberControllerSlider.prototype.__proto__ || Object.getPrototypeOf(NumberControllerSlider.prototype), 'updateDisplay', this).call(this);
  24763. }
  24764. }]);
  24765. return NumberControllerSlider;
  24766. }(NumberController);
  24767. var FunctionController = function (_Controller) {
  24768. inherits(FunctionController, _Controller);
  24769. function FunctionController(object, property, text) {
  24770. classCallCheck(this, FunctionController);
  24771. var _this2 = possibleConstructorReturn(this, (FunctionController.__proto__ || Object.getPrototypeOf(FunctionController)).call(this, object, property));
  24772. var _this = _this2;
  24773. _this2.__button = document.createElement('div');
  24774. _this2.__button.innerHTML = text === undefined ? 'Fire' : text;
  24775. dom.bind(_this2.__button, 'click', function (e) {
  24776. e.preventDefault();
  24777. _this.fire();
  24778. return false;
  24779. });
  24780. dom.addClass(_this2.__button, 'button');
  24781. _this2.domElement.appendChild(_this2.__button);
  24782. return _this2;
  24783. }
  24784. createClass(FunctionController, [{
  24785. key: 'fire',
  24786. value: function fire() {
  24787. if (this.__onChange) {
  24788. this.__onChange.call(this);
  24789. }
  24790. this.getValue().call(this.object);
  24791. if (this.__onFinishChange) {
  24792. this.__onFinishChange.call(this, this.getValue());
  24793. }
  24794. }
  24795. }]);
  24796. return FunctionController;
  24797. }(Controller);
  24798. var ColorController = function (_Controller) {
  24799. inherits(ColorController, _Controller);
  24800. function ColorController(object, property) {
  24801. classCallCheck(this, ColorController);
  24802. var _this2 = possibleConstructorReturn(this, (ColorController.__proto__ || Object.getPrototypeOf(ColorController)).call(this, object, property));
  24803. _this2.__color = new Color(_this2.getValue());
  24804. _this2.__temp = new Color(0);
  24805. var _this = _this2;
  24806. _this2.domElement = document.createElement('div');
  24807. dom.makeSelectable(_this2.domElement, false);
  24808. _this2.__selector = document.createElement('div');
  24809. _this2.__selector.className = 'selector';
  24810. _this2.__saturation_field = document.createElement('div');
  24811. _this2.__saturation_field.className = 'saturation-field';
  24812. _this2.__field_knob = document.createElement('div');
  24813. _this2.__field_knob.className = 'field-knob';
  24814. _this2.__field_knob_border = '2px solid ';
  24815. _this2.__hue_knob = document.createElement('div');
  24816. _this2.__hue_knob.className = 'hue-knob';
  24817. _this2.__hue_field = document.createElement('div');
  24818. _this2.__hue_field.className = 'hue-field';
  24819. _this2.__input = document.createElement('input');
  24820. _this2.__input.type = 'text';
  24821. _this2.__input_textShadow = '0 1px 1px ';
  24822. dom.bind(_this2.__input, 'keydown', function (e) {
  24823. if (e.keyCode === 13) {
  24824. onBlur.call(this);
  24825. }
  24826. });
  24827. dom.bind(_this2.__input, 'blur', onBlur);
  24828. dom.bind(_this2.__selector, 'mousedown', function () {
  24829. dom.addClass(this, 'drag').bind(window, 'mouseup', function () {
  24830. dom.removeClass(_this.__selector, 'drag');
  24831. });
  24832. });
  24833. dom.bind(_this2.__selector, 'touchstart', function () {
  24834. dom.addClass(this, 'drag').bind(window, 'touchend', function () {
  24835. dom.removeClass(_this.__selector, 'drag');
  24836. });
  24837. });
  24838. var valueField = document.createElement('div');
  24839. Common.extend(_this2.__selector.style, {
  24840. width: '122px',
  24841. height: '102px',
  24842. padding: '3px',
  24843. backgroundColor: '#222',
  24844. boxShadow: '0px 1px 3px rgba(0,0,0,0.3)'
  24845. });
  24846. Common.extend(_this2.__field_knob.style, {
  24847. position: 'absolute',
  24848. width: '12px',
  24849. height: '12px',
  24850. border: _this2.__field_knob_border + (_this2.__color.v < 0.5 ? '#fff' : '#000'),
  24851. boxShadow: '0px 1px 3px rgba(0,0,0,0.5)',
  24852. borderRadius: '12px',
  24853. zIndex: 1
  24854. });
  24855. Common.extend(_this2.__hue_knob.style, {
  24856. position: 'absolute',
  24857. width: '15px',
  24858. height: '2px',
  24859. borderRight: '4px solid #fff',
  24860. zIndex: 1
  24861. });
  24862. Common.extend(_this2.__saturation_field.style, {
  24863. width: '100px',
  24864. height: '100px',
  24865. border: '1px solid #555',
  24866. marginRight: '3px',
  24867. display: 'inline-block',
  24868. cursor: 'pointer'
  24869. });
  24870. Common.extend(valueField.style, {
  24871. width: '100%',
  24872. height: '100%',
  24873. background: 'none'
  24874. });
  24875. linearGradient(valueField, 'top', 'rgba(0,0,0,0)', '#000');
  24876. Common.extend(_this2.__hue_field.style, {
  24877. width: '15px',
  24878. height: '100px',
  24879. border: '1px solid #555',
  24880. cursor: 'ns-resize',
  24881. position: 'absolute',
  24882. top: '3px',
  24883. right: '3px'
  24884. });
  24885. hueGradient(_this2.__hue_field);
  24886. Common.extend(_this2.__input.style, {
  24887. outline: 'none',
  24888. textAlign: 'center',
  24889. color: '#fff',
  24890. border: 0,
  24891. fontWeight: 'bold',
  24892. textShadow: _this2.__input_textShadow + 'rgba(0,0,0,0.7)'
  24893. });
  24894. dom.bind(_this2.__saturation_field, 'mousedown', fieldDown);
  24895. dom.bind(_this2.__saturation_field, 'touchstart', fieldDown);
  24896. dom.bind(_this2.__field_knob, 'mousedown', fieldDown);
  24897. dom.bind(_this2.__field_knob, 'touchstart', fieldDown);
  24898. dom.bind(_this2.__hue_field, 'mousedown', fieldDownH);
  24899. dom.bind(_this2.__hue_field, 'touchstart', fieldDownH);
  24900. function fieldDown(e) {
  24901. setSV(e);
  24902. dom.bind(window, 'mousemove', setSV);
  24903. dom.bind(window, 'touchmove', setSV);
  24904. dom.bind(window, 'mouseup', fieldUpSV);
  24905. dom.bind(window, 'touchend', fieldUpSV);
  24906. }
  24907. function fieldDownH(e) {
  24908. setH(e);
  24909. dom.bind(window, 'mousemove', setH);
  24910. dom.bind(window, 'touchmove', setH);
  24911. dom.bind(window, 'mouseup', fieldUpH);
  24912. dom.bind(window, 'touchend', fieldUpH);
  24913. }
  24914. function fieldUpSV() {
  24915. dom.unbind(window, 'mousemove', setSV);
  24916. dom.unbind(window, 'touchmove', setSV);
  24917. dom.unbind(window, 'mouseup', fieldUpSV);
  24918. dom.unbind(window, 'touchend', fieldUpSV);
  24919. onFinish();
  24920. }
  24921. function fieldUpH() {
  24922. dom.unbind(window, 'mousemove', setH);
  24923. dom.unbind(window, 'touchmove', setH);
  24924. dom.unbind(window, 'mouseup', fieldUpH);
  24925. dom.unbind(window, 'touchend', fieldUpH);
  24926. onFinish();
  24927. }
  24928. function onBlur() {
  24929. var i = interpret(this.value);
  24930. if (i !== false) {
  24931. _this.__color.__state = i;
  24932. _this.setValue(_this.__color.toOriginal());
  24933. } else {
  24934. this.value = _this.__color.toString();
  24935. }
  24936. }
  24937. function onFinish() {
  24938. if (_this.__onFinishChange) {
  24939. _this.__onFinishChange.call(_this, _this.__color.toOriginal());
  24940. }
  24941. }
  24942. _this2.__saturation_field.appendChild(valueField);
  24943. _this2.__selector.appendChild(_this2.__field_knob);
  24944. _this2.__selector.appendChild(_this2.__saturation_field);
  24945. _this2.__selector.appendChild(_this2.__hue_field);
  24946. _this2.__hue_field.appendChild(_this2.__hue_knob);
  24947. _this2.domElement.appendChild(_this2.__input);
  24948. _this2.domElement.appendChild(_this2.__selector);
  24949. _this2.updateDisplay();
  24950. function setSV(e) {
  24951. if (e.type.indexOf('touch') === -1) {
  24952. e.preventDefault();
  24953. }
  24954. var fieldRect = _this.__saturation_field.getBoundingClientRect();
  24955. var _ref = e.touches && e.touches[0] || e,
  24956. clientX = _ref.clientX,
  24957. clientY = _ref.clientY;
  24958. var s = (clientX - fieldRect.left) / (fieldRect.right - fieldRect.left);
  24959. var v = 1 - (clientY - fieldRect.top) / (fieldRect.bottom - fieldRect.top);
  24960. if (v > 1) {
  24961. v = 1;
  24962. } else if (v < 0) {
  24963. v = 0;
  24964. }
  24965. if (s > 1) {
  24966. s = 1;
  24967. } else if (s < 0) {
  24968. s = 0;
  24969. }
  24970. _this.__color.v = v;
  24971. _this.__color.s = s;
  24972. _this.setValue(_this.__color.toOriginal());
  24973. return false;
  24974. }
  24975. function setH(e) {
  24976. if (e.type.indexOf('touch') === -1) {
  24977. e.preventDefault();
  24978. }
  24979. var fieldRect = _this.__hue_field.getBoundingClientRect();
  24980. var _ref2 = e.touches && e.touches[0] || e,
  24981. clientY = _ref2.clientY;
  24982. var h = 1 - (clientY - fieldRect.top) / (fieldRect.bottom - fieldRect.top);
  24983. if (h > 1) {
  24984. h = 1;
  24985. } else if (h < 0) {
  24986. h = 0;
  24987. }
  24988. _this.__color.h = h * 360;
  24989. _this.setValue(_this.__color.toOriginal());
  24990. return false;
  24991. }
  24992. return _this2;
  24993. }
  24994. createClass(ColorController, [{
  24995. key: 'updateDisplay',
  24996. value: function updateDisplay() {
  24997. var i = interpret(this.getValue());
  24998. if (i !== false) {
  24999. var mismatch = false;
  25000. Common.each(Color.COMPONENTS, function (component) {
  25001. if (!Common.isUndefined(i[component]) && !Common.isUndefined(this.__color.__state[component]) && i[component] !== this.__color.__state[component]) {
  25002. mismatch = true;
  25003. return {};
  25004. }
  25005. }, this);
  25006. if (mismatch) {
  25007. Common.extend(this.__color.__state, i);
  25008. }
  25009. }
  25010. Common.extend(this.__temp.__state, this.__color.__state);
  25011. this.__temp.a = 1;
  25012. var flip = this.__color.v < 0.5 || this.__color.s > 0.5 ? 255 : 0;
  25013. var _flip = 255 - flip;
  25014. Common.extend(this.__field_knob.style, {
  25015. marginLeft: 100 * this.__color.s - 7 + 'px',
  25016. marginTop: 100 * (1 - this.__color.v) - 7 + 'px',
  25017. backgroundColor: this.__temp.toHexString(),
  25018. border: this.__field_knob_border + 'rgb(' + flip + ',' + flip + ',' + flip + ')'
  25019. });
  25020. this.__hue_knob.style.marginTop = (1 - this.__color.h / 360) * 100 + 'px';
  25021. this.__temp.s = 1;
  25022. this.__temp.v = 1;
  25023. linearGradient(this.__saturation_field, 'left', '#fff', this.__temp.toHexString());
  25024. this.__input.value = this.__color.toString();
  25025. Common.extend(this.__input.style, {
  25026. backgroundColor: this.__color.toHexString(),
  25027. color: 'rgb(' + flip + ',' + flip + ',' + flip + ')',
  25028. textShadow: this.__input_textShadow + 'rgba(' + _flip + ',' + _flip + ',' + _flip + ',.7)'
  25029. });
  25030. }
  25031. }]);
  25032. return ColorController;
  25033. }(Controller);
  25034. var vendors = ['-moz-', '-o-', '-webkit-', '-ms-', ''];
  25035. function linearGradient(elem, x, a, b) {
  25036. elem.style.background = '';
  25037. Common.each(vendors, function (vendor) {
  25038. elem.style.cssText += 'background: ' + vendor + 'linear-gradient(' + x + ', ' + a + ' 0%, ' + b + ' 100%); ';
  25039. });
  25040. }
  25041. function hueGradient(elem) {
  25042. elem.style.background = '';
  25043. elem.style.cssText += 'background: -moz-linear-gradient(top, #ff0000 0%, #ff00ff 17%, #0000ff 34%, #00ffff 50%, #00ff00 67%, #ffff00 84%, #ff0000 100%);';
  25044. elem.style.cssText += 'background: -webkit-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';
  25045. elem.style.cssText += 'background: -o-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';
  25046. elem.style.cssText += 'background: -ms-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';
  25047. elem.style.cssText += 'background: linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';
  25048. }
  25049. var css = {
  25050. load: function load(url, indoc) {
  25051. var doc = indoc || document;
  25052. var link = doc.createElement('link');
  25053. link.type = 'text/css';
  25054. link.rel = 'stylesheet';
  25055. link.href = url;
  25056. doc.getElementsByTagName('head')[0].appendChild(link);
  25057. },
  25058. inject: function inject(cssContent, indoc) {
  25059. var doc = indoc || document;
  25060. var injected = document.createElement('style');
  25061. injected.type = 'text/css';
  25062. injected.innerHTML = cssContent;
  25063. var head = doc.getElementsByTagName('head')[0];
  25064. try {
  25065. head.appendChild(injected);
  25066. } catch (e) { }
  25067. }
  25068. };
  25069. var saveDialogContents = "<div id=\"dg-save\" class=\"dg dialogue\">\n\n Here's the new load parameter for your <code>GUI</code>'s constructor:\n\n <textarea id=\"dg-new-constructor\"></textarea>\n\n <div id=\"dg-save-locally\">\n\n <input id=\"dg-local-storage\" type=\"checkbox\"/> Automatically save\n values to <code>localStorage</code> on exit.\n\n <div id=\"dg-local-explain\">The values saved to <code>localStorage</code> will\n override those passed to <code>dat.GUI</code>'s constructor. This makes it\n easier to work incrementally, but <code>localStorage</code> is fragile,\n and your friends may not see the same values you do.\n\n </div>\n\n </div>\n\n</div>";
  25070. var ControllerFactory = function ControllerFactory(object, property) {
  25071. var initialValue = object[property];
  25072. if (Common.isArray(arguments[2]) || Common.isObject(arguments[2])) {
  25073. return new OptionController(object, property, arguments[2]);
  25074. }
  25075. if (Common.isNumber(initialValue)) {
  25076. if (Common.isNumber(arguments[2]) && Common.isNumber(arguments[3])) {
  25077. if (Common.isNumber(arguments[4])) {
  25078. return new NumberControllerSlider(object, property, arguments[2], arguments[3], arguments[4]);
  25079. }
  25080. return new NumberControllerSlider(object, property, arguments[2], arguments[3]);
  25081. }
  25082. if (Common.isNumber(arguments[4])) {
  25083. return new NumberControllerBox(object, property, {
  25084. min: arguments[2],
  25085. max: arguments[3],
  25086. step: arguments[4]
  25087. });
  25088. }
  25089. return new NumberControllerBox(object, property, {
  25090. min: arguments[2],
  25091. max: arguments[3]
  25092. });
  25093. }
  25094. if (Common.isString(initialValue)) {
  25095. return new StringController(object, property);
  25096. }
  25097. if (Common.isFunction(initialValue)) {
  25098. return new FunctionController(object, property, '');
  25099. }
  25100. if (Common.isBoolean(initialValue)) {
  25101. return new BooleanController(object, property);
  25102. }
  25103. return null;
  25104. };
  25105. function requestAnimationFrame(callback) {
  25106. setTimeout(callback, 1000 / 60);
  25107. }
  25108. var requestAnimationFrame$1 = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || requestAnimationFrame;
  25109. var CenteredDiv = function () {
  25110. function CenteredDiv() {
  25111. classCallCheck(this, CenteredDiv);
  25112. this.backgroundElement = document.createElement('div');
  25113. Common.extend(this.backgroundElement.style, {
  25114. backgroundColor: 'rgba(0,0,0,0.8)',
  25115. top: 0,
  25116. left: 0,
  25117. display: 'none',
  25118. zIndex: '1000',
  25119. opacity: 0,
  25120. WebkitTransition: 'opacity 0.2s linear',
  25121. transition: 'opacity 0.2s linear'
  25122. });
  25123. dom.makeFullscreen(this.backgroundElement);
  25124. this.backgroundElement.style.position = 'fixed';
  25125. this.domElement = document.createElement('div');
  25126. Common.extend(this.domElement.style, {
  25127. position: 'fixed',
  25128. display: 'none',
  25129. zIndex: '1001',
  25130. opacity: 0,
  25131. WebkitTransition: '-webkit-transform 0.2s ease-out, opacity 0.2s linear',
  25132. transition: 'transform 0.2s ease-out, opacity 0.2s linear'
  25133. });
  25134. document.body.appendChild(this.backgroundElement);
  25135. document.body.appendChild(this.domElement);
  25136. var _this = this;
  25137. dom.bind(this.backgroundElement, 'click', function () {
  25138. _this.hide();
  25139. });
  25140. }
  25141. createClass(CenteredDiv, [{
  25142. key: 'show',
  25143. value: function show() {
  25144. var _this = this;
  25145. this.backgroundElement.style.display = 'block';
  25146. this.domElement.style.display = 'block';
  25147. this.domElement.style.opacity = 0;
  25148. this.domElement.style.webkitTransform = 'scale(1.1)';
  25149. this.layout();
  25150. Common.defer(function () {
  25151. _this.backgroundElement.style.opacity = 1;
  25152. _this.domElement.style.opacity = 1;
  25153. _this.domElement.style.webkitTransform = 'scale(1)';
  25154. });
  25155. }
  25156. }, {
  25157. key: 'hide',
  25158. value: function hide() {
  25159. var _this = this;
  25160. var hide = function hide() {
  25161. _this.domElement.style.display = 'none';
  25162. _this.backgroundElement.style.display = 'none';
  25163. dom.unbind(_this.domElement, 'webkitTransitionEnd', hide);
  25164. dom.unbind(_this.domElement, 'transitionend', hide);
  25165. dom.unbind(_this.domElement, 'oTransitionEnd', hide);
  25166. };
  25167. dom.bind(this.domElement, 'webkitTransitionEnd', hide);
  25168. dom.bind(this.domElement, 'transitionend', hide);
  25169. dom.bind(this.domElement, 'oTransitionEnd', hide);
  25170. this.backgroundElement.style.opacity = 0;
  25171. this.domElement.style.opacity = 0;
  25172. this.domElement.style.webkitTransform = 'scale(1.1)';
  25173. }
  25174. }, {
  25175. key: 'layout',
  25176. value: function layout() {
  25177. this.domElement.style.left = window.innerWidth / 2 - dom.getWidth(this.domElement) / 2 + 'px';
  25178. this.domElement.style.top = window.innerHeight / 2 - dom.getHeight(this.domElement) / 2 + 'px';
  25179. }
  25180. }]);
  25181. return CenteredDiv;
  25182. }();
  25183. var styleSheet = ___$insertStyle(".dg ul{list-style:none;margin:0;padding:0;width:100%;clear:both}.dg.ac{position:fixed;top:0;left:0;right:0;height:0;z-index:0}.dg:not(.ac) .main{overflow:hidden}.dg.main{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear}.dg.main.taller-than-window{overflow-y:auto}.dg.main.taller-than-window .close-button{opacity:1;margin-top:-1px;border-top:1px solid #2c2c2c}.dg.main ul.closed .close-button{opacity:1 !important}.dg.main:hover .close-button,.dg.main .close-button.drag{opacity:1}.dg.main .close-button{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear;border:0;line-height:19px;height:20px;cursor:pointer;text-align:center;background-color:#000}.dg.main .close-button.close-top{position:relative}.dg.main .close-button.close-bottom{position:absolute}.dg.main .close-button:hover{background-color:#111}.dg.a{float:right;margin-right:15px;overflow-y:visible}.dg.a.has-save>ul.close-top{margin-top:0}.dg.a.has-save>ul.close-bottom{margin-top:27px}.dg.a.has-save>ul.closed{margin-top:0}.dg.a .save-row{top:0;z-index:1002}.dg.a .save-row.close-top{position:relative}.dg.a .save-row.close-bottom{position:fixed}.dg li{-webkit-transition:height .1s ease-out;-o-transition:height .1s ease-out;-moz-transition:height .1s ease-out;transition:height .1s ease-out;-webkit-transition:overflow .1s linear;-o-transition:overflow .1s linear;-moz-transition:overflow .1s linear;transition:overflow .1s linear}.dg li:not(.folder){cursor:auto;height:27px;line-height:27px;padding:0 4px 0 5px}.dg li.folder{padding:0;border-left:4px solid rgba(0,0,0,0)}.dg li.title{cursor:pointer;margin-left:-4px}.dg .closed li:not(.title),.dg .closed ul li,.dg .closed ul li>*{height:0;overflow:hidden;border:0}.dg .cr{clear:both;padding-left:3px;height:27px;overflow:hidden}.dg .property-name{cursor:default;float:left;clear:left;width:40%;overflow:hidden;text-overflow:ellipsis}.dg .c{float:left;width:60%;position:relative}.dg .c input[type=text]{border:0;margin-top:4px;padding:3px;width:100%;float:right}.dg .has-slider input[type=text]{width:30%;margin-left:0}.dg .slider{float:left;width:66%;margin-left:-5px;margin-right:0;height:19px;margin-top:4px}.dg .slider-fg{height:100%}.dg .c input[type=checkbox]{margin-top:7px}.dg .c select{margin-top:5px}.dg .cr.function,.dg .cr.function .property-name,.dg .cr.function *,.dg .cr.boolean,.dg .cr.boolean *{cursor:pointer}.dg .cr.color{overflow:visible}.dg .selector{display:none;position:absolute;margin-left:-9px;margin-top:23px;z-index:10}.dg .c:hover .selector,.dg .selector.drag{display:block}.dg li.save-row{padding:0}.dg li.save-row .button{display:inline-block;padding:0px 6px}.dg.dialogue{background-color:#222;width:460px;padding:15px;font-size:13px;line-height:15px}#dg-new-constructor{padding:10px;color:#222;font-family:Monaco, monospace;font-size:10px;border:0;resize:none;box-shadow:inset 1px 1px 1px #888;word-wrap:break-word;margin:12px 0;display:block;width:440px;overflow-y:scroll;height:100px;position:relative}#dg-local-explain{display:none;font-size:11px;line-height:17px;border-radius:3px;background-color:#333;padding:8px;margin-top:10px}#dg-local-explain code{font-size:10px}#dat-gui-save-locally{display:none}.dg{color:#eee;font:11px 'Lucida Grande', sans-serif;text-shadow:0 -1px 0 #111}.dg.main::-webkit-scrollbar{width:5px;background:#1a1a1a}.dg.main::-webkit-scrollbar-corner{height:0;display:none}.dg.main::-webkit-scrollbar-thumb{border-radius:5px;background:#676767}.dg li:not(.folder){background:#1a1a1a;border-bottom:1px solid #2c2c2c}.dg li.save-row{line-height:25px;background:#dad5cb;border:0}.dg li.save-row select{margin-left:5px;width:108px}.dg li.save-row .button{margin-left:5px;margin-top:1px;border-radius:2px;font-size:9px;line-height:7px;padding:4px 4px 5px 4px;background:#c5bdad;color:#fff;text-shadow:0 1px 0 #b0a58f;box-shadow:0 -1px 0 #b0a58f;cursor:pointer}.dg li.save-row .button.gears{background:#c5bdad url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAYAAAB/9ZQ7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpiYKAU/P//PwGIC/ApCABiBSAW+I8AClAcgKxQ4T9hoMAEUrxx2QSGN6+egDX+/vWT4e7N82AMYoPAx/evwWoYoSYbACX2s7KxCxzcsezDh3evFoDEBYTEEqycggWAzA9AuUSQQgeYPa9fPv6/YWm/Acx5IPb7ty/fw+QZblw67vDs8R0YHyQhgObx+yAJkBqmG5dPPDh1aPOGR/eugW0G4vlIoTIfyFcA+QekhhHJhPdQxbiAIguMBTQZrPD7108M6roWYDFQiIAAv6Aow/1bFwXgis+f2LUAynwoIaNcz8XNx3Dl7MEJUDGQpx9gtQ8YCueB+D26OECAAQDadt7e46D42QAAAABJRU5ErkJggg==) 2px 1px no-repeat;height:7px;width:8px}.dg li.save-row .button:hover{background-color:#bab19e;box-shadow:0 -1px 0 #b0a58f}.dg li.folder{border-bottom:0}.dg li.title{padding-left:16px;background:#000 url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlI+hKgFxoCgAOw==) 6px 10px no-repeat;cursor:pointer;border-bottom:1px solid rgba(255,255,255,0.2)}.dg .closed li.title{background-image:url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlGIWqMCbWAEAOw==)}.dg .cr.boolean{border-left:3px solid #806787}.dg .cr.color{border-left:3px solid}.dg .cr.function{border-left:3px solid #e61d5f}.dg .cr.number{border-left:3px solid #2FA1D6}.dg .cr.number input[type=text]{color:#2FA1D6}.dg .cr.string{border-left:3px solid #1ed36f}.dg .cr.string input[type=text]{color:#1ed36f}.dg .cr.function:hover,.dg .cr.boolean:hover{background:#111}.dg .c input[type=text]{background:#303030;outline:none}.dg .c input[type=text]:hover{background:#3c3c3c}.dg .c input[type=text]:focus{background:#494949;color:#fff}.dg .c .slider{background:#303030;cursor:ew-resize}.dg .c .slider-fg{background:#2FA1D6;max-width:100%}.dg .c .slider:hover{background:#3c3c3c}.dg .c .slider:hover .slider-fg{background:#44abda}\n");
  25184. css.inject(styleSheet);
  25185. var CSS_NAMESPACE = 'dg';
  25186. var HIDE_KEY_CODE = 72;
  25187. var CLOSE_BUTTON_HEIGHT = 20;
  25188. var DEFAULT_DEFAULT_PRESET_NAME = 'Default';
  25189. var SUPPORTS_LOCAL_STORAGE = function () {
  25190. try {
  25191. return !!window.localStorage;
  25192. } catch (e) {
  25193. return false;
  25194. }
  25195. }();
  25196. var SAVE_DIALOGUE = void 0;
  25197. var autoPlaceVirgin = true;
  25198. var autoPlaceContainer = void 0;
  25199. var hide = false;
  25200. var hideableGuis = [];
  25201. var GUI = function GUI(pars) {
  25202. var _this = this;
  25203. var params = pars || {};
  25204. this.domElement = document.createElement('div');
  25205. this.__ul = document.createElement('ul');
  25206. this.domElement.appendChild(this.__ul);
  25207. dom.addClass(this.domElement, CSS_NAMESPACE);
  25208. this.__folders = {};
  25209. this.__controllers = [];
  25210. this.__rememberedObjects = [];
  25211. this.__rememberedObjectIndecesToControllers = [];
  25212. this.__listening = [];
  25213. params = Common.defaults(params, {
  25214. closeOnTop: false,
  25215. autoPlace: true,
  25216. width: GUI.DEFAULT_WIDTH
  25217. });
  25218. params = Common.defaults(params, {
  25219. resizable: params.autoPlace,
  25220. hideable: params.autoPlace
  25221. });
  25222. if (!Common.isUndefined(params.load)) {
  25223. if (params.preset) {
  25224. params.load.preset = params.preset;
  25225. }
  25226. } else {
  25227. params.load = {
  25228. preset: DEFAULT_DEFAULT_PRESET_NAME
  25229. };
  25230. }
  25231. if (Common.isUndefined(params.parent) && params.hideable) {
  25232. hideableGuis.push(this);
  25233. }
  25234. params.resizable = Common.isUndefined(params.parent) && params.resizable;
  25235. if (params.autoPlace && Common.isUndefined(params.scrollable)) {
  25236. params.scrollable = true;
  25237. }
  25238. var useLocalStorage = SUPPORTS_LOCAL_STORAGE && localStorage.getItem(getLocalStorageHash(this, 'isLocal')) === 'true';
  25239. var saveToLocalStorage = void 0;
  25240. var titleRow = void 0;
  25241. Object.defineProperties(this, {
  25242. parent: {
  25243. get: function get$$1() {
  25244. return params.parent;
  25245. }
  25246. },
  25247. scrollable: {
  25248. get: function get$$1() {
  25249. return params.scrollable;
  25250. }
  25251. },
  25252. autoPlace: {
  25253. get: function get$$1() {
  25254. return params.autoPlace;
  25255. }
  25256. },
  25257. closeOnTop: {
  25258. get: function get$$1() {
  25259. return params.closeOnTop;
  25260. }
  25261. },
  25262. preset: {
  25263. get: function get$$1() {
  25264. if (_this.parent) {
  25265. return _this.getRoot().preset;
  25266. }
  25267. return params.load.preset;
  25268. },
  25269. set: function set$$1(v) {
  25270. if (_this.parent) {
  25271. _this.getRoot().preset = v;
  25272. } else {
  25273. params.load.preset = v;
  25274. }
  25275. setPresetSelectIndex(this);
  25276. _this.revert();
  25277. }
  25278. },
  25279. width: {
  25280. get: function get$$1() {
  25281. return params.width;
  25282. },
  25283. set: function set$$1(v) {
  25284. params.width = v;
  25285. setWidth(_this, v);
  25286. }
  25287. },
  25288. name: {
  25289. get: function get$$1() {
  25290. return params.name;
  25291. },
  25292. set: function set$$1(v) {
  25293. params.name = v;
  25294. if (titleRow) {
  25295. titleRow.innerHTML = params.name;
  25296. }
  25297. }
  25298. },
  25299. closed: {
  25300. get: function get$$1() {
  25301. return params.closed;
  25302. },
  25303. set: function set$$1(v) {
  25304. params.closed = v;
  25305. if (params.closed) {
  25306. dom.addClass(_this.__ul, GUI.CLASS_CLOSED);
  25307. } else {
  25308. dom.removeClass(_this.__ul, GUI.CLASS_CLOSED);
  25309. }
  25310. this.onResize();
  25311. if (_this.__closeButton) {
  25312. _this.__closeButton.innerHTML = v ? GUI.TEXT_OPEN : GUI.TEXT_CLOSED;
  25313. }
  25314. }
  25315. },
  25316. load: {
  25317. get: function get$$1() {
  25318. return params.load;
  25319. }
  25320. },
  25321. useLocalStorage: {
  25322. get: function get$$1() {
  25323. return useLocalStorage;
  25324. },
  25325. set: function set$$1(bool) {
  25326. if (SUPPORTS_LOCAL_STORAGE) {
  25327. useLocalStorage = bool;
  25328. if (bool) {
  25329. dom.bind(window, 'unload', saveToLocalStorage);
  25330. } else {
  25331. dom.unbind(window, 'unload', saveToLocalStorage);
  25332. }
  25333. localStorage.setItem(getLocalStorageHash(_this, 'isLocal'), bool);
  25334. }
  25335. }
  25336. }
  25337. });
  25338. if (Common.isUndefined(params.parent)) {
  25339. this.closed = params.closed || false;
  25340. dom.addClass(this.domElement, GUI.CLASS_MAIN);
  25341. dom.makeSelectable(this.domElement, false);
  25342. if (SUPPORTS_LOCAL_STORAGE) {
  25343. if (useLocalStorage) {
  25344. _this.useLocalStorage = true;
  25345. var savedGui = localStorage.getItem(getLocalStorageHash(this, 'gui'));
  25346. if (savedGui) {
  25347. params.load = JSON.parse(savedGui);
  25348. }
  25349. }
  25350. }
  25351. this.__closeButton = document.createElement('div');
  25352. this.__closeButton.innerHTML = GUI.TEXT_CLOSED;
  25353. dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_BUTTON);
  25354. if (params.closeOnTop) {
  25355. dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_TOP);
  25356. this.domElement.insertBefore(this.__closeButton, this.domElement.childNodes[0]);
  25357. } else {
  25358. dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_BOTTOM);
  25359. this.domElement.appendChild(this.__closeButton);
  25360. }
  25361. dom.bind(this.__closeButton, 'click', function () {
  25362. _this.closed = !_this.closed;
  25363. });
  25364. } else {
  25365. if (params.closed === undefined) {
  25366. params.closed = true;
  25367. }
  25368. var titleRowName = document.createTextNode(params.name);
  25369. dom.addClass(titleRowName, 'controller-name');
  25370. titleRow = addRow(_this, titleRowName);
  25371. var onClickTitle = function onClickTitle(e) {
  25372. e.preventDefault();
  25373. _this.closed = !_this.closed;
  25374. return false;
  25375. };
  25376. dom.addClass(this.__ul, GUI.CLASS_CLOSED);
  25377. dom.addClass(titleRow, 'title');
  25378. dom.bind(titleRow, 'click', onClickTitle);
  25379. if (!params.closed) {
  25380. this.closed = false;
  25381. }
  25382. }
  25383. if (params.autoPlace) {
  25384. if (Common.isUndefined(params.parent)) {
  25385. if (autoPlaceVirgin) {
  25386. autoPlaceContainer = document.createElement('div');
  25387. dom.addClass(autoPlaceContainer, CSS_NAMESPACE);
  25388. dom.addClass(autoPlaceContainer, GUI.CLASS_AUTO_PLACE_CONTAINER);
  25389. document.body.appendChild(autoPlaceContainer);
  25390. autoPlaceVirgin = false;
  25391. }
  25392. autoPlaceContainer.appendChild(this.domElement);
  25393. dom.addClass(this.domElement, GUI.CLASS_AUTO_PLACE);
  25394. }
  25395. if (!this.parent) {
  25396. setWidth(_this, params.width);
  25397. }
  25398. }
  25399. this.__resizeHandler = function () {
  25400. _this.onResizeDebounced();
  25401. };
  25402. dom.bind(window, 'resize', this.__resizeHandler);
  25403. dom.bind(this.__ul, 'webkitTransitionEnd', this.__resizeHandler);
  25404. dom.bind(this.__ul, 'transitionend', this.__resizeHandler);
  25405. dom.bind(this.__ul, 'oTransitionEnd', this.__resizeHandler);
  25406. this.onResize();
  25407. if (params.resizable) {
  25408. addResizeHandle(this);
  25409. }
  25410. saveToLocalStorage = function saveToLocalStorage() {
  25411. if (SUPPORTS_LOCAL_STORAGE && localStorage.getItem(getLocalStorageHash(_this, 'isLocal')) === 'true') {
  25412. localStorage.setItem(getLocalStorageHash(_this, 'gui'), JSON.stringify(_this.getSaveObject()));
  25413. }
  25414. };
  25415. this.saveToLocalStorageIfPossible = saveToLocalStorage;
  25416. function resetWidth() {
  25417. var root = _this.getRoot();
  25418. root.width += 1;
  25419. Common.defer(function () {
  25420. root.width -= 1;
  25421. });
  25422. }
  25423. if (!params.parent) {
  25424. resetWidth();
  25425. }
  25426. };
  25427. GUI.toggleHide = function () {
  25428. hide = !hide;
  25429. Common.each(hideableGuis, function (gui) {
  25430. gui.domElement.style.display = hide ? 'none' : '';
  25431. });
  25432. };
  25433. GUI.CLASS_AUTO_PLACE = 'a';
  25434. GUI.CLASS_AUTO_PLACE_CONTAINER = 'ac';
  25435. GUI.CLASS_MAIN = 'main';
  25436. GUI.CLASS_CONTROLLER_ROW = 'cr';
  25437. GUI.CLASS_TOO_TALL = 'taller-than-window';
  25438. GUI.CLASS_CLOSED = 'closed';
  25439. GUI.CLASS_CLOSE_BUTTON = 'close-button';
  25440. GUI.CLASS_CLOSE_TOP = 'close-top';
  25441. GUI.CLASS_CLOSE_BOTTOM = 'close-bottom';
  25442. GUI.CLASS_DRAG = 'drag';
  25443. GUI.DEFAULT_WIDTH = 245;
  25444. GUI.TEXT_CLOSED = 'Close Controls';
  25445. GUI.TEXT_OPEN = 'Open Controls';
  25446. GUI._keydownHandler = function (e) {
  25447. if (document.activeElement.type !== 'text' && (e.which === HIDE_KEY_CODE || e.keyCode === HIDE_KEY_CODE)) {
  25448. GUI.toggleHide();
  25449. }
  25450. };
  25451. dom.bind(window, 'keydown', GUI._keydownHandler, false);
  25452. Common.extend(GUI.prototype, {
  25453. add: function add(object, property) {
  25454. return _add(this, object, property, {
  25455. factoryArgs: Array.prototype.slice.call(arguments, 2)
  25456. });
  25457. },
  25458. addColor: function addColor(object, property) {
  25459. return _add(this, object, property, {
  25460. color: true
  25461. });
  25462. },
  25463. remove: function remove(controller) {
  25464. this.__ul.removeChild(controller.__li);
  25465. this.__controllers.splice(this.__controllers.indexOf(controller), 1);
  25466. var _this = this;
  25467. Common.defer(function () {
  25468. _this.onResize();
  25469. });
  25470. },
  25471. destroy: function destroy() {
  25472. if (this.parent) {
  25473. throw new Error('Only the root GUI should be removed with .destroy(). ' + 'For subfolders, use gui.removeFolder(folder) instead.');
  25474. }
  25475. if (this.autoPlace) {
  25476. autoPlaceContainer.removeChild(this.domElement);
  25477. }
  25478. var _this = this;
  25479. Common.each(this.__folders, function (subfolder) {
  25480. _this.removeFolder(subfolder);
  25481. });
  25482. dom.unbind(window, 'keydown', GUI._keydownHandler, false);
  25483. removeListeners(this);
  25484. },
  25485. addFolder: function addFolder(name) {
  25486. if (this.__folders[name] !== undefined) {
  25487. throw new Error('You already have a folder in this GUI by the' + ' name "' + name + '"');
  25488. }
  25489. var newGuiParams = {
  25490. name: name,
  25491. parent: this
  25492. };
  25493. newGuiParams.autoPlace = this.autoPlace;
  25494. if (this.load && this.load.folders && this.load.folders[name]) {
  25495. newGuiParams.closed = this.load.folders[name].closed;
  25496. newGuiParams.load = this.load.folders[name];
  25497. }
  25498. var gui = new GUI(newGuiParams);
  25499. this.__folders[name] = gui;
  25500. var li = addRow(this, gui.domElement);
  25501. dom.addClass(li, 'folder');
  25502. return gui;
  25503. },
  25504. removeFolder: function removeFolder(folder) {
  25505. this.__ul.removeChild(folder.domElement.parentElement);
  25506. delete this.__folders[folder.name];
  25507. if (this.load && this.load.folders && this.load.folders[folder.name]) {
  25508. delete this.load.folders[folder.name];
  25509. }
  25510. removeListeners(folder);
  25511. var _this = this;
  25512. Common.each(folder.__folders, function (subfolder) {
  25513. folder.removeFolder(subfolder);
  25514. });
  25515. Common.defer(function () {
  25516. _this.onResize();
  25517. });
  25518. },
  25519. open: function open() {
  25520. this.closed = false;
  25521. },
  25522. close: function close() {
  25523. this.closed = true;
  25524. },
  25525. onResize: function onResize() {
  25526. var root = this.getRoot();
  25527. if (root.scrollable) {
  25528. var top = dom.getOffset(root.__ul).top;
  25529. var h = 0;
  25530. Common.each(root.__ul.childNodes, function (node) {
  25531. if (!(root.autoPlace && node === root.__save_row)) {
  25532. h += dom.getHeight(node);
  25533. }
  25534. });
  25535. if (window.innerHeight - top - CLOSE_BUTTON_HEIGHT < h) {
  25536. dom.addClass(root.domElement, GUI.CLASS_TOO_TALL);
  25537. root.__ul.style.height = window.innerHeight - top - CLOSE_BUTTON_HEIGHT + 'px';
  25538. } else {
  25539. dom.removeClass(root.domElement, GUI.CLASS_TOO_TALL);
  25540. root.__ul.style.height = 'auto';
  25541. }
  25542. }
  25543. if (root.__resize_handle) {
  25544. Common.defer(function () {
  25545. root.__resize_handle.style.height = root.__ul.offsetHeight + 'px';
  25546. });
  25547. }
  25548. if (root.__closeButton) {
  25549. root.__closeButton.style.width = root.width + 'px';
  25550. }
  25551. },
  25552. onResizeDebounced: Common.debounce(function () {
  25553. this.onResize();
  25554. }, 50),
  25555. remember: function remember() {
  25556. if (Common.isUndefined(SAVE_DIALOGUE)) {
  25557. SAVE_DIALOGUE = new CenteredDiv();
  25558. SAVE_DIALOGUE.domElement.innerHTML = saveDialogContents;
  25559. }
  25560. if (this.parent) {
  25561. throw new Error('You can only call remember on a top level GUI.');
  25562. }
  25563. var _this = this;
  25564. Common.each(Array.prototype.slice.call(arguments), function (object) {
  25565. if (_this.__rememberedObjects.length === 0) {
  25566. addSaveMenu(_this);
  25567. }
  25568. if (_this.__rememberedObjects.indexOf(object) === -1) {
  25569. _this.__rememberedObjects.push(object);
  25570. }
  25571. });
  25572. if (this.autoPlace) {
  25573. setWidth(this, this.width);
  25574. }
  25575. },
  25576. getRoot: function getRoot() {
  25577. var gui = this;
  25578. while (gui.parent) {
  25579. gui = gui.parent;
  25580. }
  25581. return gui;
  25582. },
  25583. getSaveObject: function getSaveObject() {
  25584. var toReturn = this.load;
  25585. toReturn.closed = this.closed;
  25586. if (this.__rememberedObjects.length > 0) {
  25587. toReturn.preset = this.preset;
  25588. if (!toReturn.remembered) {
  25589. toReturn.remembered = {};
  25590. }
  25591. toReturn.remembered[this.preset] = getCurrentPreset(this);
  25592. }
  25593. toReturn.folders = {};
  25594. Common.each(this.__folders, function (element, key) {
  25595. toReturn.folders[key] = element.getSaveObject();
  25596. });
  25597. return toReturn;
  25598. },
  25599. save: function save() {
  25600. if (!this.load.remembered) {
  25601. this.load.remembered = {};
  25602. }
  25603. this.load.remembered[this.preset] = getCurrentPreset(this);
  25604. markPresetModified(this, false);
  25605. this.saveToLocalStorageIfPossible();
  25606. },
  25607. saveAs: function saveAs(presetName) {
  25608. if (!this.load.remembered) {
  25609. this.load.remembered = {};
  25610. this.load.remembered[DEFAULT_DEFAULT_PRESET_NAME] = getCurrentPreset(this, true);
  25611. }
  25612. this.load.remembered[presetName] = getCurrentPreset(this);
  25613. this.preset = presetName;
  25614. addPresetOption(this, presetName, true);
  25615. this.saveToLocalStorageIfPossible();
  25616. },
  25617. revert: function revert(gui) {
  25618. Common.each(this.__controllers, function (controller) {
  25619. if (!this.getRoot().load.remembered) {
  25620. controller.setValue(controller.initialValue);
  25621. } else {
  25622. recallSavedValue(gui || this.getRoot(), controller);
  25623. }
  25624. if (controller.__onFinishChange) {
  25625. controller.__onFinishChange.call(controller, controller.getValue());
  25626. }
  25627. }, this);
  25628. Common.each(this.__folders, function (folder) {
  25629. folder.revert(folder);
  25630. });
  25631. if (!gui) {
  25632. markPresetModified(this.getRoot(), false);
  25633. }
  25634. },
  25635. listen: function listen(controller) {
  25636. var init = this.__listening.length === 0;
  25637. this.__listening.push(controller);
  25638. if (init) {
  25639. updateDisplays(this.__listening);
  25640. }
  25641. },
  25642. updateDisplay: function updateDisplay() {
  25643. Common.each(this.__controllers, function (controller) {
  25644. controller.updateDisplay();
  25645. });
  25646. Common.each(this.__folders, function (folder) {
  25647. folder.updateDisplay();
  25648. });
  25649. }
  25650. });
  25651. function addRow(gui, newDom, liBefore) {
  25652. var li = document.createElement('li');
  25653. if (newDom) {
  25654. li.appendChild(newDom);
  25655. }
  25656. if (liBefore) {
  25657. gui.__ul.insertBefore(li, liBefore);
  25658. } else {
  25659. gui.__ul.appendChild(li);
  25660. }
  25661. gui.onResize();
  25662. return li;
  25663. }
  25664. function removeListeners(gui) {
  25665. dom.unbind(window, 'resize', gui.__resizeHandler);
  25666. if (gui.saveToLocalStorageIfPossible) {
  25667. dom.unbind(window, 'unload', gui.saveToLocalStorageIfPossible);
  25668. }
  25669. }
  25670. function markPresetModified(gui, modified) {
  25671. var opt = gui.__preset_select[gui.__preset_select.selectedIndex];
  25672. if (modified) {
  25673. opt.innerHTML = opt.value + '*';
  25674. } else {
  25675. opt.innerHTML = opt.value;
  25676. }
  25677. }
  25678. function augmentController(gui, li, controller) {
  25679. controller.__li = li;
  25680. controller.__gui = gui;
  25681. Common.extend(controller, {
  25682. options: function options(_options) {
  25683. if (arguments.length > 1) {
  25684. var nextSibling = controller.__li.nextElementSibling;
  25685. controller.remove();
  25686. return _add(gui, controller.object, controller.property, {
  25687. before: nextSibling,
  25688. factoryArgs: [Common.toArray(arguments)]
  25689. });
  25690. }
  25691. if (Common.isArray(_options) || Common.isObject(_options)) {
  25692. var _nextSibling = controller.__li.nextElementSibling;
  25693. controller.remove();
  25694. return _add(gui, controller.object, controller.property, {
  25695. before: _nextSibling,
  25696. factoryArgs: [_options]
  25697. });
  25698. }
  25699. },
  25700. name: function name(_name) {
  25701. controller.__li.firstElementChild.firstElementChild.innerHTML = _name;
  25702. return controller;
  25703. },
  25704. listen: function listen() {
  25705. controller.__gui.listen(controller);
  25706. return controller;
  25707. },
  25708. remove: function remove() {
  25709. controller.__gui.remove(controller);
  25710. return controller;
  25711. }
  25712. });
  25713. if (controller instanceof NumberControllerSlider) {
  25714. var box = new NumberControllerBox(controller.object, controller.property, {
  25715. min: controller.__min,
  25716. max: controller.__max,
  25717. step: controller.__step
  25718. });
  25719. Common.each(['updateDisplay', 'onChange', 'onFinishChange', 'step', 'min', 'max'], function (method) {
  25720. var pc = controller[method];
  25721. var pb = box[method];
  25722. controller[method] = box[method] = function () {
  25723. var args = Array.prototype.slice.call(arguments);
  25724. pb.apply(box, args);
  25725. return pc.apply(controller, args);
  25726. };
  25727. });
  25728. dom.addClass(li, 'has-slider');
  25729. controller.domElement.insertBefore(box.domElement, controller.domElement.firstElementChild);
  25730. } else if (controller instanceof NumberControllerBox) {
  25731. var r = function r(returned) {
  25732. if (Common.isNumber(controller.__min) && Common.isNumber(controller.__max)) {
  25733. var oldName = controller.__li.firstElementChild.firstElementChild.innerHTML;
  25734. var wasListening = controller.__gui.__listening.indexOf(controller) > -1;
  25735. controller.remove();
  25736. var newController = _add(gui, controller.object, controller.property, {
  25737. before: controller.__li.nextElementSibling,
  25738. factoryArgs: [controller.__min, controller.__max, controller.__step]
  25739. });
  25740. newController.name(oldName);
  25741. if (wasListening) newController.listen();
  25742. return newController;
  25743. }
  25744. return returned;
  25745. };
  25746. controller.min = Common.compose(r, controller.min);
  25747. controller.max = Common.compose(r, controller.max);
  25748. } else if (controller instanceof BooleanController) {
  25749. dom.bind(li, 'click', function () {
  25750. dom.fakeEvent(controller.__checkbox, 'click');
  25751. });
  25752. dom.bind(controller.__checkbox, 'click', function (e) {
  25753. e.stopPropagation();
  25754. });
  25755. } else if (controller instanceof FunctionController) {
  25756. dom.bind(li, 'click', function () {
  25757. dom.fakeEvent(controller.__button, 'click');
  25758. });
  25759. dom.bind(li, 'mouseover', function () {
  25760. dom.addClass(controller.__button, 'hover');
  25761. });
  25762. dom.bind(li, 'mouseout', function () {
  25763. dom.removeClass(controller.__button, 'hover');
  25764. });
  25765. } else if (controller instanceof ColorController) {
  25766. dom.addClass(li, 'color');
  25767. controller.updateDisplay = Common.compose(function (val) {
  25768. li.style.borderLeftColor = controller.__color.toString();
  25769. return val;
  25770. }, controller.updateDisplay);
  25771. controller.updateDisplay();
  25772. }
  25773. controller.setValue = Common.compose(function (val) {
  25774. if (gui.getRoot().__preset_select && controller.isModified()) {
  25775. markPresetModified(gui.getRoot(), true);
  25776. }
  25777. return val;
  25778. }, controller.setValue);
  25779. }
  25780. function recallSavedValue(gui, controller) {
  25781. var root = gui.getRoot();
  25782. var matchedIndex = root.__rememberedObjects.indexOf(controller.object);
  25783. if (matchedIndex !== -1) {
  25784. var controllerMap = root.__rememberedObjectIndecesToControllers[matchedIndex];
  25785. if (controllerMap === undefined) {
  25786. controllerMap = {};
  25787. root.__rememberedObjectIndecesToControllers[matchedIndex] = controllerMap;
  25788. }
  25789. controllerMap[controller.property] = controller;
  25790. if (root.load && root.load.remembered) {
  25791. var presetMap = root.load.remembered;
  25792. var preset = void 0;
  25793. if (presetMap[gui.preset]) {
  25794. preset = presetMap[gui.preset];
  25795. } else if (presetMap[DEFAULT_DEFAULT_PRESET_NAME]) {
  25796. preset = presetMap[DEFAULT_DEFAULT_PRESET_NAME];
  25797. } else {
  25798. return;
  25799. }
  25800. if (preset[matchedIndex] && preset[matchedIndex][controller.property] !== undefined) {
  25801. var value = preset[matchedIndex][controller.property];
  25802. controller.initialValue = value;
  25803. controller.setValue(value);
  25804. }
  25805. }
  25806. }
  25807. }
  25808. function _add(gui, object, property, params) {
  25809. if (object[property] === undefined) {
  25810. throw new Error('Object "' + object + '" has no property "' + property + '"');
  25811. }
  25812. var controller = void 0;
  25813. if (params.color) {
  25814. controller = new ColorController(object, property);
  25815. } else {
  25816. var factoryArgs = [object, property].concat(params.factoryArgs);
  25817. controller = ControllerFactory.apply(gui, factoryArgs);
  25818. }
  25819. if (params.before instanceof Controller) {
  25820. params.before = params.before.__li;
  25821. }
  25822. recallSavedValue(gui, controller);
  25823. dom.addClass(controller.domElement, 'c');
  25824. var name = document.createElement('span');
  25825. dom.addClass(name, 'property-name');
  25826. name.innerHTML = controller.property;
  25827. var container = document.createElement('div');
  25828. container.appendChild(name);
  25829. container.appendChild(controller.domElement);
  25830. var li = addRow(gui, container, params.before);
  25831. dom.addClass(li, GUI.CLASS_CONTROLLER_ROW);
  25832. if (controller instanceof ColorController) {
  25833. dom.addClass(li, 'color');
  25834. } else {
  25835. dom.addClass(li, _typeof(controller.getValue()));
  25836. }
  25837. augmentController(gui, li, controller);
  25838. gui.__controllers.push(controller);
  25839. return controller;
  25840. }
  25841. function getLocalStorageHash(gui, key) {
  25842. return document.location.href + '.' + key;
  25843. }
  25844. function addPresetOption(gui, name, setSelected) {
  25845. var opt = document.createElement('option');
  25846. opt.innerHTML = name;
  25847. opt.value = name;
  25848. gui.__preset_select.appendChild(opt);
  25849. if (setSelected) {
  25850. gui.__preset_select.selectedIndex = gui.__preset_select.length - 1;
  25851. }
  25852. }
  25853. function showHideExplain(gui, explain) {
  25854. explain.style.display = gui.useLocalStorage ? 'block' : 'none';
  25855. }
  25856. function addSaveMenu(gui) {
  25857. var div = gui.__save_row = document.createElement('li');
  25858. dom.addClass(gui.domElement, 'has-save');
  25859. gui.__ul.insertBefore(div, gui.__ul.firstChild);
  25860. dom.addClass(div, 'save-row');
  25861. var gears = document.createElement('span');
  25862. gears.innerHTML = '&nbsp;';
  25863. dom.addClass(gears, 'button gears');
  25864. var button = document.createElement('span');
  25865. button.innerHTML = 'Save';
  25866. dom.addClass(button, 'button');
  25867. dom.addClass(button, 'save');
  25868. var button2 = document.createElement('span');
  25869. button2.innerHTML = 'New';
  25870. dom.addClass(button2, 'button');
  25871. dom.addClass(button2, 'save-as');
  25872. var button3 = document.createElement('span');
  25873. button3.innerHTML = 'Revert';
  25874. dom.addClass(button3, 'button');
  25875. dom.addClass(button3, 'revert');
  25876. var select = gui.__preset_select = document.createElement('select');
  25877. if (gui.load && gui.load.remembered) {
  25878. Common.each(gui.load.remembered, function (value, key) {
  25879. addPresetOption(gui, key, key === gui.preset);
  25880. });
  25881. } else {
  25882. addPresetOption(gui, DEFAULT_DEFAULT_PRESET_NAME, false);
  25883. }
  25884. dom.bind(select, 'change', function () {
  25885. for (var index = 0; index < gui.__preset_select.length; index++) {
  25886. gui.__preset_select[index].innerHTML = gui.__preset_select[index].value;
  25887. }
  25888. gui.preset = this.value;
  25889. });
  25890. div.appendChild(select);
  25891. div.appendChild(gears);
  25892. div.appendChild(button);
  25893. div.appendChild(button2);
  25894. div.appendChild(button3);
  25895. if (SUPPORTS_LOCAL_STORAGE) {
  25896. var explain = document.getElementById('dg-local-explain');
  25897. var localStorageCheckBox = document.getElementById('dg-local-storage');
  25898. var saveLocally = document.getElementById('dg-save-locally');
  25899. saveLocally.style.display = 'block';
  25900. if (localStorage.getItem(getLocalStorageHash(gui, 'isLocal')) === 'true') {
  25901. localStorageCheckBox.setAttribute('checked', 'checked');
  25902. }
  25903. showHideExplain(gui, explain);
  25904. dom.bind(localStorageCheckBox, 'change', function () {
  25905. gui.useLocalStorage = !gui.useLocalStorage;
  25906. showHideExplain(gui, explain);
  25907. });
  25908. }
  25909. var newConstructorTextArea = document.getElementById('dg-new-constructor');
  25910. dom.bind(newConstructorTextArea, 'keydown', function (e) {
  25911. if (e.metaKey && (e.which === 67 || e.keyCode === 67)) {
  25912. SAVE_DIALOGUE.hide();
  25913. }
  25914. });
  25915. dom.bind(gears, 'click', function () {
  25916. newConstructorTextArea.innerHTML = JSON.stringify(gui.getSaveObject(), undefined, 2);
  25917. SAVE_DIALOGUE.show();
  25918. newConstructorTextArea.focus();
  25919. newConstructorTextArea.select();
  25920. });
  25921. dom.bind(button, 'click', function () {
  25922. gui.save();
  25923. });
  25924. dom.bind(button2, 'click', function () {
  25925. var presetName = prompt('Enter a new preset name.');
  25926. if (presetName) {
  25927. gui.saveAs(presetName);
  25928. }
  25929. });
  25930. dom.bind(button3, 'click', function () {
  25931. gui.revert();
  25932. });
  25933. }
  25934. function addResizeHandle(gui) {
  25935. var pmouseX = void 0;
  25936. gui.__resize_handle = document.createElement('div');
  25937. Common.extend(gui.__resize_handle.style, {
  25938. width: '6px',
  25939. marginLeft: '-3px',
  25940. height: '200px',
  25941. cursor: 'ew-resize',
  25942. position: 'absolute'
  25943. });
  25944. function drag(e) {
  25945. e.preventDefault();
  25946. gui.width += pmouseX - e.clientX;
  25947. gui.onResize();
  25948. pmouseX = e.clientX;
  25949. return false;
  25950. }
  25951. function dragStop() {
  25952. dom.removeClass(gui.__closeButton, GUI.CLASS_DRAG);
  25953. dom.unbind(window, 'mousemove', drag);
  25954. dom.unbind(window, 'mouseup', dragStop);
  25955. }
  25956. function dragStart(e) {
  25957. e.preventDefault();
  25958. pmouseX = e.clientX;
  25959. dom.addClass(gui.__closeButton, GUI.CLASS_DRAG);
  25960. dom.bind(window, 'mousemove', drag);
  25961. dom.bind(window, 'mouseup', dragStop);
  25962. return false;
  25963. }
  25964. dom.bind(gui.__resize_handle, 'mousedown', dragStart);
  25965. dom.bind(gui.__closeButton, 'mousedown', dragStart);
  25966. gui.domElement.insertBefore(gui.__resize_handle, gui.domElement.firstElementChild);
  25967. }
  25968. function setWidth(gui, w) {
  25969. gui.domElement.style.width = w + 'px';
  25970. if (gui.__save_row && gui.autoPlace) {
  25971. gui.__save_row.style.width = w + 'px';
  25972. }
  25973. if (gui.__closeButton) {
  25974. gui.__closeButton.style.width = w + 'px';
  25975. }
  25976. }
  25977. function getCurrentPreset(gui, useInitialValues) {
  25978. var toReturn = {};
  25979. Common.each(gui.__rememberedObjects, function (val, index) {
  25980. var savedValues = {};
  25981. var controllerMap = gui.__rememberedObjectIndecesToControllers[index];
  25982. Common.each(controllerMap, function (controller, property) {
  25983. savedValues[property] = useInitialValues ? controller.initialValue : controller.getValue();
  25984. });
  25985. toReturn[index] = savedValues;
  25986. });
  25987. return toReturn;
  25988. }
  25989. function setPresetSelectIndex(gui) {
  25990. for (var index = 0; index < gui.__preset_select.length; index++) {
  25991. if (gui.__preset_select[index].value === gui.preset) {
  25992. gui.__preset_select.selectedIndex = index;
  25993. }
  25994. }
  25995. }
  25996. function updateDisplays(controllerArray) {
  25997. if (controllerArray.length !== 0) {
  25998. requestAnimationFrame$1.call(window, function () {
  25999. updateDisplays(controllerArray);
  26000. });
  26001. }
  26002. Common.each(controllerArray, function (c) {
  26003. c.updateDisplay();
  26004. });
  26005. }
  26006. var color = {
  26007. Color: Color,
  26008. math: ColorMath,
  26009. interpret: interpret
  26010. };
  26011. exports.color = color;
  26012. var controllers = {
  26013. Controller: Controller,
  26014. BooleanController: BooleanController,
  26015. OptionController: OptionController,
  26016. StringController: StringController,
  26017. NumberController: NumberController,
  26018. NumberControllerBox: NumberControllerBox,
  26019. NumberControllerSlider: NumberControllerSlider,
  26020. FunctionController: FunctionController,
  26021. ColorController: ColorController
  26022. };
  26023. exports.controllers = controllers;
  26024. var dom$1 = {
  26025. dom: dom
  26026. };
  26027. exports.dom = dom$1;
  26028. var gui = {
  26029. GUI: GUI
  26030. };
  26031. exports.gui = gui;
  26032. var GUI$1 = GUI;
  26033. exports.GUI = GUI$1;
  26034. var index = {
  26035. color: color,
  26036. controllers: controllers,
  26037. dom: dom$1,
  26038. gui: gui,
  26039. GUI: GUI$1
  26040. };
  26041. var _default = index;
  26042. exports.default = _default;
  26043. }, {}], "node_modules/stats.js/build/stats.min.js": [function (require, module, exports) {
  26044. var define;
  26045. // stats.js - http://github.com/mrdoob/stats.js
  26046. (function (f, e) { "object" === typeof exports && "undefined" !== typeof module ? module.exports = e() : "function" === typeof define && define.amd ? define(e) : f.Stats = e() })(this, function () {
  26047. var f = function () {
  26048. function e(a) { c.appendChild(a.dom); return a } function u(a) { for (var d = 0; d < c.children.length; d++)c.children[d].style.display = d === a ? "block" : "none"; l = a } var l = 0, c = document.createElement("div"); c.style.cssText = "position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000"; c.addEventListener("click", function (a) {
  26049. a.preventDefault();
  26050. u(++l % c.children.length)
  26051. }, !1); var k = (performance || Date).now(), g = k, a = 0, r = e(new f.Panel("FPS", "#0ff", "#002")), h = e(new f.Panel("MS", "#0f0", "#020")); if (self.performance && self.performance.memory) var t = e(new f.Panel("MB", "#f08", "#201")); u(0); return {
  26052. REVISION: 16, dom: c, addPanel: e, showPanel: u, begin: function () { k = (performance || Date).now() }, end: function () {
  26053. a++; var c = (performance || Date).now(); h.update(c - k, 200); if (c > g + 1E3 && (r.update(1E3 * a / (c - g), 100), g = c, a = 0, t)) {
  26054. var d = performance.memory; t.update(d.usedJSHeapSize /
  26055. 1048576, d.jsHeapSizeLimit / 1048576)
  26056. } return c
  26057. }, update: function () { k = this.end() }, domElement: c, setMode: u
  26058. }
  26059. }; f.Panel = function (e, f, l) {
  26060. var c = Infinity, k = 0, g = Math.round, a = g(window.devicePixelRatio || 1), r = 80 * a, h = 48 * a, t = 3 * a, v = 2 * a, d = 3 * a, m = 15 * a, n = 74 * a, p = 30 * a, q = document.createElement("canvas"); q.width = r; q.height = h; q.style.cssText = "width:80px;height:48px"; var b = q.getContext("2d"); b.font = "bold " + 9 * a + "px Helvetica,Arial,sans-serif"; b.textBaseline = "top"; b.fillStyle = l; b.fillRect(0, 0, r, h); b.fillStyle = f; b.fillText(e, t, v);
  26061. b.fillRect(d, m, n, p); b.fillStyle = l; b.globalAlpha = .9; b.fillRect(d, m, n, p); return { dom: q, update: function (h, w) { c = Math.min(c, h); k = Math.max(k, h); b.fillStyle = l; b.globalAlpha = 1; b.fillRect(0, 0, r, m); b.fillStyle = f; b.fillText(g(h) + " " + e + " (" + g(c) + "-" + g(k) + ")", t, v); b.drawImage(q, d + a, m, n - a, p, d, m, n - a, p); b.fillRect(d + n - a, m, a, p); b.fillStyle = l; b.globalAlpha = .9; b.fillRect(d + n - a, m, a, g((1 - h / w) * p)) } }
  26062. }; return f
  26063. });
  26064. }, {}], "node_modules/@tensorflow/tfjs-layers/dist/tf-layers.esm.js": [function (require, module, exports) {
  26065. "use strict";
  26066. Object.defineProperty(exports, "__esModule", {
  26067. value: true
  26068. });
  26069. exports.input = input;
  26070. exports.loadLayersModel = loadLayersModel;
  26071. exports.model = model;
  26072. exports.registerCallbackConstructor = registerCallbackConstructor;
  26073. exports.sequential = sequential;
  26074. exports.version_layers = exports.LayerVariable = exports.Sequential = exports.RNN = exports.LayersModel = exports.SymbolicTensor = exports.InputSpec = exports.EarlyStopping = exports.callbacks = exports.Callback = exports.History = exports.CustomCallback = exports.CallbackList = exports.regularizers = exports.models = exports.metrics = exports.layers = exports.initializers = exports.constraints = void 0;
  26075. var _tfjsCore = require("@tensorflow/tfjs-core");
  26076. /**
  26077. * @license
  26078. * Copyright 2019 Google LLC. All Rights Reserved.
  26079. * Licensed under the Apache License, Version 2.0 (the "License");
  26080. * you may not use this file except in compliance with the License.
  26081. * You may obtain a copy of the License at
  26082. *
  26083. * http://www.apache.org/licenses/LICENSE-2.0
  26084. *
  26085. * Unless required by applicable law or agreed to in writing, software
  26086. * distributed under the License is distributed on an "AS IS" BASIS,
  26087. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  26088. * See the License for the specific language governing permissions and
  26089. * limitations under the License.
  26090. * =============================================================================
  26091. */
  26092. var extendStatics = function (e, t) {
  26093. return (extendStatics = Object.setPrototypeOf || {
  26094. __proto__: []
  26095. } instanceof Array && function (e, t) {
  26096. e.__proto__ = t;
  26097. } || function (e, t) {
  26098. for (var n in t) t.hasOwnProperty(n) && (e[n] = t[n]);
  26099. })(e, t);
  26100. };
  26101. function __extends(e, t) {
  26102. function n() {
  26103. this.constructor = e;
  26104. }
  26105. extendStatics(e, t), e.prototype = null === t ? Object.create(t) : (n.prototype = t.prototype, new n());
  26106. }
  26107. var _epsilon,
  26108. __assign = function () {
  26109. return (__assign = Object.assign || function (e) {
  26110. for (var t, n = 1, r = arguments.length; n < r; n++) for (var i in t = arguments[n]) Object.prototype.hasOwnProperty.call(t, i) && (e[i] = t[i]);
  26111. return e;
  26112. }).apply(this, arguments);
  26113. };
  26114. function __awaiter(e, t, n, r) {
  26115. return new (n || (n = Promise))(function (i, a) {
  26116. function o(e) {
  26117. try {
  26118. l(r.next(e));
  26119. } catch (e) {
  26120. a(e);
  26121. }
  26122. }
  26123. function s(e) {
  26124. try {
  26125. l(r.throw(e));
  26126. } catch (e) {
  26127. a(e);
  26128. }
  26129. }
  26130. function l(e) {
  26131. e.done ? i(e.value) : new n(function (t) {
  26132. t(e.value);
  26133. }).then(o, s);
  26134. }
  26135. l((r = r.apply(e, t || [])).next());
  26136. });
  26137. }
  26138. function __generator(e, t) {
  26139. var n,
  26140. r,
  26141. i,
  26142. a,
  26143. o = {
  26144. label: 0,
  26145. sent: function () {
  26146. if (1 & i[0]) throw i[1];
  26147. return i[1];
  26148. },
  26149. trys: [],
  26150. ops: []
  26151. };
  26152. return a = {
  26153. next: s(0),
  26154. throw: s(1),
  26155. return: s(2)
  26156. }, "function" == typeof Symbol && (a[Symbol.iterator] = function () {
  26157. return this;
  26158. }), a;
  26159. function s(a) {
  26160. return function (s) {
  26161. return function (a) {
  26162. if (n) throw new TypeError("Generator is already executing.");
  26163. for (; o;) try {
  26164. if (n = 1, r && (i = 2 & a[0] ? r.return : a[0] ? r.throw || ((i = r.return) && i.call(r), 0) : r.next) && !(i = i.call(r, a[1])).done) return i;
  26165. switch (r = 0, i && (a = [2 & a[0], i.value]), a[0]) {
  26166. case 0:
  26167. case 1:
  26168. i = a;
  26169. break;
  26170. case 4:
  26171. return o.label++, {
  26172. value: a[1],
  26173. done: !1
  26174. };
  26175. case 5:
  26176. o.label++, r = a[1], a = [0];
  26177. continue;
  26178. case 7:
  26179. a = o.ops.pop(), o.trys.pop();
  26180. continue;
  26181. default:
  26182. if (!(i = (i = o.trys).length > 0 && i[i.length - 1]) && (6 === a[0] || 2 === a[0])) {
  26183. o = 0;
  26184. continue;
  26185. }
  26186. if (3 === a[0] && (!i || a[1] > i[0] && a[1] < i[3])) {
  26187. o.label = a[1];
  26188. break;
  26189. }
  26190. if (6 === a[0] && o.label < i[1]) {
  26191. o.label = i[1], i = a;
  26192. break;
  26193. }
  26194. if (i && o.label < i[2]) {
  26195. o.label = i[2], o.ops.push(a);
  26196. break;
  26197. }
  26198. i[2] && o.ops.pop(), o.trys.pop();
  26199. continue;
  26200. }
  26201. a = t.call(e, o);
  26202. } catch (e) {
  26203. a = [6, e], r = 0;
  26204. } finally {
  26205. n = i = 0;
  26206. }
  26207. if (5 & a[0]) throw a[1];
  26208. return {
  26209. value: a[0] ? a[1] : void 0,
  26210. done: !0
  26211. };
  26212. }([a, s]);
  26213. };
  26214. }
  26215. }
  26216. function epsilon() {
  26217. return null == _epsilon && (_epsilon = (0, _tfjsCore.backend)().epsilon()), _epsilon;
  26218. }
  26219. function imageDataFormat() {
  26220. return "channelsLast";
  26221. }
  26222. var AttributeError = function (e) {
  26223. function t(n) {
  26224. var r = e.call(this, n) || this;
  26225. return Object.setPrototypeOf(r, t.prototype), r;
  26226. }
  26227. return __extends(t, e), t;
  26228. }(Error),
  26229. RuntimeError = function (e) {
  26230. function t(n) {
  26231. var r = e.call(this, n) || this;
  26232. return Object.setPrototypeOf(r, t.prototype), r;
  26233. }
  26234. return __extends(t, e), t;
  26235. }(Error),
  26236. ValueError = function (e) {
  26237. function t(n) {
  26238. var r = e.call(this, n) || this;
  26239. return Object.setPrototypeOf(r, t.prototype), r;
  26240. }
  26241. return __extends(t, e), t;
  26242. }(Error),
  26243. NotImplementedError = function (e) {
  26244. function t(n) {
  26245. var r = e.call(this, n) || this;
  26246. return Object.setPrototypeOf(r, t.prototype), r;
  26247. }
  26248. return __extends(t, e), t;
  26249. }(Error),
  26250. AssertionError = function (e) {
  26251. function t(n) {
  26252. var r = e.call(this, n) || this;
  26253. return Object.setPrototypeOf(r, t.prototype), r;
  26254. }
  26255. return __extends(t, e), t;
  26256. }(Error),
  26257. IndexError = function (e) {
  26258. function t(n) {
  26259. var r = e.call(this, n) || this;
  26260. return Object.setPrototypeOf(r, t.prototype), r;
  26261. }
  26262. return __extends(t, e), t;
  26263. }(Error);
  26264. function pyListRepeat(e, t) {
  26265. if (Array.isArray(e)) {
  26266. for (var n = [], r = 0; r < t; r++) n = n.concat(e);
  26267. return n;
  26268. }
  26269. return (n = new Array(t)).fill(e), n;
  26270. }
  26271. function assert(e, t) {
  26272. if (!e) throw new AssertionError(t);
  26273. }
  26274. function count(e, t) {
  26275. for (var n = 0, r = 0, i = e; r < i.length; r++) {
  26276. i[r] === t && n++;
  26277. }
  26278. return n;
  26279. }
  26280. function singletonOrArray(e) {
  26281. return 1 === e.length ? e[0] : e;
  26282. }
  26283. function toList(e) {
  26284. return Array.isArray(e) ? e : [e];
  26285. }
  26286. function toSnakeCase(e) {
  26287. var t = e.replace(/(.)([A-Z][a-z0-9]+)/g, "$1_$2").replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
  26288. return "_" !== t[0] ? t : "private" + t;
  26289. }
  26290. function toCamelCase(e) {
  26291. return e.length <= 1 ? e : -1 === e.indexOf("_") ? e : e.replace(/[_]+(\w|$)/g, function (e, t) {
  26292. return t.toUpperCase();
  26293. });
  26294. }
  26295. var _GLOBAL_CUSTOM_OBJECTS = {};
  26296. function serializeKerasObject(e) {
  26297. if (null === e || void 0 === e) return null;
  26298. var t = {};
  26299. return t.className = e.getClassName(), t.config = e.getConfig(), t;
  26300. }
  26301. function convertNDArrayScalarsInConfig(e) {
  26302. if (null != e && "object" == typeof e) if (Array.isArray(e)) e.forEach(function (e) {
  26303. return convertNDArrayScalarsInConfig(e);
  26304. }); else for (var t = 0, n = Object.keys(e); t < n.length; t++) {
  26305. var r = n[t],
  26306. i = e[r];
  26307. null != i && "object" == typeof i && (Array.isArray(i) || "ndarray" !== i.type || "number" != typeof i.value ? convertNDArrayScalarsInConfig(i) : e[r] = i.value);
  26308. }
  26309. }
  26310. function deserializeKerasObject(e, t, n, r, i) {
  26311. var a, o, s;
  26312. if (void 0 === t && (t = {}), void 0 === n && (n = {}), void 0 === r && (r = "object"), void 0 === i && (i = !1), "string" == typeof e) {
  26313. var l = e,
  26314. u = void 0;
  26315. if (l in n) u = n[l]; else if (l in _GLOBAL_CUSTOM_OBJECTS) u = _GLOBAL_CUSTOM_OBJECTS[l]; else if (null == (u = t[l])) throw new ValueError("Unknown " + r + ": " + e + ". This may be due to one of the following reasons:\n1. The " + r + " is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.\n2. The custom " + r + " is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().");
  26316. return u;
  26317. }
  26318. var c = e;
  26319. if (null == c.className || null == c.config) throw new ValueError(r + ": Improper config format: " + JSON.stringify(c) + ".\n'className' and 'config' must set.");
  26320. var p = c.className,
  26321. h = void 0,
  26322. d = void 0;
  26323. if (p in n ? (h = (a = n[p])[0], d = a[1]) : p in _GLOBAL_CUSTOM_OBJECTS ? (h = (o = _GLOBAL_CUSTOM_OBJECTS.className)[0], d = o[1]) : p in t && (h = (s = t[p])[0], d = s[1]), null == h) throw new ValueError("Unknown " + r + ": " + p + ". This may be due to one of the following reasons:\n1. The " + r + " is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.\n2. The custom " + r + " is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().");
  26324. if (null != d) {
  26325. for (var f = {}, g = 0, m = Object.keys(_GLOBAL_CUSTOM_OBJECTS); g < m.length; g++) {
  26326. f[S = m[g]] = _GLOBAL_CUSTOM_OBJECTS[S];
  26327. }
  26328. for (var y = 0, v = Object.keys(n); y < v.length; y++) {
  26329. f[S = v[y]] = n[S];
  26330. }
  26331. c.config.customObjects = f;
  26332. for (var b = __assign({}, _GLOBAL_CUSTOM_OBJECTS), w = 0, z = Object.keys(n); w < z.length; w++) {
  26333. var S = z[w];
  26334. _GLOBAL_CUSTOM_OBJECTS[S] = n[S];
  26335. }
  26336. convertNDArrayScalarsInConfig(c.config);
  26337. var A = d(h, c.config, n, i);
  26338. return _GLOBAL_CUSTOM_OBJECTS = __assign({}, b), A;
  26339. }
  26340. b = __assign({}, _GLOBAL_CUSTOM_OBJECTS);
  26341. for (var _ = 0, I = Object.keys(n); _ < I.length; _++) {
  26342. S = I[_];
  26343. _GLOBAL_CUSTOM_OBJECTS[S] = n[S];
  26344. }
  26345. A = new h(c.config);
  26346. return _GLOBAL_CUSTOM_OBJECTS = __assign({}, b), A;
  26347. }
  26348. function numberCompare(e, t) {
  26349. return e < t ? -1 : e > t ? 1 : 0;
  26350. }
  26351. function reverseNumberCompare(e, t) {
  26352. return -1 * numberCompare(e, t);
  26353. }
  26354. function unique(e) {
  26355. if (null == e) return e;
  26356. for (var t = [], n = 0, r = e; n < r.length; n++) {
  26357. var i = r[n];
  26358. -1 === t.indexOf(i) && t.push(i);
  26359. }
  26360. return t;
  26361. }
  26362. function isObjectEmpty(e) {
  26363. if (null == e) throw new ValueError("Invalid value in obj: " + JSON.stringify(e));
  26364. for (var t in e) if (e.hasOwnProperty(t)) return !1;
  26365. return !0;
  26366. }
  26367. function checkStringTypeUnionValue(e, t, n) {
  26368. if (null != n && e.indexOf(n) < 0) throw new ValueError(n + " is not a valid " + t + ". Valid values are " + e + " or null/undefined.");
  26369. }
  26370. function checkArrayTypeAndLength(e, t, n, r) {
  26371. return void 0 === n && (n = 0), void 0 === r && (r = 1 / 0), assert(n >= 0), assert(r >= n), Array.isArray(e) && e.length >= n && e.length <= r && e.every(function (e) {
  26372. return typeof e === t;
  26373. });
  26374. }
  26375. function assertPositiveInteger(e, t) {
  26376. Array.isArray(e) ? (_tfjsCore.util.assert(e.length > 0, function () {
  26377. return t + " is unexpectedly an empty array.";
  26378. }), e.forEach(function (e, n) {
  26379. return assertPositiveInteger(e, "element " + (n + 1) + " of " + t);
  26380. })) : _tfjsCore.util.assert(Number.isInteger(e) && e > 0, function () {
  26381. return "Expected " + t + " to be a positive integer, but got " + formatAsFriendlyString(e) + ".";
  26382. });
  26383. }
  26384. function formatAsFriendlyString(e) {
  26385. return null === e ? "null" : Array.isArray(e) ? "[" + e.map(function (e) {
  26386. return formatAsFriendlyString(e);
  26387. }).join(",") + "]" : "string" == typeof e ? '"' + e + '"' : "" + e;
  26388. }
  26389. function debounce(e, t) {
  26390. var n,
  26391. r = _tfjsCore.util.now();
  26392. return function () {
  26393. for (var i = [], a = 0; a < arguments.length; a++) i[a] = arguments[a];
  26394. var o = _tfjsCore.util.now();
  26395. return o - r < t ? n : (r = o, n = e.apply(void 0, i));
  26396. };
  26397. }
  26398. function mapActivationToFusedKernel(e) {
  26399. return "relu" === e ? "relu" : "linear" === e ? "linear" : "elu" === e ? "elu" : null;
  26400. }
  26401. function calcL2Norms(e, t) {
  26402. return (0, _tfjsCore.tidy)(function () {
  26403. return (0, _tfjsCore.sqrt)((0, _tfjsCore.sum)((0, _tfjsCore.mulStrict)(e, e), t, !0));
  26404. });
  26405. }
  26406. var Constraint = function (e) {
  26407. function t() {
  26408. return null !== e && e.apply(this, arguments) || this;
  26409. }
  26410. return __extends(t, e), t.prototype.getConfig = function () {
  26411. return {};
  26412. }, t;
  26413. }(_tfjsCore.serialization.Serializable),
  26414. MaxNorm = function (e) {
  26415. function t(t) {
  26416. var n = e.call(this) || this;
  26417. return n.defaultMaxValue = 2, n.defaultAxis = 0, n.maxValue = null != t.maxValue ? t.maxValue : n.defaultMaxValue, n.axis = null != t.axis ? t.axis : n.defaultAxis, n;
  26418. }
  26419. return __extends(t, e), t.prototype.apply = function (e) {
  26420. var t = this;
  26421. return (0, _tfjsCore.tidy)(function () {
  26422. var n = calcL2Norms(e, t.axis),
  26423. r = (0, _tfjsCore.clipByValue)(n, 0, t.maxValue);
  26424. return (0, _tfjsCore.mul)(e, (0, _tfjsCore.div)(r, (0, _tfjsCore.add)(epsilon(), n)));
  26425. });
  26426. }, t.prototype.getConfig = function () {
  26427. return {
  26428. maxValue: this.maxValue,
  26429. axis: this.axis
  26430. };
  26431. }, t.className = "MaxNorm", t;
  26432. }(Constraint);
  26433. _tfjsCore.serialization.registerClass(MaxNorm);
  26434. var UnitNorm = function (e) {
  26435. function t(t) {
  26436. var n = e.call(this) || this;
  26437. return n.defaultAxis = 0, n.axis = null != t.axis ? t.axis : n.defaultAxis, n;
  26438. }
  26439. return __extends(t, e), t.prototype.apply = function (e) {
  26440. var t = this;
  26441. return (0, _tfjsCore.tidy)(function () {
  26442. return (0, _tfjsCore.div)(e, (0, _tfjsCore.add)(epsilon(), calcL2Norms(e, t.axis)));
  26443. });
  26444. }, t.prototype.getConfig = function () {
  26445. return {
  26446. axis: this.axis
  26447. };
  26448. }, t.className = "UnitNorm", t;
  26449. }(Constraint);
  26450. _tfjsCore.serialization.registerClass(UnitNorm);
  26451. var NonNeg = function (e) {
  26452. function t() {
  26453. return null !== e && e.apply(this, arguments) || this;
  26454. }
  26455. return __extends(t, e), t.prototype.apply = function (e) {
  26456. return (0, _tfjsCore.relu)(e);
  26457. }, t.className = "NonNeg", t;
  26458. }(Constraint);
  26459. _tfjsCore.serialization.registerClass(NonNeg);
  26460. var MinMaxNorm = function (e) {
  26461. function t(t) {
  26462. var n = e.call(this) || this;
  26463. return n.defaultMinValue = 0, n.defaultMaxValue = 1, n.defaultRate = 1, n.defaultAxis = 0, n.minValue = null != t.minValue ? t.minValue : n.defaultMinValue, n.maxValue = null != t.maxValue ? t.maxValue : n.defaultMaxValue, n.rate = null != t.rate ? t.rate : n.defaultRate, n.axis = null != t.axis ? t.axis : n.defaultAxis, n;
  26464. }
  26465. return __extends(t, e), t.prototype.apply = function (e) {
  26466. var t = this;
  26467. return (0, _tfjsCore.tidy)(function () {
  26468. var n = calcL2Norms(e, t.axis),
  26469. r = (0, _tfjsCore.add)((0, _tfjsCore.mul)(t.rate, (0, _tfjsCore.clipByValue)(n, t.minValue, t.maxValue)), (0, _tfjsCore.mul)(1 - t.rate, n));
  26470. return (0, _tfjsCore.mul)(e, (0, _tfjsCore.div)(r, (0, _tfjsCore.add)(epsilon(), n)));
  26471. });
  26472. }, t.prototype.getConfig = function () {
  26473. return {
  26474. minValue: this.minValue,
  26475. maxValue: this.maxValue,
  26476. rate: this.rate,
  26477. axis: this.axis
  26478. };
  26479. }, t.className = "MinMaxNorm", t;
  26480. }(Constraint);
  26481. _tfjsCore.serialization.registerClass(MinMaxNorm);
  26482. var CONSTRAINT_IDENTIFIER_REGISTRY_SYMBOL_MAP = {
  26483. maxNorm: "MaxNorm",
  26484. minMaxNorm: "MinMaxNorm",
  26485. nonNeg: "NonNeg",
  26486. unitNorm: "UnitNorm"
  26487. };
  26488. function serializeConstraint(e) {
  26489. return serializeKerasObject(e);
  26490. }
  26491. function deserializeConstraint(e, t) {
  26492. return void 0 === t && (t = {}), deserializeKerasObject(e, _tfjsCore.serialization.SerializationMap.getMap().classNameMap, t, "constraint");
  26493. }
  26494. function getConstraint(e) {
  26495. return null == e ? null : "string" == typeof e ? deserializeConstraint({
  26496. className: e in CONSTRAINT_IDENTIFIER_REGISTRY_SYMBOL_MAP ? CONSTRAINT_IDENTIFIER_REGISTRY_SYMBOL_MAP[e] : e,
  26497. config: {}
  26498. }) : e instanceof Constraint ? e : deserializeConstraint(e);
  26499. }
  26500. function maxNorm(e) {
  26501. return new MaxNorm(e);
  26502. }
  26503. function unitNorm(e) {
  26504. return new UnitNorm(e);
  26505. }
  26506. function nonNeg() {
  26507. return new NonNeg();
  26508. }
  26509. function minMaxNorm(e) {
  26510. return new MinMaxNorm(e);
  26511. }
  26512. var exports_constraints = Object.freeze({
  26513. maxNorm: maxNorm,
  26514. unitNorm: unitNorm,
  26515. nonNeg: nonNeg,
  26516. minMaxNorm: minMaxNorm
  26517. }),
  26518. VALID_DATA_FORMAT_VALUES = ["channelsFirst", "channelsLast"],
  26519. VALID_PADDING_MODE_VALUES = ["valid", "same", "causal"],
  26520. VALID_POOL_MODE_VALUES = ["max", "avg"],
  26521. VALID_BIDIRECTIONAL_MERGE_MODES = ["sum", "mul", "concat", "ave"],
  26522. nameMap = new Map();
  26523. exports.constraints = exports_constraints;
  26524. function checkDataFormat(e) {
  26525. checkStringTypeUnionValue(VALID_DATA_FORMAT_VALUES, "DataFormat", e);
  26526. }
  26527. function checkPaddingMode(e) {
  26528. checkStringTypeUnionValue(VALID_PADDING_MODE_VALUES, "PaddingMode", e);
  26529. }
  26530. function checkPoolMode(e) {
  26531. checkStringTypeUnionValue(VALID_POOL_MODE_VALUES, "PoolMode", e);
  26532. }
  26533. var _nameScopeStack = [],
  26534. _nameScopeDivider = "/";
  26535. function nameScope(e, t) {
  26536. _nameScopeStack.push(e);
  26537. try {
  26538. var n = t();
  26539. return _nameScopeStack.pop(), n;
  26540. } catch (e) {
  26541. throw _nameScopeStack.pop(), e;
  26542. }
  26543. }
  26544. function currentNameScopePrefix() {
  26545. return 0 === _nameScopeStack.length ? "" : _nameScopeStack.join(_nameScopeDivider) + _nameScopeDivider;
  26546. }
  26547. function getScopedTensorName(e) {
  26548. if (!isValidTensorName(e)) throw new Error("Not a valid tensor name: '" + e + "'");
  26549. return currentNameScopePrefix() + e;
  26550. }
  26551. function getUniqueTensorName(e) {
  26552. if (!isValidTensorName(e)) throw new Error("Not a valid tensor name: '" + e + "'");
  26553. nameMap.has(e) || nameMap.set(e, 0);
  26554. var t = nameMap.get(e);
  26555. if (nameMap.set(e, nameMap.get(e) + 1), t > 0) {
  26556. var n = e + "_" + t;
  26557. return nameMap.set(n, 1), n;
  26558. }
  26559. return e;
  26560. }
  26561. var tensorNameRegex = new RegExp(/^[A-Za-z0-9][-A-Za-z0-9\._\/]*$/);
  26562. function isValidTensorName(e) {
  26563. return !!e.match(tensorNameRegex);
  26564. }
  26565. function isInteger(e) {
  26566. return e === parseInt(e.toString(), 10);
  26567. }
  26568. function arrayProd(e, t, n) {
  26569. null == t && (t = 0), null == n && (n = e.length);
  26570. for (var r = 1, i = t; i < n; ++i) r *= e[i];
  26571. return r;
  26572. }
  26573. function toArray1D(e) {
  26574. return e = Array.isArray(e) ? new Float32Array(e) : e, (0, _tfjsCore.tensor1d)(e);
  26575. }
  26576. function min$1(e) {
  26577. return (0, _tfjsCore.min)(toArray1D(e)).dataSync()[0];
  26578. }
  26579. function max$1(e) {
  26580. return (0, _tfjsCore.max)(toArray1D(e)).dataSync()[0];
  26581. }
  26582. function range(e, t) {
  26583. if (t < e) throw new ValueError("end (" + t + ") < begin (" + e + ") is forbidden.");
  26584. for (var n = [], r = e; r < t; ++r) n.push(r);
  26585. return n;
  26586. }
  26587. function cast$1(e, t) {
  26588. return e.asType(t);
  26589. }
  26590. function expandDims$1(e, t) {
  26591. void 0 === t && (t = -1);
  26592. var n = e.shape.slice();
  26593. return t < 0 && (t = n.length + t + 1), n.splice(t, 0, 1), e.reshape(n);
  26594. }
  26595. function repeat(e, t) {
  26596. return (0, _tfjsCore.tidy)(function () {
  26597. if (2 !== e.shape.length) throw new ValueError("repeat() expects a rank-2 tensor, but received a rank-" + e.shape.length + " tensor.");
  26598. return tile$1(expandDims$1(e, 1), [1, t, 1]);
  26599. });
  26600. }
  26601. function flatten(e) {
  26602. var t = [arrayProd(e.shape)];
  26603. return e.reshape(t);
  26604. }
  26605. function batchFlatten(e) {
  26606. if (e.rank <= 1) throw new ValueError("batchFlatten requires a minimum rank of 2. Got rank: " + e.rank + ".");
  26607. var t = [e.shape[0], arrayProd(e.shape, 1)];
  26608. return e.reshape(t);
  26609. }
  26610. function sliceAlongFirstAxis(e, t, n) {
  26611. return (0, _tfjsCore.tidy)(function () {
  26612. switch (e.rank) {
  26613. case 1:
  26614. return (0, _tfjsCore.slice1d)(e, t, n);
  26615. case 2:
  26616. return (0, _tfjsCore.slice2d)(e, [t, 0], [n, e.shape[1]]);
  26617. case 3:
  26618. return (0, _tfjsCore.slice3d)(e, [t, 0, 0], [n, e.shape[1], e.shape[2]]);
  26619. case 4:
  26620. return (0, _tfjsCore.slice4d)(e, [t, 0, 0, 0], [n, e.shape[1], e.shape[2], e.shape[3]]);
  26621. case 5:
  26622. return (0, _tfjsCore.slice)(e, [t, 0, 0, 0, 0], [n, e.shape[1], e.shape[2], e.shape[3], e.shape[4]]);
  26623. case 6:
  26624. return (0, _tfjsCore.slice)(e, [t, 0, 0, 0, 0, 0], [n, e.shape[1], e.shape[2], e.shape[3], e.shape[4], e.shape[5]]);
  26625. default:
  26626. throw new ValueError("sliceAlongFirstAxis() received an unsupported tensor rank: " + e.rank);
  26627. }
  26628. });
  26629. }
  26630. function sliceAlongLastAxis(e, t, n) {
  26631. return (0, _tfjsCore.tidy)(function () {
  26632. switch (e.rank) {
  26633. case 1:
  26634. return (0, _tfjsCore.slice1d)(e, t, n);
  26635. case 2:
  26636. return (0, _tfjsCore.slice2d)(e, [0, t], [e.shape[0], n]);
  26637. case 3:
  26638. return (0, _tfjsCore.slice3d)(e, [0, 0, t], [e.shape[0], e.shape[1], n]);
  26639. case 4:
  26640. return (0, _tfjsCore.slice4d)(e, [0, 0, 0, t], [e.shape[0], e.shape[1], e.shape[2], n]);
  26641. default:
  26642. throw new ValueError("sliceAlongLastAxis() received an unsupported tensor rank: " + e.rank);
  26643. }
  26644. });
  26645. }
  26646. function sliceAlongAxis(e, t, n, r) {
  26647. return (0, _tfjsCore.tidy)(function () {
  26648. switch (e.rank) {
  26649. case 1:
  26650. return (0, _tfjsCore.slice1d)(e, t, n);
  26651. case 2:
  26652. switch (r) {
  26653. case 1:
  26654. return sliceAlongFirstAxis(e, t, n);
  26655. case 2:
  26656. return sliceAlongLastAxis(e, t, n);
  26657. default:
  26658. throw new ValueError("The axis is not within the rank of the tensor " + r);
  26659. }
  26660. case 3:
  26661. switch (r) {
  26662. case 1:
  26663. return sliceAlongFirstAxis(e, t, n);
  26664. case 2:
  26665. return (0, _tfjsCore.slice3d)(e, [0, t, 0], [e.shape[0], n, e.shape[2]]);
  26666. case 3:
  26667. return sliceAlongLastAxis(e, t, n);
  26668. default:
  26669. throw new ValueError("The axis is not within the rank of the tensor " + r);
  26670. }
  26671. case 4:
  26672. switch (r) {
  26673. case 1:
  26674. return sliceAlongFirstAxis(e, t, n);
  26675. case 2:
  26676. return (0, _tfjsCore.slice4d)(e, [0, t, 0, 0], [e.shape[0], n, e.shape[2], e.shape[3]]);
  26677. case 3:
  26678. return (0, _tfjsCore.slice4d)(e, [0, 0, t, 0], [e.shape[0], e.shape[1], n, e.shape[3]]);
  26679. case 4:
  26680. return sliceAlongLastAxis(e, t, n);
  26681. default:
  26682. throw new ValueError("The axis is not within the rank of the tensor " + r);
  26683. }
  26684. default:
  26685. throw new ValueError("sliceAlongLastAxis() received an unsupported tensor rank: " + e.rank);
  26686. }
  26687. });
  26688. }
  26689. function concatenate(e, t) {
  26690. var n;
  26691. return void 0 === t && (t = -1), t < 0 && (t = 0 !== (n = e[0].rank) ? n : 0), t === e[0].rank && (t = -1), (0, _tfjsCore.concat)(e, t);
  26692. }
  26693. function concatAlongFirstAxis(e, t) {
  26694. switch (e.rank) {
  26695. case 1:
  26696. return (0, _tfjsCore.concat1d)([e, t]);
  26697. case 2:
  26698. return (0, _tfjsCore.concat2d)([e, t], 0);
  26699. case 3:
  26700. return (0, _tfjsCore.concat3d)([e, t], 0);
  26701. case 4:
  26702. return (0, _tfjsCore.concat4d)([e, t], 0);
  26703. default:
  26704. throw new ValueError("concatAlongFirstAxis() received an unsupported tensor rank: " + e.rank);
  26705. }
  26706. }
  26707. function tile$1(e, t) {
  26708. if (Array.isArray(t) || (t = [t]), e.rank !== t.length) throw new ValueError("The length of input n (" + t.length + ") does not match the number of dimensions in input x (" + e.rank + ")");
  26709. return (0, _tfjsCore.tile)(e, t);
  26710. }
  26711. function randomNormal$1(e, t, n, r, i) {
  26712. return void 0 === t && (t = 0), void 0 === n && (n = 1), (0, _tfjsCore.randomNormal)(e, t, n, r, i);
  26713. }
  26714. function dot(e, t, n, r) {
  26715. if (e.rank < 2 || t.rank < 2) throw new NotImplementedError("dot requires both inputs to be rank >= 2 but got x shape = " + e.shape + " and y shape = " + t.shape);
  26716. if (t.rank >= 3 && e.shape.slice(-1)[0] !== (c = t.shape.slice(-2)[0])) throw new NotImplementedError("If rank y >= 3, then the second last dim of y must equal the last dim of x but got x shape = " + e.shape + " and y shape = " + t.shape);
  26717. if (2 === e.rank && 2 === t.rank) {
  26718. var i = !1,
  26719. a = !1;
  26720. return _tfjsCore.fused.matMul({
  26721. a: e,
  26722. b: t,
  26723. transposeA: i,
  26724. transposeB: a,
  26725. bias: r ? reshapeBias(e.rank, r, imageDataFormat()) : null,
  26726. activation: n
  26727. });
  26728. }
  26729. var o = e.shape.slice(),
  26730. s = o.pop();
  26731. e = e.reshape([-1, s]);
  26732. var l = t.shape.slice(),
  26733. u = l.pop(),
  26734. c = l.pop(),
  26735. p = l.concat([u]),
  26736. h = Array.from({
  26737. length: t.rank
  26738. }, function (e, n) {
  26739. return 0 === n ? t.rank - 2 : n <= t.rank - 2 ? n - 1 : n;
  26740. });
  26741. t = t.transpose(h).reshape([c, -1]);
  26742. var d = o.concat(p);
  26743. i = !1, a = !1;
  26744. return _tfjsCore.fused.matMul({
  26745. a: e,
  26746. b: t,
  26747. transposeA: i,
  26748. transposeB: a,
  26749. bias: r ? reshapeBias(e.rank, r, imageDataFormat()) : null,
  26750. activation: n
  26751. }).reshape(d);
  26752. }
  26753. function gather$1(e, t, n) {
  26754. return (0, _tfjsCore.tidy)(function () {
  26755. return t = Array.isArray(t) ? (0, _tfjsCore.tensor1d)(t, "int32") : t.toInt(), (0, _tfjsCore.gather)(e, t, n);
  26756. });
  26757. }
  26758. function square(e) {
  26759. return (0, _tfjsCore.mulStrict)(e, e);
  26760. }
  26761. function reshapeBias(e, t, n) {
  26762. var r = t.shape;
  26763. if (1 !== t.rank && t.rank !== e) throw new ValueError("Unexpected bias dimensions: " + t.rank + "; expected it to be 1 or " + e);
  26764. if (5 === e) {
  26765. if ("channelsFirst" === n) return 1 === r.length ? t.reshape([1, r[0], 1, 1, 1]) : t.reshape([1, r[3], r[0], r[1], r[2]]);
  26766. if ("channelsLast" === n) return 1 === r.length ? t.reshape([1, 1, 1, 1, r[0]]) : t.reshape([1].concat(r));
  26767. } else if (4 === e) {
  26768. if ("channelsFirst" === n) return 1 === r.length ? t.reshape([1, r[0], 1, 1]) : t.reshape([1, r[2], r[0], r[1]]);
  26769. if ("channelsLast" === n) return 1 === r.length ? t.reshape([1, 1, 1, r[0]]) : t.reshape([1].concat(r));
  26770. } else if (3 === e) {
  26771. if ("channelsFirst" === n) return 1 === r.length ? t.reshape([1, r[0], 1]) : t.reshape([1, r[1], r[0]]);
  26772. if ("channelsLast" === n) return 1 === r.length ? t.reshape([1, 1, r[0]]) : t.reshape([1].concat(r));
  26773. } else if (e < 3) return t;
  26774. throw new ValueError("Unsupported input rank by biasAdd: " + t.rank);
  26775. }
  26776. function biasAdd(e, t, n) {
  26777. return (0, _tfjsCore.tidy)(function () {
  26778. return null == n && (n = imageDataFormat()), checkDataFormat(n), e.add(reshapeBias(e.rank, t, n));
  26779. });
  26780. }
  26781. function elu$1(e, t) {
  26782. if (void 0 === t && (t = 1), 1 !== t) throw new NotImplementedError("Support for alpha values other than 1 (" + t + ") is not implemented yet.");
  26783. return (0, _tfjsCore.elu)(e);
  26784. }
  26785. function softsign(e) {
  26786. return (0, _tfjsCore.tidy)(function () {
  26787. return (0, _tfjsCore.div)(e, (0, _tfjsCore.abs)(e).add(1));
  26788. });
  26789. }
  26790. function dropout$1(e, t, n, r) {
  26791. return (0, _tfjsCore.tidy)(function () {
  26792. return (0, _tfjsCore.dropout)(e, t, n, r);
  26793. });
  26794. }
  26795. function hardSigmoid(e) {
  26796. return (0, _tfjsCore.tidy)(function () {
  26797. var t = (0, _tfjsCore.add)(.5, (0, _tfjsCore.mul)(.2, e));
  26798. return (0, _tfjsCore.clipByValue)(t, 0, 1);
  26799. });
  26800. }
  26801. function inTrainPhase(e, t, n) {
  26802. return void 0 === n && (n = !1), n ? e() : t();
  26803. }
  26804. var VALID_FAN_MODE_VALUES = ["fanIn", "fanOut", "fanAvg"],
  26805. VALID_DISTRIBUTION_VALUES = ["normal", "uniform", "truncatedNormal"];
  26806. function checkFanMode(e) {
  26807. checkStringTypeUnionValue(VALID_FAN_MODE_VALUES, "FanMode", e);
  26808. }
  26809. function checkDistribution(e) {
  26810. checkStringTypeUnionValue(VALID_DISTRIBUTION_VALUES, "Distribution", e);
  26811. }
  26812. var Initializer = function (e) {
  26813. function t() {
  26814. return null !== e && e.apply(this, arguments) || this;
  26815. }
  26816. return __extends(t, e), t.prototype.fromConfigUsesCustomObjects = function () {
  26817. return !1;
  26818. }, t.prototype.getConfig = function () {
  26819. return {};
  26820. }, t;
  26821. }(_tfjsCore.serialization.Serializable),
  26822. Zeros = function (e) {
  26823. function t() {
  26824. return null !== e && e.apply(this, arguments) || this;
  26825. }
  26826. return __extends(t, e), t.prototype.apply = function (e, t) {
  26827. return (0, _tfjsCore.zeros)(e, t);
  26828. }, t.className = "Zeros", t;
  26829. }(Initializer);
  26830. _tfjsCore.serialization.registerClass(Zeros);
  26831. var Ones = function (e) {
  26832. function t() {
  26833. return null !== e && e.apply(this, arguments) || this;
  26834. }
  26835. return __extends(t, e), t.prototype.apply = function (e, t) {
  26836. return (0, _tfjsCore.ones)(e, t);
  26837. }, t.className = "Ones", t;
  26838. }(Initializer);
  26839. _tfjsCore.serialization.registerClass(Ones);
  26840. var Constant = function (e) {
  26841. function t(t) {
  26842. var n = e.call(this) || this;
  26843. if ("object" != typeof t) throw new ValueError("Expected argument of type ConstantConfig but got " + t);
  26844. if (void 0 === t.value) throw new ValueError("config must have value set but got " + t);
  26845. return n.value = t.value, n;
  26846. }
  26847. return __extends(t, e), t.prototype.apply = function (e, t) {
  26848. var n = this;
  26849. return (0, _tfjsCore.tidy)(function () {
  26850. return (0, _tfjsCore.mul)((0, _tfjsCore.scalar)(n.value), (0, _tfjsCore.ones)(e, t));
  26851. });
  26852. }, t.prototype.getConfig = function () {
  26853. return {
  26854. value: this.value
  26855. };
  26856. }, t.className = "Constant", t;
  26857. }(Initializer);
  26858. _tfjsCore.serialization.registerClass(Constant);
  26859. var RandomUniform = function (e) {
  26860. function t(t) {
  26861. var n = e.call(this) || this;
  26862. return n.DEFAULT_MINVAL = -.05, n.DEFAULT_MAXVAL = .05, n.minval = t.minval || n.DEFAULT_MINVAL, n.maxval = t.maxval || n.DEFAULT_MAXVAL, n.seed = t.seed, n;
  26863. }
  26864. return __extends(t, e), t.prototype.apply = function (e, t) {
  26865. return (0, _tfjsCore.randomUniform)(e, this.minval, this.maxval, t);
  26866. }, t.prototype.getConfig = function () {
  26867. return {
  26868. minval: this.minval,
  26869. maxval: this.maxval,
  26870. seed: this.seed
  26871. };
  26872. }, t.className = "RandomUniform", t;
  26873. }(Initializer);
  26874. _tfjsCore.serialization.registerClass(RandomUniform);
  26875. var RandomNormal = function (e) {
  26876. function t(t) {
  26877. var n = e.call(this) || this;
  26878. return n.DEFAULT_MEAN = 0, n.DEFAULT_STDDEV = .05, n.mean = t.mean || n.DEFAULT_MEAN, n.stddev = t.stddev || n.DEFAULT_STDDEV, n.seed = t.seed, n;
  26879. }
  26880. return __extends(t, e), t.prototype.apply = function (e, t) {
  26881. if ("float32" !== (t = t || "float32") && "int32" !== t) throw new NotImplementedError("randomNormal does not support dType " + t + ".");
  26882. return randomNormal$1(e, this.mean, this.stddev, t, this.seed);
  26883. }, t.prototype.getConfig = function () {
  26884. return {
  26885. mean: this.mean,
  26886. stddev: this.stddev,
  26887. seed: this.seed
  26888. };
  26889. }, t.className = "RandomNormal", t;
  26890. }(Initializer);
  26891. _tfjsCore.serialization.registerClass(RandomNormal);
  26892. var TruncatedNormal = function (e) {
  26893. function t(t) {
  26894. var n = e.call(this) || this;
  26895. return n.DEFAULT_MEAN = 0, n.DEFAULT_STDDEV = .05, n.mean = t.mean || n.DEFAULT_MEAN, n.stddev = t.stddev || n.DEFAULT_STDDEV, n.seed = t.seed, n;
  26896. }
  26897. return __extends(t, e), t.prototype.apply = function (e, t) {
  26898. if ("float32" !== (t = t || "float32") && "int32" !== t) throw new NotImplementedError("truncatedNormal does not support dType " + t + ".");
  26899. return (0, _tfjsCore.truncatedNormal)(e, this.mean, this.stddev, t, this.seed);
  26900. }, t.prototype.getConfig = function () {
  26901. return {
  26902. mean: this.mean,
  26903. stddev: this.stddev,
  26904. seed: this.seed
  26905. };
  26906. }, t.className = "TruncatedNormal", t;
  26907. }(Initializer);
  26908. _tfjsCore.serialization.registerClass(TruncatedNormal);
  26909. var Identity = function (e) {
  26910. function t(t) {
  26911. var n = e.call(this) || this;
  26912. return n.gain = null != t.gain ? t.gain : 1, n;
  26913. }
  26914. return __extends(t, e), t.prototype.apply = function (e, t) {
  26915. var n = this;
  26916. return (0, _tfjsCore.tidy)(function () {
  26917. if (2 !== e.length || e[0] !== e[1]) throw new ValueError("Identity matrix initializer can only be used for 2D square matrices.");
  26918. return (0, _tfjsCore.mul)(n.gain, (0, _tfjsCore.eye)(e[0]));
  26919. });
  26920. }, t.prototype.getConfig = function () {
  26921. return {
  26922. gain: this.gain
  26923. };
  26924. }, t.className = "Identity", t;
  26925. }(Initializer);
  26926. function computeFans(e, t) {
  26927. var n, r;
  26928. if (void 0 === t && (t = "channelsLast"), checkDataFormat(t), 2 === e.length) n = e[0], r = e[1]; else if (-1 !== [3, 4, 5].indexOf(e.length)) {
  26929. if ("channelsFirst" === t) {
  26930. var i = arrayProd(e, 2);
  26931. n = e[1] * i, r = e[0] * i;
  26932. } else if ("channelsLast" === t) {
  26933. i = arrayProd(e, 0, e.length - 2);
  26934. n = e[e.length - 2] * i, r = e[e.length - 1] * i;
  26935. }
  26936. } else {
  26937. var a = arrayProd(e);
  26938. n = Math.sqrt(a), r = Math.sqrt(a);
  26939. }
  26940. return [n, r];
  26941. }
  26942. _tfjsCore.serialization.registerClass(Identity);
  26943. var VarianceScaling = function (e) {
  26944. function t(t) {
  26945. var n = e.call(this) || this;
  26946. if (t.scale < 0) throw new ValueError("scale must be a positive float. Got: " + t.scale);
  26947. return n.scale = null == t.scale ? 1 : t.scale, n.mode = null == t.mode ? "fanIn" : t.mode, checkFanMode(n.mode), n.distribution = null == t.distribution ? "normal" : t.distribution, checkDistribution(n.distribution), n.seed = t.seed, n;
  26948. }
  26949. return __extends(t, e), t.prototype.apply = function (e, t) {
  26950. var n = computeFans(e),
  26951. r = n[0],
  26952. i = n[1],
  26953. a = this.scale;
  26954. if ("fanIn" === this.mode ? a /= Math.max(1, r) : "fanOut" === this.mode ? a /= Math.max(1, i) : a /= Math.max(1, (r + i) / 2), "normal" === this.distribution) {
  26955. var o = Math.sqrt(a);
  26956. if ("float32" !== (t = t || "float32") && "int32" !== t) throw new NotImplementedError(this.getClassName() + " does not support dType " + t + ".");
  26957. return (0, _tfjsCore.truncatedNormal)(e, 0, o, t, this.seed);
  26958. }
  26959. var s = Math.sqrt(3 * a);
  26960. return (0, _tfjsCore.randomUniform)(e, -s, s, t);
  26961. }, t.prototype.getConfig = function () {
  26962. return {
  26963. scale: this.scale,
  26964. mode: this.mode,
  26965. distribution: this.distribution,
  26966. seed: this.seed
  26967. };
  26968. }, t.className = "VarianceScaling", t;
  26969. }(Initializer);
  26970. _tfjsCore.serialization.registerClass(VarianceScaling);
  26971. var GlorotUniform = function (e) {
  26972. function t(t) {
  26973. return e.call(this, {
  26974. scale: 1,
  26975. mode: "fanAvg",
  26976. distribution: "uniform",
  26977. seed: null == t ? null : t.seed
  26978. }) || this;
  26979. }
  26980. return __extends(t, e), t.prototype.getClassName = function () {
  26981. return VarianceScaling.className;
  26982. }, t.className = "GlorotUniform", t;
  26983. }(VarianceScaling);
  26984. _tfjsCore.serialization.registerClass(GlorotUniform);
  26985. var GlorotNormal = function (e) {
  26986. function t(t) {
  26987. return e.call(this, {
  26988. scale: 1,
  26989. mode: "fanAvg",
  26990. distribution: "normal",
  26991. seed: null == t ? null : t.seed
  26992. }) || this;
  26993. }
  26994. return __extends(t, e), t.prototype.getClassName = function () {
  26995. return VarianceScaling.className;
  26996. }, t.className = "GlorotNormal", t;
  26997. }(VarianceScaling);
  26998. _tfjsCore.serialization.registerClass(GlorotNormal);
  26999. var HeNormal = function (e) {
  27000. function t(t) {
  27001. return e.call(this, {
  27002. scale: 2,
  27003. mode: "fanIn",
  27004. distribution: "normal",
  27005. seed: null == t ? null : t.seed
  27006. }) || this;
  27007. }
  27008. return __extends(t, e), t.prototype.getClassName = function () {
  27009. return VarianceScaling.className;
  27010. }, t.className = "HeNormal", t;
  27011. }(VarianceScaling);
  27012. _tfjsCore.serialization.registerClass(HeNormal);
  27013. var HeUniform = function (e) {
  27014. function t(t) {
  27015. return e.call(this, {
  27016. scale: 2,
  27017. mode: "fanIn",
  27018. distribution: "uniform",
  27019. seed: null == t ? null : t.seed
  27020. }) || this;
  27021. }
  27022. return __extends(t, e), t.prototype.getClassName = function () {
  27023. return VarianceScaling.className;
  27024. }, t.className = "HeUniform", t;
  27025. }(VarianceScaling);
  27026. _tfjsCore.serialization.registerClass(HeUniform);
  27027. var LeCunNormal = function (e) {
  27028. function t(t) {
  27029. return e.call(this, {
  27030. scale: 1,
  27031. mode: "fanIn",
  27032. distribution: "normal",
  27033. seed: null == t ? null : t.seed
  27034. }) || this;
  27035. }
  27036. return __extends(t, e), t.prototype.getClassName = function () {
  27037. return VarianceScaling.className;
  27038. }, t.className = "LeCunNormal", t;
  27039. }(VarianceScaling);
  27040. _tfjsCore.serialization.registerClass(LeCunNormal);
  27041. var LeCunUniform = function (e) {
  27042. function t(t) {
  27043. return e.call(this, {
  27044. scale: 1,
  27045. mode: "fanIn",
  27046. distribution: "uniform",
  27047. seed: null == t ? null : t.seed
  27048. }) || this;
  27049. }
  27050. return __extends(t, e), t.prototype.getClassName = function () {
  27051. return VarianceScaling.className;
  27052. }, t.className = "LeCunNormal", t;
  27053. }(VarianceScaling);
  27054. _tfjsCore.serialization.registerClass(LeCunUniform);
  27055. var Orthogonal = function (e) {
  27056. function t(t) {
  27057. var n = e.call(this) || this;
  27058. if (n.DEFAULT_GAIN = 1, n.gain = null == t.gain ? n.DEFAULT_GAIN : t.gain, n.seed = t.seed, null != n.seed) throw new NotImplementedError("Random seed is not implemented for Orthogonal Initializer yet.");
  27059. return n;
  27060. }
  27061. return __extends(t, e), t.prototype.apply = function (e, t) {
  27062. var n = this;
  27063. return (0, _tfjsCore.tidy)(function () {
  27064. if (2 !== e.length) throw new NotImplementedError("The Orthogonal Initializer does not support non-2D shapes yet.");
  27065. e[0] * e[1] > 2e3 && console.warn("Orthogonal initializer is being called on a matrix with more than 2000 (" + e[0] * e[1] + ") elements: Slowness may result.");
  27066. var t = randomNormal$1(e[0] > e[1] ? [e[1], e[0]] : e, 0, 1, "float32"),
  27067. r = _tfjsCore.linalg.gramSchmidt(t);
  27068. return e[0] > e[1] && (r = r.transpose()), (0, _tfjsCore.mul)(n.gain, r);
  27069. });
  27070. }, t.prototype.getConfig = function () {
  27071. return {
  27072. gain: this.gain,
  27073. seed: this.seed
  27074. };
  27075. }, t.className = "Orthogonal", t;
  27076. }(Initializer);
  27077. _tfjsCore.serialization.registerClass(Orthogonal);
  27078. var INITIALIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP = {
  27079. constant: "Constant",
  27080. glorotNormal: "GlorotNormal",
  27081. glorotUniform: "GlorotUniform",
  27082. heNormal: "HeNormal",
  27083. heUniform: "HeUniform",
  27084. identity: "Identity",
  27085. leCunNormal: "LeCunNormal",
  27086. leCunUniform: "LeCunUniform",
  27087. ones: "Ones",
  27088. orthogonal: "Orthogonal",
  27089. randomNormal: "RandomNormal",
  27090. randomUniform: "RandomUniform",
  27091. truncatedNormal: "TruncatedNormal",
  27092. varianceScaling: "VarianceScaling",
  27093. zeros: "Zeros"
  27094. };
  27095. function deserializeInitializer(e, t) {
  27096. return void 0 === t && (t = {}), deserializeKerasObject(e, _tfjsCore.serialization.SerializationMap.getMap().classNameMap, t, "initializer");
  27097. }
  27098. function serializeInitializer(e) {
  27099. return serializeKerasObject(e);
  27100. }
  27101. function getInitializer(e) {
  27102. if ("string" == typeof e) {
  27103. var t = e in INITIALIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP ? INITIALIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP[e] : e;
  27104. if ("GlorotNormal" === t) return new GlorotNormal();
  27105. if ("GlorotUniform" === t) return new GlorotUniform();
  27106. if ("HeNormal" === t) return new HeNormal();
  27107. if ("HeUniform" === t) return new HeUniform();
  27108. if ("LeCunNormal" === t) return new LeCunNormal();
  27109. if ("LeCunUniform" === t) return new LeCunUniform();
  27110. var n = {};
  27111. return n.className = t, n.config = {}, deserializeInitializer(n);
  27112. }
  27113. return e instanceof Initializer ? e : deserializeInitializer(e);
  27114. }
  27115. function zeros$1() {
  27116. return new Zeros();
  27117. }
  27118. function ones$1() {
  27119. return new Ones();
  27120. }
  27121. function constant(e) {
  27122. return new Constant(e);
  27123. }
  27124. function randomUniform$1(e) {
  27125. return new RandomUniform(e);
  27126. }
  27127. function randomNormal$2(e) {
  27128. return new RandomNormal(e);
  27129. }
  27130. function truncatedNormal$1(e) {
  27131. return new TruncatedNormal(e);
  27132. }
  27133. function identity(e) {
  27134. return new Identity(e);
  27135. }
  27136. function varianceScaling(e) {
  27137. return new VarianceScaling(e);
  27138. }
  27139. function glorotUniform(e) {
  27140. return new GlorotUniform(e);
  27141. }
  27142. function glorotNormal(e) {
  27143. return new GlorotNormal(e);
  27144. }
  27145. function heNormal(e) {
  27146. return new HeNormal(e);
  27147. }
  27148. function heUniform(e) {
  27149. return new HeUniform(e);
  27150. }
  27151. function leCunNormal(e) {
  27152. return new LeCunNormal(e);
  27153. }
  27154. function leCunUniform(e) {
  27155. return new LeCunUniform(e);
  27156. }
  27157. function orthogonal(e) {
  27158. return new Orthogonal(e);
  27159. }
  27160. var exports_initializers = Object.freeze({
  27161. zeros: zeros$1,
  27162. ones: ones$1,
  27163. constant: constant,
  27164. randomUniform: randomUniform$1,
  27165. randomNormal: randomNormal$2,
  27166. truncatedNormal: truncatedNormal$1,
  27167. identity: identity,
  27168. varianceScaling: varianceScaling,
  27169. glorotUniform: glorotUniform,
  27170. glorotNormal: glorotNormal,
  27171. heNormal: heNormal,
  27172. heUniform: heUniform,
  27173. leCunNormal: leCunNormal,
  27174. leCunUniform: leCunUniform,
  27175. orthogonal: orthogonal
  27176. }),
  27177. _nextUniqueTensorId = 0;
  27178. exports.initializers = exports_initializers;
  27179. function getNextUniqueTensorId() {
  27180. return _nextUniqueTensorId++;
  27181. }
  27182. var _uidPrefixes = {};
  27183. function getUid(e) {
  27184. return void 0 === e && (e = ""), e in _uidPrefixes || (_uidPrefixes[e] = 0), _uidPrefixes[e] += 1, e + _uidPrefixes[e].toString();
  27185. }
  27186. function isArrayOfShapes(e) {
  27187. return Array.isArray(e) && Array.isArray(e[0]);
  27188. }
  27189. function normalizeShapeList(e) {
  27190. return 0 === e.length ? [] : Array.isArray(e[0]) ? e : [e];
  27191. }
  27192. function getExactlyOneTensor(e) {
  27193. var t;
  27194. if (Array.isArray(e)) {
  27195. if (1 !== e.length) throw new ValueError("Expected Tensor length to be 1; got " + e.length);
  27196. t = e[0];
  27197. } else t = e;
  27198. return t;
  27199. }
  27200. function getExactlyOneShape(e) {
  27201. if (Array.isArray(e) && Array.isArray(e[0])) {
  27202. if (1 === e.length) return (e = e)[0];
  27203. throw new ValueError("Expected exactly 1 Shape; got " + e.length);
  27204. }
  27205. return e;
  27206. }
  27207. function countParamsInWeights(e) {
  27208. for (var t = 0, n = 0, r = e; n < r.length; n++) {
  27209. var i = r[n];
  27210. 0 === i.shape.length ? t += 1 : t += i.shape.reduce(function (e, t) {
  27211. return e * t;
  27212. });
  27213. }
  27214. return t;
  27215. }
  27216. var DEFAULT_VARIABLE_NAME_PREFIX = "Variable",
  27217. LayerVariable = function () {
  27218. function e(e, t, n, r, i) {
  27219. void 0 === t && (t = "float32"), void 0 === n && (n = DEFAULT_VARIABLE_NAME_PREFIX), void 0 === r && (r = !0), void 0 === i && (i = null), this.dtype = null == t ? "float32" : t, this.shape = e.shape, this.id = getNextUniqueTensorId(), n = null == n ? DEFAULT_VARIABLE_NAME_PREFIX : n, this.originalName = getScopedTensorName(n), this.name = getUniqueTensorName(this.originalName), this.trainable_ = r, this.constraint = i, this.val = (0, _tfjsCore.variable)(e, this.trainable_, this.name, this.dtype);
  27220. }
  27221. return e.prototype.read = function () {
  27222. return this.assertNotDisposed(), this.val;
  27223. }, e.prototype.write = function (e) {
  27224. return this.assertNotDisposed(), checkShapesMatch(this.val, e), this.val.id !== e.id && (this.val.assign(e), null != this.constraint && this.val.assign(this.constraint.apply(this.val))), this;
  27225. }, e.prototype.dispose = function () {
  27226. this.assertNotDisposed(), this.val.dispose();
  27227. }, e.prototype.assertNotDisposed = function () {
  27228. if (this.val.isDisposed) throw new Error("LayersVariable " + this.name + " is already disposed.");
  27229. }, Object.defineProperty(e.prototype, "trainable", {
  27230. get: function () {
  27231. return this.trainable_;
  27232. },
  27233. set: function (e) {
  27234. this.trainable_ = e, this.val.trainable = e;
  27235. },
  27236. enumerable: !0,
  27237. configurable: !0
  27238. }), e;
  27239. }();
  27240. exports.LayerVariable = LayerVariable;
  27241. function checkShapesMatch(e, t) {
  27242. if (e.shape.toString() !== t.shape.toString()) throw new Error("Shape mismatch: " + JSON.stringify(e.shape) + " vs. " + JSON.stringify(t.shape));
  27243. }
  27244. function batchGetValue(e) {
  27245. return e.map(function (e) {
  27246. return e.read();
  27247. });
  27248. }
  27249. function batchSetValue(e) {
  27250. e.forEach(function (e) {
  27251. e[0].write(e[1]);
  27252. });
  27253. }
  27254. var InputSpec = function () {
  27255. return function (e) {
  27256. this.dtype = e.dtype, this.shape = e.shape, null != e.shape ? this.ndim = e.shape.length : this.ndim = e.ndim, this.maxNDim = e.maxNDim, this.minNDim = e.minNDim, this.axes = e.axes || {};
  27257. };
  27258. }(),
  27259. SymbolicTensor = function () {
  27260. return function (e, t, n, r, i, a, o) {
  27261. this.dtype = e, this.shape = t, this.sourceLayer = n, this.inputs = r, this.callArgs = i, this.outputTensorIndex = o, this.id = getNextUniqueTensorId(), null != a && (this.originalName = getScopedTensorName(a), this.name = getUniqueTensorName(this.originalName)), this.rank = t.length;
  27262. };
  27263. }(),
  27264. _nextNodeID = 0,
  27265. Node = function () {
  27266. function e(e, t) {
  27267. this.callArgs = t, this.id = _nextNodeID++, this.outboundLayer = e.outboundLayer, this.inboundLayers = e.inboundLayers, this.nodeIndices = e.nodeIndices, this.tensorIndices = e.tensorIndices, this.inputTensors = e.inputTensors, this.outputTensors = e.outputTensors, this.inputMasks = e.inputMasks, this.outputMasks = e.outputMasks, this.inputShapes = e.inputShapes, this.outputShapes = e.outputShapes;
  27268. for (var n = 0, r = e.inboundLayers; n < r.length; n++) {
  27269. var i = r[n];
  27270. null != i && i.outboundNodes.push(this);
  27271. }
  27272. e.outboundLayer.inboundNodes.push(this);
  27273. }
  27274. return e.prototype.getConfig = function () {
  27275. for (var e = [], t = 0, n = this.inboundLayers; t < n.length; t++) {
  27276. var r = n[t];
  27277. null != r ? e.push(r.name) : e.push(null);
  27278. }
  27279. return {
  27280. outboundLayer: this.outboundLayer ? this.outboundLayer.name : null,
  27281. inboundLayers: e,
  27282. nodeIndices: this.nodeIndices,
  27283. tensorIndices: this.tensorIndices
  27284. };
  27285. }, e;
  27286. }(),
  27287. _nextLayerID = 0,
  27288. Layer = function (e) {
  27289. function t(t) {
  27290. var n = e.call(this) || this;
  27291. n._callHook = null, n._addedWeightNames = [], n._stateful = !1, n.id = _nextLayerID++, n.activityRegularizer = null, n.inputSpec = null, n.supportsMasking = !1, n._trainableWeights = [], n._nonTrainableWeights = [], n._losses = [], n._updates = [], n._built = !1, n.inboundNodes = [], n.outboundNodes = [];
  27292. var r = t.name;
  27293. if (!r) {
  27294. var i = n.getClassName();
  27295. r = toSnakeCase(i) + "_" + getUid(i);
  27296. }
  27297. if (n.name = r, n.trainable_ = null == t.trainable || t.trainable, null != t.inputShape || null != t.batchInputShape) {
  27298. var a = void 0;
  27299. if (null != t.batchInputShape) a = t.batchInputShape; else if (null != t.inputShape) {
  27300. var o = null;
  27301. null != t.batchSize && (o = t.batchSize), a = [o].concat(t.inputShape);
  27302. }
  27303. n.batchInputShape = a;
  27304. var s = t.dtype;
  27305. null == s && (s = t.inputDType), null == s && (s = "float32"), n.dtype = s;
  27306. }
  27307. return null != t.weights ? n.initialWeights = t.weights : n.initialWeights = null, n._refCount = null, n.fastWeightInitDuringBuild = !1, n;
  27308. }
  27309. return __extends(t, e), t.nodeKey = function (e, t) {
  27310. return e.name + "_ib-" + t.toString();
  27311. }, t.prototype.getNodeAtIndex = function (e, t) {
  27312. if (0 === this.inboundNodes.length) throw new RuntimeError("The layer has never been called and thus has no defined " + t + ".");
  27313. if (this.inboundNodes.length <= e) throw new ValueError("Asked to get " + t + " at node " + e + ", but the layer has only " + this.inboundNodes.length + " inbound nodes.");
  27314. return this.inboundNodes[e];
  27315. }, t.prototype.getInputAt = function (e) {
  27316. return singletonOrArray(this.getNodeAtIndex(e, "input").inputTensors);
  27317. }, t.prototype.getOutputAt = function (e) {
  27318. return singletonOrArray(this.getNodeAtIndex(e, "output").outputTensors);
  27319. }, Object.defineProperty(t.prototype, "input", {
  27320. get: function () {
  27321. if (this.inboundNodes.length > 1) throw new AttributeError("Layer " + this.name + ' has multiple inbound nodes, hence the notion of "layer input" is ill-defined. Use `getInputAt(nodeIndex)` instead.');
  27322. if (0 === this.inboundNodes.length) throw new AttributeError("Layer " + this.name + " is not connected, no input to return.");
  27323. return singletonOrArray(this.getNodeAtIndex(0, "input").inputTensors);
  27324. },
  27325. enumerable: !0,
  27326. configurable: !0
  27327. }), Object.defineProperty(t.prototype, "output", {
  27328. get: function () {
  27329. if (0 === this.inboundNodes.length) throw new AttributeError("Layer " + this.name + " has no inbound nodes.");
  27330. if (this.inboundNodes.length > 1) throw new AttributeError("Layer " + this.name + ' has multiple inbound nodes, hence the notion of "layer output" is ill-defined. Use `getOutputAt(nodeIndex)` instead.');
  27331. return singletonOrArray(this.getNodeAtIndex(0, "output").outputTensors);
  27332. },
  27333. enumerable: !0,
  27334. configurable: !0
  27335. }), Object.defineProperty(t.prototype, "losses", {
  27336. get: function () {
  27337. return this._losses;
  27338. },
  27339. enumerable: !0,
  27340. configurable: !0
  27341. }), t.prototype.calculateLosses = function () {
  27342. return this.losses.map(function (e) {
  27343. return e();
  27344. });
  27345. }, Object.defineProperty(t.prototype, "updates", {
  27346. get: function () {
  27347. return this._updates;
  27348. },
  27349. enumerable: !0,
  27350. configurable: !0
  27351. }), Object.defineProperty(t.prototype, "built", {
  27352. get: function () {
  27353. return this._built;
  27354. },
  27355. set: function (e) {
  27356. this._built = e;
  27357. },
  27358. enumerable: !0,
  27359. configurable: !0
  27360. }), Object.defineProperty(t.prototype, "trainable", {
  27361. get: function () {
  27362. return this.trainable_;
  27363. },
  27364. set: function (e) {
  27365. this._trainableWeights.forEach(function (t) {
  27366. return t.trainable = e;
  27367. }), this.trainable_ = e;
  27368. },
  27369. enumerable: !0,
  27370. configurable: !0
  27371. }), Object.defineProperty(t.prototype, "trainableWeights", {
  27372. get: function () {
  27373. return this.trainable_ ? this._trainableWeights.filter(function (e) {
  27374. return e.trainable;
  27375. }) : [];
  27376. },
  27377. set: function (e) {
  27378. this._trainableWeights = e;
  27379. },
  27380. enumerable: !0,
  27381. configurable: !0
  27382. }), Object.defineProperty(t.prototype, "nonTrainableWeights", {
  27383. get: function () {
  27384. return this.trainable ? this._trainableWeights.filter(function (e) {
  27385. return !e.trainable;
  27386. }).concat(this._nonTrainableWeights) : this._trainableWeights.concat(this._nonTrainableWeights);
  27387. },
  27388. set: function (e) {
  27389. this._nonTrainableWeights = e;
  27390. },
  27391. enumerable: !0,
  27392. configurable: !0
  27393. }), Object.defineProperty(t.prototype, "weights", {
  27394. get: function () {
  27395. return this.trainableWeights.concat(this.nonTrainableWeights);
  27396. },
  27397. enumerable: !0,
  27398. configurable: !0
  27399. }), Object.defineProperty(t.prototype, "stateful", {
  27400. get: function () {
  27401. return this._stateful;
  27402. },
  27403. enumerable: !0,
  27404. configurable: !0
  27405. }), t.prototype.resetStates = function () {
  27406. if (!this.stateful) throw new Error("Cannot call the resetStates() method of a non-stateful Layer object.");
  27407. }, t.prototype.assertInputCompatibility = function (e) {
  27408. if (e = toList(e), null != this.inputSpec && 0 !== this.inputSpec.length) {
  27409. var t = toList(this.inputSpec);
  27410. if (e.length !== t.length) throw new ValueError("Layer " + this.name + " expects " + t.length + " inputs, but it received " + e.length + " input tensors. Input received: " + e);
  27411. for (var n = 0; n < e.length; n++) {
  27412. var r = e[n],
  27413. i = t[n];
  27414. if (null != i) {
  27415. var a = r.rank;
  27416. if (null != i.ndim && a !== i.ndim) throw new ValueError("Input " + n + " is incompatible with layer " + this.name + ": expected ndim=" + i.ndim + ", found ndim=" + a);
  27417. if (null != i.maxNDim && a > i.maxNDim) throw new ValueError("Input " + n + " is incompatible with layer " + this.name + ": expected max_ndim=" + i.maxNDim + ", found ndim=" + a);
  27418. if (null != i.minNDim && a < i.minNDim) throw new ValueError("Input " + n + " is incompatible with layer " + this.name + ": expected min_ndim=" + i.minNDim + ", found ndim=" + a + ".");
  27419. if (null != i.dtype && r.dtype !== i.dtype) throw new ValueError("Input " + n + " is incompatible with layer " + this.name + " : expected dtype=" + i.dtype + ", found dtype=" + r.dtype + ".");
  27420. if (i.axes) {
  27421. var o = r.shape;
  27422. for (var s in i.axes) {
  27423. var l = Number(s),
  27424. u = i.axes[s],
  27425. c = l >= 0 ? o[l] : o[o.length + l];
  27426. if (null != u && -1 === [u, null].indexOf(c)) throw new ValueError("Input " + n + " is incompatible with layer " + this.name + ": expected axis " + l + " of input shape to have value " + u + " but got shape " + o + ".");
  27427. }
  27428. }
  27429. if (null != i.shape) for (var p = 0; p < i.shape.length; ++p) {
  27430. var h = i.shape[p],
  27431. d = r.shape[p];
  27432. if (null != h && null != d && h !== d) throw new ValueError("Input " + n + " is incompatible with layer " + this.name + ": expected shape=" + i.shape + ", found shape=" + r.shape + ".");
  27433. }
  27434. }
  27435. }
  27436. }
  27437. }, t.prototype.call = function (e, t) {
  27438. return e;
  27439. }, t.prototype.invokeCallHook = function (e, t) {
  27440. null != this._callHook && this._callHook(e, t);
  27441. }, t.prototype.setCallHook = function (e) {
  27442. this._callHook = e;
  27443. }, t.prototype.clearCallHook = function () {
  27444. this._callHook = null;
  27445. }, t.prototype.apply = function (e, t) {
  27446. var n = this;
  27447. t = t || {}, this.assertNotDisposed();
  27448. for (var r = toList(e), i = !0, a = 0, o = r; a < o.length; a++) {
  27449. if (!(o[a] instanceof SymbolicTensor)) {
  27450. i = !1;
  27451. break;
  27452. }
  27453. }
  27454. for (var s = !0, l = 0, u = r; l < u.length; l++) {
  27455. if (u[l] instanceof SymbolicTensor) {
  27456. s = !1;
  27457. break;
  27458. }
  27459. }
  27460. if (i === s) throw new ValueError("Arguments to apply() must be all SymbolicTensors or all Tensors");
  27461. return nameScope(this.name, function () {
  27462. if (!n.built) {
  27463. n.assertInputCompatibility(e);
  27464. for (var i = [], a = 0, o = toList(e); a < o.length; a++) {
  27465. var l = o[a];
  27466. i.push(l.shape);
  27467. }
  27468. n.build(singletonOrArray(i)), n.built = !0, n.initialWeights && n.setWeights(n.initialWeights), null === n._refCount && s && (n._refCount = 1);
  27469. }
  27470. if (n.assertInputCompatibility(e), s) {
  27471. for (var u = [], c = 0, p = toList(g = n.call(e, t)); c < p.length; c++) {
  27472. var h = p[c];
  27473. -1 !== r.indexOf(h) && (h = h.clone()), u.push(h);
  27474. }
  27475. if (g = singletonOrArray(u), null != n.activityRegularizer) throw new NotImplementedError("Layer invocation in the presence of activity regularizer(s) is not supported yet.");
  27476. return g;
  27477. }
  27478. var d = collectInputShape(e),
  27479. f = n.computeOutputShape(d),
  27480. g = void 0,
  27481. m = guessOutputDType(e);
  27482. if (n.warnOnIncompatibleInputShape(Array.isArray(e) ? d[0] : d), g = null != f && f.length > 0 && Array.isArray(f[0]) ? f.map(function (r, i) {
  27483. return new SymbolicTensor(m, r, n, toList(e), t, n.name, i);
  27484. }) : new SymbolicTensor(m, f, n, toList(e), t, n.name), n.addInboundNode(e, g, null, null, d, f, t), n._refCount++, null != n.activityRegularizer) throw new NotImplementedError("Layer invocation in the presence of activity regularizer(s) is not supported yet.");
  27485. return g;
  27486. });
  27487. }, t.prototype.warnOnIncompatibleInputShape = function (e) {
  27488. if (null != this.batchInputShape) if (e.length !== this.batchInputShape.length) console.warn("The rank of the input tensor provided (shape: " + JSON.stringify(e) + ") does not match that of the batchInputShape (" + JSON.stringify(this.batchInputShape) + ") of the layer " + this.name); else {
  27489. var t = !1;
  27490. this.batchInputShape.forEach(function (n, r) {
  27491. null != n && null != e[r] && e[r] !== n && (t = !0);
  27492. }), t && console.warn("The shape of the input tensor (" + JSON.stringify(e) + ") does not match the expectation of layer " + this.name + ": " + JSON.stringify(this.batchInputShape));
  27493. }
  27494. }, Object.defineProperty(t.prototype, "outputShape", {
  27495. get: function () {
  27496. if (null == this.inboundNodes || 0 === this.inboundNodes.length) throw new AttributeError("The layer " + this.name + " has never been called and thus has no defined output shape.");
  27497. for (var e = [], t = 0, n = this.inboundNodes; t < n.length; t++) {
  27498. var r = n[t],
  27499. i = JSON.stringify(r.outputShapes);
  27500. -1 === e.indexOf(i) && e.push(i);
  27501. }
  27502. if (1 === e.length) {
  27503. var a = this.inboundNodes[0].outputShapes;
  27504. return Array.isArray(a) && Array.isArray(a[0]) && 1 === a.length ? a[0] : a;
  27505. }
  27506. throw new AttributeError("The layer " + this.name + ' has multiple inbound nodes with different output shapes. Hence the notion of "outut shape" is ill-defined for the layer.');
  27507. },
  27508. enumerable: !0,
  27509. configurable: !0
  27510. }), t.prototype.countParams = function () {
  27511. if (!this.built) throw new RuntimeError("You tried to call countParams() on " + this.name + ", but the layer is not built yet. Build it first by calling build(batchInputShape).");
  27512. return countParamsInWeights(this.weights);
  27513. }, t.prototype.build = function (e) {
  27514. this.built = !0;
  27515. }, t.prototype.getWeights = function (e) {
  27516. return void 0 === e && (e = !1), batchGetValue(e ? this.trainableWeights : this.weights);
  27517. }, t.prototype.setWeights = function (e) {
  27518. var t = this;
  27519. (0, _tfjsCore.tidy)(function () {
  27520. var n = t.weights;
  27521. if (n.length !== e.length) throw new ValueError('You called setWeights(weights) on layer "' + t.name + '" with a weight list of length ' + e.length + ", but the layer was expecting " + n.length + " weights. Provided weights: " + e + "...");
  27522. if (0 !== n.length) {
  27523. for (var r = [], i = batchGetValue(n), a = 0; a < i.length; ++a) {
  27524. var o = i[a],
  27525. s = n[a],
  27526. l = e[a];
  27527. if (!_tfjsCore.util.arraysEqual(o.shape, l.shape)) throw new ValueError("Layer weight shape " + o.shape + " not compatible with provided weight shape " + l.shape);
  27528. r.push([s, l]);
  27529. }
  27530. batchSetValue(r);
  27531. }
  27532. });
  27533. }, t.prototype.addWeight = function (e, t, n, r, i, a, o) {
  27534. if (-1 !== this._addedWeightNames.indexOf(e)) throw new ValueError("Duplicate weight name " + e + " for layer " + this.name);
  27535. this._addedWeightNames.push(e), null == n && (n = "float32"), this.fastWeightInitDuringBuild && (r = getInitializer("zeros"));
  27536. var s = r.apply(t, n),
  27537. l = new LayerVariable(s, n, e, a, o);
  27538. return s.dispose(), null != i && this.addLoss(function () {
  27539. return i.apply(l.read());
  27540. }), null == a && (a = !0), a ? this._trainableWeights.push(l) : this._nonTrainableWeights.push(l), l;
  27541. }, t.prototype.setFastWeightInitDuringBuild = function (e) {
  27542. this.fastWeightInitDuringBuild = e;
  27543. }, t.prototype.addLoss = function (e) {
  27544. var t;
  27545. null == e || Array.isArray(e) && 0 === e.length || (e = toList(e), void 0 !== this._losses && null !== this._losses && (t = this.losses).push.apply(t, e));
  27546. }, t.prototype.computeOutputShape = function (e) {
  27547. return e;
  27548. }, t.prototype.computeMask = function (e, t) {
  27549. var n = this;
  27550. if (!this.supportsMasking) {
  27551. if (null != t) {
  27552. if (!Array.isArray(t)) throw new TypeError("Layer " + this.name + " does not support masking, but was passed an inputMask.");
  27553. t.forEach(function (e) {
  27554. if (null != e) throw new TypeError("Layer " + n.name + " does not support masking, but was passed an inputMask.");
  27555. });
  27556. }
  27557. return null;
  27558. }
  27559. return t;
  27560. }, t.prototype.addInboundNode = function (e, t, n, r, i, a, o) {
  27561. void 0 === o && (o = null);
  27562. var s = toList(e);
  27563. t = toList(t), n = toList(n), r = toList(r), i = normalizeShapeList(i), a = normalizeShapeList(a);
  27564. for (var l = [], u = [], c = [], p = 0, h = s; p < h.length; p++) {
  27565. var d = h[p];
  27566. l.push(d.sourceLayer), u.push(d.nodeIndex), c.push(d.tensorIndex);
  27567. }
  27568. new Node({
  27569. outboundLayer: this,
  27570. inboundLayers: l,
  27571. nodeIndices: u,
  27572. tensorIndices: c,
  27573. inputTensors: s,
  27574. outputTensors: t,
  27575. inputMasks: n,
  27576. outputMasks: r,
  27577. inputShapes: i,
  27578. outputShapes: a
  27579. }, o);
  27580. for (var f = 0; f < t.length; f++) t[f].sourceLayer = this, t[f].nodeIndex = this.inboundNodes.length - 1, t[f].tensorIndex = f;
  27581. }, t.prototype.getConfig = function () {
  27582. var e = {
  27583. name: this.name,
  27584. trainable: this.trainable
  27585. };
  27586. return null != this.batchInputShape && (e.batchInputShape = this.batchInputShape), null != this.dtype && (e.dtype = this.dtype), e;
  27587. }, t.prototype.disposeWeights = function () {
  27588. return this.weights.forEach(function (e) {
  27589. return e.dispose();
  27590. }), this.weights.length;
  27591. }, t.prototype.assertNotDisposed = function () {
  27592. if (0 === this._refCount) throw new Error("Layer '" + this.name + "' is already disposed.");
  27593. }, t.prototype.dispose = function () {
  27594. if (!this.built) throw new Error("Cannot dispose Layer " + this.name + " because it has not been built yet.");
  27595. if (null === this._refCount) throw new Error("Cannot dispose Layer " + this.name + " because it has not been used yet.");
  27596. this.assertNotDisposed();
  27597. var e = 0;
  27598. return 0 == --this._refCount && (e = this.disposeWeights()), {
  27599. refCountAfterDispose: this._refCount,
  27600. numDisposedVariables: e
  27601. };
  27602. }, t;
  27603. }(_tfjsCore.serialization.Serializable);
  27604. exports.SymbolicTensor = SymbolicTensor;
  27605. exports.InputSpec = InputSpec;
  27606. function collectInputShape(e) {
  27607. for (var t = [], n = 0, r = e = toList(e); n < r.length; n++) {
  27608. var i = r[n];
  27609. t.push(i.shape);
  27610. }
  27611. return singletonOrArray(t);
  27612. }
  27613. function guessOutputDType(e) {
  27614. return "float32";
  27615. }
  27616. function getSourceInputs(e, t, n) {
  27617. if ((null == t || null != n && n > 0) && (t = e.sourceLayer, n = e.nodeIndex), 0 === t.inboundNodes.length) return [e];
  27618. var r = t.inboundNodes[n];
  27619. if (0 === r.inboundLayers.length) return r.inputTensors;
  27620. for (var i = [], a = 0; a < r.inboundLayers.length; a++) for (var o = 0, s = getSourceInputs(r.inputTensors[a], r.inboundLayers[a], r.nodeIndices[a]); o < s.length; o++) {
  27621. var l = s[o];
  27622. -1 === i.indexOf(l) && i.push(l);
  27623. }
  27624. return i;
  27625. }
  27626. var ModelLoggingVerbosity,
  27627. InputLayer = function (e) {
  27628. function t(t) {
  27629. var n = e.call(this, {
  27630. dtype: t.dtype,
  27631. name: null != t.name ? t.name : getUid("input").toString()
  27632. }) || this;
  27633. if (null == t.batchSize && (t.batchSize = null), null == t.sparse && (t.sparse = !1), n.trainable = !1, n.built = !0, n.sparse = t.sparse, null != t.inputShape && null != t.batchInputShape) throw new ValueError("Only provide the inputShape OR batchInputShape argument to inputLayer, not both at the same time.");
  27634. var r = t.batchInputShape;
  27635. if (null == r) {
  27636. if (null == t.inputShape) throw new ValueError("An InputLayer should be passed either a `batchInputShape` or an `inputShape`.");
  27637. r = [t.batchSize].concat(t.inputShape);
  27638. } else if (null != t.batchSize) throw new ValueError("Cannot specify batchSize if batchInputShape is specified when creating an InputLayer.");
  27639. var i = t.dtype || "float32";
  27640. n.batchInputShape = r, n.dtype = i, n.inputSpec = [{
  27641. shape: r
  27642. }];
  27643. var a = new SymbolicTensor(n.dtype, n.batchInputShape, n, [], {}, n.name);
  27644. return a.nodeIndex = 0, a.tensorIndex = 0, new Node({
  27645. outboundLayer: n,
  27646. inboundLayers: [],
  27647. nodeIndices: [],
  27648. tensorIndices: [],
  27649. inputTensors: [a],
  27650. outputTensors: [a],
  27651. inputMasks: [null],
  27652. outputMasks: [null],
  27653. inputShapes: [r],
  27654. outputShapes: [r]
  27655. }), n;
  27656. }
  27657. return __extends(t, e), t.prototype.apply = function (e, t) {
  27658. throw new ValueError("Cannot pass any input to an InputLayer's apply() method. InputLayer name: " + this.name);
  27659. }, t.prototype.dispose = function () {
  27660. return {
  27661. refCountAfterDispose: this._refCount,
  27662. numDisposedVariables: 0
  27663. };
  27664. }, t.prototype.getConfig = function () {
  27665. return {
  27666. batchInputShape: this.batchInputShape,
  27667. dtype: this.dtype,
  27668. sparse: this.sparse,
  27669. name: this.name
  27670. };
  27671. }, t.className = "InputLayer", t;
  27672. }(Layer);
  27673. function Input(e) {
  27674. if (null == e.batchShape && null == e.shape) throw new Error("Please provide to Input either a `shape` or a `batchShape` argument. Note that `shape` does not include the batch dimension.");
  27675. if (null != e.batchShape && null != e.shape) throw new ValueError("Please provide either a `shape` or `batchShape` argument to Input, but not both.");
  27676. var t = e.batchShape;
  27677. null != e.shape && null == t && (t = [null].concat(e.shape));
  27678. var n = e.dtype;
  27679. return null == n && (n = "float32"), new InputLayer({
  27680. batchInputShape: t,
  27681. name: e.name,
  27682. dtype: n,
  27683. sparse: e.sparse
  27684. }).inboundNodes[0].outputTensors[0];
  27685. }
  27686. function resolveScalarsInLogs(e) {
  27687. return __awaiter(this, void 0, void 0, function () {
  27688. var t, n, r, i, a, o, s, l;
  27689. return __generator(this, function (u) {
  27690. switch (u.label) {
  27691. case 0:
  27692. if (null == e) return [2];
  27693. for (i in t = [], n = [], r = [], e) "number" != typeof (a = e[i]) && (o = a, t.push(o.data()), n.push(i), r.push(o));
  27694. return t.length > 0 ? [4, Promise.all(t)] : [3, 2];
  27695. case 1:
  27696. for (s = u.sent(), l = 0; l < s.length; ++l) e[n[l]] = s[l][0];
  27697. (0, _tfjsCore.dispose)(r), u.label = 2;
  27698. case 2:
  27699. return [2];
  27700. }
  27701. });
  27702. });
  27703. }
  27704. function disposeTensorsInLogs(e) {
  27705. if (null != e) for (var t in e) {
  27706. var n = e[t];
  27707. "number" != typeof n && n.dispose();
  27708. }
  27709. }
  27710. _tfjsCore.serialization.registerClass(InputLayer), function (e) {
  27711. e[e.SILENT = 0] = "SILENT", e[e.VERBOSE = 1] = "VERBOSE";
  27712. }(ModelLoggingVerbosity || (ModelLoggingVerbosity = {}));
  27713. var DEFAULT_YIELD_EVERY_MS = 125,
  27714. BaseCallback = function () {
  27715. function e() {
  27716. this.validationData = null;
  27717. }
  27718. return e.prototype.setParams = function (e) {
  27719. this.params = e;
  27720. }, e.prototype.onEpochBegin = function (e, t) {
  27721. return __awaiter(this, void 0, void 0, function () {
  27722. return __generator(this, function (e) {
  27723. return [2];
  27724. });
  27725. });
  27726. }, e.prototype.onEpochEnd = function (e, t) {
  27727. return __awaiter(this, void 0, void 0, function () {
  27728. return __generator(this, function (e) {
  27729. return [2];
  27730. });
  27731. });
  27732. }, e.prototype.onBatchBegin = function (e, t) {
  27733. return __awaiter(this, void 0, void 0, function () {
  27734. return __generator(this, function (e) {
  27735. return [2];
  27736. });
  27737. });
  27738. }, e.prototype.onBatchEnd = function (e, t) {
  27739. return __awaiter(this, void 0, void 0, function () {
  27740. return __generator(this, function (e) {
  27741. return [2];
  27742. });
  27743. });
  27744. }, e.prototype.onTrainBegin = function (e) {
  27745. return __awaiter(this, void 0, void 0, function () {
  27746. return __generator(this, function (e) {
  27747. return [2];
  27748. });
  27749. });
  27750. }, e.prototype.onTrainEnd = function (e) {
  27751. return __awaiter(this, void 0, void 0, function () {
  27752. return __generator(this, function (e) {
  27753. return [2];
  27754. });
  27755. });
  27756. }, e.prototype.setModel = function (e) { }, e;
  27757. }(),
  27758. CallbackList = function () {
  27759. function e(e, t) {
  27760. void 0 === t && (t = 10), null == e && (e = []), this.callbacks = e, this.queueLength = t;
  27761. }
  27762. return e.prototype.append = function (e) {
  27763. this.callbacks.push(e);
  27764. }, e.prototype.setParams = function (e) {
  27765. for (var t = 0, n = this.callbacks; t < n.length; t++) {
  27766. n[t].setParams(e);
  27767. }
  27768. }, e.prototype.setModel = function (e) {
  27769. for (var t = 0, n = this.callbacks; t < n.length; t++) {
  27770. n[t].setModel(e);
  27771. }
  27772. }, e.prototype.onEpochBegin = function (e, t) {
  27773. return __awaiter(this, void 0, void 0, function () {
  27774. var n, r;
  27775. return __generator(this, function (i) {
  27776. switch (i.label) {
  27777. case 0:
  27778. null == t && (t = {}), n = 0, r = this.callbacks, i.label = 1;
  27779. case 1:
  27780. return n < r.length ? [4, r[n].onEpochBegin(e, t)] : [3, 4];
  27781. case 2:
  27782. i.sent(), i.label = 3;
  27783. case 3:
  27784. return n++, [3, 1];
  27785. case 4:
  27786. return [2];
  27787. }
  27788. });
  27789. });
  27790. }, e.prototype.onEpochEnd = function (e, t) {
  27791. return __awaiter(this, void 0, void 0, function () {
  27792. var n, r;
  27793. return __generator(this, function (i) {
  27794. switch (i.label) {
  27795. case 0:
  27796. null == t && (t = {}), n = 0, r = this.callbacks, i.label = 1;
  27797. case 1:
  27798. return n < r.length ? [4, r[n].onEpochEnd(e, t)] : [3, 4];
  27799. case 2:
  27800. i.sent(), i.label = 3;
  27801. case 3:
  27802. return n++, [3, 1];
  27803. case 4:
  27804. return [2];
  27805. }
  27806. });
  27807. });
  27808. }, e.prototype.onBatchBegin = function (e, t) {
  27809. return __awaiter(this, void 0, void 0, function () {
  27810. var n, r;
  27811. return __generator(this, function (i) {
  27812. switch (i.label) {
  27813. case 0:
  27814. null == t && (t = {}), n = 0, r = this.callbacks, i.label = 1;
  27815. case 1:
  27816. return n < r.length ? [4, r[n].onBatchBegin(e, t)] : [3, 4];
  27817. case 2:
  27818. i.sent(), i.label = 3;
  27819. case 3:
  27820. return n++, [3, 1];
  27821. case 4:
  27822. return [2];
  27823. }
  27824. });
  27825. });
  27826. }, e.prototype.onBatchEnd = function (e, t) {
  27827. return __awaiter(this, void 0, void 0, function () {
  27828. var n, r;
  27829. return __generator(this, function (i) {
  27830. switch (i.label) {
  27831. case 0:
  27832. null == t && (t = {}), n = 0, r = this.callbacks, i.label = 1;
  27833. case 1:
  27834. return n < r.length ? [4, r[n].onBatchEnd(e, t)] : [3, 4];
  27835. case 2:
  27836. i.sent(), i.label = 3;
  27837. case 3:
  27838. return n++, [3, 1];
  27839. case 4:
  27840. return [2];
  27841. }
  27842. });
  27843. });
  27844. }, e.prototype.onTrainBegin = function (e) {
  27845. return __awaiter(this, void 0, void 0, function () {
  27846. var t, n;
  27847. return __generator(this, function (r) {
  27848. switch (r.label) {
  27849. case 0:
  27850. null == e && (e = {}), t = 0, n = this.callbacks, r.label = 1;
  27851. case 1:
  27852. return t < n.length ? [4, n[t].onTrainBegin(e)] : [3, 4];
  27853. case 2:
  27854. r.sent(), r.label = 3;
  27855. case 3:
  27856. return t++, [3, 1];
  27857. case 4:
  27858. return [2];
  27859. }
  27860. });
  27861. });
  27862. }, e.prototype.onTrainEnd = function (e) {
  27863. return __awaiter(this, void 0, void 0, function () {
  27864. var t, n;
  27865. return __generator(this, function (r) {
  27866. switch (r.label) {
  27867. case 0:
  27868. null == e && (e = {}), t = 0, n = this.callbacks, r.label = 1;
  27869. case 1:
  27870. return t < n.length ? [4, n[t].onTrainEnd(e)] : [3, 4];
  27871. case 2:
  27872. r.sent(), r.label = 3;
  27873. case 3:
  27874. return t++, [3, 1];
  27875. case 4:
  27876. return [2];
  27877. }
  27878. });
  27879. });
  27880. }, e;
  27881. }(),
  27882. BaseLogger = function (e) {
  27883. function t() {
  27884. return e.call(this) || this;
  27885. }
  27886. return __extends(t, e), t.prototype.onEpochBegin = function (e) {
  27887. return __awaiter(this, void 0, void 0, function () {
  27888. return __generator(this, function (e) {
  27889. return this.seen = 0, this.totals = {}, [2];
  27890. });
  27891. });
  27892. }, t.prototype.onBatchEnd = function (e, t) {
  27893. return __awaiter(this, void 0, void 0, function () {
  27894. var e,
  27895. n,
  27896. r,
  27897. i,
  27898. a = this;
  27899. return __generator(this, function (o) {
  27900. for (i in null == t && (t = {}), e = null == t.size ? 0 : t.size, this.seen += e, n = function (n) {
  27901. var i = t[n];
  27902. if ("number" == typeof i) r.totals.hasOwnProperty(n) || (r.totals[n] = 0), r.totals[n] = r.totals[n] + i * e; else {
  27903. var o = void 0;
  27904. n in r.totals ? o = r.totals[n] : r.totals[n] = 0;
  27905. var s = (0, _tfjsCore.tidy)(function () {
  27906. return (0, _tfjsCore.add)(a.totals[n], (0, _tfjsCore.mul)(i, e));
  27907. });
  27908. r.totals[n] = s, null != o && o.dispose();
  27909. }
  27910. }, r = this, t) n(i);
  27911. return [2];
  27912. });
  27913. });
  27914. }, t.prototype.onEpochEnd = function (e, t) {
  27915. return __awaiter(this, void 0, void 0, function () {
  27916. var e,
  27917. n,
  27918. r,
  27919. i,
  27920. a,
  27921. o = this;
  27922. return __generator(this, function (s) {
  27923. if (null != t) for (e = function (e) {
  27924. if (null == n.totals[e]) return "continue";
  27925. "number" == typeof n.totals[e] ? t[e] = n.totals[e] / n.seen : (0, _tfjsCore.tidy)(function () {
  27926. var n = (0, _tfjsCore.mul)((0, _tfjsCore.div)(1, o.seen), o.totals[e]);
  27927. t[e] = n, o.totals[e].dispose(), (0, _tfjsCore.keep)(t[e]);
  27928. });
  27929. }, n = this, r = 0, i = this.params.metrics; r < i.length; r++) a = i[r], e(a);
  27930. return [2];
  27931. });
  27932. });
  27933. }, t;
  27934. }(BaseCallback),
  27935. History = function (e) {
  27936. function t() {
  27937. return null !== e && e.apply(this, arguments) || this;
  27938. }
  27939. return __extends(t, e), t.prototype.onTrainBegin = function (e) {
  27940. return __awaiter(this, void 0, void 0, function () {
  27941. return __generator(this, function (e) {
  27942. return this.epoch = [], this.history = {}, [2];
  27943. });
  27944. });
  27945. }, t.prototype.onEpochEnd = function (e, t) {
  27946. return __awaiter(this, void 0, void 0, function () {
  27947. var n;
  27948. return __generator(this, function (r) {
  27949. for (n in null == t && (t = {}), this.epoch.push(e), t) null == this.history[n] && (this.history[n] = []), this.history[n].push(t[n]);
  27950. return [2];
  27951. });
  27952. });
  27953. }, t.prototype.syncData = function () {
  27954. return __awaiter(this, void 0, void 0, function () {
  27955. var e, t, n, r, i, a, o, s, l;
  27956. return __generator(this, function (u) {
  27957. switch (u.label) {
  27958. case 0:
  27959. for (r in e = [], t = [], n = [], this.history) for (i = this.history[r], a = 0; a < i.length; ++a) "number" != typeof i[a] && (o = i[a], e.push(o.data()), t.push(r), n.push(a));
  27960. return [4, Promise.all(e)];
  27961. case 1:
  27962. for (s = u.sent(), l = 0; l < s.length; ++l) this.history[t[l]][n[l]].dispose(), this.history[t[l]][n[l]] = s[l][0];
  27963. return [2];
  27964. }
  27965. });
  27966. });
  27967. }, t;
  27968. }(BaseCallback),
  27969. CustomCallback = function (e) {
  27970. function t(t, n) {
  27971. var r = e.call(this) || this;
  27972. if (r.currentEpoch = 0, r.yieldEvery = n || "auto", "auto" === r.yieldEvery && (r.yieldEvery = DEFAULT_YIELD_EVERY_MS), "never" === r.yieldEvery && null != t.onYield) throw new Error("yieldEvery is `never` but you provided an `onYield` callback. Either change `yieldEvery` or remove the callback");
  27973. return _tfjsCore.util.isNumber(r.yieldEvery) && (r.maybeWait = debounce(r.maybeWait.bind(r), r.yieldEvery)), r.trainBegin = t.onTrainBegin, r.trainEnd = t.onTrainEnd, r.epochBegin = t.onEpochBegin, r.epochEnd = t.onEpochEnd, r.batchBegin = t.onBatchBegin, r.batchEnd = t.onBatchEnd, r.yield = t.onYield, r;
  27974. }
  27975. return __extends(t, e), t.prototype.maybeWait = function (e, t, n) {
  27976. return __awaiter(this, void 0, void 0, function () {
  27977. var r;
  27978. return __generator(this, function (i) {
  27979. switch (i.label) {
  27980. case 0:
  27981. return r = [], null == this.yield ? [3, 2] : [4, resolveScalarsInLogs(n)];
  27982. case 1:
  27983. i.sent(), r.push(this.yield(e, t, n)), i.label = 2;
  27984. case 2:
  27985. return r.push((0, _tfjsCore.nextFrame)()), [4, Promise.all(r)];
  27986. case 3:
  27987. return i.sent(), [2];
  27988. }
  27989. });
  27990. });
  27991. }, t.prototype.onEpochBegin = function (e, t) {
  27992. return __awaiter(this, void 0, void 0, function () {
  27993. return __generator(this, function (n) {
  27994. switch (n.label) {
  27995. case 0:
  27996. return this.currentEpoch = e, null == this.epochBegin ? [3, 3] : [4, resolveScalarsInLogs(t)];
  27997. case 1:
  27998. return n.sent(), [4, this.epochBegin(e, t)];
  27999. case 2:
  28000. n.sent(), n.label = 3;
  28001. case 3:
  28002. return [2];
  28003. }
  28004. });
  28005. });
  28006. }, t.prototype.onEpochEnd = function (e, t) {
  28007. return __awaiter(this, void 0, void 0, function () {
  28008. var n;
  28009. return __generator(this, function (r) {
  28010. switch (r.label) {
  28011. case 0:
  28012. return n = [], null == this.epochEnd ? [3, 2] : [4, resolveScalarsInLogs(t)];
  28013. case 1:
  28014. r.sent(), n.push(this.epochEnd(e, t)), r.label = 2;
  28015. case 2:
  28016. return "epoch" === this.yieldEvery && n.push((0, _tfjsCore.nextFrame)()), [4, Promise.all(n)];
  28017. case 3:
  28018. return r.sent(), [2];
  28019. }
  28020. });
  28021. });
  28022. }, t.prototype.onBatchBegin = function (e, t) {
  28023. return __awaiter(this, void 0, void 0, function () {
  28024. return __generator(this, function (n) {
  28025. switch (n.label) {
  28026. case 0:
  28027. return null == this.batchBegin ? [3, 3] : [4, resolveScalarsInLogs(t)];
  28028. case 1:
  28029. return n.sent(), [4, this.batchBegin(e, t)];
  28030. case 2:
  28031. n.sent(), n.label = 3;
  28032. case 3:
  28033. return [2];
  28034. }
  28035. });
  28036. });
  28037. }, t.prototype.onBatchEnd = function (e, t) {
  28038. return __awaiter(this, void 0, void 0, function () {
  28039. var n;
  28040. return __generator(this, function (r) {
  28041. switch (r.label) {
  28042. case 0:
  28043. return n = [], null == this.batchEnd ? [3, 2] : [4, resolveScalarsInLogs(t)];
  28044. case 1:
  28045. r.sent(), n.push(this.batchEnd(e, t)), r.label = 2;
  28046. case 2:
  28047. return "batch" === this.yieldEvery ? n.push((0, _tfjsCore.nextFrame)()) : _tfjsCore.util.isNumber(this.yieldEvery) && n.push(this.maybeWait(this.currentEpoch, e, t)), [4, Promise.all(n)];
  28048. case 3:
  28049. return r.sent(), [2];
  28050. }
  28051. });
  28052. });
  28053. }, t.prototype.onTrainBegin = function (e) {
  28054. return __awaiter(this, void 0, void 0, function () {
  28055. return __generator(this, function (t) {
  28056. switch (t.label) {
  28057. case 0:
  28058. return null == this.trainBegin ? [3, 3] : [4, resolveScalarsInLogs(e)];
  28059. case 1:
  28060. return t.sent(), [4, this.trainBegin(e)];
  28061. case 2:
  28062. t.sent(), t.label = 3;
  28063. case 3:
  28064. return [2];
  28065. }
  28066. });
  28067. });
  28068. }, t.prototype.onTrainEnd = function (e) {
  28069. return __awaiter(this, void 0, void 0, function () {
  28070. return __generator(this, function (t) {
  28071. switch (t.label) {
  28072. case 0:
  28073. return null == this.trainEnd ? [3, 3] : [4, resolveScalarsInLogs(e)];
  28074. case 1:
  28075. return t.sent(), [4, this.trainEnd(e)];
  28076. case 2:
  28077. t.sent(), t.label = 3;
  28078. case 3:
  28079. return [2];
  28080. }
  28081. });
  28082. });
  28083. }, t;
  28084. }(BaseCallback);
  28085. exports.CustomCallback = CustomCallback;
  28086. exports.History = History;
  28087. exports.CallbackList = CallbackList;
  28088. function standardizeCallbacks(e, t) {
  28089. return null == e && (e = {}), e instanceof BaseCallback ? [e] : Array.isArray(e) && e[0] instanceof BaseCallback ? e : toList(e).map(function (e) {
  28090. return new CustomCallback(e, t);
  28091. });
  28092. }
  28093. var CallbackConstructorRegistry = function () {
  28094. function e() { }
  28095. return e.registerCallbackConstructor = function (t, n) {
  28096. _tfjsCore.util.assert(t >= 0 && Number.isInteger(t), function () {
  28097. return "Verbosity level is expected to be an integer >= 0, but got " + t;
  28098. }), e.checkForDuplicate(n), null == e.constructors[t] && (e.constructors[t] = []), e.constructors[t].push(n);
  28099. }, e.checkForDuplicate = function (t) {
  28100. for (var n in e.constructors) {
  28101. e.constructors[+n].forEach(function (e) {
  28102. if (e === t) throw new ValueError("Duplicate callback constructor.");
  28103. });
  28104. }
  28105. }, e.clear = function () {
  28106. e.constructors = {};
  28107. }, e.createCallbacks = function (t) {
  28108. var n = [];
  28109. for (var r in e.constructors) {
  28110. var i = +r;
  28111. t >= i && n.push.apply(n, e.constructors[i]);
  28112. }
  28113. return n.map(function (e) {
  28114. return new e();
  28115. });
  28116. }, e.constructors = {}, e;
  28117. }();
  28118. function configureCallbacks(e, t, n, r, i, a, o, s, l) {
  28119. var u = new History(),
  28120. c = [new BaseLogger()].concat(CallbackConstructorRegistry.createCallbacks(t));
  28121. null != e && c.push.apply(c, e), c.push(u);
  28122. var p = new CallbackList(c);
  28123. return p.setParams({
  28124. epochs: n,
  28125. initialEpoch: r,
  28126. samples: i,
  28127. steps: a,
  28128. batchSize: o,
  28129. verbose: t,
  28130. doValidation: s,
  28131. metrics: l
  28132. }), {
  28133. callbackList: p,
  28134. history: u
  28135. };
  28136. }
  28137. function deserialize(e, t, n) {
  28138. return void 0 === t && (t = {}), void 0 === n && (n = !1), deserializeKerasObject(e, _tfjsCore.serialization.SerializationMap.getMap().classNameMap, t, "layer", n);
  28139. }
  28140. function l2Normalize(e, t) {
  28141. return (0, _tfjsCore.tidy)(function () {
  28142. "float32" !== e.dtype && (e = e.asType("float32"));
  28143. var n = (0, _tfjsCore.sum)(square(e), t, !0),
  28144. r = (0, _tfjsCore.fill)(n.shape, epsilon()),
  28145. i = (0, _tfjsCore.sqrt)((0, _tfjsCore.maximum)(n, r));
  28146. return (0, _tfjsCore.div)(e, i);
  28147. });
  28148. }
  28149. function meanSquaredError(e, t) {
  28150. return (0, _tfjsCore.tidy)(function () {
  28151. return (0, _tfjsCore.mean)(square((0, _tfjsCore.sub)(t, e)), -1);
  28152. });
  28153. }
  28154. function meanAbsoluteError(e, t) {
  28155. return (0, _tfjsCore.tidy)(function () {
  28156. return (0, _tfjsCore.mean)((0, _tfjsCore.abs)((0, _tfjsCore.sub)(t, e)), -1);
  28157. });
  28158. }
  28159. function meanAbsolutePercentageError(e, t) {
  28160. return (0, _tfjsCore.tidy)(function () {
  28161. var n = (0, _tfjsCore.sub)(e, t),
  28162. r = (0, _tfjsCore.clipByValue)((0, _tfjsCore.abs)(e), epsilon(), Number.MAX_VALUE),
  28163. i = (0, _tfjsCore.abs)((0, _tfjsCore.div)(n, r));
  28164. return (0, _tfjsCore.mul)(100, (0, _tfjsCore.mean)(i, -1));
  28165. });
  28166. }
  28167. function meanSquaredLogarithmicError(e, t) {
  28168. return (0, _tfjsCore.tidy)(function () {
  28169. var n = (0, _tfjsCore.clipByValue)(t, epsilon(), Number.MAX_VALUE),
  28170. r = (0, _tfjsCore.log)((0, _tfjsCore.add)(1, n)),
  28171. i = (0, _tfjsCore.clipByValue)(e, epsilon(), Number.MAX_VALUE),
  28172. a = (0, _tfjsCore.log)((0, _tfjsCore.add)(1, i));
  28173. return (0, _tfjsCore.mean)(square((0, _tfjsCore.sub)(r, a)), -1);
  28174. });
  28175. }
  28176. function squaredHinge(e, t) {
  28177. return (0, _tfjsCore.tidy)(function () {
  28178. var n = (0, _tfjsCore.maximum)(0, (0, _tfjsCore.sub)(1, (0, _tfjsCore.mul)(e, t)));
  28179. return (0, _tfjsCore.mean)(square(n), -1);
  28180. });
  28181. }
  28182. function hinge(e, t) {
  28183. return (0, _tfjsCore.tidy)(function () {
  28184. var n = (0, _tfjsCore.maximum)(0, (0, _tfjsCore.sub)(1, (0, _tfjsCore.mul)(e, t)));
  28185. return (0, _tfjsCore.mean)(n, -1);
  28186. });
  28187. }
  28188. function categoricalHinge(e, t) {
  28189. return (0, _tfjsCore.tidy)(function () {
  28190. var n = (0, _tfjsCore.sum)((0, _tfjsCore.mul)(e, t), -1),
  28191. r = (0, _tfjsCore.max)((0, _tfjsCore.mul)((0, _tfjsCore.sub)(1, e), t), -1);
  28192. return (0, _tfjsCore.maximum)(0, (0, _tfjsCore.add)(1, (0, _tfjsCore.sub)(r, n)));
  28193. });
  28194. }
  28195. function logcosh(e, t) {
  28196. return (0, _tfjsCore.tidy)(function () {
  28197. var n = Math.log(2),
  28198. r = (0, _tfjsCore.sub)(t, e),
  28199. i = (0, _tfjsCore.sub)((0, _tfjsCore.add)(r, (0, _tfjsCore.softplus)((0, _tfjsCore.mul)(-2, r))), n);
  28200. return (0, _tfjsCore.mean)(i, -1);
  28201. });
  28202. }
  28203. function categoricalCrossentropy(e, t, n) {
  28204. return void 0 === n && (n = !1), (0, _tfjsCore.tidy)(function () {
  28205. if (n) t = (0, _tfjsCore.softmax)(t); else {
  28206. var r = (0, _tfjsCore.sum)(t, t.shape.length - 1, !0);
  28207. t = (0, _tfjsCore.div)(t, r);
  28208. }
  28209. return t = (0, _tfjsCore.clipByValue)(t, epsilon(), 1 - epsilon()), (0, _tfjsCore.neg)((0, _tfjsCore.sum)((0, _tfjsCore.mul)(e.toFloat(), (0, _tfjsCore.log)(t)), t.shape.length - 1));
  28210. });
  28211. }
  28212. function sparseCategoricalCrossentropy(e, t) {
  28213. return (0, _tfjsCore.tidy)(function () {
  28214. var n = (0, _tfjsCore.floor)(flatten(e)).toInt(),
  28215. r = (t = (0, _tfjsCore.clipByValue)(t, epsilon(), 1 - epsilon())).shape;
  28216. return categoricalCrossentropy((0, _tfjsCore.oneHot)(n, r[r.length - 1]).reshape(r), t, !1);
  28217. });
  28218. }
  28219. function sigmoidCrossEntropyWithLogits(e, t) {
  28220. if (!_tfjsCore.util.arraysEqual(e.shape, t.shape)) throw new ValueError("logits and labels must have the same shape, but got shapes " + JSON.stringify(e.shape) + " and " + JSON.stringify(t.shape));
  28221. return (0, _tfjsCore.tidy)(function () {
  28222. var n = t.relu(),
  28223. r = t.abs().neg();
  28224. return n.sub(t.mul(e)).add(r.exp().log1p());
  28225. });
  28226. }
  28227. function binaryCrossentropy(e, t) {
  28228. return (0, _tfjsCore.tidy)(function () {
  28229. var n;
  28230. return n = (0, _tfjsCore.clipByValue)(t, epsilon(), 1 - epsilon()), n = (0, _tfjsCore.log)((0, _tfjsCore.div)(n, (0, _tfjsCore.sub)(1, n))), (0, _tfjsCore.mean)(sigmoidCrossEntropyWithLogits(e, n), -1);
  28231. });
  28232. }
  28233. function kullbackLeiblerDivergence(e, t) {
  28234. return (0, _tfjsCore.tidy)(function () {
  28235. var n = (0, _tfjsCore.clipByValue)(e, epsilon(), 1),
  28236. r = (0, _tfjsCore.clipByValue)(t, epsilon(), 1);
  28237. return (0, _tfjsCore.sum)((0, _tfjsCore.mul)(e, (0, _tfjsCore.log)((0, _tfjsCore.div)(n, r))), -1);
  28238. });
  28239. }
  28240. function poisson(e, t) {
  28241. return (0, _tfjsCore.tidy)(function () {
  28242. var n = (0, _tfjsCore.log)((0, _tfjsCore.add)(epsilon(), t));
  28243. return (0, _tfjsCore.mean)((0, _tfjsCore.sub)(t, (0, _tfjsCore.mul)(e, n)), -1);
  28244. });
  28245. }
  28246. function cosineProximity(e, t) {
  28247. return (0, _tfjsCore.tidy)(function () {
  28248. var n = l2Normalize(e, -1),
  28249. r = l2Normalize(t, -1),
  28250. i = (0, _tfjsCore.mul)(n, r);
  28251. return (0, _tfjsCore.neg)((0, _tfjsCore.sum)(i, -1));
  28252. });
  28253. }
  28254. var lossesMap = {
  28255. meanSquaredError: meanSquaredError,
  28256. meanAbsoluteError: meanAbsoluteError,
  28257. meanAbsolutePercentageError: meanAbsolutePercentageError,
  28258. meanSquaredLogarithmicError: meanSquaredLogarithmicError,
  28259. squaredHinge: squaredHinge,
  28260. hinge: hinge,
  28261. categoricalHinge: categoricalHinge,
  28262. logcosh: logcosh,
  28263. categoricalCrossentropy: categoricalCrossentropy,
  28264. sparseCategoricalCrossentropy: sparseCategoricalCrossentropy,
  28265. binaryCrossentropy: binaryCrossentropy,
  28266. kullbackLeiblerDivergence: kullbackLeiblerDivergence,
  28267. poisson: poisson,
  28268. cosineProximity: cosineProximity
  28269. };
  28270. function get(e) {
  28271. if ("string" == typeof e) {
  28272. if (e in lossesMap) return lossesMap[e];
  28273. var t = "Unknown loss " + e;
  28274. throw e.toLowerCase().includes("softmaxcrossentropy") && (t = "Unknown loss " + e + '. Use "categoricalCrossentropy" as the string name for tf.losses.softmaxCrossEntropy'), new ValueError(t);
  28275. }
  28276. return e;
  28277. }
  28278. function binaryAccuracy(e, t) {
  28279. return (0, _tfjsCore.tidy)(function () {
  28280. var n = (0, _tfjsCore.mul)(.5, (0, _tfjsCore.onesLike)(t)),
  28281. r = cast$1((0, _tfjsCore.greater)(t, n), e.dtype);
  28282. return (0, _tfjsCore.mean)((0, _tfjsCore.equal)(e, r), -1);
  28283. });
  28284. }
  28285. function categoricalAccuracy(e, t) {
  28286. return (0, _tfjsCore.tidy)(function () {
  28287. return cast$1((0, _tfjsCore.equal)((0, _tfjsCore.argMax)(e, -1), (0, _tfjsCore.argMax)(t, -1)), "float32");
  28288. });
  28289. }
  28290. function truePositives(e, t) {
  28291. return (0, _tfjsCore.tidy)(function () {
  28292. return (0, _tfjsCore.logicalAnd)(e.equal(1), t.equal(1)).sum().cast("float32");
  28293. });
  28294. }
  28295. function falseNegatives(e, t) {
  28296. return (0, _tfjsCore.tidy)(function () {
  28297. return (0, _tfjsCore.logicalAnd)(e.equal(1), t.equal(0)).sum().cast("float32");
  28298. });
  28299. }
  28300. function falsePositives(e, t) {
  28301. return (0, _tfjsCore.tidy)(function () {
  28302. return (0, _tfjsCore.logicalAnd)(e.equal(0), t.equal(1)).sum().cast("float32");
  28303. });
  28304. }
  28305. function precision(e, t) {
  28306. return (0, _tfjsCore.tidy)(function () {
  28307. var n = truePositives(e, t),
  28308. r = falsePositives(e, t),
  28309. i = n.add(r);
  28310. return (0, _tfjsCore.where)((0, _tfjsCore.greater)(i, 0), n.div(i), 0).cast("float32");
  28311. });
  28312. }
  28313. function recall(e, t) {
  28314. return (0, _tfjsCore.tidy)(function () {
  28315. var n = truePositives(e, t),
  28316. r = falseNegatives(e, t),
  28317. i = n.add(r);
  28318. return (0, _tfjsCore.where)((0, _tfjsCore.greater)(i, 0), n.div(i), 0).cast("float32");
  28319. });
  28320. }
  28321. function binaryCrossentropy$1(e, t) {
  28322. return binaryCrossentropy(e, t);
  28323. }
  28324. function sparseCategoricalAccuracy(e, t) {
  28325. return e.rank === t.rank && (e = e.squeeze([e.rank - 1])), (t = t.argMax(-1)).dtype !== e.dtype && (t = t.asType(e.dtype)), (0, _tfjsCore.equal)(e, t).asType("float32");
  28326. }
  28327. var mse$1 = meanSquaredError,
  28328. MSE$1 = meanSquaredError,
  28329. mae$1 = meanAbsoluteError,
  28330. MAE$1 = meanAbsoluteError,
  28331. mape$1 = meanAbsolutePercentageError,
  28332. MAPE$1 = meanAbsolutePercentageError,
  28333. categoricalCrossentropy$1 = categoricalCrossentropy,
  28334. cosine$1 = cosineProximity,
  28335. sparseCategoricalCrossentropy$1 = sparseCategoricalCrossentropy,
  28336. metricsMap = {
  28337. binaryAccuracy: binaryAccuracy,
  28338. categoricalAccuracy: categoricalAccuracy,
  28339. precision: precision,
  28340. categoricalCrossentropy: categoricalCrossentropy$1,
  28341. sparseCategoricalCrossentropy: sparseCategoricalCrossentropy$1,
  28342. mse: mse$1,
  28343. MSE: MSE$1,
  28344. mae: mae$1,
  28345. MAE: MAE$1,
  28346. mape: mape$1,
  28347. MAPE: MAPE$1,
  28348. cosine: cosine$1
  28349. };
  28350. function get$1(e) {
  28351. if ("string" == typeof e && e in metricsMap) return metricsMap[e];
  28352. if ("string" != typeof e && null != e) return e;
  28353. throw new ValueError("Unknown metric " + e);
  28354. }
  28355. function getLossOrMetricName(e) {
  28356. if (assert(null !== e, "Unknown LossOrMetricFn " + e), "string" == typeof e) return e;
  28357. for (var t = void 0, n = 0, r = Object.keys(lossesMap); n < r.length; n++) {
  28358. var i = r[n];
  28359. if (lossesMap[i] === e) {
  28360. t = i;
  28361. break;
  28362. }
  28363. }
  28364. if (void 0 !== t) return t;
  28365. for (var a = 0, o = Object.keys(metricsMap); a < o.length; a++) {
  28366. i = o[a];
  28367. if (metricsMap[i] === e) {
  28368. t = i;
  28369. break;
  28370. }
  28371. }
  28372. return void 0 !== t ? t : e.name;
  28373. }
  28374. function getOptimizer(e) {
  28375. var t = {
  28376. Adagrad: function () {
  28377. return _tfjsCore.train.adagrad(.01);
  28378. },
  28379. Adadelta: function () {
  28380. return _tfjsCore.train.adadelta(1, .95, epsilon());
  28381. },
  28382. Adam: function () {
  28383. return _tfjsCore.train.adam(.001, .9, .999, epsilon());
  28384. },
  28385. Adamax: function () {
  28386. return _tfjsCore.train.adamax(.002, .9, .999, epsilon(), 0);
  28387. },
  28388. RMSProp: function () {
  28389. return _tfjsCore.train.rmsprop(.001, .9, 0, epsilon());
  28390. },
  28391. SGD: function () {
  28392. return _tfjsCore.train.sgd(.01);
  28393. }
  28394. };
  28395. if (t.adagrad = t.Adagrad, t.adadelta = t.Adadelta, t.adam = t.Adam, t.adamax = t.Adamax, t.rmsprop = t.RMSProp, t.sgd = t.SGD, e in t) return t[e]();
  28396. throw new ValueError("Unknown Optimizer " + e);
  28397. }
  28398. var MAX_USER_DEFINED_METADATA_SERIALIZED_LENGTH = 1048576;
  28399. function checkUserDefinedMetadata(e, t, n) {
  28400. if (void 0 === n && (n = !1), null == e || "object" != typeof e || Object.getPrototypeOf(e) !== Object.prototype || !plainObjectCheck(e)) throw new Error("User-defined metadata is expected to be a JSON object, but is not.");
  28401. if (n) {
  28402. var r = JSON.stringify(e);
  28403. r.length > MAX_USER_DEFINED_METADATA_SERIALIZED_LENGTH && console.warn('User-defined metadata of model "' + t + '" is too large in size (length=' + r.length + " when serialized). It is not recommended to store such large objects in user-defined metadata. Please make sure its serialized length is <= " + MAX_USER_DEFINED_METADATA_SERIALIZED_LENGTH + ".");
  28404. }
  28405. }
  28406. function plainObjectCheck(e) {
  28407. if (null === e) return !0;
  28408. if ("object" == typeof e) {
  28409. if (Object.getPrototypeOf(e) === Object.prototype) {
  28410. for (var t = 0, n = Object.keys(e); t < n.length; t++) {
  28411. var r = n[t];
  28412. if ("string" != typeof r) return !1;
  28413. if (!plainObjectCheck(e[r])) return !1;
  28414. }
  28415. return !0;
  28416. }
  28417. if (Array.isArray(e)) {
  28418. for (var i = 0, a = e; i < a.length; i++) {
  28419. if (!plainObjectCheck(a[i])) return !1;
  28420. }
  28421. return !0;
  28422. }
  28423. return !1;
  28424. }
  28425. var o = typeof e;
  28426. return "string" === o || "number" === o || "boolean" === o;
  28427. }
  28428. function printSummary(e, t, n, r) {
  28429. void 0 === r && (r = console.log);
  28430. var i,
  28431. a = isModelSequentialLike(e),
  28432. o = ["Layer (type)", "Output shape", "Param #"];
  28433. if (a ? (t = t || 65, n = n || [.45, .85, 1]) : (t = t || 98, n = n || [.33, .55, .67, 1]), n[n.length - 1] <= 1 && (n = n.map(function (e) {
  28434. return Math.floor(t * e);
  28435. })), !a) for (var s in o.push("Receives inputs"), i = [], e.nodesByDepth) i.push.apply(i, e.nodesByDepth[s]);
  28436. r("_".repeat(t)), printRow(o, n, r), r("=".repeat(t));
  28437. for (var l = e.layers, u = 0; u < l.length; ++u) a ? printLayerSummary(l[u], n, r) : printLayerSummaryWithConnections(l[u], n, i, r), r((u === l.length - 1 ? "=" : "_").repeat(t));
  28438. e.checkTrainableWeightsConsistency();
  28439. var c = countTrainableParams(e),
  28440. p = countParamsInWeights(e.nonTrainableWeights);
  28441. r("Total params: " + (c + p)), r("Trainable params: " + c), r("Non-trainable params: " + p), r("_".repeat(t));
  28442. }
  28443. function countTrainableParams(e) {
  28444. return null != e.collectedTrainableWeights ? countParamsInWeights(e.collectedTrainableWeights) : countParamsInWeights(e.trainableWeights);
  28445. }
  28446. function isModelSequentialLike(e) {
  28447. var t = !0,
  28448. n = [],
  28449. r = [];
  28450. for (var i in e.nodesByDepth) n.push(e.nodesByDepth[i]);
  28451. for (var a = 0, o = n; a < o.length; a++) {
  28452. var s = o[a];
  28453. if (s.length > 1 || 1 === s.length && s[0].inboundLayers.length > 1) {
  28454. t = !1;
  28455. break;
  28456. }
  28457. r.push.apply(r, s);
  28458. }
  28459. if (t) for (var l = 0, u = e.layers; l < u.length; l++) {
  28460. for (var c = !1, p = 0, h = u[l].inboundNodes; p < h.length; p++) {
  28461. var d = h[p];
  28462. if (-1 !== r.indexOf(d)) {
  28463. if (c) {
  28464. t = !1;
  28465. break;
  28466. }
  28467. c = !0;
  28468. }
  28469. }
  28470. if (!t) break;
  28471. }
  28472. return t;
  28473. }
  28474. function printRow(e, t, n) {
  28475. void 0 === n && (n = console.log);
  28476. for (var r = "", i = 0; i < e.length; ++i) i > 0 && (r = r.slice(0, r.length - 1) + " "), r = (r += e[i]).slice(0, t[i]), r += " ".repeat(t[i] - r.length);
  28477. n(r);
  28478. }
  28479. function printLayerSummary(e, t, n) {
  28480. var r;
  28481. try {
  28482. r = JSON.stringify(e.outputShape);
  28483. } catch (e) {
  28484. r = "multiple";
  28485. }
  28486. printRow([e.name + " (" + e.getClassName() + ")", r, e.countParams().toString()], t, n);
  28487. }
  28488. function printLayerSummaryWithConnections(e, t, n, r) {
  28489. var i;
  28490. try {
  28491. i = JSON.stringify(e.outputShape);
  28492. } catch (e) {
  28493. i = "multiple";
  28494. }
  28495. for (var a = [], o = 0, s = e.inboundNodes; o < s.length; o++) {
  28496. var l = s[o];
  28497. if (!(null != n && n.length > 0 && -1 === n.indexOf(l))) for (var u = 0; u < l.inboundLayers.length; ++u) {
  28498. var c = l.inboundLayers[u].name,
  28499. p = l.nodeIndices[u],
  28500. h = l.tensorIndices[u];
  28501. a.push(c + "[" + p + "][" + h + "]");
  28502. }
  28503. }
  28504. var d = e.name,
  28505. f = e.getClassName(),
  28506. g = 0 === a.length ? "" : a[0];
  28507. printRow([d + " (" + f + ")", i, e.countParams().toString(), g], t, r);
  28508. for (u = 1; u < a.length; ++u) printRow(["", "", "", a[u]], t, r);
  28509. }
  28510. function isArrayItemInputOrOutputName(e, t, n) {
  28511. return ("inboundNodes" === e || "outputLayers" === e || "inputLayers" === e) && 0 === t && "string" == typeof n;
  28512. }
  28513. function convertPythonicToTs(e, t) {
  28514. if (null === e) return null;
  28515. if ("string" == typeof e) return toCamelCase(e);
  28516. if ("number" == typeof e || "boolean" == typeof e) return e;
  28517. if (e instanceof Array) {
  28518. for (var n = [], r = e.length, i = 0; i < r; ++i) {
  28519. var a = e[i];
  28520. isArrayItemInputOrOutputName(t, i, a) ? n.push(a) : n.push(convertPythonicToTs(a, t));
  28521. }
  28522. return n;
  28523. }
  28524. for (var o = {}, s = 0, l = Object.keys(e); s < l.length; s++) {
  28525. var u = l[s],
  28526. c = e[u];
  28527. if ("name" === u && "string" == typeof c) o[u] = c; else {
  28528. var p = toCamelCase(u);
  28529. o[p] = convertPythonicToTs(c, p);
  28530. }
  28531. }
  28532. return o;
  28533. }
  28534. function convertTsToPythonic(e, t) {
  28535. if (null === e || void 0 === e) return null;
  28536. if ("string" == typeof e) return toSnakeCase(e);
  28537. if ("number" == typeof e || "boolean" == typeof e) return e;
  28538. if (e instanceof Array) {
  28539. for (var n = [], r = e.length, i = 0; i < r; ++i) {
  28540. var a = e[i];
  28541. isArrayItemInputOrOutputName(t, i, a) ? n.push(a) : n.push(convertTsToPythonic(a, t));
  28542. }
  28543. return n;
  28544. }
  28545. for (var o = {}, s = 0, l = Object.keys(e); s < l.length; s++) {
  28546. var u = l[s],
  28547. c = e[u],
  28548. p = toSnakeCase(u);
  28549. o[p] = "name" !== u && "className" !== u || "string" != typeof c ? convertTsToPythonic(c, u) : c;
  28550. }
  28551. return o;
  28552. }
  28553. var version = "1.3.1";
  28554. exports.version_layers = version;
  28555. function assertFeedCompatibility(e, t) {
  28556. if (null == e.dtype || e.dtype === t.dtype) return t;
  28557. try {
  28558. return (0, _tfjsCore.cast)(t, e.dtype);
  28559. } catch (n) {
  28560. throw new ValueError("The dtype of the feed (" + t.dtype + ") can not be cast to the dtype of the key '" + e.name + "' (" + e.dtype + ").");
  28561. }
  28562. }
  28563. var FeedDict = function () {
  28564. function e(t) {
  28565. if (this.id2Value = {}, this.id2Mask = {}, this.name2Id = {}, t instanceof e) for (var n in t.id2Value) this.id2Value[n] = t.id2Value[n], n in t.id2Mask && (this.id2Mask[n] = t.id2Mask[n]); else {
  28566. if (null == t) return;
  28567. for (var r = 0, i = t; r < i.length; r++) {
  28568. var a = i[r];
  28569. this.add(a.key, a.value);
  28570. }
  28571. }
  28572. }
  28573. return e.prototype.add = function (e, t, n) {
  28574. if (null != this.id2Value[e.id]) throw new ValueError("Duplicate key: name=" + e.name + ", id=" + e.id);
  28575. return this.id2Value[e.id] = assertFeedCompatibility(e, t), this.name2Id[e.name] = e.id, null != n && (this.id2Mask[e.id] = n), this;
  28576. }, e.prototype.addFeed = function (e) {
  28577. this.add(e.key, e.value);
  28578. }, e.prototype.hasKey = function (e) {
  28579. return null != this.id2Value[e.id];
  28580. }, e.prototype.names = function () {
  28581. return Object.keys(this.name2Id);
  28582. }, e.prototype.getValue = function (e) {
  28583. if (e instanceof SymbolicTensor) {
  28584. if (null == this.id2Value[e.id]) throw new ValueError("Nonexistent key: " + e.name);
  28585. return this.id2Value[e.id];
  28586. }
  28587. var t = this.name2Id[e];
  28588. if (null == t) throw new ValueError("Feed dict has no SymbolicTensor name: " + e);
  28589. return this.id2Value[t];
  28590. }, e.prototype.getMask = function (e) {
  28591. if (e instanceof SymbolicTensor) {
  28592. if (null == this.id2Value[e.id]) throw new ValueError("Nonexistent key: " + e.name);
  28593. return this.id2Mask[e.id];
  28594. }
  28595. var t = this.name2Id[e];
  28596. if (null == t) throw new ValueError("Feed dict has no SymbolicTensor name: " + e);
  28597. return this.id2Mask[t];
  28598. }, e.prototype.disposeMasks = function () {
  28599. null != this.id2Mask && (0, _tfjsCore.dispose)(this.id2Mask);
  28600. }, e;
  28601. }(),
  28602. cachedSorted = {},
  28603. cachedRecipientCounts = {};
  28604. function execute(e, t, n, r) {
  28605. for (var i = null != n && n.training, a = Array.isArray(e), o = a ? e : [e], s = o.map(function (e) {
  28606. return e.name;
  28607. }), l = [], u = t.names(), c = 0, p = s; c < p.length; c++) {
  28608. var h = p[c];
  28609. -1 !== u.indexOf(h) ? l.push(t.getValue(h)) : l.push(null);
  28610. }
  28611. null != r && (r.maxNumTensors = -1 / 0, r.minNumTensors = 1 / 0);
  28612. var d,
  28613. f,
  28614. g = s.join(",") + "|" + t.names().join(",");
  28615. if (null == cachedSorted[g]) {
  28616. var m = getTopologicalSortAndRecipientCounts(o, t);
  28617. d = m.sorted, f = m.recipientCounts, cachedSorted[g] = d, cachedRecipientCounts[g] = f;
  28618. }
  28619. d = cachedSorted[g], f = {}, i || Object.assign(f, cachedRecipientCounts[g]);
  28620. for (var y = new FeedDict(t), v = 0; v < d.length; ++v) {
  28621. if (null != r) {
  28622. var b = (0, _tfjsCore.memory)().numTensors;
  28623. b > r.maxNumTensors && (r.maxNumTensors = b), b < r.minNumTensors && (r.minNumTensors = b);
  28624. }
  28625. var w = d[v],
  28626. z = w.sourceLayer;
  28627. if (!(z instanceof InputLayer)) {
  28628. for (var S = [], A = [], _ = [], I = !1, C = 0, E = w.inputs; C < E.length; C++) {
  28629. var N = E[C],
  28630. k = y.getValue(N),
  28631. x = y.getMask(N);
  28632. S.push(k), A.push(x), null != x && (I = !0), i || (f[N.name]--, 0 !== f[N.name] || t.hasKey(N) || -1 !== s.indexOf(N.name) || k.isDisposed || !0 === N.sourceLayer.stateful || _.push(k));
  28633. }
  28634. I && ((n = n || {}).mask = A[0]);
  28635. var L = toList(z.apply(S, n)),
  28636. T = null;
  28637. z.supportsMasking && (T = z.computeMask(S, A));
  28638. for (var D = getNodeOutputs(w), O = Array.isArray(D) ? D : [D], R = 0; R < O.length; ++R) {
  28639. y.hasKey(O[R]) || y.add(O[R], L[R], Array.isArray(T) ? T[0] : T);
  28640. var M = s.indexOf(O[R].name);
  28641. -1 !== M && (l[M] = L[R]);
  28642. }
  28643. i || (0, _tfjsCore.dispose)(_);
  28644. }
  28645. }
  28646. return y.disposeMasks(), a ? l : l[0];
  28647. }
  28648. function getTopologicalSortAndRecipientCounts(e, t) {
  28649. _tfjsCore.util.assert(null != e && e.length > 0, function () {
  28650. return "Expected at least one fetch, got none";
  28651. });
  28652. var n = [],
  28653. r = {};
  28654. if (1 === e.length) {
  28655. var i = getTopologicalSortAndRecipientCountsForOneFetch(e[0], t);
  28656. n = i.sorted, r = i.recipientMap;
  28657. } else for (var a = new Set(), o = 0, s = e; o < s.length; o++) {
  28658. for (var l = getTopologicalSortAndRecipientCountsForOneFetch(s[o], t), u = l.sorted, c = l.recipientMap, p = 0, h = u; p < h.length; p++) {
  28659. var d = h[p];
  28660. a.has(d.name) || (n.push(d), a.add(d.name));
  28661. }
  28662. var f = function (e) {
  28663. null == r[e] && (r[e] = new Set()), c[e].forEach(function (t) {
  28664. return r[e].add(t);
  28665. });
  28666. };
  28667. for (var g in c) f(g);
  28668. }
  28669. return {
  28670. sorted: n,
  28671. recipientCounts: recipientMap2Counts(r)
  28672. };
  28673. }
  28674. function recipientMap2Counts(e) {
  28675. var t = {};
  28676. for (var n in e) t[n] = e[n].size;
  28677. return t;
  28678. }
  28679. function getTopologicalSortAndRecipientCountsForOneFetch(e, t) {
  28680. for (var n = new Set(), r = [], i = {}, a = 0, o = t.names(); a < o.length; a++) {
  28681. var s = o[a];
  28682. n.add(s);
  28683. }
  28684. var l = [],
  28685. u = [];
  28686. for (l.push(e); l.length > 0;) {
  28687. var c = l[l.length - 1];
  28688. if (n.has(c.name)) l.pop(); else {
  28689. var p = u[u.length - 1] === l.length - 1;
  28690. if (0 === c.inputs.length || p) l.pop(), r.push(c), n.add(c.name), p && u.pop(); else {
  28691. u.push(l.length - 1);
  28692. for (var h = 0, d = c.inputs; h < d.length; h++) {
  28693. var f = d[h];
  28694. null == i[f.name] && (i[f.name] = new Set()), i[f.name].add(c.name), n.has(f.name) || l.push(f);
  28695. }
  28696. }
  28697. }
  28698. }
  28699. return {
  28700. sorted: r,
  28701. recipientMap: i
  28702. };
  28703. }
  28704. function getNodeOutputs(e) {
  28705. var t;
  28706. if (1 === e.sourceLayer.inboundNodes.length) t = e.sourceLayer.output; else {
  28707. for (var n = null, r = 0; r < e.sourceLayer.inboundNodes.length; ++r) for (var i = 0, a = e.sourceLayer.inboundNodes[r].outputTensors; i < a.length; i++) {
  28708. if (a[i].id === e.id) {
  28709. n = r;
  28710. break;
  28711. }
  28712. }
  28713. t = e.sourceLayer.getOutputAt(n);
  28714. }
  28715. return t;
  28716. }
  28717. var Container = function (e) {
  28718. function t(n) {
  28719. var r = e.call(this, {}) || this;
  28720. if (r.containerNodes = new Set(), r.name = n.name, null == r.name) {
  28721. var i = r.getClassName().toLowerCase();
  28722. r.name = getUid(i);
  28723. }
  28724. if (r.supportsMasking = !1, r.trainable_ = !0, Array.isArray(n.inputs) ? r.inputs = n.inputs.slice() : r.inputs = [n.inputs], Array.isArray(n.outputs) ? r.outputs = n.outputs.slice() : r.outputs = [n.outputs], unique(r.inputs).length !== r.inputs.length) throw new ValueError("The list of inputs passed to the model is redundant. All inputs should only appear once. Found: " + r.inputs.map(function (e) {
  28725. return e.name;
  28726. }));
  28727. unique(r.outputs).length !== r.outputs.length && console.warn("The list of outputs passed to the model is redundant. All outputs should only appear once. Found: " + r.outputs.map(function (e) {
  28728. return e.name;
  28729. })), r.inputLayers = [], r.inputLayersNodeIndices = [], r.inputLayersTensorIndices = [], r.outputLayers = [], r.outputLayersNodeIndices = [], r.outputLayersTensorIndices = [], r.layers = [], r.internalContainerRefs = [];
  28730. for (var a = 0, o = r.outputs; a < o.length; a++) {
  28731. var s = (C = o[a]).sourceLayer,
  28732. l = C.nodeIndex,
  28733. u = C.tensorIndex;
  28734. r.outputLayers.push(s), r.outputLayersNodeIndices.push(l), r.outputLayersTensorIndices.push(u);
  28735. }
  28736. for (var c = 0, p = r.inputs; c < p.length; c++) {
  28737. s = (C = p[c]).sourceLayer, l = C.nodeIndex, u = C.tensorIndex;
  28738. assert(0 === l, "input layer has >1 nodes"), assert(0 === u, "input layer has >1 tensors"), r.inputLayers.push(s), r.inputLayersNodeIndices.push(l), r.inputLayersTensorIndices.push(u);
  28739. }
  28740. r.inputNames = [], r.outputNames = [], r.feedInputShapes = [], r.feedInputNames = [], r.feedOutputNames = [];
  28741. for (var h = 0; h < r.inputLayers.length; h++) {
  28742. if (!((s = r.inputLayers[h]) instanceof InputLayer)) throw new TypeError("Input layers to a LayersModel must be InputLayer objects. Received inputs: " + n.inputs + ". Input " + h + " (0-based) originates from layer type " + s.getClassName() + ".");
  28743. r.inputNames.push(s.name), r.feedInputShapes.push(s.batchInputShape), r.feedInputNames.push(s.name);
  28744. }
  28745. for (var d = 0, f = r.outputLayers; d < f.length; d++) {
  28746. s = f[d];
  28747. r.outputNames.push(s.name);
  28748. }
  28749. r.internalInputShapes = r.inputs.map(function (e) {
  28750. return e.shape;
  28751. }), r.internalOutputShapes = r.outputs.map(function (e) {
  28752. return e.shape;
  28753. });
  28754. for (var g = {}, m = {}, y = {}, v = {}, b = {}, w = [], z = function (e, n, i, a, o, s) {
  28755. null != a && null != o && null != s || (a = e.sourceLayer, o = e.nodeIndex, s = e.tensorIndex);
  28756. var l = a.inboundNodes[o];
  28757. if (-1 !== i.indexOf(l)) throw new RuntimeError("The tensor " + e.name + ' at layer "' + a.name + '" is part of a cycle.');
  28758. if (-1 === n.indexOf(l)) {
  28759. r.containerNodes.add(t.nodeKey(a, o)), (a.id in b) || (b[a.id] = Object.keys(b).length), -1 === i.indexOf(l) && i.push(l);
  28760. for (var u = l.inboundLayers.length, c = 0; c < u; c++) {
  28761. var p = l.inputTensors[c],
  28762. h = l.inboundLayers[c],
  28763. d = l.nodeIndices[c],
  28764. f = l.tensorIndices[c];
  28765. z(p, n, i, h, d, f);
  28766. }
  28767. for (n.push(l); i.indexOf(l) >= 0;) i.splice(i.indexOf(l), 1);
  28768. w.push(l);
  28769. }
  28770. }, S = [], A = [], _ = 0, I = r.outputs; _ < I.length; _++) {
  28771. var C = I[_];
  28772. z(C, S, A);
  28773. }
  28774. for (var E = 0, N = w.slice().reverse(); E < N.length; E++) {
  28775. m[(K = N[E]).id] = K, K.id in g || (g[K.id] = 0);
  28776. var k = g[K.id],
  28777. x = null == y[K.outboundLayer.id] ? 0 : y[K.outboundLayer.id];
  28778. k = Math.max(k, x), y[K.outboundLayer.id] = k, v[K.outboundLayer.id] = K.outboundLayer, g[K.id] = k;
  28779. for (h = 0; h < K.inboundLayers.length; h++) {
  28780. var L = K.inboundLayers[h],
  28781. T = (l = K.nodeIndices[h], L.inboundNodes[l]),
  28782. D = null == g[T.id] ? 0 : g[T.id];
  28783. g[T.id] = Math.max(k + 1, D), m[T.id] = T;
  28784. }
  28785. }
  28786. var O = {};
  28787. for (var R in g) {
  28788. (k = g[R]) in O || (O[k] = []), O[k].push(m[R]);
  28789. }
  28790. var M = {};
  28791. for (var P in y) {
  28792. (k = y[P]) in M || (M[k] = []), M[k].push(v[P]);
  28793. }
  28794. var F = Object.keys(M).map(function (e) {
  28795. return parseInt(e, 10);
  28796. }).sort(reverseNumberCompare);
  28797. r.layers = [];
  28798. for (var V = 0, B = F; V < B.length; V++) {
  28799. var U = M[k = B[V]];
  28800. U.sort(function (e, t) {
  28801. var n = b[e.id],
  28802. r = b[t.id];
  28803. return n < r ? -1 : n > r ? 1 : 0;
  28804. });
  28805. for (var j = 0, W = U; j < W.length; j++) {
  28806. (s = W[j]) instanceof t && r.internalContainerRefs.push(s), r.layers.push(s);
  28807. }
  28808. }
  28809. r.layersByDepth = M, F = Object.keys(O).map(function (e) {
  28810. return parseInt(e, 10);
  28811. }).sort(reverseNumberCompare);
  28812. for (var $ = r.inputs.slice(), q = [], G = 0, H = F; G < H.length; G++) for (var J = 0, Z = O[k = H[G]]; J < Z.length; J++) {
  28813. var K;
  28814. if (null != (s = (K = Z[J]).outboundLayer)) {
  28815. for (var Y = 0, X = K.inputTensors; Y < X.length; Y++) {
  28816. C = X[Y];
  28817. if (-1 === $.indexOf(C)) throw new RuntimeError("Graph disconnected: cannot obtain value for tensor " + C + ' at layer "' + s.name + '". The following previous layers were accessed without issue: ' + q);
  28818. }
  28819. for (var Q = 0, ee = K.outputTensors; Q < ee.length; Q++) {
  28820. C = ee[Q];
  28821. $.push(C);
  28822. }
  28823. q.push(s.name);
  28824. }
  28825. }
  28826. r.nodesByDepth = O;
  28827. for (var te = r.layers.map(function (e) {
  28828. return e.name;
  28829. }), ne = function (e) {
  28830. var t = te.filter(function (t) {
  28831. return t === e;
  28832. }).length;
  28833. if (1 !== t) throw new RuntimeError('The name "' + e + '" is used ' + t + " times in the model. All layer names should be unique. Layer names: " + JSON.stringify(te));
  28834. }, re = 0, ie = te; re < ie.length; re++) {
  28835. ne(ie[re]);
  28836. }
  28837. return r.outboundNodes = [], r.inboundNodes = [], new Node({
  28838. outboundLayer: r,
  28839. inboundLayers: [],
  28840. nodeIndices: [],
  28841. tensorIndices: [],
  28842. inputTensors: r.inputs,
  28843. outputTensors: r.outputs,
  28844. inputMasks: r.inputs.map(function (e) {
  28845. return null;
  28846. }),
  28847. outputMasks: r.outputs.map(function (e) {
  28848. return null;
  28849. }),
  28850. inputShapes: r.inputs.map(function (e) {
  28851. return e.shape;
  28852. }),
  28853. outputShapes: r.outputs.map(function (e) {
  28854. return e.shape;
  28855. })
  28856. }), r.built = !0, r._refCount = 1, r;
  28857. }
  28858. return __extends(t, e), t.prototype.assertNotDisposed = function () {
  28859. if (0 === this._refCount) throw new Error("Container '" + this.name + "' is already disposed.");
  28860. }, t.prototype.dispose = function () {
  28861. this.assertNotDisposed();
  28862. var e = {
  28863. refCountAfterDispose: null,
  28864. numDisposedVariables: 0
  28865. };
  28866. if (0 == --this._refCount) {
  28867. for (var t = 0, n = this.layers; t < n.length; t++) {
  28868. var r = n[t];
  28869. e.numDisposedVariables += r.dispose().numDisposedVariables;
  28870. }
  28871. for (var i = 0, a = this.internalContainerRefs; i < a.length; i++) {
  28872. var o = a[i];
  28873. e.numDisposedVariables += o.dispose().numDisposedVariables;
  28874. }
  28875. }
  28876. return e.refCountAfterDispose = this._refCount, e;
  28877. }, Object.defineProperty(t.prototype, "trainable", {
  28878. get: function () {
  28879. return this.trainable_;
  28880. },
  28881. set: function (e) {
  28882. this.layers.forEach(function (t) {
  28883. t._trainableWeights.forEach(function (t) {
  28884. return t.trainable = e;
  28885. });
  28886. }), this.trainable_ = e;
  28887. },
  28888. enumerable: !0,
  28889. configurable: !0
  28890. }), Object.defineProperty(t.prototype, "trainableWeights", {
  28891. get: function () {
  28892. if (this._trainableWeights.length > 0) throw new ValueError("Container instance unexpectedly contains _trainableWeights.The trainable weights of a Container are a union of the trainable weights of its consituent Layers. Its own _trainableWeights must remain an empty Array.");
  28893. if (!this.trainable) return [];
  28894. for (var e = [], t = 0, n = this.layers; t < n.length; t++) {
  28895. var r = n[t];
  28896. e = e.concat(r.trainableWeights);
  28897. }
  28898. return e;
  28899. },
  28900. enumerable: !0,
  28901. configurable: !0
  28902. }), Object.defineProperty(t.prototype, "nonTrainableWeights", {
  28903. get: function () {
  28904. for (var e = [], t = 0, n = this.layers; t < n.length; t++) {
  28905. var r = n[t];
  28906. e.push.apply(e, r.nonTrainableWeights);
  28907. }
  28908. if (!this.trainable) {
  28909. for (var i = [], a = 0, o = this.layers; a < o.length; a++) {
  28910. r = o[a];
  28911. i.push.apply(i, r.trainableWeights);
  28912. }
  28913. return i.concat(e);
  28914. }
  28915. return e;
  28916. },
  28917. enumerable: !0,
  28918. configurable: !0
  28919. }), Object.defineProperty(t.prototype, "weights", {
  28920. get: function () {
  28921. return this.trainableWeights.concat(this.nonTrainableWeights);
  28922. },
  28923. enumerable: !0,
  28924. configurable: !0
  28925. }), t.prototype.loadWeights = function (e, t) {
  28926. void 0 === t && (t = !0);
  28927. for (var n = {}, r = 0, i = 0, a = this.layers; i < a.length; i++) for (var o = 0, s = a[i].weights; o < s.length; o++) {
  28928. var l = s[o];
  28929. if (null != n[l.originalName]) throw new ValueError("Duplicate weight name: " + l.originalName);
  28930. n[l.originalName] = l, r++;
  28931. }
  28932. var u = [];
  28933. for (var c in e) {
  28934. if (null != n[c]) u.push([n[c], e[c]]); else if (t) throw new ValueError("Provided weight data has no target variable: " + c);
  28935. delete n[c];
  28936. }
  28937. if (t) {
  28938. var p = [];
  28939. for (var h in n) p.push(h);
  28940. if (p.length > 0) throw new ValueError(p.length + " of " + r + " weights are not set: " + p);
  28941. }
  28942. batchSetValue(u);
  28943. }, t.prototype.updatedConfig = function () {
  28944. var e = this.getConfig(),
  28945. t = {};
  28946. return t.className = this.getClassName(), t.config = e, t.kerasVersion = "tfjs-layers " + version, t.backend = "TensorFlow.js", t;
  28947. }, t.prototype.toJSON = function (e, t) {
  28948. void 0 === t && (t = !0);
  28949. var n = convertTsToPythonic(this.updatedConfig());
  28950. return t ? JSON.stringify(n) : n;
  28951. }, t.prototype.call = function (e, t) {
  28952. var n = this;
  28953. return (0, _tfjsCore.tidy)(function () {
  28954. e = toList(e);
  28955. for (var r = new FeedDict(), i = 0; i < n.inputs.length; ++i) r.add(n.inputs[i], e[i]);
  28956. return execute(n.outputs, r, t);
  28957. });
  28958. }, t.prototype.computeMask = function (e, t) {
  28959. var n = this;
  28960. return (0, _tfjsCore.tidy)(function () {
  28961. var r;
  28962. return e = toList(e), r = null == t ? pyListRepeat(null, e.length) : toList(t), n.runInternalGraph(e, r)[1];
  28963. });
  28964. }, t.prototype.computeOutputShape = function (e) {
  28965. var t = normalizeShapeList(e);
  28966. if (t.length !== this.inputLayers.length) throw new ValueError("Invalid inputShape argument " + e + ": model has " + this.inputLayers.length + " tensor inputs.");
  28967. for (var n = {}, r = 0; r < t.length; r++) {
  28968. var i = this.inputLayers[r],
  28969. a = t[r];
  28970. n[A = i.name + "_0_0"] = a;
  28971. }
  28972. var o = Object.keys(this.nodesByDepth).map(function (e) {
  28973. return parseInt(e, 10);
  28974. }).sort(reverseNumberCompare);
  28975. if (o.length > 1) for (var s = 0, l = o; s < l.length; s++) for (var u = l[s], c = 0, p = this.nodesByDepth[u]; c < p.length; c++) {
  28976. var h = p[c];
  28977. i = h.outboundLayer;
  28978. if (-1 === this.inputLayers.map(function (e) {
  28979. return e.id;
  28980. }).indexOf(i.id)) {
  28981. for (var d = [], f = 0; f < h.inboundLayers.length; f++) {
  28982. var g = h.inboundLayers[f],
  28983. m = h.nodeIndices[f],
  28984. y = h.tensorIndices[f],
  28985. v = n[A = g.name + "_" + m + "_" + y];
  28986. d.push(v);
  28987. }
  28988. var b = normalizeShapeList(i.computeOutputShape(singletonOrArray(d))),
  28989. w = i.inboundNodes.indexOf(h);
  28990. for (f = 0; f < b.length; f++) {
  28991. n[A = i.name + "_" + w + "_" + f] = b[f];
  28992. }
  28993. }
  28994. }
  28995. var z = [],
  28996. S = [];
  28997. for (r = 0; r < this.outputLayers.length; r++) {
  28998. i = this.outputLayers[r], w = this.outputLayersNodeIndices[r], y = this.outputLayersTensorIndices[r];
  28999. var A = i.name + "_" + w + "_" + y;
  29000. S.push(A);
  29001. }
  29002. for (r = 0; r < S.length; r++) {
  29003. var _ = S[r];
  29004. assert(_ in n), z.push(n[_]);
  29005. }
  29006. return singletonOrArray(z);
  29007. }, t.prototype.runInternalGraph = function (e, t) {
  29008. null == t && (t = pyListRepeat(null, e.length));
  29009. for (var n = {}, r = 0; r < this.inputs.length; ++r) {
  29010. var i = this.inputs[r],
  29011. a = e[r],
  29012. o = t[r];
  29013. n[i.id] = [a, o];
  29014. }
  29015. for (var s = 0, l = Object.keys(this.nodesByDepth).map(function (e) {
  29016. return parseInt(e, 10);
  29017. }).sort(reverseNumberCompare); s < l.length; s++) for (var u = l[s], c = 0, p = this.nodesByDepth[u]; c < p.length; c++) {
  29018. for (var h = p[c], d = h.outboundLayer, f = h.inputTensors, g = h.outputTensors, m = new Array(), y = 0, v = f; y < v.length; y++) {
  29019. (i = v[y]).id in n && m.push(n[i.id]);
  29020. }
  29021. if (m.length === f.length) {
  29022. var b = {},
  29023. w = void 0,
  29024. z = void 0,
  29025. S = void 0,
  29026. A = void 0;
  29027. if (null != h.callArgs && (b = h.callArgs), 1 === m.length) {
  29028. var _ = m[0],
  29029. I = _[0],
  29030. C = _[1];
  29031. null == b.mask && (b.mask = C), S = toList(d.call(I, b)), A = toList(d.computeMask(I, C)), w = [I], z = [C];
  29032. } else w = m.map(function (e) {
  29033. return e[0];
  29034. }), z = m.map(function (e) {
  29035. return e[1];
  29036. }), null == b.mask && (b.mask = z), S = toList(d.call(w, b)), A = toList(d.computeMask(w, z));
  29037. if (d.activityRegularizer) throw new NotImplementedError("LayersModel invocation with concrete Tensor value(s) in the presence of activity regularizer(s) is not supported yet.");
  29038. for (r = 0; r < g.length; ++r) {
  29039. i = g[r], a = S[r], o = A[r];
  29040. n[i.id] = [a, o];
  29041. }
  29042. }
  29043. }
  29044. for (var E = [], N = [], k = [], x = 0, L = this.outputs; x < L.length; x++) {
  29045. assert((i = L[x]).id in n, "Could not compute output " + i.name + " : " + i.id);
  29046. var T = n[i.id],
  29047. D = T[0];
  29048. o = T[1];
  29049. k.push(D.shape), E.push(D), N.push(o);
  29050. }
  29051. return [E, N, k];
  29052. }, t.prototype.buildNodeConversionMap = function (e) {
  29053. for (var n, r = {}, i = 0, a = this.layers; i < a.length; i++) {
  29054. var o = a[i];
  29055. n = o instanceof t ? 1 : 0;
  29056. for (var s = 0; s < o.inboundNodes.length; s++) {
  29057. var l = t.nodeKey(o, s);
  29058. this.containerNodes.has(l) && (r[l] = n, n += 1);
  29059. }
  29060. }
  29061. return r;
  29062. }, t.prototype.getLayer = function (e, t) {
  29063. if (null != t) {
  29064. if (this.layers.length <= t) throw new ValueError("Was asked to retrieve layer at index " + t + ", but model only has " + this.layers.length + " layer(s).");
  29065. return this.layers[t];
  29066. }
  29067. if (null == e) throw new ValueError("Provide either a layer name or layer index");
  29068. for (var n = 0, r = this.layers; n < r.length; n++) {
  29069. var i = r[n];
  29070. if (i.name === e) return i;
  29071. }
  29072. throw new ValueError("No such layer: " + e);
  29073. }, t.prototype.calculateLosses = function () {
  29074. var e = this;
  29075. return (0, _tfjsCore.tidy)(function () {
  29076. for (var n = [], r = 0, i = e.layers; r < i.length; r++) for (var a = i[r], o = 0; o < a.inboundNodes.length; ++o) {
  29077. var s = t.nodeKey(a, o);
  29078. e.containerNodes.has(s) && n.push.apply(n, a.calculateLosses());
  29079. }
  29080. return n;
  29081. });
  29082. }, t.prototype.getConfig = function () {
  29083. for (var e = {
  29084. name: this.name
  29085. }, n = this.buildNodeConversionMap(this.layers), r = [], i = 0, a = this.layers; i < a.length; i++) {
  29086. for (var o = (w = a[i]).getClassName(), s = w.getConfig(), l = [], u = 0; u < w.inboundNodes.length; u++) {
  29087. var c = w.inboundNodes[u],
  29088. p = t.nodeKey(w, u),
  29089. h = {};
  29090. if (this.containerNodes.has(p)) {
  29091. if (c.callArgs) try {
  29092. JSON.stringify(c.callArgs), h = c.callArgs;
  29093. } catch (e) {
  29094. console.warn("Layer " + w.name + " was passed non-serializable keyword arguments: " + c.callArgs + ". They will not be included in the serialized model (and thus will be missing at deserialization time)."), h = {};
  29095. }
  29096. if (c.inboundLayers.length > 0) {
  29097. for (var d = [], f = 0; f < c.inboundLayers.length; f++) {
  29098. var g = c.inboundLayers[f],
  29099. m = c.nodeIndices[f],
  29100. y = c.tensorIndices[f];
  29101. null == (S = n[t.nodeKey(g, m)]) && (S = 0), d.push([g.name, S, y, h]);
  29102. }
  29103. l.push(d);
  29104. }
  29105. }
  29106. }
  29107. var v = {};
  29108. v.name = w.name, v.className = o, v.config = s, v.inboundNodes = l, r.push(v);
  29109. }
  29110. e.layers = r;
  29111. var b = [];
  29112. for (f = 0; f < this.inputLayers.length; f++) {
  29113. var w = this.inputLayers[f];
  29114. m = this.inputLayersNodeIndices[f], p = t.nodeKey(w, m);
  29115. if (this.containerNodes.has(p)) {
  29116. null !== (S = n[p]) && void 0 !== S || (S = 0);
  29117. y = this.inputLayersTensorIndices[f];
  29118. b.push([w.name, S, y]);
  29119. }
  29120. }
  29121. e.inputLayers = b;
  29122. var z = [];
  29123. for (f = 0; f < this.outputLayers.length; f++) {
  29124. w = this.outputLayers[f], m = this.outputLayersNodeIndices[f], p = t.nodeKey(w, m);
  29125. if (this.containerNodes.has(p)) {
  29126. var S;
  29127. null !== (S = n[p]) && void 0 !== S || (S = 0);
  29128. y = this.outputLayersTensorIndices[f];
  29129. z.push([w.name, S, y]);
  29130. }
  29131. }
  29132. return e.outputLayers = z, e;
  29133. }, t.fromConfig = function (e, t, n, r) {
  29134. void 0 === n && (n = {}), void 0 === r && (r = !1);
  29135. var i = {},
  29136. a = {};
  29137. function o(e, t) {
  29138. e.name in a ? a[e.name].push(t) : a[e.name] = [t];
  29139. }
  29140. function s(e, t) {
  29141. for (var n, r = [], a = 0, s = t; a < s.length; a++) {
  29142. var l = s[a],
  29143. u = l[0],
  29144. c = l[1],
  29145. p = l[2];
  29146. if (n = null == l[3] ? {} : l[3], !(u in i)) return void o(e, t);
  29147. var h = i[u];
  29148. if (h.inboundNodes.length <= c) return void o(e, t);
  29149. var d = h.inboundNodes[c];
  29150. r.push(d.outputTensors[p]);
  29151. }
  29152. r.length > 0 && e.apply(singletonOrArray(r), n);
  29153. }
  29154. function l(e) {
  29155. var n = e.name,
  29156. a = deserialize(e, null != t.customObjects ? t.customObjects : {});
  29157. a.setFastWeightInitDuringBuild(r), i[n] = a, e.inboundNodes.forEach(function (e) {
  29158. if (!(e instanceof Array)) throw new ValueError("Corrupted configuration, expected array for nodeData: " + e);
  29159. o(a, e);
  29160. });
  29161. }
  29162. for (var u = t.name, c = t.layers, p = 0, h = c; p < h.length; p++) {
  29163. l(g = h[p]);
  29164. }
  29165. for (; !isObjectEmpty(a);) for (var d = 0, f = c; d < f.length; d++) {
  29166. var g = f[d];
  29167. if ((k = i[g.name]).name in a) {
  29168. var m = a[k.name];
  29169. delete a[k.name];
  29170. for (var y = 0, v = m; y < v.length; y++) {
  29171. s(k, v[y]);
  29172. }
  29173. }
  29174. }
  29175. for (var b = [], w = [], z = 0, S = t.inputLayers; z < S.length; z++) {
  29176. var A = (g = S[z])[0],
  29177. _ = g[1],
  29178. I = g[2];
  29179. assert(A in i);
  29180. var C = (k = i[A]).inboundNodes[_].outputTensors;
  29181. b.push(C[I]);
  29182. }
  29183. for (var E = 0, N = t.outputLayers; E < N.length; E++) {
  29184. A = (g = N[E])[0], _ = g[1], I = g[2];
  29185. assert(A in i);
  29186. var k;
  29187. C = (k = i[A]).inboundNodes[_].outputTensors;
  29188. w.push(C[I]);
  29189. }
  29190. return new e({
  29191. inputs: b,
  29192. outputs: w,
  29193. name: u
  29194. });
  29195. }, Object.defineProperty(t.prototype, "stateful", {
  29196. get: function () {
  29197. if (this._stateful) throw new ValueError("Container instance unexpectedly has _stateful = true. The statefulness of a Container is determined by the Layers it contains. Its _stateful property must remain the default false.");
  29198. for (var e = 0, t = this.layers; e < t.length; e++) {
  29199. if (t[e].stateful) return !0;
  29200. }
  29201. return !1;
  29202. },
  29203. enumerable: !0,
  29204. configurable: !0
  29205. }), t.prototype.resetStates = function () {
  29206. var e = this;
  29207. (0, _tfjsCore.tidy)(function () {
  29208. e.layers.forEach(function (e) {
  29209. e.stateful && e.resetStates();
  29210. });
  29211. });
  29212. }, t;
  29213. }(Layer);
  29214. function standardizeSampleOrClassWeights(e, t, n) {
  29215. var r = t.length;
  29216. if (null == e || Array.isArray(e) && 0 === e.length) return t.map(function (e) {
  29217. return null;
  29218. });
  29219. if (1 === r) return Array.isArray(e) && 1 === e.length ? e : "object" == typeof e && t[0] in e ? [e[t[0]]] : [e];
  29220. if (Array.isArray(e)) {
  29221. if (e.length !== r) throw new Error("Provided " + n + " is an array of " + e.length + " element(s), but the model has " + r + " outputs. Make sure a set of weights is provided for each model output.");
  29222. return e;
  29223. }
  29224. if ("object" == typeof e && Object.keys(e).length > 0 && "object" == typeof e[Object.keys(e)[0]]) {
  29225. var i = [];
  29226. return t.forEach(function (t) {
  29227. t in e ? i.push(e[t]) : i.push(null);
  29228. }), i;
  29229. }
  29230. throw new Error("The model has multiple (" + r + ") outputs, so " + n + " must be either an array with " + r + " elements or an object with " + t + " keys. Provided " + n + " not understood: " + JSON.stringify(e));
  29231. }
  29232. function standardizeClassWeights(e, t) {
  29233. return standardizeSampleOrClassWeights(e, t, "classWeight");
  29234. }
  29235. function standardizeWeights(e, t, n, r) {
  29236. return __awaiter(this, void 0, void 0, function () {
  29237. var i, a, o, s, l;
  29238. return __generator(this, function (u) {
  29239. switch (u.label) {
  29240. case 0:
  29241. if (null != t || null != r) throw new Error("Support sampleWeight is not implemented yet");
  29242. return null == n ? [3, 2] : (i = (0, _tfjsCore.tidy)(function () {
  29243. if (1 === e.shape.length) return e.clone();
  29244. if (2 === e.shape.length) {
  29245. if (e.shape[1] > 1) {
  29246. return e.argMax(1);
  29247. }
  29248. if (1 === e.shape[1]) return e.reshape([e.shape[0]]);
  29249. throw new Error("Encountered unexpected last-dimension size (" + e.shape[1] + ") during handling of class weights. The size is expected to be >= 1.");
  29250. }
  29251. throw new Error("Unexpected rank of target (y) tensor (" + e.rank + ") during handling of class weights. The rank is expected to be 1 or 2.");
  29252. }), s = (o = Array).from, [4, i.data()]);
  29253. case 1:
  29254. return a = s.apply(o, [u.sent()]), (0, _tfjsCore.dispose)(i), l = [], a.forEach(function (e) {
  29255. if (null == n[e]) throw new Error("classWeight must contain all classes in the training data. The class " + e + " exists in the data but not in classWeight");
  29256. l.push(n[e]);
  29257. }), [2, (0, _tfjsCore.tensor1d)(l, "float32")];
  29258. case 2:
  29259. return [2, null];
  29260. }
  29261. });
  29262. });
  29263. }
  29264. function computeWeightedLoss(e, t) {
  29265. return (0, _tfjsCore.mul)(e, t);
  29266. }
  29267. var DEFAULT_VALIDATION_BATCH_SIZE = 32;
  29268. function standardizeDataIteratorOutput(e, t) {
  29269. var n,
  29270. r,
  29271. i = t;
  29272. n = i.xs, r = i.ys, _tfjsCore.util.assert(null != n && null != r, function () {
  29273. return "A Dataset iterator for fitDataset() is expected to generate objects of the form `{xs: xVal, ys: yVal}`, where the two values may be `tf.Tensor`, an array of Tensors, or a map of string to Tensor. The provided Dataset instead generates " + t;
  29274. });
  29275. var a = flattenTensorOrArrayOrMap("input", e.inputNames, n),
  29276. o = flattenTensorOrArrayOrMap("output", e.outputNames, r),
  29277. s = a[0].shape[0];
  29278. _tfjsCore.util.assert(a.length === e.inputs.length, function () {
  29279. return "LayersModel has " + e.inputs.length + " inputs, but the dataset provides " + a.length + " inputs. (Expected input keys: " + JSON.stringify(e.inputNames) + ")";
  29280. }), _tfjsCore.util.assert(o.length === e.outputs.length, function () {
  29281. return "LayersModel has " + e.outputs.length + " outputs, but the dataset provides " + o.length + " outputs. (Expected output keys: " + JSON.stringify(e.outputNames) + ")";
  29282. });
  29283. var l = function (t) {
  29284. _tfjsCore.util.assert(a[t].shape[0] === s, function () {
  29285. return "Batch size mismatch: input " + e.inputNames[t] + " has " + a[t].shape[0] + "; expected " + s + " based on input " + e.inputNames[0] + ".";
  29286. });
  29287. };
  29288. for (var u in a) l(u);
  29289. var c = function (t) {
  29290. _tfjsCore.util.assert(o[t].shape[0] === s, function () {
  29291. return "Batch size mismatch: output " + e.outputNames[t] + " has " + o[t].shape[0] + "; expected " + s + " based on input " + e.inputNames[0] + ".";
  29292. });
  29293. };
  29294. for (var p in o) c(p);
  29295. return {
  29296. xs: a,
  29297. ys: o
  29298. };
  29299. }
  29300. function flattenTensorOrArrayOrMap(e, t, n) {
  29301. if (n instanceof _tfjsCore.Tensor) return [n];
  29302. if (Array.isArray(n)) return _tfjsCore.util.assert(n.length === t.length, function () {
  29303. return "Received an array of " + n.length + " Tensors, but expected " + t.length + " to match the " + e + " keys " + t + ".";
  29304. }), n;
  29305. for (var r = [], i = 0, a = t; i < a.length; i++) {
  29306. var o = a[i];
  29307. if (null == n[o]) throw new ValueError("The feature data generated by the dataset lacks the required " + e + " key '" + o + "'.");
  29308. r.push(n[o]);
  29309. }
  29310. return r;
  29311. }
  29312. function standardizeTensorValidationData(e) {
  29313. if (3 === e.length) throw new NotImplementedError("Validation with sample weights is not implemented yet.");
  29314. return {
  29315. xs: e[0],
  29316. ys: e[1]
  29317. };
  29318. }
  29319. function fitDataset(e, t, n) {
  29320. return __awaiter(this, void 0, void 0, function () {
  29321. var r, i, a, o, s, l, u, c, p, h, d, f, g, m, y, v, b, w, z, S, A, _, I, C, E, N, k, x, L, T, D, O, R, M;
  29322. return __generator(this, function (P) {
  29323. switch (P.label) {
  29324. case 0:
  29325. if (r = null != n.batchesPerEpoch, _tfjsCore.util.assert(null != e.optimizer, function () {
  29326. return "You must compile a model before training/testing. Use LayersModel.compile(modelCompileConfig).";
  29327. }), _tfjsCore.util.assert(null != n, function () {
  29328. return "For fitDataset(), the 2nd argument (config) is required, but it is not provided in this call.";
  29329. }), _tfjsCore.util.assert(null != n.epochs && n.epochs > 0 && Number.isInteger(n.epochs), function () {
  29330. return "For fitDataset(), config.epochs is expected to be a positive integer, but got " + n.epochs;
  29331. }), _tfjsCore.util.assert(!r || n.batchesPerEpoch > 0 && Number.isInteger(n.batchesPerEpoch), function () {
  29332. return "For fitDataset(), config.batchesPerEpoch is expected to be a positive integer if specified, but got " + n.batchesPerEpoch;
  29333. }), _tfjsCore.util.assert(null == n.validationSplit, function () {
  29334. return "`validationSplit` is not supported by `fitDataset()`. Use validationData instead.";
  29335. }), e.isTraining) throw new Error("Cannot start training because another fit() call is ongoing.");
  29336. e.isTraining = !0, P.label = 1;
  29337. case 1:
  29338. return P.trys.push([1, , 26, 27]), i = null != n.validationData, a = void 0, o = void 0, i && (isDatasetObject(n.validationData) ? _tfjsCore.util.assert(null == n.validationBatches || n.validationBatches > 0 && Number.isInteger(n.validationBatches), function () {
  29339. return "For fitDataset() with dataset-based validation, config.validationBatches is expected not to be provided, or to be a positive integer, but got " + n.validationBatches;
  29340. }) : (s = standardizeTensorValidationData(n.validationData), a = s.xs, o = s.ys)), l = e.makeTrainFunction(), u = e.getDedupedMetricsNames(), c = void 0, c = i ? u.slice().concat(u.map(function (e) {
  29341. return "val_" + e;
  29342. })) : u.slice(), p = standardizeCallbacks(n.callbacks, n.yieldEvery), h = null == n.verbose ? 1 : n.verbose, d = configureCallbacks(p, h, n.epochs, null, null, getStepsPerEpoch(t, n), null, i, c), f = d.callbackList, g = d.history, f.setModel(e), e.history = g, [4, f.onTrainBegin()];
  29343. case 2:
  29344. return P.sent(), e.stopTraining_ = !1, m = null == n.initialEpoch ? 0 : n.initialEpoch, [4, t.iterator()];
  29345. case 3:
  29346. y = P.sent(), P.label = 4;
  29347. case 4:
  29348. return m < n.epochs ? (v = {}, [4, f.onEpochBegin(m)]) : [3, 23];
  29349. case 5:
  29350. return P.sent(), b = 0, w = 0, r ? [3, 7] : [4, t.iterator()];
  29351. case 6:
  29352. y = P.sent(), P.label = 7;
  29353. case 7:
  29354. return !r || b < n.batchesPerEpoch ? [4, y.next()] : [3, 21];
  29355. case 8:
  29356. return z = P.sent(), r && z.done ? (console.warn("You provided `batchesPerEpoch` as " + n.batchesPerEpoch + ", but your dataset iterator ran out of data after " + b + " batches; interrupting training. Make sure that your dataset can generate at least `batchesPerEpoch * epochs` batches (in this case, " + n.batchesPerEpoch * n.epochs + " batches). You may need to use the repeat() function when building your dataset."), [3, 21]) : null == z.value ? [3, 15] : (S = standardizeDataIteratorOutput(e, z.value), A = S.xs, _ = S.ys, (I = {}).batch = w, I.size = A[0].shape[0], [4, f.onBatchBegin(w, I)]);
  29357. case 9:
  29358. if (P.sent(), C = [], null == n.classWeight) return [3, 13];
  29359. E = standardizeClassWeights(n.classWeight, e.outputNames), M = 0, P.label = 10;
  29360. case 10:
  29361. return M < E.length ? (k = (N = C).push, [4, standardizeWeights(_[M], null, E[M])]) : [3, 13];
  29362. case 11:
  29363. k.apply(N, [P.sent()]), P.label = 12;
  29364. case 12:
  29365. return ++M, [3, 10];
  29366. case 13:
  29367. for (x = A.concat(_).concat(C), L = l(x), (0, _tfjsCore.dispose)(x), M = 0; M < u.length; ++M) T = u[M], D = L[M], I[T] = D, (0, _tfjsCore.keep)(D);
  29368. return [4, f.onBatchEnd(w, I)];
  29369. case 14:
  29370. P.sent(), disposeTensorsInLogs(I), w++, b++, P.label = 15;
  29371. case 15:
  29372. return (r ? b >= n.batchesPerEpoch : z.done) ? i ? (O = void 0, isDatasetObject(n.validationData) ? (R = toList, [4, e.evaluateDataset(n.validationData, {
  29373. batches: n.validationBatches
  29374. })]) : [3, 17]) : [3, 19] : [3, 20];
  29375. case 16:
  29376. return O = R.apply(void 0, [P.sent()]), [3, 18];
  29377. case 17:
  29378. O = toList(e.evaluate(a, o, {
  29379. batchSize: null == n.validationBatchSize ? DEFAULT_VALIDATION_BATCH_SIZE : n.validationBatchSize,
  29380. verbose: 0
  29381. })), P.label = 18;
  29382. case 18:
  29383. for (M = 0; M < e.metricsNames.length; ++M) v["val_" + e.metricsNames[M]] = O[M];
  29384. P.label = 19;
  29385. case 19:
  29386. return [3, 21];
  29387. case 20:
  29388. return e.stopTraining_ ? [3, 21] : [3, 7];
  29389. case 21:
  29390. return [4, f.onEpochEnd(m, v)];
  29391. case 22:
  29392. return P.sent(), m++, e.stopTraining_ ? [3, 23] : [3, 4];
  29393. case 23:
  29394. return [4, f.onTrainEnd()];
  29395. case 24:
  29396. return P.sent(), [4, e.history.syncData()];
  29397. case 25:
  29398. return P.sent(), [2, e.history];
  29399. case 26:
  29400. return e.isTraining = !1, [7];
  29401. case 27:
  29402. return [2];
  29403. }
  29404. });
  29405. });
  29406. }
  29407. function getStepsPerEpoch(e, t) {
  29408. var n = null;
  29409. return null != t.batchesPerEpoch ? n = t.batchesPerEpoch : Number.isFinite(e.size) && (n = e.size), n;
  29410. }
  29411. function isDatasetObject(e) {
  29412. return "function" == typeof e.iterator;
  29413. }
  29414. function isLazyIteratorObject(e) {
  29415. return "function" == typeof e.next;
  29416. }
  29417. function evaluateDataset(e, t, n) {
  29418. return __awaiter(this, void 0, void 0, function () {
  29419. var r, i, a, o, s, l, u, c, p, h;
  29420. return __generator(this, function (d) {
  29421. switch (d.label) {
  29422. case 0:
  29423. if (r = null != (n = n || {}).batches, i = e.testFunction, a = [], n.verbose > 0) throw new NotImplementedError("Verbose mode is not implemented yet.");
  29424. return _tfjsCore.util.assert(!r || n.batches > 0 && Number.isInteger(n.batches), function () {
  29425. return "Test loop expects `batches` to be a positive integer, but received " + JSON.stringify(n.batches);
  29426. }), isLazyIteratorObject(t) ? (s = t, [3, 3]) : [3, 1];
  29427. case 1:
  29428. return [4, t.iterator()];
  29429. case 2:
  29430. s = d.sent(), d.label = 3;
  29431. case 3:
  29432. o = s, l = 0, u = 0, c = function () {
  29433. var t;
  29434. return __generator(this, function (s) {
  29435. switch (s.label) {
  29436. case 0:
  29437. return [4, o.next()];
  29438. case 1:
  29439. return t = s.sent(), a = (0, _tfjsCore.tidy)(function () {
  29440. if (t.value) {
  29441. var n = standardizeDataIteratorOutput(e, t.value),
  29442. r = n.xs,
  29443. o = n.ys,
  29444. s = r.concat(o),
  29445. c = (0, _tfjsCore.tidy)(function () {
  29446. return i(s);
  29447. });
  29448. if ((0, _tfjsCore.dispose)(s), 0 === u) for (var p = 0; p < c.length; ++p) a.push((0, _tfjsCore.scalar)(0));
  29449. var h = s[0].shape[0],
  29450. d = function (e) {
  29451. var t = c[e],
  29452. n = a[e];
  29453. a[e] = (0, _tfjsCore.tidy)(function () {
  29454. return (0, _tfjsCore.add)(a[e], (0, _tfjsCore.mul)(h, t));
  29455. }), u > 0 && (0, _tfjsCore.dispose)(n);
  29456. };
  29457. for (p = 0; p < c.length; ++p) d(p);
  29458. (0, _tfjsCore.dispose)(c), l += h, ++u;
  29459. }
  29460. return a;
  29461. }), t.done ? (r && console.warn("Your dataset iterator ran out of data during evaluateDataset(). Interrupting evalution. Make sure that your dataset can generate at least `batches` batches (in this case, " + n.batches + " batches). You may need to use the repeat() function when building your dataset."), [2, "break"]) : [2];
  29462. }
  29463. });
  29464. }, d.label = 4;
  29465. case 4:
  29466. return !r || u < n.batches ? [5, c()] : [3, 6];
  29467. case 5:
  29468. return "break" === d.sent() ? [3, 6] : [3, 4];
  29469. case 6:
  29470. for (p = 0; p < a.length; ++p) h = a[p], a[p] = (0, _tfjsCore.div)(a[p], l), (0, _tfjsCore.dispose)(h);
  29471. return [2, singletonOrArray(a)];
  29472. }
  29473. });
  29474. });
  29475. }
  29476. function checkBatchSize(e) {
  29477. _tfjsCore.util.assert(e > 0 && Number.isInteger(e), function () {
  29478. return "batchSize is required to be a positive integer, but got " + e;
  29479. });
  29480. }
  29481. function sliceArrays(e, t, n) {
  29482. return null == e ? [null] : Array.isArray(e) ? e.map(function (e) {
  29483. return sliceAlongFirstAxis(e, t, n - t);
  29484. }) : sliceAlongFirstAxis(e, t, n - t);
  29485. }
  29486. function sliceArraysByIndices(e, t) {
  29487. return (0, _tfjsCore.tidy)(function () {
  29488. return null == e ? null : Array.isArray(e) ? e.map(function (e) {
  29489. return sliceArraysByIndices(e, t);
  29490. }) : gather$1(e, "int32" === t.dtype ? t : t.toInt());
  29491. });
  29492. }
  29493. function makeBatches(e, t) {
  29494. for (var n = [], r = 0, i = null; r < e;) (i = r + t) >= e && (i = e), n.push([r, i]), r = i;
  29495. return n;
  29496. }
  29497. function fitLoop(e, t, n, r, i, a, o, s, l, u, c, p, h, d, f) {
  29498. return __awaiter(this, void 0, void 0, function () {
  29499. var g, m, y, v, b, w, z, S;
  29500. return __generator(this, function (A) {
  29501. switch (A.label) {
  29502. case 0:
  29503. if (null == i && (i = 32), null == a && (a = 1), null == c && (c = !0), null == h && (h = 0), g = !1, null != l && null != u && (g = !0), null != f && (g = !0, null == d)) throw new ValueError("Can only use `validationSteps` when doing step-wise training, i.e., `stepsPerEpoch` must be set.");
  29504. return null != (m = e.checkNumSamples(n, i, d, "steps_per_epoch")) && (y = range(0, m)), null == o && (o = 1), v = configureCallbacks(s, o, a, h, m, d, i, g, p), b = v.callbackList, w = v.history, b.setModel(e), e.history = w, [4, b.onTrainBegin()];
  29505. case 1:
  29506. A.sent(), e.stopTraining_ = !1, z = function (a) {
  29507. var o, s, p, h, f;
  29508. return __generator(this, function (v) {
  29509. switch (v.label) {
  29510. case 0:
  29511. return [4, b.onEpochBegin(a)];
  29512. case 1:
  29513. if (v.sent(), o = {}, null == d) return [3, 2];
  29514. throw new NotImplementedError("stepsPerEpoch mode is not implemented yet.");
  29515. case 2:
  29516. if ("batch" === c) throw new NotImplementedError("batch shuffling is not implemneted yet");
  29517. c && _tfjsCore.util.shuffle(y), s = (0, _tfjsCore.tensor1d)(y), p = makeBatches(m, i), h = function (a) {
  29518. var c;
  29519. return __generator(this, function (h) {
  29520. switch (h.label) {
  29521. case 0:
  29522. return c = {}, [4, b.onBatchBegin(a, c)];
  29523. case 1:
  29524. return h.sent(), (0, _tfjsCore.tidy)(function () {
  29525. var h = p[a][0],
  29526. d = p[a][1],
  29527. f = sliceAlongFirstAxis(s, h, d - h);
  29528. c.batch = a, c.size = d - h;
  29529. for (var m = sliceArraysByIndices(n, f), y = t(m), v = 0; v < r.length; ++v) {
  29530. var b = r[v],
  29531. w = y[v];
  29532. c[b] = w, (0, _tfjsCore.keep)(w);
  29533. }
  29534. if (a === p.length - 1 && g) {
  29535. var z = e.testLoop(l, u, i);
  29536. for (v = 0; v < r.length; ++v) {
  29537. b = r[v], w = z[v];
  29538. (0, _tfjsCore.keep)(w), o["val_" + b] = w;
  29539. }
  29540. }
  29541. }), [4, b.onBatchEnd(a, c)];
  29542. case 2:
  29543. return h.sent(), disposeTensorsInLogs(c), e.stopTraining_ ? [2, "break"] : [2];
  29544. }
  29545. });
  29546. }, f = 0, v.label = 3;
  29547. case 3:
  29548. return f < p.length ? [5, h(f)] : [3, 6];
  29549. case 4:
  29550. if ("break" === v.sent()) return [3, 6];
  29551. v.label = 5;
  29552. case 5:
  29553. return ++f, [3, 3];
  29554. case 6:
  29555. s.dispose(), v.label = 7;
  29556. case 7:
  29557. return [4, b.onEpochEnd(a, o)];
  29558. case 8:
  29559. return v.sent(), e.stopTraining_ ? [2, "break"] : [2];
  29560. }
  29561. });
  29562. }, S = h, A.label = 2;
  29563. case 2:
  29564. return S < a ? [5, z(S)] : [3, 5];
  29565. case 3:
  29566. if ("break" === A.sent()) return [3, 5];
  29567. A.label = 4;
  29568. case 4:
  29569. return ++S, [3, 2];
  29570. case 5:
  29571. return [4, b.onTrainEnd()];
  29572. case 6:
  29573. return A.sent(), [4, e.history.syncData()];
  29574. case 7:
  29575. return A.sent(), [2, e.history];
  29576. }
  29577. });
  29578. });
  29579. }
  29580. function fitTensors(e, t, n, r) {
  29581. return void 0 === r && (r = {}), __awaiter(this, void 0, void 0, function () {
  29582. var i, a, o, s, l, u, c, p, h, d, f, g, m, y, v, b, w, z, S, A, _, I;
  29583. return __generator(this, function (C) {
  29584. switch (C.label) {
  29585. case 0:
  29586. if (e.isTraining) throw new Error("Cannot start training because another fit() call is ongoing.");
  29587. e.isTraining = !0, C.label = 1;
  29588. case 1:
  29589. return C.trys.push([1, , 7, 8]), checkBatchSize(p = null == r.batchSize ? 32 : r.batchSize), h = !1, [4, e.standardizeUserData(t, n, r.sampleWeight, r.classWeight, h, p)];
  29590. case 2:
  29591. if (d = C.sent(), i = d[0], a = d[1], c = d[2], f = !1, g = void 0, !(null != r.validationData && r.validationData.length > 0)) return [3, 4];
  29592. if (f = !0, 2 !== r.validationData.length) throw 3 === r.validationData.length ? new NotImplementedError("validationData including sample weights is not supported yet.") : new ValueError("When passing validation data, it must contain 2 (valX, valY) or 3 (valX, valY, valSampleWeight) items; " + r.validationData + " is invalid.");
  29593. return o = r.validationData[0], s = r.validationData[1], m = !0, [4, e.standardizeUserData(o, s, null, null, m, p)];
  29594. case 3:
  29595. return y = C.sent(), l = y[0], u = y[1], g = l.concat(u), [3, 5];
  29596. case 4:
  29597. null != r.validationSplit && r.validationSplit > 0 && r.validationSplit < 1 ? (f = !0, v = Math.floor(i[0].shape[0] * (1 - r.validationSplit)), b = i[0].shape[0], l = sliceArrays(i, v, b), i = sliceArrays(i, 0, v), u = sliceArrays(a, v, b), a = sliceArrays(a, 0, v), g = l.concat(u)) : null != r.validationSteps && (f = !0), C.label = 5;
  29598. case 5:
  29599. return w = i.concat(a).concat(c), e.checkTrainableWeightsConsistency(), z = e.makeTrainFunction(), S = e.getDedupedMetricsNames(), A = void 0, _ = void 0, f ? (e.makeTestFunction(), A = e.testFunction, _ = S.slice().concat(S.map(function (e) {
  29600. return "val_" + e;
  29601. }))) : (A = null, g = [], _ = S.slice()), I = standardizeCallbacks(r.callbacks, r.yieldEvery), [4, fitLoop(e, z, w, S, p, r.epochs, r.verbose, I, A, g, r.shuffle, _, r.initialEpoch, null, null)];
  29602. case 6:
  29603. return [2, C.sent()];
  29604. case 7:
  29605. return e.isTraining = !1, disposeNewTensors(i, t), disposeNewTensors(a, n), disposeNewTensors(l, o), disposeNewTensors(u, s), null != c && (0, _tfjsCore.dispose)(c), [7];
  29606. case 8:
  29607. return [2];
  29608. }
  29609. });
  29610. });
  29611. }
  29612. function ensureTensorsRank2OrHigher(e) {
  29613. var t = [];
  29614. e instanceof _tfjsCore.Tensor && (e = [e]);
  29615. for (var n = 0; n < e.length; ++n) {
  29616. var r = e[n];
  29617. if (1 === r.rank) t.push(expandDims$1(r, 1)); else {
  29618. if (0 === r.rank) throw new Error("Expected tensor to be at least 1D, but received a 0D tensor (scalar).");
  29619. t.push(r);
  29620. }
  29621. }
  29622. return t;
  29623. }
  29624. function disposeNewTensors(e, t) {
  29625. if (null != e) {
  29626. var n = [];
  29627. if (t instanceof _tfjsCore.Tensor) n.push(t.id); else if (Array.isArray(t)) t.forEach(function (e) {
  29628. return n.push(e.id);
  29629. }); else if (null != t) for (var r in t) {
  29630. var i = t[r];
  29631. n.push(i.id);
  29632. }
  29633. var a = [];
  29634. if (e instanceof _tfjsCore.Tensor) -1 === n.indexOf(e.id) && a.push(e); else if (Array.isArray(e)) e.forEach(function (e) {
  29635. -1 === n.indexOf(e.id) && a.push(e);
  29636. }); else if (null != e) for (var o in e) {
  29637. var s = e[o];
  29638. -1 === n.indexOf(s.id) && a.push(s);
  29639. }
  29640. a.forEach(function (e) {
  29641. e.isDisposed || e.dispose();
  29642. });
  29643. }
  29644. }
  29645. function isDataTensor(e) {
  29646. return e instanceof _tfjsCore.Tensor;
  29647. }
  29648. function isDataArray(e) {
  29649. return Array.isArray(e);
  29650. }
  29651. function isDataDict(e) {
  29652. return !isDataTensor(e) && !isDataArray(e);
  29653. }
  29654. function standardizeInputData(e, t, n, r, i) {
  29655. if (void 0 === r && (r = !0), void 0 === i && (i = ""), null == t || 0 === t.length) {
  29656. if (null != e) {
  29657. var a = !1;
  29658. if (isDataArray(e) && e.length > 0) a = !0; else if (isDataDict(e)) {
  29659. for (var o in e) if (e.hasOwnProperty(o)) {
  29660. a = !0;
  29661. break;
  29662. }
  29663. } else a = !0;
  29664. if (a) throw new ValueError("Error when checking model " + i + " expected no data, but got " + e);
  29665. }
  29666. return [];
  29667. }
  29668. if (null == e) return t.map(function (e) {
  29669. return null;
  29670. });
  29671. var s;
  29672. if (isDataDict(e)) {
  29673. e = e, s = [];
  29674. for (var l = 0, u = t; l < u.length; l++) {
  29675. var c = u[l];
  29676. if (null == e[c]) throw new ValueError('No data provided for "' + c + '". Need data for each key in: ' + t);
  29677. s.push(e[c]);
  29678. }
  29679. } else if (isDataArray(e)) {
  29680. if ((e = e).length !== t.length) throw new ValueError("Error when checking model " + i + ": the Array of Tensors that you are passing to your model is not the size the model expected. Expected to see " + t.length + " Tensor(s), but instead got the following list of Tensor(s): " + e);
  29681. s = e;
  29682. } else {
  29683. if (e = e, t.length > 1) throw new ValueError("The model " + i + " expects " + t.length + " Tensor(s), but only received one Tensor. Found: Tensor with shape " + e.shape);
  29684. s = [e];
  29685. }
  29686. if (s = ensureTensorsRank2OrHigher(s), null != n) for (var p = 0; p < t.length; ++p) if (null != n[p]) {
  29687. var h = s[p];
  29688. if (h.shape.length !== n[p].length) throw new ValueError("Error when checking " + i + ": expected " + t[p] + " to have " + n[p].length + " dimension(s). but got array with shape " + h.shape);
  29689. for (var d = 0; d < n[p].length; ++d) if (0 !== d || r) {
  29690. var f = h.shape[d],
  29691. g = n[p][d];
  29692. if (null != g && g >= 0 && f !== g) throw new ValueError("Error when checking " + i + ": expected " + t[p] + " to have shape [" + n[p] + "], but got array with shape [" + h.shape + "].");
  29693. }
  29694. }
  29695. return s;
  29696. }
  29697. function checkArrayLengths(e, t, n) {
  29698. var r = unique(e.map(function (e) {
  29699. return e.shape[0];
  29700. }));
  29701. r.sort();
  29702. var i = unique(t.map(function (e) {
  29703. return e.shape[0];
  29704. }));
  29705. if (i.sort(), r.length > 1) throw new ValueError("All input Tensors (x) should have the same number of samples. Got array shapes: " + JSON.stringify(e.map(function (e) {
  29706. return e.shape;
  29707. })));
  29708. if (i.length > 1) throw new ValueError("All target Tensors (y) should have the same number of samples. Got array shapes: " + JSON.stringify(t.map(function (e) {
  29709. return e.shape;
  29710. })));
  29711. if (r.length > 0 && i.length > 0 && !_tfjsCore.util.arraysEqual(r, i)) throw new ValueError("Input Tensors should have the same number of samples as target Tensors. Found " + r[0] + " input sample(s) and " + i[0] + " target sample(s).");
  29712. }
  29713. function checkLossAndTargetCompatibility(e, t, n) {
  29714. for (var r = [meanSquaredError, binaryCrossentropy, categoricalCrossentropy], i = 0; i < e.length; ++i) {
  29715. var a = e[i],
  29716. o = t[i],
  29717. s = n[i];
  29718. if (null != o) {
  29719. if (o === categoricalCrossentropy && 1 === a.shape[a.shape.length - 1]) throw new ValueError("You are passing a target array of shape " + a.shape + " while using a loss 'categorical_crossentropy'. 'categorical_crossentropy'expects targets to be binary matrices (1s and 0s) of shape [samples, classes].");
  29720. if (-1 !== r.indexOf(o)) for (var l = a.shape.slice(1), u = s.slice(1), c = 0; c < l.length; ++c) {
  29721. var p = l[c],
  29722. h = u[c];
  29723. if (null != h && p !== h) throw new ValueError("A target Tensor with shape " + a.shape + " was passed for an output of shape " + s + ", while using a loss function that expects targets to have the same shape as the output.");
  29724. }
  29725. }
  29726. }
  29727. }
  29728. function checkInputData(e, t, n, r, i) {
  29729. var a;
  29730. if (void 0 === r && (r = !0), void 0 === i && (i = ""), Array.isArray(e)) {
  29731. if (e.length !== t.length) throw new ValueError("Error when checking model " + i + ": the Array of Tensors that you are passing to your model is not the size the the model expected. Expected to see " + t.length + " Tensor(s), but instead got " + e.length + " Tensors(s).");
  29732. a = e;
  29733. } else {
  29734. if (t.length > 1) throw new ValueError("The model expects " + t.length + " " + i + " Tensors, but only received one Tensor. Found: array with shape " + JSON.stringify(e.shape) + ".");
  29735. a = [e];
  29736. }
  29737. if (null != n) for (var o = 0; o < t.length; ++o) if (null != n[o]) {
  29738. var s = a[o];
  29739. if (s.shape.length !== n[o].length) throw new ValueError("Error when checking " + i + ": expected " + t[o] + " to have " + n[o].length + " dimension(s), but got array with shape " + JSON.stringify(s.shape));
  29740. for (var l = 0; l < n[o].length; ++l) if (0 !== l || r) {
  29741. var u = s.shape[l],
  29742. c = n[o][l];
  29743. if (null != c && c !== u) throw new ValueError("Error when checking " + i + ": expected " + t[o] + " to have shape " + JSON.stringify(n[o]) + " but got array with shape " + JSON.stringify(s.shape) + ".");
  29744. }
  29745. }
  29746. }
  29747. function collectMetrics(e, t) {
  29748. if (null == e || Array.isArray(e) && 0 === e.length) return t.map(function (e) {
  29749. return [];
  29750. });
  29751. var n;
  29752. if ("string" == typeof e || "function" == typeof e) n = [e]; else {
  29753. if (!Array.isArray(e) && "object" != typeof e) throw new TypeError("Type of metrics argument not understood. Expected an string,function, Array, or Object, found: " + e);
  29754. n = e;
  29755. }
  29756. if (Array.isArray(n)) return t.map(function (e) {
  29757. return n;
  29758. });
  29759. for (var r = [], i = 0, a = t; i < a.length; i++) {
  29760. var o = a[i],
  29761. s = n.hasOwnProperty(o) ? n[o] : [];
  29762. Array.isArray(s) || (s = [s]), r.push(s);
  29763. }
  29764. return r;
  29765. }
  29766. var LAYERS_MODEL_FORMAT_NAME = "layers-model",
  29767. LayersModel = function (e) {
  29768. function t(t) {
  29769. var n = e.call(this, t) || this;
  29770. return n.isTraining = !1, n;
  29771. }
  29772. return __extends(t, e), t.prototype.summary = function (e, t, n) {
  29773. if (void 0 === n && (n = console.log), !this.built) throw new ValueError("This model has never been called, thus its weights have not been created yet. So no summary can be displayed. Build the model first (e.g., by calling it on some test data).");
  29774. printSummary(this, e, t, n);
  29775. }, t.prototype.compile = function (e) {
  29776. var t = this;
  29777. if (null == e.loss && (e.loss = []), this.loss = e.loss, "string" == typeof e.optimizer) this.optimizer_ = getOptimizer(e.optimizer), this.isOptimizerOwned = !0; else {
  29778. if (!(e.optimizer instanceof _tfjsCore.Optimizer)) throw new ValueError("User-defined optimizer must be an instance of tf.Optimizer.");
  29779. this.optimizer_ = e.optimizer, this.isOptimizerOwned = !1;
  29780. }
  29781. var n = [];
  29782. if (Array.isArray(e.loss) || "string" == typeof e.loss || "function" == typeof e.loss) {
  29783. if (Array.isArray(e.loss)) {
  29784. if (e.loss.length !== this.outputs.length) throw new ValueError("When passing an Array as loss, it should have one entry per model output. The model has " + this.outputs.length + " output(s), but you passed loss=" + e.loss + ".");
  29785. var r = e.loss;
  29786. n = r.map(function (e) {
  29787. return get(e);
  29788. });
  29789. } else {
  29790. var i = get(e.loss);
  29791. this.outputs.forEach(function (e) {
  29792. n.push(i);
  29793. });
  29794. }
  29795. } else {
  29796. for (var a in e.loss = e.loss, e.loss) if (-1 === this.outputNames.indexOf(a)) throw new ValueError('Unknown entry in loss dictionary: "' + a + '". Only expected the following keys: ' + this.outputNames);
  29797. for (var o = 0, s = this.outputNames; o < s.length; o++) {
  29798. var l = s[o];
  29799. null == e.loss[l] && console.warn('Output "' + l + '" is missing from loss dictionary. We assume this was done on purpose, and we will not be expecting data to be passed to ' + l + " during training"), n.push(get(e.loss[l]));
  29800. }
  29801. }
  29802. this.lossFunctions = n, this.feedOutputNames = [], this.feedOutputShapes = [], this.feedLossFns = [];
  29803. for (var u = 0; u < this.outputs.length; ++u) {
  29804. var c = this.internalOutputShapes[u],
  29805. p = this.outputNames[u];
  29806. this.feedOutputNames.push(p), this.feedOutputShapes.push(c), this.feedLossFns.push(this.lossFunctions[u]);
  29807. }
  29808. var h = [];
  29809. this.metrics = e.metrics, this.metricsNames = ["loss"], this.metricsTensors = [], nameScope("loss", function () {
  29810. for (var e = 0; e < t.outputs.length; ++e) if (-1 === h.indexOf(e)) {
  29811. var n = t.lossFunctions[e];
  29812. t.outputs.length > 1 && (t.metricsTensors.push([n, e]), t.metricsNames.push(t.outputNames[e] + "_loss"));
  29813. }
  29814. });
  29815. var d = collectMetrics(e.metrics, this.outputNames);
  29816. nameScope("metric", function () {
  29817. for (var e = function (e) {
  29818. if (-1 !== h.indexOf(e)) return "continue";
  29819. !function (n) {
  29820. for (var r, i, a, o = function (n) {
  29821. if ("string" == typeof n && -1 !== ["accuracy", "acc", "crossentropy", "ce"].indexOf(n)) {
  29822. var o = t.internalOutputShapes[e];
  29823. 1 === o[o.length - 1] || t.lossFunctions[e] === binaryCrossentropy ? -1 !== ["accuracy", "acc"].indexOf(n) ? i = binaryAccuracy : -1 !== ["crossentropy", "ce"].indexOf(n) && (i = binaryCrossentropy$1) : t.lossFunctions[e] === sparseCategoricalCrossentropy ? -1 !== ["accuracy", "acc"].indexOf(n) ? i = sparseCategoricalAccuracy : -1 !== ["crossentropy", "ce"].indexOf(n) && (i = sparseCategoricalCrossentropy$1) : -1 !== ["accuracy", "acc"].indexOf(n) ? i = categoricalAccuracy : -1 !== ["crossentropy", "ce"].indexOf(n) && (i = categoricalCrossentropy$1);
  29824. var s = void 0;
  29825. -1 !== ["accuracy", "acc"].indexOf(n) ? s = "acc" : -1 !== ["crossentropy", "ce"].indexOf(n) && (s = "ce"), a = i, r = "" + s;
  29826. } else {
  29827. var l = get$1(n);
  29828. a = l, r = "" + getLossOrMetricName(n);
  29829. }
  29830. var u;
  29831. nameScope(r, function () {
  29832. u = a;
  29833. }), function (e, n, r) {
  29834. t.outputNames.length > 1 && (n = t.outputNames[e] + "_" + n), t.metricsNames.push(n), t.metricsTensors.push([r, e]);
  29835. }(e, r, u);
  29836. }, s = 0, l = n; s < l.length; s++) o(l[s]);
  29837. }(d[e]);
  29838. }, n = 0; n < t.outputs.length; ++n) e(n);
  29839. }), this.collectedTrainableWeights = this.trainableWeights;
  29840. }, t.prototype.checkTrainableWeightsConsistency = function () {
  29841. null != this.collectedTrainableWeights && this.trainableWeights.length !== this.collectedTrainableWeights.length && console.warn("Discrepancy between trainableweights and collected trainable weights. Did you set `model.trainable` without calling `model.compile()` afterwards?");
  29842. }, t.prototype.evaluate = function (e, t, n) {
  29843. void 0 === n && (n = {});
  29844. var r = null == n.batchSize ? 32 : n.batchSize;
  29845. checkBatchSize(r);
  29846. var i = this.standardizeUserDataXY(e, t, !0, r);
  29847. try {
  29848. var a = i[0].concat(i[1]);
  29849. this.makeTestFunction();
  29850. var o = this.testFunction;
  29851. return singletonOrArray(this.testLoop(o, a, r, n.verbose, n.steps));
  29852. } finally {
  29853. disposeNewTensors(i[0], e), disposeNewTensors(i[1], t);
  29854. }
  29855. }, t.prototype.evaluateDataset = function (e, t) {
  29856. return __awaiter(this, void 0, void 0, function () {
  29857. return __generator(this, function (n) {
  29858. return this.makeTestFunction(), [2, evaluateDataset(this, e, t)];
  29859. });
  29860. });
  29861. }, t.prototype.checkNumSamples = function (e, t, n, r) {
  29862. var i;
  29863. if (void 0 === r && (r = "steps"), null != n) {
  29864. if (i = null, null != t) throw new ValueError("If " + r + " is set, batchSize must be null or undefined.Got batchSize = " + t);
  29865. } else {
  29866. if (null == e) throw new ValueError("Either the input data should have a defined shape, or " + r + " shoud be specified.");
  29867. i = Array.isArray(e) ? e[0].shape[0] : e.shape[0];
  29868. }
  29869. return i;
  29870. }, t.prototype.execute = function (e, t) {
  29871. if (Array.isArray(t) && 0 === t.length) throw new ValueError("`outputs` is an empty Array, which is not allowed.");
  29872. var n = Array.isArray(t),
  29873. r = n ? t : [t],
  29874. i = this.retrieveSymbolicTensors(r),
  29875. a = new FeedDict();
  29876. if (e instanceof _tfjsCore.Tensor && (e = [e]), Array.isArray(e)) {
  29877. if (e.length !== this.inputs.length) throw new ValueError("The number of inputs provided (" + e.length + ") does not match the number of inputs of this model (" + this.inputs.length + ").");
  29878. for (var o = 0; o < this.inputs.length; ++o) a.add(this.inputs[o], e[o]);
  29879. } else for (var s = 0, l = this.inputs; s < l.length; s++) {
  29880. var u = l[s],
  29881. c = e[u.name];
  29882. if (null == c) throw new ValueError("No value is provided for the model's input " + u.name);
  29883. a.add(u, c);
  29884. }
  29885. var p = execute(i, a);
  29886. return n ? p : p[0];
  29887. }, t.prototype.retrieveSymbolicTensors = function (e) {
  29888. for (var t = pyListRepeat(null, e.length), n = e.length, r = 0, i = this.layers; r < i.length; r++) {
  29889. for (var a = i[r], o = Array.isArray(a.output) ? a.output : [a.output], s = o.map(function (e) {
  29890. return e.name;
  29891. }), l = 0; l < e.length; ++l) {
  29892. var u = s.indexOf(e[l]);
  29893. if (-1 !== u && (t[l] = o[u], n--), 0 === n) break;
  29894. }
  29895. if (0 === n) break;
  29896. }
  29897. if (n > 0) {
  29898. var c = [];
  29899. throw t.forEach(function (t, n) {
  29900. null == t && c.push(e[n]);
  29901. }), new ValueError("Cannot find SymbolicTensors for output name(s): " + JSON.stringify(c));
  29902. }
  29903. return t;
  29904. }, t.prototype.predictLoop = function (e, t, n) {
  29905. var r = this;
  29906. return void 0 === t && (t = 32), void 0 === n && (n = !1), (0, _tfjsCore.tidy)(function () {
  29907. var i = r.checkNumSamples(e);
  29908. if (n) throw new NotImplementedError("Verbose predictLoop() is not implemented yet.");
  29909. for (var a = makeBatches(i, t), o = r.outputs.map(function (e) {
  29910. return [];
  29911. }), s = function (t) {
  29912. (0, _tfjsCore.tidy)(function () {
  29913. var n = a[t][0],
  29914. i = a[t][1],
  29915. o = sliceArrays(e, n, i),
  29916. s = [];
  29917. if (Array.isArray(o)) for (var l = 0; l < o.length; ++l) s.push({
  29918. key: r.inputs[l],
  29919. value: o[l]
  29920. }); else s.push({
  29921. key: r.inputs[0],
  29922. value: o
  29923. });
  29924. var u = new FeedDict(s);
  29925. return execute(r.outputs, u);
  29926. }).forEach(function (e, t) {
  29927. return o[t].push(e);
  29928. });
  29929. }, l = 0; l < a.length; ++l) s(l);
  29930. return singletonOrArray(o.map(function (e) {
  29931. return (0, _tfjsCore.concat)(e, 0);
  29932. }));
  29933. });
  29934. }, t.prototype.predict = function (e, t) {
  29935. void 0 === t && (t = {});
  29936. var n = ensureTensorsRank2OrHigher(e);
  29937. checkInputData(n, this.inputNames, this.feedInputShapes, !1);
  29938. try {
  29939. var r = null == t.batchSize ? 32 : t.batchSize;
  29940. return checkBatchSize(r), this.predictLoop(n, r);
  29941. } finally {
  29942. disposeNewTensors(n, e);
  29943. }
  29944. }, t.prototype.predictOnBatch = function (e) {
  29945. checkInputData(e, this.inputNames, this.feedInputShapes, !0);
  29946. var t = (Array.isArray(e) ? e[0] : e).shape[0];
  29947. return this.predictLoop(e, t);
  29948. }, t.prototype.standardizeUserDataXY = function (e, t, n, r) {
  29949. if (void 0 === n && (n = !0), null == this.optimizer_) throw new RuntimeError("You must compile a model before training/testing. Use LayersModel.compile(modelCompileArgs).");
  29950. for (var i = [], a = 0; a < this.feedOutputShapes.length; ++a) {
  29951. var o = this.feedOutputShapes[a];
  29952. this.feedLossFns[a] === sparseCategoricalCrossentropy ? i.push(o.slice(0, o.length - 1).concat([1])) : i.push(o);
  29953. }
  29954. if (checkArrayLengths(e = standardizeInputData(e, this.feedInputNames, this.feedInputShapes, !1, "input"), t = standardizeInputData(t, this.feedOutputNames, i, !1, "target"), null), checkLossAndTargetCompatibility(t, this.feedLossFns, this.feedOutputShapes), this.stateful && null != r && r > 0 && e[0].shape[0] % r != 0) throw new ValueError("In a stateful network, you should only pass inputs with a number of samples that is divisible by the batch size " + r + ". Found: " + e[0].shape[0] + " sample(s).");
  29955. return [e, t];
  29956. }, t.prototype.standardizeUserData = function (e, t, n, r, i, a) {
  29957. return void 0 === i && (i = !0), __awaiter(this, void 0, void 0, function () {
  29958. var o, s, l, u, c, p, h, d;
  29959. return __generator(this, function (f) {
  29960. switch (f.label) {
  29961. case 0:
  29962. if (o = this.standardizeUserDataXY(e, t, i, a), s = o[0], l = o[1], null != n) throw new Error("sample weight is not supported yet.");
  29963. if (u = null, null == r) return [3, 4];
  29964. c = standardizeClassWeights(r, this.outputNames), u = [], p = 0, f.label = 1;
  29965. case 1:
  29966. return p < c.length ? (d = (h = u).push, [4, standardizeWeights(l[p], null, c[p])]) : [3, 4];
  29967. case 2:
  29968. d.apply(h, [f.sent()]), f.label = 3;
  29969. case 3:
  29970. return ++p, [3, 1];
  29971. case 4:
  29972. return [2, [s, l, u]];
  29973. }
  29974. });
  29975. });
  29976. }, t.prototype.testLoop = function (e, t, n, r, i) {
  29977. var a = this;
  29978. return void 0 === r && (r = 0), (0, _tfjsCore.tidy)(function () {
  29979. var o = a.checkNumSamples(t, n, i, "steps"),
  29980. s = [];
  29981. if (r > 0) throw new NotImplementedError("Verbose mode is not implemented yet.");
  29982. if (null != i) throw new NotImplementedError("steps mode in testLoop() is not implemented yet");
  29983. for (var l = makeBatches(o, n), u = (0, _tfjsCore.tensor1d)(range(0, o)), c = 0; c < l.length; ++c) {
  29984. var p = l[c][0],
  29985. h = l[c][1],
  29986. d = sliceAlongFirstAxis(u, p, h - p),
  29987. f = sliceArraysByIndices(t, d),
  29988. g = e(f);
  29989. if (0 === c) for (var m = 0; m < g.length; ++m) s.push((0, _tfjsCore.scalar)(0));
  29990. for (m = 0; m < g.length; ++m) {
  29991. var y = g[m];
  29992. s[m] = (0, _tfjsCore.add)(s[m], (0, _tfjsCore.mul)(h - p, y));
  29993. }
  29994. }
  29995. for (m = 0; m < s.length; ++m) s[m] = (0, _tfjsCore.div)(s[m], o);
  29996. return s;
  29997. });
  29998. }, t.prototype.getDedupedMetricsNames = function () {
  29999. for (var e = this.metricsNames, t = [], n = 0; n < e.length; ++n) {
  30000. var r = e[n],
  30001. i = r;
  30002. if (count(e, r) > 1) i += "_" + count(e.slice(0, n), r);
  30003. t.push(i);
  30004. }
  30005. return t;
  30006. }, t.prototype.makeTrainFunction = function () {
  30007. var e = this;
  30008. return function (t) {
  30009. var n = [],
  30010. r = t.slice(0, e.inputs.length),
  30011. i = t.slice(e.inputs.length, e.inputs.length + e.outputs.length),
  30012. a = t.slice(e.inputs.length + e.outputs.length, e.inputs.length + 2 * e.outputs.length),
  30013. o = [],
  30014. s = e.collectedTrainableWeights.map(function (e) {
  30015. return e.read();
  30016. });
  30017. return [e.optimizer_.minimize(function () {
  30018. for (var t = [], s = 0; s < e.inputs.length; ++s) t.push({
  30019. key: e.inputs[s],
  30020. value: r[s]
  30021. });
  30022. var l,
  30023. u = new FeedDict(t),
  30024. c = execute(e.outputs, u, {
  30025. training: !0
  30026. });
  30027. for (s = 0; s < e.lossFunctions.length; ++s) {
  30028. var p = (0, e.lossFunctions[s])(i[s], c[s]);
  30029. null != a[s] && (p = computeWeightedLoss(p, a[s]));
  30030. var h = (0, _tfjsCore.mean)(p);
  30031. n.push(h), l = 0 === s ? p : (0, _tfjsCore.add)(l, p);
  30032. }
  30033. for (s = 0; s < e.metricsTensors.length; ++s) {
  30034. var d = void 0;
  30035. if (e.outputs.length > 1 && s < e.outputs.length) d = n[s]; else {
  30036. var f = e.metricsTensors[s][0],
  30037. g = e.metricsTensors[s][1];
  30038. d = (0, _tfjsCore.mean)(f(i[g], c[g]));
  30039. }
  30040. (0, _tfjsCore.keep)(d), o.push(d);
  30041. }
  30042. return l = (0, _tfjsCore.mean)(l), e.calculateLosses().forEach(function (e) {
  30043. l = (0, _tfjsCore.add)(l, e);
  30044. }), l;
  30045. }, !0, s)].concat(o);
  30046. };
  30047. }, t.prototype.makeTestFunction = function () {
  30048. var e = this;
  30049. this.testFunction = function (t) {
  30050. return (0, _tfjsCore.tidy)(function () {
  30051. for (var n, r = [], i = t.slice(0, e.inputs.length), a = t.slice(e.inputs.length, e.inputs.length + e.outputs.length), o = [], s = 0; s < e.inputs.length; ++s) o.push({
  30052. key: e.inputs[s],
  30053. value: i[s]
  30054. });
  30055. var l = new FeedDict(o),
  30056. u = execute(e.outputs, l);
  30057. for (s = 0; s < e.lossFunctions.length; ++s) {
  30058. var c = e.lossFunctions[s],
  30059. p = (0, _tfjsCore.mean)(c(a[s], u[s]));
  30060. n = 0 === s ? p : (0, _tfjsCore.add)(n, p), r.push(n);
  30061. }
  30062. for (s = 0; s < e.metricsTensors.length; ++s) {
  30063. var h = e.metricsTensors[s][0],
  30064. d = e.metricsTensors[s][1],
  30065. f = (0, _tfjsCore.mean)(h(a[d], u[d]));
  30066. r.push(f);
  30067. }
  30068. return r;
  30069. });
  30070. };
  30071. }, t.prototype.fit = function (e, t, n) {
  30072. return void 0 === n && (n = {}), __awaiter(this, void 0, void 0, function () {
  30073. return __generator(this, function (r) {
  30074. return [2, fitTensors(this, e, t, n)];
  30075. });
  30076. });
  30077. }, t.prototype.fitDataset = function (e, t) {
  30078. return __awaiter(this, void 0, void 0, function () {
  30079. return __generator(this, function (n) {
  30080. return [2, fitDataset(this, e, t)];
  30081. });
  30082. });
  30083. }, t.prototype.trainOnBatch = function (e, t) {
  30084. return __awaiter(this, void 0, void 0, function () {
  30085. var n, r, i, a, o, s, l, u, c;
  30086. return __generator(this, function (p) {
  30087. switch (p.label) {
  30088. case 0:
  30089. return [4, this.standardizeUserData(e, t)];
  30090. case 1:
  30091. n = p.sent(), r = n[0], i = n[1], a = this.makeTrainFunction(), o = a(r.concat(i)), s = [], l = 0, u = o, p.label = 2;
  30092. case 2:
  30093. return l < u.length ? [4, u[l].data()] : [3, 5];
  30094. case 3:
  30095. c = p.sent(), s.push(c[0]), p.label = 4;
  30096. case 4:
  30097. return l++, [3, 2];
  30098. case 5:
  30099. return (0, _tfjsCore.dispose)(o), [2, singletonOrArray(s)];
  30100. }
  30101. });
  30102. });
  30103. }, t.prototype.getNamedWeights = function (e) {
  30104. for (var t = [], n = null != e && e.trainableOnly, r = n ? this.trainableWeights : this.weights, i = this.getWeights(n), a = 0; a < r.length; ++a) n && !r[a].trainable || t.push({
  30105. name: r[a].originalName,
  30106. tensor: i[a]
  30107. });
  30108. return t;
  30109. }, Object.defineProperty(t.prototype, "stopTraining", {
  30110. get: function () {
  30111. return this.stopTraining_;
  30112. },
  30113. set: function (e) {
  30114. this.stopTraining_ = e;
  30115. },
  30116. enumerable: !0,
  30117. configurable: !0
  30118. }), Object.defineProperty(t.prototype, "optimizer", {
  30119. get: function () {
  30120. return this.optimizer_;
  30121. },
  30122. set: function (e) {
  30123. this.optimizer_ !== e && (this.optimizer_ = e, this.isOptimizerOwned = !1);
  30124. },
  30125. enumerable: !0,
  30126. configurable: !0
  30127. }), t.prototype.dispose = function () {
  30128. var t = e.prototype.dispose.call(this);
  30129. if (0 === t.refCountAfterDispose && null != this.optimizer && this.isOptimizerOwned) {
  30130. var n = (0, _tfjsCore.memory)().numTensors;
  30131. this.optimizer_.dispose(), t.numDisposedVariables += n - (0, _tfjsCore.memory)().numTensors;
  30132. }
  30133. return t;
  30134. }, t.prototype.getLossIdentifiers = function () {
  30135. var e;
  30136. if ("string" == typeof this.loss) e = toSnakeCase(this.loss); else if (Array.isArray(this.loss)) {
  30137. for (var t = 0, n = this.loss; t < n.length; t++) {
  30138. if ("string" != typeof n[t]) throw new Error("Serialization of non-string loss is not supported.");
  30139. }
  30140. e = this.loss.map(function (e) {
  30141. return toSnakeCase(e);
  30142. });
  30143. } else {
  30144. var r = Object.keys(this.loss);
  30145. e = {};
  30146. for (var i = this.loss, a = 0, o = r; a < o.length; a++) {
  30147. var s = o[a];
  30148. if ("string" != typeof i[s]) throw new Error("Serialization of non-string loss is not supported.");
  30149. e[s] = toSnakeCase(i[s]);
  30150. }
  30151. }
  30152. return e;
  30153. }, t.prototype.getMetricIdentifiers = function () {
  30154. if ("string" == typeof this.metrics || "function" == typeof this.metrics) return [toSnakeCase(getLossOrMetricName(this.metrics))];
  30155. if (Array.isArray(this.metrics)) return this.metrics.map(function (e) {
  30156. return toSnakeCase(getLossOrMetricName(e));
  30157. });
  30158. var e = {};
  30159. for (var t in this.metrics) e[t] = toSnakeCase(getLossOrMetricName(this.metrics[t]));
  30160. return e;
  30161. }, t.prototype.getTrainingConfig = function () {
  30162. return {
  30163. loss: this.getLossIdentifiers(),
  30164. metrics: this.getMetricIdentifiers(),
  30165. optimizer_config: {
  30166. class_name: this.optimizer.getClassName(),
  30167. config: this.optimizer.getConfig()
  30168. }
  30169. };
  30170. }, t.prototype.loadTrainingConfig = function (e) {
  30171. if (null != e.weighted_metrics) throw new Error("Loading weight_metrics is not supported yet.");
  30172. if (null != e.loss_weights) throw new Error("Loading loss_weights is not supported yet.");
  30173. if (null != e.sample_weight_mode) throw new Error("Loading sample_weight_mode is not supported yet.");
  30174. var t,
  30175. n,
  30176. r = deserialize(convertPythonicToTs(e.optimizer_config));
  30177. if ("string" == typeof e.loss) t = toCamelCase(e.loss); else if (Array.isArray(e.loss)) t = e.loss.map(function (e) {
  30178. return toCamelCase(e);
  30179. }); else if (null != e.loss) for (var i in t = {}, e.loss) t[i] = toCamelCase(e.loss[i]);
  30180. if (Array.isArray(e.metrics)) n = e.metrics.map(function (e) {
  30181. return toCamelCase(e);
  30182. }); else if (null != e.metrics) for (var i in n = {}, e.metrics) n[i] = toCamelCase(e.metrics[i]);
  30183. this.compile({
  30184. loss: t,
  30185. metrics: n,
  30186. optimizer: r
  30187. });
  30188. }, t.prototype.save = function (e, t) {
  30189. return __awaiter(this, void 0, void 0, function () {
  30190. var n, r, i, a, o, s, l, u, c, p, h, d, f, g;
  30191. return __generator(this, function (m) {
  30192. switch (m.label) {
  30193. case 0:
  30194. if ("string" == typeof e) {
  30195. if (0 === (n = _tfjsCore.io.getSaveHandlers(e)).length) throw new ValueError("Cannot find any save handlers for URL '" + e + "'");
  30196. if (n.length > 1) throw new ValueError("Found more than one (" + n.length + ") save handlers for URL '" + e + "'");
  30197. e = n[0];
  30198. }
  30199. if (null == e.save) throw new ValueError("LayersModel.save() cannot proceed because the IOHandler provided does not have the `save` attribute defined.");
  30200. return [4, _tfjsCore.io.encodeWeights(this.getNamedWeights(t))];
  30201. case 1:
  30202. return r = m.sent(), i = !1, a = null, o = this.toJSON(a, i), s = {
  30203. modelTopology: o,
  30204. format: LAYERS_MODEL_FORMAT_NAME,
  30205. generatedBy: "TensorFlow.js tfjs-layers v" + version,
  30206. convertedBy: null
  30207. }, null != t && t.includeOptimizer && null != this.optimizer ? (s.trainingConfig = this.getTrainingConfig(), l = "optimizer", d = (h = _tfjsCore.io).encodeWeights, [4, this.optimizer.getWeights()]) : [3, 4];
  30208. case 2:
  30209. return [4, d.apply(h, [m.sent(), l])];
  30210. case 3:
  30211. u = m.sent(), c = u.data, p = u.specs, (g = r.specs).push.apply(g, p), r.data = _tfjsCore.io.concatenateArrayBuffers([r.data, c]), m.label = 4;
  30212. case 4:
  30213. return null != this.userDefinedMetadata && (f = !0, checkUserDefinedMetadata(this.userDefinedMetadata, this.name, f), s.userDefinedMetadata = this.userDefinedMetadata), s.weightData = r.data, s.weightSpecs = r.specs, [2, e.save(s)];
  30214. }
  30215. });
  30216. });
  30217. }, t.prototype.setUserDefinedMetadata = function (e) {
  30218. checkUserDefinedMetadata(e, this.name), this.userDefinedMetadata = e;
  30219. }, t.prototype.getUserDefinedMetadata = function () {
  30220. return this.userDefinedMetadata;
  30221. }, t.className = "Model", t;
  30222. }(Container);
  30223. exports.LayersModel = LayersModel;
  30224. function modelFromJSON(e, t) {
  30225. return __awaiter(this, void 0, void 0, function () {
  30226. var n, r, i, a, o, s, l, u;
  30227. return __generator(this, function (c) {
  30228. switch (c.label) {
  30229. case 0:
  30230. return "modelTopology" in e || (e = {
  30231. modelTopology: e
  30232. }), null != (n = (e = e).modelTopology).model_config && (n = n.model_config), r = convertPythonicToTs(n), i = deserialize(r, t), null == e.weightsManifest ? [3, 2] : [4, _tfjsCore.io.loadWeights(e.weightsManifest, e.pathPrefix, i.weights.map(function (e) {
  30233. return e.originalName;
  30234. }))];
  30235. case 1:
  30236. for (a = c.sent(), o = {}, s = 0, l = i.weights; s < l.length; s++) u = l[s], o[u.originalName] = a[u.originalName];
  30237. i.loadWeights(o), (0, _tfjsCore.dispose)(a), c.label = 2;
  30238. case 2:
  30239. return [2, i];
  30240. }
  30241. });
  30242. });
  30243. }
  30244. function loadLayersModelInternal(e, t) {
  30245. return __awaiter(this, void 0, void 0, function () {
  30246. var n;
  30247. return __generator(this, function (r) {
  30248. if (null == t && (t = {}), "string" == typeof e) {
  30249. if (0 === (n = _tfjsCore.io.getLoadHandlers(e, t.onProgress)).length) n.push(_tfjsCore.io.browserHTTPRequest(e, t)); else if (n.length > 1) throw new ValueError("Found more than one (" + n.length + ") load handlers for URL '" + e + "'");
  30250. e = n[0];
  30251. }
  30252. return [2, loadLayersModelFromIOHandler(e, void 0, t)];
  30253. });
  30254. });
  30255. }
  30256. function loadLayersModelFromIOHandler(e, t, n) {
  30257. return __awaiter(this, void 0, void 0, function () {
  30258. var r, i, a, o, s, l, u, c, p;
  30259. return __generator(this, function (h) {
  30260. switch (h.label) {
  30261. case 0:
  30262. if (null == n && (n = {}), null == e.load) throw new ValueError("Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.");
  30263. return [4, e.load()];
  30264. case 1:
  30265. if (r = h.sent(), null != (i = r.modelTopology).model_config && (i = i.model_config), a = null == n.strict || n.strict, o = null != r.weightData && null != r.weightSpecs && a, s = deserialize(convertPythonicToTs(i), t, o), null != (l = r.trainingConfig) && s.loadTrainingConfig(l), null != r.userDefinedMetadata && s.setUserDefinedMetadata(r.userDefinedMetadata), null == r.weightData) return [3, 4];
  30266. if (null == r.weightSpecs) throw new ValueError("LayersModel artifacts contains weight data, but not weight specs. Therefore loading of weights cannot proceed.");
  30267. return u = decodeModelAndOptimizerWeights(r.weightData, r.weightSpecs), c = u.modelWeights, p = u.optimizerWeights, s.loadWeights(c, a), null != s.optimizer && p.length > 0 ? [4, s.optimizer.setWeights(p)] : [3, 3];
  30268. case 2:
  30269. h.sent(), h.label = 3;
  30270. case 3:
  30271. (0, _tfjsCore.dispose)(c), (0, _tfjsCore.dispose)(p.map(function (e) {
  30272. return e.tensor;
  30273. })), h.label = 4;
  30274. case 4:
  30275. return [2, s];
  30276. }
  30277. });
  30278. });
  30279. }
  30280. function decodeModelAndOptimizerWeights(e, t) {
  30281. var n = _tfjsCore.io.decodeWeights(e, t),
  30282. r = {},
  30283. i = [];
  30284. return t.forEach(function (e) {
  30285. "optimizer" === e.group ? i.push({
  30286. name: e.name,
  30287. tensor: n[e.name]
  30288. }) : r[e.name] = n[e.name];
  30289. }), {
  30290. modelWeights: r,
  30291. optimizerWeights: i
  30292. };
  30293. }
  30294. _tfjsCore.serialization.registerClass(LayersModel);
  30295. var Sequential = function (e) {
  30296. function t(t) {
  30297. var n = e.call(this, {
  30298. inputs: [],
  30299. outputs: []
  30300. }) || this;
  30301. if (t = t || {}, n.trainable = !0, n.built = !1, n.name = null != t.name ? t.name : getUid("sequential_"), null != t.layers) for (var r = 0, i = t.layers; r < i.length; r++) {
  30302. var a = i[r];
  30303. n.add(a);
  30304. }
  30305. return n;
  30306. }
  30307. return __extends(t, e), t.prototype.checkShape = function (e) {
  30308. if (e.inboundNodes[0].outputTensors[0].shape.some(function (e) {
  30309. return e < 0;
  30310. })) throw new ValueError("Negative dimension size caused by adding layer " + e.name + " with input shape [" + e.inboundNodes[0].inputTensors[0].shape + "]");
  30311. }, t.prototype.add = function (e) {
  30312. var n,
  30313. r = e instanceof t || e instanceof LayersModel;
  30314. if (r) {
  30315. if (1 !== (n = e).outputs.length) throw new ValueError("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API.");
  30316. if (1 !== n.inputs.length) throw new ValueError("All layers in a Sequential model should have a single input tensor. For multi-input layers, use the functional API.");
  30317. }
  30318. if (0 === this.outputs.length) {
  30319. if (0 === e.inboundNodes.length) {
  30320. if (null == e.batchInputShape) throw new ValueError("The first layer in a Sequential model must get an `inputShape` or `batchInputShape` argument.");
  30321. var i = Input({
  30322. batchShape: e.batchInputShape,
  30323. dtype: e.dtype,
  30324. name: e.name + "_input"
  30325. });
  30326. e.apply(i);
  30327. }
  30328. if (r) this.outputs = n.outputs, this.inputs = n.inputs; else {
  30329. if (1 !== e.inboundNodes.length) throw new ValueError("A layer added to a Sequential model must not already be connected somewhere else. LayersModel received layer " + e.name + " which has " + e.inboundNodes.length + " pre-existing inbound connections.");
  30330. if (1 !== e.inboundNodes[0].outputTensors.length) throw new ValueError("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API.");
  30331. this.checkShape(e), this.outputs = [e.inboundNodes[0].outputTensors[0]], this.inputs = getSourceInputs(this.outputs[0]);
  30332. }
  30333. this.inboundNodes = [], new Node({
  30334. outboundLayer: this,
  30335. inboundLayers: [],
  30336. nodeIndices: [],
  30337. tensorIndices: [],
  30338. inputTensors: this.inputs,
  30339. outputTensors: this.outputs,
  30340. inputMasks: pyListRepeat(null, this.inputs.length),
  30341. outputMasks: [null],
  30342. inputShapes: this.inputs.map(function (e) {
  30343. return e.shape;
  30344. }),
  30345. outputShapes: this.outputs[0].shape
  30346. });
  30347. } else {
  30348. var a = e.apply(this.outputs[0]);
  30349. if (Array.isArray(a)) throw new TypeError("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API.");
  30350. this.checkShape(e), this.outputs = [a], this.inboundNodes[0].outputTensors = this.outputs, this.inboundNodes[0].outputShapes = [this.outputs[0].shape];
  30351. }
  30352. this.layers.push(e), this.built = !1;
  30353. }, t.prototype.pop = function () {
  30354. if (0 === this.layers.length) throw new TypeError("There are no layers in the model.");
  30355. if (this.layers.pop(), 0 === this.layers.length) this.outputs = [], this.inboundNodes = [], this.outboundNodes = []; else {
  30356. var e = this.layers.length - 1;
  30357. this.layers[e].outboundNodes = [], this.outputs = [this.layers[e].output], this.inboundNodes[0].outputTensors = this.outputs, this.inboundNodes[0].outputShapes = [this.outputs[0].shape];
  30358. }
  30359. }, t.prototype.call = function (e, t) {
  30360. return null == this.model && this.build(), this.model.call(e, t);
  30361. }, t.prototype.build = function (e) {
  30362. if (getExactlyOneShape(e), 0 === this.inputs.length || 0 === this.outputs.length) throw new TypeError("Sequential model cannot be built: model is empty. Add some layers first.");
  30363. this.model = new LayersModel({
  30364. inputs: this.inputs,
  30365. outputs: this.outputs[0],
  30366. name: this.name + "_model"
  30367. }), this.model.trainable = this.trainable, this.supportsMasking = this.model.supportsMasking, this.inputLayers = this.model.inputLayers, this.inputLayersNodeIndices = this.model.inputLayersNodeIndices, this.inputLayersTensorIndices = this.model.inputLayersTensorIndices, this.outputLayers = this.model.outputLayers, this.outputLayersNodeIndices = this.model.outputLayersNodeIndices, this.outputLayersTensorIndices = this.model.outputLayersTensorIndices, this.nodesByDepth = this.model.nodesByDepth, this.containerNodes = this.model.containerNodes, this.outputNames = this.model.outputNames, this.inputNames = this.model.inputNames, this.built = !0;
  30368. }, t.prototype.countParams = function () {
  30369. return this.built || this.build(), e.prototype.countParams.call(this);
  30370. }, t.prototype.summary = function (t, n, r) {
  30371. void 0 === r && (r = console.log), this.built || this.build(), e.prototype.summary.call(this, t, n, r);
  30372. }, t.prototype.setWeights = function (e) {
  30373. null == this.model && this.build(), this.model.setWeights(e);
  30374. }, t.prototype.evaluate = function (e, t, n) {
  30375. if (void 0 === n && (n = {}), !this.built) throw new RuntimeError("The model needs to be compiled before being used.");
  30376. return this.model.evaluate(e, t, n);
  30377. }, t.prototype.evaluateDataset = function (e, t) {
  30378. return __awaiter(this, void 0, void 0, function () {
  30379. return __generator(this, function (n) {
  30380. if (!this.built) throw new RuntimeError("The model needs to be compiled before being used.");
  30381. return [2, this.model.evaluateDataset(e, t)];
  30382. });
  30383. });
  30384. }, t.prototype.predict = function (e, t) {
  30385. return void 0 === t && (t = {}), null == this.model && this.build(), this.model.predict(e, t);
  30386. }, t.prototype.predictOnBatch = function (e) {
  30387. return null == this.model && this.build(), this.model.predictOnBatch(e);
  30388. }, t.prototype.compile = function (e) {
  30389. this.build(), this.model.compile(e), this.optimizer_ = this.model.optimizer, this.isOptimizerOwned = this.model.isOptimizerOwned, this.loss = this.model.loss, this.metrics = this.model.metrics, this.metricsTensors = this.model.metricsTensors, this.metricsNames = this.model.metricsNames;
  30390. }, Object.defineProperty(t.prototype, "optimizer", {
  30391. get: function () {
  30392. return null == this.model ? void 0 : this.model.optimizer;
  30393. },
  30394. set: function (e) {
  30395. this.model.optimizer = e;
  30396. },
  30397. enumerable: !0,
  30398. configurable: !0
  30399. }), t.prototype.fit = function (e, t, n) {
  30400. return void 0 === n && (n = {}), __awaiter(this, void 0, void 0, function () {
  30401. return __generator(this, function (r) {
  30402. if (!this.built) throw new RuntimeError("The model needs to be compiled before being used.");
  30403. return [2, this.model.fit(e, t, n)];
  30404. });
  30405. });
  30406. }, t.prototype.fitDataset = function (e, t) {
  30407. return __awaiter(this, void 0, void 0, function () {
  30408. return __generator(this, function (n) {
  30409. if (!this.built) throw new RuntimeError("The model needs to be compiled before being used.");
  30410. return [2, this.model.fitDataset(e, t)];
  30411. });
  30412. });
  30413. }, t.prototype.trainOnBatch = function (e, t) {
  30414. return __awaiter(this, void 0, void 0, function () {
  30415. return __generator(this, function (n) {
  30416. return [2, this.model.trainOnBatch(e, t)];
  30417. });
  30418. });
  30419. }, t.fromConfig = function (e, n, r, i) {
  30420. var a;
  30421. void 0 === r && (r = {}), void 0 === i && (i = !1);
  30422. var o = {};
  30423. if (n instanceof Array) {
  30424. if (null == n[0].className || "Merge" === n[0].className) throw new ValueError("Legacy serialization format not supported yet.");
  30425. a = n;
  30426. } else _tfjsCore.util.assert(null != n.layers, function () {
  30427. return "When the config data for a Sequential model is not an Array, it must be an Object that contains the 'layers' field.";
  30428. }), a = n.layers, delete n.layers, o = n;
  30429. var s = new e(o);
  30430. if (!(s instanceof t)) throw new NotImplementedError("Sequential.fromConfig called on non-Sequential input: " + s);
  30431. for (var l = 0, u = a; l < u.length; l++) {
  30432. var c = deserialize(u[l], void 0, i);
  30433. i && c.setFastWeightInitDuringBuild(!0), s.add(c);
  30434. }
  30435. return s;
  30436. }, Object.defineProperty(t.prototype, "stopTraining", {
  30437. get: function () {
  30438. if (null == this.model) throw new ValueError("Cannot get the stopTraining property of a sequential model before it is compiled.");
  30439. return this.model.stopTraining;
  30440. },
  30441. set: function (e) {
  30442. if (null == this.model) throw new ValueError("Cannot set the stopTraining property of a sequential model before it is compiled.");
  30443. this.model.stopTraining = e;
  30444. },
  30445. enumerable: !0,
  30446. configurable: !0
  30447. }), t.prototype.getConfig = function () {
  30448. for (var e = [], t = 0, n = this.layers; t < n.length; t++) {
  30449. var r = n[t],
  30450. i = {};
  30451. i.className = r.getClassName(), i.config = r.getConfig(), e.push(i);
  30452. }
  30453. return {
  30454. name: this.name,
  30455. layers: e
  30456. };
  30457. }, t.className = "Sequential", t;
  30458. }(LayersModel);
  30459. exports.Sequential = Sequential;
  30460. function model(e) {
  30461. return new LayersModel(e);
  30462. }
  30463. function sequential(e) {
  30464. return new Sequential(e);
  30465. }
  30466. function loadLayersModel(e, t) {
  30467. return null == t && (t = {}), loadLayersModelInternal(e, t);
  30468. }
  30469. function input(e) {
  30470. return Input(e);
  30471. }
  30472. function registerCallbackConstructor(e, t) {
  30473. CallbackConstructorRegistry.registerCallbackConstructor(e, t);
  30474. }
  30475. _tfjsCore.serialization.registerClass(Sequential);
  30476. var Activation = function (e) {
  30477. function t() {
  30478. return null !== e && e.apply(this, arguments) || this;
  30479. }
  30480. return __extends(t, e), t.prototype.getConfig = function () {
  30481. return {};
  30482. }, t;
  30483. }(_tfjsCore.serialization.Serializable),
  30484. Elu = function (e) {
  30485. function t() {
  30486. return null !== e && e.apply(this, arguments) || this;
  30487. }
  30488. return __extends(t, e), t.prototype.apply = function (e, t) {
  30489. return void 0 === t && (t = 1), elu$1(e, t);
  30490. }, t.className = "elu", t;
  30491. }(Activation);
  30492. _tfjsCore.serialization.registerClass(Elu);
  30493. var Selu = function (e) {
  30494. function t() {
  30495. return null !== e && e.apply(this, arguments) || this;
  30496. }
  30497. return __extends(t, e), t.prototype.apply = function (e) {
  30498. return (0, _tfjsCore.selu)(e);
  30499. }, t.className = "selu", t;
  30500. }(Activation);
  30501. _tfjsCore.serialization.registerClass(Selu);
  30502. var Relu = function (e) {
  30503. function t() {
  30504. return null !== e && e.apply(this, arguments) || this;
  30505. }
  30506. return __extends(t, e), t.prototype.apply = function (e) {
  30507. return (0, _tfjsCore.relu)(e);
  30508. }, t.className = "relu", t;
  30509. }(Activation);
  30510. _tfjsCore.serialization.registerClass(Relu);
  30511. var Relu6 = function (e) {
  30512. function t() {
  30513. return null !== e && e.apply(this, arguments) || this;
  30514. }
  30515. return __extends(t, e), t.prototype.apply = function (e) {
  30516. return (0, _tfjsCore.tidy)(function () {
  30517. return (0, _tfjsCore.minimum)(6, (0, _tfjsCore.relu)(e));
  30518. });
  30519. }, t.className = "relu6", t;
  30520. }(Activation);
  30521. _tfjsCore.serialization.registerClass(Relu6);
  30522. var Linear = function (e) {
  30523. function t() {
  30524. return null !== e && e.apply(this, arguments) || this;
  30525. }
  30526. return __extends(t, e), t.prototype.apply = function (e) {
  30527. return e;
  30528. }, t.className = "linear", t;
  30529. }(Activation);
  30530. _tfjsCore.serialization.registerClass(Linear);
  30531. var Sigmoid = function (e) {
  30532. function t() {
  30533. return null !== e && e.apply(this, arguments) || this;
  30534. }
  30535. return __extends(t, e), t.prototype.apply = function (e) {
  30536. return (0, _tfjsCore.sigmoid)(e);
  30537. }, t.className = "sigmoid", t;
  30538. }(Activation);
  30539. _tfjsCore.serialization.registerClass(Sigmoid);
  30540. var HardSigmoid = function (e) {
  30541. function t() {
  30542. return null !== e && e.apply(this, arguments) || this;
  30543. }
  30544. return __extends(t, e), t.prototype.apply = function (e) {
  30545. return hardSigmoid(e);
  30546. }, t.className = "hardSigmoid", t;
  30547. }(Activation);
  30548. _tfjsCore.serialization.registerClass(HardSigmoid);
  30549. var Softplus = function (e) {
  30550. function t() {
  30551. return null !== e && e.apply(this, arguments) || this;
  30552. }
  30553. return __extends(t, e), t.prototype.apply = function (e) {
  30554. return (0, _tfjsCore.softplus)(e);
  30555. }, t.className = "softplus", t;
  30556. }(Activation);
  30557. _tfjsCore.serialization.registerClass(Softplus);
  30558. var Softsign = function (e) {
  30559. function t() {
  30560. return null !== e && e.apply(this, arguments) || this;
  30561. }
  30562. return __extends(t, e), t.prototype.apply = function (e) {
  30563. return softsign(e);
  30564. }, t.className = "softsign", t;
  30565. }(Activation);
  30566. _tfjsCore.serialization.registerClass(Softsign);
  30567. var Tanh = function (e) {
  30568. function t() {
  30569. return null !== e && e.apply(this, arguments) || this;
  30570. }
  30571. return __extends(t, e), t.prototype.apply = function (e) {
  30572. return (0, _tfjsCore.tanh)(e);
  30573. }, t.className = "tanh", t;
  30574. }(Activation);
  30575. _tfjsCore.serialization.registerClass(Tanh);
  30576. var Softmax = function (e) {
  30577. function t() {
  30578. return null !== e && e.apply(this, arguments) || this;
  30579. }
  30580. return __extends(t, e), t.prototype.apply = function (e, t) {
  30581. return void 0 === t && (t = -1), (0, _tfjsCore.softmax)(e, t);
  30582. }, t.className = "softmax", t;
  30583. }(Activation);
  30584. _tfjsCore.serialization.registerClass(Softmax);
  30585. var LogSoftmax = function (e) {
  30586. function t() {
  30587. return null !== e && e.apply(this, arguments) || this;
  30588. }
  30589. return __extends(t, e), t.prototype.apply = function (e, t) {
  30590. return void 0 === t && (t = -1), (0, _tfjsCore.logSoftmax)(e, t);
  30591. }, t.className = "logSoftmax", t;
  30592. }(Activation);
  30593. function serializeActivation(e) {
  30594. return e.getClassName();
  30595. }
  30596. function deserializeActivation(e, t) {
  30597. return void 0 === t && (t = {}), deserializeKerasObject(e, _tfjsCore.serialization.SerializationMap.getMap().classNameMap, t, "activation");
  30598. }
  30599. function getActivation(e) {
  30600. var t;
  30601. return null == e ? deserializeActivation(t = {
  30602. className: "linear",
  30603. config: {}
  30604. }) : "string" == typeof e ? ((t = {}).className = e, t.config = {}, deserializeActivation(t)) : e instanceof Activation ? e : deserializeActivation(e);
  30605. }
  30606. function assertObjectArgs(e) {
  30607. if (null != e && "object" != typeof e) throw new Error("Argument to L1L2 regularizer's constructor is expected to be an object, but received: " + e);
  30608. }
  30609. _tfjsCore.serialization.registerClass(LogSoftmax);
  30610. var Regularizer = function (e) {
  30611. function t() {
  30612. return null !== e && e.apply(this, arguments) || this;
  30613. }
  30614. return __extends(t, e), t;
  30615. }(_tfjsCore.serialization.Serializable),
  30616. L1L2 = function (e) {
  30617. function t(t) {
  30618. var n = e.call(this) || this;
  30619. return assertObjectArgs(t), n.l1 = null == t || null == t.l1 ? .01 : t.l1, n.l2 = null == t || null == t.l2 ? .01 : t.l2, n.hasL1 = 0 !== n.l1, n.hasL2 = 0 !== n.l2, n;
  30620. }
  30621. return __extends(t, e), t.prototype.apply = function (e) {
  30622. var t = this;
  30623. return (0, _tfjsCore.tidy)(function () {
  30624. var n = (0, _tfjsCore.zeros)([1]);
  30625. return t.hasL1 && (n = (0, _tfjsCore.add)(n, (0, _tfjsCore.sum)((0, _tfjsCore.mul)(t.l1, (0, _tfjsCore.abs)(e))))), t.hasL2 && (n = (0, _tfjsCore.add)(n, (0, _tfjsCore.sum)((0, _tfjsCore.mul)(t.l2, square(e))))), n.asScalar();
  30626. });
  30627. }, t.prototype.getConfig = function () {
  30628. return {
  30629. l1: this.l1,
  30630. l2: this.l2
  30631. };
  30632. }, t.fromConfig = function (e, t) {
  30633. return new e({
  30634. l1: t.l1,
  30635. l2: t.l2
  30636. });
  30637. }, t.className = "L1L2", t;
  30638. }(Regularizer);
  30639. function l1(e) {
  30640. return assertObjectArgs(e), new L1L2({
  30641. l1: null != e ? e.l1 : null,
  30642. l2: 0
  30643. });
  30644. }
  30645. function l2(e) {
  30646. return assertObjectArgs(e), new L1L2({
  30647. l2: null != e ? e.l2 : null,
  30648. l1: 0
  30649. });
  30650. }
  30651. _tfjsCore.serialization.registerClass(L1L2);
  30652. var REGULARIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP = {
  30653. l1l2: "L1L2"
  30654. };
  30655. function serializeRegularizer(e) {
  30656. return serializeKerasObject(e);
  30657. }
  30658. function deserializeRegularizer(e, t) {
  30659. return void 0 === t && (t = {}), deserializeKerasObject(e, _tfjsCore.serialization.SerializationMap.getMap().classNameMap, t, "regularizer");
  30660. }
  30661. function getRegularizer(e) {
  30662. return null == e ? null : "string" == typeof e ? deserializeRegularizer({
  30663. className: e in REGULARIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP ? REGULARIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP[e] : e,
  30664. config: {}
  30665. }) : e instanceof Regularizer ? e : deserializeRegularizer(e);
  30666. }
  30667. var ReLU = function (e) {
  30668. function t(t) {
  30669. var n = e.call(this, null == t ? {} : t) || this;
  30670. return n.supportsMasking = !0, null != t && (n.maxValue = t.maxValue), n;
  30671. }
  30672. return __extends(t, e), t.prototype.call = function (e, t) {
  30673. e = getExactlyOneTensor(e);
  30674. var n = (0, _tfjsCore.relu)(e);
  30675. return null != this.maxValue && (n = (0, _tfjsCore.clipByValue)(n, 0, this.maxValue)), n;
  30676. }, t.prototype.computeOutputShape = function (e) {
  30677. return e;
  30678. }, t.prototype.getConfig = function () {
  30679. var t = {
  30680. maxValue: this.maxValue
  30681. },
  30682. n = e.prototype.getConfig.call(this);
  30683. return Object.assign(t, n), t;
  30684. }, t.className = "ReLU", t;
  30685. }(Layer);
  30686. _tfjsCore.serialization.registerClass(ReLU);
  30687. var LeakyReLU = function (e) {
  30688. function t(t) {
  30689. var n = e.call(this, null == t ? {} : t) || this;
  30690. return n.DEFAULT_ALPHA = .3, null == t && (t = {}), n.alpha = null == t.alpha ? n.DEFAULT_ALPHA : t.alpha, n;
  30691. }
  30692. return __extends(t, e), t.prototype.call = function (e, t) {
  30693. var n = getExactlyOneTensor(e);
  30694. return (0, _tfjsCore.leakyRelu)(n, this.alpha);
  30695. }, t.prototype.computeOutputShape = function (e) {
  30696. return e;
  30697. }, t.prototype.getConfig = function () {
  30698. var t = {
  30699. alpha: this.alpha
  30700. },
  30701. n = e.prototype.getConfig.call(this);
  30702. return Object.assign(t, n), t;
  30703. }, t.className = "LeakyReLU", t;
  30704. }(Layer);
  30705. _tfjsCore.serialization.registerClass(LeakyReLU);
  30706. var PReLU = function (e) {
  30707. function t(t) {
  30708. var n = e.call(this, null == t ? {} : t) || this;
  30709. if (n.DEFAULT_ALPHA_INITIALIZER = "zeros", null == t && (t = {}), n.supportsMasking = !0, n.alphaInitializer = getInitializer(t.alphaInitializer || n.DEFAULT_ALPHA_INITIALIZER), n.alphaRegularizer = getRegularizer(t.alphaRegularizer), n.alphaConstraint = getConstraint(t.alphaConstraint), null == t.sharedAxes) n.sharedAxes = null; else if (Array.isArray(t.sharedAxes)) n.sharedAxes = t.sharedAxes; else {
  30710. if ("number" != typeof t.sharedAxes) throw new ValueError("Expected sharedAxes to be a number or an array of numbers, but got " + t.sharedAxes);
  30711. n.sharedAxes = [t.sharedAxes];
  30712. }
  30713. return n;
  30714. }
  30715. return __extends(t, e), t.prototype.build = function (e) {
  30716. var t = (e = getExactlyOneShape(e)).slice(1);
  30717. if (null != this.sharedAxes) for (var n = 0, r = this.sharedAxes; n < r.length; n++) {
  30718. t[(a = r[n]) - 1] = 1;
  30719. }
  30720. this.alpha = this.addWeight("alpha", t, "float32", this.alphaInitializer, this.alphaRegularizer, !0, this.alphaConstraint);
  30721. var i = {};
  30722. if (null != this.sharedAxes) for (var a = 1; a < e.length; ++a) i[a] = e[a];
  30723. this.inputSpec = [new InputSpec({
  30724. ndim: e.length,
  30725. axes: i
  30726. })], this.built = !0;
  30727. }, t.prototype.call = function (e, t) {
  30728. return e = getExactlyOneTensor(e), (0, _tfjsCore.prelu)(e, this.alpha.read());
  30729. }, t.prototype.getConfig = function () {
  30730. var t = {
  30731. alphaInitializer: serializeInitializer(this.alphaInitializer),
  30732. alphaRegularizer: serializeRegularizer(this.alphaRegularizer),
  30733. alphaConstraint: serializeConstraint(this.alphaConstraint),
  30734. sharedAxes: this.sharedAxes
  30735. },
  30736. n = e.prototype.getConfig.call(this);
  30737. return Object.assign(t, n), t;
  30738. }, t.className = "PReLU", t;
  30739. }(Layer);
  30740. _tfjsCore.serialization.registerClass(PReLU);
  30741. var ELU = function (e) {
  30742. function t(t) {
  30743. var n = e.call(this, null == t ? {} : t) || this;
  30744. if (n.DEFAULT_ALPHA = 1, null == t && (t = {}), null != t.alpha && t.alpha !== n.DEFAULT_ALPHA) throw new NotImplementedError("Non-default alpha value (" + t.alpha + ") is not supported by the ELU layer yet.");
  30745. return n.alpha = null == t.alpha ? n.DEFAULT_ALPHA : t.alpha, n;
  30746. }
  30747. return __extends(t, e), t.prototype.call = function (e, t) {
  30748. var n = getExactlyOneTensor(e);
  30749. return (0, _tfjsCore.elu)(n);
  30750. }, t.prototype.computeOutputShape = function (e) {
  30751. return e;
  30752. }, t.prototype.getConfig = function () {
  30753. var t = {
  30754. alpha: this.alpha
  30755. },
  30756. n = e.prototype.getConfig.call(this);
  30757. return Object.assign(t, n), t;
  30758. }, t.className = "ELU", t;
  30759. }(Layer);
  30760. _tfjsCore.serialization.registerClass(ELU);
  30761. var ThresholdedReLU = function (e) {
  30762. function t(t) {
  30763. var n = e.call(this, null == t ? {} : t) || this;
  30764. return n.DEFAULT_THETA = 1, null == t && (t = {}), n.theta = null == t.theta ? n.DEFAULT_THETA : t.theta, n;
  30765. }
  30766. return __extends(t, e), t.prototype.call = function (e, t) {
  30767. var n = getExactlyOneTensor(e);
  30768. return n.mul(cast$1(n.greater(this.theta), "float32"));
  30769. }, t.prototype.computeOutputShape = function (e) {
  30770. return e;
  30771. }, t.prototype.getConfig = function () {
  30772. var t = {
  30773. theta: this.theta
  30774. },
  30775. n = e.prototype.getConfig.call(this);
  30776. return Object.assign(t, n), t;
  30777. }, t.className = "ThresholdedReLU", t;
  30778. }(Layer);
  30779. _tfjsCore.serialization.registerClass(ThresholdedReLU);
  30780. var Softmax$1 = function (e) {
  30781. function t(t) {
  30782. var n = e.call(this, null == t ? {} : t) || this;
  30783. return n.DEFAULT_AXIS = 1, null == t && (t = {}), n.softmax = new Softmax().apply, n.axis = null == t.axis ? n.DEFAULT_AXIS : t.axis, n;
  30784. }
  30785. return __extends(t, e), t.prototype.call = function (e, t) {
  30786. var n = getExactlyOneTensor(e);
  30787. return this.softmax(n, this.axis);
  30788. }, t.prototype.computeOutputShape = function (e) {
  30789. return e;
  30790. }, t.prototype.getConfig = function () {
  30791. var t = {
  30792. axis: this.axis
  30793. },
  30794. n = e.prototype.getConfig.call(this);
  30795. return Object.assign(t, n), t;
  30796. }, t.className = "Softmax", t;
  30797. }(Layer);
  30798. function normalizeArray(e, t, n) {
  30799. if ("number" == typeof e) return pyListRepeat(e, t);
  30800. if (e.length !== t) throw new ValueError("The " + n + " argument must be an integer or tuple of " + t + " integers. Received: " + e.length + " elements.");
  30801. for (var r = 0; r < t; ++r) {
  30802. var i = e[r];
  30803. if (!isInteger(i)) throw new ValueError("The " + n + " argument must be an integer or tuple of " + t + " integers. Received: " + JSON.stringify(e) + " including a non-integer number " + i);
  30804. }
  30805. return e;
  30806. }
  30807. function convOutputLength(e, t, n, r, i) {
  30808. return void 0 === i && (i = 1), null == e ? e : (a = "same" === n ? e : e - (t + (t - 1) * (i - 1)) + 1, Math.floor((a + r - 1) / r));
  30809. var a;
  30810. }
  30811. function deconvLength(e, t, n, r) {
  30812. if (null == e) return null;
  30813. if ("valid" === r) e = e * t + max$1([n - t, 0]); else {
  30814. if ("same" !== r) throw new ValueError("Unsupport padding mode: " + r + ".");
  30815. e *= t;
  30816. }
  30817. return e;
  30818. }
  30819. function preprocessConv2DInput(e, t) {
  30820. return (0, _tfjsCore.tidy)(function () {
  30821. return checkDataFormat(t), "channelsFirst" === t ? (0, _tfjsCore.transpose)(e, [0, 2, 3, 1]) : e;
  30822. });
  30823. }
  30824. function preprocessConv3DInput(e, t) {
  30825. return (0, _tfjsCore.tidy)(function () {
  30826. return checkDataFormat(t), "channelsFirst" === t ? (0, _tfjsCore.transpose)(e, [0, 2, 3, 4, 1]) : e;
  30827. });
  30828. }
  30829. function conv1dWithBias(e, t, n, r, i, a, o) {
  30830. return void 0 === r && (r = 1), void 0 === i && (i = "valid"), void 0 === o && (o = 1), (0, _tfjsCore.tidy)(function () {
  30831. if (null == a && (a = imageDataFormat()), checkDataFormat(a), 3 !== e.shape.length) throw new ValueError("The input of a conv1dWithBias operation should be 3, but is " + e.shape.length + " instead.");
  30832. if (3 !== t.shape.length) throw new ValueError("The kernel for a conv1dWithBias operation should be 3, but is " + t.shape.length + " instead");
  30833. if (null != n && 1 !== n.shape.length) throw new ValueError("The bias for a conv1dWithBias operation should be 1, but is " + t.shape.length + " instead");
  30834. if ("channelsFirst" === a && (e = (0, _tfjsCore.transpose)(e, [0, 2, 1])), "causal" === i) throw new NotImplementedError("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet.");
  30835. var s = (0, _tfjsCore.conv1d)(e, t, r, "same" === i ? "same" : "valid", "NWC", o);
  30836. return null != n && (s = biasAdd(s, n)), s;
  30837. });
  30838. }
  30839. function conv2dWithBiasActivation(e, t, n, r, i, a, o, s) {
  30840. return void 0 === r && (r = [1, 1]), void 0 === i && (i = "valid"), void 0 === s && (s = null), (0, _tfjsCore.tidy)(function () {
  30841. if (null == a && (a = imageDataFormat()), checkDataFormat(a), 3 !== e.rank && 4 !== e.rank) throw new ValueError("conv2dWithBiasActivation expects input to be of rank 3 or 4, but received " + e.rank + ".");
  30842. if (3 !== t.rank && 4 !== t.rank) throw new ValueError("conv2dWithBiasActivation expects kernel to be of rank 3 or 4, but received " + e.rank + ".");
  30843. var l = preprocessConv2DInput(e, a);
  30844. if ("causal" === i) throw new NotImplementedError("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet.");
  30845. return l = _tfjsCore.fused.conv2d({
  30846. x: l,
  30847. filter: t,
  30848. strides: r,
  30849. pad: "same" === i ? "same" : "valid",
  30850. dilations: o,
  30851. dataFormat: "NHWC",
  30852. bias: n,
  30853. activation: s
  30854. }), "channelsFirst" === a && (l = (0, _tfjsCore.transpose)(l, [0, 3, 1, 2])), l;
  30855. });
  30856. }
  30857. function conv3dWithBias(e, t, n, r, i, a, o) {
  30858. return void 0 === r && (r = [1, 1, 1]), void 0 === i && (i = "valid"), (0, _tfjsCore.tidy)(function () {
  30859. if (null == a && (a = imageDataFormat()), checkDataFormat(a), 4 !== e.rank && 5 !== e.rank) throw new ValueError("conv3dWithBias expects input to be of rank 4 or 5, but received " + e.rank + ".");
  30860. if (4 !== t.rank && 5 !== t.rank) throw new ValueError("conv3dWithBias expects kernel to be of rank 4 or 5, but received " + e.rank + ".");
  30861. var s = preprocessConv3DInput(e, a);
  30862. if ("causal" === i) throw new NotImplementedError("The support for CAUSAL padding mode in conv3dWithBias is not implemented yet.");
  30863. return s = (0, _tfjsCore.conv3d)(s, t, r, "same" === i ? "same" : "valid", "NDHWC", o), null != n && (s = biasAdd(s, n)), "channelsFirst" === a && (s = (0, _tfjsCore.transpose)(s, [0, 4, 1, 2, 3])), s;
  30864. });
  30865. }
  30866. _tfjsCore.serialization.registerClass(Softmax$1);
  30867. var BaseConv = function (e) {
  30868. function t(n, r) {
  30869. var i = e.call(this, r) || this;
  30870. if (i.bias = null, i.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", i.DEFAULT_BIAS_INITIALIZER = "zeros", t.verifyArgs(r), i.rank = n, assertPositiveInteger(i.rank, "rank"), 1 !== i.rank && 2 !== i.rank && 3 !== i.rank) throw new NotImplementedError("Convolution layer for rank other than 1, 2, or 3 (" + i.rank + ") is not implemented yet.");
  30871. if (i.kernelSize = normalizeArray(r.kernelSize, n, "kernelSize"), i.strides = normalizeArray(null == r.strides ? 1 : r.strides, n, "strides"), i.padding = null == r.padding ? "valid" : r.padding, checkPaddingMode(i.padding), i.dataFormat = null == r.dataFormat ? "channelsLast" : r.dataFormat, checkDataFormat(i.dataFormat), i.activation = getActivation(r.activation), i.useBias = null == r.useBias || r.useBias, i.biasInitializer = getInitializer(r.biasInitializer || i.DEFAULT_BIAS_INITIALIZER), i.biasConstraint = getConstraint(r.biasConstraint), i.biasRegularizer = getRegularizer(r.biasRegularizer), i.activityRegularizer = getRegularizer(r.activityRegularizer), i.dilationRate = normalizeArray(null == r.dilationRate ? 1 : r.dilationRate, n, "dilationRate"), 1 === i.rank && Array.isArray(i.dilationRate) && 1 !== i.dilationRate.length) throw new ValueError("dilationRate must be a number or an array of a single number for 1D convolution, but received " + JSON.stringify(i.dilationRate));
  30872. if (2 === i.rank) {
  30873. if ("number" == typeof i.dilationRate) i.dilationRate = [i.dilationRate, i.dilationRate]; else if (2 !== i.dilationRate.length) throw new ValueError("dilationRate must be a number or array of two numbers for 2D convolution, but received " + JSON.stringify(i.dilationRate));
  30874. } else if (3 === i.rank) if ("number" == typeof i.dilationRate) i.dilationRate = [i.dilationRate, i.dilationRate, i.dilationRate]; else if (3 !== i.dilationRate.length) throw new ValueError("dilationRate must be a number or array of three numbers for 3D convolution, but received " + JSON.stringify(i.dilationRate));
  30875. return i;
  30876. }
  30877. return __extends(t, e), t.verifyArgs = function (e) {
  30878. if (assert("kernelSize" in e, "required key 'kernelSize' not in config"), "number" != typeof e.kernelSize && !checkArrayTypeAndLength(e.kernelSize, "number", 1, 3)) throw new ValueError("BaseConv expects config.kernelSize to be number or number[] with length 1, 2, or 3, but received " + JSON.stringify(e.kernelSize) + ".");
  30879. }, t.prototype.getConfig = function () {
  30880. var t = {
  30881. kernelSize: this.kernelSize,
  30882. strides: this.strides,
  30883. padding: this.padding,
  30884. dataFormat: this.dataFormat,
  30885. dilationRate: this.dilationRate,
  30886. activation: serializeActivation(this.activation),
  30887. useBias: this.useBias,
  30888. biasInitializer: serializeInitializer(this.biasInitializer),
  30889. biasRegularizer: serializeRegularizer(this.biasRegularizer),
  30890. activityRegularizer: serializeRegularizer(this.activityRegularizer),
  30891. biasConstraint: serializeConstraint(this.biasConstraint)
  30892. },
  30893. n = e.prototype.getConfig.call(this);
  30894. return Object.assign(t, n), t;
  30895. }, t;
  30896. }(Layer),
  30897. Conv = function (e) {
  30898. function t(n, r) {
  30899. var i = e.call(this, n, r) || this;
  30900. return i.kernel = null, t.verifyArgs(r), i.filters = r.filters, assertPositiveInteger(i.filters, "filters"), i.kernelInitializer = getInitializer(r.kernelInitializer || i.DEFAULT_KERNEL_INITIALIZER), i.kernelConstraint = getConstraint(r.kernelConstraint), i.kernelRegularizer = getRegularizer(r.kernelRegularizer), i;
  30901. }
  30902. return __extends(t, e), t.prototype.build = function (e) {
  30903. var t;
  30904. e = getExactlyOneShape(e);
  30905. var n = "channelsFirst" === this.dataFormat ? 1 : e.length - 1;
  30906. if (null == e[n]) throw new ValueError("The channel dimension of the input should be defined. Found " + e[n]);
  30907. var r = e[n],
  30908. i = this.kernelSize.concat([r, this.filters]);
  30909. this.kernel = this.addWeight("kernel", i, null, this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.useBias && (this.bias = this.addWeight("bias", [this.filters], null, this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint)), this.inputSpec = [{
  30910. ndim: this.rank + 2,
  30911. axes: (t = {}, t[n] = r, t)
  30912. }], this.built = !0;
  30913. }, t.prototype.call = function (e, t) {
  30914. var n = this;
  30915. return (0, _tfjsCore.tidy)(function () {
  30916. var t;
  30917. e = getExactlyOneTensor(e);
  30918. var r = null == n.bias ? null : n.bias.read(),
  30919. i = mapActivationToFusedKernel(n.activation.getClassName());
  30920. if (null != i && 2 === n.rank) t = conv2dWithBiasActivation(e, n.kernel.read(), r, n.strides, n.padding, n.dataFormat, n.dilationRate, i); else {
  30921. if (1 === n.rank) t = conv1dWithBias(e, n.kernel.read(), r, n.strides[0], n.padding, n.dataFormat, n.dilationRate[0]); else if (2 === n.rank) t = conv2dWithBiasActivation(e, n.kernel.read(), r, n.strides, n.padding, n.dataFormat, n.dilationRate); else {
  30922. if (3 !== n.rank) throw new NotImplementedError("convolutions greater than 3D are not implemented yet.");
  30923. t = conv3dWithBias(e, n.kernel.read(), r, n.strides, n.padding, n.dataFormat, n.dilationRate);
  30924. }
  30925. null != n.activation && (t = n.activation.apply(t));
  30926. }
  30927. return t;
  30928. });
  30929. }, t.prototype.computeOutputShape = function (e) {
  30930. e = getExactlyOneShape(e);
  30931. for (var t = [], n = "channelsLast" === this.dataFormat ? e.slice(1, e.length - 1) : e.slice(2), r = 0; r < n.length; ++r) {
  30932. var i = convOutputLength(n[r], this.kernelSize[r], this.padding, this.strides[r], "number" == typeof this.dilationRate ? this.dilationRate : this.dilationRate[r]);
  30933. t.push(i);
  30934. }
  30935. var a = [e[0]];
  30936. return "channelsLast" === this.dataFormat ? (a = a.concat(t)).push(this.filters) : (a.push(this.filters), a = a.concat(t)), a;
  30937. }, t.prototype.getConfig = function () {
  30938. var t = {
  30939. filters: this.filters,
  30940. kernelInitializer: serializeInitializer(this.kernelInitializer),
  30941. kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
  30942. kernelConstraint: serializeConstraint(this.kernelConstraint)
  30943. },
  30944. n = e.prototype.getConfig.call(this);
  30945. return Object.assign(t, n), t;
  30946. }, t.verifyArgs = function (e) {
  30947. if (!("filters" in e) || "number" != typeof e.filters || e.filters < 1) throw new ValueError("Convolution layer expected config.filters to be a 'number' > 0 but got " + JSON.stringify(e.filters));
  30948. }, t;
  30949. }(BaseConv),
  30950. Conv2D = function (e) {
  30951. function t(n) {
  30952. var r = e.call(this, 2, n) || this;
  30953. return t.verifyArgs(n), r;
  30954. }
  30955. return __extends(t, e), t.prototype.getConfig = function () {
  30956. var t = e.prototype.getConfig.call(this);
  30957. return delete t.rank, t;
  30958. }, t.verifyArgs = function (e) {
  30959. if ("number" != typeof e.kernelSize && !checkArrayTypeAndLength(e.kernelSize, "number", 1, 2)) throw new ValueError("Conv2D expects config.kernelSize to be number or number[] with length 1 or 2, but received " + JSON.stringify(e.kernelSize) + ".");
  30960. }, t.className = "Conv2D", t;
  30961. }(Conv);
  30962. _tfjsCore.serialization.registerClass(Conv2D);
  30963. var Conv3D = function (e) {
  30964. function t(n) {
  30965. var r = e.call(this, 3, n) || this;
  30966. return t.verifyArgs(n), r;
  30967. }
  30968. return __extends(t, e), t.prototype.getConfig = function () {
  30969. var t = e.prototype.getConfig.call(this);
  30970. return delete t.rank, t;
  30971. }, t.verifyArgs = function (e) {
  30972. if ("number" != typeof e.kernelSize && (!Array.isArray(e.kernelSize) || 1 !== e.kernelSize.length && 3 !== e.kernelSize.length)) throw new ValueError("Conv3D expects config.kernelSize to be number or [number, number, number], but received " + JSON.stringify(e.kernelSize) + ".");
  30973. }, t.className = "Conv3D", t;
  30974. }(Conv);
  30975. _tfjsCore.serialization.registerClass(Conv3D);
  30976. var Conv2DTranspose = function (e) {
  30977. function t(t) {
  30978. var n = e.call(this, t) || this;
  30979. if (n.inputSpec = [new InputSpec({
  30980. ndim: 4
  30981. })], "same" !== n.padding && "valid" !== n.padding) throw new ValueError("Conv2DTranspose currently supports only padding modes 'same' and 'valid', but received padding mode " + n.padding);
  30982. return n;
  30983. }
  30984. return __extends(t, e), t.prototype.build = function (e) {
  30985. var t;
  30986. if (4 !== (e = getExactlyOneShape(e)).length) throw new ValueError("Input should have rank 4; Received input shape: " + JSON.stringify(e));
  30987. var n = "channelsFirst" === this.dataFormat ? 1 : e.length - 1;
  30988. if (null == e[n]) throw new ValueError("The channel dimension of the inputs should be defined. Found `None`.");
  30989. var r = e[n],
  30990. i = this.kernelSize.concat([this.filters, r]);
  30991. this.kernel = this.addWeight("kernel", i, "float32", this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.useBias && (this.bias = this.addWeight("bias", [this.filters], "float32", this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint)), this.inputSpec = [new InputSpec({
  30992. ndim: 4,
  30993. axes: (t = {}, t[n] = r, t)
  30994. })], this.built = !0;
  30995. }, t.prototype.call = function (e, t) {
  30996. var n = this;
  30997. return (0, _tfjsCore.tidy)(function () {
  30998. var t = getExactlyOneTensor(e);
  30999. if (4 !== t.shape.length) throw new ValueError("Conv2DTranspose.call() expects input tensor to be rank-4, but received a tensor of rank-" + t.shape.length);
  31000. var r,
  31001. i,
  31002. a = t.shape,
  31003. o = a[0];
  31004. "channelsFirst" === n.dataFormat ? (r = 2, i = 3) : (r = 1, i = 2);
  31005. var s = a[r],
  31006. l = a[i],
  31007. u = n.kernelSize[0],
  31008. c = n.kernelSize[1],
  31009. p = n.strides[0],
  31010. h = n.strides[1],
  31011. d = [o, deconvLength(s, p, u, n.padding), deconvLength(l, h, c, n.padding), n.filters];
  31012. "channelsLast" !== n.dataFormat && (t = (0, _tfjsCore.transpose)(t, [0, 2, 3, 1]));
  31013. var f = (0, _tfjsCore.conv2dTranspose)(t, n.kernel.read(), d, n.strides, n.padding);
  31014. return "channelsLast" !== n.dataFormat && (f = (0, _tfjsCore.transpose)(f, [0, 3, 1, 2])), null != n.bias && (f = biasAdd(f, n.bias.read(), n.dataFormat)), null != n.activation && (f = n.activation.apply(f)), f;
  31015. });
  31016. }, t.prototype.computeOutputShape = function (e) {
  31017. var t,
  31018. n,
  31019. r,
  31020. i = (e = getExactlyOneShape(e)).slice();
  31021. "channelsFirst" === this.dataFormat ? (t = 1, n = 2, r = 3) : (t = 3, n = 1, r = 2);
  31022. var a = this.kernelSize[0],
  31023. o = this.kernelSize[1],
  31024. s = this.strides[0],
  31025. l = this.strides[1];
  31026. return i[t] = this.filters, i[n] = deconvLength(i[n], s, a, this.padding), i[r] = deconvLength(i[r], l, o, this.padding), i;
  31027. }, t.prototype.getConfig = function () {
  31028. var t = e.prototype.getConfig.call(this);
  31029. return delete t.dilationRate, t;
  31030. }, t.className = "Conv2DTranspose", t;
  31031. }(Conv2D);
  31032. _tfjsCore.serialization.registerClass(Conv2DTranspose);
  31033. var SeparableConv = function (e) {
  31034. function t(t, n) {
  31035. var r = e.call(this, t, n) || this;
  31036. if (r.DEFAULT_DEPTHWISE_INITIALIZER = "glorotUniform", r.DEFAULT_POINTWISE_INITIALIZER = "glorotUniform", r.depthwiseKernel = null, r.pointwiseKernel = null, null == n.filters) throw new ValueError("The `filters` configuration field is required by SeparableConv, but is unspecified.");
  31037. if (null != n.kernelInitializer || null != n.kernelRegularizer || null != n.kernelConstraint) throw new ValueError("Fields kernelInitializer, kernelRegularizer and kernelConstraint are invalid for SeparableConv2D. Use depthwiseInitializer, depthwiseRegularizer, depthwiseConstraint, pointwiseInitializer, pointwiseRegularizer and pointwiseConstraint instead.");
  31038. if (null != n.padding && "same" !== n.padding && "valid" !== n.padding) throw new ValueError("SeparableConv" + r.rank + "D supports only padding modes: 'same' and 'valid', but received " + JSON.stringify(n.padding));
  31039. return r.depthMultiplier = null == n.depthMultiplier ? 1 : n.depthMultiplier, r.depthwiseInitializer = getInitializer(n.depthwiseInitializer || r.DEFAULT_DEPTHWISE_INITIALIZER), r.depthwiseRegularizer = getRegularizer(n.depthwiseRegularizer), r.depthwiseConstraint = getConstraint(n.depthwiseConstraint), r.pointwiseInitializer = getInitializer(n.depthwiseInitializer || r.DEFAULT_POINTWISE_INITIALIZER), r.pointwiseRegularizer = getRegularizer(n.pointwiseRegularizer), r.pointwiseConstraint = getConstraint(n.pointwiseConstraint), r;
  31040. }
  31041. return __extends(t, e), t.prototype.build = function (e) {
  31042. var t;
  31043. if ((e = getExactlyOneShape(e)).length < this.rank + 2) throw new ValueError("Inputs to SeparableConv" + this.rank + "D should have rank " + (this.rank + 2) + ", but received input shape: " + JSON.stringify(e));
  31044. var n = "channelsFirst" === this.dataFormat ? 1 : e.length - 1;
  31045. if (null == e[n] || e[n] < 0) throw new ValueError("The channel dimension of the inputs should be defined, but found " + JSON.stringify(e[n]));
  31046. for (var r = e[n], i = this.kernelSize.concat([r, this.depthMultiplier]), a = [], o = 0; o < this.rank; ++o) a.push(1);
  31047. a.push(r * this.depthMultiplier, this.filters);
  31048. this.depthwiseKernel = this.addWeight("depthwise_kernel", i, "float32", this.depthwiseInitializer, this.depthwiseRegularizer, !0, this.depthwiseConstraint), this.pointwiseKernel = this.addWeight("pointwise_kernel", a, "float32", this.pointwiseInitializer, this.pointwiseRegularizer, !0, this.pointwiseConstraint), this.useBias ? this.bias = this.addWeight("bias", [this.filters], "float32", this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint) : this.bias = null, this.inputSpec = [new InputSpec({
  31049. ndim: this.rank + 2,
  31050. axes: (t = {}, t[n] = r, t)
  31051. })], this.built = !0;
  31052. }, t.prototype.call = function (e, t) {
  31053. var n = this;
  31054. return (0, _tfjsCore.tidy)(function () {
  31055. var t;
  31056. if (e = getExactlyOneTensor(e), 1 === n.rank) throw new NotImplementedError("1D separable convolution is not implemented yet.");
  31057. return 2 === n.rank && ("channelsFirst" === n.dataFormat && (e = (0, _tfjsCore.transpose)(e, [0, 2, 3, 1])), t = (0, _tfjsCore.separableConv2d)(e, n.depthwiseKernel.read(), n.pointwiseKernel.read(), n.strides, n.padding, n.dilationRate, "NHWC")), n.useBias && (t = biasAdd(t, n.bias.read(), n.dataFormat)), null != n.activation && (t = n.activation.apply(t)), "channelsFirst" === n.dataFormat && (t = (0, _tfjsCore.transpose)(t, [0, 3, 1, 2])), t;
  31058. });
  31059. }, t.prototype.getConfig = function () {
  31060. var t = e.prototype.getConfig.call(this);
  31061. return delete t.rank, delete t.kernelInitializer, delete t.kernelRegularizer, delete t.kernelConstraint, t.depthwiseInitializer = serializeInitializer(this.depthwiseInitializer), t.pointwiseInitializer = serializeInitializer(this.pointwiseInitializer), t.depthwiseRegularizer = serializeRegularizer(this.depthwiseRegularizer), t.pointwiseRegularizer = serializeRegularizer(this.pointwiseRegularizer), t.depthwiseConstraint = serializeConstraint(this.depthwiseConstraint), t.pointwiseConstraint = serializeConstraint(this.pointwiseConstraint), t;
  31062. }, t.className = "SeparableConv", t;
  31063. }(Conv),
  31064. SeparableConv2D = function (e) {
  31065. function t(t) {
  31066. return e.call(this, 2, t) || this;
  31067. }
  31068. return __extends(t, e), t.className = "SeparableConv2D", t;
  31069. }(SeparableConv);
  31070. _tfjsCore.serialization.registerClass(SeparableConv2D);
  31071. var Conv1D = function (e) {
  31072. function t(n) {
  31073. var r = e.call(this, 1, n) || this;
  31074. return t.verifyArgs(n), r.inputSpec = [{
  31075. ndim: 3
  31076. }], r;
  31077. }
  31078. return __extends(t, e), t.prototype.getConfig = function () {
  31079. var t = e.prototype.getConfig.call(this);
  31080. return delete t.rank, delete t.dataFormat, t;
  31081. }, t.verifyArgs = function (e) {
  31082. if ("number" != typeof e.kernelSize && !checkArrayTypeAndLength(e.kernelSize, "number", 1, 1)) throw new ValueError("Conv1D expects config.kernelSize to be number or number[] with length 1, but received " + JSON.stringify(e.kernelSize) + ".");
  31083. }, t.className = "Conv1D", t;
  31084. }(Conv);
  31085. _tfjsCore.serialization.registerClass(Conv1D);
  31086. var Cropping2D = function (e) {
  31087. function t(t) {
  31088. var n = e.call(this, t) || this;
  31089. return "number" == typeof t.cropping ? n.cropping = [[t.cropping, t.cropping], [t.cropping, t.cropping]] : "number" == typeof t.cropping[0] ? n.cropping = [[t.cropping[0], t.cropping[0]], [t.cropping[1], t.cropping[1]]] : n.cropping = t.cropping, n.dataFormat = void 0 === t.dataFormat ? "channelsLast" : t.dataFormat, n.inputSpec = [{
  31090. ndim: 4
  31091. }], n;
  31092. }
  31093. return __extends(t, e), t.prototype.computeOutputShape = function (e) {
  31094. return "channelsFirst" === this.dataFormat ? [e[0], e[1], e[2] - this.cropping[0][0] - this.cropping[0][1], e[3] - this.cropping[1][0] - this.cropping[1][1]] : [e[0], e[1] - this.cropping[0][0] - this.cropping[0][1], e[2] - this.cropping[1][0] - this.cropping[1][1], e[3]];
  31095. }, t.prototype.call = function (e, t) {
  31096. var n = this;
  31097. return (0, _tfjsCore.tidy)(function () {
  31098. return e = getExactlyOneTensor(e), "channelsLast" === n.dataFormat ? sliceAlongAxis(sliceAlongAxis(e, n.cropping[0][0], e.shape[1] - n.cropping[0][0] - n.cropping[0][1], 2), n.cropping[1][0], e.shape[2] - n.cropping[1][1] - n.cropping[1][0], 3) : sliceAlongAxis(sliceAlongAxis(e, n.cropping[0][0], e.shape[2] - n.cropping[0][0] - n.cropping[0][1], 3), n.cropping[1][0], e.shape[3] - n.cropping[1][1] - n.cropping[1][0], 4);
  31099. });
  31100. }, t.prototype.getConfig = function () {
  31101. var t = {
  31102. cropping: this.cropping,
  31103. dataFormat: this.dataFormat
  31104. },
  31105. n = e.prototype.getConfig.call(this);
  31106. return Object.assign(t, n), t;
  31107. }, t.className = "Cropping2D", t;
  31108. }(Layer);
  31109. _tfjsCore.serialization.registerClass(Cropping2D);
  31110. var UpSampling2D = function (e) {
  31111. function t(t) {
  31112. var n = e.call(this, t) || this;
  31113. return n.DEFAULT_SIZE = [2, 2], n.inputSpec = [{
  31114. ndim: 4
  31115. }], n.size = null == t.size ? n.DEFAULT_SIZE : t.size, n.dataFormat = null == t.dataFormat ? "channelsLast" : t.dataFormat, n;
  31116. }
  31117. return __extends(t, e), t.prototype.computeOutputShape = function (e) {
  31118. if ("channelsFirst" === this.dataFormat) {
  31119. var t = null == e[2] ? null : this.size[0] * e[2],
  31120. n = null == e[3] ? null : this.size[1] * e[3];
  31121. return [e[0], e[1], t, n];
  31122. }
  31123. t = null == e[1] ? null : this.size[0] * e[1], n = null == e[2] ? null : this.size[1] * e[2];
  31124. return [e[0], t, n, e[3]];
  31125. }, t.prototype.call = function (e, t) {
  31126. var n = this;
  31127. return (0, _tfjsCore.tidy)(function () {
  31128. var t = getExactlyOneTensor(e),
  31129. r = t.shape;
  31130. if ("channelsFirst" === n.dataFormat) {
  31131. t = (0, _tfjsCore.transpose)(t, [0, 2, 3, 1]);
  31132. var i = n.size[0] * r[2],
  31133. a = n.size[1] * r[3],
  31134. o = t.resizeNearestNeighbor([i, a]);
  31135. return (0, _tfjsCore.transpose)(o, [0, 3, 1, 2]);
  31136. }
  31137. i = n.size[0] * r[1], a = n.size[1] * r[2];
  31138. return t.resizeNearestNeighbor([i, a]);
  31139. });
  31140. }, t.prototype.getConfig = function () {
  31141. var t = {
  31142. size: this.size,
  31143. dataFormat: this.dataFormat
  31144. },
  31145. n = e.prototype.getConfig.call(this);
  31146. return Object.assign(t, n), t;
  31147. }, t.className = "UpSampling2D", t;
  31148. }(Layer);
  31149. function depthwiseConv2d$1(e, t, n, r, i, a) {
  31150. return void 0 === n && (n = [1, 1]), void 0 === r && (r = "valid"), (0, _tfjsCore.tidy)(function () {
  31151. null == i && (i = imageDataFormat()), checkDataFormat(i);
  31152. var o = preprocessConv2DInput(e, i);
  31153. if (4 !== e.rank) throw new ValueError("Input for depthwiseConv2d is required to be 4-D, but is instead " + e.rank + "-D");
  31154. if (4 !== t.rank) throw new ValueError("depthwiseKernel is required to be 4-D, but is instead " + t.rank + "-D");
  31155. return o = (0, _tfjsCore.depthwiseConv2d)(o, t, n, "same" === r ? "same" : "valid", "NHWC", a), "channelsFirst" === i && (o = (0, _tfjsCore.transpose)(o, [0, 3, 1, 2])), o;
  31156. });
  31157. }
  31158. _tfjsCore.serialization.registerClass(UpSampling2D);
  31159. var DepthwiseConv2D = function (e) {
  31160. function t(t) {
  31161. var n = e.call(this, 2, t) || this;
  31162. return n.depthwiseKernel = null, n.depthMultiplier = null == t.depthMultiplier ? 1 : t.depthMultiplier, n.depthwiseInitializer = getInitializer(t.depthwiseInitializer || n.DEFAULT_KERNEL_INITIALIZER), n.depthwiseConstraint = getConstraint(t.depthwiseConstraint), n.depthwiseRegularizer = getRegularizer(t.depthwiseRegularizer), n;
  31163. }
  31164. return __extends(t, e), t.prototype.build = function (e) {
  31165. if ((e = getExactlyOneShape(e)).length < 4) throw new ValueError("Inputs to DepthwiseConv2D should have rank 4. Received input shape: " + JSON.stringify(e) + ".");
  31166. var t = "channelsFirst" === this.dataFormat ? 1 : 3;
  31167. if (null == e[t] || e[t] < 0) throw new ValueError("The channel dimension of the inputs to DepthwiseConv2D should be defined, but is not (" + e[t] + ").");
  31168. var n = e[t],
  31169. r = [this.kernelSize[0], this.kernelSize[1], n, this.depthMultiplier];
  31170. this.depthwiseKernel = this.addWeight("depthwise_kernel", r, null, this.depthwiseInitializer, this.depthwiseRegularizer, !0, this.depthwiseConstraint), this.useBias ? this.bias = this.addWeight("bias", [n * this.depthMultiplier], null, this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint) : this.bias = null, this.built = !0;
  31171. }, t.prototype.call = function (e, t) {
  31172. var n = this;
  31173. return (0, _tfjsCore.tidy)(function () {
  31174. var t = depthwiseConv2d$1(e = getExactlyOneTensor(e), n.depthwiseKernel.read(), n.strides, n.padding, n.dataFormat, null);
  31175. return n.useBias && (t = biasAdd(t, n.bias.read(), n.dataFormat)), null != n.activation && (t = n.activation.apply(t)), t;
  31176. });
  31177. }, t.prototype.computeOutputShape = function (e) {
  31178. e = getExactlyOneShape(e);
  31179. var t = "channelsFirst" === this.dataFormat ? e[2] : e[1],
  31180. n = "channelsFirst" === this.dataFormat ? e[3] : e[2],
  31181. r = "channelsFirst" === this.dataFormat ? e[1] * this.depthMultiplier : e[3] * this.depthMultiplier,
  31182. i = convOutputLength(t, this.kernelSize[0], this.padding, this.strides[0]),
  31183. a = convOutputLength(n, this.kernelSize[1], this.padding, this.strides[1]);
  31184. return "channelsFirst" === this.dataFormat ? [e[0], r, i, a] : [e[0], i, a, r];
  31185. }, t.prototype.getConfig = function () {
  31186. var t = e.prototype.getConfig.call(this);
  31187. return t.depthMultiplier = this.depthMultiplier, t.depthwiseInitializer = serializeInitializer(this.depthwiseInitializer), t.depthwiseRegularizer = serializeRegularizer(this.depthwiseRegularizer), t.depthwiseConstraint = serializeConstraint(this.depthwiseRegularizer), t;
  31188. }, t.className = "DepthwiseConv2D", t;
  31189. }(BaseConv);
  31190. _tfjsCore.serialization.registerClass(DepthwiseConv2D);
  31191. var Dropout = function (e) {
  31192. function t(t) {
  31193. var n = e.call(this, t) || this;
  31194. return n.rate = Math.max(Math.min(t.rate, 1), 0), n.noiseShape = t.noiseShape, n.seed = t.seed, n.supportsMasking = !0, n;
  31195. }
  31196. return __extends(t, e), t.prototype.getNoiseShape = function (e) {
  31197. if (null == this.noiseShape) return this.noiseShape;
  31198. for (var t = e.shape, n = [], r = 0; r < this.noiseShape.length; ++r) n.push(null == this.noiseShape[r] ? t[r] : this.noiseShape[r]);
  31199. return n;
  31200. }, t.prototype.call = function (e, t) {
  31201. var n = this;
  31202. return (0, _tfjsCore.tidy)(function () {
  31203. n.invokeCallHook(e, t);
  31204. var r = getExactlyOneTensor(e);
  31205. if (0 < n.rate && n.rate < 1) {
  31206. var i = null != t.training && t.training,
  31207. a = n.getNoiseShape(r);
  31208. return inTrainPhase(function () {
  31209. return dropout$1(r, n.rate, a, n.seed);
  31210. }, function () {
  31211. return r;
  31212. }, i);
  31213. }
  31214. return e;
  31215. });
  31216. }, t.prototype.getConfig = function () {
  31217. var t = {
  31218. rate: this.rate,
  31219. noiseShape: this.noiseShape,
  31220. seed: this.seed
  31221. },
  31222. n = e.prototype.getConfig.call(this);
  31223. return Object.assign(t, n), t;
  31224. }, t.prototype.dispose = function () {
  31225. return e.prototype.dispose.call(this);
  31226. }, t.className = "Dropout", t;
  31227. }(Layer);
  31228. _tfjsCore.serialization.registerClass(Dropout);
  31229. var Dense = function (e) {
  31230. function t(t) {
  31231. var n = e.call(this, t) || this;
  31232. if (n.activation = null, n.useBias = !0, n.kernel = null, n.bias = null, n.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", n.DEFAULT_BIAS_INITIALIZER = "zeros", null == t.batchInputShape && null == t.inputShape && null != t.inputDim) {
  31233. var r = null;
  31234. null != t.batchSize && (r = t.batchSize), n.batchInputShape = [r, t.inputDim];
  31235. }
  31236. return n.units = t.units, assertPositiveInteger(n.units, "units"), n.activation = getActivation(t.activation), null != t.useBias && (n.useBias = t.useBias), n.kernelInitializer = getInitializer(t.kernelInitializer || n.DEFAULT_KERNEL_INITIALIZER), n.biasInitializer = getInitializer(t.biasInitializer || n.DEFAULT_BIAS_INITIALIZER), n.kernelConstraint = getConstraint(t.kernelConstraint), n.biasConstraint = getConstraint(t.biasConstraint), n.kernelRegularizer = getRegularizer(t.kernelRegularizer), n.biasRegularizer = getRegularizer(t.biasRegularizer), n.activityRegularizer = getRegularizer(t.activityRegularizer), n.supportsMasking = !0, n.inputSpec = [{
  31237. minNDim: 2
  31238. }], n;
  31239. }
  31240. return __extends(t, e), t.prototype.build = function (e) {
  31241. var t,
  31242. n = (e = getExactlyOneShape(e))[e.length - 1];
  31243. null == this.kernel && (this.kernel = this.addWeight("kernel", [n, this.units], null, this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.useBias && (this.bias = this.addWeight("bias", [this.units], null, this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint))), this.inputSpec = [{
  31244. minNDim: 2,
  31245. axes: (t = {}, t[-1] = n, t)
  31246. }], this.built = !0;
  31247. }, t.prototype.computeOutputShape = function (e) {
  31248. var t = (e = getExactlyOneShape(e)).slice();
  31249. return t[t.length - 1] = this.units, t;
  31250. }, t.prototype.call = function (e, t) {
  31251. var n = this;
  31252. return (0, _tfjsCore.tidy)(function () {
  31253. n.invokeCallHook(e, t);
  31254. var r,
  31255. i = getExactlyOneTensor(e),
  31256. a = mapActivationToFusedKernel(n.activation.getClassName());
  31257. return null != a ? r = dot(i, n.kernel.read(), a, n.bias ? n.bias.read() : null) : (r = dot(i, n.kernel.read()), null != n.bias && (r = biasAdd(r, n.bias.read())), null != n.activation && (r = n.activation.apply(r))), r;
  31258. });
  31259. }, t.prototype.getConfig = function () {
  31260. var t = {
  31261. units: this.units,
  31262. activation: serializeActivation(this.activation),
  31263. useBias: this.useBias,
  31264. kernelInitializer: serializeInitializer(this.kernelInitializer),
  31265. biasInitializer: serializeInitializer(this.biasInitializer),
  31266. kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
  31267. biasRegularizer: serializeRegularizer(this.biasRegularizer),
  31268. activityRegularizer: serializeRegularizer(this.activityRegularizer),
  31269. kernelConstraint: serializeConstraint(this.kernelConstraint),
  31270. biasConstraint: serializeConstraint(this.biasConstraint)
  31271. },
  31272. n = e.prototype.getConfig.call(this);
  31273. return Object.assign(t, n), t;
  31274. }, t.className = "Dense", t;
  31275. }(Layer);
  31276. _tfjsCore.serialization.registerClass(Dense);
  31277. var Flatten = function (e) {
  31278. function t(t) {
  31279. var n = e.call(this, t || {}) || this;
  31280. return n.inputSpec = [{
  31281. minNDim: 3
  31282. }], n;
  31283. }
  31284. return __extends(t, e), t.prototype.computeOutputShape = function (e) {
  31285. for (var t = 0, n = (e = getExactlyOneShape(e)).slice(1); t < n.length; t++) {
  31286. if (null == n[t]) throw new ValueError('The shape of the input to "Flatten" is not fully defined (got ' + e.slice(1) + '). Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model.');
  31287. }
  31288. return [e[0], arrayProd(e, 1)];
  31289. }, t.prototype.call = function (e, t) {
  31290. var n = this;
  31291. return (0, _tfjsCore.tidy)(function () {
  31292. return n.invokeCallHook(e, t), batchFlatten(getExactlyOneTensor(e));
  31293. });
  31294. }, t.className = "Flatten", t;
  31295. }(Layer);
  31296. _tfjsCore.serialization.registerClass(Flatten);
  31297. var Activation$1 = function (e) {
  31298. function t(t) {
  31299. var n = e.call(this, t) || this;
  31300. return n.supportsMasking = !0, n.activation = getActivation(t.activation), n;
  31301. }
  31302. return __extends(t, e), t.prototype.call = function (e, t) {
  31303. var n = this;
  31304. return (0, _tfjsCore.tidy)(function () {
  31305. n.invokeCallHook(e, t);
  31306. var r = getExactlyOneTensor(e);
  31307. return n.activation.apply(r);
  31308. });
  31309. }, t.prototype.getConfig = function () {
  31310. var t = {
  31311. activation: serializeActivation(this.activation)
  31312. },
  31313. n = e.prototype.getConfig.call(this);
  31314. return Object.assign(t, n), t;
  31315. }, t.className = "Activation", t;
  31316. }(Layer);
  31317. _tfjsCore.serialization.registerClass(Activation$1);
  31318. var RepeatVector = function (e) {
  31319. function t(t) {
  31320. var n = e.call(this, t) || this;
  31321. return n.n = t.n, n.inputSpec = [{
  31322. ndim: 2
  31323. }], n;
  31324. }
  31325. return __extends(t, e), t.prototype.computeOutputShape = function (e) {
  31326. return [e[0], this.n, e[1]];
  31327. }, t.prototype.call = function (e, t) {
  31328. var n = this;
  31329. return (0, _tfjsCore.tidy)(function () {
  31330. return repeat(e = getExactlyOneTensor(e), n.n);
  31331. });
  31332. }, t.prototype.getConfig = function () {
  31333. var t = {
  31334. n: this.n
  31335. },
  31336. n = e.prototype.getConfig.call(this);
  31337. return Object.assign(t, n), t;
  31338. }, t.className = "RepeatVector", t;
  31339. }(Layer);
  31340. _tfjsCore.serialization.registerClass(RepeatVector);
  31341. var Reshape = function (e) {
  31342. function t(t) {
  31343. var n = e.call(this, t) || this;
  31344. n.targetShape = t.targetShape;
  31345. for (var r = 0; r < n.targetShape.length; ++r) n.isUnknown(n.targetShape[r]) && (n.targetShape[r] = null);
  31346. return n;
  31347. }
  31348. return __extends(t, e), t.prototype.isUnknown = function (e) {
  31349. return e < 0 || null == e;
  31350. }, t.prototype.fixUnknownDimension = function (e, t) {
  31351. for (var n = "Total size of new array must be unchanged.", r = t.slice(), i = 1, a = null, o = 0; o < r.length; ++o) {
  31352. var s = r[o];
  31353. if (this.isUnknown(s)) {
  31354. if (null !== a) throw new ValueError("Can only specifiy one unknown dimension.");
  31355. a = o;
  31356. } else i *= s;
  31357. }
  31358. var l = arrayProd(e);
  31359. if (null !== a) {
  31360. if (0 === i || l % i != 0) throw new ValueError(n);
  31361. r[a] = l / i;
  31362. } else if (l !== i) throw new ValueError(n);
  31363. return r;
  31364. }, t.prototype.computeOutputShape = function (e) {
  31365. for (var t = !1, n = 0; n < e.length; ++n) if (this.isUnknown(e[n])) {
  31366. t = !0;
  31367. break;
  31368. }
  31369. return t ? e.slice(0, 1).concat(this.targetShape) : e.slice(0, 1).concat(this.fixUnknownDimension(e.slice(1), this.targetShape));
  31370. }, t.prototype.call = function (e, t) {
  31371. var n = this;
  31372. return (0, _tfjsCore.tidy)(function () {
  31373. n.invokeCallHook(e, t);
  31374. var r = getExactlyOneTensor(e),
  31375. i = r.shape,
  31376. a = i.slice(0, 1).concat(n.fixUnknownDimension(i.slice(1), n.targetShape));
  31377. return r.reshape(a);
  31378. });
  31379. }, t.prototype.getConfig = function () {
  31380. var t = {
  31381. targetShape: this.targetShape
  31382. },
  31383. n = e.prototype.getConfig.call(this);
  31384. return Object.assign(t, n), t;
  31385. }, t.className = "Reshape", t;
  31386. }(Layer);
  31387. _tfjsCore.serialization.registerClass(Reshape);
  31388. var Permute = function (e) {
  31389. function t(t) {
  31390. var n = e.call(this, t) || this;
  31391. if (null == t.dims) throw new Error("Required configuration field `dims` is missing during Permute constructor call.");
  31392. if (!Array.isArray(t.dims)) throw new Error("Permute constructor requires `dims` to be an Array, but received " + t.dims + " instead.");
  31393. var r = range(1, t.dims.length + 1);
  31394. if (!_tfjsCore.util.arraysEqual(t.dims.slice().sort(), r)) throw new Error("Invalid permutation `dims`: " + JSON.stringify(t.dims) + " `dims` must contain consecutive integers starting from 1.");
  31395. return n.dims = t.dims, n.dimsIncludingBatch = [0].concat(n.dims), n.inputSpec = [new InputSpec({
  31396. ndim: n.dims.length + 1
  31397. })], n;
  31398. }
  31399. return __extends(t, e), t.prototype.computeOutputShape = function (e) {
  31400. var t = (e = getExactlyOneShape(e)).slice();
  31401. return this.dims.forEach(function (n, r) {
  31402. t[r + 1] = e[n];
  31403. }), t;
  31404. }, t.prototype.call = function (e, t) {
  31405. return (0, _tfjsCore.transpose)(getExactlyOneTensor(e), this.dimsIncludingBatch);
  31406. }, t.prototype.getConfig = function () {
  31407. var t = {
  31408. dims: this.dims
  31409. },
  31410. n = e.prototype.getConfig.call(this);
  31411. return Object.assign(t, n), t;
  31412. }, t.className = "Permute", t;
  31413. }(Layer);
  31414. _tfjsCore.serialization.registerClass(Permute);
  31415. var Masking = function (e) {
  31416. function t(t) {
  31417. var n = e.call(this, null == t ? {} : t) || this;
  31418. return n.supportsMasking = !0, n.maskValue = null != t ? null == t.maskValue ? 0 : t.maskValue : 0, n;
  31419. }
  31420. return __extends(t, e), t.prototype.computeOutputShape = function (e) {
  31421. return e;
  31422. }, t.prototype.getConfig = function () {
  31423. var t = e.prototype.getConfig.call(this),
  31424. n = {
  31425. maskValue: this.maskValue
  31426. };
  31427. return Object.assign(n, t), n;
  31428. }, t.prototype.computeMask = function (e, t) {
  31429. var n = getExactlyOneTensor(e);
  31430. return (0, _tfjsCore.any)((0, _tfjsCore.notEqual)(n, this.maskValue), -1);
  31431. }, t.prototype.call = function (e, t) {
  31432. var n = this;
  31433. return (0, _tfjsCore.tidy)(function () {
  31434. n.invokeCallHook(e, t);
  31435. var r = getExactlyOneTensor(e),
  31436. i = (0, _tfjsCore.any)((0, _tfjsCore.notEqual)(r, n.maskValue), -1, !0);
  31437. return r.mul(i.asType(r.dtype));
  31438. });
  31439. }, t.className = "Masking", t;
  31440. }(Layer);
  31441. _tfjsCore.serialization.registerClass(Masking);
  31442. var Embedding = function (e) {
  31443. function t(t) {
  31444. var n = e.call(this, t) || this;
  31445. if (n.embeddings = null, n.DEFAULT_EMBEDDINGS_INITIALIZER = "randomUniform", null == t.batchInputShape && null == t.inputShape) {
  31446. var r = null;
  31447. null != t.batchSize && (r = t.batchSize), null == t.inputLength ? n.batchInputShape = [r, null] : n.batchInputShape = [r].concat(toList(t.inputLength));
  31448. }
  31449. return n.inputDim = t.inputDim, assertPositiveInteger(n.inputDim, "inputDim"), n.outputDim = t.outputDim, assertPositiveInteger(n.outputDim, "outputDim"), n.embeddingsInitializer = getInitializer(t.embeddingsInitializer || n.DEFAULT_EMBEDDINGS_INITIALIZER), n.embeddingsRegularizer = getRegularizer(t.embeddingsRegularizer), n.activityRegularizer = getRegularizer(t.activityRegularizer), n.embeddingsConstraint = getConstraint(t.embeddingsConstraint), n.maskZero = t.maskZero, n.supportsMasking = t.maskZero, n.inputLength = t.inputLength, n;
  31450. }
  31451. return __extends(t, e), t.prototype.build = function (e) {
  31452. this.embeddings = this.addWeight("embeddings", [this.inputDim, this.outputDim], this.dtype, this.embeddingsInitializer, this.embeddingsRegularizer, !0, this.embeddingsConstraint), this.built = !0;
  31453. }, t.prototype.warnOnIncompatibleInputShape = function (e) { }, t.prototype.computeMask = function (e, t) {
  31454. var n = this;
  31455. return (0, _tfjsCore.tidy)(function () {
  31456. return n.maskZero ? (e = getExactlyOneTensor(e), (0, _tfjsCore.notEqual)(e, (0, _tfjsCore.zerosLike)(e))) : null;
  31457. });
  31458. }, t.prototype.computeOutputShape = function (e) {
  31459. if (e = getExactlyOneShape(e), null == this.inputLength) return e.concat([this.outputDim]);
  31460. var t = toList(this.inputLength);
  31461. if (t.length !== e.length - 1) throw new ValueError('"inputLength" is ' + this.inputLength + ", but received input shape has shape " + e);
  31462. for (var n = 0, r = 0; r < t.length; ++r) {
  31463. var i = t[r],
  31464. a = e[r + 1];
  31465. if (null != i && null != a && i !== a) throw new ValueError('"inputLength" is ' + this.inputLength + ", but received input shape has shape " + e);
  31466. null == i && (t[n] = a), n++;
  31467. }
  31468. return [e[0]].concat(t, [this.outputDim]);
  31469. }, t.prototype.call = function (e, t) {
  31470. var n = this;
  31471. return (0, _tfjsCore.tidy)(function () {
  31472. n.invokeCallHook(e, t);
  31473. var r = getExactlyOneTensor(e);
  31474. return "int32" !== r.dtype && (r = cast$1(r, "int32")), gather$1(n.embeddings.read(), r.as1D()).reshape(getExactlyOneShape(n.computeOutputShape(r.shape)));
  31475. });
  31476. }, t.prototype.getConfig = function () {
  31477. var t = {
  31478. inputDim: this.inputDim,
  31479. outputDim: this.outputDim,
  31480. embeddingsInitializer: serializeInitializer(this.embeddingsInitializer),
  31481. embeddingsRegularizer: serializeRegularizer(this.embeddingsRegularizer),
  31482. activityRegularizer: serializeRegularizer(this.activityRegularizer),
  31483. embeddingsConstraint: serializeConstraint(this.embeddingsConstraint),
  31484. maskZero: this.maskZero,
  31485. inputLength: this.inputLength
  31486. },
  31487. n = e.prototype.getConfig.call(this);
  31488. return Object.assign(t, n), t;
  31489. }, t.className = "Embedding", t;
  31490. }(Layer);
  31491. _tfjsCore.serialization.registerClass(Embedding);
  31492. var Merge = function (e) {
  31493. function t(t) {
  31494. var n = e.call(this, t || {}) || this;
  31495. return n.supportsMasking = !0, n;
  31496. }
  31497. return __extends(t, e), t.prototype.mergeFunction = function (e) {
  31498. throw new NotImplementedError();
  31499. }, t.prototype.computeElementwiseOpOutputShape = function (e, t) {
  31500. if (null == e || null == t) return null;
  31501. if (e.length < t.length) return this.computeElementwiseOpOutputShape(t, e);
  31502. if (0 === t.length) return e;
  31503. for (var n = e.slice(0, e.length - t.length), r = 0; r < t.length; ++r) {
  31504. var i = e[e.length - t.length + r],
  31505. a = t[r];
  31506. if (null == i || null == a || i < 0 || a < 0) n.push(null); else if (1 === i) n.push(a); else if (1 === a) n.push(i); else {
  31507. if (i !== a) throw new ValueError("Operands could not be broadcast together with shapes " + JSON.stringify(e) + " " + JSON.stringify(t));
  31508. n.push(i);
  31509. }
  31510. }
  31511. return n;
  31512. }, t.prototype.build = function (e) {
  31513. if (Array.isArray(e) && !Array.isArray(e[0]) && (e = [getExactlyOneShape(e)]), (e = e).length < 2) throw new ValueError("A merge layer should be called on an Array of at least 2 inputs. Got " + e.length + " input(s).");
  31514. for (var t = [], n = 0, r = e; n < r.length; n++) {
  31515. null != (o = r[n]) && null !== o[0] && t.push(o[0]);
  31516. }
  31517. if ((t = unique(t)).length > 1) throw new ValueError("Can not merge tensors with different batch sizes. Got tensors with shapes: " + JSON.stringify(e) + ".");
  31518. for (var i = null == e[0] ? null : e[0].slice(1), a = 1; a < e.length; ++a) {
  31519. var o = null == e[a] ? null : e[a].slice(1);
  31520. i = this.computeElementwiseOpOutputShape(i, o);
  31521. }
  31522. var s = e.map(function (e) {
  31523. return e.length;
  31524. });
  31525. -1 === e.indexOf(null) && 1 === unique(s).length ? this.reshapeRequired = !1 : this.reshapeRequired = !0;
  31526. }, t.prototype.call = function (e, t) {
  31527. var n = this;
  31528. return (0, _tfjsCore.tidy)(function () {
  31529. if (e = e, n.reshapeRequired) {
  31530. var t = [],
  31531. r = e.map(function (e) {
  31532. return e.rank;
  31533. });
  31534. if (-1 === r.indexOf(null)) {
  31535. for (var i = max$1(r), a = 0, o = e; a < o.length; a++) {
  31536. for (var s = (h = o[a]).rank, l = 0; l < i - s; ++l) h = expandDims$1(h, 1);
  31537. t.push(h);
  31538. }
  31539. return n.mergeFunction(t);
  31540. }
  31541. for (var u = !1, c = 0, p = e; c < p.length; c++) {
  31542. var h;
  31543. if (null == (s = (h = p[c]).rank)) {
  31544. var d = h.shape,
  31545. f = d[0],
  31546. g = d.slice(1).concat([f]),
  31547. m = h.reshape([f].concat(arrayProd(d.slice(1))));
  31548. m = (m = (0, _tfjsCore.transpose)(m, [1, 0])).reshape(g), t.push(m), u = !0;
  31549. } else if (s > 1) {
  31550. var y = range(1, s).concat([0]);
  31551. t.push((0, _tfjsCore.transpose)(h, y)), u = !0;
  31552. } else t.push(h);
  31553. }
  31554. var v = n.mergeFunction(t),
  31555. b = v.rank;
  31556. if (u) if (null == b) {
  31557. var w = v.shape;
  31558. g = [f = w[w.length - 1]].concat(w.slice(0, w.length - 1));
  31559. v = (0, _tfjsCore.transpose)(v.reshape([-1, f]), [1, 0]).reshape(g);
  31560. } else if (b > 1) {
  31561. y = [b - 1].concat(range(0, b - 1));
  31562. v = (0, _tfjsCore.transpose)(v, y);
  31563. }
  31564. return v;
  31565. }
  31566. return n.mergeFunction(e);
  31567. });
  31568. }, t.prototype.computeOutputShape = function (e) {
  31569. var t;
  31570. t = null == (e = e)[0] ? null : e[0].slice(1);
  31571. for (var n = 1; n < e.length; ++n) {
  31572. var r = null == e[n] ? null : e[n].slice(1);
  31573. t = this.computeElementwiseOpOutputShape(t, r);
  31574. }
  31575. for (var i = [], a = 0, o = e; a < o.length; a++) {
  31576. null != (r = o[a]) && null !== r[0] && i.push(r[0]);
  31577. }
  31578. return t = 1 === (i = unique(i)).length ? i.concat(t) : [null].concat(t);
  31579. }, t.prototype.computeMask = function (e, t) {
  31580. return (0, _tfjsCore.tidy)(function () {
  31581. if (null == t) return null;
  31582. if (!Array.isArray(t)) throw new ValueError("`mask` should be an Array");
  31583. if (!Array.isArray(e)) throw new ValueError("`inputs` should be an Array");
  31584. if (t.length !== e.length) throw new ValueError("The Array 'inputs' and 'mask' are expected to have the same length, but have different lengths (" + e.length + " vs " + t.length + ")");
  31585. if (t.every(function (e) {
  31586. return null == e;
  31587. })) return null;
  31588. for (var n = (t = t.map(function (e) {
  31589. return null == e ? e : (0, _tfjsCore.expandDims)(e, 0);
  31590. }))[0], r = 1; r < t.length - 1; ++r) n = (0, _tfjsCore.logicalAnd)(n, t[r]);
  31591. return n;
  31592. });
  31593. }, t;
  31594. }(Layer),
  31595. Add = function (e) {
  31596. function t(t) {
  31597. return e.call(this, t) || this;
  31598. }
  31599. return __extends(t, e), t.prototype.mergeFunction = function (e) {
  31600. return (0, _tfjsCore.tidy)(function () {
  31601. for (var t = e[0].clone(), n = 1; n < e.length; ++n) t = (0, _tfjsCore.add)(t, e[n]);
  31602. return t;
  31603. });
  31604. }, t.className = "Add", t;
  31605. }(Merge);
  31606. _tfjsCore.serialization.registerClass(Add);
  31607. var Multiply = function (e) {
  31608. function t(t) {
  31609. return e.call(this, t) || this;
  31610. }
  31611. return __extends(t, e), t.prototype.mergeFunction = function (e) {
  31612. return (0, _tfjsCore.tidy)(function () {
  31613. for (var t = e[0].clone(), n = 1; n < e.length; ++n) t = (0, _tfjsCore.mul)(t, e[n]);
  31614. return t;
  31615. });
  31616. }, t.className = "Multiply", t;
  31617. }(Merge);
  31618. _tfjsCore.serialization.registerClass(Multiply);
  31619. var Average = function (e) {
  31620. function t(t) {
  31621. return e.call(this, t) || this;
  31622. }
  31623. return __extends(t, e), t.prototype.mergeFunction = function (e) {
  31624. return (0, _tfjsCore.tidy)(function () {
  31625. for (var t = e[0].clone(), n = 1; n < e.length; ++n) t = (0, _tfjsCore.add)(t, e[n]);
  31626. return (0, _tfjsCore.mul)(1 / e.length, t);
  31627. });
  31628. }, t.className = "Average", t;
  31629. }(Merge);
  31630. _tfjsCore.serialization.registerClass(Average);
  31631. var Maximum = function (e) {
  31632. function t(t) {
  31633. return e.call(this, t) || this;
  31634. }
  31635. return __extends(t, e), t.prototype.mergeFunction = function (e) {
  31636. return (0, _tfjsCore.tidy)(function () {
  31637. for (var t = e[0], n = 1; n < e.length; ++n) t = (0, _tfjsCore.maximum)(t, e[n]);
  31638. return t;
  31639. });
  31640. }, t.className = "Maximum", t;
  31641. }(Merge);
  31642. _tfjsCore.serialization.registerClass(Maximum);
  31643. var Minimum = function (e) {
  31644. function t(t) {
  31645. return e.call(this, t) || this;
  31646. }
  31647. return __extends(t, e), t.prototype.mergeFunction = function (e) {
  31648. return (0, _tfjsCore.tidy)(function () {
  31649. for (var t = e[0], n = 1; n < e.length; ++n) t = (0, _tfjsCore.minimum)(t, e[n]);
  31650. return t;
  31651. });
  31652. }, t.className = "Minimum", t;
  31653. }(Merge);
  31654. _tfjsCore.serialization.registerClass(Minimum);
  31655. var Concatenate = function (e) {
  31656. function t(t) {
  31657. var n = e.call(this, t) || this;
  31658. return n.DEFAULT_AXIS = -1, null == t && (t = {}), n.axis = null == t.axis ? n.DEFAULT_AXIS : t.axis, n.supportsMasking = !0, n.reshapeRequired = !1, n;
  31659. }
  31660. return __extends(t, e), t.prototype.build = function (e) {
  31661. if (!Array.isArray(e) || !Array.isArray(e[0]) || 1 === e.length) throw new ValueError("A `Concatenate` layer should be called on a list of at least 2 inputs");
  31662. for (var t = !0, n = 0, r = e = e; n < r.length; n++) {
  31663. if (null != (c = r[n])) {
  31664. t = !1;
  31665. break;
  31666. }
  31667. }
  31668. if (!t) {
  31669. for (var i = [], a = 0; a < e.length; ++a) {
  31670. var o = e[a].slice();
  31671. o.splice(this.axis, 1);
  31672. for (var s = !1, l = 0, u = i; l < u.length; l++) {
  31673. var c = u[l];
  31674. if (_tfjsCore.util.arraysEqual(c, o)) {
  31675. s = !0;
  31676. break;
  31677. }
  31678. }
  31679. s || i.push(o);
  31680. }
  31681. if (i.length > 1) throw new ValueError("A `Concatenate` layer requires inputs with matching shapes except for the concat axis. Got input shapes: " + JSON.stringify(e));
  31682. }
  31683. }, t.prototype.mergeFunction = function (e) {
  31684. var t = this;
  31685. return (0, _tfjsCore.tidy)(function () {
  31686. return concatenate(e, t.axis);
  31687. });
  31688. }, t.prototype.computeOutputShape = function (e) {
  31689. if (!Array.isArray(e) || !Array.isArray(e[0])) throw new ValueError("A `Concatenate` layer should be called on a list of inputs.");
  31690. for (var t = e, n = t[0].slice(), r = this.axis < 0 ? n.length + this.axis : this.axis, i = 0, a = t.slice(1); i < a.length; i++) {
  31691. var o = a[i];
  31692. if (null == n[r] || null == o[r]) {
  31693. n[r] = null;
  31694. break;
  31695. }
  31696. n[r] += o[r];
  31697. }
  31698. return n;
  31699. }, t.prototype.computeMask = function (e, t) {
  31700. var n = this;
  31701. if (null == t) return null;
  31702. if (!Array.isArray(t)) throw new ValueError("`mask` should be an array for Concatenate");
  31703. if (!Array.isArray(e)) throw new ValueError("`inputs` should be an array for Concatenate");
  31704. if (t.length !== e.length) throw new ValueError("Mismatch in the length of mask (" + t.length + ") and the legnth of inputs (" + e.length + ")");
  31705. return (0, _tfjsCore.tidy)(function () {
  31706. var r = !0;
  31707. if (t.forEach(function (e) {
  31708. null == e || (r = !1);
  31709. }), r) return null;
  31710. for (var i = [], a = 0; a < e.length; ++a) null == t[a] ? i.push((0, _tfjsCore.onesLike)(e[a]).asType("bool")) : t[a].rank < e[a].rank ? i.push((0, _tfjsCore.expandDims)(t[a], -1)) : i.push(t[a]);
  31711. var o = (0, _tfjsCore.concat)(i, n.axis);
  31712. return (0, _tfjsCore.all)(o, -1, !1);
  31713. });
  31714. }, t.prototype.getConfig = function () {
  31715. var t = {
  31716. axis: this.axis
  31717. },
  31718. n = e.prototype.getConfig.call(this);
  31719. return Object.assign(t, n), t;
  31720. }, t.className = "Concatenate", t;
  31721. }(Merge);
  31722. function interpretAxis(e, t) {
  31723. for (; e < 0;) e += t;
  31724. return e;
  31725. }
  31726. function batchDot(e, t, n) {
  31727. if (e.shape.length > 3 || t.shape.length > 3) throw new NotImplementedError("batchDot is not implemented for tensors of 4D or higher rank yet");
  31728. if (_tfjsCore.util.assert(e.shape.length >= 2, function () {
  31729. return "batchDot requires the rank of x to be >= 2, but got " + e.shape.length;
  31730. }), _tfjsCore.util.assert(e.shape.length >= 2, function () {
  31731. return "batchDot requires the rank of y to be >= 2, but got " + t.shape.length;
  31732. }), "number" == typeof n && (n = [n, n]), "complex64" === e.dtype || "complex64" === t.dtype) throw new NotImplementedError("batchDot is not implemented for complex64-type Tensors yet.");
  31733. var r = e.shape.length,
  31734. i = t.shape.length;
  31735. null == n && (n = [r - 1, i - 2]);
  31736. var a = n;
  31737. return (0, _tfjsCore.tidy)(function () {
  31738. var n, o;
  31739. if (r > i) {
  31740. n = r - i;
  31741. for (var s = [], l = 0; l < n; ++l) s.push(1);
  31742. t = t.reshape(t.shape.concat(s));
  31743. } else if (i > r) {
  31744. n = i - r;
  31745. for (s = [], l = 0; l < n; ++l) s.push(1);
  31746. e = e.reshape(e.shape.concat(s));
  31747. } else n = 0;
  31748. if (2 === e.shape.length && 2 === t.shape.length) o = a[0] === a[1] ? e.mulStrict(t).sum(a[0]) : e.transpose([1, 0]).mulStrict(t).sum(a[1]); else {
  31749. var u = a[0] !== e.shape.length - 1,
  31750. c = a[1] === t.shape.length - 1;
  31751. o = e.matMul(t, u, c);
  31752. }
  31753. if (n > 0) {
  31754. var p = void 0,
  31755. h = [];
  31756. for (l = p = r > i ? r + i - 3 : r - 1; l < p + n; ++l) h.push(l);
  31757. o = o.squeeze(h);
  31758. }
  31759. return 1 === o.shape.length && (o = o.expandDims(1)), o;
  31760. });
  31761. }
  31762. _tfjsCore.serialization.registerClass(Concatenate);
  31763. var Dot = function (e) {
  31764. function t(t) {
  31765. var n = e.call(this, t) || this;
  31766. return n.axes = t.axes, n.normalize = null != t.normalize && t.normalize, n.supportsMasking = !0, n.reshapeRequired = !1, n;
  31767. }
  31768. return __extends(t, e), t.prototype.build = function (e) {
  31769. _tfjsCore.util.assert(Array.isArray(e) && 2 === e.length && Array.isArray(e[0]) && Array.isArray(e[1]), function () {
  31770. return "A `Dot` layer should be called on a list of exactly 2 inputs.";
  31771. });
  31772. var t = e[0],
  31773. n = e[1];
  31774. if (t.length > 3 || n.length > 3) throw new NotImplementedError("Dot layer does not support tensors of 4D or higher rank yet.");
  31775. var r = this.interpretAxes(t, n);
  31776. if (t[r[0]] !== n[r[1]]) throw new ValueError("Dimension incompatibility: " + t[r[0]] + " !== " + n[r[1]]);
  31777. }, t.prototype.mergeFunction = function (e) {
  31778. if (2 !== e.length) throw new ValueError("A `Dot` layer must be called on exactly 2 inputs, but received " + e.length + " input(s).");
  31779. var t,
  31780. n = e[0],
  31781. r = e[1];
  31782. return t = Array.isArray(this.axes) ? this.axes.map(function (t, n) {
  31783. return interpretAxis(t, e[n].shape.length);
  31784. }) : [interpretAxis(this.axes, n.shape.length), interpretAxis(this.axes, r.shape.length)], this.normalize && (n = l2Normalize(n, t[0]), r = l2Normalize(r, t[1])), batchDot(n, r, t);
  31785. }, t.prototype.interpretAxes = function (e, t) {
  31786. return Array.isArray(this.axes) ? this.axes : [interpretAxis(this.axes, e.length), interpretAxis(this.axes, t.length)];
  31787. }, t.prototype.computeOutputShape = function (e) {
  31788. _tfjsCore.util.assert(Array.isArray(e) && 2 === e.length && Array.isArray(e[0]) && Array.isArray(e[1]), function () {
  31789. return "A `Dot` layer should be called on a list of exactly 2 inputs.";
  31790. });
  31791. var t = e[0].slice(),
  31792. n = e[1].slice();
  31793. if (t.length > 3 || n.length > 3) throw new NotImplementedError("Dot layer does not support tensors of 4D or higher rank yet.");
  31794. var r = this.interpretAxes(t, n);
  31795. t.splice(r[0], 1), n.splice(r[1], 1), n.splice(0, 1);
  31796. var i = t.concat(n);
  31797. return 1 === i.length && i.push(1), i;
  31798. }, t.prototype.computeMask = function (e, t) {
  31799. return null;
  31800. }, t.prototype.getConfig = function () {
  31801. var t = {
  31802. axes: this.axes,
  31803. normalize: this.normalize
  31804. },
  31805. n = e.prototype.getConfig.call(this);
  31806. return Object.assign(t, n), t;
  31807. }, t.className = "Dot", t;
  31808. }(Merge);
  31809. _tfjsCore.serialization.registerClass(Dot);
  31810. var GaussianNoise = function (e) {
  31811. function t(t) {
  31812. var n = e.call(this, t) || this;
  31813. return n.supportsMasking = !0, n.stddev = t.stddev, n;
  31814. }
  31815. return __extends(t, e), t.prototype.computeOutputShape = function (e) {
  31816. return e;
  31817. }, t.prototype.getConfig = function () {
  31818. var t = e.prototype.getConfig.call(this),
  31819. n = {
  31820. stddev: this.stddev
  31821. };
  31822. return Object.assign(n, t), n;
  31823. }, t.prototype.call = function (e, t) {
  31824. var n = this;
  31825. return (0, _tfjsCore.tidy)(function () {
  31826. n.invokeCallHook(e, t);
  31827. var r = getExactlyOneTensor(e);
  31828. return inTrainPhase(function () {
  31829. return randomNormal$1(r.shape, 0, n.stddev).add(r);
  31830. }, function () {
  31831. return r;
  31832. }, t.training || !1);
  31833. });
  31834. }, t.className = "GaussianNoise", t;
  31835. }(Layer);
  31836. _tfjsCore.serialization.registerClass(GaussianNoise);
  31837. var GaussianDropout = function (e) {
  31838. function t(t) {
  31839. var n = e.call(this, t) || this;
  31840. return n.supportsMasking = !0, n.rate = t.rate, n;
  31841. }
  31842. return __extends(t, e), t.prototype.computeOutputShape = function (e) {
  31843. return e;
  31844. }, t.prototype.getConfig = function () {
  31845. var t = e.prototype.getConfig.call(this),
  31846. n = {
  31847. rate: this.rate
  31848. };
  31849. return Object.assign(n, t), n;
  31850. }, t.prototype.call = function (e, t) {
  31851. var n = this;
  31852. return (0, _tfjsCore.tidy)(function () {
  31853. n.invokeCallHook(e, t);
  31854. var r = getExactlyOneTensor(e);
  31855. if (n.rate > 0 && n.rate < 1) {
  31856. return inTrainPhase(function () {
  31857. var e = Math.sqrt(n.rate / (1 - n.rate));
  31858. return r.mul(randomNormal$1(r.shape, 1, e));
  31859. }, function () {
  31860. return r;
  31861. }, t.training || !1);
  31862. }
  31863. return r;
  31864. });
  31865. }, t.className = "GaussianDropout", t;
  31866. }(Layer);
  31867. _tfjsCore.serialization.registerClass(GaussianDropout);
  31868. var AlphaDropout = function (e) {
  31869. function t(t) {
  31870. var n = e.call(this, t) || this;
  31871. return n.supportsMasking = !0, n.rate = t.rate, n.noiseShape = t.noiseShape, n;
  31872. }
  31873. return __extends(t, e), t.prototype._getNoiseShape = function (e) {
  31874. return this.noiseShape || getExactlyOneTensor(e).shape;
  31875. }, t.prototype.computeOutputShape = function (e) {
  31876. return e;
  31877. }, t.prototype.getConfig = function () {
  31878. var t = e.prototype.getConfig.call(this),
  31879. n = {
  31880. rate: this.rate
  31881. };
  31882. return Object.assign(n, t), n;
  31883. }, t.prototype.call = function (e, t) {
  31884. var n = this;
  31885. return (0, _tfjsCore.tidy)(function () {
  31886. if (n.rate < 1 && n.rate > 0) {
  31887. var r = n._getNoiseShape(e);
  31888. return inTrainPhase(function () {
  31889. var t = getExactlyOneTensor(e),
  31890. i = -1.7580993408473766,
  31891. a = (0, _tfjsCore.greaterEqual)((0, _tfjsCore.randomUniform)(r), n.rate);
  31892. a = cast$1(a, "float32");
  31893. var o = Math.pow((1 - n.rate) * (1 + n.rate * Math.pow(i, 2)), -.5),
  31894. s = -o * i * n.rate;
  31895. return t.mul(a).add(a.add(-1).mul(i)).mul(o).add(s);
  31896. }, function () {
  31897. return getExactlyOneTensor(e);
  31898. }, t.training || !1);
  31899. }
  31900. return e;
  31901. });
  31902. }, t.className = "AlphaDropout", t;
  31903. }(Layer);
  31904. function batchNormalization(e, t, n, r, i, a) {
  31905. var o;
  31906. if (void 0 === a && (a = .001), 2 === e.rank) o = (0, _tfjsCore.batchNorm2d)(e, t, n, r, i, a); else if (3 === e.rank) o = (0, _tfjsCore.batchNorm3d)(e, t, n, r, i, a); else {
  31907. if (4 !== e.rank) throw new NotImplementedError("batchNormalization is not implemented for array of rank " + e.rank + " yet");
  31908. o = (0, _tfjsCore.batchNorm4d)(e, t, n, r, i, a);
  31909. }
  31910. return o;
  31911. }
  31912. function regularNormalizeBatchInTraining(e, t, n, r, i) {
  31913. return void 0 === i && (i = .001), (0, _tfjsCore.tidy)(function () {
  31914. var a = (0, _tfjsCore.moments)(e, r),
  31915. o = a.mean,
  31916. s = a.variance;
  31917. return [batchNormalization(e, o, s, n, t, i), o, s];
  31918. });
  31919. }
  31920. function broadcastNormalizeBatchInTraining(e, t, n, r, i) {
  31921. return void 0 === i && (i = .001), (0, _tfjsCore.tidy)(function () {
  31922. for (var a = (0, _tfjsCore.moments)(e, r), o = a.mean, s = a.variance, l = [], u = 0, c = range(0, e.rank); u < c.length; u++) {
  31923. var p = c[u];
  31924. -1 !== r.indexOf(p) ? l.push(1) : l.push(e.shape[p]);
  31925. }
  31926. var h = o.reshape(l),
  31927. d = s.reshape(l),
  31928. f = null == t ? null : t.reshape(l),
  31929. g = null == n ? null : n.reshape(l);
  31930. return [batchNormalization(e, h, d, g, f, i), o, s];
  31931. });
  31932. }
  31933. function normalizeBatchInTraining(e, t, n, r, i) {
  31934. return void 0 === i && (i = .001), _tfjsCore.util.arraysEqual(r.slice().sort(), range(0, e.rank - 1)) ? regularNormalizeBatchInTraining(e, t, n, r, i) : broadcastNormalizeBatchInTraining(e, t, n, r, i);
  31935. }
  31936. _tfjsCore.serialization.registerClass(AlphaDropout);
  31937. var BatchNormalization = function (e) {
  31938. function t(t) {
  31939. var n = this;
  31940. return null == t && (t = {}), (n = e.call(this, t) || this).supportsMasking = !0, n.axis = null == t.axis ? -1 : t.axis, n.momentum = null == t.momentum ? .99 : t.momentum, n.epsilon = null == t.epsilon ? .001 : t.epsilon, n.center = null == t.center || t.center, n.scale = null == t.scale || t.scale, n.betaInitializer = getInitializer(t.betaInitializer || "zeros"), n.gammaInitializer = getInitializer(t.gammaInitializer || "ones"), n.movingMeanInitializer = getInitializer(t.movingMeanInitializer || "zeros"), n.movingVarianceInitializer = getInitializer(t.movingVarianceInitializer || "ones"), n.betaConstraint = getConstraint(t.betaConstraint), n.gammaConstraint = getConstraint(t.gammaConstraint), n.betaRegularizer = getRegularizer(t.betaRegularizer), n.gammaRegularizer = getRegularizer(t.gammaRegularizer), n;
  31941. }
  31942. return __extends(t, e), t.prototype.build = function (e) {
  31943. var t;
  31944. e = getExactlyOneShape(e);
  31945. var n = this.axis >= 0 ? this.axis : this.axis + e.length,
  31946. r = e[n];
  31947. if (null == r) throw new ValueError("Axis " + n + " of input tensor should have a defined dimension but the layer received an input with shape " + JSON.stringify(e) + ".");
  31948. this.inputSpec = [new InputSpec({
  31949. ndim: e.length,
  31950. axes: (t = {}, t[n] = r, t)
  31951. })];
  31952. var i = [r];
  31953. this.scale && (this.gamma = this.addWeight("gamma", i, null, this.gammaInitializer, this.gammaRegularizer, !0, this.gammaConstraint)), this.center && (this.beta = this.addWeight("beta", i, null, this.betaInitializer, this.betaRegularizer, !0, this.betaConstraint)), this.movingMean = this.addWeight("moving_mean", i, null, this.movingMeanInitializer, null, !1), this.movingVariance = this.addWeight("moving_variance", i, null, this.movingVarianceInitializer, null, !1), this.built = !0;
  31954. }, t.prototype.call = function (e, t) {
  31955. var n = this;
  31956. return (0, _tfjsCore.tidy)(function () {
  31957. var r = null != t.training && t.training,
  31958. i = getExactlyOneTensor(e),
  31959. a = i.shape,
  31960. o = a.length,
  31961. s = range(0, o),
  31962. l = n.axis >= 0 ? n.axis : n.axis + o;
  31963. s.splice(l, 1);
  31964. var u = pyListRepeat(1, o);
  31965. u[l] = a[l];
  31966. var c = s.slice();
  31967. c.sort();
  31968. var p = !_tfjsCore.util.arraysEqual(c, range(0, o).slice(0, o - 1));
  31969. if (!r) return function () {
  31970. if (p) {
  31971. var e = n.movingMean.read().reshape(u),
  31972. t = n.movingVariance.read().reshape(u),
  31973. r = n.center ? n.beta.read().reshape(u) : null,
  31974. a = n.scale ? n.gamma.read().reshape(u) : null;
  31975. return batchNormalization(i, e, t, r, a, n.epsilon);
  31976. }
  31977. return batchNormalization(i, n.movingMean.read(), n.movingVariance.read(), null == n.beta ? null : n.beta.read(), null == n.gamma ? null : n.gamma.read(), n.epsilon);
  31978. }();
  31979. var h = normalizeBatchInTraining(i, n.gamma.read(), n.beta.read(), s, n.epsilon),
  31980. d = h[0],
  31981. f = h[1],
  31982. g = h[2],
  31983. m = function (e, t, n) {
  31984. (0, _tfjsCore.tidy)(function () {
  31985. var r = 1 - n,
  31986. i = e.read(),
  31987. a = i.sub(t).mul(r);
  31988. e.write(i.sub(a));
  31989. });
  31990. };
  31991. return m(n.movingMean, f, n.momentum), m(n.movingVariance, g, n.momentum), d;
  31992. });
  31993. }, t.prototype.getConfig = function () {
  31994. var t = {
  31995. axis: this.axis,
  31996. momentum: this.momentum,
  31997. epsilon: this.epsilon,
  31998. center: this.center,
  31999. scale: this.scale,
  32000. betaInitializer: serializeInitializer(this.betaInitializer),
  32001. gammaInitializer: serializeInitializer(this.gammaInitializer),
  32002. movingMeanInitializer: serializeInitializer(this.movingMeanInitializer),
  32003. movingVarianceInitializer: serializeInitializer(this.movingVarianceInitializer),
  32004. betaRegularizer: serializeRegularizer(this.betaRegularizer),
  32005. gammaRegularizer: serializeRegularizer(this.gammaRegularizer),
  32006. betaConstraint: serializeConstraint(this.betaConstraint),
  32007. gammaConstraint: serializeConstraint(this.gammaConstraint)
  32008. },
  32009. n = e.prototype.getConfig.call(this);
  32010. return Object.assign(t, n), t;
  32011. }, t.className = "BatchNormalization", t;
  32012. }(Layer);
  32013. _tfjsCore.serialization.registerClass(BatchNormalization);
  32014. var LayerNormalization = function (e) {
  32015. function t(t) {
  32016. var n = this;
  32017. if (null == t && (t = {}), (n = e.call(this, t) || this).axis = null == t.axis ? -1 : t.axis, "number" == typeof n.axis) {
  32018. if (!Number.isInteger(n.axis)) throw new Error("Expected axis to be an integer, but received " + n.axis);
  32019. } else {
  32020. if (!Array.isArray(n.axis)) throw new Error("Expected axis to be an integer or an array of integers, but received " + JSON.stringify(n.axis));
  32021. for (var r = 0, i = n.axis; r < i.length; r++) {
  32022. var a = i[r];
  32023. if (!Number.isInteger(a)) throw new Error("Expected axis to be an array of integers, but received " + JSON.stringify(n.axis));
  32024. }
  32025. }
  32026. return n.epsilon = null == t.epsilon ? .001 : t.epsilon, n.center = null == t.center || t.center, n.scale = null == t.scale || t.scale, n.betaInitializer = getInitializer(t.betaInitializer || "zeros"), n.gammaInitializer = getInitializer(t.gammaInitializer || "ones"), n.betaRegularizer = getRegularizer(t.betaRegularizer), n.gammaRegularizer = getRegularizer(t.gammaRegularizer), n.supportsMasking = !0, n;
  32027. }
  32028. return __extends(t, e), t.prototype.build = function (e) {
  32029. var t = (e = getExactlyOneShape(e)).length;
  32030. "number" == typeof this.axis && (this.axis = [this.axis]);
  32031. for (var n = 0; n < this.axis.length; ++n) this.axis[n] < 0 && (this.axis[n] += t);
  32032. for (var r = 0, i = this.axis; r < i.length; r++) {
  32033. var a = i[r];
  32034. if (a < 0 || a >= t) throw new Error("Invalid axis: " + a);
  32035. }
  32036. if (this.axis.length !== unique(this.axis).length) throw new Error("Found duplicate axes in: " + this.axis);
  32037. var o = this.axis.map(function (t) {
  32038. return e[t];
  32039. });
  32040. this.scale ? this.gamma = this.addWeight("gamma", o, "float32", this.gammaInitializer, this.gammaRegularizer, !0) : this.gamma = null, this.center ? this.beta = this.addWeight("beta", o, "float32", this.betaInitializer, this.betaRegularizer, !0) : this.beta = null, this.built = !0;
  32041. }, t.prototype.call = function (e, t) {
  32042. var n = this,
  32043. r = getExactlyOneTensor(e),
  32044. i = r.shape,
  32045. a = i.length;
  32046. return (0, _tfjsCore.tidy)(function () {
  32047. for (var e = (0, _tfjsCore.moments)(r, n.axis, !0), t = e.mean, o = e.variance, s = pyListRepeat(1, a), l = 0, u = n.axis; l < u.length; l++) {
  32048. var c = u[l];
  32049. s[c] = i[c];
  32050. }
  32051. for (var p = function (e) {
  32052. return null != e && e.shape.length !== a && n.axis !== [a - 1] ? e.reshape(s) : e;
  32053. }, h = p(n.gamma.read()), d = p(n.beta.read()), f = [], g = [], m = 0; m < a; ++m) -1 !== n.axis.indexOf(m) ? (f.push(i[m]), g.push(1)) : (f.push(1), g.push(i[m]));
  32054. return t = t.tile(f), o = o.tile(f), h = h.tile(g), d = d.tile(g), batchNormalization(r, t, o, d, h, n.epsilon);
  32055. });
  32056. }, t.prototype.getConfig = function () {
  32057. var t = {
  32058. axis: this.axis,
  32059. epsilon: this.epsilon,
  32060. center: this.center,
  32061. scale: this.scale,
  32062. betaInitializer: serializeInitializer(this.betaInitializer),
  32063. gammaInitializer: serializeInitializer(this.gammaInitializer),
  32064. betaRegularizer: serializeRegularizer(this.betaRegularizer),
  32065. gammaRegularizer: serializeRegularizer(this.gammaRegularizer)
  32066. },
  32067. n = e.prototype.getConfig.call(this);
  32068. return Object.assign(t, n), t;
  32069. }, t.className = "LayerNormalization", t;
  32070. }(Layer);
  32071. function spatial2dPadding(e, t, n) {
  32072. return (0, _tfjsCore.tidy)(function () {
  32073. if (4 !== e.rank) throw new ValueError("temporalPadding expects input tensor to be 4-D, but received a " + e.rank + "-D tensor.");
  32074. if (null == t && (t = [[1, 1], [1, 1]]), 2 !== t.length || 2 !== t[0].length || 2 !== t[1].length) throw new ValueError("spatial2dPadding expects `padding` to be an Array of two Arrays, each of which is an Array of two integers.");
  32075. if (null == n && (n = imageDataFormat()), "channelsLast" !== n && "channelsFirst" !== n) throw new ValueError("Unknown data format: " + n + ". Supported data formats are 'channelsLast' and 'channelsFirst.");
  32076. var r;
  32077. return r = "channelsFirst" === n ? [[0, 0], [0, 0], t[0], t[1]] : [[0, 0], t[0], t[1], [0, 0]], (0, _tfjsCore.pad)(e, r);
  32078. });
  32079. }
  32080. _tfjsCore.serialization.registerClass(LayerNormalization);
  32081. var ZeroPadding2D = function (e) {
  32082. function t(t) {
  32083. var n = this;
  32084. if (null == t && (t = {}), (n = e.call(this, t) || this).dataFormat = null == t.dataFormat ? imageDataFormat() : t.dataFormat, null == t.padding) n.padding = [[1, 1], [1, 1]]; else if ("number" == typeof t.padding) n.padding = [[t.padding, t.padding], [t.padding, t.padding]]; else {
  32085. if (t.padding = t.padding, 2 !== t.padding.length) throw new ValueError("ZeroPadding2D expects padding to be a length-2 array, but received a length-" + t.padding.length + " array.");
  32086. var r = void 0,
  32087. i = void 0;
  32088. if ("number" == typeof t.padding[0]) r = [t.padding[0], t.padding[0]], i = [t.padding[1], t.padding[1]]; else {
  32089. if (t.padding = t.padding, 2 !== t.padding[0].length) throw new ValueError("ZeroPadding2D expects height padding to be a length-2 array, but received a length-" + t.padding[0].length + " array.");
  32090. if (r = t.padding[0], 2 !== t.padding[1].length) throw new ValueError("ZeroPadding2D expects width padding to be a length-2 array, but received a length-" + t.padding[1].length + " array.");
  32091. i = t.padding[1];
  32092. }
  32093. n.padding = [r, i];
  32094. }
  32095. return n.inputSpec = [new InputSpec({
  32096. ndim: 4
  32097. })], n;
  32098. }
  32099. return __extends(t, e), t.prototype.computeOutputShape = function (e) {
  32100. var t, n;
  32101. return e = getExactlyOneShape(e), "channelsFirst" === this.dataFormat ? (t = null != e[2] && e[2] >= 0 ? e[2] + this.padding[0][0] + this.padding[0][1] : null, n = null != e[3] && e[3] >= 0 ? e[3] + this.padding[1][0] + this.padding[1][1] : null, [e[0], e[1], t, n]) : (t = null != e[1] && e[1] >= 0 ? e[1] + this.padding[0][0] + this.padding[0][1] : null, n = null != e[2] && e[2] >= 0 ? e[2] + this.padding[1][0] + this.padding[1][1] : null, [e[0], t, n, e[3]]);
  32102. }, t.prototype.call = function (e, t) {
  32103. var n = this;
  32104. return (0, _tfjsCore.tidy)(function () {
  32105. return spatial2dPadding(getExactlyOneTensor(e), n.padding, n.dataFormat);
  32106. });
  32107. }, t.prototype.getConfig = function () {
  32108. var t = {
  32109. padding: this.padding,
  32110. dataFormat: this.dataFormat
  32111. },
  32112. n = e.prototype.getConfig.call(this);
  32113. return Object.assign(t, n), t;
  32114. }, t.className = "ZeroPadding2D", t;
  32115. }(Layer);
  32116. function pool2d(e, t, n, r, i, a) {
  32117. return (0, _tfjsCore.tidy)(function () {
  32118. var o;
  32119. checkDataFormat(i), checkPoolMode(a), checkPaddingMode(r), null == n && (n = [1, 1]), null == r && (r = "valid"), null == i && (i = imageDataFormat()), null == a && (a = "max"), e = preprocessConv2DInput(e, i);
  32120. var s = "same" === r ? "same" : "valid";
  32121. return o = "max" === a ? (0, _tfjsCore.maxPool)(e, t, n, s) : (0, _tfjsCore.avgPool)(e, t, n, s), "channelsFirst" === i && (o = (0, _tfjsCore.transpose)(o, [0, 3, 1, 2])), o;
  32122. });
  32123. }
  32124. function pool3d(e, t, n, r, i, a) {
  32125. return (0, _tfjsCore.tidy)(function () {
  32126. var o;
  32127. checkDataFormat(i), checkPoolMode(a), checkPaddingMode(r), null == n && (n = [1, 1, 1]), null == r && (r = "valid"), null == i && (i = imageDataFormat()), null == a && (a = "max"), e = preprocessConv3DInput(e, i);
  32128. var s = "same" === r ? "same" : "valid";
  32129. return o = "max" === a ? (0, _tfjsCore.maxPool3d)(e, t, n, s) : (0, _tfjsCore.avgPool3d)(e, t, n, s), "channelsFirst" === i && (o = (0, _tfjsCore.transpose)(o, [0, 4, 1, 2, 3])), o;
  32130. });
  32131. }
  32132. _tfjsCore.serialization.registerClass(ZeroPadding2D);
  32133. var Pooling1D = function (e) {
  32134. function t(t) {
  32135. var n = this;
  32136. if (null == t.poolSize && (t.poolSize = 2), n = e.call(this, t) || this, "number" == typeof t.poolSize) n.poolSize = [t.poolSize]; else {
  32137. if (!Array.isArray(t.poolSize) || 1 !== t.poolSize.length || "number" != typeof t.poolSize[0]) throw new ValueError("poolSize for 1D convolutional layer must be a number or an Array of a single number, but received " + JSON.stringify(t.poolSize));
  32138. n.poolSize = t.poolSize;
  32139. }
  32140. if (assertPositiveInteger(n.poolSize, "poolSize"), null == t.strides) n.strides = n.poolSize; else if ("number" == typeof t.strides) n.strides = [t.strides]; else {
  32141. if (!Array.isArray(t.strides) || 1 !== t.strides.length || "number" != typeof t.strides[0]) throw new ValueError("strides for 1D convolutional layer must be a number or an Array of a single number, but received " + JSON.stringify(t.strides));
  32142. n.strides = t.strides;
  32143. }
  32144. return assertPositiveInteger(n.strides, "strides"), n.padding = null == t.padding ? "valid" : t.padding, checkPaddingMode(n.padding), n.inputSpec = [new InputSpec({
  32145. ndim: 3
  32146. })], n;
  32147. }
  32148. return __extends(t, e), t.prototype.computeOutputShape = function (e) {
  32149. var t = convOutputLength((e = getExactlyOneShape(e))[1], this.poolSize[0], this.padding, this.strides[0]);
  32150. return [e[0], t, e[2]];
  32151. }, t.prototype.call = function (e, t) {
  32152. var n = this;
  32153. return (0, _tfjsCore.tidy)(function () {
  32154. n.invokeCallHook(e, t), e = expandDims$1(getExactlyOneTensor(e), 2);
  32155. var r = n.poolingFunction(getExactlyOneTensor(e), [n.poolSize[0], 1], [n.strides[0], 1], n.padding, "channelsLast");
  32156. return (0, _tfjsCore.squeeze)(r, [2]);
  32157. });
  32158. }, t.prototype.getConfig = function () {
  32159. var t = {
  32160. poolSize: this.poolSize,
  32161. padding: this.padding,
  32162. strides: this.strides
  32163. },
  32164. n = e.prototype.getConfig.call(this);
  32165. return Object.assign(t, n), t;
  32166. }, t;
  32167. }(Layer),
  32168. MaxPooling1D = function (e) {
  32169. function t(t) {
  32170. return e.call(this, t) || this;
  32171. }
  32172. return __extends(t, e), t.prototype.poolingFunction = function (e, t, n, r, i) {
  32173. return checkDataFormat(i), checkPaddingMode(r), pool2d(e, t, n, r, i, "max");
  32174. }, t.className = "MaxPooling1D", t;
  32175. }(Pooling1D);
  32176. _tfjsCore.serialization.registerClass(MaxPooling1D);
  32177. var AveragePooling1D = function (e) {
  32178. function t(t) {
  32179. return e.call(this, t) || this;
  32180. }
  32181. return __extends(t, e), t.prototype.poolingFunction = function (e, t, n, r, i) {
  32182. return checkDataFormat(i), checkPaddingMode(r), pool2d(e, t, n, r, i, "avg");
  32183. }, t.className = "AveragePooling1D", t;
  32184. }(Pooling1D);
  32185. _tfjsCore.serialization.registerClass(AveragePooling1D);
  32186. var Pooling2D = function (e) {
  32187. function t(t) {
  32188. var n = this;
  32189. if (null == t.poolSize && (t.poolSize = [2, 2]), (n = e.call(this, t) || this).poolSize = Array.isArray(t.poolSize) ? t.poolSize : [t.poolSize, t.poolSize], null == t.strides) n.strides = n.poolSize; else if (Array.isArray(t.strides)) {
  32190. if (2 !== t.strides.length) throw new ValueError("If the strides property of a 2D pooling layer is an Array, it is expected to have a length of 2, but received length " + t.strides.length + ".");
  32191. n.strides = t.strides;
  32192. } else n.strides = [t.strides, t.strides];
  32193. return assertPositiveInteger(n.poolSize, "poolSize"), assertPositiveInteger(n.strides, "strides"), n.padding = null == t.padding ? "valid" : t.padding, n.dataFormat = null == t.dataFormat ? "channelsLast" : t.dataFormat, checkDataFormat(n.dataFormat), checkPaddingMode(n.padding), n.inputSpec = [new InputSpec({
  32194. ndim: 4
  32195. })], n;
  32196. }
  32197. return __extends(t, e), t.prototype.computeOutputShape = function (e) {
  32198. e = getExactlyOneShape(e);
  32199. var t = "channelsFirst" === this.dataFormat ? e[2] : e[1],
  32200. n = "channelsFirst" === this.dataFormat ? e[3] : e[2];
  32201. return t = convOutputLength(t, this.poolSize[0], this.padding, this.strides[0]), n = convOutputLength(n, this.poolSize[1], this.padding, this.strides[1]), "channelsFirst" === this.dataFormat ? [e[0], e[1], t, n] : [e[0], t, n, e[3]];
  32202. }, t.prototype.call = function (e, t) {
  32203. var n = this;
  32204. return (0, _tfjsCore.tidy)(function () {
  32205. return n.invokeCallHook(e, t), n.poolingFunction(getExactlyOneTensor(e), n.poolSize, n.strides, n.padding, n.dataFormat);
  32206. });
  32207. }, t.prototype.getConfig = function () {
  32208. var t = {
  32209. poolSize: this.poolSize,
  32210. padding: this.padding,
  32211. strides: this.strides,
  32212. dataFormat: this.dataFormat
  32213. },
  32214. n = e.prototype.getConfig.call(this);
  32215. return Object.assign(t, n), t;
  32216. }, t;
  32217. }(Layer),
  32218. MaxPooling2D = function (e) {
  32219. function t(t) {
  32220. return e.call(this, t) || this;
  32221. }
  32222. return __extends(t, e), t.prototype.poolingFunction = function (e, t, n, r, i) {
  32223. return checkDataFormat(i), checkPaddingMode(r), pool2d(e, t, n, r, i, "max");
  32224. }, t.className = "MaxPooling2D", t;
  32225. }(Pooling2D);
  32226. _tfjsCore.serialization.registerClass(MaxPooling2D);
  32227. var AveragePooling2D = function (e) {
  32228. function t(t) {
  32229. return e.call(this, t) || this;
  32230. }
  32231. return __extends(t, e), t.prototype.poolingFunction = function (e, t, n, r, i) {
  32232. return checkDataFormat(i), checkPaddingMode(r), pool2d(e, t, n, r, i, "avg");
  32233. }, t.className = "AveragePooling2D", t;
  32234. }(Pooling2D);
  32235. _tfjsCore.serialization.registerClass(AveragePooling2D);
  32236. var Pooling3D = function (e) {
  32237. function t(t) {
  32238. var n = this;
  32239. if (null == t.poolSize && (t.poolSize = [2, 2, 2]), (n = e.call(this, t) || this).poolSize = Array.isArray(t.poolSize) ? t.poolSize : [t.poolSize, t.poolSize, t.poolSize], null == t.strides) n.strides = n.poolSize; else if (Array.isArray(t.strides)) {
  32240. if (3 !== t.strides.length) throw new ValueError("If the strides property of a 3D pooling layer is an Array, it is expected to have a length of 3, but received length " + t.strides.length + ".");
  32241. n.strides = t.strides;
  32242. } else n.strides = [t.strides, t.strides, t.strides];
  32243. return assertPositiveInteger(n.poolSize, "poolSize"), assertPositiveInteger(n.strides, "strides"), n.padding = null == t.padding ? "valid" : t.padding, n.dataFormat = null == t.dataFormat ? "channelsLast" : t.dataFormat, checkDataFormat(n.dataFormat), checkPaddingMode(n.padding), n.inputSpec = [new InputSpec({
  32244. ndim: 5
  32245. })], n;
  32246. }
  32247. return __extends(t, e), t.prototype.computeOutputShape = function (e) {
  32248. e = getExactlyOneShape(e);
  32249. var t = "channelsFirst" === this.dataFormat ? e[2] : e[1],
  32250. n = "channelsFirst" === this.dataFormat ? e[3] : e[2],
  32251. r = "channelsFirst" === this.dataFormat ? e[4] : e[3];
  32252. return t = convOutputLength(t, this.poolSize[0], this.padding, this.strides[0]), n = convOutputLength(n, this.poolSize[1], this.padding, this.strides[1]), r = convOutputLength(r, this.poolSize[2], this.padding, this.strides[2]), "channelsFirst" === this.dataFormat ? [e[0], e[1], t, n, r] : [e[0], t, n, r, e[4]];
  32253. }, t.prototype.call = function (e, t) {
  32254. var n = this;
  32255. return (0, _tfjsCore.tidy)(function () {
  32256. return n.invokeCallHook(e, t), n.poolingFunction(getExactlyOneTensor(e), n.poolSize, n.strides, n.padding, n.dataFormat);
  32257. });
  32258. }, t.prototype.getConfig = function () {
  32259. var t = {
  32260. poolSize: this.poolSize,
  32261. padding: this.padding,
  32262. strides: this.strides,
  32263. dataFormat: this.dataFormat
  32264. },
  32265. n = e.prototype.getConfig.call(this);
  32266. return Object.assign(t, n), t;
  32267. }, t;
  32268. }(Layer),
  32269. MaxPooling3D = function (e) {
  32270. function t(t) {
  32271. return e.call(this, t) || this;
  32272. }
  32273. return __extends(t, e), t.prototype.poolingFunction = function (e, t, n, r, i) {
  32274. return checkDataFormat(i), checkPaddingMode(r), pool3d(e, t, n, r, i, "max");
  32275. }, t.className = "MaxPooling3D", t;
  32276. }(Pooling3D);
  32277. _tfjsCore.serialization.registerClass(MaxPooling3D);
  32278. var AveragePooling3D = function (e) {
  32279. function t(t) {
  32280. return e.call(this, t) || this;
  32281. }
  32282. return __extends(t, e), t.prototype.poolingFunction = function (e, t, n, r, i) {
  32283. return checkDataFormat(i), checkPaddingMode(r), pool3d(e, t, n, r, i, "avg");
  32284. }, t.className = "AveragePooling3D", t;
  32285. }(Pooling3D);
  32286. _tfjsCore.serialization.registerClass(AveragePooling3D);
  32287. var GlobalPooling1D = function (e) {
  32288. function t(t) {
  32289. var n = e.call(this, t) || this;
  32290. return n.inputSpec = [new InputSpec({
  32291. ndim: 3
  32292. })], n;
  32293. }
  32294. return __extends(t, e), t.prototype.computeOutputShape = function (e) {
  32295. return [e[0], e[2]];
  32296. }, t.prototype.call = function (e, t) {
  32297. throw new NotImplementedError();
  32298. }, t;
  32299. }(Layer),
  32300. GlobalAveragePooling1D = function (e) {
  32301. function t(t) {
  32302. return e.call(this, t || {}) || this;
  32303. }
  32304. return __extends(t, e), t.prototype.call = function (e, t) {
  32305. return (0, _tfjsCore.tidy)(function () {
  32306. var t = getExactlyOneTensor(e);
  32307. return (0, _tfjsCore.mean)(t, 1);
  32308. });
  32309. }, t.className = "GlobalAveragePooling1D", t;
  32310. }(GlobalPooling1D);
  32311. _tfjsCore.serialization.registerClass(GlobalAveragePooling1D);
  32312. var GlobalMaxPooling1D = function (e) {
  32313. function t(t) {
  32314. return e.call(this, t || {}) || this;
  32315. }
  32316. return __extends(t, e), t.prototype.call = function (e, t) {
  32317. return (0, _tfjsCore.tidy)(function () {
  32318. var t = getExactlyOneTensor(e);
  32319. return (0, _tfjsCore.max)(t, 1);
  32320. });
  32321. }, t.className = "GlobalMaxPooling1D", t;
  32322. }(GlobalPooling1D);
  32323. _tfjsCore.serialization.registerClass(GlobalMaxPooling1D);
  32324. var GlobalPooling2D = function (e) {
  32325. function t(t) {
  32326. var n = e.call(this, t) || this;
  32327. return n.dataFormat = null == t.dataFormat ? "channelsLast" : t.dataFormat, checkDataFormat(n.dataFormat), n.inputSpec = [new InputSpec({
  32328. ndim: 4
  32329. })], n;
  32330. }
  32331. return __extends(t, e), t.prototype.computeOutputShape = function (e) {
  32332. return e = e, "channelsLast" === this.dataFormat ? [e[0], e[3]] : [e[0], e[1]];
  32333. }, t.prototype.call = function (e, t) {
  32334. throw new NotImplementedError();
  32335. }, t.prototype.getConfig = function () {
  32336. var t = {
  32337. dataFormat: this.dataFormat
  32338. },
  32339. n = e.prototype.getConfig.call(this);
  32340. return Object.assign(t, n), t;
  32341. }, t;
  32342. }(Layer),
  32343. GlobalAveragePooling2D = function (e) {
  32344. function t() {
  32345. return null !== e && e.apply(this, arguments) || this;
  32346. }
  32347. return __extends(t, e), t.prototype.call = function (e, t) {
  32348. var n = this;
  32349. return (0, _tfjsCore.tidy)(function () {
  32350. var t = getExactlyOneTensor(e);
  32351. return "channelsLast" === n.dataFormat ? (0, _tfjsCore.mean)(t, [1, 2]) : (0, _tfjsCore.mean)(t, [2, 3]);
  32352. });
  32353. }, t.className = "GlobalAveragePooling2D", t;
  32354. }(GlobalPooling2D);
  32355. _tfjsCore.serialization.registerClass(GlobalAveragePooling2D);
  32356. var GlobalMaxPooling2D = function (e) {
  32357. function t() {
  32358. return null !== e && e.apply(this, arguments) || this;
  32359. }
  32360. return __extends(t, e), t.prototype.call = function (e, t) {
  32361. var n = this;
  32362. return (0, _tfjsCore.tidy)(function () {
  32363. var t = getExactlyOneTensor(e);
  32364. return "channelsLast" === n.dataFormat ? (0, _tfjsCore.max)(t, [1, 2]) : (0, _tfjsCore.max)(t, [2, 3]);
  32365. });
  32366. }, t.className = "GlobalMaxPooling2D", t;
  32367. }(GlobalPooling2D);
  32368. function standardizeArgs(e, t, n, r) {
  32369. if (Array.isArray(e)) {
  32370. if (null != t || null != n) throw new ValueError("When inputs is an array, neither initialState or constants should be provided");
  32371. null != r && (n = e.slice(e.length - r, e.length), e = e.slice(0, e.length - r)), e.length > 1 && (t = e.slice(1, e.length)), e = e[0];
  32372. }
  32373. function i(e) {
  32374. return null == e || Array.isArray(e) ? e : [e];
  32375. }
  32376. return {
  32377. inputs: e,
  32378. initialState: t = i(t),
  32379. constants: n = i(n)
  32380. };
  32381. }
  32382. function rnn(e, t, n, r, i, a, o, s) {
  32383. return void 0 === r && (r = !1), void 0 === o && (o = !1), void 0 === s && (s = !1), (0, _tfjsCore.tidy)(function () {
  32384. var l = t.shape.length;
  32385. if (l < 3) throw new ValueError("Input should be at least 3D, but is " + l + "D.");
  32386. var u = [1, 0].concat(range(2, l));
  32387. if (t = (0, _tfjsCore.transpose)(t, u), null != a) throw new NotImplementedError("The rnn() functoin of the deeplearn.js backend does not support constants yet.");
  32388. o && console.warn("Backend rnn(): the unroll = true option is not applicable to the imperative deeplearn.js backend."), null != i && ((i = i.asType("bool").asType("float32")).rank === l - 1 && (i = (0, _tfjsCore.expandDims)(i, -1)), i = (0, _tfjsCore.transpose)(i, u)), r && (t = (0, _tfjsCore.reverse)(t, 0), null != i && (i = (0, _tfjsCore.reverse)(i, 0)));
  32389. var c,
  32390. p,
  32391. h = [],
  32392. d = n,
  32393. f = t.shape[0],
  32394. g = (0, _tfjsCore.unstack)(t);
  32395. null != i && (p = (0, _tfjsCore.unstack)(i));
  32396. for (var m, y = function (t) {
  32397. var n = g[t],
  32398. r = (0, _tfjsCore.tidy)(function () {
  32399. return e(n, d);
  32400. });
  32401. if (null == i) c = r[0], d = r[1]; else {
  32402. var a = (0, _tfjsCore.tidy)(function () {
  32403. var e = p[t],
  32404. n = (0, _tfjsCore.onesLike)(e).sub(e);
  32405. return {
  32406. output: r[0].mul(e).addStrict(d[0].mul(n)),
  32407. newStates: d.map(function (t, i) {
  32408. return r[1][i].mul(e).addStrict(t.mul(n));
  32409. })
  32410. };
  32411. });
  32412. c = a.output, d = a.newStates;
  32413. }
  32414. s && h.push(c);
  32415. }, v = 0; v < f; ++v) y(v);
  32416. if (s) {
  32417. m = (0, _tfjsCore.stack)(h, 1);
  32418. }
  32419. return [c, m, d];
  32420. });
  32421. }
  32422. _tfjsCore.serialization.registerClass(GlobalMaxPooling2D);
  32423. var RNN = function (e) {
  32424. function t(t) {
  32425. var n,
  32426. r = e.call(this, t) || this;
  32427. if (null == t.cell) throw new ValueError("cell property is missing for the constructor of RNN.");
  32428. if (null == (n = Array.isArray(t.cell) ? new StackedRNNCells({
  32429. cells: t.cell
  32430. }) : t.cell).stateSize) throw new ValueError("The RNN cell should have an attribute `stateSize` (tuple of integers, one integer per RNN state).");
  32431. return r.cell = n, r.returnSequences = null != t.returnSequences && t.returnSequences, r.returnState = null != t.returnState && t.returnState, r.goBackwards = null != t.goBackwards && t.goBackwards, r._stateful = null != t.stateful && t.stateful, r.unroll = null != t.unroll && t.unroll, r.supportsMasking = !0, r.inputSpec = [new InputSpec({
  32432. ndim: 3
  32433. })], r.stateSpec = null, r.states_ = null, r.numConstants = null, r.keptStates = [], r;
  32434. }
  32435. return __extends(t, e), t.prototype.getStates = function () {
  32436. return null == this.states_ ? range(0, Array.isArray(this.cell.stateSize) ? this.cell.stateSize.length : 1).map(function (e) {
  32437. return null;
  32438. }) : this.states_;
  32439. }, t.prototype.setStates = function (e) {
  32440. this.states_ = e;
  32441. }, t.prototype.computeOutputShape = function (e) {
  32442. isArrayOfShapes(e) && (e = e[0]), e = e;
  32443. var t = this.cell.stateSize;
  32444. Array.isArray(t) || (t = [t]);
  32445. var n,
  32446. r = t[0];
  32447. if (n = this.returnSequences ? [e[0], e[1], r] : [e[0], r], this.returnState) {
  32448. for (var i = [], a = 0, o = t; a < o.length; a++) {
  32449. var s = o[a];
  32450. i.push([e[0], s]);
  32451. }
  32452. return [n].concat(i);
  32453. }
  32454. return n;
  32455. }, t.prototype.computeMask = function (e, t) {
  32456. var n = this;
  32457. return (0, _tfjsCore.tidy)(function () {
  32458. Array.isArray(t) && (t = t[0]);
  32459. var e = n.returnSequences ? t : null;
  32460. if (n.returnState) {
  32461. var r = n.states.map(function (e) {
  32462. return null;
  32463. });
  32464. return [e].concat(r);
  32465. }
  32466. return e;
  32467. });
  32468. }, Object.defineProperty(t.prototype, "states", {
  32469. get: function () {
  32470. if (null == this.states_) {
  32471. for (var e = Array.isArray(this.cell.stateSize) ? this.cell.stateSize.length : 1, t = [], n = 0; n < e; ++n) t.push(null);
  32472. return t;
  32473. }
  32474. return this.states_;
  32475. },
  32476. set: function (e) {
  32477. this.states_ = e;
  32478. },
  32479. enumerable: !0,
  32480. configurable: !0
  32481. }), t.prototype.build = function (e) {
  32482. if (null != this.numConstants) throw new NotImplementedError("Constants support is not implemented in RNN yet.");
  32483. isArrayOfShapes(e) && (e = e[0]), e = e;
  32484. var t = this.stateful ? e[0] : null,
  32485. n = e[e.length - 1];
  32486. this.inputSpec[0] = new InputSpec({
  32487. shape: [t, null, n]
  32488. });
  32489. var r,
  32490. i = [e[0]].concat(e.slice(2));
  32491. if (this.cell.build(i), r = Array.isArray(this.cell.stateSize) ? this.cell.stateSize : [this.cell.stateSize], null != this.stateSpec) {
  32492. if (!_tfjsCore.util.arraysEqual(this.stateSpec.map(function (e) {
  32493. return e.shape[e.shape.length - 1];
  32494. }), r)) throw new ValueError("An initialState was passed that is not compatible with cell.stateSize. Received stateSpec=" + this.stateSpec + "; However cell.stateSize is " + this.cell.stateSize);
  32495. } else this.stateSpec = r.map(function (e) {
  32496. return new InputSpec({
  32497. shape: [null, e]
  32498. });
  32499. });
  32500. this.stateful && this.resetStates();
  32501. }, t.prototype.resetStates = function (e, t) {
  32502. var n = this;
  32503. void 0 === t && (t = !1), (0, _tfjsCore.tidy)(function () {
  32504. if (!n.stateful) throw new AttributeError("Cannot call resetStates() on an RNN Layer that is not stateful.");
  32505. var r = n.inputSpec[0].shape[0];
  32506. if (null == r) throw new ValueError("If an RNN is stateful, it needs to know its batch size. Specify the batch size of your input tensors: \n- If using a Sequential model, specify the batch size by passing a `batchInputShape` option to your first layer.\n- If using the functional API, specify the batch size by passing a `batchShape` option to your Input layer.");
  32507. if (null == n.states_) Array.isArray(n.cell.stateSize) ? n.states_ = n.cell.stateSize.map(function (e) {
  32508. return (0, _tfjsCore.zeros)([r, e]);
  32509. }) : n.states_ = [(0, _tfjsCore.zeros)([r, n.cell.stateSize])]; else if (null == e) (0, _tfjsCore.dispose)(n.states_), null != n.keptStates && ((0, _tfjsCore.dispose)(n.keptStates), n.keptStates = []), Array.isArray(n.cell.stateSize) ? n.states_ = n.cell.stateSize.map(function (e) {
  32510. return (0, _tfjsCore.zeros)([r, e]);
  32511. }) : n.states_[0] = (0, _tfjsCore.zeros)([r, n.cell.stateSize]); else {
  32512. if (Array.isArray(e) || (e = [e]), e.length !== n.states_.length) throw new ValueError("Layer " + n.name + " expects " + n.states_.length + " state(s), but it received " + e.length + " state value(s). Input received: " + e);
  32513. !0 === t ? n.keptStates.push(n.states_.slice()) : (0, _tfjsCore.dispose)(n.states_);
  32514. for (var i = 0; i < n.states_.length; ++i) {
  32515. var a = e[i],
  32516. o = Array.isArray(n.cell.stateSize) ? n.cell.stateSize[i] : n.cell.stateSize,
  32517. s = [r, o];
  32518. if (!_tfjsCore.util.arraysEqual(a.shape, s)) throw new ValueError("State " + i + " is incompatible with layer " + n.name + ": expected shape=" + s + ", received shape=" + a.shape);
  32519. n.states_[i] = a;
  32520. }
  32521. }
  32522. n.states_ = n.states_.map(function (e) {
  32523. return (0, _tfjsCore.keep)(e.clone());
  32524. });
  32525. });
  32526. }, t.prototype.apply = function (t, n) {
  32527. var r = null == n ? null : n.initialState,
  32528. i = null == n ? null : n.constants;
  32529. null == n && (n = {});
  32530. var a = standardizeArgs(t, r, i, this.numConstants);
  32531. t = a.inputs, r = a.initialState, i = a.constants;
  32532. var o = [],
  32533. s = [];
  32534. if (null != r) {
  32535. n.initialState = r, o = o.concat(r), this.stateSpec = [];
  32536. for (var l = 0, u = r; l < u.length; l++) {
  32537. var c = u[l];
  32538. this.stateSpec.push(new InputSpec({
  32539. shape: c.shape
  32540. }));
  32541. }
  32542. s = s.concat(this.stateSpec);
  32543. }
  32544. if (null != i && (n.constants = i, o = o.concat(i), this.numConstants = i.length), o[0] instanceof SymbolicTensor) {
  32545. var p = [t].concat(o),
  32546. h = this.inputSpec.concat(s),
  32547. d = this.inputSpec;
  32548. this.inputSpec = h;
  32549. var f = e.prototype.apply.call(this, p, n);
  32550. return this.inputSpec = d, f;
  32551. }
  32552. return e.prototype.apply.call(this, t, n);
  32553. }, t.prototype.call = function (e, t) {
  32554. var n = this;
  32555. return (0, _tfjsCore.tidy)(function () {
  32556. var r = null == t ? null : t.mask,
  32557. i = null == t ? null : t.training,
  32558. a = null == t ? null : t.initialState;
  32559. e = getExactlyOneTensor(e), null == a && (a = n.stateful ? n.states_ : n.getInitialState(e));
  32560. var o = Array.isArray(n.cell.stateSize) ? n.cell.stateSize.length : 1;
  32561. if (a.length !== o) throw new ValueError("RNN Layer has " + o + " state(s) but was passed " + a.length + " initial state(s).");
  32562. n.unroll && console.warn("Ignoring unroll = true for RNN layer, due to imperative backend.");
  32563. var s = {
  32564. training: i
  32565. },
  32566. l = rnn(function (e, t) {
  32567. var r = n.cell.call([e].concat(t), s);
  32568. return [r[0], r.slice(1)];
  32569. }, e, a, n.goBackwards, r, null, n.unroll, n.returnSequences),
  32570. u = l[0],
  32571. c = l[1],
  32572. p = l[2];
  32573. n.stateful && n.resetStates(p, i);
  32574. var h = n.returnSequences ? c : u;
  32575. return n.returnState ? [h].concat(p) : h;
  32576. });
  32577. }, t.prototype.getInitialState = function (e) {
  32578. var t = this;
  32579. return (0, _tfjsCore.tidy)(function () {
  32580. var n = (0, _tfjsCore.zeros)(e.shape);
  32581. return n = expandDims$1(n = (0, _tfjsCore.sum)(n, [1, 2])), Array.isArray(t.cell.stateSize) ? t.cell.stateSize.map(function (e) {
  32582. return e > 1 ? tile$1(n, [1, e]) : n;
  32583. }) : t.cell.stateSize > 1 ? [tile$1(n, [1, t.cell.stateSize])] : [n];
  32584. });
  32585. }, Object.defineProperty(t.prototype, "trainableWeights", {
  32586. get: function () {
  32587. return this.trainable ? this.cell.trainableWeights : [];
  32588. },
  32589. enumerable: !0,
  32590. configurable: !0
  32591. }), Object.defineProperty(t.prototype, "nonTrainableWeights", {
  32592. get: function () {
  32593. return this.trainable ? this.cell.nonTrainableWeights : this.cell.weights;
  32594. },
  32595. enumerable: !0,
  32596. configurable: !0
  32597. }), t.prototype.setFastWeightInitDuringBuild = function (t) {
  32598. e.prototype.setFastWeightInitDuringBuild.call(this, t), null != this.cell && this.cell.setFastWeightInitDuringBuild(t);
  32599. }, t.prototype.getConfig = function () {
  32600. var t = {
  32601. returnSequences: this.returnSequences,
  32602. returnState: this.returnState,
  32603. goBackwards: this.goBackwards,
  32604. stateful: this.stateful,
  32605. unroll: this.unroll
  32606. };
  32607. null != this.numConstants && (t.numConstants = this.numConstants);
  32608. var n = this.cell.getConfig();
  32609. t.cell = {
  32610. className: this.cell.getClassName(),
  32611. config: n
  32612. };
  32613. var r = e.prototype.getConfig.call(this);
  32614. return Object.assign(t, r), t;
  32615. }, t.fromConfig = function (e, t, n) {
  32616. void 0 === n && (n = {});
  32617. var r = deserialize(t.cell, n);
  32618. return new e(Object.assign(t, {
  32619. cell: r
  32620. }));
  32621. }, t.className = "RNN", t;
  32622. }(Layer);
  32623. exports.RNN = RNN;
  32624. _tfjsCore.serialization.registerClass(RNN);
  32625. var RNNCell = function (e) {
  32626. function t() {
  32627. return null !== e && e.apply(this, arguments) || this;
  32628. }
  32629. return __extends(t, e), t;
  32630. }(Layer),
  32631. SimpleRNNCell = function (e) {
  32632. function t(t) {
  32633. var n = e.call(this, t) || this;
  32634. return n.DEFAULT_ACTIVATION = "tanh", n.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", n.DEFAULT_RECURRENT_INITIALIZER = "orthogonal", n.DEFAULT_BIAS_INITIALIZER = "zeros", n.units = t.units, assertPositiveInteger(n.units, "units"), n.activation = getActivation(null == t.activation ? n.DEFAULT_ACTIVATION : t.activation), n.useBias = null == t.useBias || t.useBias, n.kernelInitializer = getInitializer(t.kernelInitializer || n.DEFAULT_KERNEL_INITIALIZER), n.recurrentInitializer = getInitializer(t.recurrentInitializer || n.DEFAULT_RECURRENT_INITIALIZER), n.biasInitializer = getInitializer(t.biasInitializer || n.DEFAULT_BIAS_INITIALIZER), n.kernelRegularizer = getRegularizer(t.kernelRegularizer), n.recurrentRegularizer = getRegularizer(t.recurrentRegularizer), n.biasRegularizer = getRegularizer(t.biasRegularizer), n.kernelConstraint = getConstraint(t.kernelConstraint), n.recurrentConstraint = getConstraint(t.recurrentConstraint), n.biasConstraint = getConstraint(t.biasConstraint), n.dropout = min$1([1, max$1([0, null == t.dropout ? 0 : t.dropout])]), n.recurrentDropout = min$1([1, max$1([0, null == t.recurrentDropout ? 0 : t.recurrentDropout])]), n.stateSize = n.units, n.dropoutMask = null, n.recurrentDropoutMask = null, n;
  32635. }
  32636. return __extends(t, e), t.prototype.build = function (e) {
  32637. e = getExactlyOneShape(e), this.kernel = this.addWeight("kernel", [e[e.length - 1], this.units], null, this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.recurrentKernel = this.addWeight("recurrent_kernel", [this.units, this.units], null, this.recurrentInitializer, this.recurrentRegularizer, !0, this.recurrentConstraint), this.useBias ? this.bias = this.addWeight("bias", [this.units], null, this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint) : this.bias = null, this.built = !0;
  32638. }, t.prototype.call = function (e, t) {
  32639. var n = this;
  32640. return (0, _tfjsCore.tidy)(function () {
  32641. if (2 !== (e = e).length) throw new ValueError("SimpleRNNCell expects 2 input Tensors, got " + e.length + ".");
  32642. var r = e[1];
  32643. e = e[0];
  32644. var i,
  32645. a = null != t.training && t.training;
  32646. 0 < n.dropout && n.dropout < 1 && null == n.dropoutMask && (n.dropoutMask = generateDropoutMask(function () {
  32647. return (0, _tfjsCore.onesLike)(e);
  32648. }, n.dropout, a)), 0 < n.recurrentDropout && n.recurrentDropout < 1 && null == n.recurrentDropoutMask && (n.recurrentDropoutMask = generateDropoutMask(function () {
  32649. return (0, _tfjsCore.onesLike)(r);
  32650. }, n.recurrentDropout, a));
  32651. var o = n.dropoutMask,
  32652. s = n.recurrentDropoutMask;
  32653. i = dot(null != o ? (0, _tfjsCore.mul)(e, o) : e, n.kernel.read()), null != n.bias && (i = biasAdd(i, n.bias.read())), null != s && (r = (0, _tfjsCore.mul)(r, s));
  32654. var l = (0, _tfjsCore.add)(i, dot(r, n.recurrentKernel.read()));
  32655. return null != n.activation && (l = n.activation.apply(l)), [l, l];
  32656. });
  32657. }, t.prototype.getConfig = function () {
  32658. var t = {
  32659. units: this.units,
  32660. activation: serializeActivation(this.activation),
  32661. useBias: this.useBias,
  32662. kernelInitializer: serializeInitializer(this.kernelInitializer),
  32663. recurrentInitializer: serializeInitializer(this.recurrentInitializer),
  32664. biasInitializer: serializeInitializer(this.biasInitializer),
  32665. kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
  32666. recurrentRegularizer: serializeRegularizer(this.recurrentRegularizer),
  32667. biasRegularizer: serializeRegularizer(this.biasRegularizer),
  32668. activityRegularizer: serializeRegularizer(this.activityRegularizer),
  32669. kernelConstraint: serializeConstraint(this.kernelConstraint),
  32670. recurrentConstraint: serializeConstraint(this.recurrentConstraint),
  32671. biasConstraint: serializeConstraint(this.biasConstraint),
  32672. dropout: this.dropout,
  32673. recurrentDropout: this.recurrentDropout
  32674. },
  32675. n = e.prototype.getConfig.call(this);
  32676. return Object.assign(t, n), t;
  32677. }, t.className = "SimpleRNNCell", t;
  32678. }(RNNCell);
  32679. _tfjsCore.serialization.registerClass(SimpleRNNCell);
  32680. var SimpleRNN = function (e) {
  32681. function t(t) {
  32682. return t.cell = new SimpleRNNCell(t), e.call(this, t) || this;
  32683. }
  32684. return __extends(t, e), t.prototype.call = function (t, n) {
  32685. var r = this;
  32686. return (0, _tfjsCore.tidy)(function () {
  32687. null != r.cell.dropoutMask && ((0, _tfjsCore.dispose)(r.cell.dropoutMask), r.cell.dropoutMask = null), null != r.cell.recurrentDropoutMask && ((0, _tfjsCore.dispose)(r.cell.recurrentDropoutMask), r.cell.recurrentDropoutMask = null);
  32688. var i = null == n ? null : n.mask,
  32689. a = null == n ? null : n.training,
  32690. o = null == n ? null : n.initialState;
  32691. return e.prototype.call.call(r, t, {
  32692. mask: i,
  32693. training: a,
  32694. initialState: o
  32695. });
  32696. });
  32697. }, Object.defineProperty(t.prototype, "units", {
  32698. get: function () {
  32699. return this.cell.units;
  32700. },
  32701. enumerable: !0,
  32702. configurable: !0
  32703. }), Object.defineProperty(t.prototype, "activation", {
  32704. get: function () {
  32705. return this.cell.activation;
  32706. },
  32707. enumerable: !0,
  32708. configurable: !0
  32709. }), Object.defineProperty(t.prototype, "useBias", {
  32710. get: function () {
  32711. return this.cell.useBias;
  32712. },
  32713. enumerable: !0,
  32714. configurable: !0
  32715. }), Object.defineProperty(t.prototype, "kernelInitializer", {
  32716. get: function () {
  32717. return this.cell.kernelInitializer;
  32718. },
  32719. enumerable: !0,
  32720. configurable: !0
  32721. }), Object.defineProperty(t.prototype, "recurrentInitializer", {
  32722. get: function () {
  32723. return this.cell.recurrentInitializer;
  32724. },
  32725. enumerable: !0,
  32726. configurable: !0
  32727. }), Object.defineProperty(t.prototype, "biasInitializer", {
  32728. get: function () {
  32729. return this.cell.biasInitializer;
  32730. },
  32731. enumerable: !0,
  32732. configurable: !0
  32733. }), Object.defineProperty(t.prototype, "kernelRegularizer", {
  32734. get: function () {
  32735. return this.cell.kernelRegularizer;
  32736. },
  32737. enumerable: !0,
  32738. configurable: !0
  32739. }), Object.defineProperty(t.prototype, "recurrentRegularizer", {
  32740. get: function () {
  32741. return this.cell.recurrentRegularizer;
  32742. },
  32743. enumerable: !0,
  32744. configurable: !0
  32745. }), Object.defineProperty(t.prototype, "biasRegularizer", {
  32746. get: function () {
  32747. return this.cell.biasRegularizer;
  32748. },
  32749. enumerable: !0,
  32750. configurable: !0
  32751. }), Object.defineProperty(t.prototype, "kernelConstraint", {
  32752. get: function () {
  32753. return this.cell.kernelConstraint;
  32754. },
  32755. enumerable: !0,
  32756. configurable: !0
  32757. }), Object.defineProperty(t.prototype, "recurrentConstraint", {
  32758. get: function () {
  32759. return this.cell.recurrentConstraint;
  32760. },
  32761. enumerable: !0,
  32762. configurable: !0
  32763. }), Object.defineProperty(t.prototype, "biasConstraint", {
  32764. get: function () {
  32765. return this.cell.biasConstraint;
  32766. },
  32767. enumerable: !0,
  32768. configurable: !0
  32769. }), Object.defineProperty(t.prototype, "dropout", {
  32770. get: function () {
  32771. return this.cell.dropout;
  32772. },
  32773. enumerable: !0,
  32774. configurable: !0
  32775. }), Object.defineProperty(t.prototype, "recurrentDropout", {
  32776. get: function () {
  32777. return this.cell.recurrentDropout;
  32778. },
  32779. enumerable: !0,
  32780. configurable: !0
  32781. }), t.prototype.getConfig = function () {
  32782. var t = {
  32783. units: this.units,
  32784. activation: serializeActivation(this.activation),
  32785. useBias: this.useBias,
  32786. kernelInitializer: serializeInitializer(this.kernelInitializer),
  32787. recurrentInitializer: serializeInitializer(this.recurrentInitializer),
  32788. biasInitializer: serializeInitializer(this.biasInitializer),
  32789. kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
  32790. recurrentRegularizer: serializeRegularizer(this.recurrentRegularizer),
  32791. biasRegularizer: serializeRegularizer(this.biasRegularizer),
  32792. activityRegularizer: serializeRegularizer(this.activityRegularizer),
  32793. kernelConstraint: serializeConstraint(this.kernelConstraint),
  32794. recurrentConstraint: serializeConstraint(this.recurrentConstraint),
  32795. biasConstraint: serializeConstraint(this.biasConstraint),
  32796. dropout: this.dropout,
  32797. recurrentDropout: this.recurrentDropout
  32798. },
  32799. n = e.prototype.getConfig.call(this);
  32800. return delete n.cell, Object.assign(t, n), t;
  32801. }, t.fromConfig = function (e, t) {
  32802. return new e(t);
  32803. }, t.className = "SimpleRNN", t;
  32804. }(RNN);
  32805. _tfjsCore.serialization.registerClass(SimpleRNN);
  32806. var GRUCell = function (e) {
  32807. function t(t) {
  32808. var n = e.call(this, t) || this;
  32809. return n.DEFAULT_ACTIVATION = "tanh", n.DEFAULT_RECURRENT_ACTIVATION = "hardSigmoid", n.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", n.DEFAULT_RECURRENT_INITIALIZER = "orthogonal", n.DEFAULT_BIAS_INITIALIZER = "zeros", n.units = t.units, assertPositiveInteger(n.units, "units"), n.activation = getActivation(void 0 === t.activation ? n.DEFAULT_ACTIVATION : t.activation), n.recurrentActivation = getActivation(void 0 === t.recurrentActivation ? n.DEFAULT_RECURRENT_ACTIVATION : t.recurrentActivation), n.useBias = null == t.useBias || t.useBias, n.kernelInitializer = getInitializer(t.kernelInitializer || n.DEFAULT_KERNEL_INITIALIZER), n.recurrentInitializer = getInitializer(t.recurrentInitializer || n.DEFAULT_RECURRENT_INITIALIZER), n.biasInitializer = getInitializer(t.biasInitializer || n.DEFAULT_BIAS_INITIALIZER), n.kernelRegularizer = getRegularizer(t.kernelRegularizer), n.recurrentRegularizer = getRegularizer(t.recurrentRegularizer), n.biasRegularizer = getRegularizer(t.biasRegularizer), n.kernelConstraint = getConstraint(t.kernelConstraint), n.recurrentConstraint = getConstraint(t.recurrentConstraint), n.biasConstraint = getConstraint(t.biasConstraint), n.dropout = min$1([1, max$1([0, null == t.dropout ? 0 : t.dropout])]), n.recurrentDropout = min$1([1, max$1([0, null == t.recurrentDropout ? 0 : t.recurrentDropout])]), n.implementation = t.implementation, n.stateSize = n.units, n.dropoutMask = null, n.recurrentDropoutMask = null, n;
  32810. }
  32811. return __extends(t, e), t.prototype.build = function (e) {
  32812. var t = (e = getExactlyOneShape(e))[e.length - 1];
  32813. this.kernel = this.addWeight("kernel", [t, 3 * this.units], null, this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.recurrentKernel = this.addWeight("recurrent_kernel", [this.units, 3 * this.units], null, this.recurrentInitializer, this.recurrentRegularizer, !0, this.recurrentConstraint), this.useBias ? this.bias = this.addWeight("bias", [3 * this.units], null, this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint) : this.bias = null, this.built = !0;
  32814. }, t.prototype.call = function (e, t) {
  32815. var n = this;
  32816. return (0, _tfjsCore.tidy)(function () {
  32817. if (2 !== (e = e).length) throw new ValueError("GRUCell expects 2 input Tensors (inputs, h, c), got " + e.length + ".");
  32818. var r = null != t.training && t.training,
  32819. i = e[1];
  32820. e = e[0], 0 < n.dropout && n.dropout < 1 && null == n.dropoutMask && (n.dropoutMask = generateDropoutMask(function () {
  32821. return (0, _tfjsCore.onesLike)(e);
  32822. }, n.dropout, r, 3)), 0 < n.recurrentDropout && n.recurrentDropout < 1 && null == n.recurrentDropoutMask && (n.recurrentDropoutMask = generateDropoutMask(function () {
  32823. return (0, _tfjsCore.onesLike)(i);
  32824. }, n.recurrentDropout, r, 3));
  32825. var a,
  32826. o,
  32827. s,
  32828. l = n.dropoutMask,
  32829. u = n.recurrentDropoutMask;
  32830. 0 < n.dropout && n.dropout < 1 && (e = (0, _tfjsCore.mul)(e, l[0]));
  32831. var c = dot(e, n.kernel.read());
  32832. n.useBias && (c = biasAdd(c, n.bias.read())), 0 < n.recurrentDropout && n.recurrentDropout < 1 && (i = (0, _tfjsCore.mul)(i, u[0]));
  32833. var p = n.recurrentKernel.read(),
  32834. h = (0, _tfjsCore.split)(p, [2 * n.units, n.units], p.rank - 1),
  32835. d = h[0],
  32836. f = h[1],
  32837. g = dot(i, d),
  32838. m = (0, _tfjsCore.split)(c, 3, c.rank - 1),
  32839. y = m[0],
  32840. v = m[1],
  32841. b = m[2],
  32842. w = (0, _tfjsCore.split)(g, 2, g.rank - 1),
  32843. z = w[0],
  32844. S = w[1];
  32845. a = n.recurrentActivation.apply((0, _tfjsCore.add)(y, z)), o = n.recurrentActivation.apply((0, _tfjsCore.add)(v, S));
  32846. var A = dot((0, _tfjsCore.mul)(o, i), f);
  32847. s = n.activation.apply((0, _tfjsCore.add)(b, A));
  32848. var _ = (0, _tfjsCore.add)((0, _tfjsCore.mul)(a, i), (0, _tfjsCore.mul)((0, _tfjsCore.add)(1, (0, _tfjsCore.neg)(a)), s));
  32849. return [_, _];
  32850. });
  32851. }, t.prototype.getConfig = function () {
  32852. var t = {
  32853. units: this.units,
  32854. activation: serializeActivation(this.activation),
  32855. recurrentActivation: serializeActivation(this.recurrentActivation),
  32856. useBias: this.useBias,
  32857. kernelInitializer: serializeInitializer(this.kernelInitializer),
  32858. recurrentInitializer: serializeInitializer(this.recurrentInitializer),
  32859. biasInitializer: serializeInitializer(this.biasInitializer),
  32860. kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
  32861. recurrentRegularizer: serializeRegularizer(this.recurrentRegularizer),
  32862. biasRegularizer: serializeRegularizer(this.biasRegularizer),
  32863. activityRegularizer: serializeRegularizer(this.activityRegularizer),
  32864. kernelConstraint: serializeConstraint(this.kernelConstraint),
  32865. recurrentConstraint: serializeConstraint(this.recurrentConstraint),
  32866. biasConstraint: serializeConstraint(this.biasConstraint),
  32867. dropout: this.dropout,
  32868. recurrentDropout: this.recurrentDropout,
  32869. implementation: this.implementation
  32870. },
  32871. n = e.prototype.getConfig.call(this);
  32872. return Object.assign(t, n), t;
  32873. }, t.className = "GRUCell", t;
  32874. }(RNNCell);
  32875. _tfjsCore.serialization.registerClass(GRUCell);
  32876. var GRU = function (e) {
  32877. function t(t) {
  32878. return 0 === t.implementation && console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."), t.cell = new GRUCell(t), e.call(this, t) || this;
  32879. }
  32880. return __extends(t, e), t.prototype.call = function (t, n) {
  32881. var r = this;
  32882. return (0, _tfjsCore.tidy)(function () {
  32883. null != r.cell.dropoutMask && ((0, _tfjsCore.dispose)(r.cell.dropoutMask), r.cell.dropoutMask = null), null != r.cell.recurrentDropoutMask && ((0, _tfjsCore.dispose)(r.cell.recurrentDropoutMask), r.cell.recurrentDropoutMask = null);
  32884. var i = null == n ? null : n.mask,
  32885. a = null == n ? null : n.training,
  32886. o = null == n ? null : n.initialState;
  32887. return e.prototype.call.call(r, t, {
  32888. mask: i,
  32889. training: a,
  32890. initialState: o
  32891. });
  32892. });
  32893. }, Object.defineProperty(t.prototype, "units", {
  32894. get: function () {
  32895. return this.cell.units;
  32896. },
  32897. enumerable: !0,
  32898. configurable: !0
  32899. }), Object.defineProperty(t.prototype, "activation", {
  32900. get: function () {
  32901. return this.cell.activation;
  32902. },
  32903. enumerable: !0,
  32904. configurable: !0
  32905. }), Object.defineProperty(t.prototype, "recurrentActivation", {
  32906. get: function () {
  32907. return this.cell.recurrentActivation;
  32908. },
  32909. enumerable: !0,
  32910. configurable: !0
  32911. }), Object.defineProperty(t.prototype, "useBias", {
  32912. get: function () {
  32913. return this.cell.useBias;
  32914. },
  32915. enumerable: !0,
  32916. configurable: !0
  32917. }), Object.defineProperty(t.prototype, "kernelInitializer", {
  32918. get: function () {
  32919. return this.cell.kernelInitializer;
  32920. },
  32921. enumerable: !0,
  32922. configurable: !0
  32923. }), Object.defineProperty(t.prototype, "recurrentInitializer", {
  32924. get: function () {
  32925. return this.cell.recurrentInitializer;
  32926. },
  32927. enumerable: !0,
  32928. configurable: !0
  32929. }), Object.defineProperty(t.prototype, "biasInitializer", {
  32930. get: function () {
  32931. return this.cell.biasInitializer;
  32932. },
  32933. enumerable: !0,
  32934. configurable: !0
  32935. }), Object.defineProperty(t.prototype, "kernelRegularizer", {
  32936. get: function () {
  32937. return this.cell.kernelRegularizer;
  32938. },
  32939. enumerable: !0,
  32940. configurable: !0
  32941. }), Object.defineProperty(t.prototype, "recurrentRegularizer", {
  32942. get: function () {
  32943. return this.cell.recurrentRegularizer;
  32944. },
  32945. enumerable: !0,
  32946. configurable: !0
  32947. }), Object.defineProperty(t.prototype, "biasRegularizer", {
  32948. get: function () {
  32949. return this.cell.biasRegularizer;
  32950. },
  32951. enumerable: !0,
  32952. configurable: !0
  32953. }), Object.defineProperty(t.prototype, "kernelConstraint", {
  32954. get: function () {
  32955. return this.cell.kernelConstraint;
  32956. },
  32957. enumerable: !0,
  32958. configurable: !0
  32959. }), Object.defineProperty(t.prototype, "recurrentConstraint", {
  32960. get: function () {
  32961. return this.cell.recurrentConstraint;
  32962. },
  32963. enumerable: !0,
  32964. configurable: !0
  32965. }), Object.defineProperty(t.prototype, "biasConstraint", {
  32966. get: function () {
  32967. return this.cell.biasConstraint;
  32968. },
  32969. enumerable: !0,
  32970. configurable: !0
  32971. }), Object.defineProperty(t.prototype, "dropout", {
  32972. get: function () {
  32973. return this.cell.dropout;
  32974. },
  32975. enumerable: !0,
  32976. configurable: !0
  32977. }), Object.defineProperty(t.prototype, "recurrentDropout", {
  32978. get: function () {
  32979. return this.cell.recurrentDropout;
  32980. },
  32981. enumerable: !0,
  32982. configurable: !0
  32983. }), Object.defineProperty(t.prototype, "implementation", {
  32984. get: function () {
  32985. return this.cell.implementation;
  32986. },
  32987. enumerable: !0,
  32988. configurable: !0
  32989. }), t.prototype.getConfig = function () {
  32990. var t = {
  32991. units: this.units,
  32992. activation: serializeActivation(this.activation),
  32993. recurrentActivation: serializeActivation(this.recurrentActivation),
  32994. useBias: this.useBias,
  32995. kernelInitializer: serializeInitializer(this.kernelInitializer),
  32996. recurrentInitializer: serializeInitializer(this.recurrentInitializer),
  32997. biasInitializer: serializeInitializer(this.biasInitializer),
  32998. kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
  32999. recurrentRegularizer: serializeRegularizer(this.recurrentRegularizer),
  33000. biasRegularizer: serializeRegularizer(this.biasRegularizer),
  33001. activityRegularizer: serializeRegularizer(this.activityRegularizer),
  33002. kernelConstraint: serializeConstraint(this.kernelConstraint),
  33003. recurrentConstraint: serializeConstraint(this.recurrentConstraint),
  33004. biasConstraint: serializeConstraint(this.biasConstraint),
  33005. dropout: this.dropout,
  33006. recurrentDropout: this.recurrentDropout,
  33007. implementation: this.implementation
  33008. },
  33009. n = e.prototype.getConfig.call(this);
  33010. return delete n.cell, Object.assign(t, n), t;
  33011. }, t.fromConfig = function (e, t) {
  33012. return 0 === t.implmentation && (t.implementation = 1), new e(t);
  33013. }, t.className = "GRU", t;
  33014. }(RNN);
  33015. _tfjsCore.serialization.registerClass(GRU);
  33016. var LSTMCell = function (e) {
  33017. function t(t) {
  33018. var n = e.call(this, t) || this;
  33019. return n.DEFAULT_ACTIVATION = "tanh", n.DEFAULT_RECURRENT_ACTIVATION = "hardSigmoid", n.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", n.DEFAULT_RECURRENT_INITIALIZER = "orthogonal", n.DEFAULT_BIAS_INITIALIZER = "zeros", n.units = t.units, assertPositiveInteger(n.units, "units"), n.activation = getActivation(void 0 === t.activation ? n.DEFAULT_ACTIVATION : t.activation), n.recurrentActivation = getActivation(void 0 === t.recurrentActivation ? n.DEFAULT_RECURRENT_ACTIVATION : t.recurrentActivation), n.useBias = null == t.useBias || t.useBias, n.kernelInitializer = getInitializer(t.kernelInitializer || n.DEFAULT_KERNEL_INITIALIZER), n.recurrentInitializer = getInitializer(t.recurrentInitializer || n.DEFAULT_RECURRENT_INITIALIZER), n.biasInitializer = getInitializer(t.biasInitializer || n.DEFAULT_BIAS_INITIALIZER), n.unitForgetBias = t.unitForgetBias, n.kernelRegularizer = getRegularizer(t.kernelRegularizer), n.recurrentRegularizer = getRegularizer(t.recurrentRegularizer), n.biasRegularizer = getRegularizer(t.biasRegularizer), n.kernelConstraint = getConstraint(t.kernelConstraint), n.recurrentConstraint = getConstraint(t.recurrentConstraint), n.biasConstraint = getConstraint(t.biasConstraint), n.dropout = min$1([1, max$1([0, null == t.dropout ? 0 : t.dropout])]), n.recurrentDropout = min$1([1, max$1([0, null == t.recurrentDropout ? 0 : t.recurrentDropout])]), n.implementation = t.implementation, n.stateSize = [n.units, n.units], n.dropoutMask = null, n.recurrentDropoutMask = null, n;
  33020. }
  33021. return __extends(t, e), t.prototype.build = function (e) {
  33022. var t,
  33023. n,
  33024. r = (e = getExactlyOneShape(e))[e.length - 1];
  33025. if (this.kernel = this.addWeight("kernel", [r, 4 * this.units], null, this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.recurrentKernel = this.addWeight("recurrent_kernel", [this.units, 4 * this.units], null, this.recurrentInitializer, this.recurrentRegularizer, !0, this.recurrentConstraint), this.useBias) {
  33026. if (this.unitForgetBias) {
  33027. var i = this.biasInitializer,
  33028. a = this.units;
  33029. n = new ((t = function (e) {
  33030. function t() {
  33031. return null !== e && e.apply(this, arguments) || this;
  33032. }
  33033. return __extends(t, e), t.prototype.apply = function (e, t) {
  33034. var n = i.apply([a]),
  33035. r = new Ones().apply([a]),
  33036. o = i.apply([2 * a]);
  33037. return concatAlongFirstAxis(concatAlongFirstAxis(n, r), o);
  33038. }, t;
  33039. }(Initializer)).className = "CustomInit", t)();
  33040. } else n = this.biasInitializer;
  33041. this.bias = this.addWeight("bias", [4 * this.units], null, n, this.biasRegularizer, !0, this.biasConstraint);
  33042. } else this.bias = null;
  33043. this.built = !0;
  33044. }, t.prototype.call = function (e, t) {
  33045. var n = this;
  33046. return (0, _tfjsCore.tidy)(function () {
  33047. var r = null != t.training && t.training;
  33048. if (3 !== (e = e).length) throw new ValueError("LSTMCell expects 3 input Tensors (inputs, h, c), got " + e.length + ".");
  33049. var i = e[1],
  33050. a = e[2];
  33051. e = e[0], 0 < n.dropout && n.dropout < 1 && null == n.dropoutMask && (n.dropoutMask = generateDropoutMask(function () {
  33052. return (0, _tfjsCore.onesLike)(e);
  33053. }, n.dropout, r, 4)), 0 < n.recurrentDropout && n.recurrentDropout < 1 && null == n.recurrentDropoutMask && (n.recurrentDropoutMask = generateDropoutMask(function () {
  33054. return (0, _tfjsCore.onesLike)(i);
  33055. }, n.recurrentDropout, r, 4));
  33056. var o,
  33057. s,
  33058. l,
  33059. u,
  33060. c = n.dropoutMask,
  33061. p = n.recurrentDropoutMask;
  33062. 0 < n.dropout && n.dropout < 1 && (e = (0, _tfjsCore.mul)(e, c[0]));
  33063. var h = dot(e, n.kernel.read());
  33064. 0 < n.recurrentDropout && n.recurrentDropout < 1 && (i = (0, _tfjsCore.mul)(i, p[0])), h = (0, _tfjsCore.add)(h, dot(i, n.recurrentKernel.read())), n.useBias && (h = biasAdd(h, n.bias.read()));
  33065. var d = (0, _tfjsCore.split)(h, 4, h.rank - 1),
  33066. f = d[0],
  33067. g = d[1],
  33068. m = d[2],
  33069. y = d[3];
  33070. o = n.recurrentActivation.apply(f), s = n.recurrentActivation.apply(g), l = (0, _tfjsCore.add)((0, _tfjsCore.mul)(s, a), (0, _tfjsCore.mul)(o, n.activation.apply(m))), u = n.recurrentActivation.apply(y);
  33071. var v = (0, _tfjsCore.mul)(u, n.activation.apply(l));
  33072. return [v, v, l];
  33073. });
  33074. }, t.prototype.getConfig = function () {
  33075. var t = {
  33076. units: this.units,
  33077. activation: serializeActivation(this.activation),
  33078. recurrentActivation: serializeActivation(this.recurrentActivation),
  33079. useBias: this.useBias,
  33080. kernelInitializer: serializeInitializer(this.kernelInitializer),
  33081. recurrentInitializer: serializeInitializer(this.recurrentInitializer),
  33082. biasInitializer: serializeInitializer(this.biasInitializer),
  33083. unitForgetBias: this.unitForgetBias,
  33084. kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
  33085. recurrentRegularizer: serializeRegularizer(this.recurrentRegularizer),
  33086. biasRegularizer: serializeRegularizer(this.biasRegularizer),
  33087. activityRegularizer: serializeRegularizer(this.activityRegularizer),
  33088. kernelConstraint: serializeConstraint(this.kernelConstraint),
  33089. recurrentConstraint: serializeConstraint(this.recurrentConstraint),
  33090. biasConstraint: serializeConstraint(this.biasConstraint),
  33091. dropout: this.dropout,
  33092. recurrentDropout: this.recurrentDropout,
  33093. implementation: this.implementation
  33094. },
  33095. n = e.prototype.getConfig.call(this);
  33096. return Object.assign(t, n), t;
  33097. }, t.className = "LSTMCell", t;
  33098. }(RNNCell);
  33099. _tfjsCore.serialization.registerClass(LSTMCell);
  33100. var LSTM = function (e) {
  33101. function t(t) {
  33102. return 0 === t.implementation && console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."), t.cell = new LSTMCell(t), e.call(this, t) || this;
  33103. }
  33104. return __extends(t, e), t.prototype.call = function (t, n) {
  33105. var r = this;
  33106. return (0, _tfjsCore.tidy)(function () {
  33107. null != r.cell.dropoutMask && ((0, _tfjsCore.dispose)(r.cell.dropoutMask), r.cell.dropoutMask = null), null != r.cell.recurrentDropoutMask && ((0, _tfjsCore.dispose)(r.cell.recurrentDropoutMask), r.cell.recurrentDropoutMask = null);
  33108. var i = null == n ? null : n.mask,
  33109. a = null == n ? null : n.training,
  33110. o = null == n ? null : n.initialState;
  33111. return e.prototype.call.call(r, t, {
  33112. mask: i,
  33113. training: a,
  33114. initialState: o
  33115. });
  33116. });
  33117. }, Object.defineProperty(t.prototype, "units", {
  33118. get: function () {
  33119. return this.cell.units;
  33120. },
  33121. enumerable: !0,
  33122. configurable: !0
  33123. }), Object.defineProperty(t.prototype, "activation", {
  33124. get: function () {
  33125. return this.cell.activation;
  33126. },
  33127. enumerable: !0,
  33128. configurable: !0
  33129. }), Object.defineProperty(t.prototype, "recurrentActivation", {
  33130. get: function () {
  33131. return this.cell.recurrentActivation;
  33132. },
  33133. enumerable: !0,
  33134. configurable: !0
  33135. }), Object.defineProperty(t.prototype, "useBias", {
  33136. get: function () {
  33137. return this.cell.useBias;
  33138. },
  33139. enumerable: !0,
  33140. configurable: !0
  33141. }), Object.defineProperty(t.prototype, "kernelInitializer", {
  33142. get: function () {
  33143. return this.cell.kernelInitializer;
  33144. },
  33145. enumerable: !0,
  33146. configurable: !0
  33147. }), Object.defineProperty(t.prototype, "recurrentInitializer", {
  33148. get: function () {
  33149. return this.cell.recurrentInitializer;
  33150. },
  33151. enumerable: !0,
  33152. configurable: !0
  33153. }), Object.defineProperty(t.prototype, "biasInitializer", {
  33154. get: function () {
  33155. return this.cell.biasInitializer;
  33156. },
  33157. enumerable: !0,
  33158. configurable: !0
  33159. }), Object.defineProperty(t.prototype, "unitForgetBias", {
  33160. get: function () {
  33161. return this.cell.unitForgetBias;
  33162. },
  33163. enumerable: !0,
  33164. configurable: !0
  33165. }), Object.defineProperty(t.prototype, "kernelRegularizer", {
  33166. get: function () {
  33167. return this.cell.kernelRegularizer;
  33168. },
  33169. enumerable: !0,
  33170. configurable: !0
  33171. }), Object.defineProperty(t.prototype, "recurrentRegularizer", {
  33172. get: function () {
  33173. return this.cell.recurrentRegularizer;
  33174. },
  33175. enumerable: !0,
  33176. configurable: !0
  33177. }), Object.defineProperty(t.prototype, "biasRegularizer", {
  33178. get: function () {
  33179. return this.cell.biasRegularizer;
  33180. },
  33181. enumerable: !0,
  33182. configurable: !0
  33183. }), Object.defineProperty(t.prototype, "kernelConstraint", {
  33184. get: function () {
  33185. return this.cell.kernelConstraint;
  33186. },
  33187. enumerable: !0,
  33188. configurable: !0
  33189. }), Object.defineProperty(t.prototype, "recurrentConstraint", {
  33190. get: function () {
  33191. return this.cell.recurrentConstraint;
  33192. },
  33193. enumerable: !0,
  33194. configurable: !0
  33195. }), Object.defineProperty(t.prototype, "biasConstraint", {
  33196. get: function () {
  33197. return this.cell.biasConstraint;
  33198. },
  33199. enumerable: !0,
  33200. configurable: !0
  33201. }), Object.defineProperty(t.prototype, "dropout", {
  33202. get: function () {
  33203. return this.cell.dropout;
  33204. },
  33205. enumerable: !0,
  33206. configurable: !0
  33207. }), Object.defineProperty(t.prototype, "recurrentDropout", {
  33208. get: function () {
  33209. return this.cell.recurrentDropout;
  33210. },
  33211. enumerable: !0,
  33212. configurable: !0
  33213. }), Object.defineProperty(t.prototype, "implementation", {
  33214. get: function () {
  33215. return this.cell.implementation;
  33216. },
  33217. enumerable: !0,
  33218. configurable: !0
  33219. }), t.prototype.getConfig = function () {
  33220. var t = {
  33221. units: this.units,
  33222. activation: serializeActivation(this.activation),
  33223. recurrentActivation: serializeActivation(this.recurrentActivation),
  33224. useBias: this.useBias,
  33225. kernelInitializer: serializeInitializer(this.kernelInitializer),
  33226. recurrentInitializer: serializeInitializer(this.recurrentInitializer),
  33227. biasInitializer: serializeInitializer(this.biasInitializer),
  33228. unitForgetBias: this.unitForgetBias,
  33229. kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
  33230. recurrentRegularizer: serializeRegularizer(this.recurrentRegularizer),
  33231. biasRegularizer: serializeRegularizer(this.biasRegularizer),
  33232. activityRegularizer: serializeRegularizer(this.activityRegularizer),
  33233. kernelConstraint: serializeConstraint(this.kernelConstraint),
  33234. recurrentConstraint: serializeConstraint(this.recurrentConstraint),
  33235. biasConstraint: serializeConstraint(this.biasConstraint),
  33236. dropout: this.dropout,
  33237. recurrentDropout: this.recurrentDropout,
  33238. implementation: this.implementation
  33239. },
  33240. n = e.prototype.getConfig.call(this);
  33241. return delete n.cell, Object.assign(t, n), t;
  33242. }, t.fromConfig = function (e, t) {
  33243. return 0 === t.implmentation && (t.implementation = 1), new e(t);
  33244. }, t.className = "LSTM", t;
  33245. }(RNN);
  33246. _tfjsCore.serialization.registerClass(LSTM);
  33247. var StackedRNNCells = function (e) {
  33248. function t(t) {
  33249. var n = e.call(this, t) || this;
  33250. return n.cells = t.cells, n;
  33251. }
  33252. return __extends(t, e), Object.defineProperty(t.prototype, "stateSize", {
  33253. get: function () {
  33254. for (var e = [], t = 0, n = this.cells.slice().reverse(); t < n.length; t++) {
  33255. var r = n[t];
  33256. Array.isArray(r.stateSize) ? e.push.apply(e, r.stateSize) : e.push(r.stateSize);
  33257. }
  33258. return e;
  33259. },
  33260. enumerable: !0,
  33261. configurable: !0
  33262. }), t.prototype.call = function (e, t) {
  33263. var n = this;
  33264. return (0, _tfjsCore.tidy)(function () {
  33265. for (var r = (e = e).slice(1), i = [], a = 0, o = n.cells.slice().reverse(); a < o.length; a++) {
  33266. var s = o[a];
  33267. Array.isArray(s.stateSize) ? i.push(r.splice(0, s.stateSize.length)) : i.push(r.splice(0, 1));
  33268. }
  33269. i.reverse();
  33270. for (var l, u = [], c = 0; c < n.cells.length; ++c) {
  33271. s = n.cells[c];
  33272. r = i[c], l = 0 === c ? [e[0]].concat(r) : [l[0]].concat(r), l = s.call(l, t), u.push(l.slice(1));
  33273. }
  33274. r = [];
  33275. for (var p = 0, h = u.slice().reverse(); p < h.length; p++) {
  33276. var d = h[p];
  33277. r.push.apply(r, d);
  33278. }
  33279. return [l[0]].concat(r);
  33280. });
  33281. }, t.prototype.build = function (e) {
  33282. var t;
  33283. isArrayOfShapes(e) && (e = e[0]), e = e, this.cells.forEach(function (n, r) {
  33284. nameScope("RNNCell_" + r, function () {
  33285. n.build(e), t = Array.isArray(n.stateSize) ? n.stateSize[0] : n.stateSize, e = [e[0], t];
  33286. });
  33287. }), this.built = !0;
  33288. }, t.prototype.getConfig = function () {
  33289. for (var t = [], n = 0, r = this.cells; n < r.length; n++) {
  33290. var i = r[n];
  33291. t.push({
  33292. className: i.getClassName(),
  33293. config: i.getConfig()
  33294. });
  33295. }
  33296. var a = {
  33297. cells: t
  33298. },
  33299. o = e.prototype.getConfig.call(this);
  33300. return Object.assign(a, o), a;
  33301. }, t.fromConfig = function (e, t, n) {
  33302. void 0 === n && (n = {});
  33303. for (var r = [], i = 0, a = t.cells; i < a.length; i++) {
  33304. var o = a[i];
  33305. r.push(deserialize(o, n));
  33306. }
  33307. return new e({
  33308. cells: r
  33309. });
  33310. }, Object.defineProperty(t.prototype, "trainableWeights", {
  33311. get: function () {
  33312. if (!this.trainable) return [];
  33313. for (var e = [], t = 0, n = this.cells; t < n.length; t++) {
  33314. var r = n[t];
  33315. e.push.apply(e, r.trainableWeights);
  33316. }
  33317. return e;
  33318. },
  33319. enumerable: !0,
  33320. configurable: !0
  33321. }), Object.defineProperty(t.prototype, "nonTrainableWeights", {
  33322. get: function () {
  33323. for (var e = [], t = 0, n = this.cells; t < n.length; t++) {
  33324. var r = n[t];
  33325. e.push.apply(e, r.nonTrainableWeights);
  33326. }
  33327. if (!this.trainable) {
  33328. for (var i = [], a = 0, o = this.cells; a < o.length; a++) {
  33329. r = o[a];
  33330. i.push.apply(i, r.trainableWeights);
  33331. }
  33332. return i.concat(e);
  33333. }
  33334. return e;
  33335. },
  33336. enumerable: !0,
  33337. configurable: !0
  33338. }), t.prototype.getWeights = function () {
  33339. for (var e = [], t = 0, n = this.cells; t < n.length; t++) {
  33340. var r = n[t];
  33341. e.push.apply(e, r.weights);
  33342. }
  33343. return batchGetValue(e);
  33344. }, t.prototype.setWeights = function (e) {
  33345. for (var t = [], n = 0, r = this.cells; n < r.length; n++) for (var i = r[n], a = i.weights.length, o = e.splice(a), s = 0; s < i.weights.length; ++s) t.push([i.weights[s], o[s]]);
  33346. batchSetValue(t);
  33347. }, t.className = "StackedRNNCells", t;
  33348. }(RNNCell);
  33349. function generateDropoutMask(e, t, n, r) {
  33350. function i() {
  33351. return dropout$1(e(), t);
  33352. }
  33353. if (void 0 === n && (n = null), void 0 === r && (r = 1), r > 1) {
  33354. for (var a = [], o = 0; o < r; o++) a.push(inTrainPhase(i, e, n));
  33355. return a.map(function (e) {
  33356. return (0, _tfjsCore.keep)(e.clone());
  33357. });
  33358. }
  33359. return (0, _tfjsCore.keep)(inTrainPhase(i, e, n).clone());
  33360. }
  33361. _tfjsCore.serialization.registerClass(StackedRNNCells);
  33362. var Wrapper = function (e) {
  33363. function t(t) {
  33364. var n = e.call(this, t) || this;
  33365. return n.layer = t.layer, n;
  33366. }
  33367. return __extends(t, e), t.prototype.build = function (e) {
  33368. this.built = !0;
  33369. }, Object.defineProperty(t.prototype, "trainable", {
  33370. get: function () {
  33371. return null != this.layer && this.layer.trainable;
  33372. },
  33373. set: function (e) {
  33374. null != this.layer && (this.layer.trainable = e);
  33375. },
  33376. enumerable: !0,
  33377. configurable: !0
  33378. }), Object.defineProperty(t.prototype, "trainableWeights", {
  33379. get: function () {
  33380. return this.layer.trainableWeights;
  33381. },
  33382. enumerable: !0,
  33383. configurable: !0
  33384. }), Object.defineProperty(t.prototype, "nonTrainableWeights", {
  33385. get: function () {
  33386. return this.layer.nonTrainableWeights;
  33387. },
  33388. enumerable: !0,
  33389. configurable: !0
  33390. }), Object.defineProperty(t.prototype, "updates", {
  33391. get: function () {
  33392. return this.layer._updates;
  33393. },
  33394. enumerable: !0,
  33395. configurable: !0
  33396. }), Object.defineProperty(t.prototype, "losses", {
  33397. get: function () {
  33398. return this.layer.losses;
  33399. },
  33400. enumerable: !0,
  33401. configurable: !0
  33402. }), t.prototype.getWeights = function () {
  33403. return this.layer.getWeights();
  33404. }, t.prototype.setWeights = function (e) {
  33405. this.layer.setWeights(e);
  33406. }, t.prototype.getConfig = function () {
  33407. var t = {
  33408. layer: {
  33409. className: this.layer.getClassName(),
  33410. config: this.layer.getConfig()
  33411. }
  33412. },
  33413. n = e.prototype.getConfig.call(this);
  33414. return Object.assign(t, n), t;
  33415. }, t.prototype.setFastWeightInitDuringBuild = function (t) {
  33416. e.prototype.setFastWeightInitDuringBuild.call(this, t), null != this.layer && this.layer.setFastWeightInitDuringBuild(t);
  33417. }, t.fromConfig = function (e, t, n) {
  33418. void 0 === n && (n = {});
  33419. var r = deserialize(t.layer, n);
  33420. delete t.layer;
  33421. var i = {
  33422. layer: r
  33423. };
  33424. return Object.assign(i, t), new e(i);
  33425. }, t;
  33426. }(Layer),
  33427. TimeDistributed = function (e) {
  33428. function t(t) {
  33429. var n = e.call(this, t) || this;
  33430. return n.supportsMasking = !0, n;
  33431. }
  33432. return __extends(t, e), t.prototype.build = function (t) {
  33433. if ((t = getExactlyOneShape(t)).length < 3) throw new ValueError("TimeDistributed layer expects an input shape >= 3D, but received input shape " + JSON.stringify(t));
  33434. this.inputSpec = [{
  33435. shape: t
  33436. }];
  33437. var n = [t[0]].concat(t.slice(2));
  33438. this.layer.built || (this.layer.build(n), this.layer.built = !0), e.prototype.build.call(this, t);
  33439. }, t.prototype.computeOutputShape = function (e) {
  33440. var t = [(e = getExactlyOneShape(e))[0]].concat(e.slice(2)),
  33441. n = this.layer.computeOutputShape(t),
  33442. r = e[1];
  33443. return [n[0], r].concat(n.slice(1));
  33444. }, t.prototype.call = function (e, t) {
  33445. var n = this;
  33446. return (0, _tfjsCore.tidy)(function () {
  33447. return rnn(function (e, r) {
  33448. return [getExactlyOneTensor(n.layer.call(e, t)), []];
  33449. }, e = getExactlyOneTensor(e), [], !1, null, null, !1, !0)[1];
  33450. });
  33451. }, t.className = "TimeDistributed", t;
  33452. }(Wrapper);
  33453. function checkBidirectionalMergeMode(e) {
  33454. checkStringTypeUnionValue(VALID_BIDIRECTIONAL_MERGE_MODES, "BidirectionalMergeMode", e);
  33455. }
  33456. _tfjsCore.serialization.registerClass(TimeDistributed);
  33457. var DEFAULT_BIDIRECTIONAL_MERGE_MODE = "concat",
  33458. Bidirectional = function (e) {
  33459. function t(t) {
  33460. var n = e.call(this, t) || this,
  33461. r = t.layer.getConfig(),
  33462. i = {};
  33463. i.className = t.layer.getClassName(), i.config = r, n.forwardLayer = deserialize(i), r.goBackwards = !0 !== r.goBackwards;
  33464. var a = {};
  33465. if (a.className = t.layer.getClassName(), a.config = r, n.backwardLayer = deserialize(a), n.forwardLayer.name = "forward_" + n.forwardLayer.name, n.backwardLayer.name = "backward_" + n.backwardLayer.name, n.mergeMode = void 0 === t.mergeMode ? DEFAULT_BIDIRECTIONAL_MERGE_MODE : t.mergeMode, checkBidirectionalMergeMode(n.mergeMode), t.weights) throw new NotImplementedError("weights support is not implemented for Bidirectional layer yet.");
  33466. return n._stateful = t.layer.stateful, n.returnSequences = t.layer.returnSequences, n.returnState = t.layer.returnState, n.supportsMasking = !0, n._trainable = !0, n.inputSpec = t.layer.inputSpec, n.numConstants = null, n;
  33467. }
  33468. return __extends(t, e), Object.defineProperty(t.prototype, "trainable", {
  33469. get: function () {
  33470. return this._trainable;
  33471. },
  33472. set: function (e) {
  33473. this._trainable = e, null != this.forwardLayer && (this.forwardLayer.trainable = e), null != this.backwardLayer && (this.backwardLayer.trainable = e);
  33474. },
  33475. enumerable: !0,
  33476. configurable: !0
  33477. }), t.prototype.getWeights = function () {
  33478. return this.forwardLayer.getWeights().concat(this.backwardLayer.getWeights());
  33479. }, t.prototype.setWeights = function (e) {
  33480. var t = e.length,
  33481. n = Math.floor(t / 2);
  33482. this.forwardLayer.setWeights(e.slice(0, n)), this.backwardLayer.setWeights(e.slice(n));
  33483. }, t.prototype.computeOutputShape = function (e) {
  33484. var t,
  33485. n,
  33486. r,
  33487. i = this.forwardLayer.computeOutputShape(e);
  33488. return Array.isArray(i) && Array.isArray(i[0]) || (i = [i]), i = i, this.returnState ? (r = i.slice(1), t = i[0]) : t = i[0], t = t, "concat" === this.mergeMode ? (t[t.length - 1] *= 2, n = [t]) : n = null == this.mergeMode ? [t, t.slice()] : [t], this.returnState ? null == this.mergeMode ? n.concat(r).concat(r.slice()) : [t].concat(r).concat(r.slice()) : singletonOrArray(n);
  33489. }, t.prototype.apply = function (t, n) {
  33490. var r = null == n ? null : n.initialState,
  33491. i = null == n ? null : n.constants;
  33492. null == n && (n = {});
  33493. var a = standardizeArgs(t, r, i, this.numConstants);
  33494. if (t = a.inputs, r = a.initialState, i = a.constants, Array.isArray(t) && (r = t.slice(1), t = t[0]), (null == r || 0 === r.length) && null == i) return e.prototype.apply.call(this, t, n);
  33495. var o = [],
  33496. s = [];
  33497. if (null != r) {
  33498. var l = r.length;
  33499. if (l % 2 > 0) throw new ValueError("When passing `initialState` to a Bidrectional RNN, the state should be an Array containing the states of the underlying RNNs.");
  33500. n.initialState = r, o.push.apply(o, r);
  33501. var u = r.map(function (e) {
  33502. return new InputSpec({
  33503. shape: e.shape
  33504. });
  33505. });
  33506. this.forwardLayer.stateSpec = u.slice(0, l / 2), this.backwardLayer.stateSpec = u.slice(l / 2), s.push.apply(s, u);
  33507. }
  33508. if (null != i) throw new NotImplementedError("Support for constants in Bidirectional layers is not implemented yet.");
  33509. for (var c = o[0] instanceof SymbolicTensor, p = 0, h = o; p < h.length; p++) {
  33510. if (h[p] instanceof SymbolicTensor !== c) throw new ValueError("The initial state of a Bidirectional layer cannot be specified as a mix of symbolic and non-symbolic tensors");
  33511. }
  33512. if (c) {
  33513. var d = [t].concat(o),
  33514. f = this.inputSpec.concat(s),
  33515. g = this.inputSpec;
  33516. this.inputSpec = f;
  33517. var m = e.prototype.apply.call(this, d, n);
  33518. return this.inputSpec = g, m;
  33519. }
  33520. return e.prototype.apply.call(this, t, n);
  33521. }, t.prototype.call = function (e, t) {
  33522. var n = this;
  33523. return (0, _tfjsCore.tidy)(function () {
  33524. if (null != t.mask) throw new NotImplementedError("The support for masking is not implemented for Bidirectional layers yet.");
  33525. var r,
  33526. i,
  33527. a,
  33528. o,
  33529. s = t.initialState;
  33530. if (null == s) r = n.forwardLayer.call(e, t), i = n.backwardLayer.call(e, t); else {
  33531. var l = s.slice(0, s.length / 2),
  33532. u = s.slice(s.length / 2);
  33533. r = n.forwardLayer.call(e, Object.assign(t, {
  33534. initialState: l
  33535. })), i = n.backwardLayer.call(e, Object.assign(t, {
  33536. initialState: u
  33537. }));
  33538. }
  33539. return n.returnState && (Array.isArray(r) && (a = r.slice(1).concat(i.slice(1))), r = r[0], i = i[0]), n.returnSequences && (i = (0, _tfjsCore.reverse)(i, 1)), "concat" === n.mergeMode ? o = concatenate([r, i]) : "sum" === n.mergeMode ? o = (0, _tfjsCore.add)(r, i) : "ave" === n.mergeMode ? o = (0, _tfjsCore.mul)(.5, (0, _tfjsCore.add)(r, i)) : "mul" === n.mergeMode ? o = (0, _tfjsCore.mul)(r, i) : null == n.mergeMode && (o = [r, i]), n.returnState ? null == n.mergeMode ? o.concat(a) : [o].concat(a) : o;
  33540. });
  33541. }, t.prototype.resetStates = function (e) {
  33542. this.forwardLayer.resetStates(), this.backwardLayer.resetStates();
  33543. }, t.prototype.build = function (e) {
  33544. var t = this;
  33545. nameScope(this.forwardLayer.name, function () {
  33546. t.forwardLayer.build(e);
  33547. }), nameScope(this.backwardLayer.name, function () {
  33548. t.backwardLayer.build(e);
  33549. }), this.built = !0;
  33550. }, Object.defineProperty(t.prototype, "trainableWeights", {
  33551. get: function () {
  33552. return this.forwardLayer.trainableWeights.concat(this.backwardLayer.trainableWeights);
  33553. },
  33554. enumerable: !0,
  33555. configurable: !0
  33556. }), Object.defineProperty(t.prototype, "nonTrainableWeights", {
  33557. get: function () {
  33558. return this.forwardLayer.nonTrainableWeights.concat(this.backwardLayer.nonTrainableWeights);
  33559. },
  33560. enumerable: !0,
  33561. configurable: !0
  33562. }), t.prototype.setFastWeightInitDuringBuild = function (t) {
  33563. e.prototype.setFastWeightInitDuringBuild.call(this, t), null != this.forwardLayer && this.forwardLayer.setFastWeightInitDuringBuild(t), null != this.backwardLayer && this.backwardLayer.setFastWeightInitDuringBuild(t);
  33564. }, t.prototype.getConfig = function () {
  33565. var t = {
  33566. mergeMode: this.mergeMode
  33567. },
  33568. n = e.prototype.getConfig.call(this);
  33569. return Object.assign(t, n), t;
  33570. }, t.fromConfig = function (e, t) {
  33571. var n = deserialize(t.layer);
  33572. if (delete t.layer, null != t.numConstants) throw new NotImplementedError("Deserialization of a Bidirectional layer with numConstants present is not supported yet.");
  33573. var r = t;
  33574. return r.layer = n, new e(r);
  33575. }, t.className = "Bidirectional", t;
  33576. }(Wrapper);
  33577. function inputLayer(e) {
  33578. return new InputLayer(e);
  33579. }
  33580. function elu$2(e) {
  33581. return new ELU(e);
  33582. }
  33583. function reLU(e) {
  33584. return new ReLU(e);
  33585. }
  33586. function leakyReLU(e) {
  33587. return new LeakyReLU(e);
  33588. }
  33589. function prelu$1(e) {
  33590. return new PReLU(e);
  33591. }
  33592. function softmax$1(e) {
  33593. return new Softmax$1(e);
  33594. }
  33595. function thresholdedReLU(e) {
  33596. return new ThresholdedReLU(e);
  33597. }
  33598. function conv1d$2(e) {
  33599. return new Conv1D(e);
  33600. }
  33601. function conv2d$1(e) {
  33602. return new Conv2D(e);
  33603. }
  33604. function conv2dTranspose$1(e) {
  33605. return new Conv2DTranspose(e);
  33606. }
  33607. function conv3d$2(e) {
  33608. return new Conv3D(e);
  33609. }
  33610. function separableConv2d$1(e) {
  33611. return new SeparableConv2D(e);
  33612. }
  33613. function cropping2D(e) {
  33614. return new Cropping2D(e);
  33615. }
  33616. function upSampling2d(e) {
  33617. return new UpSampling2D(e);
  33618. }
  33619. function depthwiseConv2d$2(e) {
  33620. return new DepthwiseConv2D(e);
  33621. }
  33622. function activation(e) {
  33623. return new Activation$1(e);
  33624. }
  33625. function dense(e) {
  33626. return new Dense(e);
  33627. }
  33628. function dropout$2(e) {
  33629. return new Dropout(e);
  33630. }
  33631. function flatten$1(e) {
  33632. return new Flatten(e);
  33633. }
  33634. function repeatVector(e) {
  33635. return new RepeatVector(e);
  33636. }
  33637. function reshape(e) {
  33638. return new Reshape(e);
  33639. }
  33640. function permute(e) {
  33641. return new Permute(e);
  33642. }
  33643. function embedding(e) {
  33644. return new Embedding(e);
  33645. }
  33646. function add$2(e) {
  33647. return new Add(e);
  33648. }
  33649. function average$1(e) {
  33650. return new Average(e);
  33651. }
  33652. function concatenate$2(e) {
  33653. return new Concatenate(e);
  33654. }
  33655. function maximum$2(e) {
  33656. return new Maximum(e);
  33657. }
  33658. function minimum$2(e) {
  33659. return new Minimum(e);
  33660. }
  33661. function multiply$1(e) {
  33662. return new Multiply(e);
  33663. }
  33664. function dot$1(e) {
  33665. return new Dot(e);
  33666. }
  33667. function batchNormalization$1(e) {
  33668. return new BatchNormalization(e);
  33669. }
  33670. function layerNormalization(e) {
  33671. return new LayerNormalization(e);
  33672. }
  33673. function zeroPadding2d(e) {
  33674. return new ZeroPadding2D(e);
  33675. }
  33676. function averagePooling1d(e) {
  33677. return new AveragePooling1D(e);
  33678. }
  33679. function avgPool1d(e) {
  33680. return averagePooling1d(e);
  33681. }
  33682. function avgPooling1d(e) {
  33683. return averagePooling1d(e);
  33684. }
  33685. function averagePooling2d(e) {
  33686. return new AveragePooling2D(e);
  33687. }
  33688. function avgPool2d(e) {
  33689. return averagePooling2d(e);
  33690. }
  33691. function avgPooling2d(e) {
  33692. return averagePooling2d(e);
  33693. }
  33694. function averagePooling3d(e) {
  33695. return new AveragePooling3D(e);
  33696. }
  33697. function avgPool3d$1(e) {
  33698. return averagePooling3d(e);
  33699. }
  33700. function avgPooling3d(e) {
  33701. return averagePooling3d(e);
  33702. }
  33703. function globalAveragePooling1d(e) {
  33704. return new GlobalAveragePooling1D(e);
  33705. }
  33706. function globalAveragePooling2d(e) {
  33707. return new GlobalAveragePooling2D(e);
  33708. }
  33709. function globalMaxPooling1d(e) {
  33710. return new GlobalMaxPooling1D(e);
  33711. }
  33712. function globalMaxPooling2d(e) {
  33713. return new GlobalMaxPooling2D(e);
  33714. }
  33715. function maxPooling1d(e) {
  33716. return new MaxPooling1D(e);
  33717. }
  33718. function maxPooling2d(e) {
  33719. return new MaxPooling2D(e);
  33720. }
  33721. function maxPooling3d(e) {
  33722. return new MaxPooling3D(e);
  33723. }
  33724. function gru(e) {
  33725. return new GRU(e);
  33726. }
  33727. function gruCell(e) {
  33728. return new GRUCell(e);
  33729. }
  33730. function lstm(e) {
  33731. return new LSTM(e);
  33732. }
  33733. function lstmCell(e) {
  33734. return new LSTMCell(e);
  33735. }
  33736. function simpleRNN(e) {
  33737. return new SimpleRNN(e);
  33738. }
  33739. function simpleRNNCell(e) {
  33740. return new SimpleRNNCell(e);
  33741. }
  33742. function rnn$1(e) {
  33743. return new RNN(e);
  33744. }
  33745. function stackedRNNCells(e) {
  33746. return new StackedRNNCells(e);
  33747. }
  33748. function bidirectional(e) {
  33749. return new Bidirectional(e);
  33750. }
  33751. function timeDistributed(e) {
  33752. return new TimeDistributed(e);
  33753. }
  33754. _tfjsCore.serialization.registerClass(Bidirectional);
  33755. var globalMaxPool1d = globalMaxPooling1d,
  33756. globalMaxPool2d = globalMaxPooling2d,
  33757. maxPool1d = maxPooling1d,
  33758. maxPool2d = maxPooling2d;
  33759. function gaussianNoise(e) {
  33760. return new GaussianNoise(e);
  33761. }
  33762. function gaussianDropout(e) {
  33763. return new GaussianDropout(e);
  33764. }
  33765. function alphaDropout(e) {
  33766. return new AlphaDropout(e);
  33767. }
  33768. function masking(e) {
  33769. return new Masking(e);
  33770. }
  33771. var exports_layers = Object.freeze({
  33772. inputLayer: inputLayer,
  33773. elu: elu$2,
  33774. reLU: reLU,
  33775. leakyReLU: leakyReLU,
  33776. prelu: prelu$1,
  33777. softmax: softmax$1,
  33778. thresholdedReLU: thresholdedReLU,
  33779. conv1d: conv1d$2,
  33780. conv2d: conv2d$1,
  33781. conv2dTranspose: conv2dTranspose$1,
  33782. conv3d: conv3d$2,
  33783. separableConv2d: separableConv2d$1,
  33784. cropping2D: cropping2D,
  33785. upSampling2d: upSampling2d,
  33786. depthwiseConv2d: depthwiseConv2d$2,
  33787. activation: activation,
  33788. dense: dense,
  33789. dropout: dropout$2,
  33790. flatten: flatten$1,
  33791. repeatVector: repeatVector,
  33792. reshape: reshape,
  33793. permute: permute,
  33794. embedding: embedding,
  33795. add: add$2,
  33796. average: average$1,
  33797. concatenate: concatenate$2,
  33798. maximum: maximum$2,
  33799. minimum: minimum$2,
  33800. multiply: multiply$1,
  33801. dot: dot$1,
  33802. batchNormalization: batchNormalization$1,
  33803. layerNormalization: layerNormalization,
  33804. zeroPadding2d: zeroPadding2d,
  33805. averagePooling1d: averagePooling1d,
  33806. avgPool1d: avgPool1d,
  33807. avgPooling1d: avgPooling1d,
  33808. averagePooling2d: averagePooling2d,
  33809. avgPool2d: avgPool2d,
  33810. avgPooling2d: avgPooling2d,
  33811. averagePooling3d: averagePooling3d,
  33812. avgPool3d: avgPool3d$1,
  33813. avgPooling3d: avgPooling3d,
  33814. globalAveragePooling1d: globalAveragePooling1d,
  33815. globalAveragePooling2d: globalAveragePooling2d,
  33816. globalMaxPooling1d: globalMaxPooling1d,
  33817. globalMaxPooling2d: globalMaxPooling2d,
  33818. maxPooling1d: maxPooling1d,
  33819. maxPooling2d: maxPooling2d,
  33820. maxPooling3d: maxPooling3d,
  33821. gru: gru,
  33822. gruCell: gruCell,
  33823. lstm: lstm,
  33824. lstmCell: lstmCell,
  33825. simpleRNN: simpleRNN,
  33826. simpleRNNCell: simpleRNNCell,
  33827. rnn: rnn$1,
  33828. stackedRNNCells: stackedRNNCells,
  33829. bidirectional: bidirectional,
  33830. timeDistributed: timeDistributed,
  33831. globalMaxPool1d: globalMaxPool1d,
  33832. globalMaxPool2d: globalMaxPool2d,
  33833. maxPool1d: maxPool1d,
  33834. maxPool2d: maxPool2d,
  33835. Layer: Layer,
  33836. RNN: RNN,
  33837. RNNCell: RNNCell,
  33838. input: input,
  33839. gaussianNoise: gaussianNoise,
  33840. gaussianDropout: gaussianDropout,
  33841. alphaDropout: alphaDropout,
  33842. masking: masking
  33843. });
  33844. exports.layers = exports_layers;
  33845. function binaryAccuracy$1(e, t) {
  33846. return binaryAccuracy(e, t);
  33847. }
  33848. function binaryCrossentropy$2(e, t) {
  33849. return binaryCrossentropy$1(e, t);
  33850. }
  33851. function sparseCategoricalAccuracy$1(e, t) {
  33852. return sparseCategoricalAccuracy(e, t);
  33853. }
  33854. function categoricalAccuracy$1(e, t) {
  33855. return categoricalAccuracy(e, t);
  33856. }
  33857. function categoricalCrossentropy$2(e, t) {
  33858. return categoricalCrossentropy$1(e, t);
  33859. }
  33860. function precision$1(e, t) {
  33861. return precision(e, t);
  33862. }
  33863. function recall$1(e, t) {
  33864. return recall(e, t);
  33865. }
  33866. function cosineProximity$1(e, t) {
  33867. return cosineProximity(e, t);
  33868. }
  33869. function meanAbsoluteError$1(e, t) {
  33870. return meanAbsoluteError(e, t);
  33871. }
  33872. function meanAbsolutePercentageError$1(e, t) {
  33873. return meanAbsolutePercentageError(e, t);
  33874. }
  33875. function MAPE$2(e, t) {
  33876. return meanAbsolutePercentageError(e, t);
  33877. }
  33878. function mape$2(e, t) {
  33879. return meanAbsolutePercentageError(e, t);
  33880. }
  33881. function meanSquaredError$1(e, t) {
  33882. return meanSquaredError(e, t);
  33883. }
  33884. function MSE$2(e, t) {
  33885. return meanSquaredError(e, t);
  33886. }
  33887. function mse$2(e, t) {
  33888. return meanSquaredError(e, t);
  33889. }
  33890. var exports_metrics = Object.freeze({
  33891. binaryAccuracy: binaryAccuracy$1,
  33892. binaryCrossentropy: binaryCrossentropy$2,
  33893. sparseCategoricalAccuracy: sparseCategoricalAccuracy$1,
  33894. categoricalAccuracy: categoricalAccuracy$1,
  33895. categoricalCrossentropy: categoricalCrossentropy$2,
  33896. precision: precision$1,
  33897. recall: recall$1,
  33898. cosineProximity: cosineProximity$1,
  33899. meanAbsoluteError: meanAbsoluteError$1,
  33900. meanAbsolutePercentageError: meanAbsolutePercentageError$1,
  33901. MAPE: MAPE$2,
  33902. mape: mape$2,
  33903. meanSquaredError: meanSquaredError$1,
  33904. MSE: MSE$2,
  33905. mse: mse$2
  33906. }),
  33907. exports_models = Object.freeze({
  33908. modelFromJSON: modelFromJSON
  33909. });
  33910. exports.models = exports_models;
  33911. exports.metrics = exports_metrics;
  33912. function l1l2(e) {
  33913. return new L1L2(e);
  33914. }
  33915. function l1$1(e) {
  33916. return l1(e);
  33917. }
  33918. function l2$1(e) {
  33919. return l2(e);
  33920. }
  33921. var exports_regularizers = Object.freeze({
  33922. l1l2: l1l2,
  33923. l1: l1$1,
  33924. l2: l2$1
  33925. }),
  33926. Callback = function (e) {
  33927. function t() {
  33928. var t = null !== e && e.apply(this, arguments) || this;
  33929. return t.model = null, t;
  33930. }
  33931. return __extends(t, e), t.prototype.setModel = function (e) {
  33932. if (!(e instanceof LayersModel)) throw new Error("model must be a LayersModel, not some other Container");
  33933. this.model = e;
  33934. }, t;
  33935. }(BaseCallback);
  33936. exports.Callback = Callback;
  33937. exports.regularizers = exports_regularizers;
  33938. function less(e, t) {
  33939. return e < t;
  33940. }
  33941. function greater$1(e, t) {
  33942. return e > t;
  33943. }
  33944. var EarlyStopping = function (e) {
  33945. function t(t) {
  33946. var n = e.call(this) || this;
  33947. if (null == t && (t = {}), t.restoreBestWeights) throw new NotImplementedError("restoreBestWeights = True is not implemented in EarlyStopping yet.");
  33948. return n.monitor = t.monitor || "val_loss", n.minDelta = Math.abs(t.minDelta || 0), n.patience = t.patience || 0, n.verbose = t.verbose || 0, n.mode = t.mode || "auto", n.baseline = t.baseline, -1 === ["auto", "min", "max"].indexOf(n.mode) && (console.warn("EarlyStopping mode '" + n.mode + "' is invalid. Falling back to mode 'auto'."), n.mode = "auto"), "min" === n.mode ? n.monitorFunc = less : "max" === n.mode ? n.monitorFunc = greater$1 : -1 !== n.monitor.indexOf("acc") ? n.monitorFunc = greater$1 : n.monitorFunc = less, n.monitorFunc === less && (n.minDelta *= -1), n;
  33949. }
  33950. return __extends(t, e), t.prototype.onTrainBegin = function (e) {
  33951. return __awaiter(this, void 0, void 0, function () {
  33952. return __generator(this, function (e) {
  33953. return this.wait = 0, this.stoppedEpoch = 0, null != this.baseline ? this.best = this.baseline : this.best = this.monitorFunc === less ? 1 / 0 : -1 / 0, [2];
  33954. });
  33955. });
  33956. }, t.prototype.onEpochEnd = function (e, t) {
  33957. return __awaiter(this, void 0, void 0, function () {
  33958. var n;
  33959. return __generator(this, function (r) {
  33960. switch (r.label) {
  33961. case 0:
  33962. return [4, resolveScalarsInLogs(t)];
  33963. case 1:
  33964. return r.sent(), null == (n = this.getMonitorValue(t)) ? [2] : (this.monitorFunc(n - this.minDelta, this.best) ? (this.best = n, this.wait = 0) : (this.wait++, this.wait >= this.patience && (this.stoppedEpoch = e, this.model.stopTraining = !0)), [2]);
  33965. }
  33966. });
  33967. });
  33968. }, t.prototype.onTrainEnd = function (e) {
  33969. return __awaiter(this, void 0, void 0, function () {
  33970. return __generator(this, function (e) {
  33971. return this.stoppedEpoch > 0 && this.verbose && console.log("Epoch " + this.stoppedEpoch + ": early stopping."), [2];
  33972. });
  33973. });
  33974. }, t.prototype.getMonitorValue = function (e) {
  33975. null == e && (e = {});
  33976. var t = e[this.monitor];
  33977. return null == t && console.warn("Metric for EarlyStopping " + this.monitor + " is not available. Available metrics are: " + Object.keys(e)), t;
  33978. }, t;
  33979. }(Callback);
  33980. exports.EarlyStopping = EarlyStopping;
  33981. function earlyStopping(e) {
  33982. return new EarlyStopping(e);
  33983. }
  33984. var callbacks = {
  33985. earlyStopping: earlyStopping
  33986. };
  33987. exports.callbacks = callbacks;
  33988. }, { "@tensorflow/tfjs-core": "node_modules/@tensorflow/tfjs-core/dist/tf-core.esm.js" }], "node_modules/@tensorflow/tfjs-data/dist/tf-data.esm.js": [function (require, module, exports) {
  33989. var global = arguments[3];
  33990. var Buffer = require("buffer").Buffer;
  33991. "use strict";
  33992. Object.defineProperty(exports, "__esModule", {
  33993. value: true
  33994. });
  33995. exports.array = array;
  33996. exports.zip = zip;
  33997. exports.csv = csv;
  33998. exports.func = func;
  33999. exports.generator = generator;
  34000. exports.microphone = microphone;
  34001. exports.webcam = webcam;
  34002. exports.version_data = exports.URLDataSource = exports.FileDataSource = exports.TextLineDataset = exports.CSVDataset = exports.Dataset = void 0;
  34003. var _tfjsCore = require("@tensorflow/tfjs-core");
  34004. /**
  34005. * @license
  34006. * Copyright 2019 Google LLC. All Rights Reserved.
  34007. * Licensed under the Apache License, Version 2.0 (the "License");
  34008. * you may not use this file except in compliance with the License.
  34009. * You may obtain a copy of the License at
  34010. *
  34011. * http://www.apache.org/licenses/LICENSE-2.0
  34012. *
  34013. * Unless required by applicable law or agreed to in writing, software
  34014. * distributed under the License is distributed on an "AS IS" BASIS,
  34015. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34016. * See the License for the specific language governing permissions and
  34017. * limitations under the License.
  34018. * =============================================================================
  34019. */
  34020. var extendStatics = function (t, e) {
  34021. return (extendStatics = Object.setPrototypeOf || {
  34022. __proto__: []
  34023. } instanceof Array && function (t, e) {
  34024. t.__proto__ = e;
  34025. } || function (t, e) {
  34026. for (var r in e) e.hasOwnProperty(r) && (t[r] = e[r]);
  34027. })(t, e);
  34028. };
  34029. function __extends(t, e) {
  34030. function r() {
  34031. this.constructor = t;
  34032. }
  34033. extendStatics(t, e), t.prototype = null === e ? Object.create(e) : (r.prototype = e.prototype, new r());
  34034. }
  34035. function __awaiter(t, e, r, n) {
  34036. return new (r || (r = Promise))(function (i, o) {
  34037. function a(t) {
  34038. try {
  34039. u(n.next(t));
  34040. } catch (t) {
  34041. o(t);
  34042. }
  34043. }
  34044. function s(t) {
  34045. try {
  34046. u(n.throw(t));
  34047. } catch (t) {
  34048. o(t);
  34049. }
  34050. }
  34051. function u(t) {
  34052. t.done ? i(t.value) : new r(function (e) {
  34053. e(t.value);
  34054. }).then(a, s);
  34055. }
  34056. u((n = n.apply(t, e || [])).next());
  34057. });
  34058. }
  34059. function __generator(t, e) {
  34060. var r,
  34061. n,
  34062. i,
  34063. o,
  34064. a = {
  34065. label: 0,
  34066. sent: function () {
  34067. if (1 & i[0]) throw i[1];
  34068. return i[1];
  34069. },
  34070. trys: [],
  34071. ops: []
  34072. };
  34073. return o = {
  34074. next: s(0),
  34075. throw: s(1),
  34076. return: s(2)
  34077. }, "function" == typeof Symbol && (o[Symbol.iterator] = function () {
  34078. return this;
  34079. }), o;
  34080. function s(o) {
  34081. return function (s) {
  34082. return function (o) {
  34083. if (r) throw new TypeError("Generator is already executing.");
  34084. for (; a;) try {
  34085. if (r = 1, n && (i = 2 & o[0] ? n.return : o[0] ? n.throw || ((i = n.return) && i.call(n), 0) : n.next) && !(i = i.call(n, o[1])).done) return i;
  34086. switch (n = 0, i && (o = [2 & o[0], i.value]), o[0]) {
  34087. case 0:
  34088. case 1:
  34089. i = o;
  34090. break;
  34091. case 4:
  34092. return a.label++, {
  34093. value: o[1],
  34094. done: !1
  34095. };
  34096. case 5:
  34097. a.label++, n = o[1], o = [0];
  34098. continue;
  34099. case 7:
  34100. o = a.ops.pop(), a.trys.pop();
  34101. continue;
  34102. default:
  34103. if (!(i = (i = a.trys).length > 0 && i[i.length - 1]) && (6 === o[0] || 2 === o[0])) {
  34104. a = 0;
  34105. continue;
  34106. }
  34107. if (3 === o[0] && (!i || o[1] > i[0] && o[1] < i[3])) {
  34108. a.label = o[1];
  34109. break;
  34110. }
  34111. if (6 === o[0] && a.label < i[1]) {
  34112. a.label = i[1], i = o;
  34113. break;
  34114. }
  34115. if (i && a.label < i[2]) {
  34116. a.label = i[2], a.ops.push(o);
  34117. break;
  34118. }
  34119. i[2] && a.ops.pop(), a.trys.pop();
  34120. continue;
  34121. }
  34122. o = e.call(t, a);
  34123. } catch (t) {
  34124. o = [6, t], n = 0;
  34125. } finally {
  34126. r = i = 0;
  34127. }
  34128. if (5 & o[0]) throw o[1];
  34129. return {
  34130. value: o[0] ? o[1] : void 0,
  34131. done: !0
  34132. };
  34133. }([o, s]);
  34134. };
  34135. }
  34136. }
  34137. var commonjsGlobal = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : {};
  34138. function createCommonjsModule(t, e) {
  34139. return t(e = {
  34140. exports: {}
  34141. }, e.exports), e.exports;
  34142. }
  34143. var alea = createCommonjsModule(function (t) {
  34144. !function (t, e, r) {
  34145. function n(t, e) {
  34146. return e.c = t.c, e.s0 = t.s0, e.s1 = t.s1, e.s2 = t.s2, e;
  34147. }
  34148. function i(t, e) {
  34149. var r = new function (t) {
  34150. var e,
  34151. r = this,
  34152. n = (e = 4022871197, function (t) {
  34153. t = t.toString();
  34154. for (var r = 0; r < t.length; r++) {
  34155. var n = .02519603282416938 * (e += t.charCodeAt(r));
  34156. n -= e = n >>> 0, e = (n *= e) >>> 0, e += 4294967296 * (n -= e);
  34157. }
  34158. return 2.3283064365386963e-10 * (e >>> 0);
  34159. });
  34160. r.next = function () {
  34161. var t = 2091639 * r.s0 + 2.3283064365386963e-10 * r.c;
  34162. return r.s0 = r.s1, r.s1 = r.s2, r.s2 = t - (r.c = 0 | t);
  34163. }, r.c = 1, r.s0 = n(" "), r.s1 = n(" "), r.s2 = n(" "), r.s0 -= n(t), r.s0 < 0 && (r.s0 += 1), r.s1 -= n(t), r.s1 < 0 && (r.s1 += 1), r.s2 -= n(t), r.s2 < 0 && (r.s2 += 1), n = null;
  34164. }(t),
  34165. i = e && e.state,
  34166. o = r.next;
  34167. return o.int32 = function () {
  34168. return 4294967296 * r.next() | 0;
  34169. }, o.double = function () {
  34170. return o() + 1.1102230246251565e-16 * (2097152 * o() | 0);
  34171. }, o.quick = o, i && ("object" == typeof i && n(i, r), o.state = function () {
  34172. return n(r, {});
  34173. }), o;
  34174. }
  34175. e && e.exports ? e.exports = i : r && r.amd ? r(function () {
  34176. return i;
  34177. }) : this.alea = i;
  34178. }(0, t, !1);
  34179. }),
  34180. xor128 = createCommonjsModule(function (t) {
  34181. !function (t, e, r) {
  34182. function n(t, e) {
  34183. return e.x = t.x, e.y = t.y, e.z = t.z, e.w = t.w, e;
  34184. }
  34185. function i(t, e) {
  34186. var r = new function (t) {
  34187. var e = this,
  34188. r = "";
  34189. e.x = 0, e.y = 0, e.z = 0, e.w = 0, e.next = function () {
  34190. var t = e.x ^ e.x << 11;
  34191. return e.x = e.y, e.y = e.z, e.z = e.w, e.w ^= e.w >>> 19 ^ t ^ t >>> 8;
  34192. }, t === (0 | t) ? e.x = t : r += t;
  34193. for (var n = 0; n < r.length + 64; n++) e.x ^= 0 | r.charCodeAt(n), e.next();
  34194. }(t),
  34195. i = e && e.state,
  34196. o = function () {
  34197. return (r.next() >>> 0) / 4294967296;
  34198. };
  34199. return o.double = function () {
  34200. do {
  34201. var t = ((r.next() >>> 11) + (r.next() >>> 0) / 4294967296) / (1 << 21);
  34202. } while (0 === t);
  34203. return t;
  34204. }, o.int32 = r.next, o.quick = o, i && ("object" == typeof i && n(i, r), o.state = function () {
  34205. return n(r, {});
  34206. }), o;
  34207. }
  34208. e && e.exports ? e.exports = i : r && r.amd ? r(function () {
  34209. return i;
  34210. }) : this.xor128 = i;
  34211. }(0, t, !1);
  34212. }),
  34213. xorwow = createCommonjsModule(function (t) {
  34214. !function (t, e, r) {
  34215. function n(t, e) {
  34216. return e.x = t.x, e.y = t.y, e.z = t.z, e.w = t.w, e.v = t.v, e.d = t.d, e;
  34217. }
  34218. function i(t, e) {
  34219. var r = new function (t) {
  34220. var e = this,
  34221. r = "";
  34222. e.next = function () {
  34223. var t = e.x ^ e.x >>> 2;
  34224. return e.x = e.y, e.y = e.z, e.z = e.w, e.w = e.v, (e.d = e.d + 362437 | 0) + (e.v = e.v ^ e.v << 4 ^ t ^ t << 1) | 0;
  34225. }, e.x = 0, e.y = 0, e.z = 0, e.w = 0, e.v = 0, t === (0 | t) ? e.x = t : r += t;
  34226. for (var n = 0; n < r.length + 64; n++) e.x ^= 0 | r.charCodeAt(n), n == r.length && (e.d = e.x << 10 ^ e.x >>> 4), e.next();
  34227. }(t),
  34228. i = e && e.state,
  34229. o = function () {
  34230. return (r.next() >>> 0) / 4294967296;
  34231. };
  34232. return o.double = function () {
  34233. do {
  34234. var t = ((r.next() >>> 11) + (r.next() >>> 0) / 4294967296) / (1 << 21);
  34235. } while (0 === t);
  34236. return t;
  34237. }, o.int32 = r.next, o.quick = o, i && ("object" == typeof i && n(i, r), o.state = function () {
  34238. return n(r, {});
  34239. }), o;
  34240. }
  34241. e && e.exports ? e.exports = i : r && r.amd ? r(function () {
  34242. return i;
  34243. }) : this.xorwow = i;
  34244. }(0, t, !1);
  34245. }),
  34246. xorshift7 = createCommonjsModule(function (t) {
  34247. !function (t, e, r) {
  34248. function n(t, e) {
  34249. return e.x = t.x.slice(), e.i = t.i, e;
  34250. }
  34251. function i(t, e) {
  34252. null == t && (t = +new Date());
  34253. var r = new function (t) {
  34254. var e = this;
  34255. e.next = function () {
  34256. var t,
  34257. r,
  34258. n = e.x,
  34259. i = e.i;
  34260. return t = n[i], r = (t ^= t >>> 7) ^ t << 24, r ^= (t = n[i + 1 & 7]) ^ t >>> 10, r ^= (t = n[i + 3 & 7]) ^ t >>> 3, r ^= (t = n[i + 4 & 7]) ^ t << 7, t = n[i + 7 & 7], r ^= (t ^= t << 13) ^ t << 9, n[i] = r, e.i = i + 1 & 7, r;
  34261. }, function (t, e) {
  34262. var r,
  34263. n = [];
  34264. if (e === (0 | e)) n[0] = e; else for (e = "" + e, r = 0; r < e.length; ++r) n[7 & r] = n[7 & r] << 15 ^ e.charCodeAt(r) + n[r + 1 & 7] << 13;
  34265. for (; n.length < 8;) n.push(0);
  34266. for (r = 0; r < 8 && 0 === n[r]; ++r);
  34267. for (8 == r ? n[7] = -1 : n[r], t.x = n, t.i = 0, r = 256; r > 0; --r) t.next();
  34268. }(e, t);
  34269. }(t),
  34270. i = e && e.state,
  34271. o = function () {
  34272. return (r.next() >>> 0) / 4294967296;
  34273. };
  34274. return o.double = function () {
  34275. do {
  34276. var t = ((r.next() >>> 11) + (r.next() >>> 0) / 4294967296) / (1 << 21);
  34277. } while (0 === t);
  34278. return t;
  34279. }, o.int32 = r.next, o.quick = o, i && (i.x && n(i, r), o.state = function () {
  34280. return n(r, {});
  34281. }), o;
  34282. }
  34283. e && e.exports ? e.exports = i : r && r.amd ? r(function () {
  34284. return i;
  34285. }) : this.xorshift7 = i;
  34286. }(0, t, !1);
  34287. }),
  34288. xor4096 = createCommonjsModule(function (t) {
  34289. !function (t, e, r) {
  34290. function n(t, e) {
  34291. return e.i = t.i, e.w = t.w, e.X = t.X.slice(), e;
  34292. }
  34293. function i(t, e) {
  34294. null == t && (t = +new Date());
  34295. var r = new function (t) {
  34296. var e = this;
  34297. e.next = function () {
  34298. var t,
  34299. r,
  34300. n = e.w,
  34301. i = e.X,
  34302. o = e.i;
  34303. return e.w = n = n + 1640531527 | 0, r = i[o + 34 & 127], t = i[o = o + 1 & 127], r ^= r << 13, t ^= t << 17, r ^= r >>> 15, t ^= t >>> 12, r = i[o] = r ^ t, e.i = o, r + (n ^ n >>> 16) | 0;
  34304. }, function (t, e) {
  34305. var r,
  34306. n,
  34307. i,
  34308. o,
  34309. a,
  34310. s = [],
  34311. u = 128;
  34312. for (e === (0 | e) ? (n = e, e = null) : (e += "\0", n = 0, u = Math.max(u, e.length)), i = 0, o = -32; o < u; ++o) e && (n ^= e.charCodeAt((o + 32) % e.length)), 0 === o && (a = n), n ^= n << 10, n ^= n >>> 15, n ^= n << 4, n ^= n >>> 13, o >= 0 && (a = a + 1640531527 | 0, i = 0 == (r = s[127 & o] ^= n + a) ? i + 1 : 0);
  34313. for (i >= 128 && (s[127 & (e && e.length || 0)] = -1), i = 127, o = 512; o > 0; --o) n = s[i + 34 & 127], r = s[i = i + 1 & 127], n ^= n << 13, r ^= r << 17, n ^= n >>> 15, r ^= r >>> 12, s[i] = n ^ r;
  34314. t.w = a, t.X = s, t.i = i;
  34315. }(e, t);
  34316. }(t),
  34317. i = e && e.state,
  34318. o = function () {
  34319. return (r.next() >>> 0) / 4294967296;
  34320. };
  34321. return o.double = function () {
  34322. do {
  34323. var t = ((r.next() >>> 11) + (r.next() >>> 0) / 4294967296) / (1 << 21);
  34324. } while (0 === t);
  34325. return t;
  34326. }, o.int32 = r.next, o.quick = o, i && (i.X && n(i, r), o.state = function () {
  34327. return n(r, {});
  34328. }), o;
  34329. }
  34330. e && e.exports ? e.exports = i : r && r.amd ? r(function () {
  34331. return i;
  34332. }) : this.xor4096 = i;
  34333. }(0, t, !1);
  34334. }),
  34335. tychei = createCommonjsModule(function (t) {
  34336. !function (t, e, r) {
  34337. function n(t, e) {
  34338. return e.a = t.a, e.b = t.b, e.c = t.c, e.d = t.d, e;
  34339. }
  34340. function i(t, e) {
  34341. var r = new function (t) {
  34342. var e = this,
  34343. r = "";
  34344. e.next = function () {
  34345. var t = e.b,
  34346. r = e.c,
  34347. n = e.d,
  34348. i = e.a;
  34349. return t = t << 25 ^ t >>> 7 ^ r, r = r - n | 0, n = n << 24 ^ n >>> 8 ^ i, i = i - t | 0, e.b = t = t << 20 ^ t >>> 12 ^ r, e.c = r = r - n | 0, e.d = n << 16 ^ r >>> 16 ^ i, e.a = i - t | 0;
  34350. }, e.a = 0, e.b = 0, e.c = -1640531527, e.d = 1367130551, t === Math.floor(t) ? (e.a = t / 4294967296 | 0, e.b = 0 | t) : r += t;
  34351. for (var n = 0; n < r.length + 20; n++) e.b ^= 0 | r.charCodeAt(n), e.next();
  34352. }(t),
  34353. i = e && e.state,
  34354. o = function () {
  34355. return (r.next() >>> 0) / 4294967296;
  34356. };
  34357. return o.double = function () {
  34358. do {
  34359. var t = ((r.next() >>> 11) + (r.next() >>> 0) / 4294967296) / (1 << 21);
  34360. } while (0 === t);
  34361. return t;
  34362. }, o.int32 = r.next, o.quick = o, i && ("object" == typeof i && n(i, r), o.state = function () {
  34363. return n(r, {});
  34364. }), o;
  34365. }
  34366. e && e.exports ? e.exports = i : r && r.amd ? r(function () {
  34367. return i;
  34368. }) : this.tychei = i;
  34369. }(0, t, !1);
  34370. }),
  34371. seedrandom = createCommonjsModule(function (t) {
  34372. !function (e, r) {
  34373. var n,
  34374. i = this,
  34375. o = 256,
  34376. a = 6,
  34377. s = "random",
  34378. u = r.pow(o, a),
  34379. c = r.pow(2, 52),
  34380. l = 2 * c,
  34381. h = o - 1;
  34382. function f(t, f, v) {
  34383. var _ = [],
  34384. w = p(function t(e, r) {
  34385. var n,
  34386. i = [],
  34387. o = typeof e;
  34388. if (r && "object" == o) for (n in e) try {
  34389. i.push(t(e[n], r - 1));
  34390. } catch (t) { }
  34391. return i.length ? i : "string" == o ? e : e + "\0";
  34392. }((f = 1 == f ? {
  34393. entropy: !0
  34394. } : f || {}).entropy ? [t, m(e)] : null == t ? function () {
  34395. try {
  34396. var t;
  34397. return n && (t = n.randomBytes) ? t = t(o) : (t = new Uint8Array(o), (i.crypto || i.msCrypto).getRandomValues(t)), m(t);
  34398. } catch (t) {
  34399. var r = i.navigator,
  34400. a = r && r.plugins;
  34401. return [+new Date(), i, a, i.screen, m(e)];
  34402. }
  34403. }() : t, 3), _),
  34404. y = new function (t) {
  34405. var e,
  34406. r = t.length,
  34407. n = this,
  34408. i = 0,
  34409. a = n.i = n.j = 0,
  34410. s = n.S = [];
  34411. r || (t = [r++]);
  34412. for (; i < o;) s[i] = i++;
  34413. for (i = 0; i < o; i++) s[i] = s[a = h & a + t[i % r] + (e = s[i])], s[a] = e;
  34414. (n.g = function (t) {
  34415. for (var e, r = 0, i = n.i, a = n.j, s = n.S; t--;) e = s[i = h & i + 1], r = r * o + s[h & (s[i] = s[a = h & a + e]) + (s[a] = e)];
  34416. return n.i = i, n.j = a, r;
  34417. })(o);
  34418. }(_),
  34419. g = function () {
  34420. for (var t = y.g(a), e = u, r = 0; t < c;) t = (t + r) * o, e *= o, r = y.g(1);
  34421. for (; t >= l;) t /= 2, e /= 2, r >>>= 1;
  34422. return (t + r) / e;
  34423. };
  34424. return g.int32 = function () {
  34425. return 0 | y.g(4);
  34426. }, g.quick = function () {
  34427. return y.g(4) / 4294967296;
  34428. }, g.double = g, p(m(y.S), e), (f.pass || v || function (t, e, n, i) {
  34429. return i && (i.S && d(i, y), t.state = function () {
  34430. return d(y, {});
  34431. }), n ? (r[s] = t, e) : t;
  34432. })(g, w, "global" in f ? f.global : this == r, f.state);
  34433. }
  34434. function d(t, e) {
  34435. return e.i = t.i, e.j = t.j, e.S = t.S.slice(), e;
  34436. }
  34437. function p(t, e) {
  34438. for (var r, n = t + "", i = 0; i < n.length;) e[h & i] = h & (r ^= 19 * e[h & i]) + n.charCodeAt(i++);
  34439. return m(e);
  34440. }
  34441. function m(t) {
  34442. return String.fromCharCode.apply(0, t);
  34443. }
  34444. if (r["seed" + s] = f, p(r.random(), e), t.exports) {
  34445. t.exports = f;
  34446. try {
  34447. n = require("crypto");
  34448. } catch (t) { }
  34449. } else 0;
  34450. }([], Math);
  34451. });
  34452. seedrandom.alea = alea, seedrandom.xor128 = xor128, seedrandom.xorwow = xorwow, seedrandom.xorshift7 = xorshift7, seedrandom.xor4096 = xor4096, seedrandom.tychei = tychei;
  34453. var seedrandom$1 = seedrandom,
  34454. seedrandom_1 = seedrandom$1.alea;
  34455. function deepMap(t, e) {
  34456. return deepMapInternal(t, e);
  34457. }
  34458. function deepMapInternal(t, e, r, n) {
  34459. if (void 0 === r && (r = new Map()), void 0 === n && (n = new Set()), null == t) return null;
  34460. if (n.has(t)) throw new Error("Circular references are not supported.");
  34461. if (r.has(t)) return r.get(t);
  34462. var i = e(t);
  34463. if (i.recurse && null !== i.value) throw new Error("A deep map function may not return both a value and recurse=true.");
  34464. if (i.recurse) {
  34465. if (isIterable(t)) {
  34466. var o = Array.isArray(t) ? [] : {};
  34467. for (var a in n.add(t), t) {
  34468. var s = deepMapInternal(t[a], e, r, n);
  34469. o[a] = s;
  34470. }
  34471. return n.delete(t), o;
  34472. }
  34473. throw new Error("Can't recurse into non-iterable type: " + t);
  34474. }
  34475. return r.set(t, i.value), i.value;
  34476. }
  34477. function deepZip(t, e) {
  34478. return void 0 === e && (e = zipToList), deepZipInternal(t, e);
  34479. }
  34480. function deepZipInternal(t, e, r) {
  34481. void 0 === r && (r = new Set());
  34482. var n = t[0];
  34483. if (r.has(n)) throw new Error("Circular references are not supported.");
  34484. var i = e(t);
  34485. if (i.recurse && null !== i.value) throw new Error("A deep zip function may not return both a value and recurse=true.");
  34486. if (i.recurse) {
  34487. if (isIterable(n)) {
  34488. var o = Array.isArray(n) ? [] : {};
  34489. r.add(n);
  34490. var a = function (n) {
  34491. var i = deepZipInternal(t.map(function (t) {
  34492. return t[n];
  34493. }), e, r);
  34494. o[n] = i;
  34495. };
  34496. for (var s in n) a(s);
  34497. return r.delete(n), o;
  34498. }
  34499. throw new Error("Can't recurse into non-iterable type: " + n);
  34500. }
  34501. return i.value;
  34502. }
  34503. function zipToList(t) {
  34504. return null === t ? null : isIterable(t[0]) ? {
  34505. value: null,
  34506. recurse: !0
  34507. } : {
  34508. value: t,
  34509. recurse: !1
  34510. };
  34511. }
  34512. function deepMapAndAwaitAll(t, e) {
  34513. return __awaiter(this, void 0, void 0, function () {
  34514. var r, n, i, o, a, s;
  34515. return __generator(this, function (u) {
  34516. switch (u.label) {
  34517. case 0:
  34518. r = new Map(), deepMapInternal(t, e, r), n = 0, i = Array.from(r.keys()), u.label = 1;
  34519. case 1:
  34520. return n < i.length ? (o = i[n], (a = r.get(o)) instanceof Promise ? [4, a] : [3, 3]) : [3, 4];
  34521. case 2:
  34522. s = u.sent(), r.set(o, s), u.label = 3;
  34523. case 3:
  34524. return n++, [3, 1];
  34525. case 4:
  34526. return [2, deepMapInternal(t, e, r)];
  34527. }
  34528. });
  34529. });
  34530. }
  34531. function isIterable(t) {
  34532. return null != t && !ArrayBuffer.isView(t) && (Array.isArray(t) || "object" == typeof t && !(t instanceof _tfjsCore.Tensor));
  34533. }
  34534. function canTensorify(t) {
  34535. return null == t || isPrimitive(t) || Array.isArray(t) || "object" == typeof t && t instanceof _tfjsCore.Tensor || _tfjsCore.util.isTypedArray(t);
  34536. }
  34537. function isPrimitive(t) {
  34538. return null === t || "object" != typeof t && "function" != typeof t;
  34539. }
  34540. function deepClone(t) {
  34541. return deepMap(t, cloneIfTensor);
  34542. }
  34543. function cloneIfTensor(t) {
  34544. return t instanceof _tfjsCore.Tensor ? {
  34545. value: t.clone(),
  34546. recurse: !1
  34547. } : isIterable(t) ? {
  34548. value: null,
  34549. recurse: !0
  34550. } : {
  34551. value: t,
  34552. recurse: !1
  34553. };
  34554. }
  34555. var RingBuffer = function () {
  34556. function t(t) {
  34557. if (this.capacity = t, this.begin = 0, this.end = 0, null == t) throw new RangeError("Can't create a ring buffer of unknown capacity.");
  34558. if (t < 1) throw new RangeError("Can't create ring buffer of capacity < 1.");
  34559. this.data = new Array(t), this.doubledCapacity = 2 * t;
  34560. }
  34561. return t.prototype.wrap = function (t) {
  34562. for (; t < 0;) t += this.doubledCapacity;
  34563. return t % this.doubledCapacity;
  34564. }, t.prototype.get = function (t) {
  34565. if (t < 0) throw new RangeError("Can't get item at a negative index.");
  34566. return this.data[t % this.capacity];
  34567. }, t.prototype.set = function (t, e) {
  34568. if (t < 0) throw new RangeError("Can't set item at a negative index.");
  34569. this.data[t % this.capacity] = e;
  34570. }, t.prototype.length = function () {
  34571. var t = this.end - this.begin;
  34572. return t < 0 && (t = this.doubledCapacity + t), t;
  34573. }, t.prototype.isFull = function () {
  34574. return this.length() === this.capacity;
  34575. }, t.prototype.isEmpty = function () {
  34576. return 0 === this.length();
  34577. }, t.prototype.push = function (t) {
  34578. if (this.isFull()) throw new RangeError("Ring buffer is full.");
  34579. this.set(this.end, t), this.end = this.wrap(this.end + 1);
  34580. }, t.prototype.pushAll = function (t) {
  34581. for (var e = 0, r = t; e < r.length; e++) {
  34582. var n = r[e];
  34583. this.push(n);
  34584. }
  34585. }, t.prototype.pop = function () {
  34586. if (this.isEmpty()) throw new RangeError("Ring buffer is empty.");
  34587. this.end = this.wrap(this.end - 1);
  34588. var t = this.get(this.end);
  34589. return this.set(this.end, void 0), t;
  34590. }, t.prototype.unshift = function (t) {
  34591. if (this.isFull()) throw new RangeError("Ring buffer is full.");
  34592. this.begin = this.wrap(this.begin - 1), this.set(this.begin, t);
  34593. }, t.prototype.shift = function () {
  34594. if (this.isEmpty()) throw new RangeError("Ring buffer is empty.");
  34595. var t = this.get(this.begin);
  34596. return this.set(this.begin, void 0), this.begin = this.wrap(this.begin + 1), t;
  34597. }, t.prototype.shuffleExcise = function (t) {
  34598. if (this.isEmpty()) throw new RangeError("Ring buffer is empty.");
  34599. var e = this.wrap(this.begin + t),
  34600. r = this.get(e);
  34601. return this.set(e, this.pop()), r;
  34602. }, t;
  34603. }(),
  34604. GrowingRingBuffer = function (t) {
  34605. function e() {
  34606. return t.call(this, e.INITIAL_CAPACITY) || this;
  34607. }
  34608. return __extends(e, t), e.prototype.isFull = function () {
  34609. return !1;
  34610. }, e.prototype.push = function (e) {
  34611. t.prototype.isFull.call(this) && this.expand(), t.prototype.push.call(this, e);
  34612. }, e.prototype.unshift = function (e) {
  34613. t.prototype.isFull.call(this) && this.expand(), t.prototype.unshift.call(this, e);
  34614. }, e.prototype.expand = function () {
  34615. for (var t = 2 * this.capacity, e = new Array(t), r = this.length(), n = 0; n < r; n++) e[n] = this.get(this.wrap(this.begin + n));
  34616. this.data = e, this.capacity = t, this.doubledCapacity = 2 * this.capacity, this.begin = 0, this.end = r;
  34617. }, e.INITIAL_CAPACITY = 32, e;
  34618. }(RingBuffer);
  34619. function iteratorFromItems(t) {
  34620. return new ArrayIterator(t);
  34621. }
  34622. function iteratorFromFunction(t) {
  34623. return new FunctionCallIterator(t);
  34624. }
  34625. function iteratorFromConcatenated(t, e) {
  34626. return new ChainedIterator(t, e);
  34627. }
  34628. function iteratorFromZipped(t, e) {
  34629. return void 0 === e && (e = ZipMismatchMode.FAIL), new ZipIterator(t, e);
  34630. }
  34631. var ZipMismatchMode,
  34632. LazyIterator = function () {
  34633. function t() { }
  34634. return t.prototype.toArray = function () {
  34635. return __awaiter(this, void 0, void 0, function () {
  34636. var t, e;
  34637. return __generator(this, function (r) {
  34638. switch (r.label) {
  34639. case 0:
  34640. return t = [], [4, this.next()];
  34641. case 1:
  34642. e = r.sent(), r.label = 2;
  34643. case 2:
  34644. return e.done ? [3, 4] : (t.push(e.value), [4, this.next()]);
  34645. case 3:
  34646. return e = r.sent(), [3, 2];
  34647. case 4:
  34648. return [2, t];
  34649. }
  34650. });
  34651. });
  34652. }, t.prototype.toArrayForTest = function () {
  34653. return __awaiter(this, void 0, void 0, function () {
  34654. var t, e, r;
  34655. return __generator(this, function (n) {
  34656. switch (n.label) {
  34657. case 0:
  34658. return t = this.prefetch(100), e = [], [4, t.next()];
  34659. case 1:
  34660. r = n.sent(), n.label = 2;
  34661. case 2:
  34662. return r.done ? [3, 4] : (e.push(r.value), [4, t.next()]);
  34663. case 3:
  34664. return r = n.sent(), [3, 2];
  34665. case 4:
  34666. return [2, e];
  34667. }
  34668. });
  34669. });
  34670. }, t.prototype.resolveFully = function () {
  34671. return __awaiter(this, void 0, void 0, function () {
  34672. var t;
  34673. return __generator(this, function (e) {
  34674. switch (e.label) {
  34675. case 0:
  34676. return [4, this.next()];
  34677. case 1:
  34678. t = e.sent(), e.label = 2;
  34679. case 2:
  34680. return t.done ? [3, 4] : [4, this.next()];
  34681. case 3:
  34682. return t = e.sent(), [3, 2];
  34683. case 4:
  34684. return [2];
  34685. }
  34686. });
  34687. });
  34688. }, t.prototype.resolveWhile = function (t) {
  34689. return __awaiter(this, void 0, void 0, function () {
  34690. var e, r;
  34691. return __generator(this, function (n) {
  34692. switch (n.label) {
  34693. case 0:
  34694. return [4, this.next()];
  34695. case 1:
  34696. e = n.sent(), r = t(e.value), n.label = 2;
  34697. case 2:
  34698. return e.done || !r ? [3, 4] : [4, this.next()];
  34699. case 3:
  34700. return e = n.sent(), r = t(e.value), [3, 2];
  34701. case 4:
  34702. return [2];
  34703. }
  34704. });
  34705. });
  34706. }, t.prototype.handleErrors = function (t) {
  34707. return new ErrorHandlingLazyIterator(this, t);
  34708. }, t.prototype.filter = function (t) {
  34709. return new FilterIterator(this, t);
  34710. }, t.prototype.map = function (t) {
  34711. return new MapIterator(this, t);
  34712. }, t.prototype.mapAsync = function (t) {
  34713. return new AsyncMapIterator(this, t);
  34714. }, t.prototype.serialMapAsync = function (t) {
  34715. return new AsyncMapIterator(this, t).serial();
  34716. }, t.prototype.flatmap = function (t) {
  34717. return new FlatmapIterator(this, t);
  34718. }, t.prototype.forEachAsync = function (t) {
  34719. return __awaiter(this, void 0, void 0, function () {
  34720. return __generator(this, function (e) {
  34721. return [2, this.map(t).resolveFully()];
  34722. });
  34723. });
  34724. }, t.prototype.serialForEach = function (t) {
  34725. return __awaiter(this, void 0, void 0, function () {
  34726. return __generator(this, function (e) {
  34727. return [2, this.serialMapAsync(t).resolveWhile(function (t) {
  34728. return !0 === t;
  34729. })];
  34730. });
  34731. });
  34732. }, t.prototype.rowMajorBatch = function (t, e) {
  34733. return void 0 === e && (e = !0), new RowMajorBatchIterator(this, t, e);
  34734. }, t.prototype.columnMajorBatch = function (t, e, r) {
  34735. return void 0 === e && (e = !0), void 0 === r && (r = zipToList), this.rowMajorBatch(t, e).map(function (t) {
  34736. return deepZip(t, r);
  34737. });
  34738. }, t.prototype.concatenate = function (t, e) {
  34739. return new ChainedIterator(iteratorFromItems([this, t]), e);
  34740. }, t.prototype.take = function (t) {
  34741. return t < 0 || null == t ? this : new TakeIterator(this, t);
  34742. }, t.prototype.skip = function (t) {
  34743. return t < 0 || null == t ? this : new SkipIterator(this, t);
  34744. }, t.prototype.prefetch = function (t) {
  34745. return new PrefetchIterator(this, t);
  34746. }, t.prototype.shuffle = function (t, e) {
  34747. return new ShuffleIterator(this, t, e);
  34748. }, t.prototype.serial = function () {
  34749. return new SerialIterator(this);
  34750. }, t;
  34751. }(),
  34752. ArrayIterator = function (t) {
  34753. function e(e) {
  34754. var r = t.call(this) || this;
  34755. return r.items = e, r.trav = 0, r;
  34756. }
  34757. return __extends(e, t), e.prototype.summary = function () {
  34758. return "Array of " + this.items.length + " items";
  34759. }, e.prototype.next = function () {
  34760. return __awaiter(this, void 0, void 0, function () {
  34761. var t;
  34762. return __generator(this, function (e) {
  34763. return this.trav >= this.items.length ? [2, {
  34764. value: null,
  34765. done: !0
  34766. }] : (t = this.items[this.trav], this.trav++, [2, {
  34767. value: deepClone(t),
  34768. done: !1
  34769. }]);
  34770. });
  34771. });
  34772. }, e;
  34773. }(LazyIterator),
  34774. FunctionCallIterator = function (t) {
  34775. function e(e) {
  34776. var r = t.call(this) || this;
  34777. return r.nextFn = e, r;
  34778. }
  34779. return __extends(e, t), e.prototype.summary = function () {
  34780. return "Function call";
  34781. }, e.prototype.next = function () {
  34782. return __awaiter(this, void 0, void 0, function () {
  34783. return __generator(this, function (t) {
  34784. try {
  34785. return [2, this.nextFn()];
  34786. } catch (t) {
  34787. throw t.message = "Error thrown while iterating through a dataset: " + t.message, t;
  34788. }
  34789. return [2];
  34790. });
  34791. });
  34792. }, e;
  34793. }(LazyIterator),
  34794. SerialIterator = function (t) {
  34795. function e(e) {
  34796. var r = t.call(this) || this;
  34797. return r.upstream = e, r.lastRead = Promise.resolve({
  34798. value: null,
  34799. done: !1
  34800. }), r;
  34801. }
  34802. return __extends(e, t), e.prototype.summary = function () {
  34803. return this.upstream.summary() + " -> Serial";
  34804. }, e.prototype.next = function () {
  34805. return __awaiter(this, void 0, void 0, function () {
  34806. var t = this;
  34807. return __generator(this, function (e) {
  34808. return this.lastRead = this.lastRead.then(function () {
  34809. return t.serialNext();
  34810. }), [2, this.lastRead];
  34811. });
  34812. });
  34813. }, e.prototype.serialNext = function () {
  34814. return __awaiter(this, void 0, void 0, function () {
  34815. return __generator(this, function (t) {
  34816. return [2, this.upstream.next()];
  34817. });
  34818. });
  34819. }, e;
  34820. }(LazyIterator),
  34821. SkipIterator = function (t) {
  34822. function e(e, r) {
  34823. var n = t.call(this) || this;
  34824. return n.upstream = e, n.maxCount = r, n.count = 0, n.lastRead = Promise.resolve({
  34825. value: null,
  34826. done: !1
  34827. }), n;
  34828. }
  34829. return __extends(e, t), e.prototype.summary = function () {
  34830. return this.upstream.summary() + " -> Skip";
  34831. }, e.prototype.next = function () {
  34832. return __awaiter(this, void 0, void 0, function () {
  34833. var t = this;
  34834. return __generator(this, function (e) {
  34835. return this.lastRead = this.lastRead.then(function () {
  34836. return t.serialNext();
  34837. }), [2, this.lastRead];
  34838. });
  34839. });
  34840. }, e.prototype.serialNext = function () {
  34841. return __awaiter(this, void 0, void 0, function () {
  34842. var t;
  34843. return __generator(this, function (e) {
  34844. switch (e.label) {
  34845. case 0:
  34846. return this.count++ < this.maxCount ? [4, this.upstream.next()] : [3, 2];
  34847. case 1:
  34848. return (t = e.sent()).done ? [2, t] : ((0, _tfjsCore.dispose)(t.value), [3, 0]);
  34849. case 2:
  34850. return [2, this.upstream.next()];
  34851. }
  34852. });
  34853. });
  34854. }, e;
  34855. }(LazyIterator),
  34856. TakeIterator = function (t) {
  34857. function e(e, r) {
  34858. var n = t.call(this) || this;
  34859. return n.upstream = e, n.maxCount = r, n.count = 0, n;
  34860. }
  34861. return __extends(e, t), e.prototype.summary = function () {
  34862. return this.upstream.summary() + " -> Take";
  34863. }, e.prototype.next = function () {
  34864. return __awaiter(this, void 0, void 0, function () {
  34865. return __generator(this, function (t) {
  34866. return this.count++ >= this.maxCount ? [2, {
  34867. value: null,
  34868. done: !0
  34869. }] : [2, this.upstream.next()];
  34870. });
  34871. });
  34872. }, e;
  34873. }(LazyIterator),
  34874. RowMajorBatchIterator = function (t) {
  34875. function e(e, r, n) {
  34876. void 0 === n && (n = !0);
  34877. var i = t.call(this) || this;
  34878. return i.upstream = e, i.batchSize = r, i.enableSmallLastBatch = n, i.lastRead = Promise.resolve({
  34879. value: null,
  34880. done: !1
  34881. }), i;
  34882. }
  34883. return __extends(e, t), e.prototype.summary = function () {
  34884. return this.upstream.summary() + " -> RowMajorBatch";
  34885. }, e.prototype.next = function () {
  34886. return __awaiter(this, void 0, void 0, function () {
  34887. var t = this;
  34888. return __generator(this, function (e) {
  34889. return this.lastRead = this.lastRead.then(function () {
  34890. return t.serialNext();
  34891. }), [2, this.lastRead];
  34892. });
  34893. });
  34894. }, e.prototype.serialNext = function () {
  34895. return __awaiter(this, void 0, void 0, function () {
  34896. var t, e;
  34897. return __generator(this, function (r) {
  34898. switch (r.label) {
  34899. case 0:
  34900. t = [], r.label = 1;
  34901. case 1:
  34902. return t.length < this.batchSize ? [4, this.upstream.next()] : [3, 3];
  34903. case 2:
  34904. return (e = r.sent()).done ? this.enableSmallLastBatch && t.length > 0 ? [2, {
  34905. value: t,
  34906. done: !1
  34907. }] : [2, {
  34908. value: null,
  34909. done: !0
  34910. }] : (t.push(e.value), [3, 1]);
  34911. case 3:
  34912. return [2, {
  34913. value: t,
  34914. done: !1
  34915. }];
  34916. }
  34917. });
  34918. });
  34919. }, e;
  34920. }(LazyIterator),
  34921. FilterIterator = function (t) {
  34922. function e(e, r) {
  34923. var n = t.call(this) || this;
  34924. return n.upstream = e, n.predicate = r, n.lastRead = Promise.resolve({
  34925. value: null,
  34926. done: !1
  34927. }), n;
  34928. }
  34929. return __extends(e, t), e.prototype.summary = function () {
  34930. return this.upstream.summary() + " -> Filter";
  34931. }, e.prototype.next = function () {
  34932. return __awaiter(this, void 0, void 0, function () {
  34933. var t = this;
  34934. return __generator(this, function (e) {
  34935. return this.lastRead = this.lastRead.then(function () {
  34936. return t.serialNext();
  34937. }), [2, this.lastRead];
  34938. });
  34939. });
  34940. }, e.prototype.serialNext = function () {
  34941. return __awaiter(this, void 0, void 0, function () {
  34942. var t;
  34943. return __generator(this, function (e) {
  34944. switch (e.label) {
  34945. case 0:
  34946. return [4, this.upstream.next()];
  34947. case 1:
  34948. return (t = e.sent()).done || this.predicate(t.value) ? [2, t] : ((0, _tfjsCore.dispose)(t.value), [3, 0]);
  34949. case 2:
  34950. return [2];
  34951. }
  34952. });
  34953. });
  34954. }, e;
  34955. }(LazyIterator),
  34956. MapIterator = function (t) {
  34957. function e(e, r) {
  34958. var n = t.call(this) || this;
  34959. return n.upstream = e, n.transform = r, n;
  34960. }
  34961. return __extends(e, t), e.prototype.summary = function () {
  34962. return this.upstream.summary() + " -> Map";
  34963. }, e.prototype.next = function () {
  34964. return __awaiter(this, void 0, void 0, function () {
  34965. var t, e, r, n, i, o, a;
  34966. return __generator(this, function (s) {
  34967. switch (s.label) {
  34968. case 0:
  34969. return [4, this.upstream.next()];
  34970. case 1:
  34971. if ((t = s.sent()).done) return [2, {
  34972. value: null,
  34973. done: !0
  34974. }];
  34975. for (e = _tfjsCore.tensor_util.getTensorsInContainer(t.value), r = this.transform(t.value), n = _tfjsCore.tensor_util.getTensorsInContainer(r), i = 0, o = e; i < o.length; i++) a = o[i], _tfjsCore.tensor_util.isTensorInList(a, n) || a.dispose();
  34976. return [2, {
  34977. value: r,
  34978. done: !1
  34979. }];
  34980. }
  34981. });
  34982. });
  34983. }, e;
  34984. }(LazyIterator),
  34985. ErrorHandlingLazyIterator = function (t) {
  34986. function e(e, r) {
  34987. var n = t.call(this) || this;
  34988. return n.upstream = e, n.handler = r, n.count = 0, n.lastRead = Promise.resolve({
  34989. value: null,
  34990. done: !1
  34991. }), n;
  34992. }
  34993. return __extends(e, t), e.prototype.summary = function () {
  34994. return this.upstream.summary() + " -> handleErrors";
  34995. }, e.prototype.next = function () {
  34996. return __awaiter(this, void 0, void 0, function () {
  34997. var t = this;
  34998. return __generator(this, function (e) {
  34999. return this.lastRead = this.lastRead.then(function () {
  35000. return t.serialNext();
  35001. }), [2, this.lastRead];
  35002. });
  35003. });
  35004. }, e.prototype.serialNext = function () {
  35005. return __awaiter(this, void 0, void 0, function () {
  35006. var t;
  35007. return __generator(this, function (e) {
  35008. switch (e.label) {
  35009. case 0:
  35010. e.label = 1;
  35011. case 1:
  35012. return e.trys.push([1, 3, , 4]), [4, this.upstream.next()];
  35013. case 2:
  35014. return [2, e.sent()];
  35015. case 3:
  35016. return t = e.sent(), this.handler(t) ? [3, 4] : [2, {
  35017. value: null,
  35018. done: !0
  35019. }];
  35020. case 4:
  35021. return [3, 0];
  35022. case 5:
  35023. return [2];
  35024. }
  35025. });
  35026. });
  35027. }, e;
  35028. }(LazyIterator),
  35029. AsyncMapIterator = function (t) {
  35030. function e(e, r) {
  35031. var n = t.call(this) || this;
  35032. return n.upstream = e, n.transform = r, n;
  35033. }
  35034. return __extends(e, t), e.prototype.summary = function () {
  35035. return this.upstream.summary() + " -> AsyncMap";
  35036. }, e.prototype.next = function () {
  35037. return __awaiter(this, void 0, void 0, function () {
  35038. var t, e, r, n, i, o, a;
  35039. return __generator(this, function (s) {
  35040. switch (s.label) {
  35041. case 0:
  35042. return [4, this.upstream.next()];
  35043. case 1:
  35044. return (t = s.sent()).done ? [2, {
  35045. value: null,
  35046. done: !0
  35047. }] : (e = _tfjsCore.tensor_util.getTensorsInContainer(t.value), [4, this.transform(t.value)]);
  35048. case 2:
  35049. for (r = s.sent(), n = _tfjsCore.tensor_util.getTensorsInContainer(r), i = 0, o = e; i < o.length; i++) a = o[i], _tfjsCore.tensor_util.isTensorInList(a, n) || a.dispose();
  35050. return [2, {
  35051. value: r,
  35052. done: !1
  35053. }];
  35054. }
  35055. });
  35056. });
  35057. }, e;
  35058. }(LazyIterator),
  35059. OneToManyIterator = function (t) {
  35060. function e() {
  35061. var e = t.call(this) || this;
  35062. return e.outputQueue = new GrowingRingBuffer(), e.lastRead = Promise.resolve({
  35063. value: null,
  35064. done: !1
  35065. }), e;
  35066. }
  35067. return __extends(e, t), e.prototype.next = function () {
  35068. return __awaiter(this, void 0, void 0, function () {
  35069. var t = this;
  35070. return __generator(this, function (e) {
  35071. return this.lastRead = this.lastRead.then(function () {
  35072. return t.serialNext();
  35073. }), [2, this.lastRead];
  35074. });
  35075. });
  35076. }, e.prototype.serialNext = function () {
  35077. return __awaiter(this, void 0, void 0, function () {
  35078. return __generator(this, function (t) {
  35079. switch (t.label) {
  35080. case 0:
  35081. return 0 !== this.outputQueue.length() ? [3, 2] : [4, this.pump()];
  35082. case 1:
  35083. return t.sent() ? [3, 0] : [2, {
  35084. value: null,
  35085. done: !0
  35086. }];
  35087. case 2:
  35088. return [2, {
  35089. value: this.outputQueue.shift(),
  35090. done: !1
  35091. }];
  35092. }
  35093. });
  35094. });
  35095. }, e;
  35096. }(LazyIterator),
  35097. FlatmapIterator = function (t) {
  35098. function e(e, r) {
  35099. var n = t.call(this) || this;
  35100. return n.upstream = e, n.transform = r, n;
  35101. }
  35102. return __extends(e, t), e.prototype.summary = function () {
  35103. return this.upstream.summary() + " -> Flatmap";
  35104. }, e.prototype.pump = function () {
  35105. return __awaiter(this, void 0, void 0, function () {
  35106. var t, e, r, n, i, o, a;
  35107. return __generator(this, function (s) {
  35108. switch (s.label) {
  35109. case 0:
  35110. return [4, this.upstream.next()];
  35111. case 1:
  35112. if ((t = s.sent()).done) return [2, !1];
  35113. for (e = _tfjsCore.tensor_util.getTensorsInContainer(t.value), r = this.transform(t.value), n = _tfjsCore.tensor_util.getTensorsInContainer(r), this.outputQueue.pushAll(r), i = 0, o = e; i < o.length; i++) a = o[i], _tfjsCore.tensor_util.isTensorInList(a, n) || a.dispose();
  35114. return [2, !0];
  35115. }
  35116. });
  35117. });
  35118. }, e;
  35119. }(OneToManyIterator),
  35120. ChainedIterator = function (t) {
  35121. function e(e, r) {
  35122. var n = t.call(this) || this;
  35123. return n.baseErrorHandler = r, n.lastRead = null, n.iterator = null, n.moreIterators = e, n;
  35124. }
  35125. return __extends(e, t), e.prototype.summary = function () {
  35126. return "TODO: fill in upstream of chained summaries -> Chained";
  35127. }, e.prototype.next = function () {
  35128. return __awaiter(this, void 0, void 0, function () {
  35129. return __generator(this, function (t) {
  35130. return this.lastRead = this.readFromChain(this.lastRead), [2, this.lastRead];
  35131. });
  35132. });
  35133. }, e.prototype.readFromChain = function (t) {
  35134. return __awaiter(this, void 0, void 0, function () {
  35135. var e, r;
  35136. return __generator(this, function (n) {
  35137. switch (n.label) {
  35138. case 0:
  35139. return [4, t];
  35140. case 1:
  35141. return n.sent(), null != this.iterator ? [3, 3] : [4, this.moreIterators.next()];
  35142. case 2:
  35143. if ((e = n.sent()).done) return [2, {
  35144. value: null,
  35145. done: !0
  35146. }];
  35147. this.iterator = e.value, null != this.baseErrorHandler && (this.iterator = this.iterator.handleErrors(this.baseErrorHandler)), n.label = 3;
  35148. case 3:
  35149. return [4, this.iterator.next()];
  35150. case 4:
  35151. return (r = n.sent()).done ? (this.iterator = null, [2, this.readFromChain(t)]) : [2, r];
  35152. }
  35153. });
  35154. });
  35155. }, e;
  35156. }(LazyIterator);
  35157. !function (t) {
  35158. t[t.FAIL = 0] = "FAIL", t[t.SHORTEST = 1] = "SHORTEST", t[t.LONGEST = 2] = "LONGEST";
  35159. }(ZipMismatchMode || (ZipMismatchMode = {}));
  35160. var ZipIterator = function (t) {
  35161. function e(e, r) {
  35162. void 0 === r && (r = ZipMismatchMode.FAIL);
  35163. var n = t.call(this) || this;
  35164. return n.iterators = e, n.mismatchMode = r, n.count = 0, n.currentPromise = null, n;
  35165. }
  35166. return __extends(e, t), e.prototype.summary = function () {
  35167. return "{TODO: fill in upstream of zip summaries} -> Zip";
  35168. }, e.prototype.nextState = function (t) {
  35169. return __awaiter(this, void 0, void 0, function () {
  35170. function e(t) {
  35171. return t instanceof LazyIterator ? {
  35172. value: t.next().then(function (t) {
  35173. return r++, t.done && n++, t.value;
  35174. }),
  35175. recurse: !1
  35176. } : {
  35177. value: null,
  35178. recurse: !0
  35179. };
  35180. }
  35181. var r, n, i;
  35182. return __generator(this, function (o) {
  35183. switch (o.label) {
  35184. case 0:
  35185. return [4, t];
  35186. case 1:
  35187. return o.sent(), r = 0, n = 0, [4, deepMapAndAwaitAll(this.iterators, e)];
  35188. case 2:
  35189. if (i = o.sent(), r === n) return [2, {
  35190. value: null,
  35191. done: !0
  35192. }];
  35193. if (n > 0) switch (this.mismatchMode) {
  35194. case ZipMismatchMode.FAIL:
  35195. throw new Error("Zipped streams should have the same length. Mismatched at element " + this.count + ".");
  35196. case ZipMismatchMode.SHORTEST:
  35197. return [2, {
  35198. value: null,
  35199. done: !0
  35200. }];
  35201. case ZipMismatchMode.LONGEST:
  35202. }
  35203. return this.count++, [2, {
  35204. value: i,
  35205. done: !1
  35206. }];
  35207. }
  35208. });
  35209. });
  35210. }, e.prototype.next = function () {
  35211. return __awaiter(this, void 0, void 0, function () {
  35212. return __generator(this, function (t) {
  35213. return this.currentPromise = this.nextState(this.currentPromise), [2, this.currentPromise];
  35214. });
  35215. });
  35216. }, e;
  35217. }(LazyIterator),
  35218. PrefetchIterator = function (t) {
  35219. function e(e, r) {
  35220. var n = t.call(this) || this;
  35221. return n.upstream = e, n.bufferSize = r, n.buffer = new RingBuffer(r), n;
  35222. }
  35223. return __extends(e, t), e.prototype.summary = function () {
  35224. return this.upstream.summary() + " -> Prefetch";
  35225. }, e.prototype.refill = function () {
  35226. for (; !this.buffer.isFull();) {
  35227. var t = this.upstream.next();
  35228. this.buffer.push(t);
  35229. }
  35230. }, e.prototype.next = function () {
  35231. return this.refill(), this.buffer.shift();
  35232. }, e;
  35233. }(LazyIterator),
  35234. ShuffleIterator = function (t) {
  35235. function e(e, r, n) {
  35236. var i = t.call(this, e, r) || this;
  35237. return i.upstream = e, i.windowSize = r, i.upstreamExhausted = !1, i.random = seedrandom_1(n || _tfjsCore.util.now().toString()), i.lastRead = Promise.resolve({
  35238. value: null,
  35239. done: !1
  35240. }), i;
  35241. }
  35242. return __extends(e, t), e.prototype.next = function () {
  35243. return __awaiter(this, void 0, void 0, function () {
  35244. var t = this;
  35245. return __generator(this, function (e) {
  35246. return this.lastRead = this.lastRead.then(function () {
  35247. return t.serialNext();
  35248. }), [2, this.lastRead];
  35249. });
  35250. });
  35251. }, e.prototype.randomInt = function (t) {
  35252. return Math.floor(this.random() * t);
  35253. }, e.prototype.chooseIndex = function () {
  35254. return this.randomInt(this.buffer.length());
  35255. }, e.prototype.serialNext = function () {
  35256. return __awaiter(this, void 0, void 0, function () {
  35257. var t, e;
  35258. return __generator(this, function (r) {
  35259. switch (r.label) {
  35260. case 0:
  35261. this.upstreamExhausted || this.refill(), r.label = 1;
  35262. case 1:
  35263. return this.buffer.isEmpty() ? [3, 3] : (t = this.chooseIndex(), [4, this.buffer.shuffleExcise(t)]);
  35264. case 2:
  35265. return (e = r.sent()).done ? (this.upstreamExhausted = !0, [3, 1]) : (this.refill(), [2, e]);
  35266. case 3:
  35267. return [2, {
  35268. value: null,
  35269. done: !0
  35270. }];
  35271. }
  35272. });
  35273. });
  35274. }, e;
  35275. }(PrefetchIterator),
  35276. Dataset = function () {
  35277. function t() {
  35278. this.size = null;
  35279. }
  35280. return t.prototype.batch = function (t, e) {
  35281. var r = this;
  35282. void 0 === e && (e = !0);
  35283. var n = this;
  35284. return _tfjsCore.util.assert(t > 0, function () {
  35285. return "batchSize needs to be positive, but it is\n " + t;
  35286. }), datasetFromIteratorFn(function () {
  35287. return __awaiter(r, void 0, void 0, function () {
  35288. return __generator(this, function (r) {
  35289. switch (r.label) {
  35290. case 0:
  35291. return [4, n.iterator()];
  35292. case 1:
  35293. return [2, r.sent().columnMajorBatch(t, e, deepBatchConcat)];
  35294. }
  35295. });
  35296. });
  35297. }, this.size === 1 / 0 || null == this.size ? this.size : e ? Math.ceil(this.size / t) : Math.floor(this.size / t));
  35298. }, t.prototype.concatenate = function (t) {
  35299. var e = this,
  35300. r = this;
  35301. return datasetFromIteratorFn(function () {
  35302. return __awaiter(e, void 0, void 0, function () {
  35303. var e, n;
  35304. return __generator(this, function (i) {
  35305. switch (i.label) {
  35306. case 0:
  35307. return [4, r.iterator()];
  35308. case 1:
  35309. return n = (e = i.sent()).concatenate, [4, t.iterator()];
  35310. case 2:
  35311. return [2, n.apply(e, [i.sent()])];
  35312. }
  35313. });
  35314. });
  35315. }, this.size === 1 / 0 || t.size === 1 / 0 ? 1 / 0 : null != this.size && null != t.size ? this.size + t.size : null);
  35316. }, t.prototype.filter = function (t) {
  35317. var e = this,
  35318. r = this;
  35319. return datasetFromIteratorFn(function () {
  35320. return __awaiter(e, void 0, void 0, function () {
  35321. return __generator(this, function (e) {
  35322. switch (e.label) {
  35323. case 0:
  35324. return [4, r.iterator()];
  35325. case 1:
  35326. return [2, e.sent().filter(function (e) {
  35327. return (0, _tfjsCore.tidy)(function () {
  35328. return t(e);
  35329. });
  35330. })];
  35331. }
  35332. });
  35333. });
  35334. }, this.size === 1 / 0 ? 1 / 0 : null);
  35335. }, t.prototype.forEachAsync = function (t) {
  35336. return __awaiter(this, void 0, void 0, function () {
  35337. return __generator(this, function (e) {
  35338. switch (e.label) {
  35339. case 0:
  35340. return [4, this.iterator()];
  35341. case 1:
  35342. return [2, e.sent().forEachAsync(t)];
  35343. }
  35344. });
  35345. });
  35346. }, t.prototype.forEach = function (t) {
  35347. return __awaiter(this, void 0, void 0, function () {
  35348. return __generator(this, function (e) {
  35349. return (0, _tfjsCore.deprecationWarn)("dataset.forEach() is deprecated and will be removed. Please use dataset.forEachAsync() instead"), [2, this.forEachAsync(t)];
  35350. });
  35351. });
  35352. }, t.prototype.map = function (t) {
  35353. var e = this,
  35354. r = this;
  35355. return datasetFromIteratorFn(function () {
  35356. return __awaiter(e, void 0, void 0, function () {
  35357. return __generator(this, function (e) {
  35358. switch (e.label) {
  35359. case 0:
  35360. return [4, r.iterator()];
  35361. case 1:
  35362. return [2, e.sent().map(function (e) {
  35363. return (0, _tfjsCore.tidy)(function () {
  35364. return t(e);
  35365. });
  35366. })];
  35367. }
  35368. });
  35369. });
  35370. }, this.size);
  35371. }, t.prototype.mapAsync = function (t) {
  35372. var e = this,
  35373. r = this;
  35374. return datasetFromIteratorFn(function () {
  35375. return __awaiter(e, void 0, void 0, function () {
  35376. return __generator(this, function (e) {
  35377. switch (e.label) {
  35378. case 0:
  35379. return [4, r.iterator()];
  35380. case 1:
  35381. return [2, e.sent().mapAsync(t)];
  35382. }
  35383. });
  35384. });
  35385. }, this.size);
  35386. }, t.prototype.prefetch = function (t) {
  35387. var e = this;
  35388. if (null == t) throw new RangeError("`Dataset.prefetch()` requires bufferSize to be specified.");
  35389. var r = this;
  35390. return datasetFromIteratorFn(function () {
  35391. return __awaiter(e, void 0, void 0, function () {
  35392. return __generator(this, function (e) {
  35393. switch (e.label) {
  35394. case 0:
  35395. return [4, r.iterator()];
  35396. case 1:
  35397. return [2, e.sent().prefetch(t)];
  35398. }
  35399. });
  35400. });
  35401. }, this.size);
  35402. }, t.prototype.repeat = function (t) {
  35403. var e = this,
  35404. r = this;
  35405. return datasetFromIteratorFn(function () {
  35406. return __awaiter(e, void 0, void 0, function () {
  35407. var e = this;
  35408. return __generator(this, function (n) {
  35409. return [2, iteratorFromConcatenated(iteratorFromFunction(function () {
  35410. return __awaiter(e, void 0, void 0, function () {
  35411. var t;
  35412. return __generator(this, function (e) {
  35413. switch (e.label) {
  35414. case 0:
  35415. return t = {}, [4, r.iterator()];
  35416. case 1:
  35417. return [2, (t.value = e.sent(), t.done = !1, t)];
  35418. }
  35419. });
  35420. });
  35421. }).take(t))];
  35422. });
  35423. });
  35424. }, null != this.size && t > 0 ? this.size * t : 0 === t ? 0 : null != this.size && (void 0 === t || t < 0) ? 1 / 0 : null);
  35425. }, t.prototype.skip = function (t) {
  35426. var e = this,
  35427. r = this;
  35428. return datasetFromIteratorFn(function () {
  35429. return __awaiter(e, void 0, void 0, function () {
  35430. return __generator(this, function (e) {
  35431. switch (e.label) {
  35432. case 0:
  35433. return [4, r.iterator()];
  35434. case 1:
  35435. return [2, e.sent().skip(t)];
  35436. }
  35437. });
  35438. });
  35439. }, null != this.size && t >= 0 && this.size >= t ? this.size - t : null != this.size && (this.size < t || void 0 === t || t < 0) ? 0 : null);
  35440. }, t.prototype.shuffle = function (t, e, r) {
  35441. var n = this;
  35442. if (void 0 === r && (r = !0), null == t || t < 0) throw null == this.size ? new RangeError("`Dataset.shuffle()` requires bufferSize to be specified.") : new RangeError("`Dataset.shuffle()` requires bufferSize to be specified. If your data fits in main memory (for regular JS objects), and/or GPU memory (for `tf.Tensor`s), consider setting bufferSize to the dataset size (" + this.size + " elements)");
  35443. var i = this,
  35444. o = seedrandom_1(e || _tfjsCore.util.now().toString());
  35445. return datasetFromIteratorFn(function () {
  35446. return __awaiter(n, void 0, void 0, function () {
  35447. var e;
  35448. return __generator(this, function (n) {
  35449. switch (n.label) {
  35450. case 0:
  35451. return e = o.int32(), r && (e += o.int32()), [4, i.iterator()];
  35452. case 1:
  35453. return [2, n.sent().shuffle(t, e.toString())];
  35454. }
  35455. });
  35456. });
  35457. }, this.size);
  35458. }, t.prototype.take = function (t) {
  35459. var e = this,
  35460. r = this;
  35461. return datasetFromIteratorFn(function () {
  35462. return __awaiter(e, void 0, void 0, function () {
  35463. return __generator(this, function (e) {
  35464. switch (e.label) {
  35465. case 0:
  35466. return [4, r.iterator()];
  35467. case 1:
  35468. return [2, e.sent().take(t)];
  35469. }
  35470. });
  35471. });
  35472. }, null != this.size && this.size > t ? t : null != this.size && this.size <= t ? this.size : null);
  35473. }, t.prototype.toArray = function () {
  35474. return __awaiter(this, void 0, void 0, function () {
  35475. return __generator(this, function (t) {
  35476. switch (t.label) {
  35477. case 0:
  35478. if (this.size === 1 / 0) throw new Error("Can not convert infinite data stream to array.");
  35479. return [4, this.iterator()];
  35480. case 1:
  35481. return [2, t.sent().toArray()];
  35482. }
  35483. });
  35484. });
  35485. }, t.prototype.toArrayForTest = function () {
  35486. return __awaiter(this, void 0, void 0, function () {
  35487. return __generator(this, function (t) {
  35488. switch (t.label) {
  35489. case 0:
  35490. if (this.size === 1 / 0) throw new Error("Can not convert infinite data stream to array.");
  35491. return [4, this.iterator()];
  35492. case 1:
  35493. return [2, t.sent().toArrayForTest()];
  35494. }
  35495. });
  35496. });
  35497. }, t.MAX_BUFFER_SIZE = 1e4, t;
  35498. }();
  35499. exports.Dataset = Dataset;
  35500. function datasetFromIteratorFn(t, e) {
  35501. return void 0 === e && (e = null), new (function (r) {
  35502. function n() {
  35503. var t = null !== r && r.apply(this, arguments) || this;
  35504. return t.size = e, t;
  35505. }
  35506. return __extends(n, r), n.prototype.iterator = function () {
  35507. return __awaiter(this, void 0, void 0, function () {
  35508. return __generator(this, function (e) {
  35509. return [2, t()];
  35510. });
  35511. });
  35512. }, n;
  35513. }(Dataset))();
  35514. }
  35515. function array(t) {
  35516. var e = this;
  35517. return datasetFromIteratorFn(function () {
  35518. return __awaiter(e, void 0, void 0, function () {
  35519. return __generator(this, function (e) {
  35520. return [2, iteratorFromItems(t)];
  35521. });
  35522. });
  35523. }, t.length);
  35524. }
  35525. function zip(t) {
  35526. var e,
  35527. r = this;
  35528. if (!isIterable(t)) throw new Error("The argument to zip() must be an object or array.");
  35529. if (Array.isArray(t)) for (var n = 0; n < t.length; n++) e = null == e ? t[n].size : Math.min(e, t[n].size); else if (t instanceof Object) for (var i in t) e = null == e ? t[i].size : Math.min(e, t[i].size);
  35530. return datasetFromIteratorFn(function () {
  35531. return __awaiter(r, void 0, void 0, function () {
  35532. return __generator(this, function (e) {
  35533. switch (e.label) {
  35534. case 0:
  35535. return [4, deepMapAndAwaitAll(t, function (t) {
  35536. if (t instanceof Dataset) return {
  35537. value: t.iterator(),
  35538. recurse: !1
  35539. };
  35540. if (isIterable(t)) return {
  35541. value: null,
  35542. recurse: !0
  35543. };
  35544. throw new Error("Leaves of the structure passed to zip() must be Datasets, not primitives.");
  35545. })];
  35546. case 1:
  35547. return [2, iteratorFromZipped(e.sent(), ZipMismatchMode.SHORTEST)];
  35548. }
  35549. });
  35550. });
  35551. }, e);
  35552. }
  35553. function deepBatchConcat(t) {
  35554. return null === t ? null : canTensorify(t[0]) ? {
  35555. value: batchConcat(t),
  35556. recurse: !1
  35557. } : {
  35558. value: null,
  35559. recurse: !0
  35560. };
  35561. }
  35562. function batchConcat(t) {
  35563. if (0 === t.length) throw new Error("Can't make a batch of zero elements.");
  35564. return t[0] instanceof _tfjsCore.Tensor ? (0, _tfjsCore.stack)(t) : (0, _tfjsCore.tensor)(t);
  35565. }
  35566. var TextLineDataset = function (t) {
  35567. function e(e) {
  35568. var r = t.call(this) || this;
  35569. return r.input = e, r;
  35570. }
  35571. return __extends(e, t), e.prototype.iterator = function () {
  35572. return __awaiter(this, void 0, void 0, function () {
  35573. var t, e;
  35574. return __generator(this, function (r) {
  35575. switch (r.label) {
  35576. case 0:
  35577. return [4, this.input.iterator()];
  35578. case 1:
  35579. return t = r.sent(), e = t.decodeUTF8(), [2, e.split("\n").map(function (t) {
  35580. return t.endsWith("\r") && (t = t.slice(0, -1)), t;
  35581. })];
  35582. }
  35583. });
  35584. });
  35585. }, e;
  35586. }(Dataset),
  35587. CODE_QUOTE = '"',
  35588. STATE_OUT = Symbol("out"),
  35589. STATE_FIELD = Symbol("field"),
  35590. STATE_QUOTE = Symbol("quote"),
  35591. STATE_QUOTE_AFTER_QUOTE = Symbol("quoteafterquote"),
  35592. STATE_WITHIN_QUOTE_IN_QUOTE = Symbol("quoteinquote"),
  35593. CSVDataset = function (t) {
  35594. function e(e, r) {
  35595. var n = t.call(this) || this;
  35596. return n.input = e, n.hasHeader = !0, n.fullColumnNames = null, n.columnNamesValidated = !1, n.columnConfigs = null, n.configuredColumnsOnly = !1, n.delimiter = ",", n.delimWhitespace = !1, n.base = new TextLineDataset(e), r || (r = {}), n.hasHeader = !1 !== r.hasHeader, n.fullColumnNames = r.columnNames, n.columnConfigs = r.columnConfigs, n.configuredColumnsOnly = r.configuredColumnsOnly, r.delimWhitespace ? (_tfjsCore.util.assert(null == r.delimiter, function () {
  35597. return "Delimiter should not be provided when delimWhitespace is true.";
  35598. }), n.delimWhitespace = !0, n.delimiter = " ") : n.delimiter = r.delimiter ? r.delimiter : ",", n;
  35599. }
  35600. return __extends(e, t), e.prototype.columnNames = function () {
  35601. return __awaiter(this, void 0, void 0, function () {
  35602. return __generator(this, function (t) {
  35603. switch (t.label) {
  35604. case 0:
  35605. return this.columnNamesValidated ? [3, 2] : [4, this.setColumnNames()];
  35606. case 1:
  35607. t.sent(), t.label = 2;
  35608. case 2:
  35609. return [2, this.configuredColumnsOnly ? Object.keys(this.columnConfigs) : this.fullColumnNames];
  35610. }
  35611. });
  35612. });
  35613. }, e.prototype.setColumnNames = function () {
  35614. return __awaiter(this, void 0, void 0, function () {
  35615. var t,
  35616. e,
  35617. r,
  35618. n,
  35619. i,
  35620. o,
  35621. a = this;
  35622. return __generator(this, function (s) {
  35623. switch (s.label) {
  35624. case 0:
  35625. return [4, this.maybeReadHeaderLine()];
  35626. case 1:
  35627. if (t = s.sent(), !this.fullColumnNames && !t) throw new Error("Column names must be provided if there is no header line.");
  35628. if (this.fullColumnNames && t && _tfjsCore.util.assert(t.length === this.fullColumnNames.length, function () {
  35629. return "The length of provided columnNames (" + a.fullColumnNames.length.toString() + ") does not match the length of the header line read from file (" + t.length.toString() + ").";
  35630. }), this.fullColumnNames || (this.fullColumnNames = t), e = this.fullColumnNames.reduce(function (t, e) {
  35631. return t[e] = t[e] + 1 || 1, t;
  35632. }, {}), r = Object.keys(e).filter(function (t) {
  35633. return e[t] > 1;
  35634. }), _tfjsCore.util.assert(0 === r.length, function () {
  35635. return "Duplicate column names found: " + r.toString();
  35636. }), this.columnConfigs) for (n = 0, i = Object.keys(this.columnConfigs); n < i.length; n++) if (o = i[n], -1 === this.fullColumnNames.indexOf(o)) throw new Error('The key "' + o + '" provided in columnConfigs does not match any of the column names (' + this.fullColumnNames.toString() + ").");
  35637. return this.columnNamesValidated = !0, [2];
  35638. }
  35639. });
  35640. });
  35641. }, e.prototype.maybeReadHeaderLine = function () {
  35642. return __awaiter(this, void 0, void 0, function () {
  35643. var t, e;
  35644. return __generator(this, function (r) {
  35645. switch (r.label) {
  35646. case 0:
  35647. return this.hasHeader ? [4, this.base.iterator()] : [3, 3];
  35648. case 1:
  35649. return [4, r.sent().next()];
  35650. case 2:
  35651. if ((t = r.sent()).done) throw new Error("No data was found for CSV parsing.");
  35652. return e = t.value, [2, this.parseRow(e, !1)];
  35653. case 3:
  35654. return [2, null];
  35655. }
  35656. });
  35657. });
  35658. }, e.prototype.iterator = function () {
  35659. return __awaiter(this, void 0, void 0, function () {
  35660. var t,
  35661. e = this;
  35662. return __generator(this, function (r) {
  35663. switch (r.label) {
  35664. case 0:
  35665. return this.columnNamesValidated ? [3, 2] : [4, this.setColumnNames()];
  35666. case 1:
  35667. r.sent(), r.label = 2;
  35668. case 2:
  35669. return [4, this.base.iterator()];
  35670. case 3:
  35671. return t = r.sent(), this.hasHeader && (t = t.skip(1)), [2, t.map(function (t) {
  35672. return e.makeDataElement(t);
  35673. })];
  35674. }
  35675. });
  35676. });
  35677. }, e.prototype.makeDataElement = function (t) {
  35678. for (var e = this.parseRow(t), r = {}, n = {}, i = 0; i < this.fullColumnNames.length; i++) {
  35679. var o = this.fullColumnNames[i],
  35680. a = this.columnConfigs ? this.columnConfigs[o] : null;
  35681. if (!this.configuredColumnsOnly || a) {
  35682. var s = e[i],
  35683. u = null;
  35684. if ("" === s) {
  35685. if (a && void 0 !== a.default) u = a.default; else {
  35686. if (a && (a.required || a.isLabel)) throw new Error("Required column " + o + " is empty in this line: " + t);
  35687. u = void 0;
  35688. }
  35689. } else {
  35690. var c = Number(s);
  35691. if (isNaN(c)) u = a && "bool" === a.dtype ? this.getBoolean(s) : s; else if (a && a.dtype) switch (a.dtype) {
  35692. case "float32":
  35693. u = c;
  35694. break;
  35695. case "int32":
  35696. u = Math.floor(c);
  35697. break;
  35698. case "bool":
  35699. u = this.getBoolean(s);
  35700. break;
  35701. default:
  35702. u = c;
  35703. } else u = c;
  35704. }
  35705. a && a.isLabel ? n[o] = u : r[o] = u;
  35706. }
  35707. }
  35708. return 0 === Object.keys(n).length ? r : {
  35709. xs: r,
  35710. ys: n
  35711. };
  35712. }, e.prototype.getBoolean = function (t) {
  35713. return "1" === t || "true" === t.toLowerCase() ? 1 : 0;
  35714. }, e.prototype.parseRow = function (t, e) {
  35715. void 0 === e && (e = !0);
  35716. for (var r = [], n = 0, i = t.length, o = STATE_OUT, a = 0; a < i; a++) switch (o) {
  35717. case STATE_OUT:
  35718. switch (t.charAt(a)) {
  35719. case CODE_QUOTE:
  35720. n = a + 1, o = STATE_QUOTE;
  35721. break;
  35722. case this.delimiter:
  35723. if (n = a + 1, " " === this.delimiter && this.delimWhitespace) break;
  35724. r.push(""), o = STATE_OUT;
  35725. break;
  35726. default:
  35727. o = STATE_FIELD, n = a;
  35728. }
  35729. break;
  35730. case STATE_FIELD:
  35731. switch (t.charAt(a)) {
  35732. case this.delimiter:
  35733. r.push(t.substring(n, a)), o = STATE_OUT, n = a + 1;
  35734. }
  35735. break;
  35736. case STATE_QUOTE:
  35737. switch (t.charAt(a)) {
  35738. case CODE_QUOTE:
  35739. o = STATE_QUOTE_AFTER_QUOTE;
  35740. }
  35741. break;
  35742. case STATE_QUOTE_AFTER_QUOTE:
  35743. switch (t.charAt(a)) {
  35744. case this.delimiter:
  35745. r.push(t.substring(n, a - 1)), o = STATE_OUT, n = a + 1;
  35746. break;
  35747. case CODE_QUOTE:
  35748. o = STATE_QUOTE;
  35749. break;
  35750. default:
  35751. o = STATE_WITHIN_QUOTE_IN_QUOTE;
  35752. }
  35753. break;
  35754. case STATE_WITHIN_QUOTE_IN_QUOTE:
  35755. switch (t.charAt(a)) {
  35756. case CODE_QUOTE:
  35757. o = STATE_QUOTE;
  35758. }
  35759. }
  35760. if (o === STATE_QUOTE_AFTER_QUOTE ? r.push(t.substring(n, i - 1)) : r.push(t.substring(n)), e && r.length !== this.fullColumnNames.length) throw new Error("Invalid row in csv file. Should have " + this.fullColumnNames.length + " elements in a row, but got " + r);
  35761. return r;
  35762. }, e;
  35763. }(Dataset),
  35764. MicrophoneIterator = function (t) {
  35765. function e(e) {
  35766. var r = t.call(this) || this;
  35767. r.microphoneConfig = e, r.isClosed = !1, r.fftSize = e.fftSize || 1024;
  35768. var n = Math.log2(r.fftSize);
  35769. if (r.fftSize < 0 || n < 4 || n > 14 || !Number.isInteger(n)) throw new Error("Invalid fftSize: it must be a power of 2 between 2 to 4 and 2 to 14, but got " + r.fftSize);
  35770. if (r.numFrames = e.numFramesPerSpectrogram || 43, r.sampleRateHz = e.sampleRateHz, r.columnTruncateLength = e.columnTruncateLength || r.fftSize, r.audioTrackConstraints = e.audioTrackConstraints, r.smoothingTimeConstant = e.smoothingTimeConstant || 0, r.includeSpectrogram = !1 !== e.includeSpectrogram, r.includeWaveform = !0 === e.includeWaveform, !r.includeSpectrogram && !r.includeWaveform) throw new Error("Both includeSpectrogram and includeWaveform are false. At least one type of data should be returned.");
  35771. return r;
  35772. }
  35773. return __extends(e, t), e.prototype.summary = function () {
  35774. return "microphone";
  35775. }, e.create = function (t) {
  35776. return void 0 === t && (t = {}), __awaiter(this, void 0, void 0, function () {
  35777. var r;
  35778. return __generator(this, function (n) {
  35779. switch (n.label) {
  35780. case 0:
  35781. if ((0, _tfjsCore.env)().get("IS_NODE")) throw new Error("microphone API is only supported in browser environment.");
  35782. return [4, (r = new e(t)).start()];
  35783. case 1:
  35784. return n.sent(), [2, r];
  35785. }
  35786. });
  35787. });
  35788. }, e.prototype.start = function () {
  35789. return __awaiter(this, void 0, void 0, function () {
  35790. var t, e, r, n;
  35791. return __generator(this, function (i) {
  35792. switch (i.label) {
  35793. case 0:
  35794. return i.trys.push([0, 2, , 3]), t = this, [4, navigator.mediaDevices.getUserMedia({
  35795. audio: null == this.audioTrackConstraints || this.audioTrackConstraints,
  35796. video: !1
  35797. })];
  35798. case 1:
  35799. return t.stream = i.sent(), [3, 3];
  35800. case 2:
  35801. throw e = i.sent(), new Error("Error thrown while initializing video stream: " + e.message);
  35802. case 3:
  35803. if (!this.stream) throw new Error("Could not obtain audio from microphone.");
  35804. if (r = window.AudioContext || window.webkitAudioContext, this.audioContext = new r(), this.sampleRateHz) {
  35805. if (this.audioContext.sampleRate !== this.sampleRateHz) throw new Error("Mismatch in sampling rate: Expected: " + this.sampleRateHz + "; Actual: " + this.audioContext.sampleRate);
  35806. } else this.sampleRateHz = this.audioContext.sampleRate;
  35807. return n = this.audioContext.createMediaStreamSource(this.stream), this.analyser = this.audioContext.createAnalyser(), this.analyser.fftSize = 2 * this.fftSize, this.analyser.smoothingTimeConstant = this.smoothingTimeConstant, n.connect(this.analyser), this.freqData = new Float32Array(this.fftSize), this.timeData = new Float32Array(this.fftSize), [2];
  35808. }
  35809. });
  35810. });
  35811. }, e.prototype.next = function () {
  35812. return __awaiter(this, void 0, void 0, function () {
  35813. var t, e, r, n, i;
  35814. return __generator(this, function (o) {
  35815. switch (o.label) {
  35816. case 0:
  35817. return this.isClosed ? [2, {
  35818. value: null,
  35819. done: !0
  35820. }] : [4, this.getAudioData()];
  35821. case 1:
  35822. return r = o.sent(), this.includeSpectrogram && (n = this.flattenQueue(r.freqDataQueue), t = this.getTensorFromAudioDataArray(n, [this.numFrames, this.columnTruncateLength, 1])), this.includeWaveform && (i = this.flattenQueue(r.timeDataQueue), e = this.getTensorFromAudioDataArray(i, [this.numFrames * this.fftSize, 1])), [2, {
  35823. value: {
  35824. spectrogram: t,
  35825. waveform: e
  35826. },
  35827. done: !1
  35828. }];
  35829. }
  35830. });
  35831. });
  35832. }, e.prototype.capture = function () {
  35833. return __awaiter(this, void 0, void 0, function () {
  35834. return __generator(this, function (t) {
  35835. switch (t.label) {
  35836. case 0:
  35837. return [4, this.next()];
  35838. case 1:
  35839. return [2, t.sent().value];
  35840. }
  35841. });
  35842. });
  35843. }, e.prototype.getAudioData = function () {
  35844. return __awaiter(this, void 0, void 0, function () {
  35845. var t,
  35846. e,
  35847. r,
  35848. n = this;
  35849. return __generator(this, function (i) {
  35850. return t = [], e = [], r = 0, [2, new Promise(function (i) {
  35851. var o = setInterval(function () {
  35852. n.includeSpectrogram && (n.analyser.getFloatFrequencyData(n.freqData), n.freqData[0] === -1 / 0 && i({
  35853. freqDataQueue: t,
  35854. timeDataQueue: e
  35855. }), t.push(n.freqData.slice(0, n.columnTruncateLength))), n.includeWaveform && (n.analyser.getFloatTimeDomainData(n.timeData), e.push(n.timeData.slice())), ++r === n.numFrames && (clearInterval(o), i({
  35856. freqDataQueue: t,
  35857. timeDataQueue: e
  35858. }));
  35859. }, n.fftSize / n.sampleRateHz * 1e3);
  35860. })];
  35861. });
  35862. });
  35863. }, e.prototype.stop = function () {
  35864. this.isClosed || (this.isClosed = !0, this.analyser.disconnect(), this.audioContext.close(), null != this.stream && this.stream.getTracks().length > 0 && this.stream.getTracks()[0].stop());
  35865. }, e.prototype.toArray = function () {
  35866. throw new Error("Can not convert infinite audio stream to array.");
  35867. }, e.prototype.getSampleRate = function () {
  35868. return this.sampleRateHz;
  35869. }, e.prototype.flattenQueue = function (t) {
  35870. var e = t[0].length,
  35871. r = new Float32Array(t.length * e);
  35872. return t.forEach(function (t, n) {
  35873. return r.set(t, n * e);
  35874. }), r;
  35875. }, e.prototype.getTensorFromAudioDataArray = function (t, e) {
  35876. var r = new Float32Array(_tfjsCore.util.sizeFromShape(e));
  35877. return r.set(t, r.length - t.length), (0, _tfjsCore.tensor)(r, e);
  35878. }, e;
  35879. }(LazyIterator),
  35880. WebcamIterator = function (t) {
  35881. function e(e, r) {
  35882. var n = t.call(this) || this;
  35883. if (n.webcamVideoElement = e, n.webcamConfig = r, n.isClosed = !0, n.resize = !1, n.needToResize()) if (n.resize = !0, n.cropSize = [n.webcamConfig.resizeHeight, n.webcamConfig.resizeWidth], n.cropBoxInd = (0, _tfjsCore.tensor1d)([0], "int32"), n.webcamConfig.centerCrop) {
  35884. var i = 1 * n.webcamConfig.resizeWidth / n.webcamVideoElement.width,
  35885. o = 1 * n.webcamConfig.resizeHeight / n.webcamVideoElement.height,
  35886. a = (1 - i) / 2,
  35887. s = (1 - o) / 2,
  35888. u = a + i,
  35889. c = o + s;
  35890. n.cropBox = (0, _tfjsCore.tensor2d)([s, a, c, u], [1, 4]);
  35891. } else n.cropBox = (0, _tfjsCore.tensor2d)([0, 0, 1, 1], [1, 4]);
  35892. return n;
  35893. }
  35894. return __extends(e, t), e.prototype.summary = function () {
  35895. return "webcam";
  35896. }, e.create = function (t, r) {
  35897. return void 0 === r && (r = {}), __awaiter(this, void 0, void 0, function () {
  35898. var n;
  35899. return __generator(this, function (i) {
  35900. switch (i.label) {
  35901. case 0:
  35902. if ((0, _tfjsCore.env)().get("IS_NODE")) throw new Error("tf.data.webcam is only supported in browser environment.");
  35903. if (!t) {
  35904. if (t = document.createElement("video"), !r.resizeWidth || !r.resizeHeight) throw new Error("Please provide webcam video element, or resizeWidth and resizeHeight to create a hidden video element.");
  35905. t.width = r.resizeWidth, t.height = r.resizeHeight;
  35906. }
  35907. return [4, (n = new e(t, r)).start()];
  35908. case 1:
  35909. return i.sent(), [2, n];
  35910. }
  35911. });
  35912. });
  35913. }, e.prototype.start = function () {
  35914. return __awaiter(this, void 0, void 0, function () {
  35915. var t,
  35916. e,
  35917. r = this;
  35918. return __generator(this, function (n) {
  35919. switch (n.label) {
  35920. case 0:
  35921. this.webcamConfig.facingMode && _tfjsCore.util.assert("user" === this.webcamConfig.facingMode || "environment" === this.webcamConfig.facingMode, function () {
  35922. return "Invalid webcam facing mode: " + r.webcamConfig.facingMode + ". Please provide 'user' or 'environment'";
  35923. }), n.label = 1;
  35924. case 1:
  35925. return n.trys.push([1, 3, , 4]), t = this, [4, navigator.mediaDevices.getUserMedia({
  35926. video: {
  35927. deviceId: this.webcamConfig.deviceId,
  35928. facingMode: this.webcamConfig.facingMode ? this.webcamConfig.facingMode : "user",
  35929. width: this.webcamVideoElement.width,
  35930. height: this.webcamVideoElement.height
  35931. }
  35932. })];
  35933. case 2:
  35934. return t.stream = n.sent(), [3, 4];
  35935. case 3:
  35936. throw (e = n.sent()).message = "Error thrown while initializing video stream: " + e.message, e;
  35937. case 4:
  35938. if (!this.stream) throw new Error("Could not obtain video from webcam.");
  35939. try {
  35940. this.webcamVideoElement.srcObject = this.stream;
  35941. } catch (t) {
  35942. console.log(t), this.webcamVideoElement.src = window.URL.createObjectURL(this.stream);
  35943. }
  35944. return this.webcamVideoElement.play(), this.isClosed = !1, [2, new Promise(function (t) {
  35945. r.webcamVideoElement.onloadedmetadata = function () {
  35946. t();
  35947. };
  35948. })];
  35949. }
  35950. });
  35951. });
  35952. }, e.prototype.next = function () {
  35953. return __awaiter(this, void 0, void 0, function () {
  35954. var t;
  35955. return __generator(this, function (e) {
  35956. if (this.isClosed) return [2, {
  35957. value: null,
  35958. done: !0
  35959. }];
  35960. try {
  35961. t = _tfjsCore.browser.fromPixels(this.webcamVideoElement);
  35962. } catch (t) {
  35963. throw new Error("Error thrown converting video to pixels: " + JSON.stringify(t));
  35964. }
  35965. if (!this.resize) return [2, {
  35966. value: t,
  35967. done: !1
  35968. }];
  35969. try {
  35970. return [2, {
  35971. value: this.cropAndResizeFrame(t),
  35972. done: !1
  35973. }];
  35974. } catch (t) {
  35975. throw new Error("Error thrown cropping the video: " + t.message);
  35976. } finally {
  35977. t.dispose();
  35978. }
  35979. return [2];
  35980. });
  35981. });
  35982. }, e.prototype.needToResize = function () {
  35983. return !(!this.webcamConfig.resizeWidth || !this.webcamConfig.resizeHeight || this.webcamVideoElement.width === this.webcamConfig.resizeWidth && this.webcamVideoElement.height === this.webcamConfig.resizeHeight);
  35984. }, e.prototype.cropAndResizeFrame = function (t) {
  35985. var e = this;
  35986. return (0, _tfjsCore.tidy)(function () {
  35987. var r,
  35988. n = t.toFloat().expandDims(0),
  35989. i = (r = _tfjsCore.image.cropAndResize(n, e.cropBox, e.cropBoxInd, e.cropSize, "bilinear")).shape;
  35990. return r.reshape(i.slice(1));
  35991. });
  35992. }, e.prototype.capture = function () {
  35993. return __awaiter(this, void 0, void 0, function () {
  35994. return __generator(this, function (t) {
  35995. switch (t.label) {
  35996. case 0:
  35997. return [4, this.next()];
  35998. case 1:
  35999. return [2, t.sent().value];
  36000. }
  36001. });
  36002. });
  36003. }, e.prototype.stop = function () {
  36004. this.stream.getTracks().forEach(function (t) {
  36005. return t.stop();
  36006. });
  36007. try {
  36008. this.webcamVideoElement.srcObject = null;
  36009. } catch (t) {
  36010. console.log(t), this.webcamVideoElement.src = null;
  36011. }
  36012. this.isClosed = !0;
  36013. }, e.prototype.toArray = function () {
  36014. throw new Error("Can not convert infinite video stream to array.");
  36015. }, e;
  36016. }(LazyIterator),
  36017. DataSource = function () {
  36018. return function () { };
  36019. }(),
  36020. StringIterator = function (t) {
  36021. function e() {
  36022. return null !== t && t.apply(this, arguments) || this;
  36023. }
  36024. return __extends(e, t), e.prototype.split = function (t) {
  36025. return new SplitIterator(this, t);
  36026. }, e;
  36027. }(LazyIterator),
  36028. SplitIterator = function (t) {
  36029. function e(e, r) {
  36030. var n = t.call(this) || this;
  36031. return n.upstream = e, n.impl = new SplitIteratorImpl(e, r), n;
  36032. }
  36033. return __extends(e, t), e.prototype.summary = function () {
  36034. return this.impl.summary();
  36035. }, e.prototype.next = function () {
  36036. return __awaiter(this, void 0, void 0, function () {
  36037. return __generator(this, function (t) {
  36038. return [2, this.impl.next()];
  36039. });
  36040. });
  36041. }, e;
  36042. }(StringIterator),
  36043. SplitIteratorImpl = function (t) {
  36044. function e(e, r) {
  36045. var n = t.call(this) || this;
  36046. return n.upstream = e, n.separator = r, n.carryover = "", n;
  36047. }
  36048. return __extends(e, t), e.prototype.summary = function () {
  36049. return this.upstream.summary() + " -> Split('" + this.separator + "')";
  36050. }, e.prototype.pump = function () {
  36051. return __awaiter(this, void 0, void 0, function () {
  36052. var t, e, r, n, i;
  36053. return __generator(this, function (o) {
  36054. switch (o.label) {
  36055. case 0:
  36056. return [4, this.upstream.next()];
  36057. case 1:
  36058. if ((t = o.sent()).done) return "" === this.carryover ? [2, !1] : (this.outputQueue.push(this.carryover), this.carryover = "", [2, !0]);
  36059. for ((e = t.value.split(this.separator))[0] = this.carryover + e[0], r = 0, n = e.slice(0, -1); r < n.length; r++) i = n[r], this.outputQueue.push(i);
  36060. return this.carryover = e[e.length - 1], [2, !0];
  36061. }
  36062. });
  36063. });
  36064. }, e;
  36065. }(OneToManyIterator),
  36066. ByteChunkIterator = function (t) {
  36067. function e() {
  36068. return null !== t && t.apply(this, arguments) || this;
  36069. }
  36070. return __extends(e, t), e.prototype.decodeUTF8 = function () {
  36071. return new Utf8Iterator(this);
  36072. }, e;
  36073. }(LazyIterator),
  36074. Utf8Iterator = function (t) {
  36075. function e(e) {
  36076. var r = t.call(this) || this;
  36077. return r.upstream = e, r.impl = new Utf8IteratorImpl(e), r;
  36078. }
  36079. return __extends(e, t), e.prototype.summary = function () {
  36080. return this.impl.summary();
  36081. }, e.prototype.next = function () {
  36082. return __awaiter(this, void 0, void 0, function () {
  36083. return __generator(this, function (t) {
  36084. return [2, this.impl.next()];
  36085. });
  36086. });
  36087. }, e;
  36088. }(StringIterator),
  36089. Utf8IteratorImpl = function (t) {
  36090. function e(e) {
  36091. var r = t.call(this) || this;
  36092. if (r.upstream = e, (0, _tfjsCore.env)().get("IS_BROWSER")) r.decoder = new TextDecoder("utf-8"); else {
  36093. var n = require("string_decoder").StringDecoder;
  36094. r.decoder = new n("utf8");
  36095. }
  36096. return r;
  36097. }
  36098. return __extends(e, t), e.prototype.summary = function () {
  36099. return this.upstream.summary() + " -> Utf8";
  36100. }, e.prototype.pump = function () {
  36101. return __awaiter(this, void 0, void 0, function () {
  36102. var t, e, r;
  36103. return __generator(this, function (n) {
  36104. switch (n.label) {
  36105. case 0:
  36106. return [4, this.upstream.next()];
  36107. case 1:
  36108. return (t = n.sent()).done ? [2, !1] : (e = t.value, r = (0, _tfjsCore.env)().get("IS_BROWSER") ? this.decoder.decode(e, {
  36109. stream: !0
  36110. }) : this.decoder.write(Buffer.from(e.buffer)), this.outputQueue.push(r), [2, !0]);
  36111. }
  36112. });
  36113. });
  36114. }, e;
  36115. }(OneToManyIterator),
  36116. FileChunkIterator = function (t) {
  36117. function e(e, r) {
  36118. void 0 === r && (r = {});
  36119. var n = t.call(this) || this;
  36120. return n.file = e, n.options = r, _tfjsCore.util.assert(e instanceof Uint8Array || !!(0, _tfjsCore.env)().get("IS_BROWSER") && (e instanceof File || e instanceof Blob), function () {
  36121. return "FileChunkIterator only supports File, Blob and Uint8Array right now.";
  36122. }), n.offset = r.offset || 0, n.chunkSize = r.chunkSize || 1048576, n;
  36123. }
  36124. return __extends(e, t), e.prototype.summary = function () {
  36125. return "FileChunks " + this.file;
  36126. }, e.prototype.next = function () {
  36127. return __awaiter(this, void 0, void 0, function () {
  36128. var t,
  36129. e,
  36130. r = this;
  36131. return __generator(this, function (n) {
  36132. switch (n.label) {
  36133. case 0:
  36134. return this.offset >= (this.file instanceof Uint8Array ? this.file.byteLength : this.file.size) ? [2, {
  36135. value: null,
  36136. done: !0
  36137. }] : (t = new Promise(function (t, e) {
  36138. var n = r.offset + r.chunkSize;
  36139. if (r.file instanceof Uint8Array) t(new Uint8Array(r.file.slice(r.offset, n))); else {
  36140. var i = new FileReader();
  36141. i.onload = function (r) {
  36142. var n = i.result;
  36143. if (n instanceof ArrayBuffer && (n = new Uint8Array(n)), !(n instanceof Uint8Array)) return e(new TypeError("FileReader returned unknown type."));
  36144. t(n);
  36145. }, i.onabort = function (t) {
  36146. return e(new Error("Aborted"));
  36147. }, i.onerror = function (t) {
  36148. return e(new Error(t.type));
  36149. };
  36150. var o = r.file.slice(r.offset, n);
  36151. i.readAsArrayBuffer(o);
  36152. }
  36153. r.offset = n;
  36154. }), e = {}, [4, t]);
  36155. case 1:
  36156. return [2, (e.value = n.sent(), e.done = !1, e)];
  36157. }
  36158. });
  36159. });
  36160. }, e;
  36161. }(ByteChunkIterator);
  36162. exports.CSVDataset = CSVDataset;
  36163. exports.TextLineDataset = TextLineDataset;
  36164. function urlChunkIterator(t, e) {
  36165. return void 0 === e && (e = {}), __awaiter(this, void 0, void 0, function () {
  36166. var r, n, i, o, a;
  36167. return __generator(this, function (s) {
  36168. switch (s.label) {
  36169. case 0:
  36170. return "string" == typeof t ? r = t : (r = t.url, n = getRequestInitFromRequest(t)), [4, _tfjsCore.util.fetch(r, n)];
  36171. case 1:
  36172. return (i = s.sent()).ok ? (a = Uint8Array.bind, [4, i.arrayBuffer()]) : [3, 3];
  36173. case 2:
  36174. return o = new (a.apply(Uint8Array, [void 0, s.sent()]))(), [2, new FileChunkIterator(o, e)];
  36175. case 3:
  36176. throw new Error(i.statusText);
  36177. }
  36178. });
  36179. });
  36180. }
  36181. var getRequestInitFromRequest = function (t) {
  36182. return {
  36183. method: t.method,
  36184. headers: t.headers,
  36185. body: t.body,
  36186. mode: t.mode,
  36187. credentials: t.credentials,
  36188. cache: t.cache,
  36189. redirect: t.redirect,
  36190. referrer: t.referrer,
  36191. integrity: t.integrity
  36192. };
  36193. };
  36194. function isLocalPath(t) {
  36195. return "string" == typeof t && "file://" === t.substr(0, 7);
  36196. }
  36197. var FileDataSource = function (t) {
  36198. function e(e, r) {
  36199. void 0 === r && (r = {});
  36200. var n = t.call(this) || this;
  36201. return n.input = e, n.options = r, n;
  36202. }
  36203. return __extends(e, t), e.prototype.iterator = function () {
  36204. return __awaiter(this, void 0, void 0, function () {
  36205. var t;
  36206. return __generator(this, function (e) {
  36207. return isLocalPath(this.input) && (0, _tfjsCore.env)().get("IS_NODE") && (t = require("fs"), this.input = t.readFileSync(this.input.substr(7))), [2, new FileChunkIterator(this.input, this.options)];
  36208. });
  36209. });
  36210. }, e;
  36211. }(DataSource),
  36212. URLDataSource = function (t) {
  36213. function e(e, r) {
  36214. void 0 === r && (r = {});
  36215. var n = t.call(this) || this;
  36216. return n.url = e, n.fileOptions = r, n;
  36217. }
  36218. return __extends(e, t), e.prototype.iterator = function () {
  36219. return __awaiter(this, void 0, void 0, function () {
  36220. return __generator(this, function (t) {
  36221. return isLocalPath(this.url) ? [2, new FileDataSource(this.url, this.fileOptions).iterator()] : [2, urlChunkIterator(this.url, this.fileOptions)];
  36222. });
  36223. });
  36224. }, e;
  36225. }(DataSource);
  36226. exports.URLDataSource = URLDataSource;
  36227. exports.FileDataSource = FileDataSource;
  36228. function csv(t, e) {
  36229. return void 0 === e && (e = {}), new CSVDataset(new URLDataSource(t), e);
  36230. }
  36231. function func(t) {
  36232. var e = this,
  36233. r = iteratorFromFunction(t);
  36234. return datasetFromIteratorFn(function () {
  36235. return __awaiter(e, void 0, void 0, function () {
  36236. return __generator(this, function (t) {
  36237. return [2, r];
  36238. });
  36239. });
  36240. });
  36241. }
  36242. function generator(t) {
  36243. var e = this;
  36244. return datasetFromIteratorFn(function () {
  36245. return __awaiter(e, void 0, void 0, function () {
  36246. var e;
  36247. return __generator(this, function (r) {
  36248. switch (r.label) {
  36249. case 0:
  36250. return [4, t()];
  36251. case 1:
  36252. return e = r.sent(), [2, iteratorFromFunction(function () {
  36253. return e.next();
  36254. })];
  36255. }
  36256. });
  36257. });
  36258. });
  36259. }
  36260. function webcam(t, e) {
  36261. return __awaiter(this, void 0, void 0, function () {
  36262. return __generator(this, function (r) {
  36263. return [2, WebcamIterator.create(t, e)];
  36264. });
  36265. });
  36266. }
  36267. function microphone(t) {
  36268. return __awaiter(this, void 0, void 0, function () {
  36269. return __generator(this, function (e) {
  36270. return [2, MicrophoneIterator.create(t)];
  36271. });
  36272. });
  36273. }
  36274. var version = "1.3.1";
  36275. exports.version_data = version;
  36276. }, { "@tensorflow/tfjs-core": "node_modules/@tensorflow/tfjs-core/dist/tf-core.esm.js", "crypto": "node_modules/parcel-bundler/src/builtins/_empty.js", "string_decoder": "node_modules/parcel-bundler/src/builtins/_empty.js", "fs": "node_modules/parcel-bundler/src/builtins/_empty.js", "buffer": "node_modules/buffer/index.js" }], "node_modules/@tensorflow/tfjs/dist/tf.esm.js": [function (require, module, exports) {
  36277. "use strict";
  36278. Object.defineProperty(exports, "__esModule", {
  36279. value: true
  36280. });
  36281. var _exportNames = {
  36282. version: true,
  36283. data: true
  36284. };
  36285. exports.data = exports.version = void 0;
  36286. var _tfjsCore = require("@tensorflow/tfjs-core");
  36287. Object.keys(_tfjsCore).forEach(function (key) {
  36288. if (key === "default" || key === "__esModule") return;
  36289. if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  36290. Object.defineProperty(exports, key, {
  36291. enumerable: true,
  36292. get: function () {
  36293. return _tfjsCore[key];
  36294. }
  36295. });
  36296. });
  36297. var _tfjsLayers = require("@tensorflow/tfjs-layers");
  36298. Object.keys(_tfjsLayers).forEach(function (key) {
  36299. if (key === "default" || key === "__esModule") return;
  36300. if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  36301. Object.defineProperty(exports, key, {
  36302. enumerable: true,
  36303. get: function () {
  36304. return _tfjsLayers[key];
  36305. }
  36306. });
  36307. });
  36308. var _tfjsConverter = require("@tensorflow/tfjs-converter");
  36309. Object.keys(_tfjsConverter).forEach(function (key) {
  36310. if (key === "default" || key === "__esModule") return;
  36311. if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  36312. Object.defineProperty(exports, key, {
  36313. enumerable: true,
  36314. get: function () {
  36315. return _tfjsConverter[key];
  36316. }
  36317. });
  36318. });
  36319. var tfjsData = _interopRequireWildcard(require("@tensorflow/tfjs-data"));
  36320. exports.data = tfjsData;
  36321. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  36322. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  36323. // @tensorflow/tfjs Copyright 2019 Google
  36324. var version = "1.3.1",
  36325. version$1 = {
  36326. "tfjs-core": _tfjsCore.version_core,
  36327. "tfjs-data": tfjsData.version_data,
  36328. "tfjs-layers": _tfjsLayers.version_layers,
  36329. "tfjs-converter": _tfjsConverter.version_converter,
  36330. tfjs: version
  36331. };
  36332. exports.version = version$1;
  36333. }, { "@tensorflow/tfjs-core": "node_modules/@tensorflow/tfjs-core/dist/tf-core.esm.js", "@tensorflow/tfjs-layers": "node_modules/@tensorflow/tfjs-layers/dist/tf-layers.esm.js", "@tensorflow/tfjs-converter": "node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js", "@tensorflow/tfjs-data": "node_modules/@tensorflow/tfjs-data/dist/tf-data.esm.js" }], "demo_util.js": [function (require, module, exports) {
  36334. "use strict";
  36335. Object.defineProperty(exports, "__esModule", {
  36336. value: true
  36337. });
  36338. exports.isMobile = isMobile;
  36339. exports.updateTryResNetButtonDatGuiCss = updateTryResNetButtonDatGuiCss;
  36340. exports.toggleLoadingUI = toggleLoadingUI;
  36341. exports.drawPoint = drawPoint;
  36342. exports.drawSegment = drawSegment;
  36343. exports.drawSkeleton = drawSkeleton;
  36344. exports.drawKeypoints = drawKeypoints;
  36345. exports.drawBoundingBox = drawBoundingBox;
  36346. exports.renderToCanvas = renderToCanvas;
  36347. exports.renderImageToCanvas = renderImageToCanvas;
  36348. exports.drawHeatMapValues = drawHeatMapValues;
  36349. exports.drawOffsetVectors = drawOffsetVectors;
  36350. exports.tryResNetButtonText = exports.tryResNetButtonName = void 0;
  36351. var posenet = _interopRequireWildcard(require("@tensorflow-models/posenet"));
  36352. var tf = _interopRequireWildcard(require("@tensorflow/tfjs"));
  36353. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  36354. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  36355. /**
  36356. * @license
  36357. * Copyright 2019 Google LLC. All Rights Reserved.
  36358. * Licensed under the Apache License, Version 2.0 (the "License");
  36359. * you may not use this file except in compliance with the License.
  36360. * You may obtain a copy of the License at
  36361. *
  36362. * https://www.apache.org/licenses/LICENSE-2.0
  36363. *
  36364. * Unless required by applicable law or agreed to in writing, software
  36365. * distributed under the License is distributed on an "AS IS" BASIS,
  36366. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  36367. * See the License for the specific language governing permissions and
  36368. * limitations under the License.
  36369. * =============================================================================
  36370. */
  36371. const color = 'aqua';
  36372. const boundingBoxColor = 'red';
  36373. const lineWidth = 2;
  36374. const tryResNetButtonName = 'tryResNetButton';
  36375. exports.tryResNetButtonName = tryResNetButtonName;
  36376. const tryResNetButtonText = '[New] Try ResNet50';
  36377. exports.tryResNetButtonText = tryResNetButtonText;
  36378. const tryResNetButtonTextCss = 'width:100%;text-decoration:underline;';
  36379. const tryResNetButtonBackgroundCss = 'background:#e61d5f;';
  36380. function isAndroid() {
  36381. return /Android/i.test(navigator.userAgent);
  36382. }
  36383. function isiOS() {
  36384. return /iPhone|iPad|iPod/i.test(navigator.userAgent);
  36385. }
  36386. function isMobile() {
  36387. return isAndroid() || isiOS();
  36388. }
  36389. function setDatGuiPropertyCss(propertyText, liCssString, spanCssString = '') {
  36390. var spans = document.getElementsByClassName('property-name');
  36391. for (var i = 0; i < spans.length; i++) {
  36392. var text = spans[i].textContent || spans[i].innerText;
  36393. if (text == propertyText) {
  36394. spans[i].parentNode.parentNode.style = liCssString;
  36395. if (spanCssString !== '') {
  36396. spans[i].style = spanCssString;
  36397. }
  36398. }
  36399. }
  36400. }
  36401. function updateTryResNetButtonDatGuiCss() {
  36402. setDatGuiPropertyCss(tryResNetButtonText, tryResNetButtonBackgroundCss, tryResNetButtonTextCss);
  36403. }
  36404. /**
  36405. * Toggles between the loading UI and the main canvas UI.
  36406. */
  36407. function toggleLoadingUI(showLoadingUI, loadingDivId = 'loading', mainDivId = 'main') {
  36408. // if (showLoadingUI) {
  36409. // document.getElementById(loadingDivId).style.display = 'block';
  36410. // document.getElementById(mainDivId).style.display = 'none'; // document.getElementById('selectEvent').style.display = "none";
  36411. // } else {
  36412. // document.getElementById(loadingDivId).style.display = 'none';
  36413. // document.getElementById(mainDivId).style.display = 'block';
  36414. // document.getElementById('selectEvent').style.display = "block";
  36415. // }
  36416. }
  36417. function toTuple({
  36418. y,
  36419. x
  36420. }) {
  36421. return [y, x];
  36422. }
  36423. function drawPoint(ctx, y, x, r, color, name, num) {
  36424. ctx.beginPath();
  36425. ctx.arc(x, y, r, 0, 2 * Math.PI);
  36426. if (name === 'nose') {
  36427. // ctx.fillRect(0,0,100,100)
  36428. // ctx.strokeRect(x - 15, y - 135, 50, 50); // ctx.clearRect(x, y, 100, 100)
  36429. //ctx.font = '30px Verdana';
  36430. // ctx.fillText(num, x, y - 100);
  36431. } // canvas 显示文字
  36432. ctx.font = '12px Verdana';
  36433. // ctx.fillText(name, x, y);
  36434. ctx.fillStyle = color;
  36435. ctx.fill();
  36436. }
  36437. /**
  36438. * Draws a line on a canvas, i.e. a joint
  36439. */
  36440. function drawSegment([ay, ax], [by, bx], color, scale, ctx, left, right) {
  36441. ctx.beginPath();
  36442. if (ay != 0 && ax != 0 && by != 0 && bx != 0) {
  36443. ctx.moveTo(ax * scale, ay * scale);
  36444. ctx.lineTo(bx * scale, by * scale);
  36445. }
  36446. ctx.lineWidth = lineWidth;
  36447. ctx.strokeStyle = color; // canvas 写文字 坐标点相连
  36448. // ctx.fillText(left, ax * scale, ay * scale, bx * scale, by * scale);
  36449. // ctx.fillText(right, bx * scale, by * scale, ax * scale, ay * scale);
  36450. ctx.stroke();
  36451. }
  36452. /**
  36453. * Draws a pose skeleton by looking up all adjacent keypoints/joints
  36454. * 通过查找所有相邻的关键点/关节来绘制姿态骨架
  36455. */
  36456. function drawSkeleton(keypoints, minConfidence, ctx, scale = 1) {
  36457. const adjacentKeyPoints = posenet.getAdjacentKeyPoints(keypoints, minConfidence);
  36458. adjacentKeyPoints.forEach(keypoints => {
  36459. drawSegment(toTuple(keypoints[0].position), toTuple(keypoints[1].position), color, scale, ctx, keypoints[0].part, keypoints[1].part);
  36460. });
  36461. }
  36462. /**
  36463. * Draw pose keypoints onto a canvas
  36464. * 在画布上绘制姿态关键点
  36465. */
  36466. function drawKeypoints(keypoints, minConfidence, ctx, num, scale = 1) {
  36467. for (let i = 0; i < keypoints.length; i++) {
  36468. const keypoint = keypoints[i];
  36469. if (keypoint.score < minConfidence) {
  36470. continue;
  36471. }
  36472. const {
  36473. y,
  36474. x
  36475. } = keypoint.position;
  36476. drawPoint(ctx, y * scale, x * scale, 3, color, keypoint.part, num);
  36477. }
  36478. }
  36479. /**
  36480. * Draw the bounding box of a pose. For example, for a whole person standing
  36481. * in an image, the bounding box will begin at the nose and extend to one of
  36482. * ankles
  36483. * 画一个姿势的边界框。例如,一个完整的人站着
  36484. * 在一个图像中,边界框将从鼻子开始并延伸到其中一个
  36485. * 脚踝
  36486. */
  36487. function drawBoundingBox(keypoints, ctx) {
  36488. const boundingBox = posenet.getBoundingBox(keypoints);
  36489. ctx.rect(boundingBox.minX, boundingBox.minY, boundingBox.maxX - boundingBox.minX, boundingBox.maxY - boundingBox.minY);
  36490. ctx.fillText("Hello Canvas", ax * scale, ay * scale, bx * scale, by * scale);
  36491. ctx.strokeStyle = boundingBoxColor;
  36492. ctx.stroke();
  36493. }
  36494. /**
  36495. * Converts an arary of pixel data into an ImageData object
  36496. */
  36497. async function renderToCanvas(a, ctx) {
  36498. const [height, width] = a.shape;
  36499. const imageData = new ImageData(width, height);
  36500. const data = await a.data();
  36501. for (let i = 0; i < height * width; ++i) {
  36502. const j = i * 4;
  36503. const k = i * 3;
  36504. imageData.data[j + 0] = data[k + 0];
  36505. imageData.data[j + 1] = data[k + 1];
  36506. imageData.data[j + 2] = data[k + 2];
  36507. imageData.data[j + 3] = 255;
  36508. }
  36509. ctx.putImageData(imageData, 0, 0);
  36510. }
  36511. /**
  36512. * Draw an image on a canvas
  36513. */
  36514. function renderImageToCanvas(image, size, canvas) {
  36515. canvas.width = size[0];
  36516. canvas.height = size[1];
  36517. const ctx = canvas.getContext('2d');
  36518. ctx.drawImage(image, 0, 0);
  36519. }
  36520. /**
  36521. * Draw heatmap values, one of the model outputs, on to the canvas
  36522. * Read our blog post for a description of PoseNet's heatmap outputs
  36523. * https://medium.com/tensorflow/real-time-human-pose-estimation-in-the-browser-with-tensorflow-js-7dd0bc881cd5
  36524. */
  36525. function drawHeatMapValues(heatMapValues, outputStride, canvas) {
  36526. const ctx = canvas.getContext('2d');
  36527. const radius = 5;
  36528. const scaledValues = heatMapValues.mul(tf.scalar(outputStride, 'int32'));
  36529. drawPoints(ctx, scaledValues, radius, color);
  36530. }
  36531. /**
  36532. * Used by the drawHeatMapValues method to draw heatmap points on to
  36533. * the canvas
  36534. */
  36535. function drawPoints(ctx, points, radius, color) {
  36536. const data = points.buffer().values;
  36537. for (let i = 0; i < data.length; i += 2) {
  36538. const pointY = data[i];
  36539. const pointX = data[i + 1];
  36540. if (pointX !== 0 && pointY !== 0) {
  36541. ctx.beginPath();
  36542. ctx.arc(pointX, pointY, radius, 0, 2 * Math.PI);
  36543. ctx.fillStyle = color;
  36544. ctx.fill();
  36545. }
  36546. }
  36547. }
  36548. /**
  36549. * Draw offset vector values, one of the model outputs, on to the canvas
  36550. * Read our blog post for a description of PoseNet's offset vector outputs
  36551. * https://medium.com/tensorflow/real-time-human-pose-estimation-in-the-browser-with-tensorflow-js-7dd0bc881cd5
  36552. */
  36553. function drawOffsetVectors(heatMapValues, offsets, outputStride, scale = 1, ctx) {
  36554. const offsetPoints = posenet.singlePose.getOffsetPoints(heatMapValues, outputStride, offsets);
  36555. const heatmapData = heatMapValues.buffer().values;
  36556. const offsetPointsData = offsetPoints.buffer().values;
  36557. for (let i = 0; i < heatmapData.length; i += 2) {
  36558. const heatmapY = heatmapData[i] * outputStride;
  36559. const heatmapX = heatmapData[i + 1] * outputStride;
  36560. const offsetPointY = offsetPointsData[i];
  36561. const offsetPointX = offsetPointsData[i + 1];
  36562. drawSegment([heatmapY, heatmapX], [offsetPointY, offsetPointX], color, scale, ctx);
  36563. }
  36564. }
  36565. }, { "@tensorflow-models/posenet": "node_modules/@tensorflow-models/posenet/dist/posenet.esm.js", "@tensorflow/tfjs": "node_modules/@tensorflow/tfjs/dist/tf.esm.js" }], "camera.js": [function (require, module, exports) {
  36566. "use strict";
  36567. Object.defineProperty(exports, "__esModule", {
  36568. value: true
  36569. });
  36570. exports.bindPage = bindPage;
  36571. var posenet = _interopRequireWildcard(require("@tensorflow-models/posenet"));
  36572. var _dat = _interopRequireDefault(require("dat.gui"));
  36573. var _stats = _interopRequireDefault(require("stats.js"));
  36574. var _demo_util = require("./demo_util");
  36575. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  36576. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  36577. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  36578. /**
  36579. * @license
  36580. * Copyright 2019 Google LLC. All Rights Reserved.
  36581. * Licensed under the Apache License, Version 2.0 (the "License");
  36582. * you may not use this file except in compliance with the License.
  36583. * You may obtain a copy of the License at
  36584. *
  36585. * https://www.apache.org/licenses/LICENSE-2.0
  36586. *
  36587. * Unless required by applicable law or agreed to in writing, software
  36588. * distributed under the License is distributed on an "AS IS" BASIS,
  36589. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  36590. * See the License for the specific language governing permissions and
  36591. * limitations under the License.
  36592. * =============================================================================
  36593. */
  36594. const videoWidth = 400;
  36595. const videoHeight = 436;
  36596. let data = ""; // 识别姿势
  36597. let events = ""; // 用户的所有事件
  36598. let event = ""; // 用户选取事件的apikey
  36599. let users = new Object();
  36600. const stats = new _stats.default();
  36601. let recognition_posenet = "识别姿势"; // 识别姿势
  36602. let recognition_first = "识别第"; // 识别第几人
  36603. let people = "人";
  36604. // var lang = GLOBALS.lang
  36605. // let recognition_posenet = lang == 'en' ? 'Recognizing Posture' : lang == 'hant' ? "識別姿勢" : "识别姿势"; // 识别姿势
  36606. // let recognition_first = lang == 'en' ? 'Recognizing The' : lang == 'hant' ? "識別第" : "识别第"; // 识别第几人
  36607. // let people = lang == 'en' ? 'people' : lang == 'hant' ? "人" : "人";
  36608. let getEvent = false; // cloud 发送数据
  36609. function getEvents() {
  36610. let XHR = new XMLHttpRequest();
  36611. XHR.open('get', "https://api.cocorobo.cn/iot/data/apikey/".concat(window.user.data.apiKey, "/event/"));
  36612. XHR.send();
  36613. XHR.onreadystatechange = function () {
  36614. if (XHR.readyState == 4 && XHR.status == 200) {
  36615. events = JSON.parse(XHR.responseText);
  36616. getEvent = true;
  36617. event = JSON.parse(XHR.responseText)[0].eventAPIKey;
  36618. let str = "";
  36619. events.map(x => {
  36620. str = str + "<option value=".concat(x.eventAPIKey, ">").concat(x.name, "</option>");
  36621. });
  36622. document.getElementById('selectEvent').innerHTML = str;
  36623. }
  36624. };
  36625. }
  36626. /**
  36627. * Loads a the camera to be used in the demo
  36628. *
  36629. */
  36630. async function setupCamera() {
  36631. if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
  36632. throw new Error('Browser API navigator.mediaDevices.getUserMedia not available');
  36633. }
  36634. const video = document.getElementById('video');
  36635. video.width = videoWidth;
  36636. video.height = videoHeight;
  36637. const mobile = (0, _demo_util.isMobile)();
  36638. const stream = await navigator.mediaDevices.getUserMedia({
  36639. 'audio': false,
  36640. 'video': {
  36641. facingMode: 'user',
  36642. width: mobile ? undefined : videoWidth,
  36643. height: mobile ? undefined : videoHeight
  36644. }
  36645. });
  36646. video.srcObject = stream;
  36647. return new Promise(resolve => {
  36648. video.onloadedmetadata = () => {
  36649. resolve(video);
  36650. };
  36651. });
  36652. }
  36653. async function loadVideo() {
  36654. const video = await setupCamera();
  36655. video.play();
  36656. return video;
  36657. }
  36658. const defaultQuantBytes = 2;
  36659. const defaultMobileNetMultiplier = (0, _demo_util.isMobile)() ? 0.50 : 0.75;
  36660. const defaultMobileNetStride = 16;
  36661. const defaultMobileNetInputResolution = 500;
  36662. const defaultResNetMultiplier = 1.0;
  36663. const defaultResNetStride = 32;
  36664. const defaultResNetInputResolution = 250;
  36665. const guiState = {
  36666. algorithm: 'multi-pose',
  36667. input: {
  36668. architecture: 'MobileNetV1',
  36669. outputStride: defaultMobileNetStride,
  36670. inputResolution: defaultMobileNetInputResolution,
  36671. multiplier: defaultMobileNetMultiplier,
  36672. quantBytes: defaultQuantBytes
  36673. },
  36674. singlePoseDetection: {
  36675. minPoseConfidence: 0.1,
  36676. minPartConfidence: 0.5
  36677. },
  36678. multiPoseDetection: {
  36679. maxPoseDetections: 5,
  36680. minPoseConfidence: 0.15,
  36681. minPartConfidence: 0.1,
  36682. nmsRadius: 30.0
  36683. },
  36684. output: {
  36685. showVideo: true,
  36686. showSkeleton: true,
  36687. showPoints: true,
  36688. showBoundingBox: false
  36689. },
  36690. net: null
  36691. };
  36692. /**
  36693. * Sets up dat.gui controller on the top-right of the window
  36694. */
  36695. function setupGui(cameras, net) {
  36696. guiState.net = net;
  36697. if (cameras.length > 0) {
  36698. guiState.camera = cameras[0].deviceId;
  36699. }
  36700. const gui = new _dat.default.GUI({
  36701. width: 300
  36702. });
  36703. let architectureController = null;
  36704. guiState[_demo_util.tryResNetButtonName] = function () {
  36705. architectureController.setValue('ResNet50');
  36706. };
  36707. gui.add(guiState, _demo_util.tryResNetButtonName).name(_demo_util.tryResNetButtonText);
  36708. (0, _demo_util.updateTryResNetButtonDatGuiCss)(); // The single-pose algorithm is faster and simpler but requires only one
  36709. // person to be in the frame or results will be innaccurate. Multi-pose works
  36710. // for more than 1 person
  36711. const algorithmController = gui.add(guiState, 'algorithm', ['single-pose', 'multi-pose']); // The input parameters have the most effect on accuracy and speed of the
  36712. // network
  36713. let input = gui.addFolder('Input'); // Architecture: there are a few PoseNet models varying in size and
  36714. // accuracy. 1.01 is the largest, but will be the slowest. 0.50 is the
  36715. // fastest, but least accurate.
  36716. architectureController = input.add(guiState.input, 'architecture', ['MobileNetV1', 'ResNet50']);
  36717. guiState.architecture = guiState.input.architecture; // Input resolution: Internally, this parameter affects the height and width
  36718. // of the layers in the neural network. The higher the value of the input
  36719. // resolution the better the accuracy but slower the speed.
  36720. let inputResolutionController = null;
  36721. function updateGuiInputResolution(inputResolution, inputResolutionArray) {
  36722. if (inputResolutionController) {
  36723. inputResolutionController.remove();
  36724. }
  36725. guiState.inputResolution = inputResolution;
  36726. guiState.input.inputResolution = inputResolution;
  36727. inputResolutionController = input.add(guiState.input, 'inputResolution', inputResolutionArray);
  36728. inputResolutionController.onChange(function (inputResolution) {
  36729. guiState.changeToInputResolution = inputResolution;
  36730. });
  36731. } // Output stride: Internally, this parameter affects the height and width of
  36732. // the layers in the neural network. The lower the value of the output stride
  36733. // the higher the accuracy but slower the speed, the higher the value the
  36734. // faster the speed but lower the accuracy.
  36735. let outputStrideController = null;
  36736. function updateGuiOutputStride(outputStride, outputStrideArray) {
  36737. if (outputStrideController) {
  36738. outputStrideController.remove();
  36739. }
  36740. guiState.outputStride = outputStride;
  36741. guiState.input.outputStride = outputStride;
  36742. outputStrideController = input.add(guiState.input, 'outputStride', outputStrideArray);
  36743. outputStrideController.onChange(function (outputStride) {
  36744. guiState.changeToOutputStride = outputStride;
  36745. });
  36746. } // Multiplier: this parameter affects the number of feature map channels in
  36747. // the MobileNet. The higher the value, the higher the accuracy but slower the
  36748. // speed, the lower the value the faster the speed but lower the accuracy.
  36749. let multiplierController = null;
  36750. function updateGuiMultiplier(multiplier, multiplierArray) {
  36751. if (multiplierController) {
  36752. multiplierController.remove();
  36753. }
  36754. guiState.multiplier = multiplier;
  36755. guiState.input.multiplier = multiplier;
  36756. multiplierController = input.add(guiState.input, 'multiplier', multiplierArray);
  36757. multiplierController.onChange(function (multiplier) {
  36758. guiState.changeToMultiplier = multiplier;
  36759. });
  36760. } // QuantBytes: this parameter affects weight quantization in the ResNet50
  36761. // model. The available options are 1 byte, 2 bytes, and 4 bytes. The higher
  36762. // the value, the larger the model size and thus the longer the loading time,
  36763. // the lower the value, the shorter the loading time but lower the accuracy.
  36764. let quantBytesController = null;
  36765. function updateGuiQuantBytes(quantBytes, quantBytesArray) {
  36766. if (quantBytesController) {
  36767. quantBytesController.remove();
  36768. }
  36769. guiState.quantBytes = +quantBytes;
  36770. guiState.input.quantBytes = +quantBytes;
  36771. quantBytesController = input.add(guiState.input, 'quantBytes', quantBytesArray);
  36772. quantBytesController.onChange(function (quantBytes) {
  36773. guiState.changeToQuantBytes = +quantBytes;
  36774. });
  36775. }
  36776. function updateGui() {
  36777. if (guiState.input.architecture === 'MobileNetV1') {
  36778. updateGuiInputResolution(defaultMobileNetInputResolution, [200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800]);
  36779. updateGuiOutputStride(defaultMobileNetStride, [8, 16]);
  36780. updateGuiMultiplier(defaultMobileNetMultiplier, [0.50, 0.75, 1.0]);
  36781. } else {
  36782. // guiState.input.architecture === "ResNet50"
  36783. updateGuiInputResolution(defaultResNetInputResolution, [200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800]);
  36784. updateGuiOutputStride(defaultResNetStride, [32, 16]);
  36785. updateGuiMultiplier(defaultResNetMultiplier, [1.0]);
  36786. }
  36787. updateGuiQuantBytes(defaultQuantBytes, [1, 2, 4]);
  36788. }
  36789. updateGui();
  36790. input.open(); // Pose confidence: the overall confidence in the estimation of a person's
  36791. // pose (i.e. a person detected in a frame)
  36792. // Min part confidence: the confidence that a particular estimated keypoint
  36793. // position is accurate (i.e. the elbow's position)
  36794. let single = gui.addFolder('Single Pose Detection');
  36795. single.add(guiState.singlePoseDetection, 'minPoseConfidence', 0.0, 1.0);
  36796. single.add(guiState.singlePoseDetection, 'minPartConfidence', 0.0, 1.0);
  36797. let multi = gui.addFolder('Multi Pose Detection');
  36798. multi.add(guiState.multiPoseDetection, 'maxPoseDetections').min(1).max(20).step(1);
  36799. multi.add(guiState.multiPoseDetection, 'minPoseConfidence', 0.0, 1.0);
  36800. multi.add(guiState.multiPoseDetection, 'minPartConfidence', 0.0, 1.0); // nms Radius: controls the minimum distance between poses that are returned
  36801. // defaults to 20, which is probably fine for most use cases
  36802. multi.add(guiState.multiPoseDetection, 'nmsRadius').min(0.0).max(40.0);
  36803. multi.open();
  36804. let output = gui.addFolder('Output');
  36805. output.add(guiState.output, 'showVideo');
  36806. output.add(guiState.output, 'showSkeleton');
  36807. output.add(guiState.output, 'showPoints');
  36808. output.add(guiState.output, 'showBoundingBox');
  36809. output.open();
  36810. architectureController.onChange(function (architecture) {
  36811. // if architecture is ResNet50, then show ResNet50 options
  36812. updateGui();
  36813. guiState.changeToArchitecture = architecture;
  36814. });
  36815. algorithmController.onChange(function (value) {
  36816. switch (guiState.algorithm) {
  36817. case 'single-pose':
  36818. multi.close();
  36819. single.open();
  36820. break;
  36821. case 'multi-pose':
  36822. single.close();
  36823. multi.open();
  36824. break;
  36825. }
  36826. });
  36827. }
  36828. /**
  36829. * Sets up a frames per second panel on the top-left of the window
  36830. */
  36831. function setupFPS() {
  36832. stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom
  36833. // document.getElementById('main').appendChild(stats.dom);
  36834. }
  36835. /**
  36836. * Feeds an image to posenet to estimate poses - this is where the magic
  36837. * happens. This function loops with a requestAnimationFrame method.
  36838. * 实时监测姿态
  36839. */
  36840. function detectPoseInRealTime(video, net) {
  36841. const canvas = document.getElementById('output');
  36842. const ctx = canvas.getContext('2d'); // since images are being fed from a webcam, we want to feed in the
  36843. // original image and then just flip the keypoints' x coordinates. If instead
  36844. // we flip the image, then correcting left-right keypoint pairs requires a
  36845. // permutation on all the keypoints.
  36846. const flipPoseHorizontal = true;
  36847. canvas.width = videoWidth;
  36848. canvas.height = videoHeight;
  36849. async function poseDetectionFrame() {
  36850. if (guiState.changeToArchitecture) {
  36851. // Important to purge variables and free up GPU memory
  36852. guiState.net.dispose();
  36853. (0, _demo_util.toggleLoadingUI)(true);
  36854. guiState.net = await posenet.load({
  36855. architecture: guiState.changeToArchitecture,
  36856. outputStride: guiState.outputStride,
  36857. inputResolution: guiState.inputResolution,
  36858. multiplier: guiState.multiplier
  36859. });
  36860. (0, _demo_util.toggleLoadingUI)(false);
  36861. guiState.architecture = guiState.changeToArchitecture;
  36862. guiState.changeToArchitecture = null;
  36863. }
  36864. if (guiState.changeToMultiplier) {
  36865. guiState.net.dispose();
  36866. (0, _demo_util.toggleLoadingUI)(true);
  36867. guiState.net = await posenet.load({
  36868. architecture: guiState.architecture,
  36869. outputStride: guiState.outputStride,
  36870. inputResolution: guiState.inputResolution,
  36871. multiplier: +guiState.changeToMultiplier,
  36872. quantBytes: guiState.quantBytes
  36873. });
  36874. (0, _demo_util.toggleLoadingUI)(false);
  36875. guiState.multiplier = +guiState.changeToMultiplier;
  36876. guiState.changeToMultiplier = null;
  36877. }
  36878. if (guiState.changeToOutputStride) {
  36879. // Important to purge variables and free up GPU memory
  36880. guiState.net.dispose();
  36881. (0, _demo_util.toggleLoadingUI)(true);
  36882. guiState.net = await posenet.load({
  36883. architecture: guiState.architecture,
  36884. outputStride: +guiState.changeToOutputStride,
  36885. inputResolution: guiState.inputResolution,
  36886. multiplier: guiState.multiplier,
  36887. quantBytes: guiState.quantBytes
  36888. });
  36889. (0, _demo_util.toggleLoadingUI)(false);
  36890. guiState.outputStride = +guiState.changeToOutputStride;
  36891. guiState.changeToOutputStride = null;
  36892. }
  36893. if (guiState.changeToInputResolution) {
  36894. // Important to purge variables and free up GPU memory
  36895. guiState.net.dispose();
  36896. (0, _demo_util.toggleLoadingUI)(true);
  36897. guiState.net = await posenet.load({
  36898. architecture: guiState.architecture,
  36899. outputStride: guiState.outputStride,
  36900. inputResolution: +guiState.changeToInputResolution,
  36901. multiplier: guiState.multiplier,
  36902. quantBytes: guiState.quantBytes
  36903. });
  36904. (0, _demo_util.toggleLoadingUI)(false);
  36905. guiState.inputResolution = +guiState.changeToInputResolution;
  36906. guiState.changeToInputResolution = null;
  36907. }
  36908. if (guiState.changeToQuantBytes) {
  36909. // Important to purge variables and free up GPU memory
  36910. guiState.net.dispose();
  36911. (0, _demo_util.toggleLoadingUI)(true);
  36912. guiState.net = await posenet.load({
  36913. architecture: guiState.architecture,
  36914. outputStride: guiState.outputStride,
  36915. inputResolution: guiState.inputResolution,
  36916. multiplier: guiState.multiplier,
  36917. quantBytes: guiState.changeToQuantBytes
  36918. });
  36919. (0, _demo_util.toggleLoadingUI)(false);
  36920. guiState.quantBytes = guiState.changeToQuantBytes;
  36921. guiState.changeToQuantBytes = null;
  36922. } // Begin monitoring code for frames per second
  36923. stats.begin();
  36924. let poses = [];
  36925. let minPoseConfidence;
  36926. let minPartConfidence;
  36927. switch (guiState.algorithm) {
  36928. case 'single-pose':
  36929. const pose = await guiState.net.estimatePoses(video, {
  36930. flipHorizontal: flipPoseHorizontal,
  36931. decodingMethod: 'single-person'
  36932. });
  36933. poses = poses.concat(pose);
  36934. minPoseConfidence = +guiState.singlePoseDetection.minPoseConfidence;
  36935. minPartConfidence = +guiState.singlePoseDetection.minPartConfidence;
  36936. break;
  36937. case 'multi-pose':
  36938. let all_poses = await guiState.net.estimatePoses(video, {
  36939. flipHorizontal: flipPoseHorizontal,
  36940. decodingMethod: 'multi-person',
  36941. maxDetections: guiState.multiPoseDetection.maxPoseDetections,
  36942. scoreThreshold: guiState.multiPoseDetection.minPartConfidence,
  36943. nmsRadius: guiState.multiPoseDetection.nmsRadius
  36944. });
  36945. poses = poses.concat(all_poses);
  36946. minPoseConfidence = +guiState.multiPoseDetection.minPoseConfidence;
  36947. minPartConfidence = +guiState.multiPoseDetection.minPartConfidence;
  36948. break;
  36949. }
  36950. ctx.clearRect(0, 0, videoWidth, videoHeight);
  36951. if (guiState.output.showVideo) {
  36952. ctx.save();
  36953. ctx.scale(-1, 1);
  36954. ctx.translate(-videoWidth, 0);
  36955. ctx.drawImage(video, 0, 0, videoWidth, videoHeight);
  36956. ctx.restore();
  36957. } // For each pose (i.e. person) detected in an image, loop through the poses
  36958. // and draw the resulting skeleton and keypoints if over certain confidence
  36959. // scores
  36960. /** 姿态 判断
  36961. * 当左手腕和右手腕的高度 大于 左眼或者右眼时 -----手举高状态
  36962. * 右肘和右肩大致处于同一水平面且右手腕 大于 右肩 小于 ----- 敬礼
  36963. * 臀部距脚踝的距离略 约等于 膝盖到脚踝的距离 ---- 坐着
  36964. * 臀部距脚踝的距离略 约等于 膝盖到脚踝的距离 且 手腕与肘、肩在同一水平面 ---- 深蹲
  36965. * 双手腕 超过左右眼时 ------- 挥手
  36966. * 鼻子的垂直坐标小于双肩时 ------- 鞠躬
  36967. * 鼻子的平行坐标与脚踝的平行坐标相差较大时 -------- 摔倒
  36968. */
  36969. let count = 0; // 识别的人数
  36970. let Arr = []; // 获取所有的坐标点
  36971. let strs = ""; // 坐标点字符串
  36972. let status = ""; // 识别的姿势
  36973. poses.forEach(({
  36974. score,
  36975. keypoints
  36976. }) => {
  36977. if (score >= minPoseConfidence) {
  36978. keypoints.map(x => {
  36979. if (x.position.y > 436) {
  36980. x.position.y = 0;
  36981. x.position.x = 0;
  36982. }
  36983. if (x.position.x > 400) {
  36984. x.position.y = 0;
  36985. x.position.x = 0;
  36986. }
  36987. return x;
  36988. });
  36989. let nose = keypoints[0].position.y,
  36990. leftEye = keypoints[1].position.y,
  36991. rightEye = keypoints[2].position.y,
  36992. leftEar = keypoints[3].position.y,
  36993. rightEar = keypoints[4].position.y,
  36994. leftShoulder = keypoints[5].position.y,
  36995. rightShoulder = keypoints[6].position.y,
  36996. leftElbow = keypoints[7].position.y,
  36997. rightElbow = keypoints[8].position.y,
  36998. leftWrist = keypoints[9].position.y,
  36999. rightWrist = keypoints[10].position.y,
  37000. leftHip = keypoints[11].position.y,
  37001. rightHip = keypoints[12].position.y,
  37002. leftKnee = keypoints[13].position.y,
  37003. rightknee = keypoints[14].position.y,
  37004. leftAnkle = keypoints[15].position.y,
  37005. rightAnkle = keypoints[16].position.y;
  37006. let left_hip_knee = leftHip - leftAnkle; // 左臀距左脚踝的垂直距离
  37007. let left_right_hip_knee = leftHip - rightAnkle; // 左臀距右脚踝的垂直距离
  37008. let right_hip_knee = rightHip - rightAnkle; // 右臀距右脚踝的垂直距离
  37009. let right_left_hip_knee = rightHip - leftAnkle; // 右臀距左脚踝的垂直距离
  37010. let left_knee_ankle = leftKnee - leftAnkle; // 左膝盖距左脚踝的垂直距离
  37011. let left_right_knee_ankle = leftKnee - rightAnkle; // 左膝盖距右脚踝的垂直距离
  37012. let right_Knee_ankle = rightknee - rightAnkle; // 右膝盖距右脚踝的垂直距离
  37013. let right_left_knee_ankle = rightknee - leftAnkle; // 右膝盖距左脚踝的垂直距离
  37014. // 挥手
  37015. if ((leftEye > leftWrist || rightEye > leftWrist) && (leftShoulder > leftElbow || rightShoulder > leftElbow) && leftWrist != 0 && (leftEye > rightWrist || rightEye > rightWrist) && (leftShoulder > rightElbow || rightShoulder > rightElbow) && rightWrist != 0) {
  37016. // console.log('挥手wave');
  37017. status = "wave";
  37018. } else if ((leftEye > leftWrist || rightEye > leftWrist) && (leftShoulder > leftElbow || rightShoulder > leftElbow) && leftWrist != 0) {
  37019. // console.log('左手举高liftleft')
  37020. status = "liftleft";
  37021. } else if ((leftEye > rightWrist || rightEye > rightWrist) && (leftShoulder > rightElbow || rightShoulder > rightElbow) && rightWrist != 0) {
  37022. // console.log('右手举高liftright')
  37023. status = "liftright";
  37024. } else if (rightWrist != 0 && rightEye < rightWrist && rightWrist < rightShoulder && Math.abs(rightElbow - rightShoulder) < 10) {
  37025. // 敬礼
  37026. // console.log('敬礼salute')
  37027. status = "salute";
  37028. } else if ((nose > leftShoulder || nose > rightShoulder) && rightShoulder != 0 && leftShoulder != 0) {
  37029. // console.log('鞠躬bow');
  37030. status = "bow";
  37031. } else if (leftHip != 0 && leftAnkle != 0 && leftKnee != 0) {
  37032. if (Math.abs(left_hip_knee - left_knee_ankle) > 40 && Math.abs(right_hip_knee - right_Knee_ankle) > 40 && Math.abs(left_right_hip_knee - left_right_knee_ankle) > 40 && Math.abs(right_left_hip_knee - right_left_knee_ankle) > 40) {
  37033. // console.log('站立 stand')
  37034. status = "stand";
  37035. }
  37036. } // }
  37037. // 深蹲(squat)&& 坐着 sit
  37038. if (leftHip != 0 && leftAnkle != 0 && leftKnee != 0) {
  37039. if (Math.abs(left_hip_knee - left_knee_ankle) < 40 && Math.abs(right_hip_knee - right_Knee_ankle) < 40 && Math.abs(left_right_hip_knee - left_right_knee_ankle) < 40 && Math.abs(right_left_hip_knee - right_left_knee_ankle) < 40) {
  37040. if (Math.abs(leftHip - leftKnee) < 20 || Math.abs(rightHip - rightknee) < 20) {
  37041. // console.log('深蹲squat');
  37042. status = "squat";
  37043. } else {
  37044. // console.log('坐着状态sit')
  37045. status = "sit";
  37046. }
  37047. }
  37048. } // 摔倒(falldown)
  37049. if (keypoints[15].position.x !== 0 && keypoints[16].position.x) {
  37050. if (keypoints[15].position.x - keypoints[0].position.x > 80 || keypoints[16].position.x - keypoints[0].position.x > 80) {
  37051. // console.log('摔倒falldown');
  37052. status = "falldown";
  37053. }
  37054. }
  37055. data = {
  37056. posture: status
  37057. };
  37058. // 传送到cloud 的姿势
  37059. window.dataPosenet = data.posture
  37060. count++;
  37061. Arr = Arr.concat(keypoints.map(x => x.position));
  37062. users;
  37063. let str = "<div style=\"margin-bottom:10px;\"><span>".concat(recognition_first, "<i style=\"color:#2c4fcd;padding:0 5px;font-style:normal;\"> ").concat(count, " </i>").concat(people, "</span><span style=\"margin-left:20px\">").concat(recognition_posenet, "\uFF1A<i style=").concat(status ? "color:#2c4fcd;font-style:normal" : "color:#ccc;font-style:normal", ">").concat(status ? status : 'no result', "</i></span></div>"); // keypoints.map(x => {
  37064. // str = str + `<li>${x.part}:{${x.position.x.toFixed(2)},${x.position.y.toFixed(2)}}</li>`;
  37065. // return x;
  37066. // })
  37067. // str = str + '</ul></div>';
  37068. strs = strs + str;
  37069. if (guiState.output.showPoints) {
  37070. (0, _demo_util.drawKeypoints)(keypoints, minPartConfidence, ctx, count);
  37071. }
  37072. if (guiState.output.showSkeleton) {
  37073. (0, _demo_util.drawSkeleton)(keypoints, minPartConfidence, ctx);
  37074. }
  37075. if (guiState.output.showBoundingBox) {
  37076. (0, _demo_util.drawBoundingBox)(keypoints, ctx);
  37077. }
  37078. }
  37079. }); // 识别的人数
  37080. // document.getElementById('posenet_num').innerText = count; // 坐标点
  37081. document.getElementById('coordinate_points').innerHTML = strs; // End monitoring code for frames per second
  37082. stats.end();
  37083. requestAnimationFrame(poseDetectionFrame);
  37084. }
  37085. poseDetectionFrame();
  37086. }
  37087. /**
  37088. * Kicks off the demo by loading the posenet model, finding and loading
  37089. * available camera devices, and setting off the detectPoseInRealTime function.
  37090. */
  37091. async function bindPage() {
  37092. (0, _demo_util.toggleLoadingUI)(true);
  37093. const net = await posenet.load({
  37094. architecture: guiState.input.architecture,
  37095. outputStride: guiState.input.outputStride,
  37096. inputResolution: guiState.input.inputResolution,
  37097. multiplier: guiState.input.multiplier,
  37098. quantBytes: guiState.input.quantBytes
  37099. });
  37100. (0, _demo_util.toggleLoadingUI)(false);
  37101. let video;
  37102. try {
  37103. video = await loadVideo();
  37104. } catch (e) {
  37105. let info = document.getElementById('info');
  37106. info.textContent = 'this browser does not support video capture,' + 'or this device does not have a camera';
  37107. info.style.display = 'block';
  37108. throw e;
  37109. }
  37110. setupGui([], net);
  37111. setupFPS();
  37112. detectPoseInRealTime(video, net);
  37113. }
  37114. navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia; // kick off the demo
  37115. bindPage();
  37116. }, { "@tensorflow-models/posenet": "node_modules/@tensorflow-models/posenet/dist/posenet.esm.js", "dat.gui": "node_modules/dat.gui/build/dat.gui.module.js", "stats.js": "node_modules/stats.js/build/stats.min.js", "./demo_util": "demo_util.js" }]
  37117. }, {}, ["camera.js"], null)
  37118. //# sourceMappingURL=/camera.283d5d54.js.map