You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

opdef.cpy.inl 942 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675
  1. // clang-format off
  2. template<> struct EnumTrait<AdaptivePooling::Mode> {
  3. static constexpr const char *name = "AdaptivePooling.Mode";
  4. static constexpr std::underlying_type_t<AdaptivePooling::Mode> max = 3 - 1;
  5. };
  6. template<> PyTypeObject* EnumWrapper<AdaptivePooling::Mode>::type = nullptr;
  7. template<> const char*
  8. EnumWrapper<AdaptivePooling::Mode>::members[] = {"MAX", "AVERAGE", "AVERAGE_COUNT_EXCLUDE_PADDING"};
  9. template<> std::unordered_map<std::string, AdaptivePooling::Mode>
  10. EnumWrapper<AdaptivePooling::Mode>::mem2value = {{normalize_enum("MAX"), AdaptivePooling::Mode::MAX}, {normalize_enum("AVERAGE"), AdaptivePooling::Mode::AVERAGE}, {normalize_enum("AVERAGE_COUNT_EXCLUDE_PADDING"), AdaptivePooling::Mode::AVERAGE_COUNT_EXCLUDE_PADDING}};
  11. template<> PyObject* EnumWrapper<AdaptivePooling::Mode>::pyobj_insts[3] = {nullptr};
  12. void _init_py_AdaptivePooling_Mode(PyTypeObject& py_type) {
  13. auto& e_type = EnumWrapper<AdaptivePooling::Mode>::type;
  14. static PyMethodDef tp_methods[] = {
  15. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<AdaptivePooling::Mode>::py_dump, METH_NOARGS, NULL},
  16. {NULL} /* Sentinel */
  17. };
  18. static PyType_Slot slots[] = {
  19. {Py_tp_repr, (void*)EnumWrapper<AdaptivePooling::Mode>::py_repr},
  20. {Py_tp_richcompare, (void*)EnumWrapper<AdaptivePooling::Mode>::tp_richcompare},
  21. {Py_tp_methods, tp_methods},
  22. {0, NULL}
  23. };
  24. static PyType_Spec spec = {
  25. // name
  26. "megengine.core._imperative_rt.ops.AdaptivePooling.Mode",
  27. // basicsize
  28. sizeof(EnumWrapper<AdaptivePooling::Mode>),
  29. // itemsize
  30. 0,
  31. // flags
  32. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  33. // slots
  34. slots
  35. };
  36. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  37. mgb_assert(
  38. e_type->tp_setattro(
  39. reinterpret_cast<PyObject*>(e_type),
  40. py::cast("__name__").release().ptr(),
  41. py::cast("Mode").release().ptr()) >= 0);
  42. mgb_assert(
  43. e_type->tp_setattro(
  44. reinterpret_cast<PyObject*>(e_type),
  45. py::cast("__module__").release().ptr(),
  46. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  47. mgb_assert(
  48. e_type->tp_setattro(
  49. reinterpret_cast<PyObject*>(e_type),
  50. py::cast("__qualname__").release().ptr(),
  51. py::cast("AdaptivePooling.Mode").release().ptr()) >= 0);
  52. {
  53. PyObject* inst = e_type->tp_alloc(e_type, 0);
  54. reinterpret_cast<EnumWrapper<AdaptivePooling::Mode>*>(inst)->value = AdaptivePooling::Mode::MAX;
  55. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0);
  56. EnumWrapper<AdaptivePooling::Mode>::pyobj_insts[0] = inst;
  57. }{
  58. PyObject* inst = e_type->tp_alloc(e_type, 0);
  59. reinterpret_cast<EnumWrapper<AdaptivePooling::Mode>*>(inst)->value = AdaptivePooling::Mode::AVERAGE;
  60. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AVERAGE", inst) >= 0);
  61. EnumWrapper<AdaptivePooling::Mode>::pyobj_insts[1] = inst;
  62. }{
  63. PyObject* inst = e_type->tp_alloc(e_type, 0);
  64. reinterpret_cast<EnumWrapper<AdaptivePooling::Mode>*>(inst)->value = AdaptivePooling::Mode::AVERAGE_COUNT_EXCLUDE_PADDING;
  65. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AVERAGE_COUNT_EXCLUDE_PADDING", inst) >= 0);
  66. EnumWrapper<AdaptivePooling::Mode>::pyobj_insts[2] = inst;
  67. }
  68. Py_INCREF(e_type);
  69. mgb_assert(PyDict_SetItemString(
  70. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  71. }
  72. template<> struct EnumTrait<AdaptivePooling::Format> {
  73. static constexpr const char *name = "AdaptivePooling.Format";
  74. static constexpr std::underlying_type_t<AdaptivePooling::Format> max = 18 - 1;
  75. };
  76. template<> PyTypeObject* EnumWrapper<AdaptivePooling::Format>::type = nullptr;
  77. template<> const char*
  78. EnumWrapper<AdaptivePooling::Format>::members[] = {"NCHW", "NHWC", "NHWCD4", "NCHW4", "NCHW8", "NCHW32", "NCHW88", "NCHW44", "NCHW44_DOT", "NCHW4_NCHW32", "NCHW32_NCHW4", "NCHW4_NCHW", "NHWC_NCHW", "NHWC_NCHW4_IC_SMALL", "NCHW_NCHW4_IC_SMALL", "CHWN4", "NCHW64", "NCHW4_NHWC"};
  79. template<> std::unordered_map<std::string, AdaptivePooling::Format>
  80. EnumWrapper<AdaptivePooling::Format>::mem2value = {{normalize_enum("NCHW"), AdaptivePooling::Format::NCHW}, {normalize_enum("NHWC"), AdaptivePooling::Format::NHWC}, {normalize_enum("NHWCD4"), AdaptivePooling::Format::NHWCD4}, {normalize_enum("NCHW4"), AdaptivePooling::Format::NCHW4}, {normalize_enum("NCHW8"), AdaptivePooling::Format::NCHW8}, {normalize_enum("NCHW32"), AdaptivePooling::Format::NCHW32}, {normalize_enum("NCHW88"), AdaptivePooling::Format::NCHW88}, {normalize_enum("NCHW44"), AdaptivePooling::Format::NCHW44}, {normalize_enum("NCHW44_DOT"), AdaptivePooling::Format::NCHW44_DOT}, {normalize_enum("NCHW4_NCHW32"), AdaptivePooling::Format::NCHW4_NCHW32}, {normalize_enum("NCHW32_NCHW4"), AdaptivePooling::Format::NCHW32_NCHW4}, {normalize_enum("NCHW4_NCHW"), AdaptivePooling::Format::NCHW4_NCHW}, {normalize_enum("NHWC_NCHW"), AdaptivePooling::Format::NHWC_NCHW}, {normalize_enum("NHWC_NCHW4_IC_SMALL"), AdaptivePooling::Format::NHWC_NCHW4_IC_SMALL}, {normalize_enum("NCHW_NCHW4_IC_SMALL"), AdaptivePooling::Format::NCHW_NCHW4_IC_SMALL}, {normalize_enum("CHWN4"), AdaptivePooling::Format::CHWN4}, {normalize_enum("NCHW64"), AdaptivePooling::Format::NCHW64}, {normalize_enum("NCHW4_NHWC"), AdaptivePooling::Format::NCHW4_NHWC}};
  81. template<> PyObject* EnumWrapper<AdaptivePooling::Format>::pyobj_insts[18] = {nullptr};
  82. void _init_py_AdaptivePooling_Format(PyTypeObject& py_type) {
  83. auto& e_type = EnumWrapper<AdaptivePooling::Format>::type;
  84. static PyMethodDef tp_methods[] = {
  85. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<AdaptivePooling::Format>::py_dump, METH_NOARGS, NULL},
  86. {NULL} /* Sentinel */
  87. };
  88. static PyType_Slot slots[] = {
  89. {Py_tp_repr, (void*)EnumWrapper<AdaptivePooling::Format>::py_repr},
  90. {Py_tp_richcompare, (void*)EnumWrapper<AdaptivePooling::Format>::tp_richcompare},
  91. {Py_tp_methods, tp_methods},
  92. {0, NULL}
  93. };
  94. static PyType_Spec spec = {
  95. // name
  96. "megengine.core._imperative_rt.ops.AdaptivePooling.Format",
  97. // basicsize
  98. sizeof(EnumWrapper<AdaptivePooling::Format>),
  99. // itemsize
  100. 0,
  101. // flags
  102. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  103. // slots
  104. slots
  105. };
  106. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  107. mgb_assert(
  108. e_type->tp_setattro(
  109. reinterpret_cast<PyObject*>(e_type),
  110. py::cast("__name__").release().ptr(),
  111. py::cast("Format").release().ptr()) >= 0);
  112. mgb_assert(
  113. e_type->tp_setattro(
  114. reinterpret_cast<PyObject*>(e_type),
  115. py::cast("__module__").release().ptr(),
  116. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  117. mgb_assert(
  118. e_type->tp_setattro(
  119. reinterpret_cast<PyObject*>(e_type),
  120. py::cast("__qualname__").release().ptr(),
  121. py::cast("AdaptivePooling.Format").release().ptr()) >= 0);
  122. {
  123. PyObject* inst = e_type->tp_alloc(e_type, 0);
  124. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW;
  125. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW", inst) >= 0);
  126. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[0] = inst;
  127. }{
  128. PyObject* inst = e_type->tp_alloc(e_type, 0);
  129. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NHWC;
  130. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC", inst) >= 0);
  131. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[1] = inst;
  132. }{
  133. PyObject* inst = e_type->tp_alloc(e_type, 0);
  134. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NHWCD4;
  135. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWCD4", inst) >= 0);
  136. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[2] = inst;
  137. }{
  138. PyObject* inst = e_type->tp_alloc(e_type, 0);
  139. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW4;
  140. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4", inst) >= 0);
  141. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[3] = inst;
  142. }{
  143. PyObject* inst = e_type->tp_alloc(e_type, 0);
  144. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW8;
  145. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW8", inst) >= 0);
  146. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[4] = inst;
  147. }{
  148. PyObject* inst = e_type->tp_alloc(e_type, 0);
  149. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW32;
  150. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW32", inst) >= 0);
  151. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[5] = inst;
  152. }{
  153. PyObject* inst = e_type->tp_alloc(e_type, 0);
  154. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW88;
  155. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW88", inst) >= 0);
  156. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[6] = inst;
  157. }{
  158. PyObject* inst = e_type->tp_alloc(e_type, 0);
  159. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW44;
  160. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW44", inst) >= 0);
  161. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[7] = inst;
  162. }{
  163. PyObject* inst = e_type->tp_alloc(e_type, 0);
  164. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW44_DOT;
  165. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW44_DOT", inst) >= 0);
  166. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[8] = inst;
  167. }{
  168. PyObject* inst = e_type->tp_alloc(e_type, 0);
  169. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW4_NCHW32;
  170. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NCHW32", inst) >= 0);
  171. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[9] = inst;
  172. }{
  173. PyObject* inst = e_type->tp_alloc(e_type, 0);
  174. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW32_NCHW4;
  175. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW32_NCHW4", inst) >= 0);
  176. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[10] = inst;
  177. }{
  178. PyObject* inst = e_type->tp_alloc(e_type, 0);
  179. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW4_NCHW;
  180. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NCHW", inst) >= 0);
  181. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[11] = inst;
  182. }{
  183. PyObject* inst = e_type->tp_alloc(e_type, 0);
  184. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NHWC_NCHW;
  185. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC_NCHW", inst) >= 0);
  186. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[12] = inst;
  187. }{
  188. PyObject* inst = e_type->tp_alloc(e_type, 0);
  189. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NHWC_NCHW4_IC_SMALL;
  190. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC_NCHW4_IC_SMALL", inst) >= 0);
  191. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[13] = inst;
  192. }{
  193. PyObject* inst = e_type->tp_alloc(e_type, 0);
  194. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW_NCHW4_IC_SMALL;
  195. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW_NCHW4_IC_SMALL", inst) >= 0);
  196. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[14] = inst;
  197. }{
  198. PyObject* inst = e_type->tp_alloc(e_type, 0);
  199. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::CHWN4;
  200. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CHWN4", inst) >= 0);
  201. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[15] = inst;
  202. }{
  203. PyObject* inst = e_type->tp_alloc(e_type, 0);
  204. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW64;
  205. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW64", inst) >= 0);
  206. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[16] = inst;
  207. }{
  208. PyObject* inst = e_type->tp_alloc(e_type, 0);
  209. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW4_NHWC;
  210. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NHWC", inst) >= 0);
  211. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[17] = inst;
  212. }
  213. Py_INCREF(e_type);
  214. mgb_assert(PyDict_SetItemString(
  215. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  216. }
  217. PyOpDefBegin(AdaptivePooling) // {
  218. static PyGetSetDef py_getsetters[];
  219. static PyMethodDef tp_methods[];
  220. static PyObject* getstate(PyObject* self, PyObject*) {
  221. auto& opdef = reinterpret_cast<PyOp(AdaptivePooling)*>(self)->inst();
  222. static_cast<void>(opdef);
  223. std::unordered_map<std::string, py::object> state {
  224. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  225. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  226. {"shape", serialization<decltype(opdef.shape)>::dump(opdef.shape)}
  227. };
  228. return py::cast(state).release().ptr();
  229. }
  230. static PyObject* setstate(PyObject* self, PyObject* args) {
  231. PyObject* dict = PyTuple_GetItem(args, 0);
  232. if (!dict) return NULL;
  233. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  234. auto& opdef = reinterpret_cast<PyOp(AdaptivePooling)*>(self)->inst();
  235. static_cast<void>(opdef);
  236. {
  237. auto&& iter = state.find("mode");
  238. if (iter != state.end()) {
  239. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  240. }
  241. }
  242. {
  243. auto&& iter = state.find("format");
  244. if (iter != state.end()) {
  245. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  246. }
  247. }
  248. {
  249. auto&& iter = state.find("shape");
  250. if (iter != state.end()) {
  251. opdef.shape = serialization<decltype(opdef.shape)>::load(iter->second);
  252. }
  253. }
  254. Py_RETURN_NONE;
  255. }
  256. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  257. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  258. static PyMethodDef py_init_methoddef;
  259. // };
  260. PyOpDefEnd(AdaptivePooling)
  261. int PyOp(AdaptivePooling)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  262. static const char* kwlist[] = {"mode", "format", "shape", "scope", NULL};
  263. PyObject *mode = NULL, *format = NULL, *shape = NULL, *scope = NULL;
  264. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &mode, &format, &shape, &scope))
  265. return -1;
  266. if (mode) {
  267. try {
  268. // TODO: remove this guard which is used for pybind11 implicit conversion
  269. py::detail::loader_life_support guard{};
  270. reinterpret_cast<PyOp(AdaptivePooling)*>(self)->inst().mode =
  271. py::cast<decltype(AdaptivePooling::mode)>(py::handle(mode));
  272. } CATCH_ALL(-1)
  273. }
  274. if (format) {
  275. try {
  276. // TODO: remove this guard which is used for pybind11 implicit conversion
  277. py::detail::loader_life_support guard{};
  278. reinterpret_cast<PyOp(AdaptivePooling)*>(self)->inst().format =
  279. py::cast<decltype(AdaptivePooling::format)>(py::handle(format));
  280. } CATCH_ALL(-1)
  281. }
  282. if (shape) {
  283. try {
  284. // TODO: remove this guard which is used for pybind11 implicit conversion
  285. py::detail::loader_life_support guard{};
  286. reinterpret_cast<PyOp(AdaptivePooling)*>(self)->inst().shape =
  287. py::cast<decltype(AdaptivePooling::shape)>(py::handle(shape));
  288. } CATCH_ALL(-1)
  289. }
  290. if (scope) {
  291. try {
  292. reinterpret_cast<PyOp(OpDef)*>(self)->op
  293. ->set_scope(py::cast<std::string>(py::handle(scope)));
  294. } CATCH_ALL(-1)
  295. }
  296. return 0;
  297. }
  298. PyGetSetDef PyOp(AdaptivePooling)::py_getsetters[] = {
  299. {const_cast<char*>("mode"), py_get_generic(AdaptivePooling, mode), py_set_generic(AdaptivePooling, mode), const_cast<char*>("mode"), NULL},
  300. {const_cast<char*>("format"), py_get_generic(AdaptivePooling, format), py_set_generic(AdaptivePooling, format), const_cast<char*>("format"), NULL},
  301. {const_cast<char*>("shape"), py_get_generic(AdaptivePooling, shape), py_set_generic(AdaptivePooling, shape), const_cast<char*>("shape"), NULL},
  302. {NULL} /* Sentinel */
  303. };
  304. PyMethodDef PyOp(AdaptivePooling)::tp_methods[] = {
  305. {const_cast<char*>("__getstate__"), PyOp(AdaptivePooling)::getstate, METH_NOARGS, "AdaptivePooling getstate"},
  306. {const_cast<char*>("__setstate__"), PyOp(AdaptivePooling)::setstate, METH_VARARGS, "AdaptivePooling setstate"},
  307. {NULL} /* Sentinel */
  308. };
  309. PyObject *PyOp(AdaptivePooling)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  310. if (PyOp(AdaptivePooling)::py_init(self, args, kwds) < 0) {
  311. return NULL;
  312. }
  313. Py_RETURN_NONE;
  314. }
  315. PyMethodDef PyOp(AdaptivePooling)::py_init_methoddef = {
  316. "__init__",
  317. (PyCFunction)PyOp(AdaptivePooling)::py_init_proxy,
  318. METH_VARARGS | METH_KEYWORDS,
  319. "__init__(self, mode: Union[str, Mode] = ..., format: Union[str, Format] = ..., shape: list[int] = ...) -> None\n"
  320. };
  321. void _init_py_AdaptivePooling(py::module m) {
  322. using py_op = PyOp(AdaptivePooling);
  323. auto& py_type = PyOpType(AdaptivePooling);
  324. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  325. py_type.tp_name = "megengine.core._imperative_rt.ops.AdaptivePooling";
  326. py_type.tp_basicsize = sizeof(PyOp(AdaptivePooling));
  327. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  328. py_type.tp_doc = "AdaptivePooling";
  329. py_type.tp_base = &PyOpType(OpDef);
  330. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  331. py_type.tp_new = py_new_generic<py_op>;
  332. py_type.tp_init = py_op::py_init;
  333. py_type.tp_methods = py_op::tp_methods;
  334. py_type.tp_getset = py_op::py_getsetters;
  335. py_type.tp_dict = PyDict_New();
  336. PyObject* descr = PyDescr_NewMethod(&PyOpType(AdaptivePooling), &PyOp(AdaptivePooling)::py_init_methoddef);
  337. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  338. mgb_assert(PyType_Ready(&py_type) >= 0);
  339. _init_py_AdaptivePooling_Mode(py_type);
  340. _init_py_AdaptivePooling_Format(py_type);
  341. PyType_Modified(&py_type);
  342. m.add_object("AdaptivePooling", reinterpret_cast<PyObject*>(&py_type));
  343. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(AdaptivePooling::typeinfo(), &py_type).second);
  344. }
  345. PyOpDefBegin(AddAxis) // {
  346. static PyGetSetDef py_getsetters[];
  347. static PyMethodDef tp_methods[];
  348. static PyObject* getstate(PyObject* self, PyObject*) {
  349. auto& opdef = reinterpret_cast<PyOp(AddAxis)*>(self)->inst();
  350. static_cast<void>(opdef);
  351. std::unordered_map<std::string, py::object> state {
  352. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)}
  353. };
  354. return py::cast(state).release().ptr();
  355. }
  356. static PyObject* setstate(PyObject* self, PyObject* args) {
  357. PyObject* dict = PyTuple_GetItem(args, 0);
  358. if (!dict) return NULL;
  359. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  360. auto& opdef = reinterpret_cast<PyOp(AddAxis)*>(self)->inst();
  361. static_cast<void>(opdef);
  362. {
  363. auto&& iter = state.find("axis");
  364. if (iter != state.end()) {
  365. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  366. }
  367. }
  368. Py_RETURN_NONE;
  369. }
  370. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  371. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  372. static PyMethodDef py_init_methoddef;
  373. // };
  374. PyOpDefEnd(AddAxis)
  375. int PyOp(AddAxis)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  376. static const char* kwlist[] = {"axis", "scope", NULL};
  377. PyObject *axis = NULL, *scope = NULL;
  378. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &axis, &scope))
  379. return -1;
  380. if (axis) {
  381. try {
  382. // TODO: remove this guard which is used for pybind11 implicit conversion
  383. py::detail::loader_life_support guard{};
  384. reinterpret_cast<PyOp(AddAxis)*>(self)->inst().axis =
  385. py::cast<decltype(AddAxis::axis)>(py::handle(axis));
  386. } CATCH_ALL(-1)
  387. }
  388. if (scope) {
  389. try {
  390. reinterpret_cast<PyOp(OpDef)*>(self)->op
  391. ->set_scope(py::cast<std::string>(py::handle(scope)));
  392. } CATCH_ALL(-1)
  393. }
  394. return 0;
  395. }
  396. PyGetSetDef PyOp(AddAxis)::py_getsetters[] = {
  397. {const_cast<char*>("axis"), py_get_generic(AddAxis, axis), py_set_generic(AddAxis, axis), const_cast<char*>("axis"), NULL},
  398. {NULL} /* Sentinel */
  399. };
  400. PyMethodDef PyOp(AddAxis)::tp_methods[] = {
  401. {const_cast<char*>("__getstate__"), PyOp(AddAxis)::getstate, METH_NOARGS, "AddAxis getstate"},
  402. {const_cast<char*>("__setstate__"), PyOp(AddAxis)::setstate, METH_VARARGS, "AddAxis setstate"},
  403. {NULL} /* Sentinel */
  404. };
  405. PyObject *PyOp(AddAxis)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  406. if (PyOp(AddAxis)::py_init(self, args, kwds) < 0) {
  407. return NULL;
  408. }
  409. Py_RETURN_NONE;
  410. }
  411. PyMethodDef PyOp(AddAxis)::py_init_methoddef = {
  412. "__init__",
  413. (PyCFunction)PyOp(AddAxis)::py_init_proxy,
  414. METH_VARARGS | METH_KEYWORDS,
  415. "__init__(self, axis: list[int] = ...) -> None\n"
  416. };
  417. void _init_py_AddAxis(py::module m) {
  418. using py_op = PyOp(AddAxis);
  419. auto& py_type = PyOpType(AddAxis);
  420. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  421. py_type.tp_name = "megengine.core._imperative_rt.ops.AddAxis";
  422. py_type.tp_basicsize = sizeof(PyOp(AddAxis));
  423. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  424. py_type.tp_doc = "AddAxis";
  425. py_type.tp_base = &PyOpType(OpDef);
  426. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  427. py_type.tp_new = py_new_generic<py_op>;
  428. py_type.tp_init = py_op::py_init;
  429. py_type.tp_methods = py_op::tp_methods;
  430. py_type.tp_getset = py_op::py_getsetters;
  431. py_type.tp_dict = PyDict_New();
  432. PyObject* descr = PyDescr_NewMethod(&PyOpType(AddAxis), &PyOp(AddAxis)::py_init_methoddef);
  433. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  434. mgb_assert(PyType_Ready(&py_type) >= 0);
  435. PyType_Modified(&py_type);
  436. m.add_object("AddAxis", reinterpret_cast<PyObject*>(&py_type));
  437. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(AddAxis::typeinfo(), &py_type).second);
  438. }
  439. PyOpDefBegin(Argmax) // {
  440. static PyGetSetDef py_getsetters[];
  441. static PyMethodDef tp_methods[];
  442. static PyObject* getstate(PyObject* self, PyObject*) {
  443. auto& opdef = reinterpret_cast<PyOp(Argmax)*>(self)->inst();
  444. static_cast<void>(opdef);
  445. std::unordered_map<std::string, py::object> state {
  446. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)}
  447. };
  448. return py::cast(state).release().ptr();
  449. }
  450. static PyObject* setstate(PyObject* self, PyObject* args) {
  451. PyObject* dict = PyTuple_GetItem(args, 0);
  452. if (!dict) return NULL;
  453. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  454. auto& opdef = reinterpret_cast<PyOp(Argmax)*>(self)->inst();
  455. static_cast<void>(opdef);
  456. {
  457. auto&& iter = state.find("axis");
  458. if (iter != state.end()) {
  459. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  460. }
  461. }
  462. Py_RETURN_NONE;
  463. }
  464. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  465. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  466. static PyMethodDef py_init_methoddef;
  467. // };
  468. PyOpDefEnd(Argmax)
  469. int PyOp(Argmax)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  470. static const char* kwlist[] = {"axis", "scope", NULL};
  471. PyObject *axis = NULL, *scope = NULL;
  472. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &axis, &scope))
  473. return -1;
  474. if (axis) {
  475. try {
  476. // TODO: remove this guard which is used for pybind11 implicit conversion
  477. py::detail::loader_life_support guard{};
  478. reinterpret_cast<PyOp(Argmax)*>(self)->inst().axis =
  479. py::cast<decltype(Argmax::axis)>(py::handle(axis));
  480. } CATCH_ALL(-1)
  481. }
  482. if (scope) {
  483. try {
  484. reinterpret_cast<PyOp(OpDef)*>(self)->op
  485. ->set_scope(py::cast<std::string>(py::handle(scope)));
  486. } CATCH_ALL(-1)
  487. }
  488. return 0;
  489. }
  490. PyGetSetDef PyOp(Argmax)::py_getsetters[] = {
  491. {const_cast<char*>("axis"), py_get_generic(Argmax, axis), py_set_generic(Argmax, axis), const_cast<char*>("axis"), NULL},
  492. {NULL} /* Sentinel */
  493. };
  494. PyMethodDef PyOp(Argmax)::tp_methods[] = {
  495. {const_cast<char*>("__getstate__"), PyOp(Argmax)::getstate, METH_NOARGS, "Argmax getstate"},
  496. {const_cast<char*>("__setstate__"), PyOp(Argmax)::setstate, METH_VARARGS, "Argmax setstate"},
  497. {NULL} /* Sentinel */
  498. };
  499. PyObject *PyOp(Argmax)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  500. if (PyOp(Argmax)::py_init(self, args, kwds) < 0) {
  501. return NULL;
  502. }
  503. Py_RETURN_NONE;
  504. }
  505. PyMethodDef PyOp(Argmax)::py_init_methoddef = {
  506. "__init__",
  507. (PyCFunction)PyOp(Argmax)::py_init_proxy,
  508. METH_VARARGS | METH_KEYWORDS,
  509. "__init__(self, axis: int = ...) -> None\n"
  510. };
  511. void _init_py_Argmax(py::module m) {
  512. using py_op = PyOp(Argmax);
  513. auto& py_type = PyOpType(Argmax);
  514. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  515. py_type.tp_name = "megengine.core._imperative_rt.ops.Argmax";
  516. py_type.tp_basicsize = sizeof(PyOp(Argmax));
  517. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  518. py_type.tp_doc = "Argmax";
  519. py_type.tp_base = &PyOpType(OpDef);
  520. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  521. py_type.tp_new = py_new_generic<py_op>;
  522. py_type.tp_init = py_op::py_init;
  523. py_type.tp_methods = py_op::tp_methods;
  524. py_type.tp_getset = py_op::py_getsetters;
  525. py_type.tp_dict = PyDict_New();
  526. PyObject* descr = PyDescr_NewMethod(&PyOpType(Argmax), &PyOp(Argmax)::py_init_methoddef);
  527. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  528. mgb_assert(PyType_Ready(&py_type) >= 0);
  529. PyType_Modified(&py_type);
  530. m.add_object("Argmax", reinterpret_cast<PyObject*>(&py_type));
  531. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Argmax::typeinfo(), &py_type).second);
  532. }
  533. PyOpDefBegin(Argmin) // {
  534. static PyGetSetDef py_getsetters[];
  535. static PyMethodDef tp_methods[];
  536. static PyObject* getstate(PyObject* self, PyObject*) {
  537. auto& opdef = reinterpret_cast<PyOp(Argmin)*>(self)->inst();
  538. static_cast<void>(opdef);
  539. std::unordered_map<std::string, py::object> state {
  540. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)}
  541. };
  542. return py::cast(state).release().ptr();
  543. }
  544. static PyObject* setstate(PyObject* self, PyObject* args) {
  545. PyObject* dict = PyTuple_GetItem(args, 0);
  546. if (!dict) return NULL;
  547. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  548. auto& opdef = reinterpret_cast<PyOp(Argmin)*>(self)->inst();
  549. static_cast<void>(opdef);
  550. {
  551. auto&& iter = state.find("axis");
  552. if (iter != state.end()) {
  553. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  554. }
  555. }
  556. Py_RETURN_NONE;
  557. }
  558. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  559. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  560. static PyMethodDef py_init_methoddef;
  561. // };
  562. PyOpDefEnd(Argmin)
  563. int PyOp(Argmin)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  564. static const char* kwlist[] = {"axis", "scope", NULL};
  565. PyObject *axis = NULL, *scope = NULL;
  566. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &axis, &scope))
  567. return -1;
  568. if (axis) {
  569. try {
  570. // TODO: remove this guard which is used for pybind11 implicit conversion
  571. py::detail::loader_life_support guard{};
  572. reinterpret_cast<PyOp(Argmin)*>(self)->inst().axis =
  573. py::cast<decltype(Argmin::axis)>(py::handle(axis));
  574. } CATCH_ALL(-1)
  575. }
  576. if (scope) {
  577. try {
  578. reinterpret_cast<PyOp(OpDef)*>(self)->op
  579. ->set_scope(py::cast<std::string>(py::handle(scope)));
  580. } CATCH_ALL(-1)
  581. }
  582. return 0;
  583. }
  584. PyGetSetDef PyOp(Argmin)::py_getsetters[] = {
  585. {const_cast<char*>("axis"), py_get_generic(Argmin, axis), py_set_generic(Argmin, axis), const_cast<char*>("axis"), NULL},
  586. {NULL} /* Sentinel */
  587. };
  588. PyMethodDef PyOp(Argmin)::tp_methods[] = {
  589. {const_cast<char*>("__getstate__"), PyOp(Argmin)::getstate, METH_NOARGS, "Argmin getstate"},
  590. {const_cast<char*>("__setstate__"), PyOp(Argmin)::setstate, METH_VARARGS, "Argmin setstate"},
  591. {NULL} /* Sentinel */
  592. };
  593. PyObject *PyOp(Argmin)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  594. if (PyOp(Argmin)::py_init(self, args, kwds) < 0) {
  595. return NULL;
  596. }
  597. Py_RETURN_NONE;
  598. }
  599. PyMethodDef PyOp(Argmin)::py_init_methoddef = {
  600. "__init__",
  601. (PyCFunction)PyOp(Argmin)::py_init_proxy,
  602. METH_VARARGS | METH_KEYWORDS,
  603. "__init__(self, axis: int = ...) -> None\n"
  604. };
  605. void _init_py_Argmin(py::module m) {
  606. using py_op = PyOp(Argmin);
  607. auto& py_type = PyOpType(Argmin);
  608. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  609. py_type.tp_name = "megengine.core._imperative_rt.ops.Argmin";
  610. py_type.tp_basicsize = sizeof(PyOp(Argmin));
  611. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  612. py_type.tp_doc = "Argmin";
  613. py_type.tp_base = &PyOpType(OpDef);
  614. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  615. py_type.tp_new = py_new_generic<py_op>;
  616. py_type.tp_init = py_op::py_init;
  617. py_type.tp_methods = py_op::tp_methods;
  618. py_type.tp_getset = py_op::py_getsetters;
  619. py_type.tp_dict = PyDict_New();
  620. PyObject* descr = PyDescr_NewMethod(&PyOpType(Argmin), &PyOp(Argmin)::py_init_methoddef);
  621. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  622. mgb_assert(PyType_Ready(&py_type) >= 0);
  623. PyType_Modified(&py_type);
  624. m.add_object("Argmin", reinterpret_cast<PyObject*>(&py_type));
  625. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Argmin::typeinfo(), &py_type).second);
  626. }
  627. template<> struct EnumTrait<Argsort::Order> {
  628. static constexpr const char *name = "Argsort.Order";
  629. static constexpr std::underlying_type_t<Argsort::Order> max = 2 - 1;
  630. };
  631. template<> PyTypeObject* EnumWrapper<Argsort::Order>::type = nullptr;
  632. template<> const char*
  633. EnumWrapper<Argsort::Order>::members[] = {"ASCENDING", "DESCENDING"};
  634. template<> std::unordered_map<std::string, Argsort::Order>
  635. EnumWrapper<Argsort::Order>::mem2value = {{normalize_enum("ASCENDING"), Argsort::Order::ASCENDING}, {normalize_enum("DESCENDING"), Argsort::Order::DESCENDING}};
  636. template<> PyObject* EnumWrapper<Argsort::Order>::pyobj_insts[2] = {nullptr};
  637. void _init_py_Argsort_Order(PyTypeObject& py_type) {
  638. auto& e_type = EnumWrapper<Argsort::Order>::type;
  639. static PyMethodDef tp_methods[] = {
  640. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Argsort::Order>::py_dump, METH_NOARGS, NULL},
  641. {NULL} /* Sentinel */
  642. };
  643. static PyType_Slot slots[] = {
  644. {Py_tp_repr, (void*)EnumWrapper<Argsort::Order>::py_repr},
  645. {Py_tp_richcompare, (void*)EnumWrapper<Argsort::Order>::tp_richcompare},
  646. {Py_tp_methods, tp_methods},
  647. {0, NULL}
  648. };
  649. static PyType_Spec spec = {
  650. // name
  651. "megengine.core._imperative_rt.ops.Argsort.Order",
  652. // basicsize
  653. sizeof(EnumWrapper<Argsort::Order>),
  654. // itemsize
  655. 0,
  656. // flags
  657. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  658. // slots
  659. slots
  660. };
  661. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  662. mgb_assert(
  663. e_type->tp_setattro(
  664. reinterpret_cast<PyObject*>(e_type),
  665. py::cast("__name__").release().ptr(),
  666. py::cast("Order").release().ptr()) >= 0);
  667. mgb_assert(
  668. e_type->tp_setattro(
  669. reinterpret_cast<PyObject*>(e_type),
  670. py::cast("__module__").release().ptr(),
  671. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  672. mgb_assert(
  673. e_type->tp_setattro(
  674. reinterpret_cast<PyObject*>(e_type),
  675. py::cast("__qualname__").release().ptr(),
  676. py::cast("Argsort.Order").release().ptr()) >= 0);
  677. {
  678. PyObject* inst = e_type->tp_alloc(e_type, 0);
  679. reinterpret_cast<EnumWrapper<Argsort::Order>*>(inst)->value = Argsort::Order::ASCENDING;
  680. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ASCENDING", inst) >= 0);
  681. EnumWrapper<Argsort::Order>::pyobj_insts[0] = inst;
  682. }{
  683. PyObject* inst = e_type->tp_alloc(e_type, 0);
  684. reinterpret_cast<EnumWrapper<Argsort::Order>*>(inst)->value = Argsort::Order::DESCENDING;
  685. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DESCENDING", inst) >= 0);
  686. EnumWrapper<Argsort::Order>::pyobj_insts[1] = inst;
  687. }
  688. Py_INCREF(e_type);
  689. mgb_assert(PyDict_SetItemString(
  690. py_type.tp_dict, "Order", reinterpret_cast<PyObject*>(e_type)) >= 0);
  691. }
  692. PyOpDefBegin(Argsort) // {
  693. static PyGetSetDef py_getsetters[];
  694. static PyMethodDef tp_methods[];
  695. static PyObject* getstate(PyObject* self, PyObject*) {
  696. auto& opdef = reinterpret_cast<PyOp(Argsort)*>(self)->inst();
  697. static_cast<void>(opdef);
  698. std::unordered_map<std::string, py::object> state {
  699. {"order", serialization<decltype(opdef.order)>::dump(opdef.order)}
  700. };
  701. return py::cast(state).release().ptr();
  702. }
  703. static PyObject* setstate(PyObject* self, PyObject* args) {
  704. PyObject* dict = PyTuple_GetItem(args, 0);
  705. if (!dict) return NULL;
  706. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  707. auto& opdef = reinterpret_cast<PyOp(Argsort)*>(self)->inst();
  708. static_cast<void>(opdef);
  709. {
  710. auto&& iter = state.find("order");
  711. if (iter != state.end()) {
  712. opdef.order = serialization<decltype(opdef.order)>::load(iter->second);
  713. }
  714. }
  715. Py_RETURN_NONE;
  716. }
  717. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  718. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  719. static PyMethodDef py_init_methoddef;
  720. // };
  721. PyOpDefEnd(Argsort)
  722. int PyOp(Argsort)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  723. static const char* kwlist[] = {"order", "scope", NULL};
  724. PyObject *order = NULL, *scope = NULL;
  725. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &order, &scope))
  726. return -1;
  727. if (order) {
  728. try {
  729. // TODO: remove this guard which is used for pybind11 implicit conversion
  730. py::detail::loader_life_support guard{};
  731. reinterpret_cast<PyOp(Argsort)*>(self)->inst().order =
  732. py::cast<decltype(Argsort::order)>(py::handle(order));
  733. } CATCH_ALL(-1)
  734. }
  735. if (scope) {
  736. try {
  737. reinterpret_cast<PyOp(OpDef)*>(self)->op
  738. ->set_scope(py::cast<std::string>(py::handle(scope)));
  739. } CATCH_ALL(-1)
  740. }
  741. return 0;
  742. }
  743. PyGetSetDef PyOp(Argsort)::py_getsetters[] = {
  744. {const_cast<char*>("order"), py_get_generic(Argsort, order), py_set_generic(Argsort, order), const_cast<char*>("order"), NULL},
  745. {NULL} /* Sentinel */
  746. };
  747. PyMethodDef PyOp(Argsort)::tp_methods[] = {
  748. {const_cast<char*>("__getstate__"), PyOp(Argsort)::getstate, METH_NOARGS, "Argsort getstate"},
  749. {const_cast<char*>("__setstate__"), PyOp(Argsort)::setstate, METH_VARARGS, "Argsort setstate"},
  750. {NULL} /* Sentinel */
  751. };
  752. PyObject *PyOp(Argsort)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  753. if (PyOp(Argsort)::py_init(self, args, kwds) < 0) {
  754. return NULL;
  755. }
  756. Py_RETURN_NONE;
  757. }
  758. PyMethodDef PyOp(Argsort)::py_init_methoddef = {
  759. "__init__",
  760. (PyCFunction)PyOp(Argsort)::py_init_proxy,
  761. METH_VARARGS | METH_KEYWORDS,
  762. "__init__(self, order: Union[str, Order] = ...) -> None\n"
  763. };
  764. void _init_py_Argsort(py::module m) {
  765. using py_op = PyOp(Argsort);
  766. auto& py_type = PyOpType(Argsort);
  767. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  768. py_type.tp_name = "megengine.core._imperative_rt.ops.Argsort";
  769. py_type.tp_basicsize = sizeof(PyOp(Argsort));
  770. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  771. py_type.tp_doc = "Argsort";
  772. py_type.tp_base = &PyOpType(OpDef);
  773. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  774. py_type.tp_new = py_new_generic<py_op>;
  775. py_type.tp_init = py_op::py_init;
  776. py_type.tp_methods = py_op::tp_methods;
  777. py_type.tp_getset = py_op::py_getsetters;
  778. py_type.tp_dict = PyDict_New();
  779. PyObject* descr = PyDescr_NewMethod(&PyOpType(Argsort), &PyOp(Argsort)::py_init_methoddef);
  780. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  781. mgb_assert(PyType_Ready(&py_type) >= 0);
  782. _init_py_Argsort_Order(py_type);
  783. PyType_Modified(&py_type);
  784. m.add_object("Argsort", reinterpret_cast<PyObject*>(&py_type));
  785. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Argsort::typeinfo(), &py_type).second);
  786. }
  787. PyOpDefBegin(AssertEqual) // {
  788. static PyGetSetDef py_getsetters[];
  789. static PyMethodDef tp_methods[];
  790. static PyObject* getstate(PyObject* self, PyObject*) {
  791. auto& opdef = reinterpret_cast<PyOp(AssertEqual)*>(self)->inst();
  792. static_cast<void>(opdef);
  793. std::unordered_map<std::string, py::object> state {
  794. {"maxerr", serialization<decltype(opdef.maxerr)>::dump(opdef.maxerr)},
  795. {"verbose", serialization<decltype(opdef.verbose)>::dump(opdef.verbose)}
  796. };
  797. return py::cast(state).release().ptr();
  798. }
  799. static PyObject* setstate(PyObject* self, PyObject* args) {
  800. PyObject* dict = PyTuple_GetItem(args, 0);
  801. if (!dict) return NULL;
  802. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  803. auto& opdef = reinterpret_cast<PyOp(AssertEqual)*>(self)->inst();
  804. static_cast<void>(opdef);
  805. {
  806. auto&& iter = state.find("maxerr");
  807. if (iter != state.end()) {
  808. opdef.maxerr = serialization<decltype(opdef.maxerr)>::load(iter->second);
  809. }
  810. }
  811. {
  812. auto&& iter = state.find("verbose");
  813. if (iter != state.end()) {
  814. opdef.verbose = serialization<decltype(opdef.verbose)>::load(iter->second);
  815. }
  816. }
  817. Py_RETURN_NONE;
  818. }
  819. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  820. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  821. static PyMethodDef py_init_methoddef;
  822. // };
  823. PyOpDefEnd(AssertEqual)
  824. int PyOp(AssertEqual)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  825. static const char* kwlist[] = {"maxerr", "verbose", "scope", NULL};
  826. PyObject *maxerr = NULL, *verbose = NULL, *scope = NULL;
  827. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &maxerr, &verbose, &scope))
  828. return -1;
  829. if (maxerr) {
  830. try {
  831. // TODO: remove this guard which is used for pybind11 implicit conversion
  832. py::detail::loader_life_support guard{};
  833. reinterpret_cast<PyOp(AssertEqual)*>(self)->inst().maxerr =
  834. py::cast<decltype(AssertEqual::maxerr)>(py::handle(maxerr));
  835. } CATCH_ALL(-1)
  836. }
  837. if (verbose) {
  838. try {
  839. // TODO: remove this guard which is used for pybind11 implicit conversion
  840. py::detail::loader_life_support guard{};
  841. reinterpret_cast<PyOp(AssertEqual)*>(self)->inst().verbose =
  842. py::cast<decltype(AssertEqual::verbose)>(py::handle(verbose));
  843. } CATCH_ALL(-1)
  844. }
  845. if (scope) {
  846. try {
  847. reinterpret_cast<PyOp(OpDef)*>(self)->op
  848. ->set_scope(py::cast<std::string>(py::handle(scope)));
  849. } CATCH_ALL(-1)
  850. }
  851. return 0;
  852. }
  853. PyGetSetDef PyOp(AssertEqual)::py_getsetters[] = {
  854. {const_cast<char*>("maxerr"), py_get_generic(AssertEqual, maxerr), py_set_generic(AssertEqual, maxerr), const_cast<char*>("maxerr"), NULL},
  855. {const_cast<char*>("verbose"), py_get_generic(AssertEqual, verbose), py_set_generic(AssertEqual, verbose), const_cast<char*>("verbose"), NULL},
  856. {NULL} /* Sentinel */
  857. };
  858. PyMethodDef PyOp(AssertEqual)::tp_methods[] = {
  859. {const_cast<char*>("__getstate__"), PyOp(AssertEqual)::getstate, METH_NOARGS, "AssertEqual getstate"},
  860. {const_cast<char*>("__setstate__"), PyOp(AssertEqual)::setstate, METH_VARARGS, "AssertEqual setstate"},
  861. {NULL} /* Sentinel */
  862. };
  863. PyObject *PyOp(AssertEqual)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  864. if (PyOp(AssertEqual)::py_init(self, args, kwds) < 0) {
  865. return NULL;
  866. }
  867. Py_RETURN_NONE;
  868. }
  869. PyMethodDef PyOp(AssertEqual)::py_init_methoddef = {
  870. "__init__",
  871. (PyCFunction)PyOp(AssertEqual)::py_init_proxy,
  872. METH_VARARGS | METH_KEYWORDS,
  873. "__init__(self, maxerr: float = ..., verbose: bool = ...) -> None\n"
  874. };
  875. void _init_py_AssertEqual(py::module m) {
  876. using py_op = PyOp(AssertEqual);
  877. auto& py_type = PyOpType(AssertEqual);
  878. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  879. py_type.tp_name = "megengine.core._imperative_rt.ops.AssertEqual";
  880. py_type.tp_basicsize = sizeof(PyOp(AssertEqual));
  881. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  882. py_type.tp_doc = "AssertEqual";
  883. py_type.tp_base = &PyOpType(OpDef);
  884. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  885. py_type.tp_new = py_new_generic<py_op>;
  886. py_type.tp_init = py_op::py_init;
  887. py_type.tp_methods = py_op::tp_methods;
  888. py_type.tp_getset = py_op::py_getsetters;
  889. py_type.tp_dict = PyDict_New();
  890. PyObject* descr = PyDescr_NewMethod(&PyOpType(AssertEqual), &PyOp(AssertEqual)::py_init_methoddef);
  891. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  892. mgb_assert(PyType_Ready(&py_type) >= 0);
  893. PyType_Modified(&py_type);
  894. m.add_object("AssertEqual", reinterpret_cast<PyObject*>(&py_type));
  895. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(AssertEqual::typeinfo(), &py_type).second);
  896. }
  897. PyOpDefBegin(AtlasRuntime) // {
  898. static PyGetSetDef py_getsetters[];
  899. static PyMethodDef tp_methods[];
  900. static PyObject* getstate(PyObject* self, PyObject*) {
  901. auto& opdef = reinterpret_cast<PyOp(AtlasRuntime)*>(self)->inst();
  902. static_cast<void>(opdef);
  903. std::unordered_map<std::string, py::object> state {
  904. {"buf", serialization<decltype(opdef.buf)>::dump(opdef.buf)},
  905. {"buf_size", serialization<decltype(opdef.buf_size)>::dump(opdef.buf_size)}
  906. };
  907. return py::cast(state).release().ptr();
  908. }
  909. static PyObject* setstate(PyObject* self, PyObject* args) {
  910. PyObject* dict = PyTuple_GetItem(args, 0);
  911. if (!dict) return NULL;
  912. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  913. auto& opdef = reinterpret_cast<PyOp(AtlasRuntime)*>(self)->inst();
  914. static_cast<void>(opdef);
  915. {
  916. auto&& iter = state.find("buf");
  917. if (iter != state.end()) {
  918. opdef.buf = serialization<decltype(opdef.buf)>::load(iter->second);
  919. }
  920. }
  921. {
  922. auto&& iter = state.find("buf_size");
  923. if (iter != state.end()) {
  924. opdef.buf_size = serialization<decltype(opdef.buf_size)>::load(iter->second);
  925. }
  926. }
  927. Py_RETURN_NONE;
  928. }
  929. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  930. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  931. static PyMethodDef py_init_methoddef;
  932. // };
  933. PyOpDefEnd(AtlasRuntime)
  934. int PyOp(AtlasRuntime)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  935. static const char* kwlist[] = {"buf", "buf_size", "scope", NULL};
  936. PyObject *buf = NULL, *buf_size = NULL, *scope = NULL;
  937. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &buf, &buf_size, &scope))
  938. return -1;
  939. if (buf) {
  940. try {
  941. // TODO: remove this guard which is used for pybind11 implicit conversion
  942. py::detail::loader_life_support guard{};
  943. reinterpret_cast<PyOp(AtlasRuntime)*>(self)->inst().buf =
  944. py::cast<decltype(AtlasRuntime::buf)>(py::handle(buf));
  945. } CATCH_ALL(-1)
  946. }
  947. if (buf_size) {
  948. try {
  949. // TODO: remove this guard which is used for pybind11 implicit conversion
  950. py::detail::loader_life_support guard{};
  951. reinterpret_cast<PyOp(AtlasRuntime)*>(self)->inst().buf_size =
  952. py::cast<decltype(AtlasRuntime::buf_size)>(py::handle(buf_size));
  953. } CATCH_ALL(-1)
  954. }
  955. if (scope) {
  956. try {
  957. reinterpret_cast<PyOp(OpDef)*>(self)->op
  958. ->set_scope(py::cast<std::string>(py::handle(scope)));
  959. } CATCH_ALL(-1)
  960. }
  961. return 0;
  962. }
  963. PyGetSetDef PyOp(AtlasRuntime)::py_getsetters[] = {
  964. {const_cast<char*>("buf"), py_get_generic(AtlasRuntime, buf), py_set_generic(AtlasRuntime, buf), const_cast<char*>("buf"), NULL},
  965. {const_cast<char*>("buf_size"), py_get_generic(AtlasRuntime, buf_size), py_set_generic(AtlasRuntime, buf_size), const_cast<char*>("buf_size"), NULL},
  966. {NULL} /* Sentinel */
  967. };
  968. PyMethodDef PyOp(AtlasRuntime)::tp_methods[] = {
  969. {const_cast<char*>("__getstate__"), PyOp(AtlasRuntime)::getstate, METH_NOARGS, "AtlasRuntime getstate"},
  970. {const_cast<char*>("__setstate__"), PyOp(AtlasRuntime)::setstate, METH_VARARGS, "AtlasRuntime setstate"},
  971. {NULL} /* Sentinel */
  972. };
  973. PyObject *PyOp(AtlasRuntime)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  974. if (PyOp(AtlasRuntime)::py_init(self, args, kwds) < 0) {
  975. return NULL;
  976. }
  977. Py_RETURN_NONE;
  978. }
  979. PyMethodDef PyOp(AtlasRuntime)::py_init_methoddef = {
  980. "__init__",
  981. (PyCFunction)PyOp(AtlasRuntime)::py_init_proxy,
  982. METH_VARARGS | METH_KEYWORDS,
  983. "__init__(self, buf: str = ..., buf_size: int = ...) -> None\n"
  984. };
  985. void _init_py_AtlasRuntime(py::module m) {
  986. using py_op = PyOp(AtlasRuntime);
  987. auto& py_type = PyOpType(AtlasRuntime);
  988. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  989. py_type.tp_name = "megengine.core._imperative_rt.ops.AtlasRuntime";
  990. py_type.tp_basicsize = sizeof(PyOp(AtlasRuntime));
  991. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  992. py_type.tp_doc = "AtlasRuntime";
  993. py_type.tp_base = &PyOpType(OpDef);
  994. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  995. py_type.tp_new = py_new_generic<py_op>;
  996. py_type.tp_init = py_op::py_init;
  997. py_type.tp_methods = py_op::tp_methods;
  998. py_type.tp_getset = py_op::py_getsetters;
  999. py_type.tp_dict = PyDict_New();
  1000. PyObject* descr = PyDescr_NewMethod(&PyOpType(AtlasRuntime), &PyOp(AtlasRuntime)::py_init_methoddef);
  1001. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  1002. mgb_assert(PyType_Ready(&py_type) >= 0);
  1003. PyType_Modified(&py_type);
  1004. m.add_object("AtlasRuntime", reinterpret_cast<PyObject*>(&py_type));
  1005. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(AtlasRuntime::typeinfo(), &py_type).second);
  1006. }
  1007. PyOpDefBegin(Barrier) // {
  1008. static PyGetSetDef py_getsetters[];
  1009. static PyMethodDef tp_methods[];
  1010. static PyObject* getstate(PyObject* self, PyObject*) {
  1011. auto& opdef = reinterpret_cast<PyOp(Barrier)*>(self)->inst();
  1012. static_cast<void>(opdef);
  1013. std::unordered_map<std::string, py::object> state {
  1014. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)},
  1015. {"nr_outputs", serialization<decltype(opdef.nr_outputs)>::dump(opdef.nr_outputs)}
  1016. };
  1017. return py::cast(state).release().ptr();
  1018. }
  1019. static PyObject* setstate(PyObject* self, PyObject* args) {
  1020. PyObject* dict = PyTuple_GetItem(args, 0);
  1021. if (!dict) return NULL;
  1022. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  1023. auto& opdef = reinterpret_cast<PyOp(Barrier)*>(self)->inst();
  1024. static_cast<void>(opdef);
  1025. {
  1026. auto&& iter = state.find("comp_node");
  1027. if (iter != state.end()) {
  1028. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  1029. }
  1030. }
  1031. {
  1032. auto&& iter = state.find("nr_outputs");
  1033. if (iter != state.end()) {
  1034. opdef.nr_outputs = serialization<decltype(opdef.nr_outputs)>::load(iter->second);
  1035. }
  1036. }
  1037. Py_RETURN_NONE;
  1038. }
  1039. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  1040. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  1041. static PyMethodDef py_init_methoddef;
  1042. // };
  1043. PyOpDefEnd(Barrier)
  1044. int PyOp(Barrier)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  1045. static const char* kwlist[] = {"comp_node", "nr_outputs", "scope", NULL};
  1046. PyObject *comp_node = NULL, *nr_outputs = NULL, *scope = NULL;
  1047. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &comp_node, &nr_outputs, &scope))
  1048. return -1;
  1049. if (comp_node) {
  1050. try {
  1051. // TODO: remove this guard which is used for pybind11 implicit conversion
  1052. py::detail::loader_life_support guard{};
  1053. reinterpret_cast<PyOp(Barrier)*>(self)->inst().comp_node =
  1054. py::cast<decltype(Barrier::comp_node)>(py::handle(comp_node));
  1055. } CATCH_ALL(-1)
  1056. }
  1057. if (nr_outputs) {
  1058. try {
  1059. // TODO: remove this guard which is used for pybind11 implicit conversion
  1060. py::detail::loader_life_support guard{};
  1061. reinterpret_cast<PyOp(Barrier)*>(self)->inst().nr_outputs =
  1062. py::cast<decltype(Barrier::nr_outputs)>(py::handle(nr_outputs));
  1063. } CATCH_ALL(-1)
  1064. }
  1065. if (scope) {
  1066. try {
  1067. reinterpret_cast<PyOp(OpDef)*>(self)->op
  1068. ->set_scope(py::cast<std::string>(py::handle(scope)));
  1069. } CATCH_ALL(-1)
  1070. }
  1071. return 0;
  1072. }
  1073. PyGetSetDef PyOp(Barrier)::py_getsetters[] = {
  1074. {const_cast<char*>("comp_node"), py_get_generic(Barrier, comp_node), py_set_generic(Barrier, comp_node), const_cast<char*>("comp_node"), NULL},
  1075. {const_cast<char*>("nr_outputs"), py_get_generic(Barrier, nr_outputs), py_set_generic(Barrier, nr_outputs), const_cast<char*>("nr_outputs"), NULL},
  1076. {NULL} /* Sentinel */
  1077. };
  1078. PyMethodDef PyOp(Barrier)::tp_methods[] = {
  1079. {const_cast<char*>("__getstate__"), PyOp(Barrier)::getstate, METH_NOARGS, "Barrier getstate"},
  1080. {const_cast<char*>("__setstate__"), PyOp(Barrier)::setstate, METH_VARARGS, "Barrier setstate"},
  1081. {NULL} /* Sentinel */
  1082. };
  1083. PyObject *PyOp(Barrier)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  1084. if (PyOp(Barrier)::py_init(self, args, kwds) < 0) {
  1085. return NULL;
  1086. }
  1087. Py_RETURN_NONE;
  1088. }
  1089. PyMethodDef PyOp(Barrier)::py_init_methoddef = {
  1090. "__init__",
  1091. (PyCFunction)PyOp(Barrier)::py_init_proxy,
  1092. METH_VARARGS | METH_KEYWORDS,
  1093. "__init__(self, comp_node: str = ..., nr_outputs: int = ...) -> None\n"
  1094. };
  1095. void _init_py_Barrier(py::module m) {
  1096. using py_op = PyOp(Barrier);
  1097. auto& py_type = PyOpType(Barrier);
  1098. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  1099. py_type.tp_name = "megengine.core._imperative_rt.ops.Barrier";
  1100. py_type.tp_basicsize = sizeof(PyOp(Barrier));
  1101. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  1102. py_type.tp_doc = "Barrier";
  1103. py_type.tp_base = &PyOpType(OpDef);
  1104. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  1105. py_type.tp_new = py_new_generic<py_op>;
  1106. py_type.tp_init = py_op::py_init;
  1107. py_type.tp_methods = py_op::tp_methods;
  1108. py_type.tp_getset = py_op::py_getsetters;
  1109. py_type.tp_dict = PyDict_New();
  1110. PyObject* descr = PyDescr_NewMethod(&PyOpType(Barrier), &PyOp(Barrier)::py_init_methoddef);
  1111. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  1112. mgb_assert(PyType_Ready(&py_type) >= 0);
  1113. PyType_Modified(&py_type);
  1114. m.add_object("Barrier", reinterpret_cast<PyObject*>(&py_type));
  1115. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Barrier::typeinfo(), &py_type).second);
  1116. }
  1117. template<> struct EnumTrait<BatchConvBias::NonlineMode> {
  1118. static constexpr const char *name = "BatchConvBias.NonlineMode";
  1119. static constexpr std::underlying_type_t<BatchConvBias::NonlineMode> max = 4 - 1;
  1120. };
  1121. template<> PyTypeObject* EnumWrapper<BatchConvBias::NonlineMode>::type = nullptr;
  1122. template<> const char*
  1123. EnumWrapper<BatchConvBias::NonlineMode>::members[] = {"IDENTITY", "RELU", "SIGMOID", "H_SWISH"};
  1124. template<> std::unordered_map<std::string, BatchConvBias::NonlineMode>
  1125. EnumWrapper<BatchConvBias::NonlineMode>::mem2value = {{normalize_enum("IDENTITY"), BatchConvBias::NonlineMode::IDENTITY}, {normalize_enum("RELU"), BatchConvBias::NonlineMode::RELU}, {normalize_enum("SIGMOID"), BatchConvBias::NonlineMode::SIGMOID}, {normalize_enum("H_SWISH"), BatchConvBias::NonlineMode::H_SWISH}};
  1126. template<> PyObject* EnumWrapper<BatchConvBias::NonlineMode>::pyobj_insts[4] = {nullptr};
  1127. void _init_py_BatchConvBias_NonlineMode(PyTypeObject& py_type) {
  1128. auto& e_type = EnumWrapper<BatchConvBias::NonlineMode>::type;
  1129. static PyMethodDef tp_methods[] = {
  1130. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchConvBias::NonlineMode>::py_dump, METH_NOARGS, NULL},
  1131. {NULL} /* Sentinel */
  1132. };
  1133. static PyType_Slot slots[] = {
  1134. {Py_tp_repr, (void*)EnumWrapper<BatchConvBias::NonlineMode>::py_repr},
  1135. {Py_tp_richcompare, (void*)EnumWrapper<BatchConvBias::NonlineMode>::tp_richcompare},
  1136. {Py_tp_methods, tp_methods},
  1137. {0, NULL}
  1138. };
  1139. static PyType_Spec spec = {
  1140. // name
  1141. "megengine.core._imperative_rt.ops.BatchConvBias.NonlineMode",
  1142. // basicsize
  1143. sizeof(EnumWrapper<BatchConvBias::NonlineMode>),
  1144. // itemsize
  1145. 0,
  1146. // flags
  1147. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  1148. // slots
  1149. slots
  1150. };
  1151. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  1152. mgb_assert(
  1153. e_type->tp_setattro(
  1154. reinterpret_cast<PyObject*>(e_type),
  1155. py::cast("__name__").release().ptr(),
  1156. py::cast("NonlineMode").release().ptr()) >= 0);
  1157. mgb_assert(
  1158. e_type->tp_setattro(
  1159. reinterpret_cast<PyObject*>(e_type),
  1160. py::cast("__module__").release().ptr(),
  1161. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  1162. mgb_assert(
  1163. e_type->tp_setattro(
  1164. reinterpret_cast<PyObject*>(e_type),
  1165. py::cast("__qualname__").release().ptr(),
  1166. py::cast("BatchConvBias.NonlineMode").release().ptr()) >= 0);
  1167. {
  1168. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1169. reinterpret_cast<EnumWrapper<BatchConvBias::NonlineMode>*>(inst)->value = BatchConvBias::NonlineMode::IDENTITY;
  1170. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "IDENTITY", inst) >= 0);
  1171. EnumWrapper<BatchConvBias::NonlineMode>::pyobj_insts[0] = inst;
  1172. }{
  1173. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1174. reinterpret_cast<EnumWrapper<BatchConvBias::NonlineMode>*>(inst)->value = BatchConvBias::NonlineMode::RELU;
  1175. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RELU", inst) >= 0);
  1176. EnumWrapper<BatchConvBias::NonlineMode>::pyobj_insts[1] = inst;
  1177. }{
  1178. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1179. reinterpret_cast<EnumWrapper<BatchConvBias::NonlineMode>*>(inst)->value = BatchConvBias::NonlineMode::SIGMOID;
  1180. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIGMOID", inst) >= 0);
  1181. EnumWrapper<BatchConvBias::NonlineMode>::pyobj_insts[2] = inst;
  1182. }{
  1183. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1184. reinterpret_cast<EnumWrapper<BatchConvBias::NonlineMode>*>(inst)->value = BatchConvBias::NonlineMode::H_SWISH;
  1185. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "H_SWISH", inst) >= 0);
  1186. EnumWrapper<BatchConvBias::NonlineMode>::pyobj_insts[3] = inst;
  1187. }
  1188. Py_INCREF(e_type);
  1189. mgb_assert(PyDict_SetItemString(
  1190. py_type.tp_dict, "NonlineMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1191. }
  1192. template<> struct EnumTrait<BatchConvBias::Mode> {
  1193. static constexpr const char *name = "BatchConvBias.Mode";
  1194. static constexpr std::underlying_type_t<BatchConvBias::Mode> max = 2 - 1;
  1195. };
  1196. template<> PyTypeObject* EnumWrapper<BatchConvBias::Mode>::type = nullptr;
  1197. template<> const char*
  1198. EnumWrapper<BatchConvBias::Mode>::members[] = {"CROSS_CORRELATION", "CONVOLUTION"};
  1199. template<> std::unordered_map<std::string, BatchConvBias::Mode>
  1200. EnumWrapper<BatchConvBias::Mode>::mem2value = {{normalize_enum("CROSS_CORRELATION"), BatchConvBias::Mode::CROSS_CORRELATION}, {normalize_enum("CONVOLUTION"), BatchConvBias::Mode::CONVOLUTION}};
  1201. template<> PyObject* EnumWrapper<BatchConvBias::Mode>::pyobj_insts[2] = {nullptr};
  1202. void _init_py_BatchConvBias_Mode(PyTypeObject& py_type) {
  1203. auto& e_type = EnumWrapper<BatchConvBias::Mode>::type;
  1204. static PyMethodDef tp_methods[] = {
  1205. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchConvBias::Mode>::py_dump, METH_NOARGS, NULL},
  1206. {NULL} /* Sentinel */
  1207. };
  1208. static PyType_Slot slots[] = {
  1209. {Py_tp_repr, (void*)EnumWrapper<BatchConvBias::Mode>::py_repr},
  1210. {Py_tp_richcompare, (void*)EnumWrapper<BatchConvBias::Mode>::tp_richcompare},
  1211. {Py_tp_methods, tp_methods},
  1212. {0, NULL}
  1213. };
  1214. static PyType_Spec spec = {
  1215. // name
  1216. "megengine.core._imperative_rt.ops.BatchConvBias.Mode",
  1217. // basicsize
  1218. sizeof(EnumWrapper<BatchConvBias::Mode>),
  1219. // itemsize
  1220. 0,
  1221. // flags
  1222. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  1223. // slots
  1224. slots
  1225. };
  1226. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  1227. mgb_assert(
  1228. e_type->tp_setattro(
  1229. reinterpret_cast<PyObject*>(e_type),
  1230. py::cast("__name__").release().ptr(),
  1231. py::cast("Mode").release().ptr()) >= 0);
  1232. mgb_assert(
  1233. e_type->tp_setattro(
  1234. reinterpret_cast<PyObject*>(e_type),
  1235. py::cast("__module__").release().ptr(),
  1236. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  1237. mgb_assert(
  1238. e_type->tp_setattro(
  1239. reinterpret_cast<PyObject*>(e_type),
  1240. py::cast("__qualname__").release().ptr(),
  1241. py::cast("BatchConvBias.Mode").release().ptr()) >= 0);
  1242. {
  1243. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1244. reinterpret_cast<EnumWrapper<BatchConvBias::Mode>*>(inst)->value = BatchConvBias::Mode::CROSS_CORRELATION;
  1245. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CROSS_CORRELATION", inst) >= 0);
  1246. EnumWrapper<BatchConvBias::Mode>::pyobj_insts[0] = inst;
  1247. }{
  1248. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1249. reinterpret_cast<EnumWrapper<BatchConvBias::Mode>*>(inst)->value = BatchConvBias::Mode::CONVOLUTION;
  1250. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CONVOLUTION", inst) >= 0);
  1251. EnumWrapper<BatchConvBias::Mode>::pyobj_insts[1] = inst;
  1252. }
  1253. Py_INCREF(e_type);
  1254. mgb_assert(PyDict_SetItemString(
  1255. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1256. }
  1257. template<> struct EnumTrait<BatchConvBias::Sparse> {
  1258. static constexpr const char *name = "BatchConvBias.Sparse";
  1259. static constexpr std::underlying_type_t<BatchConvBias::Sparse> max = 2 - 1;
  1260. };
  1261. template<> PyTypeObject* EnumWrapper<BatchConvBias::Sparse>::type = nullptr;
  1262. template<> const char*
  1263. EnumWrapper<BatchConvBias::Sparse>::members[] = {"DENSE", "GROUP"};
  1264. template<> std::unordered_map<std::string, BatchConvBias::Sparse>
  1265. EnumWrapper<BatchConvBias::Sparse>::mem2value = {{normalize_enum("DENSE"), BatchConvBias::Sparse::DENSE}, {normalize_enum("GROUP"), BatchConvBias::Sparse::GROUP}};
  1266. template<> PyObject* EnumWrapper<BatchConvBias::Sparse>::pyobj_insts[2] = {nullptr};
  1267. void _init_py_BatchConvBias_Sparse(PyTypeObject& py_type) {
  1268. auto& e_type = EnumWrapper<BatchConvBias::Sparse>::type;
  1269. static PyMethodDef tp_methods[] = {
  1270. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchConvBias::Sparse>::py_dump, METH_NOARGS, NULL},
  1271. {NULL} /* Sentinel */
  1272. };
  1273. static PyType_Slot slots[] = {
  1274. {Py_tp_repr, (void*)EnumWrapper<BatchConvBias::Sparse>::py_repr},
  1275. {Py_tp_richcompare, (void*)EnumWrapper<BatchConvBias::Sparse>::tp_richcompare},
  1276. {Py_tp_methods, tp_methods},
  1277. {0, NULL}
  1278. };
  1279. static PyType_Spec spec = {
  1280. // name
  1281. "megengine.core._imperative_rt.ops.BatchConvBias.Sparse",
  1282. // basicsize
  1283. sizeof(EnumWrapper<BatchConvBias::Sparse>),
  1284. // itemsize
  1285. 0,
  1286. // flags
  1287. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  1288. // slots
  1289. slots
  1290. };
  1291. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  1292. mgb_assert(
  1293. e_type->tp_setattro(
  1294. reinterpret_cast<PyObject*>(e_type),
  1295. py::cast("__name__").release().ptr(),
  1296. py::cast("Sparse").release().ptr()) >= 0);
  1297. mgb_assert(
  1298. e_type->tp_setattro(
  1299. reinterpret_cast<PyObject*>(e_type),
  1300. py::cast("__module__").release().ptr(),
  1301. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  1302. mgb_assert(
  1303. e_type->tp_setattro(
  1304. reinterpret_cast<PyObject*>(e_type),
  1305. py::cast("__qualname__").release().ptr(),
  1306. py::cast("BatchConvBias.Sparse").release().ptr()) >= 0);
  1307. {
  1308. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1309. reinterpret_cast<EnumWrapper<BatchConvBias::Sparse>*>(inst)->value = BatchConvBias::Sparse::DENSE;
  1310. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DENSE", inst) >= 0);
  1311. EnumWrapper<BatchConvBias::Sparse>::pyobj_insts[0] = inst;
  1312. }{
  1313. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1314. reinterpret_cast<EnumWrapper<BatchConvBias::Sparse>*>(inst)->value = BatchConvBias::Sparse::GROUP;
  1315. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GROUP", inst) >= 0);
  1316. EnumWrapper<BatchConvBias::Sparse>::pyobj_insts[1] = inst;
  1317. }
  1318. Py_INCREF(e_type);
  1319. mgb_assert(PyDict_SetItemString(
  1320. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1321. }
  1322. void _init_py_BatchConvBias_Format(PyTypeObject& py_type) {
  1323. auto& e_type = EnumWrapper<BatchConvBias::Format>::type;
  1324. Py_INCREF(e_type);
  1325. mgb_assert(PyDict_SetItemString(
  1326. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1327. }
  1328. template<> struct EnumTrait<BatchConvBias::ComputeMode> {
  1329. static constexpr const char *name = "BatchConvBias.ComputeMode";
  1330. static constexpr std::underlying_type_t<BatchConvBias::ComputeMode> max = 2 - 1;
  1331. };
  1332. template<> PyTypeObject* EnumWrapper<BatchConvBias::ComputeMode>::type = nullptr;
  1333. template<> const char*
  1334. EnumWrapper<BatchConvBias::ComputeMode>::members[] = {"DEFAULT", "FLOAT32"};
  1335. template<> std::unordered_map<std::string, BatchConvBias::ComputeMode>
  1336. EnumWrapper<BatchConvBias::ComputeMode>::mem2value = {{normalize_enum("DEFAULT"), BatchConvBias::ComputeMode::DEFAULT}, {normalize_enum("FLOAT32"), BatchConvBias::ComputeMode::FLOAT32}};
  1337. template<> PyObject* EnumWrapper<BatchConvBias::ComputeMode>::pyobj_insts[2] = {nullptr};
  1338. void _init_py_BatchConvBias_ComputeMode(PyTypeObject& py_type) {
  1339. auto& e_type = EnumWrapper<BatchConvBias::ComputeMode>::type;
  1340. static PyMethodDef tp_methods[] = {
  1341. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchConvBias::ComputeMode>::py_dump, METH_NOARGS, NULL},
  1342. {NULL} /* Sentinel */
  1343. };
  1344. static PyType_Slot slots[] = {
  1345. {Py_tp_repr, (void*)EnumWrapper<BatchConvBias::ComputeMode>::py_repr},
  1346. {Py_tp_richcompare, (void*)EnumWrapper<BatchConvBias::ComputeMode>::tp_richcompare},
  1347. {Py_tp_methods, tp_methods},
  1348. {0, NULL}
  1349. };
  1350. static PyType_Spec spec = {
  1351. // name
  1352. "megengine.core._imperative_rt.ops.BatchConvBias.ComputeMode",
  1353. // basicsize
  1354. sizeof(EnumWrapper<BatchConvBias::ComputeMode>),
  1355. // itemsize
  1356. 0,
  1357. // flags
  1358. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  1359. // slots
  1360. slots
  1361. };
  1362. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  1363. mgb_assert(
  1364. e_type->tp_setattro(
  1365. reinterpret_cast<PyObject*>(e_type),
  1366. py::cast("__name__").release().ptr(),
  1367. py::cast("ComputeMode").release().ptr()) >= 0);
  1368. mgb_assert(
  1369. e_type->tp_setattro(
  1370. reinterpret_cast<PyObject*>(e_type),
  1371. py::cast("__module__").release().ptr(),
  1372. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  1373. mgb_assert(
  1374. e_type->tp_setattro(
  1375. reinterpret_cast<PyObject*>(e_type),
  1376. py::cast("__qualname__").release().ptr(),
  1377. py::cast("BatchConvBias.ComputeMode").release().ptr()) >= 0);
  1378. {
  1379. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1380. reinterpret_cast<EnumWrapper<BatchConvBias::ComputeMode>*>(inst)->value = BatchConvBias::ComputeMode::DEFAULT;
  1381. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DEFAULT", inst) >= 0);
  1382. EnumWrapper<BatchConvBias::ComputeMode>::pyobj_insts[0] = inst;
  1383. }{
  1384. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1385. reinterpret_cast<EnumWrapper<BatchConvBias::ComputeMode>*>(inst)->value = BatchConvBias::ComputeMode::FLOAT32;
  1386. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT32", inst) >= 0);
  1387. EnumWrapper<BatchConvBias::ComputeMode>::pyobj_insts[1] = inst;
  1388. }
  1389. Py_INCREF(e_type);
  1390. mgb_assert(PyDict_SetItemString(
  1391. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1392. }
  1393. template<> struct EnumTrait<BatchConvBias::Strategy> {
  1394. static constexpr const char *name = "BatchConvBias.Strategy";
  1395. static constexpr std::underlying_type_t<BatchConvBias::Strategy> max = (1llu << 4) - 1;
  1396. };
  1397. template<> PyTypeObject* BitCombinedEnumWrapper<BatchConvBias::Strategy>::type = nullptr;
  1398. template<> const char*
  1399. BitCombinedEnumWrapper<BatchConvBias::Strategy>::members[] = {"HEURISTIC", "PROFILE", "REPRODUCIBLE", "OPTIMIZED"};
  1400. template<> std::unordered_map<std::string, BatchConvBias::Strategy>
  1401. BitCombinedEnumWrapper<BatchConvBias::Strategy>::mem2value = {{normalize_enum("HEURISTIC"), BatchConvBias::Strategy::HEURISTIC}, {normalize_enum("PROFILE"), BatchConvBias::Strategy::PROFILE}, {normalize_enum("REPRODUCIBLE"), BatchConvBias::Strategy::REPRODUCIBLE}, {normalize_enum("OPTIMIZED"), BatchConvBias::Strategy::OPTIMIZED}};
  1402. template<> PyObject* BitCombinedEnumWrapper<BatchConvBias::Strategy>::pyobj_insts[4] = {nullptr};
  1403. void _init_py_BatchConvBias_Strategy(PyTypeObject& py_type) {
  1404. auto& e_type = BitCombinedEnumWrapper<BatchConvBias::Strategy>::type;
  1405. static PyMethodDef tp_methods[] = {
  1406. {const_cast<char*>("dump"), (PyCFunction)BitCombinedEnumWrapper<BatchConvBias::Strategy>::py_dump, METH_NOARGS, NULL},
  1407. {NULL} /* Sentinel */
  1408. };
  1409. static PyType_Slot slots[] = {
  1410. {Py_tp_repr, (void*)BitCombinedEnumWrapper<BatchConvBias::Strategy>::py_repr},
  1411. {Py_tp_richcompare, (void*)BitCombinedEnumWrapper<BatchConvBias::Strategy>::tp_richcompare},
  1412. {Py_tp_methods, tp_methods},
  1413. {Py_tp_new, (void*)BitCombinedEnumWrapper<BatchConvBias::Strategy>::py_new_combined_enum},
  1414. {Py_nb_or, (void*)BitCombinedEnumWrapper<BatchConvBias::Strategy>::py_or},
  1415. {Py_nb_and, (void*)BitCombinedEnumWrapper<BatchConvBias::Strategy>::py_and},
  1416. {0, NULL}
  1417. };
  1418. static PyType_Spec spec = {
  1419. // name
  1420. "megengine.core._imperative_rt.ops.BatchConvBias.Strategy",
  1421. // basicsize
  1422. sizeof(BitCombinedEnumWrapper<BatchConvBias::Strategy>),
  1423. // itemsize
  1424. 0,
  1425. // flags
  1426. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  1427. // slots
  1428. slots
  1429. };
  1430. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  1431. mgb_assert(
  1432. e_type->tp_setattro(
  1433. reinterpret_cast<PyObject*>(e_type),
  1434. py::cast("__name__").release().ptr(),
  1435. py::cast("Strategy").release().ptr()) >= 0);
  1436. mgb_assert(
  1437. e_type->tp_setattro(
  1438. reinterpret_cast<PyObject*>(e_type),
  1439. py::cast("__module__").release().ptr(),
  1440. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  1441. mgb_assert(
  1442. e_type->tp_setattro(
  1443. reinterpret_cast<PyObject*>(e_type),
  1444. py::cast("__qualname__").release().ptr(),
  1445. py::cast("BatchConvBias.Strategy").release().ptr()) >= 0);
  1446. {
  1447. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1448. reinterpret_cast<BitCombinedEnumWrapper<BatchConvBias::Strategy>*>(inst)->value = BatchConvBias::Strategy::HEURISTIC;
  1449. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "HEURISTIC", inst) >= 0);
  1450. BitCombinedEnumWrapper<BatchConvBias::Strategy>::pyobj_insts[0] = inst;
  1451. }{
  1452. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1453. reinterpret_cast<BitCombinedEnumWrapper<BatchConvBias::Strategy>*>(inst)->value = BatchConvBias::Strategy::PROFILE;
  1454. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "PROFILE", inst) >= 0);
  1455. BitCombinedEnumWrapper<BatchConvBias::Strategy>::pyobj_insts[1] = inst;
  1456. }{
  1457. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1458. reinterpret_cast<BitCombinedEnumWrapper<BatchConvBias::Strategy>*>(inst)->value = BatchConvBias::Strategy::REPRODUCIBLE;
  1459. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REPRODUCIBLE", inst) >= 0);
  1460. BitCombinedEnumWrapper<BatchConvBias::Strategy>::pyobj_insts[2] = inst;
  1461. }{
  1462. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1463. reinterpret_cast<BitCombinedEnumWrapper<BatchConvBias::Strategy>*>(inst)->value = BatchConvBias::Strategy::OPTIMIZED;
  1464. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "OPTIMIZED", inst) >= 0);
  1465. BitCombinedEnumWrapper<BatchConvBias::Strategy>::pyobj_insts[3] = inst;
  1466. }
  1467. Py_INCREF(e_type);
  1468. mgb_assert(PyDict_SetItemString(
  1469. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1470. }
  1471. PyOpDefBegin(BatchConvBias) // {
  1472. static PyGetSetDef py_getsetters[];
  1473. static PyMethodDef tp_methods[];
  1474. static PyObject* getstate(PyObject* self, PyObject*) {
  1475. auto& opdef = reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst();
  1476. static_cast<void>(opdef);
  1477. std::unordered_map<std::string, py::object> state {
  1478. {"nonlineMode", serialization<decltype(opdef.nonlineMode)>::dump(opdef.nonlineMode)},
  1479. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  1480. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  1481. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  1482. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  1483. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  1484. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  1485. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  1486. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  1487. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  1488. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  1489. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  1490. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)},
  1491. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)}
  1492. };
  1493. return py::cast(state).release().ptr();
  1494. }
  1495. static PyObject* setstate(PyObject* self, PyObject* args) {
  1496. PyObject* dict = PyTuple_GetItem(args, 0);
  1497. if (!dict) return NULL;
  1498. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  1499. auto& opdef = reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst();
  1500. static_cast<void>(opdef);
  1501. {
  1502. auto&& iter = state.find("nonlineMode");
  1503. if (iter != state.end()) {
  1504. opdef.nonlineMode = serialization<decltype(opdef.nonlineMode)>::load(iter->second);
  1505. }
  1506. }
  1507. {
  1508. auto&& iter = state.find("mode");
  1509. if (iter != state.end()) {
  1510. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  1511. }
  1512. }
  1513. {
  1514. auto&& iter = state.find("pad_h");
  1515. if (iter != state.end()) {
  1516. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  1517. }
  1518. }
  1519. {
  1520. auto&& iter = state.find("pad_w");
  1521. if (iter != state.end()) {
  1522. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  1523. }
  1524. }
  1525. {
  1526. auto&& iter = state.find("stride_h");
  1527. if (iter != state.end()) {
  1528. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  1529. }
  1530. }
  1531. {
  1532. auto&& iter = state.find("stride_w");
  1533. if (iter != state.end()) {
  1534. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  1535. }
  1536. }
  1537. {
  1538. auto&& iter = state.find("dilate_h");
  1539. if (iter != state.end()) {
  1540. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  1541. }
  1542. }
  1543. {
  1544. auto&& iter = state.find("dilate_w");
  1545. if (iter != state.end()) {
  1546. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  1547. }
  1548. }
  1549. {
  1550. auto&& iter = state.find("sparse");
  1551. if (iter != state.end()) {
  1552. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  1553. }
  1554. }
  1555. {
  1556. auto&& iter = state.find("format");
  1557. if (iter != state.end()) {
  1558. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  1559. }
  1560. }
  1561. {
  1562. auto&& iter = state.find("compute_mode");
  1563. if (iter != state.end()) {
  1564. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  1565. }
  1566. }
  1567. {
  1568. auto&& iter = state.find("strategy");
  1569. if (iter != state.end()) {
  1570. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  1571. }
  1572. }
  1573. {
  1574. auto&& iter = state.find("workspace_limit");
  1575. if (iter != state.end()) {
  1576. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  1577. }
  1578. }
  1579. {
  1580. auto&& iter = state.find("dtype");
  1581. if (iter != state.end()) {
  1582. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  1583. }
  1584. }
  1585. Py_RETURN_NONE;
  1586. }
  1587. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  1588. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  1589. static PyMethodDef py_init_methoddef;
  1590. // };
  1591. PyOpDefEnd(BatchConvBias)
  1592. int PyOp(BatchConvBias)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  1593. static const char* kwlist[] = {"nonlineMode", "mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "strategy", "workspace_limit", "dtype", "scope", NULL};
  1594. PyObject *nonlineMode = NULL, *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *strategy = NULL, *workspace_limit = NULL, *dtype = NULL, *scope = NULL;
  1595. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOOO", const_cast<char**>(kwlist), &nonlineMode, &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &strategy, &workspace_limit, &dtype, &scope))
  1596. return -1;
  1597. if (nonlineMode) {
  1598. try {
  1599. // TODO: remove this guard which is used for pybind11 implicit conversion
  1600. py::detail::loader_life_support guard{};
  1601. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().nonlineMode =
  1602. py::cast<decltype(BatchConvBias::nonlineMode)>(py::handle(nonlineMode));
  1603. } CATCH_ALL(-1)
  1604. }
  1605. if (mode) {
  1606. try {
  1607. // TODO: remove this guard which is used for pybind11 implicit conversion
  1608. py::detail::loader_life_support guard{};
  1609. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().mode =
  1610. py::cast<decltype(BatchConvBias::mode)>(py::handle(mode));
  1611. } CATCH_ALL(-1)
  1612. }
  1613. if (pad_h) {
  1614. try {
  1615. // TODO: remove this guard which is used for pybind11 implicit conversion
  1616. py::detail::loader_life_support guard{};
  1617. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().pad_h =
  1618. py::cast<decltype(BatchConvBias::pad_h)>(py::handle(pad_h));
  1619. } CATCH_ALL(-1)
  1620. }
  1621. if (pad_w) {
  1622. try {
  1623. // TODO: remove this guard which is used for pybind11 implicit conversion
  1624. py::detail::loader_life_support guard{};
  1625. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().pad_w =
  1626. py::cast<decltype(BatchConvBias::pad_w)>(py::handle(pad_w));
  1627. } CATCH_ALL(-1)
  1628. }
  1629. if (stride_h) {
  1630. try {
  1631. // TODO: remove this guard which is used for pybind11 implicit conversion
  1632. py::detail::loader_life_support guard{};
  1633. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().stride_h =
  1634. py::cast<decltype(BatchConvBias::stride_h)>(py::handle(stride_h));
  1635. } CATCH_ALL(-1)
  1636. }
  1637. if (stride_w) {
  1638. try {
  1639. // TODO: remove this guard which is used for pybind11 implicit conversion
  1640. py::detail::loader_life_support guard{};
  1641. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().stride_w =
  1642. py::cast<decltype(BatchConvBias::stride_w)>(py::handle(stride_w));
  1643. } CATCH_ALL(-1)
  1644. }
  1645. if (dilate_h) {
  1646. try {
  1647. // TODO: remove this guard which is used for pybind11 implicit conversion
  1648. py::detail::loader_life_support guard{};
  1649. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().dilate_h =
  1650. py::cast<decltype(BatchConvBias::dilate_h)>(py::handle(dilate_h));
  1651. } CATCH_ALL(-1)
  1652. }
  1653. if (dilate_w) {
  1654. try {
  1655. // TODO: remove this guard which is used for pybind11 implicit conversion
  1656. py::detail::loader_life_support guard{};
  1657. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().dilate_w =
  1658. py::cast<decltype(BatchConvBias::dilate_w)>(py::handle(dilate_w));
  1659. } CATCH_ALL(-1)
  1660. }
  1661. if (sparse) {
  1662. try {
  1663. // TODO: remove this guard which is used for pybind11 implicit conversion
  1664. py::detail::loader_life_support guard{};
  1665. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().sparse =
  1666. py::cast<decltype(BatchConvBias::sparse)>(py::handle(sparse));
  1667. } CATCH_ALL(-1)
  1668. }
  1669. if (format) {
  1670. try {
  1671. // TODO: remove this guard which is used for pybind11 implicit conversion
  1672. py::detail::loader_life_support guard{};
  1673. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().format =
  1674. py::cast<decltype(BatchConvBias::format)>(py::handle(format));
  1675. } CATCH_ALL(-1)
  1676. }
  1677. if (compute_mode) {
  1678. try {
  1679. // TODO: remove this guard which is used for pybind11 implicit conversion
  1680. py::detail::loader_life_support guard{};
  1681. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().compute_mode =
  1682. py::cast<decltype(BatchConvBias::compute_mode)>(py::handle(compute_mode));
  1683. } CATCH_ALL(-1)
  1684. }
  1685. if (strategy) {
  1686. try {
  1687. // TODO: remove this guard which is used for pybind11 implicit conversion
  1688. py::detail::loader_life_support guard{};
  1689. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().strategy =
  1690. py::cast<decltype(BatchConvBias::strategy)>(py::handle(strategy));
  1691. } CATCH_ALL(-1)
  1692. }
  1693. if (workspace_limit) {
  1694. try {
  1695. // TODO: remove this guard which is used for pybind11 implicit conversion
  1696. py::detail::loader_life_support guard{};
  1697. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().workspace_limit =
  1698. py::cast<decltype(BatchConvBias::workspace_limit)>(py::handle(workspace_limit));
  1699. } CATCH_ALL(-1)
  1700. }
  1701. if (dtype) {
  1702. try {
  1703. // TODO: remove this guard which is used for pybind11 implicit conversion
  1704. py::detail::loader_life_support guard{};
  1705. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().dtype =
  1706. py::cast<decltype(BatchConvBias::dtype)>(py::handle(dtype));
  1707. } CATCH_ALL(-1)
  1708. }
  1709. if (scope) {
  1710. try {
  1711. reinterpret_cast<PyOp(OpDef)*>(self)->op
  1712. ->set_scope(py::cast<std::string>(py::handle(scope)));
  1713. } CATCH_ALL(-1)
  1714. }
  1715. return 0;
  1716. }
  1717. PyGetSetDef PyOp(BatchConvBias)::py_getsetters[] = {
  1718. {const_cast<char*>("nonlineMode"), py_get_generic(BatchConvBias, nonlineMode), py_set_generic(BatchConvBias, nonlineMode), const_cast<char*>("nonlineMode"), NULL},
  1719. {const_cast<char*>("mode"), py_get_generic(BatchConvBias, mode), py_set_generic(BatchConvBias, mode), const_cast<char*>("mode"), NULL},
  1720. {const_cast<char*>("pad_h"), py_get_generic(BatchConvBias, pad_h), py_set_generic(BatchConvBias, pad_h), const_cast<char*>("pad_h"), NULL},
  1721. {const_cast<char*>("pad_w"), py_get_generic(BatchConvBias, pad_w), py_set_generic(BatchConvBias, pad_w), const_cast<char*>("pad_w"), NULL},
  1722. {const_cast<char*>("stride_h"), py_get_generic(BatchConvBias, stride_h), py_set_generic(BatchConvBias, stride_h), const_cast<char*>("stride_h"), NULL},
  1723. {const_cast<char*>("stride_w"), py_get_generic(BatchConvBias, stride_w), py_set_generic(BatchConvBias, stride_w), const_cast<char*>("stride_w"), NULL},
  1724. {const_cast<char*>("dilate_h"), py_get_generic(BatchConvBias, dilate_h), py_set_generic(BatchConvBias, dilate_h), const_cast<char*>("dilate_h"), NULL},
  1725. {const_cast<char*>("dilate_w"), py_get_generic(BatchConvBias, dilate_w), py_set_generic(BatchConvBias, dilate_w), const_cast<char*>("dilate_w"), NULL},
  1726. {const_cast<char*>("sparse"), py_get_generic(BatchConvBias, sparse), py_set_generic(BatchConvBias, sparse), const_cast<char*>("sparse"), NULL},
  1727. {const_cast<char*>("format"), py_get_generic(BatchConvBias, format), py_set_generic(BatchConvBias, format), const_cast<char*>("format"), NULL},
  1728. {const_cast<char*>("compute_mode"), py_get_generic(BatchConvBias, compute_mode), py_set_generic(BatchConvBias, compute_mode), const_cast<char*>("compute_mode"), NULL},
  1729. {const_cast<char*>("strategy"), py_get_generic(BatchConvBias, strategy), py_set_generic(BatchConvBias, strategy), const_cast<char*>("strategy"), NULL},
  1730. {const_cast<char*>("workspace_limit"), py_get_generic(BatchConvBias, workspace_limit), py_set_generic(BatchConvBias, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  1731. {const_cast<char*>("dtype"), py_get_generic(BatchConvBias, dtype), py_set_generic(BatchConvBias, dtype), const_cast<char*>("dtype"), NULL},
  1732. {NULL} /* Sentinel */
  1733. };
  1734. PyMethodDef PyOp(BatchConvBias)::tp_methods[] = {
  1735. {const_cast<char*>("__getstate__"), PyOp(BatchConvBias)::getstate, METH_NOARGS, "BatchConvBias getstate"},
  1736. {const_cast<char*>("__setstate__"), PyOp(BatchConvBias)::setstate, METH_VARARGS, "BatchConvBias setstate"},
  1737. {NULL} /* Sentinel */
  1738. };
  1739. PyObject *PyOp(BatchConvBias)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  1740. if (PyOp(BatchConvBias)::py_init(self, args, kwds) < 0) {
  1741. return NULL;
  1742. }
  1743. Py_RETURN_NONE;
  1744. }
  1745. PyMethodDef PyOp(BatchConvBias)::py_init_methoddef = {
  1746. "__init__",
  1747. (PyCFunction)PyOp(BatchConvBias)::py_init_proxy,
  1748. METH_VARARGS | METH_KEYWORDS,
  1749. "__init__(self, nonlineMode: Union[str, NonlineMode] = ..., mode: Union[str, Mode] = ..., pad_h: int = ..., pad_w: int = ..., stride_h: int = ..., stride_w: int = ..., dilate_h: int = ..., dilate_w: int = ..., sparse: Union[str, Sparse] = ..., format: Union[str, Format] = ..., compute_mode: Union[str, ComputeMode] = ..., strategy: Union[str, Strategy] = ..., dtype: str = ...) -> None\n"
  1750. };
  1751. void _init_py_BatchConvBias(py::module m) {
  1752. using py_op = PyOp(BatchConvBias);
  1753. auto& py_type = PyOpType(BatchConvBias);
  1754. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  1755. py_type.tp_name = "megengine.core._imperative_rt.ops.BatchConvBias";
  1756. py_type.tp_basicsize = sizeof(PyOp(BatchConvBias));
  1757. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  1758. py_type.tp_doc = "BatchConvBias";
  1759. py_type.tp_base = &PyOpType(OpDef);
  1760. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  1761. py_type.tp_new = py_new_generic<py_op>;
  1762. py_type.tp_init = py_op::py_init;
  1763. py_type.tp_methods = py_op::tp_methods;
  1764. py_type.tp_getset = py_op::py_getsetters;
  1765. py_type.tp_dict = PyDict_New();
  1766. PyObject* descr = PyDescr_NewMethod(&PyOpType(BatchConvBias), &PyOp(BatchConvBias)::py_init_methoddef);
  1767. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  1768. mgb_assert(PyType_Ready(&py_type) >= 0);
  1769. _init_py_BatchConvBias_NonlineMode(py_type);
  1770. _init_py_BatchConvBias_Mode(py_type);
  1771. _init_py_BatchConvBias_Sparse(py_type);
  1772. _init_py_BatchConvBias_Format(py_type);
  1773. _init_py_BatchConvBias_ComputeMode(py_type);
  1774. _init_py_BatchConvBias_Strategy(py_type);
  1775. PyType_Modified(&py_type);
  1776. m.add_object("BatchConvBias", reinterpret_cast<PyObject*>(&py_type));
  1777. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchConvBias::typeinfo(), &py_type).second);
  1778. }
  1779. template<> struct EnumTrait<BatchNorm::ParamDim> {
  1780. static constexpr const char *name = "BatchNorm.ParamDim";
  1781. static constexpr std::underlying_type_t<BatchNorm::ParamDim> max = 4 - 1;
  1782. };
  1783. template<> PyTypeObject* EnumWrapper<BatchNorm::ParamDim>::type = nullptr;
  1784. template<> const char*
  1785. EnumWrapper<BatchNorm::ParamDim>::members[] = {"DIM_11HW", "DIM_1CHW", "DIM_1C11", "DIM_111C"};
  1786. template<> std::unordered_map<std::string, BatchNorm::ParamDim>
  1787. EnumWrapper<BatchNorm::ParamDim>::mem2value = {{normalize_enum("DIM_11HW"), BatchNorm::ParamDim::DIM_11HW}, {normalize_enum("DIM_1CHW"), BatchNorm::ParamDim::DIM_1CHW}, {normalize_enum("DIM_1C11"), BatchNorm::ParamDim::DIM_1C11}, {normalize_enum("DIM_111C"), BatchNorm::ParamDim::DIM_111C}};
  1788. template<> PyObject* EnumWrapper<BatchNorm::ParamDim>::pyobj_insts[4] = {nullptr};
  1789. void _init_py_BatchNorm_ParamDim(PyTypeObject& py_type) {
  1790. auto& e_type = EnumWrapper<BatchNorm::ParamDim>::type;
  1791. static PyMethodDef tp_methods[] = {
  1792. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchNorm::ParamDim>::py_dump, METH_NOARGS, NULL},
  1793. {NULL} /* Sentinel */
  1794. };
  1795. static PyType_Slot slots[] = {
  1796. {Py_tp_repr, (void*)EnumWrapper<BatchNorm::ParamDim>::py_repr},
  1797. {Py_tp_richcompare, (void*)EnumWrapper<BatchNorm::ParamDim>::tp_richcompare},
  1798. {Py_tp_methods, tp_methods},
  1799. {0, NULL}
  1800. };
  1801. static PyType_Spec spec = {
  1802. // name
  1803. "megengine.core._imperative_rt.ops.BatchNorm.ParamDim",
  1804. // basicsize
  1805. sizeof(EnumWrapper<BatchNorm::ParamDim>),
  1806. // itemsize
  1807. 0,
  1808. // flags
  1809. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  1810. // slots
  1811. slots
  1812. };
  1813. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  1814. mgb_assert(
  1815. e_type->tp_setattro(
  1816. reinterpret_cast<PyObject*>(e_type),
  1817. py::cast("__name__").release().ptr(),
  1818. py::cast("ParamDim").release().ptr()) >= 0);
  1819. mgb_assert(
  1820. e_type->tp_setattro(
  1821. reinterpret_cast<PyObject*>(e_type),
  1822. py::cast("__module__").release().ptr(),
  1823. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  1824. mgb_assert(
  1825. e_type->tp_setattro(
  1826. reinterpret_cast<PyObject*>(e_type),
  1827. py::cast("__qualname__").release().ptr(),
  1828. py::cast("BatchNorm.ParamDim").release().ptr()) >= 0);
  1829. {
  1830. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1831. reinterpret_cast<EnumWrapper<BatchNorm::ParamDim>*>(inst)->value = BatchNorm::ParamDim::DIM_11HW;
  1832. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DIM_11HW", inst) >= 0);
  1833. EnumWrapper<BatchNorm::ParamDim>::pyobj_insts[0] = inst;
  1834. }{
  1835. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1836. reinterpret_cast<EnumWrapper<BatchNorm::ParamDim>*>(inst)->value = BatchNorm::ParamDim::DIM_1CHW;
  1837. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DIM_1CHW", inst) >= 0);
  1838. EnumWrapper<BatchNorm::ParamDim>::pyobj_insts[1] = inst;
  1839. }{
  1840. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1841. reinterpret_cast<EnumWrapper<BatchNorm::ParamDim>*>(inst)->value = BatchNorm::ParamDim::DIM_1C11;
  1842. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DIM_1C11", inst) >= 0);
  1843. EnumWrapper<BatchNorm::ParamDim>::pyobj_insts[2] = inst;
  1844. }{
  1845. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1846. reinterpret_cast<EnumWrapper<BatchNorm::ParamDim>*>(inst)->value = BatchNorm::ParamDim::DIM_111C;
  1847. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DIM_111C", inst) >= 0);
  1848. EnumWrapper<BatchNorm::ParamDim>::pyobj_insts[3] = inst;
  1849. }
  1850. Py_INCREF(e_type);
  1851. mgb_assert(PyDict_SetItemString(
  1852. py_type.tp_dict, "ParamDim", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1853. }
  1854. template<> struct EnumTrait<BatchNorm::FwdMode> {
  1855. static constexpr const char *name = "BatchNorm.FwdMode";
  1856. static constexpr std::underlying_type_t<BatchNorm::FwdMode> max = 2 - 1;
  1857. };
  1858. template<> PyTypeObject* EnumWrapper<BatchNorm::FwdMode>::type = nullptr;
  1859. template<> const char*
  1860. EnumWrapper<BatchNorm::FwdMode>::members[] = {"TRAINING", "INFERENCE"};
  1861. template<> std::unordered_map<std::string, BatchNorm::FwdMode>
  1862. EnumWrapper<BatchNorm::FwdMode>::mem2value = {{normalize_enum("TRAINING"), BatchNorm::FwdMode::TRAINING}, {normalize_enum("INFERENCE"), BatchNorm::FwdMode::INFERENCE}};
  1863. template<> PyObject* EnumWrapper<BatchNorm::FwdMode>::pyobj_insts[2] = {nullptr};
  1864. void _init_py_BatchNorm_FwdMode(PyTypeObject& py_type) {
  1865. auto& e_type = EnumWrapper<BatchNorm::FwdMode>::type;
  1866. static PyMethodDef tp_methods[] = {
  1867. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchNorm::FwdMode>::py_dump, METH_NOARGS, NULL},
  1868. {NULL} /* Sentinel */
  1869. };
  1870. static PyType_Slot slots[] = {
  1871. {Py_tp_repr, (void*)EnumWrapper<BatchNorm::FwdMode>::py_repr},
  1872. {Py_tp_richcompare, (void*)EnumWrapper<BatchNorm::FwdMode>::tp_richcompare},
  1873. {Py_tp_methods, tp_methods},
  1874. {0, NULL}
  1875. };
  1876. static PyType_Spec spec = {
  1877. // name
  1878. "megengine.core._imperative_rt.ops.BatchNorm.FwdMode",
  1879. // basicsize
  1880. sizeof(EnumWrapper<BatchNorm::FwdMode>),
  1881. // itemsize
  1882. 0,
  1883. // flags
  1884. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  1885. // slots
  1886. slots
  1887. };
  1888. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  1889. mgb_assert(
  1890. e_type->tp_setattro(
  1891. reinterpret_cast<PyObject*>(e_type),
  1892. py::cast("__name__").release().ptr(),
  1893. py::cast("FwdMode").release().ptr()) >= 0);
  1894. mgb_assert(
  1895. e_type->tp_setattro(
  1896. reinterpret_cast<PyObject*>(e_type),
  1897. py::cast("__module__").release().ptr(),
  1898. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  1899. mgb_assert(
  1900. e_type->tp_setattro(
  1901. reinterpret_cast<PyObject*>(e_type),
  1902. py::cast("__qualname__").release().ptr(),
  1903. py::cast("BatchNorm.FwdMode").release().ptr()) >= 0);
  1904. {
  1905. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1906. reinterpret_cast<EnumWrapper<BatchNorm::FwdMode>*>(inst)->value = BatchNorm::FwdMode::TRAINING;
  1907. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TRAINING", inst) >= 0);
  1908. EnumWrapper<BatchNorm::FwdMode>::pyobj_insts[0] = inst;
  1909. }{
  1910. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1911. reinterpret_cast<EnumWrapper<BatchNorm::FwdMode>*>(inst)->value = BatchNorm::FwdMode::INFERENCE;
  1912. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "INFERENCE", inst) >= 0);
  1913. EnumWrapper<BatchNorm::FwdMode>::pyobj_insts[1] = inst;
  1914. }
  1915. Py_INCREF(e_type);
  1916. mgb_assert(PyDict_SetItemString(
  1917. py_type.tp_dict, "FwdMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1918. }
  1919. PyOpDefBegin(BatchNorm) // {
  1920. static PyGetSetDef py_getsetters[];
  1921. static PyMethodDef tp_methods[];
  1922. static PyObject* getstate(PyObject* self, PyObject*) {
  1923. auto& opdef = reinterpret_cast<PyOp(BatchNorm)*>(self)->inst();
  1924. static_cast<void>(opdef);
  1925. std::unordered_map<std::string, py::object> state {
  1926. {"param_dim", serialization<decltype(opdef.param_dim)>::dump(opdef.param_dim)},
  1927. {"fwd_mode", serialization<decltype(opdef.fwd_mode)>::dump(opdef.fwd_mode)},
  1928. {"epsilon", serialization<decltype(opdef.epsilon)>::dump(opdef.epsilon)},
  1929. {"avg_factor", serialization<decltype(opdef.avg_factor)>::dump(opdef.avg_factor)},
  1930. {"scale", serialization<decltype(opdef.scale)>::dump(opdef.scale)},
  1931. {"bias", serialization<decltype(opdef.bias)>::dump(opdef.bias)}
  1932. };
  1933. return py::cast(state).release().ptr();
  1934. }
  1935. static PyObject* setstate(PyObject* self, PyObject* args) {
  1936. PyObject* dict = PyTuple_GetItem(args, 0);
  1937. if (!dict) return NULL;
  1938. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  1939. auto& opdef = reinterpret_cast<PyOp(BatchNorm)*>(self)->inst();
  1940. static_cast<void>(opdef);
  1941. {
  1942. auto&& iter = state.find("param_dim");
  1943. if (iter != state.end()) {
  1944. opdef.param_dim = serialization<decltype(opdef.param_dim)>::load(iter->second);
  1945. }
  1946. }
  1947. {
  1948. auto&& iter = state.find("fwd_mode");
  1949. if (iter != state.end()) {
  1950. opdef.fwd_mode = serialization<decltype(opdef.fwd_mode)>::load(iter->second);
  1951. }
  1952. }
  1953. {
  1954. auto&& iter = state.find("epsilon");
  1955. if (iter != state.end()) {
  1956. opdef.epsilon = serialization<decltype(opdef.epsilon)>::load(iter->second);
  1957. }
  1958. }
  1959. {
  1960. auto&& iter = state.find("avg_factor");
  1961. if (iter != state.end()) {
  1962. opdef.avg_factor = serialization<decltype(opdef.avg_factor)>::load(iter->second);
  1963. }
  1964. }
  1965. {
  1966. auto&& iter = state.find("scale");
  1967. if (iter != state.end()) {
  1968. opdef.scale = serialization<decltype(opdef.scale)>::load(iter->second);
  1969. }
  1970. }
  1971. {
  1972. auto&& iter = state.find("bias");
  1973. if (iter != state.end()) {
  1974. opdef.bias = serialization<decltype(opdef.bias)>::load(iter->second);
  1975. }
  1976. }
  1977. Py_RETURN_NONE;
  1978. }
  1979. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  1980. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  1981. static PyMethodDef py_init_methoddef;
  1982. // };
  1983. PyOpDefEnd(BatchNorm)
  1984. int PyOp(BatchNorm)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  1985. static const char* kwlist[] = {"param_dim", "fwd_mode", "epsilon", "avg_factor", "scale", "bias", "scope", NULL};
  1986. PyObject *param_dim = NULL, *fwd_mode = NULL, *epsilon = NULL, *avg_factor = NULL, *scale = NULL, *bias = NULL, *scope = NULL;
  1987. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOO", const_cast<char**>(kwlist), &param_dim, &fwd_mode, &epsilon, &avg_factor, &scale, &bias, &scope))
  1988. return -1;
  1989. if (param_dim) {
  1990. try {
  1991. // TODO: remove this guard which is used for pybind11 implicit conversion
  1992. py::detail::loader_life_support guard{};
  1993. reinterpret_cast<PyOp(BatchNorm)*>(self)->inst().param_dim =
  1994. py::cast<decltype(BatchNorm::param_dim)>(py::handle(param_dim));
  1995. } CATCH_ALL(-1)
  1996. }
  1997. if (fwd_mode) {
  1998. try {
  1999. // TODO: remove this guard which is used for pybind11 implicit conversion
  2000. py::detail::loader_life_support guard{};
  2001. reinterpret_cast<PyOp(BatchNorm)*>(self)->inst().fwd_mode =
  2002. py::cast<decltype(BatchNorm::fwd_mode)>(py::handle(fwd_mode));
  2003. } CATCH_ALL(-1)
  2004. }
  2005. if (epsilon) {
  2006. try {
  2007. // TODO: remove this guard which is used for pybind11 implicit conversion
  2008. py::detail::loader_life_support guard{};
  2009. reinterpret_cast<PyOp(BatchNorm)*>(self)->inst().epsilon =
  2010. py::cast<decltype(BatchNorm::epsilon)>(py::handle(epsilon));
  2011. } CATCH_ALL(-1)
  2012. }
  2013. if (avg_factor) {
  2014. try {
  2015. // TODO: remove this guard which is used for pybind11 implicit conversion
  2016. py::detail::loader_life_support guard{};
  2017. reinterpret_cast<PyOp(BatchNorm)*>(self)->inst().avg_factor =
  2018. py::cast<decltype(BatchNorm::avg_factor)>(py::handle(avg_factor));
  2019. } CATCH_ALL(-1)
  2020. }
  2021. if (scale) {
  2022. try {
  2023. // TODO: remove this guard which is used for pybind11 implicit conversion
  2024. py::detail::loader_life_support guard{};
  2025. reinterpret_cast<PyOp(BatchNorm)*>(self)->inst().scale =
  2026. py::cast<decltype(BatchNorm::scale)>(py::handle(scale));
  2027. } CATCH_ALL(-1)
  2028. }
  2029. if (bias) {
  2030. try {
  2031. // TODO: remove this guard which is used for pybind11 implicit conversion
  2032. py::detail::loader_life_support guard{};
  2033. reinterpret_cast<PyOp(BatchNorm)*>(self)->inst().bias =
  2034. py::cast<decltype(BatchNorm::bias)>(py::handle(bias));
  2035. } CATCH_ALL(-1)
  2036. }
  2037. if (scope) {
  2038. try {
  2039. reinterpret_cast<PyOp(OpDef)*>(self)->op
  2040. ->set_scope(py::cast<std::string>(py::handle(scope)));
  2041. } CATCH_ALL(-1)
  2042. }
  2043. return 0;
  2044. }
  2045. PyGetSetDef PyOp(BatchNorm)::py_getsetters[] = {
  2046. {const_cast<char*>("param_dim"), py_get_generic(BatchNorm, param_dim), py_set_generic(BatchNorm, param_dim), const_cast<char*>("param_dim"), NULL},
  2047. {const_cast<char*>("fwd_mode"), py_get_generic(BatchNorm, fwd_mode), py_set_generic(BatchNorm, fwd_mode), const_cast<char*>("fwd_mode"), NULL},
  2048. {const_cast<char*>("epsilon"), py_get_generic(BatchNorm, epsilon), py_set_generic(BatchNorm, epsilon), const_cast<char*>("epsilon"), NULL},
  2049. {const_cast<char*>("avg_factor"), py_get_generic(BatchNorm, avg_factor), py_set_generic(BatchNorm, avg_factor), const_cast<char*>("avg_factor"), NULL},
  2050. {const_cast<char*>("scale"), py_get_generic(BatchNorm, scale), py_set_generic(BatchNorm, scale), const_cast<char*>("scale"), NULL},
  2051. {const_cast<char*>("bias"), py_get_generic(BatchNorm, bias), py_set_generic(BatchNorm, bias), const_cast<char*>("bias"), NULL},
  2052. {NULL} /* Sentinel */
  2053. };
  2054. PyMethodDef PyOp(BatchNorm)::tp_methods[] = {
  2055. {const_cast<char*>("__getstate__"), PyOp(BatchNorm)::getstate, METH_NOARGS, "BatchNorm getstate"},
  2056. {const_cast<char*>("__setstate__"), PyOp(BatchNorm)::setstate, METH_VARARGS, "BatchNorm setstate"},
  2057. {NULL} /* Sentinel */
  2058. };
  2059. PyObject *PyOp(BatchNorm)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  2060. if (PyOp(BatchNorm)::py_init(self, args, kwds) < 0) {
  2061. return NULL;
  2062. }
  2063. Py_RETURN_NONE;
  2064. }
  2065. PyMethodDef PyOp(BatchNorm)::py_init_methoddef = {
  2066. "__init__",
  2067. (PyCFunction)PyOp(BatchNorm)::py_init_proxy,
  2068. METH_VARARGS | METH_KEYWORDS,
  2069. "__init__(self, param_dim: Union[str, ParamDim] = ..., fwd_mode: Union[str, FwdMode] = ..., epsilon: float = ..., avg_factor: float = ..., scale: float = ..., bias: float = ...) -> None\n"
  2070. };
  2071. void _init_py_BatchNorm(py::module m) {
  2072. using py_op = PyOp(BatchNorm);
  2073. auto& py_type = PyOpType(BatchNorm);
  2074. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  2075. py_type.tp_name = "megengine.core._imperative_rt.ops.BatchNorm";
  2076. py_type.tp_basicsize = sizeof(PyOp(BatchNorm));
  2077. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  2078. py_type.tp_doc = "BatchNorm";
  2079. py_type.tp_base = &PyOpType(OpDef);
  2080. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  2081. py_type.tp_new = py_new_generic<py_op>;
  2082. py_type.tp_init = py_op::py_init;
  2083. py_type.tp_methods = py_op::tp_methods;
  2084. py_type.tp_getset = py_op::py_getsetters;
  2085. py_type.tp_dict = PyDict_New();
  2086. PyObject* descr = PyDescr_NewMethod(&PyOpType(BatchNorm), &PyOp(BatchNorm)::py_init_methoddef);
  2087. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  2088. mgb_assert(PyType_Ready(&py_type) >= 0);
  2089. _init_py_BatchNorm_ParamDim(py_type);
  2090. _init_py_BatchNorm_FwdMode(py_type);
  2091. PyType_Modified(&py_type);
  2092. m.add_object("BatchNorm", reinterpret_cast<PyObject*>(&py_type));
  2093. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchNorm::typeinfo(), &py_type).second);
  2094. }
  2095. void _init_py_BatchNormBackward_ParamDim(PyTypeObject& py_type) {
  2096. auto& e_type = EnumWrapper<BatchNormBackward::ParamDim>::type;
  2097. Py_INCREF(e_type);
  2098. mgb_assert(PyDict_SetItemString(
  2099. py_type.tp_dict, "ParamDim", reinterpret_cast<PyObject*>(e_type)) >= 0);
  2100. }
  2101. void _init_py_BatchNormBackward_FwdMode(PyTypeObject& py_type) {
  2102. auto& e_type = EnumWrapper<BatchNormBackward::FwdMode>::type;
  2103. Py_INCREF(e_type);
  2104. mgb_assert(PyDict_SetItemString(
  2105. py_type.tp_dict, "FwdMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  2106. }
  2107. PyOpDefBegin(BatchNormBackward) // {
  2108. static PyGetSetDef py_getsetters[];
  2109. static PyMethodDef tp_methods[];
  2110. static PyObject* getstate(PyObject* self, PyObject*) {
  2111. auto& opdef = reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst();
  2112. static_cast<void>(opdef);
  2113. std::unordered_map<std::string, py::object> state {
  2114. {"param_dim", serialization<decltype(opdef.param_dim)>::dump(opdef.param_dim)},
  2115. {"fwd_mode", serialization<decltype(opdef.fwd_mode)>::dump(opdef.fwd_mode)},
  2116. {"epsilon", serialization<decltype(opdef.epsilon)>::dump(opdef.epsilon)},
  2117. {"avg_factor", serialization<decltype(opdef.avg_factor)>::dump(opdef.avg_factor)},
  2118. {"scale", serialization<decltype(opdef.scale)>::dump(opdef.scale)},
  2119. {"bias", serialization<decltype(opdef.bias)>::dump(opdef.bias)}
  2120. };
  2121. return py::cast(state).release().ptr();
  2122. }
  2123. static PyObject* setstate(PyObject* self, PyObject* args) {
  2124. PyObject* dict = PyTuple_GetItem(args, 0);
  2125. if (!dict) return NULL;
  2126. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  2127. auto& opdef = reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst();
  2128. static_cast<void>(opdef);
  2129. {
  2130. auto&& iter = state.find("param_dim");
  2131. if (iter != state.end()) {
  2132. opdef.param_dim = serialization<decltype(opdef.param_dim)>::load(iter->second);
  2133. }
  2134. }
  2135. {
  2136. auto&& iter = state.find("fwd_mode");
  2137. if (iter != state.end()) {
  2138. opdef.fwd_mode = serialization<decltype(opdef.fwd_mode)>::load(iter->second);
  2139. }
  2140. }
  2141. {
  2142. auto&& iter = state.find("epsilon");
  2143. if (iter != state.end()) {
  2144. opdef.epsilon = serialization<decltype(opdef.epsilon)>::load(iter->second);
  2145. }
  2146. }
  2147. {
  2148. auto&& iter = state.find("avg_factor");
  2149. if (iter != state.end()) {
  2150. opdef.avg_factor = serialization<decltype(opdef.avg_factor)>::load(iter->second);
  2151. }
  2152. }
  2153. {
  2154. auto&& iter = state.find("scale");
  2155. if (iter != state.end()) {
  2156. opdef.scale = serialization<decltype(opdef.scale)>::load(iter->second);
  2157. }
  2158. }
  2159. {
  2160. auto&& iter = state.find("bias");
  2161. if (iter != state.end()) {
  2162. opdef.bias = serialization<decltype(opdef.bias)>::load(iter->second);
  2163. }
  2164. }
  2165. Py_RETURN_NONE;
  2166. }
  2167. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  2168. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  2169. static PyMethodDef py_init_methoddef;
  2170. // };
  2171. PyOpDefEnd(BatchNormBackward)
  2172. int PyOp(BatchNormBackward)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  2173. static const char* kwlist[] = {"param_dim", "fwd_mode", "epsilon", "avg_factor", "scale", "bias", "scope", NULL};
  2174. PyObject *param_dim = NULL, *fwd_mode = NULL, *epsilon = NULL, *avg_factor = NULL, *scale = NULL, *bias = NULL, *scope = NULL;
  2175. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOO", const_cast<char**>(kwlist), &param_dim, &fwd_mode, &epsilon, &avg_factor, &scale, &bias, &scope))
  2176. return -1;
  2177. if (param_dim) {
  2178. try {
  2179. // TODO: remove this guard which is used for pybind11 implicit conversion
  2180. py::detail::loader_life_support guard{};
  2181. reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst().param_dim =
  2182. py::cast<decltype(BatchNormBackward::param_dim)>(py::handle(param_dim));
  2183. } CATCH_ALL(-1)
  2184. }
  2185. if (fwd_mode) {
  2186. try {
  2187. // TODO: remove this guard which is used for pybind11 implicit conversion
  2188. py::detail::loader_life_support guard{};
  2189. reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst().fwd_mode =
  2190. py::cast<decltype(BatchNormBackward::fwd_mode)>(py::handle(fwd_mode));
  2191. } CATCH_ALL(-1)
  2192. }
  2193. if (epsilon) {
  2194. try {
  2195. // TODO: remove this guard which is used for pybind11 implicit conversion
  2196. py::detail::loader_life_support guard{};
  2197. reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst().epsilon =
  2198. py::cast<decltype(BatchNormBackward::epsilon)>(py::handle(epsilon));
  2199. } CATCH_ALL(-1)
  2200. }
  2201. if (avg_factor) {
  2202. try {
  2203. // TODO: remove this guard which is used for pybind11 implicit conversion
  2204. py::detail::loader_life_support guard{};
  2205. reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst().avg_factor =
  2206. py::cast<decltype(BatchNormBackward::avg_factor)>(py::handle(avg_factor));
  2207. } CATCH_ALL(-1)
  2208. }
  2209. if (scale) {
  2210. try {
  2211. // TODO: remove this guard which is used for pybind11 implicit conversion
  2212. py::detail::loader_life_support guard{};
  2213. reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst().scale =
  2214. py::cast<decltype(BatchNormBackward::scale)>(py::handle(scale));
  2215. } CATCH_ALL(-1)
  2216. }
  2217. if (bias) {
  2218. try {
  2219. // TODO: remove this guard which is used for pybind11 implicit conversion
  2220. py::detail::loader_life_support guard{};
  2221. reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst().bias =
  2222. py::cast<decltype(BatchNormBackward::bias)>(py::handle(bias));
  2223. } CATCH_ALL(-1)
  2224. }
  2225. if (scope) {
  2226. try {
  2227. reinterpret_cast<PyOp(OpDef)*>(self)->op
  2228. ->set_scope(py::cast<std::string>(py::handle(scope)));
  2229. } CATCH_ALL(-1)
  2230. }
  2231. return 0;
  2232. }
  2233. PyGetSetDef PyOp(BatchNormBackward)::py_getsetters[] = {
  2234. {const_cast<char*>("param_dim"), py_get_generic(BatchNormBackward, param_dim), py_set_generic(BatchNormBackward, param_dim), const_cast<char*>("param_dim"), NULL},
  2235. {const_cast<char*>("fwd_mode"), py_get_generic(BatchNormBackward, fwd_mode), py_set_generic(BatchNormBackward, fwd_mode), const_cast<char*>("fwd_mode"), NULL},
  2236. {const_cast<char*>("epsilon"), py_get_generic(BatchNormBackward, epsilon), py_set_generic(BatchNormBackward, epsilon), const_cast<char*>("epsilon"), NULL},
  2237. {const_cast<char*>("avg_factor"), py_get_generic(BatchNormBackward, avg_factor), py_set_generic(BatchNormBackward, avg_factor), const_cast<char*>("avg_factor"), NULL},
  2238. {const_cast<char*>("scale"), py_get_generic(BatchNormBackward, scale), py_set_generic(BatchNormBackward, scale), const_cast<char*>("scale"), NULL},
  2239. {const_cast<char*>("bias"), py_get_generic(BatchNormBackward, bias), py_set_generic(BatchNormBackward, bias), const_cast<char*>("bias"), NULL},
  2240. {NULL} /* Sentinel */
  2241. };
  2242. PyMethodDef PyOp(BatchNormBackward)::tp_methods[] = {
  2243. {const_cast<char*>("__getstate__"), PyOp(BatchNormBackward)::getstate, METH_NOARGS, "BatchNormBackward getstate"},
  2244. {const_cast<char*>("__setstate__"), PyOp(BatchNormBackward)::setstate, METH_VARARGS, "BatchNormBackward setstate"},
  2245. {NULL} /* Sentinel */
  2246. };
  2247. PyObject *PyOp(BatchNormBackward)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  2248. if (PyOp(BatchNormBackward)::py_init(self, args, kwds) < 0) {
  2249. return NULL;
  2250. }
  2251. Py_RETURN_NONE;
  2252. }
  2253. PyMethodDef PyOp(BatchNormBackward)::py_init_methoddef = {
  2254. "__init__",
  2255. (PyCFunction)PyOp(BatchNormBackward)::py_init_proxy,
  2256. METH_VARARGS | METH_KEYWORDS,
  2257. "__init__(self, param_dim: Union[str, ParamDim] = ..., fwd_mode: Union[str, FwdMode] = ..., epsilon: float = ..., avg_factor: float = ..., scale: float = ..., bias: float = ...) -> None\n"
  2258. };
  2259. void _init_py_BatchNormBackward(py::module m) {
  2260. using py_op = PyOp(BatchNormBackward);
  2261. auto& py_type = PyOpType(BatchNormBackward);
  2262. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  2263. py_type.tp_name = "megengine.core._imperative_rt.ops.BatchNormBackward";
  2264. py_type.tp_basicsize = sizeof(PyOp(BatchNormBackward));
  2265. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  2266. py_type.tp_doc = "BatchNormBackward";
  2267. py_type.tp_base = &PyOpType(OpDef);
  2268. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  2269. py_type.tp_new = py_new_generic<py_op>;
  2270. py_type.tp_init = py_op::py_init;
  2271. py_type.tp_methods = py_op::tp_methods;
  2272. py_type.tp_getset = py_op::py_getsetters;
  2273. py_type.tp_dict = PyDict_New();
  2274. PyObject* descr = PyDescr_NewMethod(&PyOpType(BatchNormBackward), &PyOp(BatchNormBackward)::py_init_methoddef);
  2275. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  2276. mgb_assert(PyType_Ready(&py_type) >= 0);
  2277. _init_py_BatchNormBackward_ParamDim(py_type);
  2278. _init_py_BatchNormBackward_FwdMode(py_type);
  2279. PyType_Modified(&py_type);
  2280. m.add_object("BatchNormBackward", reinterpret_cast<PyObject*>(&py_type));
  2281. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchNormBackward::typeinfo(), &py_type).second);
  2282. }
  2283. PyOpDefBegin(BatchedIncrMeshIndexing) // {
  2284. static PyGetSetDef py_getsetters[];
  2285. static PyMethodDef tp_methods[];
  2286. static PyObject* getstate(PyObject* self, PyObject*) {
  2287. auto& opdef = reinterpret_cast<PyOp(BatchedIncrMeshIndexing)*>(self)->inst();
  2288. static_cast<void>(opdef);
  2289. std::unordered_map<std::string, py::object> state {
  2290. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  2291. };
  2292. return py::cast(state).release().ptr();
  2293. }
  2294. static PyObject* setstate(PyObject* self, PyObject* args) {
  2295. PyObject* dict = PyTuple_GetItem(args, 0);
  2296. if (!dict) return NULL;
  2297. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  2298. auto& opdef = reinterpret_cast<PyOp(BatchedIncrMeshIndexing)*>(self)->inst();
  2299. static_cast<void>(opdef);
  2300. {
  2301. auto&& iter = state.find("items");
  2302. if (iter != state.end()) {
  2303. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  2304. }
  2305. }
  2306. Py_RETURN_NONE;
  2307. }
  2308. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  2309. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  2310. static PyMethodDef py_init_methoddef;
  2311. // };
  2312. PyOpDefEnd(BatchedIncrMeshIndexing)
  2313. int PyOp(BatchedIncrMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  2314. static const char* kwlist[] = {"items", "scope", NULL};
  2315. PyObject *items = NULL, *scope = NULL;
  2316. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  2317. return -1;
  2318. if (items) {
  2319. try {
  2320. // TODO: remove this guard which is used for pybind11 implicit conversion
  2321. py::detail::loader_life_support guard{};
  2322. reinterpret_cast<PyOp(BatchedIncrMeshIndexing)*>(self)->inst().items =
  2323. py::cast<decltype(BatchedIncrMeshIndexing::items)>(py::handle(items));
  2324. } CATCH_ALL(-1)
  2325. }
  2326. if (scope) {
  2327. try {
  2328. reinterpret_cast<PyOp(OpDef)*>(self)->op
  2329. ->set_scope(py::cast<std::string>(py::handle(scope)));
  2330. } CATCH_ALL(-1)
  2331. }
  2332. return 0;
  2333. }
  2334. PyGetSetDef PyOp(BatchedIncrMeshIndexing)::py_getsetters[] = {
  2335. {const_cast<char*>("items"), py_get_generic(BatchedIncrMeshIndexing, items), py_set_generic(BatchedIncrMeshIndexing, items), const_cast<char*>("items"), NULL},
  2336. {NULL} /* Sentinel */
  2337. };
  2338. PyMethodDef PyOp(BatchedIncrMeshIndexing)::tp_methods[] = {
  2339. {const_cast<char*>("__getstate__"), PyOp(BatchedIncrMeshIndexing)::getstate, METH_NOARGS, "BatchedIncrMeshIndexing getstate"},
  2340. {const_cast<char*>("__setstate__"), PyOp(BatchedIncrMeshIndexing)::setstate, METH_VARARGS, "BatchedIncrMeshIndexing setstate"},
  2341. {NULL} /* Sentinel */
  2342. };
  2343. PyObject *PyOp(BatchedIncrMeshIndexing)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  2344. if (PyOp(BatchedIncrMeshIndexing)::py_init(self, args, kwds) < 0) {
  2345. return NULL;
  2346. }
  2347. Py_RETURN_NONE;
  2348. }
  2349. PyMethodDef PyOp(BatchedIncrMeshIndexing)::py_init_methoddef = {
  2350. "__init__",
  2351. (PyCFunction)PyOp(BatchedIncrMeshIndexing)::py_init_proxy,
  2352. METH_VARARGS | METH_KEYWORDS,
  2353. "__init__(self, items: list[tuple[int, bool, bool, bool, bool]] = ...) -> None\n"
  2354. };
  2355. void _init_py_BatchedIncrMeshIndexing(py::module m) {
  2356. using py_op = PyOp(BatchedIncrMeshIndexing);
  2357. auto& py_type = PyOpType(BatchedIncrMeshIndexing);
  2358. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  2359. py_type.tp_name = "megengine.core._imperative_rt.ops.BatchedIncrMeshIndexing";
  2360. py_type.tp_basicsize = sizeof(PyOp(BatchedIncrMeshIndexing));
  2361. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  2362. py_type.tp_doc = "BatchedIncrMeshIndexing";
  2363. py_type.tp_base = &PyOpType(OpDef);
  2364. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  2365. py_type.tp_new = py_new_generic<py_op>;
  2366. py_type.tp_init = py_op::py_init;
  2367. py_type.tp_methods = py_op::tp_methods;
  2368. py_type.tp_getset = py_op::py_getsetters;
  2369. py_type.tp_dict = PyDict_New();
  2370. PyObject* descr = PyDescr_NewMethod(&PyOpType(BatchedIncrMeshIndexing), &PyOp(BatchedIncrMeshIndexing)::py_init_methoddef);
  2371. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  2372. mgb_assert(PyType_Ready(&py_type) >= 0);
  2373. PyType_Modified(&py_type);
  2374. m.add_object("BatchedIncrMeshIndexing", reinterpret_cast<PyObject*>(&py_type));
  2375. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchedIncrMeshIndexing::typeinfo(), &py_type).second);
  2376. }
  2377. template<> struct EnumTrait<BatchedMatrixMul::ComputeMode> {
  2378. static constexpr const char *name = "BatchedMatrixMul.ComputeMode";
  2379. static constexpr std::underlying_type_t<BatchedMatrixMul::ComputeMode> max = 2 - 1;
  2380. };
  2381. template<> PyTypeObject* EnumWrapper<BatchedMatrixMul::ComputeMode>::type = nullptr;
  2382. template<> const char*
  2383. EnumWrapper<BatchedMatrixMul::ComputeMode>::members[] = {"DEFAULT", "FLOAT32"};
  2384. template<> std::unordered_map<std::string, BatchedMatrixMul::ComputeMode>
  2385. EnumWrapper<BatchedMatrixMul::ComputeMode>::mem2value = {{normalize_enum("DEFAULT"), BatchedMatrixMul::ComputeMode::DEFAULT}, {normalize_enum("FLOAT32"), BatchedMatrixMul::ComputeMode::FLOAT32}};
  2386. template<> PyObject* EnumWrapper<BatchedMatrixMul::ComputeMode>::pyobj_insts[2] = {nullptr};
  2387. void _init_py_BatchedMatrixMul_ComputeMode(PyTypeObject& py_type) {
  2388. auto& e_type = EnumWrapper<BatchedMatrixMul::ComputeMode>::type;
  2389. static PyMethodDef tp_methods[] = {
  2390. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchedMatrixMul::ComputeMode>::py_dump, METH_NOARGS, NULL},
  2391. {NULL} /* Sentinel */
  2392. };
  2393. static PyType_Slot slots[] = {
  2394. {Py_tp_repr, (void*)EnumWrapper<BatchedMatrixMul::ComputeMode>::py_repr},
  2395. {Py_tp_richcompare, (void*)EnumWrapper<BatchedMatrixMul::ComputeMode>::tp_richcompare},
  2396. {Py_tp_methods, tp_methods},
  2397. {0, NULL}
  2398. };
  2399. static PyType_Spec spec = {
  2400. // name
  2401. "megengine.core._imperative_rt.ops.BatchedMatrixMul.ComputeMode",
  2402. // basicsize
  2403. sizeof(EnumWrapper<BatchedMatrixMul::ComputeMode>),
  2404. // itemsize
  2405. 0,
  2406. // flags
  2407. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  2408. // slots
  2409. slots
  2410. };
  2411. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  2412. mgb_assert(
  2413. e_type->tp_setattro(
  2414. reinterpret_cast<PyObject*>(e_type),
  2415. py::cast("__name__").release().ptr(),
  2416. py::cast("ComputeMode").release().ptr()) >= 0);
  2417. mgb_assert(
  2418. e_type->tp_setattro(
  2419. reinterpret_cast<PyObject*>(e_type),
  2420. py::cast("__module__").release().ptr(),
  2421. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  2422. mgb_assert(
  2423. e_type->tp_setattro(
  2424. reinterpret_cast<PyObject*>(e_type),
  2425. py::cast("__qualname__").release().ptr(),
  2426. py::cast("BatchedMatrixMul.ComputeMode").release().ptr()) >= 0);
  2427. {
  2428. PyObject* inst = e_type->tp_alloc(e_type, 0);
  2429. reinterpret_cast<EnumWrapper<BatchedMatrixMul::ComputeMode>*>(inst)->value = BatchedMatrixMul::ComputeMode::DEFAULT;
  2430. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DEFAULT", inst) >= 0);
  2431. EnumWrapper<BatchedMatrixMul::ComputeMode>::pyobj_insts[0] = inst;
  2432. }{
  2433. PyObject* inst = e_type->tp_alloc(e_type, 0);
  2434. reinterpret_cast<EnumWrapper<BatchedMatrixMul::ComputeMode>*>(inst)->value = BatchedMatrixMul::ComputeMode::FLOAT32;
  2435. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT32", inst) >= 0);
  2436. EnumWrapper<BatchedMatrixMul::ComputeMode>::pyobj_insts[1] = inst;
  2437. }
  2438. Py_INCREF(e_type);
  2439. mgb_assert(PyDict_SetItemString(
  2440. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  2441. }
  2442. template<> struct EnumTrait<BatchedMatrixMul::Format> {
  2443. static constexpr const char *name = "BatchedMatrixMul.Format";
  2444. static constexpr std::underlying_type_t<BatchedMatrixMul::Format> max = 5 - 1;
  2445. };
  2446. template<> PyTypeObject* EnumWrapper<BatchedMatrixMul::Format>::type = nullptr;
  2447. template<> const char*
  2448. EnumWrapper<BatchedMatrixMul::Format>::members[] = {"DEFAULT", "MK4", "MK8", "MK4_DOT", "N32K4_DOT"};
  2449. template<> std::unordered_map<std::string, BatchedMatrixMul::Format>
  2450. EnumWrapper<BatchedMatrixMul::Format>::mem2value = {{normalize_enum("DEFAULT"), BatchedMatrixMul::Format::DEFAULT}, {normalize_enum("MK4"), BatchedMatrixMul::Format::MK4}, {normalize_enum("MK8"), BatchedMatrixMul::Format::MK8}, {normalize_enum("MK4_DOT"), BatchedMatrixMul::Format::MK4_DOT}, {normalize_enum("N32K4_DOT"), BatchedMatrixMul::Format::N32K4_DOT}};
  2451. template<> PyObject* EnumWrapper<BatchedMatrixMul::Format>::pyobj_insts[5] = {nullptr};
  2452. void _init_py_BatchedMatrixMul_Format(PyTypeObject& py_type) {
  2453. auto& e_type = EnumWrapper<BatchedMatrixMul::Format>::type;
  2454. static PyMethodDef tp_methods[] = {
  2455. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchedMatrixMul::Format>::py_dump, METH_NOARGS, NULL},
  2456. {NULL} /* Sentinel */
  2457. };
  2458. static PyType_Slot slots[] = {
  2459. {Py_tp_repr, (void*)EnumWrapper<BatchedMatrixMul::Format>::py_repr},
  2460. {Py_tp_richcompare, (void*)EnumWrapper<BatchedMatrixMul::Format>::tp_richcompare},
  2461. {Py_tp_methods, tp_methods},
  2462. {0, NULL}
  2463. };
  2464. static PyType_Spec spec = {
  2465. // name
  2466. "megengine.core._imperative_rt.ops.BatchedMatrixMul.Format",
  2467. // basicsize
  2468. sizeof(EnumWrapper<BatchedMatrixMul::Format>),
  2469. // itemsize
  2470. 0,
  2471. // flags
  2472. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  2473. // slots
  2474. slots
  2475. };
  2476. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  2477. mgb_assert(
  2478. e_type->tp_setattro(
  2479. reinterpret_cast<PyObject*>(e_type),
  2480. py::cast("__name__").release().ptr(),
  2481. py::cast("Format").release().ptr()) >= 0);
  2482. mgb_assert(
  2483. e_type->tp_setattro(
  2484. reinterpret_cast<PyObject*>(e_type),
  2485. py::cast("__module__").release().ptr(),
  2486. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  2487. mgb_assert(
  2488. e_type->tp_setattro(
  2489. reinterpret_cast<PyObject*>(e_type),
  2490. py::cast("__qualname__").release().ptr(),
  2491. py::cast("BatchedMatrixMul.Format").release().ptr()) >= 0);
  2492. {
  2493. PyObject* inst = e_type->tp_alloc(e_type, 0);
  2494. reinterpret_cast<EnumWrapper<BatchedMatrixMul::Format>*>(inst)->value = BatchedMatrixMul::Format::DEFAULT;
  2495. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DEFAULT", inst) >= 0);
  2496. EnumWrapper<BatchedMatrixMul::Format>::pyobj_insts[0] = inst;
  2497. }{
  2498. PyObject* inst = e_type->tp_alloc(e_type, 0);
  2499. reinterpret_cast<EnumWrapper<BatchedMatrixMul::Format>*>(inst)->value = BatchedMatrixMul::Format::MK4;
  2500. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MK4", inst) >= 0);
  2501. EnumWrapper<BatchedMatrixMul::Format>::pyobj_insts[1] = inst;
  2502. }{
  2503. PyObject* inst = e_type->tp_alloc(e_type, 0);
  2504. reinterpret_cast<EnumWrapper<BatchedMatrixMul::Format>*>(inst)->value = BatchedMatrixMul::Format::MK8;
  2505. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MK8", inst) >= 0);
  2506. EnumWrapper<BatchedMatrixMul::Format>::pyobj_insts[2] = inst;
  2507. }{
  2508. PyObject* inst = e_type->tp_alloc(e_type, 0);
  2509. reinterpret_cast<EnumWrapper<BatchedMatrixMul::Format>*>(inst)->value = BatchedMatrixMul::Format::MK4_DOT;
  2510. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MK4_DOT", inst) >= 0);
  2511. EnumWrapper<BatchedMatrixMul::Format>::pyobj_insts[3] = inst;
  2512. }{
  2513. PyObject* inst = e_type->tp_alloc(e_type, 0);
  2514. reinterpret_cast<EnumWrapper<BatchedMatrixMul::Format>*>(inst)->value = BatchedMatrixMul::Format::N32K4_DOT;
  2515. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "N32K4_DOT", inst) >= 0);
  2516. EnumWrapper<BatchedMatrixMul::Format>::pyobj_insts[4] = inst;
  2517. }
  2518. Py_INCREF(e_type);
  2519. mgb_assert(PyDict_SetItemString(
  2520. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  2521. }
  2522. void _init_py_BatchedMatrixMul_Strategy(PyTypeObject& py_type) {
  2523. auto& e_type = BitCombinedEnumWrapper<BatchedMatrixMul::Strategy>::type;
  2524. Py_INCREF(e_type);
  2525. mgb_assert(PyDict_SetItemString(
  2526. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  2527. }
  2528. PyOpDefBegin(BatchedMatrixMul) // {
  2529. static PyGetSetDef py_getsetters[];
  2530. static PyMethodDef tp_methods[];
  2531. static PyObject* getstate(PyObject* self, PyObject*) {
  2532. auto& opdef = reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst();
  2533. static_cast<void>(opdef);
  2534. std::unordered_map<std::string, py::object> state {
  2535. {"transposeA", serialization<decltype(opdef.transposeA)>::dump(opdef.transposeA)},
  2536. {"transposeB", serialization<decltype(opdef.transposeB)>::dump(opdef.transposeB)},
  2537. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  2538. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  2539. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  2540. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)},
  2541. {"dimA", serialization<decltype(opdef.dimA)>::dump(opdef.dimA)},
  2542. {"dimB", serialization<decltype(opdef.dimB)>::dump(opdef.dimB)}
  2543. };
  2544. return py::cast(state).release().ptr();
  2545. }
  2546. static PyObject* setstate(PyObject* self, PyObject* args) {
  2547. PyObject* dict = PyTuple_GetItem(args, 0);
  2548. if (!dict) return NULL;
  2549. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  2550. auto& opdef = reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst();
  2551. static_cast<void>(opdef);
  2552. {
  2553. auto&& iter = state.find("transposeA");
  2554. if (iter != state.end()) {
  2555. opdef.transposeA = serialization<decltype(opdef.transposeA)>::load(iter->second);
  2556. }
  2557. }
  2558. {
  2559. auto&& iter = state.find("transposeB");
  2560. if (iter != state.end()) {
  2561. opdef.transposeB = serialization<decltype(opdef.transposeB)>::load(iter->second);
  2562. }
  2563. }
  2564. {
  2565. auto&& iter = state.find("compute_mode");
  2566. if (iter != state.end()) {
  2567. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  2568. }
  2569. }
  2570. {
  2571. auto&& iter = state.find("format");
  2572. if (iter != state.end()) {
  2573. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  2574. }
  2575. }
  2576. {
  2577. auto&& iter = state.find("strategy");
  2578. if (iter != state.end()) {
  2579. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  2580. }
  2581. }
  2582. {
  2583. auto&& iter = state.find("workspace_limit");
  2584. if (iter != state.end()) {
  2585. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  2586. }
  2587. }
  2588. {
  2589. auto&& iter = state.find("dimA");
  2590. if (iter != state.end()) {
  2591. opdef.dimA = serialization<decltype(opdef.dimA)>::load(iter->second);
  2592. }
  2593. }
  2594. {
  2595. auto&& iter = state.find("dimB");
  2596. if (iter != state.end()) {
  2597. opdef.dimB = serialization<decltype(opdef.dimB)>::load(iter->second);
  2598. }
  2599. }
  2600. Py_RETURN_NONE;
  2601. }
  2602. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  2603. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  2604. static PyMethodDef py_init_methoddef;
  2605. // };
  2606. PyOpDefEnd(BatchedMatrixMul)
  2607. int PyOp(BatchedMatrixMul)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  2608. static const char* kwlist[] = {"transposeA", "transposeB", "compute_mode", "format", "strategy", "workspace_limit", "dimA", "dimB", "scope", NULL};
  2609. PyObject *transposeA = NULL, *transposeB = NULL, *compute_mode = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *dimA = NULL, *dimB = NULL, *scope = NULL;
  2610. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &transposeA, &transposeB, &compute_mode, &format, &strategy, &workspace_limit, &dimA, &dimB, &scope))
  2611. return -1;
  2612. if (transposeA) {
  2613. try {
  2614. // TODO: remove this guard which is used for pybind11 implicit conversion
  2615. py::detail::loader_life_support guard{};
  2616. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().transposeA =
  2617. py::cast<decltype(BatchedMatrixMul::transposeA)>(py::handle(transposeA));
  2618. } CATCH_ALL(-1)
  2619. }
  2620. if (transposeB) {
  2621. try {
  2622. // TODO: remove this guard which is used for pybind11 implicit conversion
  2623. py::detail::loader_life_support guard{};
  2624. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().transposeB =
  2625. py::cast<decltype(BatchedMatrixMul::transposeB)>(py::handle(transposeB));
  2626. } CATCH_ALL(-1)
  2627. }
  2628. if (compute_mode) {
  2629. try {
  2630. // TODO: remove this guard which is used for pybind11 implicit conversion
  2631. py::detail::loader_life_support guard{};
  2632. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().compute_mode =
  2633. py::cast<decltype(BatchedMatrixMul::compute_mode)>(py::handle(compute_mode));
  2634. } CATCH_ALL(-1)
  2635. }
  2636. if (format) {
  2637. try {
  2638. // TODO: remove this guard which is used for pybind11 implicit conversion
  2639. py::detail::loader_life_support guard{};
  2640. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().format =
  2641. py::cast<decltype(BatchedMatrixMul::format)>(py::handle(format));
  2642. } CATCH_ALL(-1)
  2643. }
  2644. if (strategy) {
  2645. try {
  2646. // TODO: remove this guard which is used for pybind11 implicit conversion
  2647. py::detail::loader_life_support guard{};
  2648. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().strategy =
  2649. py::cast<decltype(BatchedMatrixMul::strategy)>(py::handle(strategy));
  2650. } CATCH_ALL(-1)
  2651. }
  2652. if (workspace_limit) {
  2653. try {
  2654. // TODO: remove this guard which is used for pybind11 implicit conversion
  2655. py::detail::loader_life_support guard{};
  2656. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().workspace_limit =
  2657. py::cast<decltype(BatchedMatrixMul::workspace_limit)>(py::handle(workspace_limit));
  2658. } CATCH_ALL(-1)
  2659. }
  2660. if (dimA) {
  2661. try {
  2662. // TODO: remove this guard which is used for pybind11 implicit conversion
  2663. py::detail::loader_life_support guard{};
  2664. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().dimA =
  2665. py::cast<decltype(BatchedMatrixMul::dimA)>(py::handle(dimA));
  2666. } CATCH_ALL(-1)
  2667. }
  2668. if (dimB) {
  2669. try {
  2670. // TODO: remove this guard which is used for pybind11 implicit conversion
  2671. py::detail::loader_life_support guard{};
  2672. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().dimB =
  2673. py::cast<decltype(BatchedMatrixMul::dimB)>(py::handle(dimB));
  2674. } CATCH_ALL(-1)
  2675. }
  2676. if (scope) {
  2677. try {
  2678. reinterpret_cast<PyOp(OpDef)*>(self)->op
  2679. ->set_scope(py::cast<std::string>(py::handle(scope)));
  2680. } CATCH_ALL(-1)
  2681. }
  2682. return 0;
  2683. }
  2684. PyGetSetDef PyOp(BatchedMatrixMul)::py_getsetters[] = {
  2685. {const_cast<char*>("transposeA"), py_get_generic(BatchedMatrixMul, transposeA), py_set_generic(BatchedMatrixMul, transposeA), const_cast<char*>("transposeA"), NULL},
  2686. {const_cast<char*>("transposeB"), py_get_generic(BatchedMatrixMul, transposeB), py_set_generic(BatchedMatrixMul, transposeB), const_cast<char*>("transposeB"), NULL},
  2687. {const_cast<char*>("compute_mode"), py_get_generic(BatchedMatrixMul, compute_mode), py_set_generic(BatchedMatrixMul, compute_mode), const_cast<char*>("compute_mode"), NULL},
  2688. {const_cast<char*>("format"), py_get_generic(BatchedMatrixMul, format), py_set_generic(BatchedMatrixMul, format), const_cast<char*>("format"), NULL},
  2689. {const_cast<char*>("strategy"), py_get_generic(BatchedMatrixMul, strategy), py_set_generic(BatchedMatrixMul, strategy), const_cast<char*>("strategy"), NULL},
  2690. {const_cast<char*>("workspace_limit"), py_get_generic(BatchedMatrixMul, workspace_limit), py_set_generic(BatchedMatrixMul, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  2691. {const_cast<char*>("dimA"), py_get_generic(BatchedMatrixMul, dimA), py_set_generic(BatchedMatrixMul, dimA), const_cast<char*>("dimA"), NULL},
  2692. {const_cast<char*>("dimB"), py_get_generic(BatchedMatrixMul, dimB), py_set_generic(BatchedMatrixMul, dimB), const_cast<char*>("dimB"), NULL},
  2693. {NULL} /* Sentinel */
  2694. };
  2695. PyMethodDef PyOp(BatchedMatrixMul)::tp_methods[] = {
  2696. {const_cast<char*>("__getstate__"), PyOp(BatchedMatrixMul)::getstate, METH_NOARGS, "BatchedMatrixMul getstate"},
  2697. {const_cast<char*>("__setstate__"), PyOp(BatchedMatrixMul)::setstate, METH_VARARGS, "BatchedMatrixMul setstate"},
  2698. {NULL} /* Sentinel */
  2699. };
  2700. PyObject *PyOp(BatchedMatrixMul)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  2701. if (PyOp(BatchedMatrixMul)::py_init(self, args, kwds) < 0) {
  2702. return NULL;
  2703. }
  2704. Py_RETURN_NONE;
  2705. }
  2706. PyMethodDef PyOp(BatchedMatrixMul)::py_init_methoddef = {
  2707. "__init__",
  2708. (PyCFunction)PyOp(BatchedMatrixMul)::py_init_proxy,
  2709. METH_VARARGS | METH_KEYWORDS,
  2710. "__init__(self, transposeA: bool = ..., transposeB: bool = ..., compute_mode: Union[str, ComputeMode] = ..., format: Union[str, Format] = ..., strategy: Union[str, Strategy] = ..., dimA: int = ..., dimB: int = ...) -> None\n"
  2711. };
  2712. void _init_py_BatchedMatrixMul(py::module m) {
  2713. using py_op = PyOp(BatchedMatrixMul);
  2714. auto& py_type = PyOpType(BatchedMatrixMul);
  2715. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  2716. py_type.tp_name = "megengine.core._imperative_rt.ops.BatchedMatrixMul";
  2717. py_type.tp_basicsize = sizeof(PyOp(BatchedMatrixMul));
  2718. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  2719. py_type.tp_doc = "BatchedMatrixMul";
  2720. py_type.tp_base = &PyOpType(OpDef);
  2721. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  2722. py_type.tp_new = py_new_generic<py_op>;
  2723. py_type.tp_init = py_op::py_init;
  2724. py_type.tp_methods = py_op::tp_methods;
  2725. py_type.tp_getset = py_op::py_getsetters;
  2726. py_type.tp_dict = PyDict_New();
  2727. PyObject* descr = PyDescr_NewMethod(&PyOpType(BatchedMatrixMul), &PyOp(BatchedMatrixMul)::py_init_methoddef);
  2728. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  2729. mgb_assert(PyType_Ready(&py_type) >= 0);
  2730. _init_py_BatchedMatrixMul_ComputeMode(py_type);
  2731. _init_py_BatchedMatrixMul_Format(py_type);
  2732. _init_py_BatchedMatrixMul_Strategy(py_type);
  2733. PyType_Modified(&py_type);
  2734. m.add_object("BatchedMatrixMul", reinterpret_cast<PyObject*>(&py_type));
  2735. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchedMatrixMul::typeinfo(), &py_type).second);
  2736. }
  2737. PyOpDefBegin(BatchedMeshIndexing) // {
  2738. static PyGetSetDef py_getsetters[];
  2739. static PyMethodDef tp_methods[];
  2740. static PyObject* getstate(PyObject* self, PyObject*) {
  2741. auto& opdef = reinterpret_cast<PyOp(BatchedMeshIndexing)*>(self)->inst();
  2742. static_cast<void>(opdef);
  2743. std::unordered_map<std::string, py::object> state {
  2744. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  2745. };
  2746. return py::cast(state).release().ptr();
  2747. }
  2748. static PyObject* setstate(PyObject* self, PyObject* args) {
  2749. PyObject* dict = PyTuple_GetItem(args, 0);
  2750. if (!dict) return NULL;
  2751. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  2752. auto& opdef = reinterpret_cast<PyOp(BatchedMeshIndexing)*>(self)->inst();
  2753. static_cast<void>(opdef);
  2754. {
  2755. auto&& iter = state.find("items");
  2756. if (iter != state.end()) {
  2757. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  2758. }
  2759. }
  2760. Py_RETURN_NONE;
  2761. }
  2762. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  2763. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  2764. static PyMethodDef py_init_methoddef;
  2765. // };
  2766. PyOpDefEnd(BatchedMeshIndexing)
  2767. int PyOp(BatchedMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  2768. static const char* kwlist[] = {"items", "scope", NULL};
  2769. PyObject *items = NULL, *scope = NULL;
  2770. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  2771. return -1;
  2772. if (items) {
  2773. try {
  2774. // TODO: remove this guard which is used for pybind11 implicit conversion
  2775. py::detail::loader_life_support guard{};
  2776. reinterpret_cast<PyOp(BatchedMeshIndexing)*>(self)->inst().items =
  2777. py::cast<decltype(BatchedMeshIndexing::items)>(py::handle(items));
  2778. } CATCH_ALL(-1)
  2779. }
  2780. if (scope) {
  2781. try {
  2782. reinterpret_cast<PyOp(OpDef)*>(self)->op
  2783. ->set_scope(py::cast<std::string>(py::handle(scope)));
  2784. } CATCH_ALL(-1)
  2785. }
  2786. return 0;
  2787. }
  2788. PyGetSetDef PyOp(BatchedMeshIndexing)::py_getsetters[] = {
  2789. {const_cast<char*>("items"), py_get_generic(BatchedMeshIndexing, items), py_set_generic(BatchedMeshIndexing, items), const_cast<char*>("items"), NULL},
  2790. {NULL} /* Sentinel */
  2791. };
  2792. PyMethodDef PyOp(BatchedMeshIndexing)::tp_methods[] = {
  2793. {const_cast<char*>("__getstate__"), PyOp(BatchedMeshIndexing)::getstate, METH_NOARGS, "BatchedMeshIndexing getstate"},
  2794. {const_cast<char*>("__setstate__"), PyOp(BatchedMeshIndexing)::setstate, METH_VARARGS, "BatchedMeshIndexing setstate"},
  2795. {NULL} /* Sentinel */
  2796. };
  2797. PyObject *PyOp(BatchedMeshIndexing)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  2798. if (PyOp(BatchedMeshIndexing)::py_init(self, args, kwds) < 0) {
  2799. return NULL;
  2800. }
  2801. Py_RETURN_NONE;
  2802. }
  2803. PyMethodDef PyOp(BatchedMeshIndexing)::py_init_methoddef = {
  2804. "__init__",
  2805. (PyCFunction)PyOp(BatchedMeshIndexing)::py_init_proxy,
  2806. METH_VARARGS | METH_KEYWORDS,
  2807. "__init__(self, items: list[tuple[int, bool, bool, bool, bool]] = ...) -> None\n"
  2808. };
  2809. void _init_py_BatchedMeshIndexing(py::module m) {
  2810. using py_op = PyOp(BatchedMeshIndexing);
  2811. auto& py_type = PyOpType(BatchedMeshIndexing);
  2812. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  2813. py_type.tp_name = "megengine.core._imperative_rt.ops.BatchedMeshIndexing";
  2814. py_type.tp_basicsize = sizeof(PyOp(BatchedMeshIndexing));
  2815. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  2816. py_type.tp_doc = "BatchedMeshIndexing";
  2817. py_type.tp_base = &PyOpType(OpDef);
  2818. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  2819. py_type.tp_new = py_new_generic<py_op>;
  2820. py_type.tp_init = py_op::py_init;
  2821. py_type.tp_methods = py_op::tp_methods;
  2822. py_type.tp_getset = py_op::py_getsetters;
  2823. py_type.tp_dict = PyDict_New();
  2824. PyObject* descr = PyDescr_NewMethod(&PyOpType(BatchedMeshIndexing), &PyOp(BatchedMeshIndexing)::py_init_methoddef);
  2825. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  2826. mgb_assert(PyType_Ready(&py_type) >= 0);
  2827. PyType_Modified(&py_type);
  2828. m.add_object("BatchedMeshIndexing", reinterpret_cast<PyObject*>(&py_type));
  2829. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchedMeshIndexing::typeinfo(), &py_type).second);
  2830. }
  2831. PyOpDefBegin(BatchedSetMeshIndexing) // {
  2832. static PyGetSetDef py_getsetters[];
  2833. static PyMethodDef tp_methods[];
  2834. static PyObject* getstate(PyObject* self, PyObject*) {
  2835. auto& opdef = reinterpret_cast<PyOp(BatchedSetMeshIndexing)*>(self)->inst();
  2836. static_cast<void>(opdef);
  2837. std::unordered_map<std::string, py::object> state {
  2838. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  2839. };
  2840. return py::cast(state).release().ptr();
  2841. }
  2842. static PyObject* setstate(PyObject* self, PyObject* args) {
  2843. PyObject* dict = PyTuple_GetItem(args, 0);
  2844. if (!dict) return NULL;
  2845. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  2846. auto& opdef = reinterpret_cast<PyOp(BatchedSetMeshIndexing)*>(self)->inst();
  2847. static_cast<void>(opdef);
  2848. {
  2849. auto&& iter = state.find("items");
  2850. if (iter != state.end()) {
  2851. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  2852. }
  2853. }
  2854. Py_RETURN_NONE;
  2855. }
  2856. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  2857. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  2858. static PyMethodDef py_init_methoddef;
  2859. // };
  2860. PyOpDefEnd(BatchedSetMeshIndexing)
  2861. int PyOp(BatchedSetMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  2862. static const char* kwlist[] = {"items", "scope", NULL};
  2863. PyObject *items = NULL, *scope = NULL;
  2864. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  2865. return -1;
  2866. if (items) {
  2867. try {
  2868. // TODO: remove this guard which is used for pybind11 implicit conversion
  2869. py::detail::loader_life_support guard{};
  2870. reinterpret_cast<PyOp(BatchedSetMeshIndexing)*>(self)->inst().items =
  2871. py::cast<decltype(BatchedSetMeshIndexing::items)>(py::handle(items));
  2872. } CATCH_ALL(-1)
  2873. }
  2874. if (scope) {
  2875. try {
  2876. reinterpret_cast<PyOp(OpDef)*>(self)->op
  2877. ->set_scope(py::cast<std::string>(py::handle(scope)));
  2878. } CATCH_ALL(-1)
  2879. }
  2880. return 0;
  2881. }
  2882. PyGetSetDef PyOp(BatchedSetMeshIndexing)::py_getsetters[] = {
  2883. {const_cast<char*>("items"), py_get_generic(BatchedSetMeshIndexing, items), py_set_generic(BatchedSetMeshIndexing, items), const_cast<char*>("items"), NULL},
  2884. {NULL} /* Sentinel */
  2885. };
  2886. PyMethodDef PyOp(BatchedSetMeshIndexing)::tp_methods[] = {
  2887. {const_cast<char*>("__getstate__"), PyOp(BatchedSetMeshIndexing)::getstate, METH_NOARGS, "BatchedSetMeshIndexing getstate"},
  2888. {const_cast<char*>("__setstate__"), PyOp(BatchedSetMeshIndexing)::setstate, METH_VARARGS, "BatchedSetMeshIndexing setstate"},
  2889. {NULL} /* Sentinel */
  2890. };
  2891. PyObject *PyOp(BatchedSetMeshIndexing)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  2892. if (PyOp(BatchedSetMeshIndexing)::py_init(self, args, kwds) < 0) {
  2893. return NULL;
  2894. }
  2895. Py_RETURN_NONE;
  2896. }
  2897. PyMethodDef PyOp(BatchedSetMeshIndexing)::py_init_methoddef = {
  2898. "__init__",
  2899. (PyCFunction)PyOp(BatchedSetMeshIndexing)::py_init_proxy,
  2900. METH_VARARGS | METH_KEYWORDS,
  2901. "__init__(self, items: list[tuple[int, bool, bool, bool, bool]] = ...) -> None\n"
  2902. };
  2903. void _init_py_BatchedSetMeshIndexing(py::module m) {
  2904. using py_op = PyOp(BatchedSetMeshIndexing);
  2905. auto& py_type = PyOpType(BatchedSetMeshIndexing);
  2906. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  2907. py_type.tp_name = "megengine.core._imperative_rt.ops.BatchedSetMeshIndexing";
  2908. py_type.tp_basicsize = sizeof(PyOp(BatchedSetMeshIndexing));
  2909. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  2910. py_type.tp_doc = "BatchedSetMeshIndexing";
  2911. py_type.tp_base = &PyOpType(OpDef);
  2912. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  2913. py_type.tp_new = py_new_generic<py_op>;
  2914. py_type.tp_init = py_op::py_init;
  2915. py_type.tp_methods = py_op::tp_methods;
  2916. py_type.tp_getset = py_op::py_getsetters;
  2917. py_type.tp_dict = PyDict_New();
  2918. PyObject* descr = PyDescr_NewMethod(&PyOpType(BatchedSetMeshIndexing), &PyOp(BatchedSetMeshIndexing)::py_init_methoddef);
  2919. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  2920. mgb_assert(PyType_Ready(&py_type) >= 0);
  2921. PyType_Modified(&py_type);
  2922. m.add_object("BatchedSetMeshIndexing", reinterpret_cast<PyObject*>(&py_type));
  2923. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchedSetMeshIndexing::typeinfo(), &py_type).second);
  2924. }
  2925. PyOpDefBegin(BetaRNG) // {
  2926. static PyGetSetDef py_getsetters[];
  2927. static PyMethodDef tp_methods[];
  2928. static PyObject* getstate(PyObject* self, PyObject*) {
  2929. auto& opdef = reinterpret_cast<PyOp(BetaRNG)*>(self)->inst();
  2930. static_cast<void>(opdef);
  2931. std::unordered_map<std::string, py::object> state {
  2932. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  2933. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  2934. };
  2935. return py::cast(state).release().ptr();
  2936. }
  2937. static PyObject* setstate(PyObject* self, PyObject* args) {
  2938. PyObject* dict = PyTuple_GetItem(args, 0);
  2939. if (!dict) return NULL;
  2940. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  2941. auto& opdef = reinterpret_cast<PyOp(BetaRNG)*>(self)->inst();
  2942. static_cast<void>(opdef);
  2943. {
  2944. auto&& iter = state.find("seed");
  2945. if (iter != state.end()) {
  2946. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  2947. }
  2948. }
  2949. {
  2950. auto&& iter = state.find("handle");
  2951. if (iter != state.end()) {
  2952. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  2953. }
  2954. }
  2955. Py_RETURN_NONE;
  2956. }
  2957. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  2958. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  2959. static PyMethodDef py_init_methoddef;
  2960. // };
  2961. PyOpDefEnd(BetaRNG)
  2962. int PyOp(BetaRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  2963. static const char* kwlist[] = {"seed", "handle", "scope", NULL};
  2964. PyObject *seed = NULL, *handle = NULL, *scope = NULL;
  2965. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &seed, &handle, &scope))
  2966. return -1;
  2967. if (seed) {
  2968. try {
  2969. // TODO: remove this guard which is used for pybind11 implicit conversion
  2970. py::detail::loader_life_support guard{};
  2971. reinterpret_cast<PyOp(BetaRNG)*>(self)->inst().seed =
  2972. py::cast<decltype(BetaRNG::seed)>(py::handle(seed));
  2973. } CATCH_ALL(-1)
  2974. }
  2975. if (handle) {
  2976. try {
  2977. // TODO: remove this guard which is used for pybind11 implicit conversion
  2978. py::detail::loader_life_support guard{};
  2979. reinterpret_cast<PyOp(BetaRNG)*>(self)->inst().handle =
  2980. py::cast<decltype(BetaRNG::handle)>(py::handle(handle));
  2981. } CATCH_ALL(-1)
  2982. }
  2983. if (scope) {
  2984. try {
  2985. reinterpret_cast<PyOp(OpDef)*>(self)->op
  2986. ->set_scope(py::cast<std::string>(py::handle(scope)));
  2987. } CATCH_ALL(-1)
  2988. }
  2989. return 0;
  2990. }
  2991. PyGetSetDef PyOp(BetaRNG)::py_getsetters[] = {
  2992. {const_cast<char*>("seed"), py_get_generic(BetaRNG, seed), py_set_generic(BetaRNG, seed), const_cast<char*>("seed"), NULL},
  2993. {const_cast<char*>("handle"), py_get_generic(BetaRNG, handle), py_set_generic(BetaRNG, handle), const_cast<char*>("handle"), NULL},
  2994. {NULL} /* Sentinel */
  2995. };
  2996. PyMethodDef PyOp(BetaRNG)::tp_methods[] = {
  2997. {const_cast<char*>("__getstate__"), PyOp(BetaRNG)::getstate, METH_NOARGS, "BetaRNG getstate"},
  2998. {const_cast<char*>("__setstate__"), PyOp(BetaRNG)::setstate, METH_VARARGS, "BetaRNG setstate"},
  2999. {NULL} /* Sentinel */
  3000. };
  3001. PyObject *PyOp(BetaRNG)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  3002. if (PyOp(BetaRNG)::py_init(self, args, kwds) < 0) {
  3003. return NULL;
  3004. }
  3005. Py_RETURN_NONE;
  3006. }
  3007. PyMethodDef PyOp(BetaRNG)::py_init_methoddef = {
  3008. "__init__",
  3009. (PyCFunction)PyOp(BetaRNG)::py_init_proxy,
  3010. METH_VARARGS | METH_KEYWORDS,
  3011. "__init__(self, seed: int = ..., handle: int = ...) -> None\n"
  3012. };
  3013. void _init_py_BetaRNG(py::module m) {
  3014. using py_op = PyOp(BetaRNG);
  3015. auto& py_type = PyOpType(BetaRNG);
  3016. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  3017. py_type.tp_name = "megengine.core._imperative_rt.ops.BetaRNG";
  3018. py_type.tp_basicsize = sizeof(PyOp(BetaRNG));
  3019. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  3020. py_type.tp_doc = "BetaRNG";
  3021. py_type.tp_base = &PyOpType(OpDef);
  3022. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  3023. py_type.tp_new = py_new_generic<py_op>;
  3024. py_type.tp_init = py_op::py_init;
  3025. py_type.tp_methods = py_op::tp_methods;
  3026. py_type.tp_getset = py_op::py_getsetters;
  3027. py_type.tp_dict = PyDict_New();
  3028. PyObject* descr = PyDescr_NewMethod(&PyOpType(BetaRNG), &PyOp(BetaRNG)::py_init_methoddef);
  3029. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  3030. mgb_assert(PyType_Ready(&py_type) >= 0);
  3031. PyType_Modified(&py_type);
  3032. m.add_object("BetaRNG", reinterpret_cast<PyObject*>(&py_type));
  3033. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BetaRNG::typeinfo(), &py_type).second);
  3034. }
  3035. PyOpDefBegin(Borrow) // {
  3036. static PyGetSetDef py_getsetters[];
  3037. static PyMethodDef tp_methods[];
  3038. static PyObject* getstate(PyObject* self, PyObject*) {
  3039. auto& opdef = reinterpret_cast<PyOp(Borrow)*>(self)->inst();
  3040. static_cast<void>(opdef);
  3041. std::unordered_map<std::string, py::object> state {
  3042. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)}
  3043. };
  3044. return py::cast(state).release().ptr();
  3045. }
  3046. static PyObject* setstate(PyObject* self, PyObject* args) {
  3047. PyObject* dict = PyTuple_GetItem(args, 0);
  3048. if (!dict) return NULL;
  3049. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  3050. auto& opdef = reinterpret_cast<PyOp(Borrow)*>(self)->inst();
  3051. static_cast<void>(opdef);
  3052. {
  3053. auto&& iter = state.find("comp_node");
  3054. if (iter != state.end()) {
  3055. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  3056. }
  3057. }
  3058. Py_RETURN_NONE;
  3059. }
  3060. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  3061. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  3062. static PyMethodDef py_init_methoddef;
  3063. // };
  3064. PyOpDefEnd(Borrow)
  3065. int PyOp(Borrow)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  3066. static const char* kwlist[] = {"comp_node", "scope", NULL};
  3067. PyObject *comp_node = NULL, *scope = NULL;
  3068. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &comp_node, &scope))
  3069. return -1;
  3070. if (comp_node) {
  3071. try {
  3072. // TODO: remove this guard which is used for pybind11 implicit conversion
  3073. py::detail::loader_life_support guard{};
  3074. reinterpret_cast<PyOp(Borrow)*>(self)->inst().comp_node =
  3075. py::cast<decltype(Borrow::comp_node)>(py::handle(comp_node));
  3076. } CATCH_ALL(-1)
  3077. }
  3078. if (scope) {
  3079. try {
  3080. reinterpret_cast<PyOp(OpDef)*>(self)->op
  3081. ->set_scope(py::cast<std::string>(py::handle(scope)));
  3082. } CATCH_ALL(-1)
  3083. }
  3084. return 0;
  3085. }
  3086. PyGetSetDef PyOp(Borrow)::py_getsetters[] = {
  3087. {const_cast<char*>("comp_node"), py_get_generic(Borrow, comp_node), py_set_generic(Borrow, comp_node), const_cast<char*>("comp_node"), NULL},
  3088. {NULL} /* Sentinel */
  3089. };
  3090. PyMethodDef PyOp(Borrow)::tp_methods[] = {
  3091. {const_cast<char*>("__getstate__"), PyOp(Borrow)::getstate, METH_NOARGS, "Borrow getstate"},
  3092. {const_cast<char*>("__setstate__"), PyOp(Borrow)::setstate, METH_VARARGS, "Borrow setstate"},
  3093. {NULL} /* Sentinel */
  3094. };
  3095. PyObject *PyOp(Borrow)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  3096. if (PyOp(Borrow)::py_init(self, args, kwds) < 0) {
  3097. return NULL;
  3098. }
  3099. Py_RETURN_NONE;
  3100. }
  3101. PyMethodDef PyOp(Borrow)::py_init_methoddef = {
  3102. "__init__",
  3103. (PyCFunction)PyOp(Borrow)::py_init_proxy,
  3104. METH_VARARGS | METH_KEYWORDS,
  3105. "__init__(self, comp_node: str = ...) -> None\n"
  3106. };
  3107. void _init_py_Borrow(py::module m) {
  3108. using py_op = PyOp(Borrow);
  3109. auto& py_type = PyOpType(Borrow);
  3110. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  3111. py_type.tp_name = "megengine.core._imperative_rt.ops.Borrow";
  3112. py_type.tp_basicsize = sizeof(PyOp(Borrow));
  3113. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  3114. py_type.tp_doc = "Borrow";
  3115. py_type.tp_base = &PyOpType(OpDef);
  3116. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  3117. py_type.tp_new = py_new_generic<py_op>;
  3118. py_type.tp_init = py_op::py_init;
  3119. py_type.tp_methods = py_op::tp_methods;
  3120. py_type.tp_getset = py_op::py_getsetters;
  3121. py_type.tp_dict = PyDict_New();
  3122. PyObject* descr = PyDescr_NewMethod(&PyOpType(Borrow), &PyOp(Borrow)::py_init_methoddef);
  3123. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  3124. mgb_assert(PyType_Ready(&py_type) >= 0);
  3125. PyType_Modified(&py_type);
  3126. m.add_object("Borrow", reinterpret_cast<PyObject*>(&py_type));
  3127. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Borrow::typeinfo(), &py_type).second);
  3128. }
  3129. PyOpDefBegin(Broadcast) // {
  3130. static PyGetSetDef py_getsetters[];
  3131. static PyMethodDef tp_methods[];
  3132. static PyObject* getstate(PyObject* self, PyObject*) {
  3133. auto& opdef = reinterpret_cast<PyOp(Broadcast)*>(self)->inst();
  3134. static_cast<void>(opdef);
  3135. std::unordered_map<std::string, py::object> state {
  3136. {"shape", serialization<decltype(opdef.shape)>::dump(opdef.shape)}
  3137. };
  3138. return py::cast(state).release().ptr();
  3139. }
  3140. static PyObject* setstate(PyObject* self, PyObject* args) {
  3141. PyObject* dict = PyTuple_GetItem(args, 0);
  3142. if (!dict) return NULL;
  3143. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  3144. auto& opdef = reinterpret_cast<PyOp(Broadcast)*>(self)->inst();
  3145. static_cast<void>(opdef);
  3146. {
  3147. auto&& iter = state.find("shape");
  3148. if (iter != state.end()) {
  3149. opdef.shape = serialization<decltype(opdef.shape)>::load(iter->second);
  3150. }
  3151. }
  3152. Py_RETURN_NONE;
  3153. }
  3154. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  3155. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  3156. static PyMethodDef py_init_methoddef;
  3157. // };
  3158. PyOpDefEnd(Broadcast)
  3159. int PyOp(Broadcast)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  3160. static const char* kwlist[] = {"shape", "scope", NULL};
  3161. PyObject *shape = NULL, *scope = NULL;
  3162. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &shape, &scope))
  3163. return -1;
  3164. if (shape) {
  3165. try {
  3166. // TODO: remove this guard which is used for pybind11 implicit conversion
  3167. py::detail::loader_life_support guard{};
  3168. reinterpret_cast<PyOp(Broadcast)*>(self)->inst().shape =
  3169. py::cast<decltype(Broadcast::shape)>(py::handle(shape));
  3170. } CATCH_ALL(-1)
  3171. }
  3172. if (scope) {
  3173. try {
  3174. reinterpret_cast<PyOp(OpDef)*>(self)->op
  3175. ->set_scope(py::cast<std::string>(py::handle(scope)));
  3176. } CATCH_ALL(-1)
  3177. }
  3178. return 0;
  3179. }
  3180. PyGetSetDef PyOp(Broadcast)::py_getsetters[] = {
  3181. {const_cast<char*>("shape"), py_get_generic(Broadcast, shape), py_set_generic(Broadcast, shape), const_cast<char*>("shape"), NULL},
  3182. {NULL} /* Sentinel */
  3183. };
  3184. PyMethodDef PyOp(Broadcast)::tp_methods[] = {
  3185. {const_cast<char*>("__getstate__"), PyOp(Broadcast)::getstate, METH_NOARGS, "Broadcast getstate"},
  3186. {const_cast<char*>("__setstate__"), PyOp(Broadcast)::setstate, METH_VARARGS, "Broadcast setstate"},
  3187. {NULL} /* Sentinel */
  3188. };
  3189. PyObject *PyOp(Broadcast)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  3190. if (PyOp(Broadcast)::py_init(self, args, kwds) < 0) {
  3191. return NULL;
  3192. }
  3193. Py_RETURN_NONE;
  3194. }
  3195. PyMethodDef PyOp(Broadcast)::py_init_methoddef = {
  3196. "__init__",
  3197. (PyCFunction)PyOp(Broadcast)::py_init_proxy,
  3198. METH_VARARGS | METH_KEYWORDS,
  3199. "__init__(self, shape: list[int] = ...) -> None\n"
  3200. };
  3201. void _init_py_Broadcast(py::module m) {
  3202. using py_op = PyOp(Broadcast);
  3203. auto& py_type = PyOpType(Broadcast);
  3204. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  3205. py_type.tp_name = "megengine.core._imperative_rt.ops.Broadcast";
  3206. py_type.tp_basicsize = sizeof(PyOp(Broadcast));
  3207. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  3208. py_type.tp_doc = "Broadcast";
  3209. py_type.tp_base = &PyOpType(OpDef);
  3210. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  3211. py_type.tp_new = py_new_generic<py_op>;
  3212. py_type.tp_init = py_op::py_init;
  3213. py_type.tp_methods = py_op::tp_methods;
  3214. py_type.tp_getset = py_op::py_getsetters;
  3215. py_type.tp_dict = PyDict_New();
  3216. PyObject* descr = PyDescr_NewMethod(&PyOpType(Broadcast), &PyOp(Broadcast)::py_init_methoddef);
  3217. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  3218. mgb_assert(PyType_Ready(&py_type) >= 0);
  3219. PyType_Modified(&py_type);
  3220. m.add_object("Broadcast", reinterpret_cast<PyObject*>(&py_type));
  3221. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Broadcast::typeinfo(), &py_type).second);
  3222. }
  3223. PyOpDefBegin(CambriconRuntime) // {
  3224. static PyGetSetDef py_getsetters[];
  3225. static PyMethodDef tp_methods[];
  3226. static PyObject* getstate(PyObject* self, PyObject*) {
  3227. auto& opdef = reinterpret_cast<PyOp(CambriconRuntime)*>(self)->inst();
  3228. static_cast<void>(opdef);
  3229. std::unordered_map<std::string, py::object> state {
  3230. {"buf", serialization<decltype(opdef.buf)>::dump(opdef.buf)},
  3231. {"buf_size", serialization<decltype(opdef.buf_size)>::dump(opdef.buf_size)},
  3232. {"symbol", serialization<decltype(opdef.symbol)>::dump(opdef.symbol)},
  3233. {"tensor_dim_mutable", serialization<decltype(opdef.tensor_dim_mutable)>::dump(opdef.tensor_dim_mutable)}
  3234. };
  3235. return py::cast(state).release().ptr();
  3236. }
  3237. static PyObject* setstate(PyObject* self, PyObject* args) {
  3238. PyObject* dict = PyTuple_GetItem(args, 0);
  3239. if (!dict) return NULL;
  3240. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  3241. auto& opdef = reinterpret_cast<PyOp(CambriconRuntime)*>(self)->inst();
  3242. static_cast<void>(opdef);
  3243. {
  3244. auto&& iter = state.find("buf");
  3245. if (iter != state.end()) {
  3246. opdef.buf = serialization<decltype(opdef.buf)>::load(iter->second);
  3247. }
  3248. }
  3249. {
  3250. auto&& iter = state.find("buf_size");
  3251. if (iter != state.end()) {
  3252. opdef.buf_size = serialization<decltype(opdef.buf_size)>::load(iter->second);
  3253. }
  3254. }
  3255. {
  3256. auto&& iter = state.find("symbol");
  3257. if (iter != state.end()) {
  3258. opdef.symbol = serialization<decltype(opdef.symbol)>::load(iter->second);
  3259. }
  3260. }
  3261. {
  3262. auto&& iter = state.find("tensor_dim_mutable");
  3263. if (iter != state.end()) {
  3264. opdef.tensor_dim_mutable = serialization<decltype(opdef.tensor_dim_mutable)>::load(iter->second);
  3265. }
  3266. }
  3267. Py_RETURN_NONE;
  3268. }
  3269. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  3270. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  3271. static PyMethodDef py_init_methoddef;
  3272. // };
  3273. PyOpDefEnd(CambriconRuntime)
  3274. int PyOp(CambriconRuntime)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  3275. static const char* kwlist[] = {"buf", "buf_size", "symbol", "tensor_dim_mutable", "scope", NULL};
  3276. PyObject *buf = NULL, *buf_size = NULL, *symbol = NULL, *tensor_dim_mutable = NULL, *scope = NULL;
  3277. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &buf, &buf_size, &symbol, &tensor_dim_mutable, &scope))
  3278. return -1;
  3279. if (buf) {
  3280. try {
  3281. // TODO: remove this guard which is used for pybind11 implicit conversion
  3282. py::detail::loader_life_support guard{};
  3283. reinterpret_cast<PyOp(CambriconRuntime)*>(self)->inst().buf =
  3284. py::cast<decltype(CambriconRuntime::buf)>(py::handle(buf));
  3285. } CATCH_ALL(-1)
  3286. }
  3287. if (buf_size) {
  3288. try {
  3289. // TODO: remove this guard which is used for pybind11 implicit conversion
  3290. py::detail::loader_life_support guard{};
  3291. reinterpret_cast<PyOp(CambriconRuntime)*>(self)->inst().buf_size =
  3292. py::cast<decltype(CambriconRuntime::buf_size)>(py::handle(buf_size));
  3293. } CATCH_ALL(-1)
  3294. }
  3295. if (symbol) {
  3296. try {
  3297. // TODO: remove this guard which is used for pybind11 implicit conversion
  3298. py::detail::loader_life_support guard{};
  3299. reinterpret_cast<PyOp(CambriconRuntime)*>(self)->inst().symbol =
  3300. py::cast<decltype(CambriconRuntime::symbol)>(py::handle(symbol));
  3301. } CATCH_ALL(-1)
  3302. }
  3303. if (tensor_dim_mutable) {
  3304. try {
  3305. // TODO: remove this guard which is used for pybind11 implicit conversion
  3306. py::detail::loader_life_support guard{};
  3307. reinterpret_cast<PyOp(CambriconRuntime)*>(self)->inst().tensor_dim_mutable =
  3308. py::cast<decltype(CambriconRuntime::tensor_dim_mutable)>(py::handle(tensor_dim_mutable));
  3309. } CATCH_ALL(-1)
  3310. }
  3311. if (scope) {
  3312. try {
  3313. reinterpret_cast<PyOp(OpDef)*>(self)->op
  3314. ->set_scope(py::cast<std::string>(py::handle(scope)));
  3315. } CATCH_ALL(-1)
  3316. }
  3317. return 0;
  3318. }
  3319. PyGetSetDef PyOp(CambriconRuntime)::py_getsetters[] = {
  3320. {const_cast<char*>("buf"), py_get_generic(CambriconRuntime, buf), py_set_generic(CambriconRuntime, buf), const_cast<char*>("buf"), NULL},
  3321. {const_cast<char*>("buf_size"), py_get_generic(CambriconRuntime, buf_size), py_set_generic(CambriconRuntime, buf_size), const_cast<char*>("buf_size"), NULL},
  3322. {const_cast<char*>("symbol"), py_get_generic(CambriconRuntime, symbol), py_set_generic(CambriconRuntime, symbol), const_cast<char*>("symbol"), NULL},
  3323. {const_cast<char*>("tensor_dim_mutable"), py_get_generic(CambriconRuntime, tensor_dim_mutable), py_set_generic(CambriconRuntime, tensor_dim_mutable), const_cast<char*>("tensor_dim_mutable"), NULL},
  3324. {NULL} /* Sentinel */
  3325. };
  3326. PyMethodDef PyOp(CambriconRuntime)::tp_methods[] = {
  3327. {const_cast<char*>("__getstate__"), PyOp(CambriconRuntime)::getstate, METH_NOARGS, "CambriconRuntime getstate"},
  3328. {const_cast<char*>("__setstate__"), PyOp(CambriconRuntime)::setstate, METH_VARARGS, "CambriconRuntime setstate"},
  3329. {NULL} /* Sentinel */
  3330. };
  3331. PyObject *PyOp(CambriconRuntime)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  3332. if (PyOp(CambriconRuntime)::py_init(self, args, kwds) < 0) {
  3333. return NULL;
  3334. }
  3335. Py_RETURN_NONE;
  3336. }
  3337. PyMethodDef PyOp(CambriconRuntime)::py_init_methoddef = {
  3338. "__init__",
  3339. (PyCFunction)PyOp(CambriconRuntime)::py_init_proxy,
  3340. METH_VARARGS | METH_KEYWORDS,
  3341. "__init__(self, buf: str = ..., buf_size: int = ..., symbol: str = ..., tensor_dim_mutable: bool = ...) -> None\n"
  3342. };
  3343. void _init_py_CambriconRuntime(py::module m) {
  3344. using py_op = PyOp(CambriconRuntime);
  3345. auto& py_type = PyOpType(CambriconRuntime);
  3346. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  3347. py_type.tp_name = "megengine.core._imperative_rt.ops.CambriconRuntime";
  3348. py_type.tp_basicsize = sizeof(PyOp(CambriconRuntime));
  3349. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  3350. py_type.tp_doc = "CambriconRuntime";
  3351. py_type.tp_base = &PyOpType(OpDef);
  3352. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  3353. py_type.tp_new = py_new_generic<py_op>;
  3354. py_type.tp_init = py_op::py_init;
  3355. py_type.tp_methods = py_op::tp_methods;
  3356. py_type.tp_getset = py_op::py_getsetters;
  3357. py_type.tp_dict = PyDict_New();
  3358. PyObject* descr = PyDescr_NewMethod(&PyOpType(CambriconRuntime), &PyOp(CambriconRuntime)::py_init_methoddef);
  3359. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  3360. mgb_assert(PyType_Ready(&py_type) >= 0);
  3361. PyType_Modified(&py_type);
  3362. m.add_object("CambriconRuntime", reinterpret_cast<PyObject*>(&py_type));
  3363. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CambriconRuntime::typeinfo(), &py_type).second);
  3364. }
  3365. PyOpDefBegin(CheckNonFinite) // {
  3366. static PyGetSetDef py_getsetters[];
  3367. static PyMethodDef tp_methods[];
  3368. static PyObject* getstate(PyObject* self, PyObject*) {
  3369. auto& opdef = reinterpret_cast<PyOp(CheckNonFinite)*>(self)->inst();
  3370. static_cast<void>(opdef);
  3371. std::unordered_map<std::string, py::object> state {
  3372. {"scale", serialization<decltype(opdef.scale)>::dump(opdef.scale)}
  3373. };
  3374. return py::cast(state).release().ptr();
  3375. }
  3376. static PyObject* setstate(PyObject* self, PyObject* args) {
  3377. PyObject* dict = PyTuple_GetItem(args, 0);
  3378. if (!dict) return NULL;
  3379. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  3380. auto& opdef = reinterpret_cast<PyOp(CheckNonFinite)*>(self)->inst();
  3381. static_cast<void>(opdef);
  3382. {
  3383. auto&& iter = state.find("scale");
  3384. if (iter != state.end()) {
  3385. opdef.scale = serialization<decltype(opdef.scale)>::load(iter->second);
  3386. }
  3387. }
  3388. Py_RETURN_NONE;
  3389. }
  3390. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  3391. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  3392. static PyMethodDef py_init_methoddef;
  3393. // };
  3394. PyOpDefEnd(CheckNonFinite)
  3395. int PyOp(CheckNonFinite)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  3396. static const char* kwlist[] = {"scale", "scope", NULL};
  3397. PyObject *scale = NULL, *scope = NULL;
  3398. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &scale, &scope))
  3399. return -1;
  3400. if (scale) {
  3401. try {
  3402. // TODO: remove this guard which is used for pybind11 implicit conversion
  3403. py::detail::loader_life_support guard{};
  3404. reinterpret_cast<PyOp(CheckNonFinite)*>(self)->inst().scale =
  3405. py::cast<decltype(CheckNonFinite::scale)>(py::handle(scale));
  3406. } CATCH_ALL(-1)
  3407. }
  3408. if (scope) {
  3409. try {
  3410. reinterpret_cast<PyOp(OpDef)*>(self)->op
  3411. ->set_scope(py::cast<std::string>(py::handle(scope)));
  3412. } CATCH_ALL(-1)
  3413. }
  3414. return 0;
  3415. }
  3416. PyGetSetDef PyOp(CheckNonFinite)::py_getsetters[] = {
  3417. {const_cast<char*>("scale"), py_get_generic(CheckNonFinite, scale), py_set_generic(CheckNonFinite, scale), const_cast<char*>("scale"), NULL},
  3418. {NULL} /* Sentinel */
  3419. };
  3420. PyMethodDef PyOp(CheckNonFinite)::tp_methods[] = {
  3421. {const_cast<char*>("__getstate__"), PyOp(CheckNonFinite)::getstate, METH_NOARGS, "CheckNonFinite getstate"},
  3422. {const_cast<char*>("__setstate__"), PyOp(CheckNonFinite)::setstate, METH_VARARGS, "CheckNonFinite setstate"},
  3423. {NULL} /* Sentinel */
  3424. };
  3425. PyObject *PyOp(CheckNonFinite)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  3426. if (PyOp(CheckNonFinite)::py_init(self, args, kwds) < 0) {
  3427. return NULL;
  3428. }
  3429. Py_RETURN_NONE;
  3430. }
  3431. PyMethodDef PyOp(CheckNonFinite)::py_init_methoddef = {
  3432. "__init__",
  3433. (PyCFunction)PyOp(CheckNonFinite)::py_init_proxy,
  3434. METH_VARARGS | METH_KEYWORDS,
  3435. "__init__(self, scale: float = ...) -> None\n"
  3436. };
  3437. void _init_py_CheckNonFinite(py::module m) {
  3438. using py_op = PyOp(CheckNonFinite);
  3439. auto& py_type = PyOpType(CheckNonFinite);
  3440. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  3441. py_type.tp_name = "megengine.core._imperative_rt.ops.CheckNonFinite";
  3442. py_type.tp_basicsize = sizeof(PyOp(CheckNonFinite));
  3443. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  3444. py_type.tp_doc = "CheckNonFinite";
  3445. py_type.tp_base = &PyOpType(OpDef);
  3446. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  3447. py_type.tp_new = py_new_generic<py_op>;
  3448. py_type.tp_init = py_op::py_init;
  3449. py_type.tp_methods = py_op::tp_methods;
  3450. py_type.tp_getset = py_op::py_getsetters;
  3451. py_type.tp_dict = PyDict_New();
  3452. PyObject* descr = PyDescr_NewMethod(&PyOpType(CheckNonFinite), &PyOp(CheckNonFinite)::py_init_methoddef);
  3453. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  3454. mgb_assert(PyType_Ready(&py_type) >= 0);
  3455. PyType_Modified(&py_type);
  3456. m.add_object("CheckNonFinite", reinterpret_cast<PyObject*>(&py_type));
  3457. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CheckNonFinite::typeinfo(), &py_type).second);
  3458. }
  3459. template<> struct EnumTrait<CollectiveComm::Mode> {
  3460. static constexpr const char *name = "CollectiveComm.Mode";
  3461. static constexpr std::underlying_type_t<CollectiveComm::Mode> max = 11 - 1;
  3462. };
  3463. template<> PyTypeObject* EnumWrapper<CollectiveComm::Mode>::type = nullptr;
  3464. template<> const char*
  3465. EnumWrapper<CollectiveComm::Mode>::members[] = {"REDUCE_SUM", "BROADCAST", "ALL_GATHER", "REDUCE_SCATTER_SUM", "ALL_REDUCE_SUM", "ALL_REDUCE_MAX", "ALL_REDUCE_MIN", "ALL_REDUCE_PROD", "GATHER", "SCATTER", "ALL_TO_ALL"};
  3466. template<> std::unordered_map<std::string, CollectiveComm::Mode>
  3467. EnumWrapper<CollectiveComm::Mode>::mem2value = {{normalize_enum("REDUCE_SUM"), CollectiveComm::Mode::REDUCE_SUM}, {normalize_enum("BROADCAST"), CollectiveComm::Mode::BROADCAST}, {normalize_enum("ALL_GATHER"), CollectiveComm::Mode::ALL_GATHER}, {normalize_enum("REDUCE_SCATTER_SUM"), CollectiveComm::Mode::REDUCE_SCATTER_SUM}, {normalize_enum("ALL_REDUCE_SUM"), CollectiveComm::Mode::ALL_REDUCE_SUM}, {normalize_enum("ALL_REDUCE_MAX"), CollectiveComm::Mode::ALL_REDUCE_MAX}, {normalize_enum("ALL_REDUCE_MIN"), CollectiveComm::Mode::ALL_REDUCE_MIN}, {normalize_enum("ALL_REDUCE_PROD"), CollectiveComm::Mode::ALL_REDUCE_PROD}, {normalize_enum("GATHER"), CollectiveComm::Mode::GATHER}, {normalize_enum("SCATTER"), CollectiveComm::Mode::SCATTER}, {normalize_enum("ALL_TO_ALL"), CollectiveComm::Mode::ALL_TO_ALL}};
  3468. template<> PyObject* EnumWrapper<CollectiveComm::Mode>::pyobj_insts[11] = {nullptr};
  3469. void _init_py_CollectiveComm_Mode(PyTypeObject& py_type) {
  3470. auto& e_type = EnumWrapper<CollectiveComm::Mode>::type;
  3471. static PyMethodDef tp_methods[] = {
  3472. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<CollectiveComm::Mode>::py_dump, METH_NOARGS, NULL},
  3473. {NULL} /* Sentinel */
  3474. };
  3475. static PyType_Slot slots[] = {
  3476. {Py_tp_repr, (void*)EnumWrapper<CollectiveComm::Mode>::py_repr},
  3477. {Py_tp_richcompare, (void*)EnumWrapper<CollectiveComm::Mode>::tp_richcompare},
  3478. {Py_tp_methods, tp_methods},
  3479. {0, NULL}
  3480. };
  3481. static PyType_Spec spec = {
  3482. // name
  3483. "megengine.core._imperative_rt.ops.CollectiveComm.Mode",
  3484. // basicsize
  3485. sizeof(EnumWrapper<CollectiveComm::Mode>),
  3486. // itemsize
  3487. 0,
  3488. // flags
  3489. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  3490. // slots
  3491. slots
  3492. };
  3493. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  3494. mgb_assert(
  3495. e_type->tp_setattro(
  3496. reinterpret_cast<PyObject*>(e_type),
  3497. py::cast("__name__").release().ptr(),
  3498. py::cast("Mode").release().ptr()) >= 0);
  3499. mgb_assert(
  3500. e_type->tp_setattro(
  3501. reinterpret_cast<PyObject*>(e_type),
  3502. py::cast("__module__").release().ptr(),
  3503. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  3504. mgb_assert(
  3505. e_type->tp_setattro(
  3506. reinterpret_cast<PyObject*>(e_type),
  3507. py::cast("__qualname__").release().ptr(),
  3508. py::cast("CollectiveComm.Mode").release().ptr()) >= 0);
  3509. {
  3510. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3511. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::REDUCE_SUM;
  3512. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REDUCE_SUM", inst) >= 0);
  3513. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[0] = inst;
  3514. }{
  3515. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3516. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::BROADCAST;
  3517. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BROADCAST", inst) >= 0);
  3518. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[1] = inst;
  3519. }{
  3520. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3521. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::ALL_GATHER;
  3522. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_GATHER", inst) >= 0);
  3523. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[2] = inst;
  3524. }{
  3525. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3526. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::REDUCE_SCATTER_SUM;
  3527. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REDUCE_SCATTER_SUM", inst) >= 0);
  3528. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[3] = inst;
  3529. }{
  3530. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3531. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::ALL_REDUCE_SUM;
  3532. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_REDUCE_SUM", inst) >= 0);
  3533. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[4] = inst;
  3534. }{
  3535. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3536. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::ALL_REDUCE_MAX;
  3537. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_REDUCE_MAX", inst) >= 0);
  3538. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[5] = inst;
  3539. }{
  3540. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3541. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::ALL_REDUCE_MIN;
  3542. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_REDUCE_MIN", inst) >= 0);
  3543. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[6] = inst;
  3544. }{
  3545. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3546. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::ALL_REDUCE_PROD;
  3547. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_REDUCE_PROD", inst) >= 0);
  3548. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[7] = inst;
  3549. }{
  3550. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3551. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::GATHER;
  3552. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GATHER", inst) >= 0);
  3553. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[8] = inst;
  3554. }{
  3555. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3556. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::SCATTER;
  3557. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SCATTER", inst) >= 0);
  3558. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[9] = inst;
  3559. }{
  3560. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3561. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::ALL_TO_ALL;
  3562. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_TO_ALL", inst) >= 0);
  3563. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[10] = inst;
  3564. }
  3565. Py_INCREF(e_type);
  3566. mgb_assert(PyDict_SetItemString(
  3567. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  3568. }
  3569. PyOpDefBegin(CollectiveComm) // {
  3570. static PyGetSetDef py_getsetters[];
  3571. static PyMethodDef tp_methods[];
  3572. static PyObject* getstate(PyObject* self, PyObject*) {
  3573. auto& opdef = reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst();
  3574. static_cast<void>(opdef);
  3575. std::unordered_map<std::string, py::object> state {
  3576. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  3577. {"key", serialization<decltype(opdef.key)>::dump(opdef.key)},
  3578. {"nr_devices", serialization<decltype(opdef.nr_devices)>::dump(opdef.nr_devices)},
  3579. {"rank", serialization<decltype(opdef.rank)>::dump(opdef.rank)},
  3580. {"is_root", serialization<decltype(opdef.is_root)>::dump(opdef.is_root)},
  3581. {"local_grad", serialization<decltype(opdef.local_grad)>::dump(opdef.local_grad)},
  3582. {"addr", serialization<decltype(opdef.addr)>::dump(opdef.addr)},
  3583. {"port", serialization<decltype(opdef.port)>::dump(opdef.port)},
  3584. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  3585. {"backend", serialization<decltype(opdef.backend)>::dump(opdef.backend)},
  3586. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)}
  3587. };
  3588. return py::cast(state).release().ptr();
  3589. }
  3590. static PyObject* setstate(PyObject* self, PyObject* args) {
  3591. PyObject* dict = PyTuple_GetItem(args, 0);
  3592. if (!dict) return NULL;
  3593. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  3594. auto& opdef = reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst();
  3595. static_cast<void>(opdef);
  3596. {
  3597. auto&& iter = state.find("mode");
  3598. if (iter != state.end()) {
  3599. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  3600. }
  3601. }
  3602. {
  3603. auto&& iter = state.find("key");
  3604. if (iter != state.end()) {
  3605. opdef.key = serialization<decltype(opdef.key)>::load(iter->second);
  3606. }
  3607. }
  3608. {
  3609. auto&& iter = state.find("nr_devices");
  3610. if (iter != state.end()) {
  3611. opdef.nr_devices = serialization<decltype(opdef.nr_devices)>::load(iter->second);
  3612. }
  3613. }
  3614. {
  3615. auto&& iter = state.find("rank");
  3616. if (iter != state.end()) {
  3617. opdef.rank = serialization<decltype(opdef.rank)>::load(iter->second);
  3618. }
  3619. }
  3620. {
  3621. auto&& iter = state.find("is_root");
  3622. if (iter != state.end()) {
  3623. opdef.is_root = serialization<decltype(opdef.is_root)>::load(iter->second);
  3624. }
  3625. }
  3626. {
  3627. auto&& iter = state.find("local_grad");
  3628. if (iter != state.end()) {
  3629. opdef.local_grad = serialization<decltype(opdef.local_grad)>::load(iter->second);
  3630. }
  3631. }
  3632. {
  3633. auto&& iter = state.find("addr");
  3634. if (iter != state.end()) {
  3635. opdef.addr = serialization<decltype(opdef.addr)>::load(iter->second);
  3636. }
  3637. }
  3638. {
  3639. auto&& iter = state.find("port");
  3640. if (iter != state.end()) {
  3641. opdef.port = serialization<decltype(opdef.port)>::load(iter->second);
  3642. }
  3643. }
  3644. {
  3645. auto&& iter = state.find("dtype");
  3646. if (iter != state.end()) {
  3647. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  3648. }
  3649. }
  3650. {
  3651. auto&& iter = state.find("backend");
  3652. if (iter != state.end()) {
  3653. opdef.backend = serialization<decltype(opdef.backend)>::load(iter->second);
  3654. }
  3655. }
  3656. {
  3657. auto&& iter = state.find("comp_node");
  3658. if (iter != state.end()) {
  3659. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  3660. }
  3661. }
  3662. Py_RETURN_NONE;
  3663. }
  3664. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  3665. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  3666. static PyMethodDef py_init_methoddef;
  3667. // };
  3668. PyOpDefEnd(CollectiveComm)
  3669. int PyOp(CollectiveComm)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  3670. static const char* kwlist[] = {"mode", "key", "nr_devices", "rank", "is_root", "local_grad", "addr", "port", "dtype", "backend", "comp_node", "scope", NULL};
  3671. PyObject *mode = NULL, *key = NULL, *nr_devices = NULL, *rank = NULL, *is_root = NULL, *local_grad = NULL, *addr = NULL, *port = NULL, *dtype = NULL, *backend = NULL, *comp_node = NULL, *scope = NULL;
  3672. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &key, &nr_devices, &rank, &is_root, &local_grad, &addr, &port, &dtype, &backend, &comp_node, &scope))
  3673. return -1;
  3674. if (mode) {
  3675. try {
  3676. // TODO: remove this guard which is used for pybind11 implicit conversion
  3677. py::detail::loader_life_support guard{};
  3678. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().mode =
  3679. py::cast<decltype(CollectiveComm::mode)>(py::handle(mode));
  3680. } CATCH_ALL(-1)
  3681. }
  3682. if (key) {
  3683. try {
  3684. // TODO: remove this guard which is used for pybind11 implicit conversion
  3685. py::detail::loader_life_support guard{};
  3686. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().key =
  3687. py::cast<decltype(CollectiveComm::key)>(py::handle(key));
  3688. } CATCH_ALL(-1)
  3689. }
  3690. if (nr_devices) {
  3691. try {
  3692. // TODO: remove this guard which is used for pybind11 implicit conversion
  3693. py::detail::loader_life_support guard{};
  3694. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().nr_devices =
  3695. py::cast<decltype(CollectiveComm::nr_devices)>(py::handle(nr_devices));
  3696. } CATCH_ALL(-1)
  3697. }
  3698. if (rank) {
  3699. try {
  3700. // TODO: remove this guard which is used for pybind11 implicit conversion
  3701. py::detail::loader_life_support guard{};
  3702. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().rank =
  3703. py::cast<decltype(CollectiveComm::rank)>(py::handle(rank));
  3704. } CATCH_ALL(-1)
  3705. }
  3706. if (is_root) {
  3707. try {
  3708. // TODO: remove this guard which is used for pybind11 implicit conversion
  3709. py::detail::loader_life_support guard{};
  3710. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().is_root =
  3711. py::cast<decltype(CollectiveComm::is_root)>(py::handle(is_root));
  3712. } CATCH_ALL(-1)
  3713. }
  3714. if (local_grad) {
  3715. try {
  3716. // TODO: remove this guard which is used for pybind11 implicit conversion
  3717. py::detail::loader_life_support guard{};
  3718. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().local_grad =
  3719. py::cast<decltype(CollectiveComm::local_grad)>(py::handle(local_grad));
  3720. } CATCH_ALL(-1)
  3721. }
  3722. if (addr) {
  3723. try {
  3724. // TODO: remove this guard which is used for pybind11 implicit conversion
  3725. py::detail::loader_life_support guard{};
  3726. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().addr =
  3727. py::cast<decltype(CollectiveComm::addr)>(py::handle(addr));
  3728. } CATCH_ALL(-1)
  3729. }
  3730. if (port) {
  3731. try {
  3732. // TODO: remove this guard which is used for pybind11 implicit conversion
  3733. py::detail::loader_life_support guard{};
  3734. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().port =
  3735. py::cast<decltype(CollectiveComm::port)>(py::handle(port));
  3736. } CATCH_ALL(-1)
  3737. }
  3738. if (dtype) {
  3739. try {
  3740. // TODO: remove this guard which is used for pybind11 implicit conversion
  3741. py::detail::loader_life_support guard{};
  3742. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().dtype =
  3743. py::cast<decltype(CollectiveComm::dtype)>(py::handle(dtype));
  3744. } CATCH_ALL(-1)
  3745. }
  3746. if (backend) {
  3747. try {
  3748. // TODO: remove this guard which is used for pybind11 implicit conversion
  3749. py::detail::loader_life_support guard{};
  3750. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().backend =
  3751. py::cast<decltype(CollectiveComm::backend)>(py::handle(backend));
  3752. } CATCH_ALL(-1)
  3753. }
  3754. if (comp_node) {
  3755. try {
  3756. // TODO: remove this guard which is used for pybind11 implicit conversion
  3757. py::detail::loader_life_support guard{};
  3758. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().comp_node =
  3759. py::cast<decltype(CollectiveComm::comp_node)>(py::handle(comp_node));
  3760. } CATCH_ALL(-1)
  3761. }
  3762. if (scope) {
  3763. try {
  3764. reinterpret_cast<PyOp(OpDef)*>(self)->op
  3765. ->set_scope(py::cast<std::string>(py::handle(scope)));
  3766. } CATCH_ALL(-1)
  3767. }
  3768. return 0;
  3769. }
  3770. PyGetSetDef PyOp(CollectiveComm)::py_getsetters[] = {
  3771. {const_cast<char*>("mode"), py_get_generic(CollectiveComm, mode), py_set_generic(CollectiveComm, mode), const_cast<char*>("mode"), NULL},
  3772. {const_cast<char*>("key"), py_get_generic(CollectiveComm, key), py_set_generic(CollectiveComm, key), const_cast<char*>("key"), NULL},
  3773. {const_cast<char*>("nr_devices"), py_get_generic(CollectiveComm, nr_devices), py_set_generic(CollectiveComm, nr_devices), const_cast<char*>("nr_devices"), NULL},
  3774. {const_cast<char*>("rank"), py_get_generic(CollectiveComm, rank), py_set_generic(CollectiveComm, rank), const_cast<char*>("rank"), NULL},
  3775. {const_cast<char*>("is_root"), py_get_generic(CollectiveComm, is_root), py_set_generic(CollectiveComm, is_root), const_cast<char*>("is_root"), NULL},
  3776. {const_cast<char*>("local_grad"), py_get_generic(CollectiveComm, local_grad), py_set_generic(CollectiveComm, local_grad), const_cast<char*>("local_grad"), NULL},
  3777. {const_cast<char*>("addr"), py_get_generic(CollectiveComm, addr), py_set_generic(CollectiveComm, addr), const_cast<char*>("addr"), NULL},
  3778. {const_cast<char*>("port"), py_get_generic(CollectiveComm, port), py_set_generic(CollectiveComm, port), const_cast<char*>("port"), NULL},
  3779. {const_cast<char*>("dtype"), py_get_generic(CollectiveComm, dtype), py_set_generic(CollectiveComm, dtype), const_cast<char*>("dtype"), NULL},
  3780. {const_cast<char*>("backend"), py_get_generic(CollectiveComm, backend), py_set_generic(CollectiveComm, backend), const_cast<char*>("backend"), NULL},
  3781. {const_cast<char*>("comp_node"), py_get_generic(CollectiveComm, comp_node), py_set_generic(CollectiveComm, comp_node), const_cast<char*>("comp_node"), NULL},
  3782. {NULL} /* Sentinel */
  3783. };
  3784. PyMethodDef PyOp(CollectiveComm)::tp_methods[] = {
  3785. {const_cast<char*>("__getstate__"), PyOp(CollectiveComm)::getstate, METH_NOARGS, "CollectiveComm getstate"},
  3786. {const_cast<char*>("__setstate__"), PyOp(CollectiveComm)::setstate, METH_VARARGS, "CollectiveComm setstate"},
  3787. {NULL} /* Sentinel */
  3788. };
  3789. PyObject *PyOp(CollectiveComm)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  3790. if (PyOp(CollectiveComm)::py_init(self, args, kwds) < 0) {
  3791. return NULL;
  3792. }
  3793. Py_RETURN_NONE;
  3794. }
  3795. PyMethodDef PyOp(CollectiveComm)::py_init_methoddef = {
  3796. "__init__",
  3797. (PyCFunction)PyOp(CollectiveComm)::py_init_proxy,
  3798. METH_VARARGS | METH_KEYWORDS,
  3799. "__init__(self, mode: Union[str, Mode] = ..., key: str = ..., nr_devices: int = ..., rank: int = ..., is_root: bool = ..., local_grad: bool = ..., addr: str = ..., port: int = ..., dtype: str = ..., backend: str = ..., comp_node: str = ...) -> None\n"
  3800. };
  3801. void _init_py_CollectiveComm(py::module m) {
  3802. using py_op = PyOp(CollectiveComm);
  3803. auto& py_type = PyOpType(CollectiveComm);
  3804. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  3805. py_type.tp_name = "megengine.core._imperative_rt.ops.CollectiveComm";
  3806. py_type.tp_basicsize = sizeof(PyOp(CollectiveComm));
  3807. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  3808. py_type.tp_doc = "CollectiveComm";
  3809. py_type.tp_base = &PyOpType(OpDef);
  3810. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  3811. py_type.tp_new = py_new_generic<py_op>;
  3812. py_type.tp_init = py_op::py_init;
  3813. py_type.tp_methods = py_op::tp_methods;
  3814. py_type.tp_getset = py_op::py_getsetters;
  3815. py_type.tp_dict = PyDict_New();
  3816. PyObject* descr = PyDescr_NewMethod(&PyOpType(CollectiveComm), &PyOp(CollectiveComm)::py_init_methoddef);
  3817. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  3818. mgb_assert(PyType_Ready(&py_type) >= 0);
  3819. _init_py_CollectiveComm_Mode(py_type);
  3820. PyType_Modified(&py_type);
  3821. m.add_object("CollectiveComm", reinterpret_cast<PyObject*>(&py_type));
  3822. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CollectiveComm::typeinfo(), &py_type).second);
  3823. }
  3824. PyOpDefBegin(Concat) // {
  3825. static PyGetSetDef py_getsetters[];
  3826. static PyMethodDef tp_methods[];
  3827. static PyObject* getstate(PyObject* self, PyObject*) {
  3828. auto& opdef = reinterpret_cast<PyOp(Concat)*>(self)->inst();
  3829. static_cast<void>(opdef);
  3830. std::unordered_map<std::string, py::object> state {
  3831. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  3832. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)}
  3833. };
  3834. return py::cast(state).release().ptr();
  3835. }
  3836. static PyObject* setstate(PyObject* self, PyObject* args) {
  3837. PyObject* dict = PyTuple_GetItem(args, 0);
  3838. if (!dict) return NULL;
  3839. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  3840. auto& opdef = reinterpret_cast<PyOp(Concat)*>(self)->inst();
  3841. static_cast<void>(opdef);
  3842. {
  3843. auto&& iter = state.find("axis");
  3844. if (iter != state.end()) {
  3845. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  3846. }
  3847. }
  3848. {
  3849. auto&& iter = state.find("comp_node");
  3850. if (iter != state.end()) {
  3851. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  3852. }
  3853. }
  3854. Py_RETURN_NONE;
  3855. }
  3856. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  3857. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  3858. static PyMethodDef py_init_methoddef;
  3859. // };
  3860. PyOpDefEnd(Concat)
  3861. int PyOp(Concat)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  3862. static const char* kwlist[] = {"axis", "comp_node", "scope", NULL};
  3863. PyObject *axis = NULL, *comp_node = NULL, *scope = NULL;
  3864. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &axis, &comp_node, &scope))
  3865. return -1;
  3866. if (axis) {
  3867. try {
  3868. // TODO: remove this guard which is used for pybind11 implicit conversion
  3869. py::detail::loader_life_support guard{};
  3870. reinterpret_cast<PyOp(Concat)*>(self)->inst().axis =
  3871. py::cast<decltype(Concat::axis)>(py::handle(axis));
  3872. } CATCH_ALL(-1)
  3873. }
  3874. if (comp_node) {
  3875. try {
  3876. // TODO: remove this guard which is used for pybind11 implicit conversion
  3877. py::detail::loader_life_support guard{};
  3878. reinterpret_cast<PyOp(Concat)*>(self)->inst().comp_node =
  3879. py::cast<decltype(Concat::comp_node)>(py::handle(comp_node));
  3880. } CATCH_ALL(-1)
  3881. }
  3882. if (scope) {
  3883. try {
  3884. reinterpret_cast<PyOp(OpDef)*>(self)->op
  3885. ->set_scope(py::cast<std::string>(py::handle(scope)));
  3886. } CATCH_ALL(-1)
  3887. }
  3888. return 0;
  3889. }
  3890. PyGetSetDef PyOp(Concat)::py_getsetters[] = {
  3891. {const_cast<char*>("axis"), py_get_generic(Concat, axis), py_set_generic(Concat, axis), const_cast<char*>("axis"), NULL},
  3892. {const_cast<char*>("comp_node"), py_get_generic(Concat, comp_node), py_set_generic(Concat, comp_node), const_cast<char*>("comp_node"), NULL},
  3893. {NULL} /* Sentinel */
  3894. };
  3895. PyMethodDef PyOp(Concat)::tp_methods[] = {
  3896. {const_cast<char*>("__getstate__"), PyOp(Concat)::getstate, METH_NOARGS, "Concat getstate"},
  3897. {const_cast<char*>("__setstate__"), PyOp(Concat)::setstate, METH_VARARGS, "Concat setstate"},
  3898. {NULL} /* Sentinel */
  3899. };
  3900. PyObject *PyOp(Concat)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  3901. if (PyOp(Concat)::py_init(self, args, kwds) < 0) {
  3902. return NULL;
  3903. }
  3904. Py_RETURN_NONE;
  3905. }
  3906. PyMethodDef PyOp(Concat)::py_init_methoddef = {
  3907. "__init__",
  3908. (PyCFunction)PyOp(Concat)::py_init_proxy,
  3909. METH_VARARGS | METH_KEYWORDS,
  3910. "__init__(self, axis: int = ..., comp_node: str = ...) -> None\n"
  3911. };
  3912. void _init_py_Concat(py::module m) {
  3913. using py_op = PyOp(Concat);
  3914. auto& py_type = PyOpType(Concat);
  3915. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  3916. py_type.tp_name = "megengine.core._imperative_rt.ops.Concat";
  3917. py_type.tp_basicsize = sizeof(PyOp(Concat));
  3918. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  3919. py_type.tp_doc = "Concat";
  3920. py_type.tp_base = &PyOpType(OpDef);
  3921. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  3922. py_type.tp_new = py_new_generic<py_op>;
  3923. py_type.tp_init = py_op::py_init;
  3924. py_type.tp_methods = py_op::tp_methods;
  3925. py_type.tp_getset = py_op::py_getsetters;
  3926. py_type.tp_dict = PyDict_New();
  3927. PyObject* descr = PyDescr_NewMethod(&PyOpType(Concat), &PyOp(Concat)::py_init_methoddef);
  3928. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  3929. mgb_assert(PyType_Ready(&py_type) >= 0);
  3930. PyType_Modified(&py_type);
  3931. m.add_object("Concat", reinterpret_cast<PyObject*>(&py_type));
  3932. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Concat::typeinfo(), &py_type).second);
  3933. }
  3934. PyOpDefBegin(CondTake) // {
  3935. static PyGetSetDef py_getsetters[];
  3936. static PyMethodDef tp_methods[];
  3937. static PyObject* getstate(PyObject* self, PyObject*) {
  3938. auto& opdef = reinterpret_cast<PyOp(CondTake)*>(self)->inst();
  3939. static_cast<void>(opdef);
  3940. std::unordered_map<std::string, py::object> state {
  3941. };
  3942. return py::cast(state).release().ptr();
  3943. }
  3944. static PyObject* setstate(PyObject* self, PyObject* args) {
  3945. PyObject* dict = PyTuple_GetItem(args, 0);
  3946. if (!dict) return NULL;
  3947. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  3948. auto& opdef = reinterpret_cast<PyOp(CondTake)*>(self)->inst();
  3949. static_cast<void>(opdef);
  3950. Py_RETURN_NONE;
  3951. }
  3952. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  3953. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  3954. static PyMethodDef py_init_methoddef;
  3955. // };
  3956. PyOpDefEnd(CondTake)
  3957. int PyOp(CondTake)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  3958. return 0;
  3959. }
  3960. PyGetSetDef PyOp(CondTake)::py_getsetters[] = {
  3961. {NULL} /* Sentinel */
  3962. };
  3963. PyMethodDef PyOp(CondTake)::tp_methods[] = {
  3964. {const_cast<char*>("__getstate__"), PyOp(CondTake)::getstate, METH_NOARGS, "CondTake getstate"},
  3965. {const_cast<char*>("__setstate__"), PyOp(CondTake)::setstate, METH_VARARGS, "CondTake setstate"},
  3966. {NULL} /* Sentinel */
  3967. };
  3968. PyObject *PyOp(CondTake)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  3969. if (PyOp(CondTake)::py_init(self, args, kwds) < 0) {
  3970. return NULL;
  3971. }
  3972. Py_RETURN_NONE;
  3973. }
  3974. PyMethodDef PyOp(CondTake)::py_init_methoddef = {
  3975. "__init__",
  3976. (PyCFunction)PyOp(CondTake)::py_init_proxy,
  3977. METH_VARARGS | METH_KEYWORDS,
  3978. "__init__(self) -> None\n"
  3979. };
  3980. void _init_py_CondTake(py::module m) {
  3981. using py_op = PyOp(CondTake);
  3982. auto& py_type = PyOpType(CondTake);
  3983. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  3984. py_type.tp_name = "megengine.core._imperative_rt.ops.CondTake";
  3985. py_type.tp_basicsize = sizeof(PyOp(CondTake));
  3986. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  3987. py_type.tp_doc = "CondTake";
  3988. py_type.tp_base = &PyOpType(OpDef);
  3989. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  3990. py_type.tp_new = py_new_generic<py_op>;
  3991. py_type.tp_init = py_op::py_init;
  3992. py_type.tp_methods = py_op::tp_methods;
  3993. py_type.tp_getset = py_op::py_getsetters;
  3994. py_type.tp_dict = PyDict_New();
  3995. PyObject* descr = PyDescr_NewMethod(&PyOpType(CondTake), &PyOp(CondTake)::py_init_methoddef);
  3996. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  3997. mgb_assert(PyType_Ready(&py_type) >= 0);
  3998. PyType_Modified(&py_type);
  3999. m.add_object("CondTake", reinterpret_cast<PyObject*>(&py_type));
  4000. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CondTake::typeinfo(), &py_type).second);
  4001. }
  4002. void _init_py_ConvBias_NonlineMode(PyTypeObject& py_type) {
  4003. auto& e_type = EnumWrapper<ConvBias::NonlineMode>::type;
  4004. Py_INCREF(e_type);
  4005. mgb_assert(PyDict_SetItemString(
  4006. py_type.tp_dict, "NonlineMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4007. }
  4008. void _init_py_ConvBias_Mode(PyTypeObject& py_type) {
  4009. auto& e_type = EnumWrapper<ConvBias::Mode>::type;
  4010. Py_INCREF(e_type);
  4011. mgb_assert(PyDict_SetItemString(
  4012. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4013. }
  4014. void _init_py_ConvBias_Sparse(PyTypeObject& py_type) {
  4015. auto& e_type = EnumWrapper<ConvBias::Sparse>::type;
  4016. Py_INCREF(e_type);
  4017. mgb_assert(PyDict_SetItemString(
  4018. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4019. }
  4020. void _init_py_ConvBias_Format(PyTypeObject& py_type) {
  4021. auto& e_type = EnumWrapper<ConvBias::Format>::type;
  4022. Py_INCREF(e_type);
  4023. mgb_assert(PyDict_SetItemString(
  4024. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4025. }
  4026. void _init_py_ConvBias_ComputeMode(PyTypeObject& py_type) {
  4027. auto& e_type = EnumWrapper<ConvBias::ComputeMode>::type;
  4028. Py_INCREF(e_type);
  4029. mgb_assert(PyDict_SetItemString(
  4030. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4031. }
  4032. void _init_py_ConvBias_Strategy(PyTypeObject& py_type) {
  4033. auto& e_type = BitCombinedEnumWrapper<ConvBias::Strategy>::type;
  4034. Py_INCREF(e_type);
  4035. mgb_assert(PyDict_SetItemString(
  4036. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4037. }
  4038. PyOpDefBegin(ConvBias) // {
  4039. static PyGetSetDef py_getsetters[];
  4040. static PyMethodDef tp_methods[];
  4041. static PyObject* getstate(PyObject* self, PyObject*) {
  4042. auto& opdef = reinterpret_cast<PyOp(ConvBias)*>(self)->inst();
  4043. static_cast<void>(opdef);
  4044. std::unordered_map<std::string, py::object> state {
  4045. {"nonlineMode", serialization<decltype(opdef.nonlineMode)>::dump(opdef.nonlineMode)},
  4046. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  4047. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  4048. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  4049. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  4050. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  4051. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  4052. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  4053. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  4054. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  4055. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  4056. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  4057. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)},
  4058. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)}
  4059. };
  4060. return py::cast(state).release().ptr();
  4061. }
  4062. static PyObject* setstate(PyObject* self, PyObject* args) {
  4063. PyObject* dict = PyTuple_GetItem(args, 0);
  4064. if (!dict) return NULL;
  4065. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  4066. auto& opdef = reinterpret_cast<PyOp(ConvBias)*>(self)->inst();
  4067. static_cast<void>(opdef);
  4068. {
  4069. auto&& iter = state.find("nonlineMode");
  4070. if (iter != state.end()) {
  4071. opdef.nonlineMode = serialization<decltype(opdef.nonlineMode)>::load(iter->second);
  4072. }
  4073. }
  4074. {
  4075. auto&& iter = state.find("mode");
  4076. if (iter != state.end()) {
  4077. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  4078. }
  4079. }
  4080. {
  4081. auto&& iter = state.find("sparse");
  4082. if (iter != state.end()) {
  4083. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  4084. }
  4085. }
  4086. {
  4087. auto&& iter = state.find("format");
  4088. if (iter != state.end()) {
  4089. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  4090. }
  4091. }
  4092. {
  4093. auto&& iter = state.find("pad_h");
  4094. if (iter != state.end()) {
  4095. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  4096. }
  4097. }
  4098. {
  4099. auto&& iter = state.find("pad_w");
  4100. if (iter != state.end()) {
  4101. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  4102. }
  4103. }
  4104. {
  4105. auto&& iter = state.find("stride_h");
  4106. if (iter != state.end()) {
  4107. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  4108. }
  4109. }
  4110. {
  4111. auto&& iter = state.find("stride_w");
  4112. if (iter != state.end()) {
  4113. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  4114. }
  4115. }
  4116. {
  4117. auto&& iter = state.find("dilate_h");
  4118. if (iter != state.end()) {
  4119. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  4120. }
  4121. }
  4122. {
  4123. auto&& iter = state.find("dilate_w");
  4124. if (iter != state.end()) {
  4125. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  4126. }
  4127. }
  4128. {
  4129. auto&& iter = state.find("compute_mode");
  4130. if (iter != state.end()) {
  4131. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  4132. }
  4133. }
  4134. {
  4135. auto&& iter = state.find("strategy");
  4136. if (iter != state.end()) {
  4137. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  4138. }
  4139. }
  4140. {
  4141. auto&& iter = state.find("workspace_limit");
  4142. if (iter != state.end()) {
  4143. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  4144. }
  4145. }
  4146. {
  4147. auto&& iter = state.find("dtype");
  4148. if (iter != state.end()) {
  4149. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  4150. }
  4151. }
  4152. Py_RETURN_NONE;
  4153. }
  4154. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  4155. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  4156. static PyMethodDef py_init_methoddef;
  4157. // };
  4158. PyOpDefEnd(ConvBias)
  4159. int PyOp(ConvBias)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  4160. static const char* kwlist[] = {"nonlineMode", "mode", "sparse", "format", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "compute_mode", "strategy", "workspace_limit", "dtype", "scope", NULL};
  4161. PyObject *nonlineMode = NULL, *mode = NULL, *sparse = NULL, *format = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *compute_mode = NULL, *strategy = NULL, *workspace_limit = NULL, *dtype = NULL, *scope = NULL;
  4162. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOOO", const_cast<char**>(kwlist), &nonlineMode, &mode, &sparse, &format, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &compute_mode, &strategy, &workspace_limit, &dtype, &scope))
  4163. return -1;
  4164. if (nonlineMode) {
  4165. try {
  4166. // TODO: remove this guard which is used for pybind11 implicit conversion
  4167. py::detail::loader_life_support guard{};
  4168. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().nonlineMode =
  4169. py::cast<decltype(ConvBias::nonlineMode)>(py::handle(nonlineMode));
  4170. } CATCH_ALL(-1)
  4171. }
  4172. if (mode) {
  4173. try {
  4174. // TODO: remove this guard which is used for pybind11 implicit conversion
  4175. py::detail::loader_life_support guard{};
  4176. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().mode =
  4177. py::cast<decltype(ConvBias::mode)>(py::handle(mode));
  4178. } CATCH_ALL(-1)
  4179. }
  4180. if (sparse) {
  4181. try {
  4182. // TODO: remove this guard which is used for pybind11 implicit conversion
  4183. py::detail::loader_life_support guard{};
  4184. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().sparse =
  4185. py::cast<decltype(ConvBias::sparse)>(py::handle(sparse));
  4186. } CATCH_ALL(-1)
  4187. }
  4188. if (format) {
  4189. try {
  4190. // TODO: remove this guard which is used for pybind11 implicit conversion
  4191. py::detail::loader_life_support guard{};
  4192. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().format =
  4193. py::cast<decltype(ConvBias::format)>(py::handle(format));
  4194. } CATCH_ALL(-1)
  4195. }
  4196. if (pad_h) {
  4197. try {
  4198. // TODO: remove this guard which is used for pybind11 implicit conversion
  4199. py::detail::loader_life_support guard{};
  4200. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().pad_h =
  4201. py::cast<decltype(ConvBias::pad_h)>(py::handle(pad_h));
  4202. } CATCH_ALL(-1)
  4203. }
  4204. if (pad_w) {
  4205. try {
  4206. // TODO: remove this guard which is used for pybind11 implicit conversion
  4207. py::detail::loader_life_support guard{};
  4208. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().pad_w =
  4209. py::cast<decltype(ConvBias::pad_w)>(py::handle(pad_w));
  4210. } CATCH_ALL(-1)
  4211. }
  4212. if (stride_h) {
  4213. try {
  4214. // TODO: remove this guard which is used for pybind11 implicit conversion
  4215. py::detail::loader_life_support guard{};
  4216. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().stride_h =
  4217. py::cast<decltype(ConvBias::stride_h)>(py::handle(stride_h));
  4218. } CATCH_ALL(-1)
  4219. }
  4220. if (stride_w) {
  4221. try {
  4222. // TODO: remove this guard which is used for pybind11 implicit conversion
  4223. py::detail::loader_life_support guard{};
  4224. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().stride_w =
  4225. py::cast<decltype(ConvBias::stride_w)>(py::handle(stride_w));
  4226. } CATCH_ALL(-1)
  4227. }
  4228. if (dilate_h) {
  4229. try {
  4230. // TODO: remove this guard which is used for pybind11 implicit conversion
  4231. py::detail::loader_life_support guard{};
  4232. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().dilate_h =
  4233. py::cast<decltype(ConvBias::dilate_h)>(py::handle(dilate_h));
  4234. } CATCH_ALL(-1)
  4235. }
  4236. if (dilate_w) {
  4237. try {
  4238. // TODO: remove this guard which is used for pybind11 implicit conversion
  4239. py::detail::loader_life_support guard{};
  4240. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().dilate_w =
  4241. py::cast<decltype(ConvBias::dilate_w)>(py::handle(dilate_w));
  4242. } CATCH_ALL(-1)
  4243. }
  4244. if (compute_mode) {
  4245. try {
  4246. // TODO: remove this guard which is used for pybind11 implicit conversion
  4247. py::detail::loader_life_support guard{};
  4248. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().compute_mode =
  4249. py::cast<decltype(ConvBias::compute_mode)>(py::handle(compute_mode));
  4250. } CATCH_ALL(-1)
  4251. }
  4252. if (strategy) {
  4253. try {
  4254. // TODO: remove this guard which is used for pybind11 implicit conversion
  4255. py::detail::loader_life_support guard{};
  4256. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().strategy =
  4257. py::cast<decltype(ConvBias::strategy)>(py::handle(strategy));
  4258. } CATCH_ALL(-1)
  4259. }
  4260. if (workspace_limit) {
  4261. try {
  4262. // TODO: remove this guard which is used for pybind11 implicit conversion
  4263. py::detail::loader_life_support guard{};
  4264. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().workspace_limit =
  4265. py::cast<decltype(ConvBias::workspace_limit)>(py::handle(workspace_limit));
  4266. } CATCH_ALL(-1)
  4267. }
  4268. if (dtype) {
  4269. try {
  4270. // TODO: remove this guard which is used for pybind11 implicit conversion
  4271. py::detail::loader_life_support guard{};
  4272. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().dtype =
  4273. py::cast<decltype(ConvBias::dtype)>(py::handle(dtype));
  4274. } CATCH_ALL(-1)
  4275. }
  4276. if (scope) {
  4277. try {
  4278. reinterpret_cast<PyOp(OpDef)*>(self)->op
  4279. ->set_scope(py::cast<std::string>(py::handle(scope)));
  4280. } CATCH_ALL(-1)
  4281. }
  4282. return 0;
  4283. }
  4284. PyGetSetDef PyOp(ConvBias)::py_getsetters[] = {
  4285. {const_cast<char*>("nonlineMode"), py_get_generic(ConvBias, nonlineMode), py_set_generic(ConvBias, nonlineMode), const_cast<char*>("nonlineMode"), NULL},
  4286. {const_cast<char*>("mode"), py_get_generic(ConvBias, mode), py_set_generic(ConvBias, mode), const_cast<char*>("mode"), NULL},
  4287. {const_cast<char*>("sparse"), py_get_generic(ConvBias, sparse), py_set_generic(ConvBias, sparse), const_cast<char*>("sparse"), NULL},
  4288. {const_cast<char*>("format"), py_get_generic(ConvBias, format), py_set_generic(ConvBias, format), const_cast<char*>("format"), NULL},
  4289. {const_cast<char*>("pad_h"), py_get_generic(ConvBias, pad_h), py_set_generic(ConvBias, pad_h), const_cast<char*>("pad_h"), NULL},
  4290. {const_cast<char*>("pad_w"), py_get_generic(ConvBias, pad_w), py_set_generic(ConvBias, pad_w), const_cast<char*>("pad_w"), NULL},
  4291. {const_cast<char*>("stride_h"), py_get_generic(ConvBias, stride_h), py_set_generic(ConvBias, stride_h), const_cast<char*>("stride_h"), NULL},
  4292. {const_cast<char*>("stride_w"), py_get_generic(ConvBias, stride_w), py_set_generic(ConvBias, stride_w), const_cast<char*>("stride_w"), NULL},
  4293. {const_cast<char*>("dilate_h"), py_get_generic(ConvBias, dilate_h), py_set_generic(ConvBias, dilate_h), const_cast<char*>("dilate_h"), NULL},
  4294. {const_cast<char*>("dilate_w"), py_get_generic(ConvBias, dilate_w), py_set_generic(ConvBias, dilate_w), const_cast<char*>("dilate_w"), NULL},
  4295. {const_cast<char*>("compute_mode"), py_get_generic(ConvBias, compute_mode), py_set_generic(ConvBias, compute_mode), const_cast<char*>("compute_mode"), NULL},
  4296. {const_cast<char*>("strategy"), py_get_generic(ConvBias, strategy), py_set_generic(ConvBias, strategy), const_cast<char*>("strategy"), NULL},
  4297. {const_cast<char*>("workspace_limit"), py_get_generic(ConvBias, workspace_limit), py_set_generic(ConvBias, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  4298. {const_cast<char*>("dtype"), py_get_generic(ConvBias, dtype), py_set_generic(ConvBias, dtype), const_cast<char*>("dtype"), NULL},
  4299. {NULL} /* Sentinel */
  4300. };
  4301. PyMethodDef PyOp(ConvBias)::tp_methods[] = {
  4302. {const_cast<char*>("__getstate__"), PyOp(ConvBias)::getstate, METH_NOARGS, "ConvBias getstate"},
  4303. {const_cast<char*>("__setstate__"), PyOp(ConvBias)::setstate, METH_VARARGS, "ConvBias setstate"},
  4304. {NULL} /* Sentinel */
  4305. };
  4306. PyObject *PyOp(ConvBias)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  4307. if (PyOp(ConvBias)::py_init(self, args, kwds) < 0) {
  4308. return NULL;
  4309. }
  4310. Py_RETURN_NONE;
  4311. }
  4312. PyMethodDef PyOp(ConvBias)::py_init_methoddef = {
  4313. "__init__",
  4314. (PyCFunction)PyOp(ConvBias)::py_init_proxy,
  4315. METH_VARARGS | METH_KEYWORDS,
  4316. "__init__(self, nonlineMode: Union[str, NonlineMode] = ..., mode: Union[str, Mode] = ..., sparse: Union[str, Sparse] = ..., format: Union[str, Format] = ..., pad_h: int = ..., pad_w: int = ..., stride_h: int = ..., stride_w: int = ..., dilate_h: int = ..., dilate_w: int = ..., compute_mode: Union[str, ComputeMode] = ..., strategy: Union[str, Strategy] = ..., dtype: str = ...) -> None\n"
  4317. };
  4318. void _init_py_ConvBias(py::module m) {
  4319. using py_op = PyOp(ConvBias);
  4320. auto& py_type = PyOpType(ConvBias);
  4321. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  4322. py_type.tp_name = "megengine.core._imperative_rt.ops.ConvBias";
  4323. py_type.tp_basicsize = sizeof(PyOp(ConvBias));
  4324. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  4325. py_type.tp_doc = "ConvBias";
  4326. py_type.tp_base = &PyOpType(OpDef);
  4327. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  4328. py_type.tp_new = py_new_generic<py_op>;
  4329. py_type.tp_init = py_op::py_init;
  4330. py_type.tp_methods = py_op::tp_methods;
  4331. py_type.tp_getset = py_op::py_getsetters;
  4332. py_type.tp_dict = PyDict_New();
  4333. PyObject* descr = PyDescr_NewMethod(&PyOpType(ConvBias), &PyOp(ConvBias)::py_init_methoddef);
  4334. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  4335. mgb_assert(PyType_Ready(&py_type) >= 0);
  4336. _init_py_ConvBias_NonlineMode(py_type);
  4337. _init_py_ConvBias_Mode(py_type);
  4338. _init_py_ConvBias_Sparse(py_type);
  4339. _init_py_ConvBias_Format(py_type);
  4340. _init_py_ConvBias_ComputeMode(py_type);
  4341. _init_py_ConvBias_Strategy(py_type);
  4342. PyType_Modified(&py_type);
  4343. m.add_object("ConvBias", reinterpret_cast<PyObject*>(&py_type));
  4344. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ConvBias::typeinfo(), &py_type).second);
  4345. }
  4346. void _init_py_Convolution_Mode(PyTypeObject& py_type) {
  4347. auto& e_type = EnumWrapper<Convolution::Mode>::type;
  4348. Py_INCREF(e_type);
  4349. mgb_assert(PyDict_SetItemString(
  4350. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4351. }
  4352. void _init_py_Convolution_Sparse(PyTypeObject& py_type) {
  4353. auto& e_type = EnumWrapper<Convolution::Sparse>::type;
  4354. Py_INCREF(e_type);
  4355. mgb_assert(PyDict_SetItemString(
  4356. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4357. }
  4358. void _init_py_Convolution_Format(PyTypeObject& py_type) {
  4359. auto& e_type = EnumWrapper<Convolution::Format>::type;
  4360. Py_INCREF(e_type);
  4361. mgb_assert(PyDict_SetItemString(
  4362. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4363. }
  4364. void _init_py_Convolution_ComputeMode(PyTypeObject& py_type) {
  4365. auto& e_type = EnumWrapper<Convolution::ComputeMode>::type;
  4366. Py_INCREF(e_type);
  4367. mgb_assert(PyDict_SetItemString(
  4368. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4369. }
  4370. void _init_py_Convolution_Strategy(PyTypeObject& py_type) {
  4371. auto& e_type = BitCombinedEnumWrapper<Convolution::Strategy>::type;
  4372. Py_INCREF(e_type);
  4373. mgb_assert(PyDict_SetItemString(
  4374. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4375. }
  4376. PyOpDefBegin(Convolution) // {
  4377. static PyGetSetDef py_getsetters[];
  4378. static PyMethodDef tp_methods[];
  4379. static PyObject* getstate(PyObject* self, PyObject*) {
  4380. auto& opdef = reinterpret_cast<PyOp(Convolution)*>(self)->inst();
  4381. static_cast<void>(opdef);
  4382. std::unordered_map<std::string, py::object> state {
  4383. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  4384. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  4385. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  4386. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  4387. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  4388. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  4389. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  4390. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  4391. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  4392. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  4393. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  4394. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)}
  4395. };
  4396. return py::cast(state).release().ptr();
  4397. }
  4398. static PyObject* setstate(PyObject* self, PyObject* args) {
  4399. PyObject* dict = PyTuple_GetItem(args, 0);
  4400. if (!dict) return NULL;
  4401. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  4402. auto& opdef = reinterpret_cast<PyOp(Convolution)*>(self)->inst();
  4403. static_cast<void>(opdef);
  4404. {
  4405. auto&& iter = state.find("mode");
  4406. if (iter != state.end()) {
  4407. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  4408. }
  4409. }
  4410. {
  4411. auto&& iter = state.find("pad_h");
  4412. if (iter != state.end()) {
  4413. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  4414. }
  4415. }
  4416. {
  4417. auto&& iter = state.find("pad_w");
  4418. if (iter != state.end()) {
  4419. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  4420. }
  4421. }
  4422. {
  4423. auto&& iter = state.find("stride_h");
  4424. if (iter != state.end()) {
  4425. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  4426. }
  4427. }
  4428. {
  4429. auto&& iter = state.find("stride_w");
  4430. if (iter != state.end()) {
  4431. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  4432. }
  4433. }
  4434. {
  4435. auto&& iter = state.find("dilate_h");
  4436. if (iter != state.end()) {
  4437. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  4438. }
  4439. }
  4440. {
  4441. auto&& iter = state.find("dilate_w");
  4442. if (iter != state.end()) {
  4443. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  4444. }
  4445. }
  4446. {
  4447. auto&& iter = state.find("sparse");
  4448. if (iter != state.end()) {
  4449. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  4450. }
  4451. }
  4452. {
  4453. auto&& iter = state.find("format");
  4454. if (iter != state.end()) {
  4455. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  4456. }
  4457. }
  4458. {
  4459. auto&& iter = state.find("compute_mode");
  4460. if (iter != state.end()) {
  4461. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  4462. }
  4463. }
  4464. {
  4465. auto&& iter = state.find("strategy");
  4466. if (iter != state.end()) {
  4467. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  4468. }
  4469. }
  4470. {
  4471. auto&& iter = state.find("workspace_limit");
  4472. if (iter != state.end()) {
  4473. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  4474. }
  4475. }
  4476. Py_RETURN_NONE;
  4477. }
  4478. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  4479. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  4480. static PyMethodDef py_init_methoddef;
  4481. // };
  4482. PyOpDefEnd(Convolution)
  4483. int PyOp(Convolution)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  4484. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "strategy", "workspace_limit", "scope", NULL};
  4485. PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *strategy = NULL, *workspace_limit = NULL, *scope = NULL;
  4486. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &strategy, &workspace_limit, &scope))
  4487. return -1;
  4488. if (mode) {
  4489. try {
  4490. // TODO: remove this guard which is used for pybind11 implicit conversion
  4491. py::detail::loader_life_support guard{};
  4492. reinterpret_cast<PyOp(Convolution)*>(self)->inst().mode =
  4493. py::cast<decltype(Convolution::mode)>(py::handle(mode));
  4494. } CATCH_ALL(-1)
  4495. }
  4496. if (pad_h) {
  4497. try {
  4498. // TODO: remove this guard which is used for pybind11 implicit conversion
  4499. py::detail::loader_life_support guard{};
  4500. reinterpret_cast<PyOp(Convolution)*>(self)->inst().pad_h =
  4501. py::cast<decltype(Convolution::pad_h)>(py::handle(pad_h));
  4502. } CATCH_ALL(-1)
  4503. }
  4504. if (pad_w) {
  4505. try {
  4506. // TODO: remove this guard which is used for pybind11 implicit conversion
  4507. py::detail::loader_life_support guard{};
  4508. reinterpret_cast<PyOp(Convolution)*>(self)->inst().pad_w =
  4509. py::cast<decltype(Convolution::pad_w)>(py::handle(pad_w));
  4510. } CATCH_ALL(-1)
  4511. }
  4512. if (stride_h) {
  4513. try {
  4514. // TODO: remove this guard which is used for pybind11 implicit conversion
  4515. py::detail::loader_life_support guard{};
  4516. reinterpret_cast<PyOp(Convolution)*>(self)->inst().stride_h =
  4517. py::cast<decltype(Convolution::stride_h)>(py::handle(stride_h));
  4518. } CATCH_ALL(-1)
  4519. }
  4520. if (stride_w) {
  4521. try {
  4522. // TODO: remove this guard which is used for pybind11 implicit conversion
  4523. py::detail::loader_life_support guard{};
  4524. reinterpret_cast<PyOp(Convolution)*>(self)->inst().stride_w =
  4525. py::cast<decltype(Convolution::stride_w)>(py::handle(stride_w));
  4526. } CATCH_ALL(-1)
  4527. }
  4528. if (dilate_h) {
  4529. try {
  4530. // TODO: remove this guard which is used for pybind11 implicit conversion
  4531. py::detail::loader_life_support guard{};
  4532. reinterpret_cast<PyOp(Convolution)*>(self)->inst().dilate_h =
  4533. py::cast<decltype(Convolution::dilate_h)>(py::handle(dilate_h));
  4534. } CATCH_ALL(-1)
  4535. }
  4536. if (dilate_w) {
  4537. try {
  4538. // TODO: remove this guard which is used for pybind11 implicit conversion
  4539. py::detail::loader_life_support guard{};
  4540. reinterpret_cast<PyOp(Convolution)*>(self)->inst().dilate_w =
  4541. py::cast<decltype(Convolution::dilate_w)>(py::handle(dilate_w));
  4542. } CATCH_ALL(-1)
  4543. }
  4544. if (sparse) {
  4545. try {
  4546. // TODO: remove this guard which is used for pybind11 implicit conversion
  4547. py::detail::loader_life_support guard{};
  4548. reinterpret_cast<PyOp(Convolution)*>(self)->inst().sparse =
  4549. py::cast<decltype(Convolution::sparse)>(py::handle(sparse));
  4550. } CATCH_ALL(-1)
  4551. }
  4552. if (format) {
  4553. try {
  4554. // TODO: remove this guard which is used for pybind11 implicit conversion
  4555. py::detail::loader_life_support guard{};
  4556. reinterpret_cast<PyOp(Convolution)*>(self)->inst().format =
  4557. py::cast<decltype(Convolution::format)>(py::handle(format));
  4558. } CATCH_ALL(-1)
  4559. }
  4560. if (compute_mode) {
  4561. try {
  4562. // TODO: remove this guard which is used for pybind11 implicit conversion
  4563. py::detail::loader_life_support guard{};
  4564. reinterpret_cast<PyOp(Convolution)*>(self)->inst().compute_mode =
  4565. py::cast<decltype(Convolution::compute_mode)>(py::handle(compute_mode));
  4566. } CATCH_ALL(-1)
  4567. }
  4568. if (strategy) {
  4569. try {
  4570. // TODO: remove this guard which is used for pybind11 implicit conversion
  4571. py::detail::loader_life_support guard{};
  4572. reinterpret_cast<PyOp(Convolution)*>(self)->inst().strategy =
  4573. py::cast<decltype(Convolution::strategy)>(py::handle(strategy));
  4574. } CATCH_ALL(-1)
  4575. }
  4576. if (workspace_limit) {
  4577. try {
  4578. // TODO: remove this guard which is used for pybind11 implicit conversion
  4579. py::detail::loader_life_support guard{};
  4580. reinterpret_cast<PyOp(Convolution)*>(self)->inst().workspace_limit =
  4581. py::cast<decltype(Convolution::workspace_limit)>(py::handle(workspace_limit));
  4582. } CATCH_ALL(-1)
  4583. }
  4584. if (scope) {
  4585. try {
  4586. reinterpret_cast<PyOp(OpDef)*>(self)->op
  4587. ->set_scope(py::cast<std::string>(py::handle(scope)));
  4588. } CATCH_ALL(-1)
  4589. }
  4590. return 0;
  4591. }
  4592. PyGetSetDef PyOp(Convolution)::py_getsetters[] = {
  4593. {const_cast<char*>("mode"), py_get_generic(Convolution, mode), py_set_generic(Convolution, mode), const_cast<char*>("mode"), NULL},
  4594. {const_cast<char*>("pad_h"), py_get_generic(Convolution, pad_h), py_set_generic(Convolution, pad_h), const_cast<char*>("pad_h"), NULL},
  4595. {const_cast<char*>("pad_w"), py_get_generic(Convolution, pad_w), py_set_generic(Convolution, pad_w), const_cast<char*>("pad_w"), NULL},
  4596. {const_cast<char*>("stride_h"), py_get_generic(Convolution, stride_h), py_set_generic(Convolution, stride_h), const_cast<char*>("stride_h"), NULL},
  4597. {const_cast<char*>("stride_w"), py_get_generic(Convolution, stride_w), py_set_generic(Convolution, stride_w), const_cast<char*>("stride_w"), NULL},
  4598. {const_cast<char*>("dilate_h"), py_get_generic(Convolution, dilate_h), py_set_generic(Convolution, dilate_h), const_cast<char*>("dilate_h"), NULL},
  4599. {const_cast<char*>("dilate_w"), py_get_generic(Convolution, dilate_w), py_set_generic(Convolution, dilate_w), const_cast<char*>("dilate_w"), NULL},
  4600. {const_cast<char*>("sparse"), py_get_generic(Convolution, sparse), py_set_generic(Convolution, sparse), const_cast<char*>("sparse"), NULL},
  4601. {const_cast<char*>("format"), py_get_generic(Convolution, format), py_set_generic(Convolution, format), const_cast<char*>("format"), NULL},
  4602. {const_cast<char*>("compute_mode"), py_get_generic(Convolution, compute_mode), py_set_generic(Convolution, compute_mode), const_cast<char*>("compute_mode"), NULL},
  4603. {const_cast<char*>("strategy"), py_get_generic(Convolution, strategy), py_set_generic(Convolution, strategy), const_cast<char*>("strategy"), NULL},
  4604. {const_cast<char*>("workspace_limit"), py_get_generic(Convolution, workspace_limit), py_set_generic(Convolution, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  4605. {NULL} /* Sentinel */
  4606. };
  4607. PyMethodDef PyOp(Convolution)::tp_methods[] = {
  4608. {const_cast<char*>("__getstate__"), PyOp(Convolution)::getstate, METH_NOARGS, "Convolution getstate"},
  4609. {const_cast<char*>("__setstate__"), PyOp(Convolution)::setstate, METH_VARARGS, "Convolution setstate"},
  4610. {NULL} /* Sentinel */
  4611. };
  4612. PyObject *PyOp(Convolution)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  4613. if (PyOp(Convolution)::py_init(self, args, kwds) < 0) {
  4614. return NULL;
  4615. }
  4616. Py_RETURN_NONE;
  4617. }
  4618. PyMethodDef PyOp(Convolution)::py_init_methoddef = {
  4619. "__init__",
  4620. (PyCFunction)PyOp(Convolution)::py_init_proxy,
  4621. METH_VARARGS | METH_KEYWORDS,
  4622. "__init__(self, mode: Union[str, Mode] = ..., pad_h: int = ..., pad_w: int = ..., stride_h: int = ..., stride_w: int = ..., dilate_h: int = ..., dilate_w: int = ..., sparse: Union[str, Sparse] = ..., format: Union[str, Format] = ..., compute_mode: Union[str, ComputeMode] = ..., strategy: Union[str, Strategy] = ...) -> None\n"
  4623. };
  4624. void _init_py_Convolution(py::module m) {
  4625. using py_op = PyOp(Convolution);
  4626. auto& py_type = PyOpType(Convolution);
  4627. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  4628. py_type.tp_name = "megengine.core._imperative_rt.ops.Convolution";
  4629. py_type.tp_basicsize = sizeof(PyOp(Convolution));
  4630. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  4631. py_type.tp_doc = "Convolution";
  4632. py_type.tp_base = &PyOpType(OpDef);
  4633. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  4634. py_type.tp_new = py_new_generic<py_op>;
  4635. py_type.tp_init = py_op::py_init;
  4636. py_type.tp_methods = py_op::tp_methods;
  4637. py_type.tp_getset = py_op::py_getsetters;
  4638. py_type.tp_dict = PyDict_New();
  4639. PyObject* descr = PyDescr_NewMethod(&PyOpType(Convolution), &PyOp(Convolution)::py_init_methoddef);
  4640. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  4641. mgb_assert(PyType_Ready(&py_type) >= 0);
  4642. _init_py_Convolution_Mode(py_type);
  4643. _init_py_Convolution_Sparse(py_type);
  4644. _init_py_Convolution_Format(py_type);
  4645. _init_py_Convolution_ComputeMode(py_type);
  4646. _init_py_Convolution_Strategy(py_type);
  4647. PyType_Modified(&py_type);
  4648. m.add_object("Convolution", reinterpret_cast<PyObject*>(&py_type));
  4649. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Convolution::typeinfo(), &py_type).second);
  4650. }
  4651. template<> struct EnumTrait<Convolution3D::Mode> {
  4652. static constexpr const char *name = "Convolution3D.Mode";
  4653. static constexpr std::underlying_type_t<Convolution3D::Mode> max = 2 - 1;
  4654. };
  4655. template<> PyTypeObject* EnumWrapper<Convolution3D::Mode>::type = nullptr;
  4656. template<> const char*
  4657. EnumWrapper<Convolution3D::Mode>::members[] = {"CROSS_CORRELATION", "CONVOLUTION"};
  4658. template<> std::unordered_map<std::string, Convolution3D::Mode>
  4659. EnumWrapper<Convolution3D::Mode>::mem2value = {{normalize_enum("CROSS_CORRELATION"), Convolution3D::Mode::CROSS_CORRELATION}, {normalize_enum("CONVOLUTION"), Convolution3D::Mode::CONVOLUTION}};
  4660. template<> PyObject* EnumWrapper<Convolution3D::Mode>::pyobj_insts[2] = {nullptr};
  4661. void _init_py_Convolution3D_Mode(PyTypeObject& py_type) {
  4662. auto& e_type = EnumWrapper<Convolution3D::Mode>::type;
  4663. static PyMethodDef tp_methods[] = {
  4664. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Convolution3D::Mode>::py_dump, METH_NOARGS, NULL},
  4665. {NULL} /* Sentinel */
  4666. };
  4667. static PyType_Slot slots[] = {
  4668. {Py_tp_repr, (void*)EnumWrapper<Convolution3D::Mode>::py_repr},
  4669. {Py_tp_richcompare, (void*)EnumWrapper<Convolution3D::Mode>::tp_richcompare},
  4670. {Py_tp_methods, tp_methods},
  4671. {0, NULL}
  4672. };
  4673. static PyType_Spec spec = {
  4674. // name
  4675. "megengine.core._imperative_rt.ops.Convolution3D.Mode",
  4676. // basicsize
  4677. sizeof(EnumWrapper<Convolution3D::Mode>),
  4678. // itemsize
  4679. 0,
  4680. // flags
  4681. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  4682. // slots
  4683. slots
  4684. };
  4685. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  4686. mgb_assert(
  4687. e_type->tp_setattro(
  4688. reinterpret_cast<PyObject*>(e_type),
  4689. py::cast("__name__").release().ptr(),
  4690. py::cast("Mode").release().ptr()) >= 0);
  4691. mgb_assert(
  4692. e_type->tp_setattro(
  4693. reinterpret_cast<PyObject*>(e_type),
  4694. py::cast("__module__").release().ptr(),
  4695. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  4696. mgb_assert(
  4697. e_type->tp_setattro(
  4698. reinterpret_cast<PyObject*>(e_type),
  4699. py::cast("__qualname__").release().ptr(),
  4700. py::cast("Convolution3D.Mode").release().ptr()) >= 0);
  4701. {
  4702. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4703. reinterpret_cast<EnumWrapper<Convolution3D::Mode>*>(inst)->value = Convolution3D::Mode::CROSS_CORRELATION;
  4704. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CROSS_CORRELATION", inst) >= 0);
  4705. EnumWrapper<Convolution3D::Mode>::pyobj_insts[0] = inst;
  4706. }{
  4707. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4708. reinterpret_cast<EnumWrapper<Convolution3D::Mode>*>(inst)->value = Convolution3D::Mode::CONVOLUTION;
  4709. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CONVOLUTION", inst) >= 0);
  4710. EnumWrapper<Convolution3D::Mode>::pyobj_insts[1] = inst;
  4711. }
  4712. Py_INCREF(e_type);
  4713. mgb_assert(PyDict_SetItemString(
  4714. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4715. }
  4716. template<> struct EnumTrait<Convolution3D::Sparse> {
  4717. static constexpr const char *name = "Convolution3D.Sparse";
  4718. static constexpr std::underlying_type_t<Convolution3D::Sparse> max = 2 - 1;
  4719. };
  4720. template<> PyTypeObject* EnumWrapper<Convolution3D::Sparse>::type = nullptr;
  4721. template<> const char*
  4722. EnumWrapper<Convolution3D::Sparse>::members[] = {"DENSE", "GROUP"};
  4723. template<> std::unordered_map<std::string, Convolution3D::Sparse>
  4724. EnumWrapper<Convolution3D::Sparse>::mem2value = {{normalize_enum("DENSE"), Convolution3D::Sparse::DENSE}, {normalize_enum("GROUP"), Convolution3D::Sparse::GROUP}};
  4725. template<> PyObject* EnumWrapper<Convolution3D::Sparse>::pyobj_insts[2] = {nullptr};
  4726. void _init_py_Convolution3D_Sparse(PyTypeObject& py_type) {
  4727. auto& e_type = EnumWrapper<Convolution3D::Sparse>::type;
  4728. static PyMethodDef tp_methods[] = {
  4729. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Convolution3D::Sparse>::py_dump, METH_NOARGS, NULL},
  4730. {NULL} /* Sentinel */
  4731. };
  4732. static PyType_Slot slots[] = {
  4733. {Py_tp_repr, (void*)EnumWrapper<Convolution3D::Sparse>::py_repr},
  4734. {Py_tp_richcompare, (void*)EnumWrapper<Convolution3D::Sparse>::tp_richcompare},
  4735. {Py_tp_methods, tp_methods},
  4736. {0, NULL}
  4737. };
  4738. static PyType_Spec spec = {
  4739. // name
  4740. "megengine.core._imperative_rt.ops.Convolution3D.Sparse",
  4741. // basicsize
  4742. sizeof(EnumWrapper<Convolution3D::Sparse>),
  4743. // itemsize
  4744. 0,
  4745. // flags
  4746. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  4747. // slots
  4748. slots
  4749. };
  4750. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  4751. mgb_assert(
  4752. e_type->tp_setattro(
  4753. reinterpret_cast<PyObject*>(e_type),
  4754. py::cast("__name__").release().ptr(),
  4755. py::cast("Sparse").release().ptr()) >= 0);
  4756. mgb_assert(
  4757. e_type->tp_setattro(
  4758. reinterpret_cast<PyObject*>(e_type),
  4759. py::cast("__module__").release().ptr(),
  4760. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  4761. mgb_assert(
  4762. e_type->tp_setattro(
  4763. reinterpret_cast<PyObject*>(e_type),
  4764. py::cast("__qualname__").release().ptr(),
  4765. py::cast("Convolution3D.Sparse").release().ptr()) >= 0);
  4766. {
  4767. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4768. reinterpret_cast<EnumWrapper<Convolution3D::Sparse>*>(inst)->value = Convolution3D::Sparse::DENSE;
  4769. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DENSE", inst) >= 0);
  4770. EnumWrapper<Convolution3D::Sparse>::pyobj_insts[0] = inst;
  4771. }{
  4772. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4773. reinterpret_cast<EnumWrapper<Convolution3D::Sparse>*>(inst)->value = Convolution3D::Sparse::GROUP;
  4774. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GROUP", inst) >= 0);
  4775. EnumWrapper<Convolution3D::Sparse>::pyobj_insts[1] = inst;
  4776. }
  4777. Py_INCREF(e_type);
  4778. mgb_assert(PyDict_SetItemString(
  4779. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4780. }
  4781. template<> struct EnumTrait<Convolution3D::DataType> {
  4782. static constexpr const char *name = "Convolution3D.DataType";
  4783. static constexpr std::underlying_type_t<Convolution3D::DataType> max = 2 - 1;
  4784. };
  4785. template<> PyTypeObject* EnumWrapper<Convolution3D::DataType>::type = nullptr;
  4786. template<> const char*
  4787. EnumWrapper<Convolution3D::DataType>::members[] = {"FLOAT", "FLOAT_IO16xC32"};
  4788. template<> std::unordered_map<std::string, Convolution3D::DataType>
  4789. EnumWrapper<Convolution3D::DataType>::mem2value = {{normalize_enum("FLOAT"), Convolution3D::DataType::FLOAT}, {normalize_enum("FLOAT_IO16xC32"), Convolution3D::DataType::FLOAT_IO16xC32}};
  4790. template<> PyObject* EnumWrapper<Convolution3D::DataType>::pyobj_insts[2] = {nullptr};
  4791. void _init_py_Convolution3D_DataType(PyTypeObject& py_type) {
  4792. auto& e_type = EnumWrapper<Convolution3D::DataType>::type;
  4793. static PyMethodDef tp_methods[] = {
  4794. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Convolution3D::DataType>::py_dump, METH_NOARGS, NULL},
  4795. {NULL} /* Sentinel */
  4796. };
  4797. static PyType_Slot slots[] = {
  4798. {Py_tp_repr, (void*)EnumWrapper<Convolution3D::DataType>::py_repr},
  4799. {Py_tp_richcompare, (void*)EnumWrapper<Convolution3D::DataType>::tp_richcompare},
  4800. {Py_tp_methods, tp_methods},
  4801. {0, NULL}
  4802. };
  4803. static PyType_Spec spec = {
  4804. // name
  4805. "megengine.core._imperative_rt.ops.Convolution3D.DataType",
  4806. // basicsize
  4807. sizeof(EnumWrapper<Convolution3D::DataType>),
  4808. // itemsize
  4809. 0,
  4810. // flags
  4811. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  4812. // slots
  4813. slots
  4814. };
  4815. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  4816. mgb_assert(
  4817. e_type->tp_setattro(
  4818. reinterpret_cast<PyObject*>(e_type),
  4819. py::cast("__name__").release().ptr(),
  4820. py::cast("DataType").release().ptr()) >= 0);
  4821. mgb_assert(
  4822. e_type->tp_setattro(
  4823. reinterpret_cast<PyObject*>(e_type),
  4824. py::cast("__module__").release().ptr(),
  4825. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  4826. mgb_assert(
  4827. e_type->tp_setattro(
  4828. reinterpret_cast<PyObject*>(e_type),
  4829. py::cast("__qualname__").release().ptr(),
  4830. py::cast("Convolution3D.DataType").release().ptr()) >= 0);
  4831. {
  4832. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4833. reinterpret_cast<EnumWrapper<Convolution3D::DataType>*>(inst)->value = Convolution3D::DataType::FLOAT;
  4834. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT", inst) >= 0);
  4835. EnumWrapper<Convolution3D::DataType>::pyobj_insts[0] = inst;
  4836. }{
  4837. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4838. reinterpret_cast<EnumWrapper<Convolution3D::DataType>*>(inst)->value = Convolution3D::DataType::FLOAT_IO16xC32;
  4839. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT_IO16xC32", inst) >= 0);
  4840. EnumWrapper<Convolution3D::DataType>::pyobj_insts[1] = inst;
  4841. }
  4842. Py_INCREF(e_type);
  4843. mgb_assert(PyDict_SetItemString(
  4844. py_type.tp_dict, "DataType", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4845. }
  4846. template<> struct EnumTrait<Convolution3D::Format> {
  4847. static constexpr const char *name = "Convolution3D.Format";
  4848. static constexpr std::underlying_type_t<Convolution3D::Format> max = 2 - 1;
  4849. };
  4850. template<> PyTypeObject* EnumWrapper<Convolution3D::Format>::type = nullptr;
  4851. template<> const char*
  4852. EnumWrapper<Convolution3D::Format>::members[] = {"NCDHW", "NDHWC"};
  4853. template<> std::unordered_map<std::string, Convolution3D::Format>
  4854. EnumWrapper<Convolution3D::Format>::mem2value = {{normalize_enum("NCDHW"), Convolution3D::Format::NCDHW}, {normalize_enum("NDHWC"), Convolution3D::Format::NDHWC}};
  4855. template<> PyObject* EnumWrapper<Convolution3D::Format>::pyobj_insts[2] = {nullptr};
  4856. void _init_py_Convolution3D_Format(PyTypeObject& py_type) {
  4857. auto& e_type = EnumWrapper<Convolution3D::Format>::type;
  4858. static PyMethodDef tp_methods[] = {
  4859. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Convolution3D::Format>::py_dump, METH_NOARGS, NULL},
  4860. {NULL} /* Sentinel */
  4861. };
  4862. static PyType_Slot slots[] = {
  4863. {Py_tp_repr, (void*)EnumWrapper<Convolution3D::Format>::py_repr},
  4864. {Py_tp_richcompare, (void*)EnumWrapper<Convolution3D::Format>::tp_richcompare},
  4865. {Py_tp_methods, tp_methods},
  4866. {0, NULL}
  4867. };
  4868. static PyType_Spec spec = {
  4869. // name
  4870. "megengine.core._imperative_rt.ops.Convolution3D.Format",
  4871. // basicsize
  4872. sizeof(EnumWrapper<Convolution3D::Format>),
  4873. // itemsize
  4874. 0,
  4875. // flags
  4876. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  4877. // slots
  4878. slots
  4879. };
  4880. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  4881. mgb_assert(
  4882. e_type->tp_setattro(
  4883. reinterpret_cast<PyObject*>(e_type),
  4884. py::cast("__name__").release().ptr(),
  4885. py::cast("Format").release().ptr()) >= 0);
  4886. mgb_assert(
  4887. e_type->tp_setattro(
  4888. reinterpret_cast<PyObject*>(e_type),
  4889. py::cast("__module__").release().ptr(),
  4890. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  4891. mgb_assert(
  4892. e_type->tp_setattro(
  4893. reinterpret_cast<PyObject*>(e_type),
  4894. py::cast("__qualname__").release().ptr(),
  4895. py::cast("Convolution3D.Format").release().ptr()) >= 0);
  4896. {
  4897. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4898. reinterpret_cast<EnumWrapper<Convolution3D::Format>*>(inst)->value = Convolution3D::Format::NCDHW;
  4899. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCDHW", inst) >= 0);
  4900. EnumWrapper<Convolution3D::Format>::pyobj_insts[0] = inst;
  4901. }{
  4902. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4903. reinterpret_cast<EnumWrapper<Convolution3D::Format>*>(inst)->value = Convolution3D::Format::NDHWC;
  4904. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NDHWC", inst) >= 0);
  4905. EnumWrapper<Convolution3D::Format>::pyobj_insts[1] = inst;
  4906. }
  4907. Py_INCREF(e_type);
  4908. mgb_assert(PyDict_SetItemString(
  4909. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4910. }
  4911. void _init_py_Convolution3D_Strategy(PyTypeObject& py_type) {
  4912. auto& e_type = BitCombinedEnumWrapper<Convolution3D::Strategy>::type;
  4913. Py_INCREF(e_type);
  4914. mgb_assert(PyDict_SetItemString(
  4915. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4916. }
  4917. PyOpDefBegin(Convolution3D) // {
  4918. static PyGetSetDef py_getsetters[];
  4919. static PyMethodDef tp_methods[];
  4920. static PyObject* getstate(PyObject* self, PyObject*) {
  4921. auto& opdef = reinterpret_cast<PyOp(Convolution3D)*>(self)->inst();
  4922. static_cast<void>(opdef);
  4923. std::unordered_map<std::string, py::object> state {
  4924. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  4925. {"pad_d", serialization<decltype(opdef.pad_d)>::dump(opdef.pad_d)},
  4926. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  4927. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  4928. {"stride_d", serialization<decltype(opdef.stride_d)>::dump(opdef.stride_d)},
  4929. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  4930. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  4931. {"dilate_d", serialization<decltype(opdef.dilate_d)>::dump(opdef.dilate_d)},
  4932. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  4933. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  4934. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  4935. {"data_type", serialization<decltype(opdef.data_type)>::dump(opdef.data_type)},
  4936. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  4937. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  4938. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)}
  4939. };
  4940. return py::cast(state).release().ptr();
  4941. }
  4942. static PyObject* setstate(PyObject* self, PyObject* args) {
  4943. PyObject* dict = PyTuple_GetItem(args, 0);
  4944. if (!dict) return NULL;
  4945. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  4946. auto& opdef = reinterpret_cast<PyOp(Convolution3D)*>(self)->inst();
  4947. static_cast<void>(opdef);
  4948. {
  4949. auto&& iter = state.find("mode");
  4950. if (iter != state.end()) {
  4951. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  4952. }
  4953. }
  4954. {
  4955. auto&& iter = state.find("pad_d");
  4956. if (iter != state.end()) {
  4957. opdef.pad_d = serialization<decltype(opdef.pad_d)>::load(iter->second);
  4958. }
  4959. }
  4960. {
  4961. auto&& iter = state.find("pad_h");
  4962. if (iter != state.end()) {
  4963. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  4964. }
  4965. }
  4966. {
  4967. auto&& iter = state.find("pad_w");
  4968. if (iter != state.end()) {
  4969. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  4970. }
  4971. }
  4972. {
  4973. auto&& iter = state.find("stride_d");
  4974. if (iter != state.end()) {
  4975. opdef.stride_d = serialization<decltype(opdef.stride_d)>::load(iter->second);
  4976. }
  4977. }
  4978. {
  4979. auto&& iter = state.find("stride_h");
  4980. if (iter != state.end()) {
  4981. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  4982. }
  4983. }
  4984. {
  4985. auto&& iter = state.find("stride_w");
  4986. if (iter != state.end()) {
  4987. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  4988. }
  4989. }
  4990. {
  4991. auto&& iter = state.find("dilate_d");
  4992. if (iter != state.end()) {
  4993. opdef.dilate_d = serialization<decltype(opdef.dilate_d)>::load(iter->second);
  4994. }
  4995. }
  4996. {
  4997. auto&& iter = state.find("dilate_h");
  4998. if (iter != state.end()) {
  4999. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  5000. }
  5001. }
  5002. {
  5003. auto&& iter = state.find("dilate_w");
  5004. if (iter != state.end()) {
  5005. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  5006. }
  5007. }
  5008. {
  5009. auto&& iter = state.find("sparse");
  5010. if (iter != state.end()) {
  5011. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  5012. }
  5013. }
  5014. {
  5015. auto&& iter = state.find("data_type");
  5016. if (iter != state.end()) {
  5017. opdef.data_type = serialization<decltype(opdef.data_type)>::load(iter->second);
  5018. }
  5019. }
  5020. {
  5021. auto&& iter = state.find("format");
  5022. if (iter != state.end()) {
  5023. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  5024. }
  5025. }
  5026. {
  5027. auto&& iter = state.find("strategy");
  5028. if (iter != state.end()) {
  5029. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  5030. }
  5031. }
  5032. {
  5033. auto&& iter = state.find("workspace_limit");
  5034. if (iter != state.end()) {
  5035. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  5036. }
  5037. }
  5038. Py_RETURN_NONE;
  5039. }
  5040. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  5041. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  5042. static PyMethodDef py_init_methoddef;
  5043. // };
  5044. PyOpDefEnd(Convolution3D)
  5045. int PyOp(Convolution3D)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  5046. static const char* kwlist[] = {"mode", "pad_d", "pad_h", "pad_w", "stride_d", "stride_h", "stride_w", "dilate_d", "dilate_h", "dilate_w", "sparse", "data_type", "format", "strategy", "workspace_limit", "scope", NULL};
  5047. PyObject *mode = NULL, *pad_d = NULL, *pad_h = NULL, *pad_w = NULL, *stride_d = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_d = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *data_type = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *scope = NULL;
  5048. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_d, &pad_h, &pad_w, &stride_d, &stride_h, &stride_w, &dilate_d, &dilate_h, &dilate_w, &sparse, &data_type, &format, &strategy, &workspace_limit, &scope))
  5049. return -1;
  5050. if (mode) {
  5051. try {
  5052. // TODO: remove this guard which is used for pybind11 implicit conversion
  5053. py::detail::loader_life_support guard{};
  5054. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().mode =
  5055. py::cast<decltype(Convolution3D::mode)>(py::handle(mode));
  5056. } CATCH_ALL(-1)
  5057. }
  5058. if (pad_d) {
  5059. try {
  5060. // TODO: remove this guard which is used for pybind11 implicit conversion
  5061. py::detail::loader_life_support guard{};
  5062. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().pad_d =
  5063. py::cast<decltype(Convolution3D::pad_d)>(py::handle(pad_d));
  5064. } CATCH_ALL(-1)
  5065. }
  5066. if (pad_h) {
  5067. try {
  5068. // TODO: remove this guard which is used for pybind11 implicit conversion
  5069. py::detail::loader_life_support guard{};
  5070. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().pad_h =
  5071. py::cast<decltype(Convolution3D::pad_h)>(py::handle(pad_h));
  5072. } CATCH_ALL(-1)
  5073. }
  5074. if (pad_w) {
  5075. try {
  5076. // TODO: remove this guard which is used for pybind11 implicit conversion
  5077. py::detail::loader_life_support guard{};
  5078. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().pad_w =
  5079. py::cast<decltype(Convolution3D::pad_w)>(py::handle(pad_w));
  5080. } CATCH_ALL(-1)
  5081. }
  5082. if (stride_d) {
  5083. try {
  5084. // TODO: remove this guard which is used for pybind11 implicit conversion
  5085. py::detail::loader_life_support guard{};
  5086. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().stride_d =
  5087. py::cast<decltype(Convolution3D::stride_d)>(py::handle(stride_d));
  5088. } CATCH_ALL(-1)
  5089. }
  5090. if (stride_h) {
  5091. try {
  5092. // TODO: remove this guard which is used for pybind11 implicit conversion
  5093. py::detail::loader_life_support guard{};
  5094. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().stride_h =
  5095. py::cast<decltype(Convolution3D::stride_h)>(py::handle(stride_h));
  5096. } CATCH_ALL(-1)
  5097. }
  5098. if (stride_w) {
  5099. try {
  5100. // TODO: remove this guard which is used for pybind11 implicit conversion
  5101. py::detail::loader_life_support guard{};
  5102. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().stride_w =
  5103. py::cast<decltype(Convolution3D::stride_w)>(py::handle(stride_w));
  5104. } CATCH_ALL(-1)
  5105. }
  5106. if (dilate_d) {
  5107. try {
  5108. // TODO: remove this guard which is used for pybind11 implicit conversion
  5109. py::detail::loader_life_support guard{};
  5110. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().dilate_d =
  5111. py::cast<decltype(Convolution3D::dilate_d)>(py::handle(dilate_d));
  5112. } CATCH_ALL(-1)
  5113. }
  5114. if (dilate_h) {
  5115. try {
  5116. // TODO: remove this guard which is used for pybind11 implicit conversion
  5117. py::detail::loader_life_support guard{};
  5118. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().dilate_h =
  5119. py::cast<decltype(Convolution3D::dilate_h)>(py::handle(dilate_h));
  5120. } CATCH_ALL(-1)
  5121. }
  5122. if (dilate_w) {
  5123. try {
  5124. // TODO: remove this guard which is used for pybind11 implicit conversion
  5125. py::detail::loader_life_support guard{};
  5126. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().dilate_w =
  5127. py::cast<decltype(Convolution3D::dilate_w)>(py::handle(dilate_w));
  5128. } CATCH_ALL(-1)
  5129. }
  5130. if (sparse) {
  5131. try {
  5132. // TODO: remove this guard which is used for pybind11 implicit conversion
  5133. py::detail::loader_life_support guard{};
  5134. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().sparse =
  5135. py::cast<decltype(Convolution3D::sparse)>(py::handle(sparse));
  5136. } CATCH_ALL(-1)
  5137. }
  5138. if (data_type) {
  5139. try {
  5140. // TODO: remove this guard which is used for pybind11 implicit conversion
  5141. py::detail::loader_life_support guard{};
  5142. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().data_type =
  5143. py::cast<decltype(Convolution3D::data_type)>(py::handle(data_type));
  5144. } CATCH_ALL(-1)
  5145. }
  5146. if (format) {
  5147. try {
  5148. // TODO: remove this guard which is used for pybind11 implicit conversion
  5149. py::detail::loader_life_support guard{};
  5150. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().format =
  5151. py::cast<decltype(Convolution3D::format)>(py::handle(format));
  5152. } CATCH_ALL(-1)
  5153. }
  5154. if (strategy) {
  5155. try {
  5156. // TODO: remove this guard which is used for pybind11 implicit conversion
  5157. py::detail::loader_life_support guard{};
  5158. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().strategy =
  5159. py::cast<decltype(Convolution3D::strategy)>(py::handle(strategy));
  5160. } CATCH_ALL(-1)
  5161. }
  5162. if (workspace_limit) {
  5163. try {
  5164. // TODO: remove this guard which is used for pybind11 implicit conversion
  5165. py::detail::loader_life_support guard{};
  5166. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().workspace_limit =
  5167. py::cast<decltype(Convolution3D::workspace_limit)>(py::handle(workspace_limit));
  5168. } CATCH_ALL(-1)
  5169. }
  5170. if (scope) {
  5171. try {
  5172. reinterpret_cast<PyOp(OpDef)*>(self)->op
  5173. ->set_scope(py::cast<std::string>(py::handle(scope)));
  5174. } CATCH_ALL(-1)
  5175. }
  5176. return 0;
  5177. }
  5178. PyGetSetDef PyOp(Convolution3D)::py_getsetters[] = {
  5179. {const_cast<char*>("mode"), py_get_generic(Convolution3D, mode), py_set_generic(Convolution3D, mode), const_cast<char*>("mode"), NULL},
  5180. {const_cast<char*>("pad_d"), py_get_generic(Convolution3D, pad_d), py_set_generic(Convolution3D, pad_d), const_cast<char*>("pad_d"), NULL},
  5181. {const_cast<char*>("pad_h"), py_get_generic(Convolution3D, pad_h), py_set_generic(Convolution3D, pad_h), const_cast<char*>("pad_h"), NULL},
  5182. {const_cast<char*>("pad_w"), py_get_generic(Convolution3D, pad_w), py_set_generic(Convolution3D, pad_w), const_cast<char*>("pad_w"), NULL},
  5183. {const_cast<char*>("stride_d"), py_get_generic(Convolution3D, stride_d), py_set_generic(Convolution3D, stride_d), const_cast<char*>("stride_d"), NULL},
  5184. {const_cast<char*>("stride_h"), py_get_generic(Convolution3D, stride_h), py_set_generic(Convolution3D, stride_h), const_cast<char*>("stride_h"), NULL},
  5185. {const_cast<char*>("stride_w"), py_get_generic(Convolution3D, stride_w), py_set_generic(Convolution3D, stride_w), const_cast<char*>("stride_w"), NULL},
  5186. {const_cast<char*>("dilate_d"), py_get_generic(Convolution3D, dilate_d), py_set_generic(Convolution3D, dilate_d), const_cast<char*>("dilate_d"), NULL},
  5187. {const_cast<char*>("dilate_h"), py_get_generic(Convolution3D, dilate_h), py_set_generic(Convolution3D, dilate_h), const_cast<char*>("dilate_h"), NULL},
  5188. {const_cast<char*>("dilate_w"), py_get_generic(Convolution3D, dilate_w), py_set_generic(Convolution3D, dilate_w), const_cast<char*>("dilate_w"), NULL},
  5189. {const_cast<char*>("sparse"), py_get_generic(Convolution3D, sparse), py_set_generic(Convolution3D, sparse), const_cast<char*>("sparse"), NULL},
  5190. {const_cast<char*>("data_type"), py_get_generic(Convolution3D, data_type), py_set_generic(Convolution3D, data_type), const_cast<char*>("data_type"), NULL},
  5191. {const_cast<char*>("format"), py_get_generic(Convolution3D, format), py_set_generic(Convolution3D, format), const_cast<char*>("format"), NULL},
  5192. {const_cast<char*>("strategy"), py_get_generic(Convolution3D, strategy), py_set_generic(Convolution3D, strategy), const_cast<char*>("strategy"), NULL},
  5193. {const_cast<char*>("workspace_limit"), py_get_generic(Convolution3D, workspace_limit), py_set_generic(Convolution3D, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  5194. {NULL} /* Sentinel */
  5195. };
  5196. PyMethodDef PyOp(Convolution3D)::tp_methods[] = {
  5197. {const_cast<char*>("__getstate__"), PyOp(Convolution3D)::getstate, METH_NOARGS, "Convolution3D getstate"},
  5198. {const_cast<char*>("__setstate__"), PyOp(Convolution3D)::setstate, METH_VARARGS, "Convolution3D setstate"},
  5199. {NULL} /* Sentinel */
  5200. };
  5201. PyObject *PyOp(Convolution3D)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  5202. if (PyOp(Convolution3D)::py_init(self, args, kwds) < 0) {
  5203. return NULL;
  5204. }
  5205. Py_RETURN_NONE;
  5206. }
  5207. PyMethodDef PyOp(Convolution3D)::py_init_methoddef = {
  5208. "__init__",
  5209. (PyCFunction)PyOp(Convolution3D)::py_init_proxy,
  5210. METH_VARARGS | METH_KEYWORDS,
  5211. "__init__(self, mode: Union[str, Mode] = ..., pad_d: int = ..., pad_h: int = ..., pad_w: int = ..., stride_d: int = ..., stride_h: int = ..., stride_w: int = ..., dilate_d: int = ..., dilate_h: int = ..., dilate_w: int = ..., sparse: Union[str, Sparse] = ..., data_type: Union[str, DataType] = ..., format: Union[str, Format] = ..., strategy: Union[str, Strategy] = ...) -> None\n"
  5212. };
  5213. void _init_py_Convolution3D(py::module m) {
  5214. using py_op = PyOp(Convolution3D);
  5215. auto& py_type = PyOpType(Convolution3D);
  5216. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  5217. py_type.tp_name = "megengine.core._imperative_rt.ops.Convolution3D";
  5218. py_type.tp_basicsize = sizeof(PyOp(Convolution3D));
  5219. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  5220. py_type.tp_doc = "Convolution3D";
  5221. py_type.tp_base = &PyOpType(OpDef);
  5222. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  5223. py_type.tp_new = py_new_generic<py_op>;
  5224. py_type.tp_init = py_op::py_init;
  5225. py_type.tp_methods = py_op::tp_methods;
  5226. py_type.tp_getset = py_op::py_getsetters;
  5227. py_type.tp_dict = PyDict_New();
  5228. PyObject* descr = PyDescr_NewMethod(&PyOpType(Convolution3D), &PyOp(Convolution3D)::py_init_methoddef);
  5229. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  5230. mgb_assert(PyType_Ready(&py_type) >= 0);
  5231. _init_py_Convolution3D_Mode(py_type);
  5232. _init_py_Convolution3D_Sparse(py_type);
  5233. _init_py_Convolution3D_DataType(py_type);
  5234. _init_py_Convolution3D_Format(py_type);
  5235. _init_py_Convolution3D_Strategy(py_type);
  5236. PyType_Modified(&py_type);
  5237. m.add_object("Convolution3D", reinterpret_cast<PyObject*>(&py_type));
  5238. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Convolution3D::typeinfo(), &py_type).second);
  5239. }
  5240. void _init_py_Convolution3DBackwardData_Mode(PyTypeObject& py_type) {
  5241. auto& e_type = EnumWrapper<Convolution3DBackwardData::Mode>::type;
  5242. Py_INCREF(e_type);
  5243. mgb_assert(PyDict_SetItemString(
  5244. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5245. }
  5246. void _init_py_Convolution3DBackwardData_Sparse(PyTypeObject& py_type) {
  5247. auto& e_type = EnumWrapper<Convolution3DBackwardData::Sparse>::type;
  5248. Py_INCREF(e_type);
  5249. mgb_assert(PyDict_SetItemString(
  5250. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5251. }
  5252. void _init_py_Convolution3DBackwardData_DataType(PyTypeObject& py_type) {
  5253. auto& e_type = EnumWrapper<Convolution3DBackwardData::DataType>::type;
  5254. Py_INCREF(e_type);
  5255. mgb_assert(PyDict_SetItemString(
  5256. py_type.tp_dict, "DataType", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5257. }
  5258. void _init_py_Convolution3DBackwardData_Format(PyTypeObject& py_type) {
  5259. auto& e_type = EnumWrapper<Convolution3DBackwardData::Format>::type;
  5260. Py_INCREF(e_type);
  5261. mgb_assert(PyDict_SetItemString(
  5262. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5263. }
  5264. void _init_py_Convolution3DBackwardData_Strategy(PyTypeObject& py_type) {
  5265. auto& e_type = BitCombinedEnumWrapper<Convolution3DBackwardData::Strategy>::type;
  5266. Py_INCREF(e_type);
  5267. mgb_assert(PyDict_SetItemString(
  5268. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5269. }
  5270. PyOpDefBegin(Convolution3DBackwardData) // {
  5271. static PyGetSetDef py_getsetters[];
  5272. static PyMethodDef tp_methods[];
  5273. static PyObject* getstate(PyObject* self, PyObject*) {
  5274. auto& opdef = reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst();
  5275. static_cast<void>(opdef);
  5276. std::unordered_map<std::string, py::object> state {
  5277. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  5278. {"pad_d", serialization<decltype(opdef.pad_d)>::dump(opdef.pad_d)},
  5279. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  5280. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  5281. {"stride_d", serialization<decltype(opdef.stride_d)>::dump(opdef.stride_d)},
  5282. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  5283. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  5284. {"dilate_d", serialization<decltype(opdef.dilate_d)>::dump(opdef.dilate_d)},
  5285. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  5286. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  5287. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  5288. {"data_type", serialization<decltype(opdef.data_type)>::dump(opdef.data_type)},
  5289. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  5290. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  5291. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)}
  5292. };
  5293. return py::cast(state).release().ptr();
  5294. }
  5295. static PyObject* setstate(PyObject* self, PyObject* args) {
  5296. PyObject* dict = PyTuple_GetItem(args, 0);
  5297. if (!dict) return NULL;
  5298. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  5299. auto& opdef = reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst();
  5300. static_cast<void>(opdef);
  5301. {
  5302. auto&& iter = state.find("mode");
  5303. if (iter != state.end()) {
  5304. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  5305. }
  5306. }
  5307. {
  5308. auto&& iter = state.find("pad_d");
  5309. if (iter != state.end()) {
  5310. opdef.pad_d = serialization<decltype(opdef.pad_d)>::load(iter->second);
  5311. }
  5312. }
  5313. {
  5314. auto&& iter = state.find("pad_h");
  5315. if (iter != state.end()) {
  5316. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  5317. }
  5318. }
  5319. {
  5320. auto&& iter = state.find("pad_w");
  5321. if (iter != state.end()) {
  5322. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  5323. }
  5324. }
  5325. {
  5326. auto&& iter = state.find("stride_d");
  5327. if (iter != state.end()) {
  5328. opdef.stride_d = serialization<decltype(opdef.stride_d)>::load(iter->second);
  5329. }
  5330. }
  5331. {
  5332. auto&& iter = state.find("stride_h");
  5333. if (iter != state.end()) {
  5334. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  5335. }
  5336. }
  5337. {
  5338. auto&& iter = state.find("stride_w");
  5339. if (iter != state.end()) {
  5340. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  5341. }
  5342. }
  5343. {
  5344. auto&& iter = state.find("dilate_d");
  5345. if (iter != state.end()) {
  5346. opdef.dilate_d = serialization<decltype(opdef.dilate_d)>::load(iter->second);
  5347. }
  5348. }
  5349. {
  5350. auto&& iter = state.find("dilate_h");
  5351. if (iter != state.end()) {
  5352. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  5353. }
  5354. }
  5355. {
  5356. auto&& iter = state.find("dilate_w");
  5357. if (iter != state.end()) {
  5358. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  5359. }
  5360. }
  5361. {
  5362. auto&& iter = state.find("sparse");
  5363. if (iter != state.end()) {
  5364. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  5365. }
  5366. }
  5367. {
  5368. auto&& iter = state.find("data_type");
  5369. if (iter != state.end()) {
  5370. opdef.data_type = serialization<decltype(opdef.data_type)>::load(iter->second);
  5371. }
  5372. }
  5373. {
  5374. auto&& iter = state.find("format");
  5375. if (iter != state.end()) {
  5376. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  5377. }
  5378. }
  5379. {
  5380. auto&& iter = state.find("strategy");
  5381. if (iter != state.end()) {
  5382. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  5383. }
  5384. }
  5385. {
  5386. auto&& iter = state.find("workspace_limit");
  5387. if (iter != state.end()) {
  5388. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  5389. }
  5390. }
  5391. Py_RETURN_NONE;
  5392. }
  5393. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  5394. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  5395. static PyMethodDef py_init_methoddef;
  5396. // };
  5397. PyOpDefEnd(Convolution3DBackwardData)
  5398. int PyOp(Convolution3DBackwardData)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  5399. static const char* kwlist[] = {"mode", "pad_d", "pad_h", "pad_w", "stride_d", "stride_h", "stride_w", "dilate_d", "dilate_h", "dilate_w", "sparse", "data_type", "format", "strategy", "workspace_limit", "scope", NULL};
  5400. PyObject *mode = NULL, *pad_d = NULL, *pad_h = NULL, *pad_w = NULL, *stride_d = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_d = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *data_type = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *scope = NULL;
  5401. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_d, &pad_h, &pad_w, &stride_d, &stride_h, &stride_w, &dilate_d, &dilate_h, &dilate_w, &sparse, &data_type, &format, &strategy, &workspace_limit, &scope))
  5402. return -1;
  5403. if (mode) {
  5404. try {
  5405. // TODO: remove this guard which is used for pybind11 implicit conversion
  5406. py::detail::loader_life_support guard{};
  5407. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().mode =
  5408. py::cast<decltype(Convolution3DBackwardData::mode)>(py::handle(mode));
  5409. } CATCH_ALL(-1)
  5410. }
  5411. if (pad_d) {
  5412. try {
  5413. // TODO: remove this guard which is used for pybind11 implicit conversion
  5414. py::detail::loader_life_support guard{};
  5415. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().pad_d =
  5416. py::cast<decltype(Convolution3DBackwardData::pad_d)>(py::handle(pad_d));
  5417. } CATCH_ALL(-1)
  5418. }
  5419. if (pad_h) {
  5420. try {
  5421. // TODO: remove this guard which is used for pybind11 implicit conversion
  5422. py::detail::loader_life_support guard{};
  5423. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().pad_h =
  5424. py::cast<decltype(Convolution3DBackwardData::pad_h)>(py::handle(pad_h));
  5425. } CATCH_ALL(-1)
  5426. }
  5427. if (pad_w) {
  5428. try {
  5429. // TODO: remove this guard which is used for pybind11 implicit conversion
  5430. py::detail::loader_life_support guard{};
  5431. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().pad_w =
  5432. py::cast<decltype(Convolution3DBackwardData::pad_w)>(py::handle(pad_w));
  5433. } CATCH_ALL(-1)
  5434. }
  5435. if (stride_d) {
  5436. try {
  5437. // TODO: remove this guard which is used for pybind11 implicit conversion
  5438. py::detail::loader_life_support guard{};
  5439. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().stride_d =
  5440. py::cast<decltype(Convolution3DBackwardData::stride_d)>(py::handle(stride_d));
  5441. } CATCH_ALL(-1)
  5442. }
  5443. if (stride_h) {
  5444. try {
  5445. // TODO: remove this guard which is used for pybind11 implicit conversion
  5446. py::detail::loader_life_support guard{};
  5447. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().stride_h =
  5448. py::cast<decltype(Convolution3DBackwardData::stride_h)>(py::handle(stride_h));
  5449. } CATCH_ALL(-1)
  5450. }
  5451. if (stride_w) {
  5452. try {
  5453. // TODO: remove this guard which is used for pybind11 implicit conversion
  5454. py::detail::loader_life_support guard{};
  5455. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().stride_w =
  5456. py::cast<decltype(Convolution3DBackwardData::stride_w)>(py::handle(stride_w));
  5457. } CATCH_ALL(-1)
  5458. }
  5459. if (dilate_d) {
  5460. try {
  5461. // TODO: remove this guard which is used for pybind11 implicit conversion
  5462. py::detail::loader_life_support guard{};
  5463. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().dilate_d =
  5464. py::cast<decltype(Convolution3DBackwardData::dilate_d)>(py::handle(dilate_d));
  5465. } CATCH_ALL(-1)
  5466. }
  5467. if (dilate_h) {
  5468. try {
  5469. // TODO: remove this guard which is used for pybind11 implicit conversion
  5470. py::detail::loader_life_support guard{};
  5471. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().dilate_h =
  5472. py::cast<decltype(Convolution3DBackwardData::dilate_h)>(py::handle(dilate_h));
  5473. } CATCH_ALL(-1)
  5474. }
  5475. if (dilate_w) {
  5476. try {
  5477. // TODO: remove this guard which is used for pybind11 implicit conversion
  5478. py::detail::loader_life_support guard{};
  5479. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().dilate_w =
  5480. py::cast<decltype(Convolution3DBackwardData::dilate_w)>(py::handle(dilate_w));
  5481. } CATCH_ALL(-1)
  5482. }
  5483. if (sparse) {
  5484. try {
  5485. // TODO: remove this guard which is used for pybind11 implicit conversion
  5486. py::detail::loader_life_support guard{};
  5487. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().sparse =
  5488. py::cast<decltype(Convolution3DBackwardData::sparse)>(py::handle(sparse));
  5489. } CATCH_ALL(-1)
  5490. }
  5491. if (data_type) {
  5492. try {
  5493. // TODO: remove this guard which is used for pybind11 implicit conversion
  5494. py::detail::loader_life_support guard{};
  5495. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().data_type =
  5496. py::cast<decltype(Convolution3DBackwardData::data_type)>(py::handle(data_type));
  5497. } CATCH_ALL(-1)
  5498. }
  5499. if (format) {
  5500. try {
  5501. // TODO: remove this guard which is used for pybind11 implicit conversion
  5502. py::detail::loader_life_support guard{};
  5503. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().format =
  5504. py::cast<decltype(Convolution3DBackwardData::format)>(py::handle(format));
  5505. } CATCH_ALL(-1)
  5506. }
  5507. if (strategy) {
  5508. try {
  5509. // TODO: remove this guard which is used for pybind11 implicit conversion
  5510. py::detail::loader_life_support guard{};
  5511. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().strategy =
  5512. py::cast<decltype(Convolution3DBackwardData::strategy)>(py::handle(strategy));
  5513. } CATCH_ALL(-1)
  5514. }
  5515. if (workspace_limit) {
  5516. try {
  5517. // TODO: remove this guard which is used for pybind11 implicit conversion
  5518. py::detail::loader_life_support guard{};
  5519. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().workspace_limit =
  5520. py::cast<decltype(Convolution3DBackwardData::workspace_limit)>(py::handle(workspace_limit));
  5521. } CATCH_ALL(-1)
  5522. }
  5523. if (scope) {
  5524. try {
  5525. reinterpret_cast<PyOp(OpDef)*>(self)->op
  5526. ->set_scope(py::cast<std::string>(py::handle(scope)));
  5527. } CATCH_ALL(-1)
  5528. }
  5529. return 0;
  5530. }
  5531. PyGetSetDef PyOp(Convolution3DBackwardData)::py_getsetters[] = {
  5532. {const_cast<char*>("mode"), py_get_generic(Convolution3DBackwardData, mode), py_set_generic(Convolution3DBackwardData, mode), const_cast<char*>("mode"), NULL},
  5533. {const_cast<char*>("pad_d"), py_get_generic(Convolution3DBackwardData, pad_d), py_set_generic(Convolution3DBackwardData, pad_d), const_cast<char*>("pad_d"), NULL},
  5534. {const_cast<char*>("pad_h"), py_get_generic(Convolution3DBackwardData, pad_h), py_set_generic(Convolution3DBackwardData, pad_h), const_cast<char*>("pad_h"), NULL},
  5535. {const_cast<char*>("pad_w"), py_get_generic(Convolution3DBackwardData, pad_w), py_set_generic(Convolution3DBackwardData, pad_w), const_cast<char*>("pad_w"), NULL},
  5536. {const_cast<char*>("stride_d"), py_get_generic(Convolution3DBackwardData, stride_d), py_set_generic(Convolution3DBackwardData, stride_d), const_cast<char*>("stride_d"), NULL},
  5537. {const_cast<char*>("stride_h"), py_get_generic(Convolution3DBackwardData, stride_h), py_set_generic(Convolution3DBackwardData, stride_h), const_cast<char*>("stride_h"), NULL},
  5538. {const_cast<char*>("stride_w"), py_get_generic(Convolution3DBackwardData, stride_w), py_set_generic(Convolution3DBackwardData, stride_w), const_cast<char*>("stride_w"), NULL},
  5539. {const_cast<char*>("dilate_d"), py_get_generic(Convolution3DBackwardData, dilate_d), py_set_generic(Convolution3DBackwardData, dilate_d), const_cast<char*>("dilate_d"), NULL},
  5540. {const_cast<char*>("dilate_h"), py_get_generic(Convolution3DBackwardData, dilate_h), py_set_generic(Convolution3DBackwardData, dilate_h), const_cast<char*>("dilate_h"), NULL},
  5541. {const_cast<char*>("dilate_w"), py_get_generic(Convolution3DBackwardData, dilate_w), py_set_generic(Convolution3DBackwardData, dilate_w), const_cast<char*>("dilate_w"), NULL},
  5542. {const_cast<char*>("sparse"), py_get_generic(Convolution3DBackwardData, sparse), py_set_generic(Convolution3DBackwardData, sparse), const_cast<char*>("sparse"), NULL},
  5543. {const_cast<char*>("data_type"), py_get_generic(Convolution3DBackwardData, data_type), py_set_generic(Convolution3DBackwardData, data_type), const_cast<char*>("data_type"), NULL},
  5544. {const_cast<char*>("format"), py_get_generic(Convolution3DBackwardData, format), py_set_generic(Convolution3DBackwardData, format), const_cast<char*>("format"), NULL},
  5545. {const_cast<char*>("strategy"), py_get_generic(Convolution3DBackwardData, strategy), py_set_generic(Convolution3DBackwardData, strategy), const_cast<char*>("strategy"), NULL},
  5546. {const_cast<char*>("workspace_limit"), py_get_generic(Convolution3DBackwardData, workspace_limit), py_set_generic(Convolution3DBackwardData, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  5547. {NULL} /* Sentinel */
  5548. };
  5549. PyMethodDef PyOp(Convolution3DBackwardData)::tp_methods[] = {
  5550. {const_cast<char*>("__getstate__"), PyOp(Convolution3DBackwardData)::getstate, METH_NOARGS, "Convolution3DBackwardData getstate"},
  5551. {const_cast<char*>("__setstate__"), PyOp(Convolution3DBackwardData)::setstate, METH_VARARGS, "Convolution3DBackwardData setstate"},
  5552. {NULL} /* Sentinel */
  5553. };
  5554. PyObject *PyOp(Convolution3DBackwardData)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  5555. if (PyOp(Convolution3DBackwardData)::py_init(self, args, kwds) < 0) {
  5556. return NULL;
  5557. }
  5558. Py_RETURN_NONE;
  5559. }
  5560. PyMethodDef PyOp(Convolution3DBackwardData)::py_init_methoddef = {
  5561. "__init__",
  5562. (PyCFunction)PyOp(Convolution3DBackwardData)::py_init_proxy,
  5563. METH_VARARGS | METH_KEYWORDS,
  5564. "__init__(self, mode: Union[str, Mode] = ..., pad_d: int = ..., pad_h: int = ..., pad_w: int = ..., stride_d: int = ..., stride_h: int = ..., stride_w: int = ..., dilate_d: int = ..., dilate_h: int = ..., dilate_w: int = ..., sparse: Union[str, Sparse] = ..., data_type: Union[str, DataType] = ..., format: Union[str, Format] = ..., strategy: Union[str, Strategy] = ...) -> None\n"
  5565. };
  5566. void _init_py_Convolution3DBackwardData(py::module m) {
  5567. using py_op = PyOp(Convolution3DBackwardData);
  5568. auto& py_type = PyOpType(Convolution3DBackwardData);
  5569. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  5570. py_type.tp_name = "megengine.core._imperative_rt.ops.Convolution3DBackwardData";
  5571. py_type.tp_basicsize = sizeof(PyOp(Convolution3DBackwardData));
  5572. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  5573. py_type.tp_doc = "Convolution3DBackwardData";
  5574. py_type.tp_base = &PyOpType(OpDef);
  5575. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  5576. py_type.tp_new = py_new_generic<py_op>;
  5577. py_type.tp_init = py_op::py_init;
  5578. py_type.tp_methods = py_op::tp_methods;
  5579. py_type.tp_getset = py_op::py_getsetters;
  5580. py_type.tp_dict = PyDict_New();
  5581. PyObject* descr = PyDescr_NewMethod(&PyOpType(Convolution3DBackwardData), &PyOp(Convolution3DBackwardData)::py_init_methoddef);
  5582. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  5583. mgb_assert(PyType_Ready(&py_type) >= 0);
  5584. _init_py_Convolution3DBackwardData_Mode(py_type);
  5585. _init_py_Convolution3DBackwardData_Sparse(py_type);
  5586. _init_py_Convolution3DBackwardData_DataType(py_type);
  5587. _init_py_Convolution3DBackwardData_Format(py_type);
  5588. _init_py_Convolution3DBackwardData_Strategy(py_type);
  5589. PyType_Modified(&py_type);
  5590. m.add_object("Convolution3DBackwardData", reinterpret_cast<PyObject*>(&py_type));
  5591. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Convolution3DBackwardData::typeinfo(), &py_type).second);
  5592. }
  5593. void _init_py_ConvolutionBackwardData_Mode(PyTypeObject& py_type) {
  5594. auto& e_type = EnumWrapper<ConvolutionBackwardData::Mode>::type;
  5595. Py_INCREF(e_type);
  5596. mgb_assert(PyDict_SetItemString(
  5597. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5598. }
  5599. void _init_py_ConvolutionBackwardData_Sparse(PyTypeObject& py_type) {
  5600. auto& e_type = EnumWrapper<ConvolutionBackwardData::Sparse>::type;
  5601. Py_INCREF(e_type);
  5602. mgb_assert(PyDict_SetItemString(
  5603. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5604. }
  5605. void _init_py_ConvolutionBackwardData_Format(PyTypeObject& py_type) {
  5606. auto& e_type = EnumWrapper<ConvolutionBackwardData::Format>::type;
  5607. Py_INCREF(e_type);
  5608. mgb_assert(PyDict_SetItemString(
  5609. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5610. }
  5611. void _init_py_ConvolutionBackwardData_ComputeMode(PyTypeObject& py_type) {
  5612. auto& e_type = EnumWrapper<ConvolutionBackwardData::ComputeMode>::type;
  5613. Py_INCREF(e_type);
  5614. mgb_assert(PyDict_SetItemString(
  5615. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5616. }
  5617. void _init_py_ConvolutionBackwardData_Strategy(PyTypeObject& py_type) {
  5618. auto& e_type = BitCombinedEnumWrapper<ConvolutionBackwardData::Strategy>::type;
  5619. Py_INCREF(e_type);
  5620. mgb_assert(PyDict_SetItemString(
  5621. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5622. }
  5623. PyOpDefBegin(ConvolutionBackwardData) // {
  5624. static PyGetSetDef py_getsetters[];
  5625. static PyMethodDef tp_methods[];
  5626. static PyObject* getstate(PyObject* self, PyObject*) {
  5627. auto& opdef = reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst();
  5628. static_cast<void>(opdef);
  5629. std::unordered_map<std::string, py::object> state {
  5630. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  5631. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  5632. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  5633. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  5634. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  5635. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  5636. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  5637. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  5638. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  5639. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  5640. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  5641. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)},
  5642. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)}
  5643. };
  5644. return py::cast(state).release().ptr();
  5645. }
  5646. static PyObject* setstate(PyObject* self, PyObject* args) {
  5647. PyObject* dict = PyTuple_GetItem(args, 0);
  5648. if (!dict) return NULL;
  5649. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  5650. auto& opdef = reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst();
  5651. static_cast<void>(opdef);
  5652. {
  5653. auto&& iter = state.find("mode");
  5654. if (iter != state.end()) {
  5655. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  5656. }
  5657. }
  5658. {
  5659. auto&& iter = state.find("pad_h");
  5660. if (iter != state.end()) {
  5661. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  5662. }
  5663. }
  5664. {
  5665. auto&& iter = state.find("pad_w");
  5666. if (iter != state.end()) {
  5667. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  5668. }
  5669. }
  5670. {
  5671. auto&& iter = state.find("stride_h");
  5672. if (iter != state.end()) {
  5673. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  5674. }
  5675. }
  5676. {
  5677. auto&& iter = state.find("stride_w");
  5678. if (iter != state.end()) {
  5679. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  5680. }
  5681. }
  5682. {
  5683. auto&& iter = state.find("dilate_h");
  5684. if (iter != state.end()) {
  5685. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  5686. }
  5687. }
  5688. {
  5689. auto&& iter = state.find("dilate_w");
  5690. if (iter != state.end()) {
  5691. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  5692. }
  5693. }
  5694. {
  5695. auto&& iter = state.find("sparse");
  5696. if (iter != state.end()) {
  5697. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  5698. }
  5699. }
  5700. {
  5701. auto&& iter = state.find("format");
  5702. if (iter != state.end()) {
  5703. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  5704. }
  5705. }
  5706. {
  5707. auto&& iter = state.find("compute_mode");
  5708. if (iter != state.end()) {
  5709. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  5710. }
  5711. }
  5712. {
  5713. auto&& iter = state.find("strategy");
  5714. if (iter != state.end()) {
  5715. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  5716. }
  5717. }
  5718. {
  5719. auto&& iter = state.find("workspace_limit");
  5720. if (iter != state.end()) {
  5721. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  5722. }
  5723. }
  5724. {
  5725. auto&& iter = state.find("dtype");
  5726. if (iter != state.end()) {
  5727. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  5728. }
  5729. }
  5730. Py_RETURN_NONE;
  5731. }
  5732. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  5733. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  5734. static PyMethodDef py_init_methoddef;
  5735. // };
  5736. PyOpDefEnd(ConvolutionBackwardData)
  5737. int PyOp(ConvolutionBackwardData)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  5738. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "strategy", "workspace_limit", "dtype", "scope", NULL};
  5739. PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *strategy = NULL, *workspace_limit = NULL, *dtype = NULL, *scope = NULL;
  5740. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &strategy, &workspace_limit, &dtype, &scope))
  5741. return -1;
  5742. if (mode) {
  5743. try {
  5744. // TODO: remove this guard which is used for pybind11 implicit conversion
  5745. py::detail::loader_life_support guard{};
  5746. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().mode =
  5747. py::cast<decltype(ConvolutionBackwardData::mode)>(py::handle(mode));
  5748. } CATCH_ALL(-1)
  5749. }
  5750. if (pad_h) {
  5751. try {
  5752. // TODO: remove this guard which is used for pybind11 implicit conversion
  5753. py::detail::loader_life_support guard{};
  5754. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().pad_h =
  5755. py::cast<decltype(ConvolutionBackwardData::pad_h)>(py::handle(pad_h));
  5756. } CATCH_ALL(-1)
  5757. }
  5758. if (pad_w) {
  5759. try {
  5760. // TODO: remove this guard which is used for pybind11 implicit conversion
  5761. py::detail::loader_life_support guard{};
  5762. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().pad_w =
  5763. py::cast<decltype(ConvolutionBackwardData::pad_w)>(py::handle(pad_w));
  5764. } CATCH_ALL(-1)
  5765. }
  5766. if (stride_h) {
  5767. try {
  5768. // TODO: remove this guard which is used for pybind11 implicit conversion
  5769. py::detail::loader_life_support guard{};
  5770. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().stride_h =
  5771. py::cast<decltype(ConvolutionBackwardData::stride_h)>(py::handle(stride_h));
  5772. } CATCH_ALL(-1)
  5773. }
  5774. if (stride_w) {
  5775. try {
  5776. // TODO: remove this guard which is used for pybind11 implicit conversion
  5777. py::detail::loader_life_support guard{};
  5778. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().stride_w =
  5779. py::cast<decltype(ConvolutionBackwardData::stride_w)>(py::handle(stride_w));
  5780. } CATCH_ALL(-1)
  5781. }
  5782. if (dilate_h) {
  5783. try {
  5784. // TODO: remove this guard which is used for pybind11 implicit conversion
  5785. py::detail::loader_life_support guard{};
  5786. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().dilate_h =
  5787. py::cast<decltype(ConvolutionBackwardData::dilate_h)>(py::handle(dilate_h));
  5788. } CATCH_ALL(-1)
  5789. }
  5790. if (dilate_w) {
  5791. try {
  5792. // TODO: remove this guard which is used for pybind11 implicit conversion
  5793. py::detail::loader_life_support guard{};
  5794. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().dilate_w =
  5795. py::cast<decltype(ConvolutionBackwardData::dilate_w)>(py::handle(dilate_w));
  5796. } CATCH_ALL(-1)
  5797. }
  5798. if (sparse) {
  5799. try {
  5800. // TODO: remove this guard which is used for pybind11 implicit conversion
  5801. py::detail::loader_life_support guard{};
  5802. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().sparse =
  5803. py::cast<decltype(ConvolutionBackwardData::sparse)>(py::handle(sparse));
  5804. } CATCH_ALL(-1)
  5805. }
  5806. if (format) {
  5807. try {
  5808. // TODO: remove this guard which is used for pybind11 implicit conversion
  5809. py::detail::loader_life_support guard{};
  5810. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().format =
  5811. py::cast<decltype(ConvolutionBackwardData::format)>(py::handle(format));
  5812. } CATCH_ALL(-1)
  5813. }
  5814. if (compute_mode) {
  5815. try {
  5816. // TODO: remove this guard which is used for pybind11 implicit conversion
  5817. py::detail::loader_life_support guard{};
  5818. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().compute_mode =
  5819. py::cast<decltype(ConvolutionBackwardData::compute_mode)>(py::handle(compute_mode));
  5820. } CATCH_ALL(-1)
  5821. }
  5822. if (strategy) {
  5823. try {
  5824. // TODO: remove this guard which is used for pybind11 implicit conversion
  5825. py::detail::loader_life_support guard{};
  5826. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().strategy =
  5827. py::cast<decltype(ConvolutionBackwardData::strategy)>(py::handle(strategy));
  5828. } CATCH_ALL(-1)
  5829. }
  5830. if (workspace_limit) {
  5831. try {
  5832. // TODO: remove this guard which is used for pybind11 implicit conversion
  5833. py::detail::loader_life_support guard{};
  5834. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().workspace_limit =
  5835. py::cast<decltype(ConvolutionBackwardData::workspace_limit)>(py::handle(workspace_limit));
  5836. } CATCH_ALL(-1)
  5837. }
  5838. if (dtype) {
  5839. try {
  5840. // TODO: remove this guard which is used for pybind11 implicit conversion
  5841. py::detail::loader_life_support guard{};
  5842. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().dtype =
  5843. py::cast<decltype(ConvolutionBackwardData::dtype)>(py::handle(dtype));
  5844. } CATCH_ALL(-1)
  5845. }
  5846. if (scope) {
  5847. try {
  5848. reinterpret_cast<PyOp(OpDef)*>(self)->op
  5849. ->set_scope(py::cast<std::string>(py::handle(scope)));
  5850. } CATCH_ALL(-1)
  5851. }
  5852. return 0;
  5853. }
  5854. PyGetSetDef PyOp(ConvolutionBackwardData)::py_getsetters[] = {
  5855. {const_cast<char*>("mode"), py_get_generic(ConvolutionBackwardData, mode), py_set_generic(ConvolutionBackwardData, mode), const_cast<char*>("mode"), NULL},
  5856. {const_cast<char*>("pad_h"), py_get_generic(ConvolutionBackwardData, pad_h), py_set_generic(ConvolutionBackwardData, pad_h), const_cast<char*>("pad_h"), NULL},
  5857. {const_cast<char*>("pad_w"), py_get_generic(ConvolutionBackwardData, pad_w), py_set_generic(ConvolutionBackwardData, pad_w), const_cast<char*>("pad_w"), NULL},
  5858. {const_cast<char*>("stride_h"), py_get_generic(ConvolutionBackwardData, stride_h), py_set_generic(ConvolutionBackwardData, stride_h), const_cast<char*>("stride_h"), NULL},
  5859. {const_cast<char*>("stride_w"), py_get_generic(ConvolutionBackwardData, stride_w), py_set_generic(ConvolutionBackwardData, stride_w), const_cast<char*>("stride_w"), NULL},
  5860. {const_cast<char*>("dilate_h"), py_get_generic(ConvolutionBackwardData, dilate_h), py_set_generic(ConvolutionBackwardData, dilate_h), const_cast<char*>("dilate_h"), NULL},
  5861. {const_cast<char*>("dilate_w"), py_get_generic(ConvolutionBackwardData, dilate_w), py_set_generic(ConvolutionBackwardData, dilate_w), const_cast<char*>("dilate_w"), NULL},
  5862. {const_cast<char*>("sparse"), py_get_generic(ConvolutionBackwardData, sparse), py_set_generic(ConvolutionBackwardData, sparse), const_cast<char*>("sparse"), NULL},
  5863. {const_cast<char*>("format"), py_get_generic(ConvolutionBackwardData, format), py_set_generic(ConvolutionBackwardData, format), const_cast<char*>("format"), NULL},
  5864. {const_cast<char*>("compute_mode"), py_get_generic(ConvolutionBackwardData, compute_mode), py_set_generic(ConvolutionBackwardData, compute_mode), const_cast<char*>("compute_mode"), NULL},
  5865. {const_cast<char*>("strategy"), py_get_generic(ConvolutionBackwardData, strategy), py_set_generic(ConvolutionBackwardData, strategy), const_cast<char*>("strategy"), NULL},
  5866. {const_cast<char*>("workspace_limit"), py_get_generic(ConvolutionBackwardData, workspace_limit), py_set_generic(ConvolutionBackwardData, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  5867. {const_cast<char*>("dtype"), py_get_generic(ConvolutionBackwardData, dtype), py_set_generic(ConvolutionBackwardData, dtype), const_cast<char*>("dtype"), NULL},
  5868. {NULL} /* Sentinel */
  5869. };
  5870. PyMethodDef PyOp(ConvolutionBackwardData)::tp_methods[] = {
  5871. {const_cast<char*>("__getstate__"), PyOp(ConvolutionBackwardData)::getstate, METH_NOARGS, "ConvolutionBackwardData getstate"},
  5872. {const_cast<char*>("__setstate__"), PyOp(ConvolutionBackwardData)::setstate, METH_VARARGS, "ConvolutionBackwardData setstate"},
  5873. {NULL} /* Sentinel */
  5874. };
  5875. PyObject *PyOp(ConvolutionBackwardData)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  5876. if (PyOp(ConvolutionBackwardData)::py_init(self, args, kwds) < 0) {
  5877. return NULL;
  5878. }
  5879. Py_RETURN_NONE;
  5880. }
  5881. PyMethodDef PyOp(ConvolutionBackwardData)::py_init_methoddef = {
  5882. "__init__",
  5883. (PyCFunction)PyOp(ConvolutionBackwardData)::py_init_proxy,
  5884. METH_VARARGS | METH_KEYWORDS,
  5885. "__init__(self, mode: Union[str, Mode] = ..., pad_h: int = ..., pad_w: int = ..., stride_h: int = ..., stride_w: int = ..., dilate_h: int = ..., dilate_w: int = ..., sparse: Union[str, Sparse] = ..., format: Union[str, Format] = ..., compute_mode: Union[str, ComputeMode] = ..., strategy: Union[str, Strategy] = ..., dtype: str = ...) -> None\n"
  5886. };
  5887. void _init_py_ConvolutionBackwardData(py::module m) {
  5888. using py_op = PyOp(ConvolutionBackwardData);
  5889. auto& py_type = PyOpType(ConvolutionBackwardData);
  5890. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  5891. py_type.tp_name = "megengine.core._imperative_rt.ops.ConvolutionBackwardData";
  5892. py_type.tp_basicsize = sizeof(PyOp(ConvolutionBackwardData));
  5893. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  5894. py_type.tp_doc = "ConvolutionBackwardData";
  5895. py_type.tp_base = &PyOpType(OpDef);
  5896. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  5897. py_type.tp_new = py_new_generic<py_op>;
  5898. py_type.tp_init = py_op::py_init;
  5899. py_type.tp_methods = py_op::tp_methods;
  5900. py_type.tp_getset = py_op::py_getsetters;
  5901. py_type.tp_dict = PyDict_New();
  5902. PyObject* descr = PyDescr_NewMethod(&PyOpType(ConvolutionBackwardData), &PyOp(ConvolutionBackwardData)::py_init_methoddef);
  5903. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  5904. mgb_assert(PyType_Ready(&py_type) >= 0);
  5905. _init_py_ConvolutionBackwardData_Mode(py_type);
  5906. _init_py_ConvolutionBackwardData_Sparse(py_type);
  5907. _init_py_ConvolutionBackwardData_Format(py_type);
  5908. _init_py_ConvolutionBackwardData_ComputeMode(py_type);
  5909. _init_py_ConvolutionBackwardData_Strategy(py_type);
  5910. PyType_Modified(&py_type);
  5911. m.add_object("ConvolutionBackwardData", reinterpret_cast<PyObject*>(&py_type));
  5912. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ConvolutionBackwardData::typeinfo(), &py_type).second);
  5913. }
  5914. PyOpDefBegin(Copy) // {
  5915. static PyGetSetDef py_getsetters[];
  5916. static PyMethodDef tp_methods[];
  5917. static PyObject* getstate(PyObject* self, PyObject*) {
  5918. auto& opdef = reinterpret_cast<PyOp(Copy)*>(self)->inst();
  5919. static_cast<void>(opdef);
  5920. std::unordered_map<std::string, py::object> state {
  5921. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)}
  5922. };
  5923. return py::cast(state).release().ptr();
  5924. }
  5925. static PyObject* setstate(PyObject* self, PyObject* args) {
  5926. PyObject* dict = PyTuple_GetItem(args, 0);
  5927. if (!dict) return NULL;
  5928. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  5929. auto& opdef = reinterpret_cast<PyOp(Copy)*>(self)->inst();
  5930. static_cast<void>(opdef);
  5931. {
  5932. auto&& iter = state.find("comp_node");
  5933. if (iter != state.end()) {
  5934. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  5935. }
  5936. }
  5937. Py_RETURN_NONE;
  5938. }
  5939. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  5940. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  5941. static PyMethodDef py_init_methoddef;
  5942. // };
  5943. PyOpDefEnd(Copy)
  5944. int PyOp(Copy)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  5945. static const char* kwlist[] = {"comp_node", "scope", NULL};
  5946. PyObject *comp_node = NULL, *scope = NULL;
  5947. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &comp_node, &scope))
  5948. return -1;
  5949. if (comp_node) {
  5950. try {
  5951. // TODO: remove this guard which is used for pybind11 implicit conversion
  5952. py::detail::loader_life_support guard{};
  5953. reinterpret_cast<PyOp(Copy)*>(self)->inst().comp_node =
  5954. py::cast<decltype(Copy::comp_node)>(py::handle(comp_node));
  5955. } CATCH_ALL(-1)
  5956. }
  5957. if (scope) {
  5958. try {
  5959. reinterpret_cast<PyOp(OpDef)*>(self)->op
  5960. ->set_scope(py::cast<std::string>(py::handle(scope)));
  5961. } CATCH_ALL(-1)
  5962. }
  5963. return 0;
  5964. }
  5965. PyGetSetDef PyOp(Copy)::py_getsetters[] = {
  5966. {const_cast<char*>("comp_node"), py_get_generic(Copy, comp_node), py_set_generic(Copy, comp_node), const_cast<char*>("comp_node"), NULL},
  5967. {NULL} /* Sentinel */
  5968. };
  5969. PyMethodDef PyOp(Copy)::tp_methods[] = {
  5970. {const_cast<char*>("__getstate__"), PyOp(Copy)::getstate, METH_NOARGS, "Copy getstate"},
  5971. {const_cast<char*>("__setstate__"), PyOp(Copy)::setstate, METH_VARARGS, "Copy setstate"},
  5972. {NULL} /* Sentinel */
  5973. };
  5974. PyObject *PyOp(Copy)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  5975. if (PyOp(Copy)::py_init(self, args, kwds) < 0) {
  5976. return NULL;
  5977. }
  5978. Py_RETURN_NONE;
  5979. }
  5980. PyMethodDef PyOp(Copy)::py_init_methoddef = {
  5981. "__init__",
  5982. (PyCFunction)PyOp(Copy)::py_init_proxy,
  5983. METH_VARARGS | METH_KEYWORDS,
  5984. "__init__(self, comp_node: str = ...) -> None\n"
  5985. };
  5986. void _init_py_Copy(py::module m) {
  5987. using py_op = PyOp(Copy);
  5988. auto& py_type = PyOpType(Copy);
  5989. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  5990. py_type.tp_name = "megengine.core._imperative_rt.ops.Copy";
  5991. py_type.tp_basicsize = sizeof(PyOp(Copy));
  5992. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  5993. py_type.tp_doc = "Copy";
  5994. py_type.tp_base = &PyOpType(OpDef);
  5995. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  5996. py_type.tp_new = py_new_generic<py_op>;
  5997. py_type.tp_init = py_op::py_init;
  5998. py_type.tp_methods = py_op::tp_methods;
  5999. py_type.tp_getset = py_op::py_getsetters;
  6000. py_type.tp_dict = PyDict_New();
  6001. PyObject* descr = PyDescr_NewMethod(&PyOpType(Copy), &PyOp(Copy)::py_init_methoddef);
  6002. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  6003. mgb_assert(PyType_Ready(&py_type) >= 0);
  6004. PyType_Modified(&py_type);
  6005. m.add_object("Copy", reinterpret_cast<PyObject*>(&py_type));
  6006. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Copy::typeinfo(), &py_type).second);
  6007. }
  6008. template<> struct EnumTrait<Correlation::Format> {
  6009. static constexpr const char *name = "Correlation.Format";
  6010. static constexpr std::underlying_type_t<Correlation::Format> max = 20 - 1;
  6011. };
  6012. template<> PyTypeObject* EnumWrapper<Correlation::Format>::type = nullptr;
  6013. template<> const char*
  6014. EnumWrapper<Correlation::Format>::members[] = {"NCHW", "NHWC", "NHWCD4", "NCHW4", "NCHW8", "NCHW32", "NCHW88", "NCHW44", "NCHW44_DOT", "NCHW_WINOGRAD", "NCHW88_WINOGRAD", "NCHW44_WINOGRAD", "NCHW4_NCHW32", "NCHW32_NCHW4", "NCHW4_NCHW", "NHWC_NCHW", "NHWC_NCHW4_IC_SMALL", "NCHW_NCHW4_IC_SMALL", "CHWN4", "NCHW4_NHWC"};
  6015. template<> std::unordered_map<std::string, Correlation::Format>
  6016. EnumWrapper<Correlation::Format>::mem2value = {{normalize_enum("NCHW"), Correlation::Format::NCHW}, {normalize_enum("NHWC"), Correlation::Format::NHWC}, {normalize_enum("NHWCD4"), Correlation::Format::NHWCD4}, {normalize_enum("NCHW4"), Correlation::Format::NCHW4}, {normalize_enum("NCHW8"), Correlation::Format::NCHW8}, {normalize_enum("NCHW32"), Correlation::Format::NCHW32}, {normalize_enum("NCHW88"), Correlation::Format::NCHW88}, {normalize_enum("NCHW44"), Correlation::Format::NCHW44}, {normalize_enum("NCHW44_DOT"), Correlation::Format::NCHW44_DOT}, {normalize_enum("NCHW_WINOGRAD"), Correlation::Format::NCHW_WINOGRAD}, {normalize_enum("NCHW88_WINOGRAD"), Correlation::Format::NCHW88_WINOGRAD}, {normalize_enum("NCHW44_WINOGRAD"), Correlation::Format::NCHW44_WINOGRAD}, {normalize_enum("NCHW4_NCHW32"), Correlation::Format::NCHW4_NCHW32}, {normalize_enum("NCHW32_NCHW4"), Correlation::Format::NCHW32_NCHW4}, {normalize_enum("NCHW4_NCHW"), Correlation::Format::NCHW4_NCHW}, {normalize_enum("NHWC_NCHW"), Correlation::Format::NHWC_NCHW}, {normalize_enum("NHWC_NCHW4_IC_SMALL"), Correlation::Format::NHWC_NCHW4_IC_SMALL}, {normalize_enum("NCHW_NCHW4_IC_SMALL"), Correlation::Format::NCHW_NCHW4_IC_SMALL}, {normalize_enum("CHWN4"), Correlation::Format::CHWN4}, {normalize_enum("NCHW4_NHWC"), Correlation::Format::NCHW4_NHWC}};
  6017. template<> PyObject* EnumWrapper<Correlation::Format>::pyobj_insts[20] = {nullptr};
  6018. void _init_py_Correlation_Format(PyTypeObject& py_type) {
  6019. auto& e_type = EnumWrapper<Correlation::Format>::type;
  6020. static PyMethodDef tp_methods[] = {
  6021. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Correlation::Format>::py_dump, METH_NOARGS, NULL},
  6022. {NULL} /* Sentinel */
  6023. };
  6024. static PyType_Slot slots[] = {
  6025. {Py_tp_repr, (void*)EnumWrapper<Correlation::Format>::py_repr},
  6026. {Py_tp_richcompare, (void*)EnumWrapper<Correlation::Format>::tp_richcompare},
  6027. {Py_tp_methods, tp_methods},
  6028. {0, NULL}
  6029. };
  6030. static PyType_Spec spec = {
  6031. // name
  6032. "megengine.core._imperative_rt.ops.Correlation.Format",
  6033. // basicsize
  6034. sizeof(EnumWrapper<Correlation::Format>),
  6035. // itemsize
  6036. 0,
  6037. // flags
  6038. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  6039. // slots
  6040. slots
  6041. };
  6042. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  6043. mgb_assert(
  6044. e_type->tp_setattro(
  6045. reinterpret_cast<PyObject*>(e_type),
  6046. py::cast("__name__").release().ptr(),
  6047. py::cast("Format").release().ptr()) >= 0);
  6048. mgb_assert(
  6049. e_type->tp_setattro(
  6050. reinterpret_cast<PyObject*>(e_type),
  6051. py::cast("__module__").release().ptr(),
  6052. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  6053. mgb_assert(
  6054. e_type->tp_setattro(
  6055. reinterpret_cast<PyObject*>(e_type),
  6056. py::cast("__qualname__").release().ptr(),
  6057. py::cast("Correlation.Format").release().ptr()) >= 0);
  6058. {
  6059. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6060. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW;
  6061. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW", inst) >= 0);
  6062. EnumWrapper<Correlation::Format>::pyobj_insts[0] = inst;
  6063. }{
  6064. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6065. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NHWC;
  6066. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC", inst) >= 0);
  6067. EnumWrapper<Correlation::Format>::pyobj_insts[1] = inst;
  6068. }{
  6069. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6070. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NHWCD4;
  6071. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWCD4", inst) >= 0);
  6072. EnumWrapper<Correlation::Format>::pyobj_insts[2] = inst;
  6073. }{
  6074. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6075. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW4;
  6076. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4", inst) >= 0);
  6077. EnumWrapper<Correlation::Format>::pyobj_insts[3] = inst;
  6078. }{
  6079. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6080. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW8;
  6081. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW8", inst) >= 0);
  6082. EnumWrapper<Correlation::Format>::pyobj_insts[4] = inst;
  6083. }{
  6084. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6085. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW32;
  6086. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW32", inst) >= 0);
  6087. EnumWrapper<Correlation::Format>::pyobj_insts[5] = inst;
  6088. }{
  6089. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6090. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW88;
  6091. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW88", inst) >= 0);
  6092. EnumWrapper<Correlation::Format>::pyobj_insts[6] = inst;
  6093. }{
  6094. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6095. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW44;
  6096. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW44", inst) >= 0);
  6097. EnumWrapper<Correlation::Format>::pyobj_insts[7] = inst;
  6098. }{
  6099. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6100. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW44_DOT;
  6101. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW44_DOT", inst) >= 0);
  6102. EnumWrapper<Correlation::Format>::pyobj_insts[8] = inst;
  6103. }{
  6104. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6105. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW_WINOGRAD;
  6106. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW_WINOGRAD", inst) >= 0);
  6107. EnumWrapper<Correlation::Format>::pyobj_insts[9] = inst;
  6108. }{
  6109. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6110. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW88_WINOGRAD;
  6111. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW88_WINOGRAD", inst) >= 0);
  6112. EnumWrapper<Correlation::Format>::pyobj_insts[10] = inst;
  6113. }{
  6114. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6115. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW44_WINOGRAD;
  6116. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW44_WINOGRAD", inst) >= 0);
  6117. EnumWrapper<Correlation::Format>::pyobj_insts[11] = inst;
  6118. }{
  6119. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6120. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW4_NCHW32;
  6121. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NCHW32", inst) >= 0);
  6122. EnumWrapper<Correlation::Format>::pyobj_insts[12] = inst;
  6123. }{
  6124. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6125. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW32_NCHW4;
  6126. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW32_NCHW4", inst) >= 0);
  6127. EnumWrapper<Correlation::Format>::pyobj_insts[13] = inst;
  6128. }{
  6129. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6130. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW4_NCHW;
  6131. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NCHW", inst) >= 0);
  6132. EnumWrapper<Correlation::Format>::pyobj_insts[14] = inst;
  6133. }{
  6134. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6135. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NHWC_NCHW;
  6136. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC_NCHW", inst) >= 0);
  6137. EnumWrapper<Correlation::Format>::pyobj_insts[15] = inst;
  6138. }{
  6139. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6140. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NHWC_NCHW4_IC_SMALL;
  6141. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC_NCHW4_IC_SMALL", inst) >= 0);
  6142. EnumWrapper<Correlation::Format>::pyobj_insts[16] = inst;
  6143. }{
  6144. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6145. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW_NCHW4_IC_SMALL;
  6146. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW_NCHW4_IC_SMALL", inst) >= 0);
  6147. EnumWrapper<Correlation::Format>::pyobj_insts[17] = inst;
  6148. }{
  6149. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6150. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::CHWN4;
  6151. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CHWN4", inst) >= 0);
  6152. EnumWrapper<Correlation::Format>::pyobj_insts[18] = inst;
  6153. }{
  6154. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6155. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW4_NHWC;
  6156. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NHWC", inst) >= 0);
  6157. EnumWrapper<Correlation::Format>::pyobj_insts[19] = inst;
  6158. }
  6159. Py_INCREF(e_type);
  6160. mgb_assert(PyDict_SetItemString(
  6161. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6162. }
  6163. PyOpDefBegin(Correlation) // {
  6164. static PyGetSetDef py_getsetters[];
  6165. static PyMethodDef tp_methods[];
  6166. static PyObject* getstate(PyObject* self, PyObject*) {
  6167. auto& opdef = reinterpret_cast<PyOp(Correlation)*>(self)->inst();
  6168. static_cast<void>(opdef);
  6169. std::unordered_map<std::string, py::object> state {
  6170. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  6171. {"kernel_size", serialization<decltype(opdef.kernel_size)>::dump(opdef.kernel_size)},
  6172. {"max_displacement", serialization<decltype(opdef.max_displacement)>::dump(opdef.max_displacement)},
  6173. {"stride1", serialization<decltype(opdef.stride1)>::dump(opdef.stride1)},
  6174. {"stride2", serialization<decltype(opdef.stride2)>::dump(opdef.stride2)},
  6175. {"pad_size", serialization<decltype(opdef.pad_size)>::dump(opdef.pad_size)},
  6176. {"is_multiply", serialization<decltype(opdef.is_multiply)>::dump(opdef.is_multiply)}
  6177. };
  6178. return py::cast(state).release().ptr();
  6179. }
  6180. static PyObject* setstate(PyObject* self, PyObject* args) {
  6181. PyObject* dict = PyTuple_GetItem(args, 0);
  6182. if (!dict) return NULL;
  6183. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6184. auto& opdef = reinterpret_cast<PyOp(Correlation)*>(self)->inst();
  6185. static_cast<void>(opdef);
  6186. {
  6187. auto&& iter = state.find("format");
  6188. if (iter != state.end()) {
  6189. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  6190. }
  6191. }
  6192. {
  6193. auto&& iter = state.find("kernel_size");
  6194. if (iter != state.end()) {
  6195. opdef.kernel_size = serialization<decltype(opdef.kernel_size)>::load(iter->second);
  6196. }
  6197. }
  6198. {
  6199. auto&& iter = state.find("max_displacement");
  6200. if (iter != state.end()) {
  6201. opdef.max_displacement = serialization<decltype(opdef.max_displacement)>::load(iter->second);
  6202. }
  6203. }
  6204. {
  6205. auto&& iter = state.find("stride1");
  6206. if (iter != state.end()) {
  6207. opdef.stride1 = serialization<decltype(opdef.stride1)>::load(iter->second);
  6208. }
  6209. }
  6210. {
  6211. auto&& iter = state.find("stride2");
  6212. if (iter != state.end()) {
  6213. opdef.stride2 = serialization<decltype(opdef.stride2)>::load(iter->second);
  6214. }
  6215. }
  6216. {
  6217. auto&& iter = state.find("pad_size");
  6218. if (iter != state.end()) {
  6219. opdef.pad_size = serialization<decltype(opdef.pad_size)>::load(iter->second);
  6220. }
  6221. }
  6222. {
  6223. auto&& iter = state.find("is_multiply");
  6224. if (iter != state.end()) {
  6225. opdef.is_multiply = serialization<decltype(opdef.is_multiply)>::load(iter->second);
  6226. }
  6227. }
  6228. Py_RETURN_NONE;
  6229. }
  6230. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6231. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  6232. static PyMethodDef py_init_methoddef;
  6233. // };
  6234. PyOpDefEnd(Correlation)
  6235. int PyOp(Correlation)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6236. static const char* kwlist[] = {"format", "kernel_size", "max_displacement", "stride1", "stride2", "pad_size", "is_multiply", "scope", NULL};
  6237. PyObject *format = NULL, *kernel_size = NULL, *max_displacement = NULL, *stride1 = NULL, *stride2 = NULL, *pad_size = NULL, *is_multiply = NULL, *scope = NULL;
  6238. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOO", const_cast<char**>(kwlist), &format, &kernel_size, &max_displacement, &stride1, &stride2, &pad_size, &is_multiply, &scope))
  6239. return -1;
  6240. if (format) {
  6241. try {
  6242. // TODO: remove this guard which is used for pybind11 implicit conversion
  6243. py::detail::loader_life_support guard{};
  6244. reinterpret_cast<PyOp(Correlation)*>(self)->inst().format =
  6245. py::cast<decltype(Correlation::format)>(py::handle(format));
  6246. } CATCH_ALL(-1)
  6247. }
  6248. if (kernel_size) {
  6249. try {
  6250. // TODO: remove this guard which is used for pybind11 implicit conversion
  6251. py::detail::loader_life_support guard{};
  6252. reinterpret_cast<PyOp(Correlation)*>(self)->inst().kernel_size =
  6253. py::cast<decltype(Correlation::kernel_size)>(py::handle(kernel_size));
  6254. } CATCH_ALL(-1)
  6255. }
  6256. if (max_displacement) {
  6257. try {
  6258. // TODO: remove this guard which is used for pybind11 implicit conversion
  6259. py::detail::loader_life_support guard{};
  6260. reinterpret_cast<PyOp(Correlation)*>(self)->inst().max_displacement =
  6261. py::cast<decltype(Correlation::max_displacement)>(py::handle(max_displacement));
  6262. } CATCH_ALL(-1)
  6263. }
  6264. if (stride1) {
  6265. try {
  6266. // TODO: remove this guard which is used for pybind11 implicit conversion
  6267. py::detail::loader_life_support guard{};
  6268. reinterpret_cast<PyOp(Correlation)*>(self)->inst().stride1 =
  6269. py::cast<decltype(Correlation::stride1)>(py::handle(stride1));
  6270. } CATCH_ALL(-1)
  6271. }
  6272. if (stride2) {
  6273. try {
  6274. // TODO: remove this guard which is used for pybind11 implicit conversion
  6275. py::detail::loader_life_support guard{};
  6276. reinterpret_cast<PyOp(Correlation)*>(self)->inst().stride2 =
  6277. py::cast<decltype(Correlation::stride2)>(py::handle(stride2));
  6278. } CATCH_ALL(-1)
  6279. }
  6280. if (pad_size) {
  6281. try {
  6282. // TODO: remove this guard which is used for pybind11 implicit conversion
  6283. py::detail::loader_life_support guard{};
  6284. reinterpret_cast<PyOp(Correlation)*>(self)->inst().pad_size =
  6285. py::cast<decltype(Correlation::pad_size)>(py::handle(pad_size));
  6286. } CATCH_ALL(-1)
  6287. }
  6288. if (is_multiply) {
  6289. try {
  6290. // TODO: remove this guard which is used for pybind11 implicit conversion
  6291. py::detail::loader_life_support guard{};
  6292. reinterpret_cast<PyOp(Correlation)*>(self)->inst().is_multiply =
  6293. py::cast<decltype(Correlation::is_multiply)>(py::handle(is_multiply));
  6294. } CATCH_ALL(-1)
  6295. }
  6296. if (scope) {
  6297. try {
  6298. reinterpret_cast<PyOp(OpDef)*>(self)->op
  6299. ->set_scope(py::cast<std::string>(py::handle(scope)));
  6300. } CATCH_ALL(-1)
  6301. }
  6302. return 0;
  6303. }
  6304. PyGetSetDef PyOp(Correlation)::py_getsetters[] = {
  6305. {const_cast<char*>("format"), py_get_generic(Correlation, format), py_set_generic(Correlation, format), const_cast<char*>("format"), NULL},
  6306. {const_cast<char*>("kernel_size"), py_get_generic(Correlation, kernel_size), py_set_generic(Correlation, kernel_size), const_cast<char*>("kernel_size"), NULL},
  6307. {const_cast<char*>("max_displacement"), py_get_generic(Correlation, max_displacement), py_set_generic(Correlation, max_displacement), const_cast<char*>("max_displacement"), NULL},
  6308. {const_cast<char*>("stride1"), py_get_generic(Correlation, stride1), py_set_generic(Correlation, stride1), const_cast<char*>("stride1"), NULL},
  6309. {const_cast<char*>("stride2"), py_get_generic(Correlation, stride2), py_set_generic(Correlation, stride2), const_cast<char*>("stride2"), NULL},
  6310. {const_cast<char*>("pad_size"), py_get_generic(Correlation, pad_size), py_set_generic(Correlation, pad_size), const_cast<char*>("pad_size"), NULL},
  6311. {const_cast<char*>("is_multiply"), py_get_generic(Correlation, is_multiply), py_set_generic(Correlation, is_multiply), const_cast<char*>("is_multiply"), NULL},
  6312. {NULL} /* Sentinel */
  6313. };
  6314. PyMethodDef PyOp(Correlation)::tp_methods[] = {
  6315. {const_cast<char*>("__getstate__"), PyOp(Correlation)::getstate, METH_NOARGS, "Correlation getstate"},
  6316. {const_cast<char*>("__setstate__"), PyOp(Correlation)::setstate, METH_VARARGS, "Correlation setstate"},
  6317. {NULL} /* Sentinel */
  6318. };
  6319. PyObject *PyOp(Correlation)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  6320. if (PyOp(Correlation)::py_init(self, args, kwds) < 0) {
  6321. return NULL;
  6322. }
  6323. Py_RETURN_NONE;
  6324. }
  6325. PyMethodDef PyOp(Correlation)::py_init_methoddef = {
  6326. "__init__",
  6327. (PyCFunction)PyOp(Correlation)::py_init_proxy,
  6328. METH_VARARGS | METH_KEYWORDS,
  6329. "__init__(self, format: Union[str, Format] = ..., kernel_size: int = ..., max_displacement: int = ..., stride1: int = ..., stride2: int = ..., pad_size: int = ..., is_multiply: bool = ...) -> None\n"
  6330. };
  6331. void _init_py_Correlation(py::module m) {
  6332. using py_op = PyOp(Correlation);
  6333. auto& py_type = PyOpType(Correlation);
  6334. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  6335. py_type.tp_name = "megengine.core._imperative_rt.ops.Correlation";
  6336. py_type.tp_basicsize = sizeof(PyOp(Correlation));
  6337. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  6338. py_type.tp_doc = "Correlation";
  6339. py_type.tp_base = &PyOpType(OpDef);
  6340. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  6341. py_type.tp_new = py_new_generic<py_op>;
  6342. py_type.tp_init = py_op::py_init;
  6343. py_type.tp_methods = py_op::tp_methods;
  6344. py_type.tp_getset = py_op::py_getsetters;
  6345. py_type.tp_dict = PyDict_New();
  6346. PyObject* descr = PyDescr_NewMethod(&PyOpType(Correlation), &PyOp(Correlation)::py_init_methoddef);
  6347. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  6348. mgb_assert(PyType_Ready(&py_type) >= 0);
  6349. _init_py_Correlation_Format(py_type);
  6350. PyType_Modified(&py_type);
  6351. m.add_object("Correlation", reinterpret_cast<PyObject*>(&py_type));
  6352. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Correlation::typeinfo(), &py_type).second);
  6353. }
  6354. PyOpDefBegin(Cumsum) // {
  6355. static PyGetSetDef py_getsetters[];
  6356. static PyMethodDef tp_methods[];
  6357. static PyObject* getstate(PyObject* self, PyObject*) {
  6358. auto& opdef = reinterpret_cast<PyOp(Cumsum)*>(self)->inst();
  6359. static_cast<void>(opdef);
  6360. std::unordered_map<std::string, py::object> state {
  6361. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  6362. {"exclusive", serialization<decltype(opdef.exclusive)>::dump(opdef.exclusive)},
  6363. {"reverse", serialization<decltype(opdef.reverse)>::dump(opdef.reverse)}
  6364. };
  6365. return py::cast(state).release().ptr();
  6366. }
  6367. static PyObject* setstate(PyObject* self, PyObject* args) {
  6368. PyObject* dict = PyTuple_GetItem(args, 0);
  6369. if (!dict) return NULL;
  6370. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6371. auto& opdef = reinterpret_cast<PyOp(Cumsum)*>(self)->inst();
  6372. static_cast<void>(opdef);
  6373. {
  6374. auto&& iter = state.find("axis");
  6375. if (iter != state.end()) {
  6376. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  6377. }
  6378. }
  6379. {
  6380. auto&& iter = state.find("exclusive");
  6381. if (iter != state.end()) {
  6382. opdef.exclusive = serialization<decltype(opdef.exclusive)>::load(iter->second);
  6383. }
  6384. }
  6385. {
  6386. auto&& iter = state.find("reverse");
  6387. if (iter != state.end()) {
  6388. opdef.reverse = serialization<decltype(opdef.reverse)>::load(iter->second);
  6389. }
  6390. }
  6391. Py_RETURN_NONE;
  6392. }
  6393. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6394. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  6395. static PyMethodDef py_init_methoddef;
  6396. // };
  6397. PyOpDefEnd(Cumsum)
  6398. int PyOp(Cumsum)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6399. static const char* kwlist[] = {"axis", "exclusive", "reverse", "scope", NULL};
  6400. PyObject *axis = NULL, *exclusive = NULL, *reverse = NULL, *scope = NULL;
  6401. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &axis, &exclusive, &reverse, &scope))
  6402. return -1;
  6403. if (axis) {
  6404. try {
  6405. // TODO: remove this guard which is used for pybind11 implicit conversion
  6406. py::detail::loader_life_support guard{};
  6407. reinterpret_cast<PyOp(Cumsum)*>(self)->inst().axis =
  6408. py::cast<decltype(Cumsum::axis)>(py::handle(axis));
  6409. } CATCH_ALL(-1)
  6410. }
  6411. if (exclusive) {
  6412. try {
  6413. // TODO: remove this guard which is used for pybind11 implicit conversion
  6414. py::detail::loader_life_support guard{};
  6415. reinterpret_cast<PyOp(Cumsum)*>(self)->inst().exclusive =
  6416. py::cast<decltype(Cumsum::exclusive)>(py::handle(exclusive));
  6417. } CATCH_ALL(-1)
  6418. }
  6419. if (reverse) {
  6420. try {
  6421. // TODO: remove this guard which is used for pybind11 implicit conversion
  6422. py::detail::loader_life_support guard{};
  6423. reinterpret_cast<PyOp(Cumsum)*>(self)->inst().reverse =
  6424. py::cast<decltype(Cumsum::reverse)>(py::handle(reverse));
  6425. } CATCH_ALL(-1)
  6426. }
  6427. if (scope) {
  6428. try {
  6429. reinterpret_cast<PyOp(OpDef)*>(self)->op
  6430. ->set_scope(py::cast<std::string>(py::handle(scope)));
  6431. } CATCH_ALL(-1)
  6432. }
  6433. return 0;
  6434. }
  6435. PyGetSetDef PyOp(Cumsum)::py_getsetters[] = {
  6436. {const_cast<char*>("axis"), py_get_generic(Cumsum, axis), py_set_generic(Cumsum, axis), const_cast<char*>("axis"), NULL},
  6437. {const_cast<char*>("exclusive"), py_get_generic(Cumsum, exclusive), py_set_generic(Cumsum, exclusive), const_cast<char*>("exclusive"), NULL},
  6438. {const_cast<char*>("reverse"), py_get_generic(Cumsum, reverse), py_set_generic(Cumsum, reverse), const_cast<char*>("reverse"), NULL},
  6439. {NULL} /* Sentinel */
  6440. };
  6441. PyMethodDef PyOp(Cumsum)::tp_methods[] = {
  6442. {const_cast<char*>("__getstate__"), PyOp(Cumsum)::getstate, METH_NOARGS, "Cumsum getstate"},
  6443. {const_cast<char*>("__setstate__"), PyOp(Cumsum)::setstate, METH_VARARGS, "Cumsum setstate"},
  6444. {NULL} /* Sentinel */
  6445. };
  6446. PyObject *PyOp(Cumsum)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  6447. if (PyOp(Cumsum)::py_init(self, args, kwds) < 0) {
  6448. return NULL;
  6449. }
  6450. Py_RETURN_NONE;
  6451. }
  6452. PyMethodDef PyOp(Cumsum)::py_init_methoddef = {
  6453. "__init__",
  6454. (PyCFunction)PyOp(Cumsum)::py_init_proxy,
  6455. METH_VARARGS | METH_KEYWORDS,
  6456. "__init__(self, axis: int = ..., exclusive: bool = ..., reverse: bool = ...) -> None\n"
  6457. };
  6458. void _init_py_Cumsum(py::module m) {
  6459. using py_op = PyOp(Cumsum);
  6460. auto& py_type = PyOpType(Cumsum);
  6461. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  6462. py_type.tp_name = "megengine.core._imperative_rt.ops.Cumsum";
  6463. py_type.tp_basicsize = sizeof(PyOp(Cumsum));
  6464. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  6465. py_type.tp_doc = "Cumsum";
  6466. py_type.tp_base = &PyOpType(OpDef);
  6467. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  6468. py_type.tp_new = py_new_generic<py_op>;
  6469. py_type.tp_init = py_op::py_init;
  6470. py_type.tp_methods = py_op::tp_methods;
  6471. py_type.tp_getset = py_op::py_getsetters;
  6472. py_type.tp_dict = PyDict_New();
  6473. PyObject* descr = PyDescr_NewMethod(&PyOpType(Cumsum), &PyOp(Cumsum)::py_init_methoddef);
  6474. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  6475. mgb_assert(PyType_Ready(&py_type) >= 0);
  6476. PyType_Modified(&py_type);
  6477. m.add_object("Cumsum", reinterpret_cast<PyObject*>(&py_type));
  6478. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Cumsum::typeinfo(), &py_type).second);
  6479. }
  6480. template<> struct EnumTrait<CvtColor::Mode> {
  6481. static constexpr const char *name = "CvtColor.Mode";
  6482. static constexpr std::underlying_type_t<CvtColor::Mode> max = 32 - 1;
  6483. };
  6484. template<> PyTypeObject* EnumWrapper<CvtColor::Mode>::type = nullptr;
  6485. template<> const char*
  6486. EnumWrapper<CvtColor::Mode>::members[] = {"RGB2GRAY", "RGB2YUV", "YUV2RGB", "GRAY2RGB", "RGBA2RGB", "RGBA2BGR", "RGBA2GRAY", "RGB2BGR", "BGR2GRAY", "BGR2RGB", "YUV2GRAY_NV21", "YUV2RGB_NV21", "YUV2BGR_NV21", "YUV2GRAY_NV12", "YUV2RGB_NV12", "YUV2BGR_NV12", "YUV2GRAY_YV12", "YUV2RGB_YV12", "YUV2BGR_YV12", "YUV2GRAY_YU12", "YUV2RGB_YU12", "YUV2BGR_YU12", "YCrCb2RGB", "YCrCb2BGR", "BT601_YUV2RGB_NV21", "BT601_YUV2BGR_NV21", "BT601_YUV2RGB_NV12", "BT601_YUV2BGR_NV12", "BT601_YUV2RGB_YV12", "BT601_YUV2BGR_YV12", "BT601_YUV2RGB_YU12", "BT601_YUV2BGR_YU12"};
  6487. template<> std::unordered_map<std::string, CvtColor::Mode>
  6488. EnumWrapper<CvtColor::Mode>::mem2value = {{normalize_enum("RGB2GRAY"), CvtColor::Mode::RGB2GRAY}, {normalize_enum("RGB2YUV"), CvtColor::Mode::RGB2YUV}, {normalize_enum("YUV2RGB"), CvtColor::Mode::YUV2RGB}, {normalize_enum("GRAY2RGB"), CvtColor::Mode::GRAY2RGB}, {normalize_enum("RGBA2RGB"), CvtColor::Mode::RGBA2RGB}, {normalize_enum("RGBA2BGR"), CvtColor::Mode::RGBA2BGR}, {normalize_enum("RGBA2GRAY"), CvtColor::Mode::RGBA2GRAY}, {normalize_enum("RGB2BGR"), CvtColor::Mode::RGB2BGR}, {normalize_enum("BGR2GRAY"), CvtColor::Mode::BGR2GRAY}, {normalize_enum("BGR2RGB"), CvtColor::Mode::BGR2RGB}, {normalize_enum("YUV2GRAY_NV21"), CvtColor::Mode::YUV2GRAY_NV21}, {normalize_enum("YUV2RGB_NV21"), CvtColor::Mode::YUV2RGB_NV21}, {normalize_enum("YUV2BGR_NV21"), CvtColor::Mode::YUV2BGR_NV21}, {normalize_enum("YUV2GRAY_NV12"), CvtColor::Mode::YUV2GRAY_NV12}, {normalize_enum("YUV2RGB_NV12"), CvtColor::Mode::YUV2RGB_NV12}, {normalize_enum("YUV2BGR_NV12"), CvtColor::Mode::YUV2BGR_NV12}, {normalize_enum("YUV2GRAY_YV12"), CvtColor::Mode::YUV2GRAY_YV12}, {normalize_enum("YUV2RGB_YV12"), CvtColor::Mode::YUV2RGB_YV12}, {normalize_enum("YUV2BGR_YV12"), CvtColor::Mode::YUV2BGR_YV12}, {normalize_enum("YUV2GRAY_YU12"), CvtColor::Mode::YUV2GRAY_YU12}, {normalize_enum("YUV2RGB_YU12"), CvtColor::Mode::YUV2RGB_YU12}, {normalize_enum("YUV2BGR_YU12"), CvtColor::Mode::YUV2BGR_YU12}, {normalize_enum("YCrCb2RGB"), CvtColor::Mode::YCrCb2RGB}, {normalize_enum("YCrCb2BGR"), CvtColor::Mode::YCrCb2BGR}, {normalize_enum("BT601_YUV2RGB_NV21"), CvtColor::Mode::BT601_YUV2RGB_NV21}, {normalize_enum("BT601_YUV2BGR_NV21"), CvtColor::Mode::BT601_YUV2BGR_NV21}, {normalize_enum("BT601_YUV2RGB_NV12"), CvtColor::Mode::BT601_YUV2RGB_NV12}, {normalize_enum("BT601_YUV2BGR_NV12"), CvtColor::Mode::BT601_YUV2BGR_NV12}, {normalize_enum("BT601_YUV2RGB_YV12"), CvtColor::Mode::BT601_YUV2RGB_YV12}, {normalize_enum("BT601_YUV2BGR_YV12"), CvtColor::Mode::BT601_YUV2BGR_YV12}, {normalize_enum("BT601_YUV2RGB_YU12"), CvtColor::Mode::BT601_YUV2RGB_YU12}, {normalize_enum("BT601_YUV2BGR_YU12"), CvtColor::Mode::BT601_YUV2BGR_YU12}};
  6489. template<> PyObject* EnumWrapper<CvtColor::Mode>::pyobj_insts[32] = {nullptr};
  6490. void _init_py_CvtColor_Mode(PyTypeObject& py_type) {
  6491. auto& e_type = EnumWrapper<CvtColor::Mode>::type;
  6492. static PyMethodDef tp_methods[] = {
  6493. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<CvtColor::Mode>::py_dump, METH_NOARGS, NULL},
  6494. {NULL} /* Sentinel */
  6495. };
  6496. static PyType_Slot slots[] = {
  6497. {Py_tp_repr, (void*)EnumWrapper<CvtColor::Mode>::py_repr},
  6498. {Py_tp_richcompare, (void*)EnumWrapper<CvtColor::Mode>::tp_richcompare},
  6499. {Py_tp_methods, tp_methods},
  6500. {0, NULL}
  6501. };
  6502. static PyType_Spec spec = {
  6503. // name
  6504. "megengine.core._imperative_rt.ops.CvtColor.Mode",
  6505. // basicsize
  6506. sizeof(EnumWrapper<CvtColor::Mode>),
  6507. // itemsize
  6508. 0,
  6509. // flags
  6510. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  6511. // slots
  6512. slots
  6513. };
  6514. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  6515. mgb_assert(
  6516. e_type->tp_setattro(
  6517. reinterpret_cast<PyObject*>(e_type),
  6518. py::cast("__name__").release().ptr(),
  6519. py::cast("Mode").release().ptr()) >= 0);
  6520. mgb_assert(
  6521. e_type->tp_setattro(
  6522. reinterpret_cast<PyObject*>(e_type),
  6523. py::cast("__module__").release().ptr(),
  6524. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  6525. mgb_assert(
  6526. e_type->tp_setattro(
  6527. reinterpret_cast<PyObject*>(e_type),
  6528. py::cast("__qualname__").release().ptr(),
  6529. py::cast("CvtColor.Mode").release().ptr()) >= 0);
  6530. {
  6531. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6532. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGB2GRAY;
  6533. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGB2GRAY", inst) >= 0);
  6534. EnumWrapper<CvtColor::Mode>::pyobj_insts[0] = inst;
  6535. }{
  6536. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6537. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGB2YUV;
  6538. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGB2YUV", inst) >= 0);
  6539. EnumWrapper<CvtColor::Mode>::pyobj_insts[1] = inst;
  6540. }{
  6541. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6542. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2RGB;
  6543. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB", inst) >= 0);
  6544. EnumWrapper<CvtColor::Mode>::pyobj_insts[2] = inst;
  6545. }{
  6546. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6547. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::GRAY2RGB;
  6548. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GRAY2RGB", inst) >= 0);
  6549. EnumWrapper<CvtColor::Mode>::pyobj_insts[3] = inst;
  6550. }{
  6551. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6552. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGBA2RGB;
  6553. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGBA2RGB", inst) >= 0);
  6554. EnumWrapper<CvtColor::Mode>::pyobj_insts[4] = inst;
  6555. }{
  6556. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6557. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGBA2BGR;
  6558. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGBA2BGR", inst) >= 0);
  6559. EnumWrapper<CvtColor::Mode>::pyobj_insts[5] = inst;
  6560. }{
  6561. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6562. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGBA2GRAY;
  6563. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGBA2GRAY", inst) >= 0);
  6564. EnumWrapper<CvtColor::Mode>::pyobj_insts[6] = inst;
  6565. }{
  6566. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6567. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGB2BGR;
  6568. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGB2BGR", inst) >= 0);
  6569. EnumWrapper<CvtColor::Mode>::pyobj_insts[7] = inst;
  6570. }{
  6571. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6572. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BGR2GRAY;
  6573. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BGR2GRAY", inst) >= 0);
  6574. EnumWrapper<CvtColor::Mode>::pyobj_insts[8] = inst;
  6575. }{
  6576. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6577. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BGR2RGB;
  6578. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BGR2RGB", inst) >= 0);
  6579. EnumWrapper<CvtColor::Mode>::pyobj_insts[9] = inst;
  6580. }{
  6581. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6582. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2GRAY_NV21;
  6583. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_NV21", inst) >= 0);
  6584. EnumWrapper<CvtColor::Mode>::pyobj_insts[10] = inst;
  6585. }{
  6586. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6587. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2RGB_NV21;
  6588. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_NV21", inst) >= 0);
  6589. EnumWrapper<CvtColor::Mode>::pyobj_insts[11] = inst;
  6590. }{
  6591. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6592. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2BGR_NV21;
  6593. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_NV21", inst) >= 0);
  6594. EnumWrapper<CvtColor::Mode>::pyobj_insts[12] = inst;
  6595. }{
  6596. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6597. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2GRAY_NV12;
  6598. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_NV12", inst) >= 0);
  6599. EnumWrapper<CvtColor::Mode>::pyobj_insts[13] = inst;
  6600. }{
  6601. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6602. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2RGB_NV12;
  6603. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_NV12", inst) >= 0);
  6604. EnumWrapper<CvtColor::Mode>::pyobj_insts[14] = inst;
  6605. }{
  6606. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6607. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2BGR_NV12;
  6608. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_NV12", inst) >= 0);
  6609. EnumWrapper<CvtColor::Mode>::pyobj_insts[15] = inst;
  6610. }{
  6611. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6612. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2GRAY_YV12;
  6613. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_YV12", inst) >= 0);
  6614. EnumWrapper<CvtColor::Mode>::pyobj_insts[16] = inst;
  6615. }{
  6616. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6617. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2RGB_YV12;
  6618. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_YV12", inst) >= 0);
  6619. EnumWrapper<CvtColor::Mode>::pyobj_insts[17] = inst;
  6620. }{
  6621. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6622. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2BGR_YV12;
  6623. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_YV12", inst) >= 0);
  6624. EnumWrapper<CvtColor::Mode>::pyobj_insts[18] = inst;
  6625. }{
  6626. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6627. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2GRAY_YU12;
  6628. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_YU12", inst) >= 0);
  6629. EnumWrapper<CvtColor::Mode>::pyobj_insts[19] = inst;
  6630. }{
  6631. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6632. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2RGB_YU12;
  6633. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_YU12", inst) >= 0);
  6634. EnumWrapper<CvtColor::Mode>::pyobj_insts[20] = inst;
  6635. }{
  6636. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6637. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2BGR_YU12;
  6638. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_YU12", inst) >= 0);
  6639. EnumWrapper<CvtColor::Mode>::pyobj_insts[21] = inst;
  6640. }{
  6641. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6642. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YCrCb2RGB;
  6643. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YCrCb2RGB", inst) >= 0);
  6644. EnumWrapper<CvtColor::Mode>::pyobj_insts[22] = inst;
  6645. }{
  6646. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6647. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YCrCb2BGR;
  6648. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YCrCb2BGR", inst) >= 0);
  6649. EnumWrapper<CvtColor::Mode>::pyobj_insts[23] = inst;
  6650. }{
  6651. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6652. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_NV21;
  6653. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_NV21", inst) >= 0);
  6654. EnumWrapper<CvtColor::Mode>::pyobj_insts[24] = inst;
  6655. }{
  6656. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6657. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_NV21;
  6658. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_NV21", inst) >= 0);
  6659. EnumWrapper<CvtColor::Mode>::pyobj_insts[25] = inst;
  6660. }{
  6661. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6662. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_NV12;
  6663. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_NV12", inst) >= 0);
  6664. EnumWrapper<CvtColor::Mode>::pyobj_insts[26] = inst;
  6665. }{
  6666. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6667. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_NV12;
  6668. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_NV12", inst) >= 0);
  6669. EnumWrapper<CvtColor::Mode>::pyobj_insts[27] = inst;
  6670. }{
  6671. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6672. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_YV12;
  6673. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_YV12", inst) >= 0);
  6674. EnumWrapper<CvtColor::Mode>::pyobj_insts[28] = inst;
  6675. }{
  6676. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6677. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_YV12;
  6678. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_YV12", inst) >= 0);
  6679. EnumWrapper<CvtColor::Mode>::pyobj_insts[29] = inst;
  6680. }{
  6681. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6682. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_YU12;
  6683. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_YU12", inst) >= 0);
  6684. EnumWrapper<CvtColor::Mode>::pyobj_insts[30] = inst;
  6685. }{
  6686. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6687. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_YU12;
  6688. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_YU12", inst) >= 0);
  6689. EnumWrapper<CvtColor::Mode>::pyobj_insts[31] = inst;
  6690. }
  6691. Py_INCREF(e_type);
  6692. mgb_assert(PyDict_SetItemString(
  6693. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6694. }
  6695. PyOpDefBegin(CvtColor) // {
  6696. static PyGetSetDef py_getsetters[];
  6697. static PyMethodDef tp_methods[];
  6698. static PyObject* getstate(PyObject* self, PyObject*) {
  6699. auto& opdef = reinterpret_cast<PyOp(CvtColor)*>(self)->inst();
  6700. static_cast<void>(opdef);
  6701. std::unordered_map<std::string, py::object> state {
  6702. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)}
  6703. };
  6704. return py::cast(state).release().ptr();
  6705. }
  6706. static PyObject* setstate(PyObject* self, PyObject* args) {
  6707. PyObject* dict = PyTuple_GetItem(args, 0);
  6708. if (!dict) return NULL;
  6709. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6710. auto& opdef = reinterpret_cast<PyOp(CvtColor)*>(self)->inst();
  6711. static_cast<void>(opdef);
  6712. {
  6713. auto&& iter = state.find("mode");
  6714. if (iter != state.end()) {
  6715. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  6716. }
  6717. }
  6718. Py_RETURN_NONE;
  6719. }
  6720. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6721. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  6722. static PyMethodDef py_init_methoddef;
  6723. // };
  6724. PyOpDefEnd(CvtColor)
  6725. int PyOp(CvtColor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6726. static const char* kwlist[] = {"mode", "scope", NULL};
  6727. PyObject *mode = NULL, *scope = NULL;
  6728. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &mode, &scope))
  6729. return -1;
  6730. if (mode) {
  6731. try {
  6732. // TODO: remove this guard which is used for pybind11 implicit conversion
  6733. py::detail::loader_life_support guard{};
  6734. reinterpret_cast<PyOp(CvtColor)*>(self)->inst().mode =
  6735. py::cast<decltype(CvtColor::mode)>(py::handle(mode));
  6736. } CATCH_ALL(-1)
  6737. }
  6738. if (scope) {
  6739. try {
  6740. reinterpret_cast<PyOp(OpDef)*>(self)->op
  6741. ->set_scope(py::cast<std::string>(py::handle(scope)));
  6742. } CATCH_ALL(-1)
  6743. }
  6744. return 0;
  6745. }
  6746. PyGetSetDef PyOp(CvtColor)::py_getsetters[] = {
  6747. {const_cast<char*>("mode"), py_get_generic(CvtColor, mode), py_set_generic(CvtColor, mode), const_cast<char*>("mode"), NULL},
  6748. {NULL} /* Sentinel */
  6749. };
  6750. PyMethodDef PyOp(CvtColor)::tp_methods[] = {
  6751. {const_cast<char*>("__getstate__"), PyOp(CvtColor)::getstate, METH_NOARGS, "CvtColor getstate"},
  6752. {const_cast<char*>("__setstate__"), PyOp(CvtColor)::setstate, METH_VARARGS, "CvtColor setstate"},
  6753. {NULL} /* Sentinel */
  6754. };
  6755. PyObject *PyOp(CvtColor)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  6756. if (PyOp(CvtColor)::py_init(self, args, kwds) < 0) {
  6757. return NULL;
  6758. }
  6759. Py_RETURN_NONE;
  6760. }
  6761. PyMethodDef PyOp(CvtColor)::py_init_methoddef = {
  6762. "__init__",
  6763. (PyCFunction)PyOp(CvtColor)::py_init_proxy,
  6764. METH_VARARGS | METH_KEYWORDS,
  6765. "__init__(self, mode: Union[str, Mode] = ...) -> None\n"
  6766. };
  6767. void _init_py_CvtColor(py::module m) {
  6768. using py_op = PyOp(CvtColor);
  6769. auto& py_type = PyOpType(CvtColor);
  6770. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  6771. py_type.tp_name = "megengine.core._imperative_rt.ops.CvtColor";
  6772. py_type.tp_basicsize = sizeof(PyOp(CvtColor));
  6773. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  6774. py_type.tp_doc = "CvtColor";
  6775. py_type.tp_base = &PyOpType(OpDef);
  6776. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  6777. py_type.tp_new = py_new_generic<py_op>;
  6778. py_type.tp_init = py_op::py_init;
  6779. py_type.tp_methods = py_op::tp_methods;
  6780. py_type.tp_getset = py_op::py_getsetters;
  6781. py_type.tp_dict = PyDict_New();
  6782. PyObject* descr = PyDescr_NewMethod(&PyOpType(CvtColor), &PyOp(CvtColor)::py_init_methoddef);
  6783. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  6784. mgb_assert(PyType_Ready(&py_type) >= 0);
  6785. _init_py_CvtColor_Mode(py_type);
  6786. PyType_Modified(&py_type);
  6787. m.add_object("CvtColor", reinterpret_cast<PyObject*>(&py_type));
  6788. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CvtColor::typeinfo(), &py_type).second);
  6789. }
  6790. void _init_py_DeformableConv_Mode(PyTypeObject& py_type) {
  6791. auto& e_type = EnumWrapper<DeformableConv::Mode>::type;
  6792. Py_INCREF(e_type);
  6793. mgb_assert(PyDict_SetItemString(
  6794. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6795. }
  6796. void _init_py_DeformableConv_Sparse(PyTypeObject& py_type) {
  6797. auto& e_type = EnumWrapper<DeformableConv::Sparse>::type;
  6798. Py_INCREF(e_type);
  6799. mgb_assert(PyDict_SetItemString(
  6800. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6801. }
  6802. void _init_py_DeformableConv_Format(PyTypeObject& py_type) {
  6803. auto& e_type = EnumWrapper<DeformableConv::Format>::type;
  6804. Py_INCREF(e_type);
  6805. mgb_assert(PyDict_SetItemString(
  6806. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6807. }
  6808. void _init_py_DeformableConv_ComputeMode(PyTypeObject& py_type) {
  6809. auto& e_type = EnumWrapper<DeformableConv::ComputeMode>::type;
  6810. Py_INCREF(e_type);
  6811. mgb_assert(PyDict_SetItemString(
  6812. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6813. }
  6814. void _init_py_DeformableConv_Strategy(PyTypeObject& py_type) {
  6815. auto& e_type = BitCombinedEnumWrapper<DeformableConv::Strategy>::type;
  6816. Py_INCREF(e_type);
  6817. mgb_assert(PyDict_SetItemString(
  6818. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6819. }
  6820. PyOpDefBegin(DeformableConv) // {
  6821. static PyGetSetDef py_getsetters[];
  6822. static PyMethodDef tp_methods[];
  6823. static PyObject* getstate(PyObject* self, PyObject*) {
  6824. auto& opdef = reinterpret_cast<PyOp(DeformableConv)*>(self)->inst();
  6825. static_cast<void>(opdef);
  6826. std::unordered_map<std::string, py::object> state {
  6827. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  6828. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  6829. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  6830. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  6831. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  6832. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  6833. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  6834. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  6835. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  6836. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  6837. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  6838. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)}
  6839. };
  6840. return py::cast(state).release().ptr();
  6841. }
  6842. static PyObject* setstate(PyObject* self, PyObject* args) {
  6843. PyObject* dict = PyTuple_GetItem(args, 0);
  6844. if (!dict) return NULL;
  6845. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6846. auto& opdef = reinterpret_cast<PyOp(DeformableConv)*>(self)->inst();
  6847. static_cast<void>(opdef);
  6848. {
  6849. auto&& iter = state.find("mode");
  6850. if (iter != state.end()) {
  6851. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  6852. }
  6853. }
  6854. {
  6855. auto&& iter = state.find("pad_h");
  6856. if (iter != state.end()) {
  6857. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  6858. }
  6859. }
  6860. {
  6861. auto&& iter = state.find("pad_w");
  6862. if (iter != state.end()) {
  6863. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  6864. }
  6865. }
  6866. {
  6867. auto&& iter = state.find("stride_h");
  6868. if (iter != state.end()) {
  6869. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  6870. }
  6871. }
  6872. {
  6873. auto&& iter = state.find("stride_w");
  6874. if (iter != state.end()) {
  6875. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  6876. }
  6877. }
  6878. {
  6879. auto&& iter = state.find("dilate_h");
  6880. if (iter != state.end()) {
  6881. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  6882. }
  6883. }
  6884. {
  6885. auto&& iter = state.find("dilate_w");
  6886. if (iter != state.end()) {
  6887. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  6888. }
  6889. }
  6890. {
  6891. auto&& iter = state.find("sparse");
  6892. if (iter != state.end()) {
  6893. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  6894. }
  6895. }
  6896. {
  6897. auto&& iter = state.find("format");
  6898. if (iter != state.end()) {
  6899. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  6900. }
  6901. }
  6902. {
  6903. auto&& iter = state.find("compute_mode");
  6904. if (iter != state.end()) {
  6905. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  6906. }
  6907. }
  6908. {
  6909. auto&& iter = state.find("strategy");
  6910. if (iter != state.end()) {
  6911. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  6912. }
  6913. }
  6914. {
  6915. auto&& iter = state.find("workspace_limit");
  6916. if (iter != state.end()) {
  6917. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  6918. }
  6919. }
  6920. Py_RETURN_NONE;
  6921. }
  6922. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6923. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  6924. static PyMethodDef py_init_methoddef;
  6925. // };
  6926. PyOpDefEnd(DeformableConv)
  6927. int PyOp(DeformableConv)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6928. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "strategy", "workspace_limit", "scope", NULL};
  6929. PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *strategy = NULL, *workspace_limit = NULL, *scope = NULL;
  6930. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &strategy, &workspace_limit, &scope))
  6931. return -1;
  6932. if (mode) {
  6933. try {
  6934. // TODO: remove this guard which is used for pybind11 implicit conversion
  6935. py::detail::loader_life_support guard{};
  6936. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().mode =
  6937. py::cast<decltype(DeformableConv::mode)>(py::handle(mode));
  6938. } CATCH_ALL(-1)
  6939. }
  6940. if (pad_h) {
  6941. try {
  6942. // TODO: remove this guard which is used for pybind11 implicit conversion
  6943. py::detail::loader_life_support guard{};
  6944. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().pad_h =
  6945. py::cast<decltype(DeformableConv::pad_h)>(py::handle(pad_h));
  6946. } CATCH_ALL(-1)
  6947. }
  6948. if (pad_w) {
  6949. try {
  6950. // TODO: remove this guard which is used for pybind11 implicit conversion
  6951. py::detail::loader_life_support guard{};
  6952. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().pad_w =
  6953. py::cast<decltype(DeformableConv::pad_w)>(py::handle(pad_w));
  6954. } CATCH_ALL(-1)
  6955. }
  6956. if (stride_h) {
  6957. try {
  6958. // TODO: remove this guard which is used for pybind11 implicit conversion
  6959. py::detail::loader_life_support guard{};
  6960. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().stride_h =
  6961. py::cast<decltype(DeformableConv::stride_h)>(py::handle(stride_h));
  6962. } CATCH_ALL(-1)
  6963. }
  6964. if (stride_w) {
  6965. try {
  6966. // TODO: remove this guard which is used for pybind11 implicit conversion
  6967. py::detail::loader_life_support guard{};
  6968. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().stride_w =
  6969. py::cast<decltype(DeformableConv::stride_w)>(py::handle(stride_w));
  6970. } CATCH_ALL(-1)
  6971. }
  6972. if (dilate_h) {
  6973. try {
  6974. // TODO: remove this guard which is used for pybind11 implicit conversion
  6975. py::detail::loader_life_support guard{};
  6976. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().dilate_h =
  6977. py::cast<decltype(DeformableConv::dilate_h)>(py::handle(dilate_h));
  6978. } CATCH_ALL(-1)
  6979. }
  6980. if (dilate_w) {
  6981. try {
  6982. // TODO: remove this guard which is used for pybind11 implicit conversion
  6983. py::detail::loader_life_support guard{};
  6984. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().dilate_w =
  6985. py::cast<decltype(DeformableConv::dilate_w)>(py::handle(dilate_w));
  6986. } CATCH_ALL(-1)
  6987. }
  6988. if (sparse) {
  6989. try {
  6990. // TODO: remove this guard which is used for pybind11 implicit conversion
  6991. py::detail::loader_life_support guard{};
  6992. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().sparse =
  6993. py::cast<decltype(DeformableConv::sparse)>(py::handle(sparse));
  6994. } CATCH_ALL(-1)
  6995. }
  6996. if (format) {
  6997. try {
  6998. // TODO: remove this guard which is used for pybind11 implicit conversion
  6999. py::detail::loader_life_support guard{};
  7000. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().format =
  7001. py::cast<decltype(DeformableConv::format)>(py::handle(format));
  7002. } CATCH_ALL(-1)
  7003. }
  7004. if (compute_mode) {
  7005. try {
  7006. // TODO: remove this guard which is used for pybind11 implicit conversion
  7007. py::detail::loader_life_support guard{};
  7008. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().compute_mode =
  7009. py::cast<decltype(DeformableConv::compute_mode)>(py::handle(compute_mode));
  7010. } CATCH_ALL(-1)
  7011. }
  7012. if (strategy) {
  7013. try {
  7014. // TODO: remove this guard which is used for pybind11 implicit conversion
  7015. py::detail::loader_life_support guard{};
  7016. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().strategy =
  7017. py::cast<decltype(DeformableConv::strategy)>(py::handle(strategy));
  7018. } CATCH_ALL(-1)
  7019. }
  7020. if (workspace_limit) {
  7021. try {
  7022. // TODO: remove this guard which is used for pybind11 implicit conversion
  7023. py::detail::loader_life_support guard{};
  7024. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().workspace_limit =
  7025. py::cast<decltype(DeformableConv::workspace_limit)>(py::handle(workspace_limit));
  7026. } CATCH_ALL(-1)
  7027. }
  7028. if (scope) {
  7029. try {
  7030. reinterpret_cast<PyOp(OpDef)*>(self)->op
  7031. ->set_scope(py::cast<std::string>(py::handle(scope)));
  7032. } CATCH_ALL(-1)
  7033. }
  7034. return 0;
  7035. }
  7036. PyGetSetDef PyOp(DeformableConv)::py_getsetters[] = {
  7037. {const_cast<char*>("mode"), py_get_generic(DeformableConv, mode), py_set_generic(DeformableConv, mode), const_cast<char*>("mode"), NULL},
  7038. {const_cast<char*>("pad_h"), py_get_generic(DeformableConv, pad_h), py_set_generic(DeformableConv, pad_h), const_cast<char*>("pad_h"), NULL},
  7039. {const_cast<char*>("pad_w"), py_get_generic(DeformableConv, pad_w), py_set_generic(DeformableConv, pad_w), const_cast<char*>("pad_w"), NULL},
  7040. {const_cast<char*>("stride_h"), py_get_generic(DeformableConv, stride_h), py_set_generic(DeformableConv, stride_h), const_cast<char*>("stride_h"), NULL},
  7041. {const_cast<char*>("stride_w"), py_get_generic(DeformableConv, stride_w), py_set_generic(DeformableConv, stride_w), const_cast<char*>("stride_w"), NULL},
  7042. {const_cast<char*>("dilate_h"), py_get_generic(DeformableConv, dilate_h), py_set_generic(DeformableConv, dilate_h), const_cast<char*>("dilate_h"), NULL},
  7043. {const_cast<char*>("dilate_w"), py_get_generic(DeformableConv, dilate_w), py_set_generic(DeformableConv, dilate_w), const_cast<char*>("dilate_w"), NULL},
  7044. {const_cast<char*>("sparse"), py_get_generic(DeformableConv, sparse), py_set_generic(DeformableConv, sparse), const_cast<char*>("sparse"), NULL},
  7045. {const_cast<char*>("format"), py_get_generic(DeformableConv, format), py_set_generic(DeformableConv, format), const_cast<char*>("format"), NULL},
  7046. {const_cast<char*>("compute_mode"), py_get_generic(DeformableConv, compute_mode), py_set_generic(DeformableConv, compute_mode), const_cast<char*>("compute_mode"), NULL},
  7047. {const_cast<char*>("strategy"), py_get_generic(DeformableConv, strategy), py_set_generic(DeformableConv, strategy), const_cast<char*>("strategy"), NULL},
  7048. {const_cast<char*>("workspace_limit"), py_get_generic(DeformableConv, workspace_limit), py_set_generic(DeformableConv, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  7049. {NULL} /* Sentinel */
  7050. };
  7051. PyMethodDef PyOp(DeformableConv)::tp_methods[] = {
  7052. {const_cast<char*>("__getstate__"), PyOp(DeformableConv)::getstate, METH_NOARGS, "DeformableConv getstate"},
  7053. {const_cast<char*>("__setstate__"), PyOp(DeformableConv)::setstate, METH_VARARGS, "DeformableConv setstate"},
  7054. {NULL} /* Sentinel */
  7055. };
  7056. PyObject *PyOp(DeformableConv)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  7057. if (PyOp(DeformableConv)::py_init(self, args, kwds) < 0) {
  7058. return NULL;
  7059. }
  7060. Py_RETURN_NONE;
  7061. }
  7062. PyMethodDef PyOp(DeformableConv)::py_init_methoddef = {
  7063. "__init__",
  7064. (PyCFunction)PyOp(DeformableConv)::py_init_proxy,
  7065. METH_VARARGS | METH_KEYWORDS,
  7066. "__init__(self, mode: Union[str, Mode] = ..., pad_h: int = ..., pad_w: int = ..., stride_h: int = ..., stride_w: int = ..., dilate_h: int = ..., dilate_w: int = ..., sparse: Union[str, Sparse] = ..., format: Union[str, Format] = ..., compute_mode: Union[str, ComputeMode] = ..., strategy: Union[str, Strategy] = ...) -> None\n"
  7067. };
  7068. void _init_py_DeformableConv(py::module m) {
  7069. using py_op = PyOp(DeformableConv);
  7070. auto& py_type = PyOpType(DeformableConv);
  7071. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  7072. py_type.tp_name = "megengine.core._imperative_rt.ops.DeformableConv";
  7073. py_type.tp_basicsize = sizeof(PyOp(DeformableConv));
  7074. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  7075. py_type.tp_doc = "DeformableConv";
  7076. py_type.tp_base = &PyOpType(OpDef);
  7077. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  7078. py_type.tp_new = py_new_generic<py_op>;
  7079. py_type.tp_init = py_op::py_init;
  7080. py_type.tp_methods = py_op::tp_methods;
  7081. py_type.tp_getset = py_op::py_getsetters;
  7082. py_type.tp_dict = PyDict_New();
  7083. PyObject* descr = PyDescr_NewMethod(&PyOpType(DeformableConv), &PyOp(DeformableConv)::py_init_methoddef);
  7084. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  7085. mgb_assert(PyType_Ready(&py_type) >= 0);
  7086. _init_py_DeformableConv_Mode(py_type);
  7087. _init_py_DeformableConv_Sparse(py_type);
  7088. _init_py_DeformableConv_Format(py_type);
  7089. _init_py_DeformableConv_ComputeMode(py_type);
  7090. _init_py_DeformableConv_Strategy(py_type);
  7091. PyType_Modified(&py_type);
  7092. m.add_object("DeformableConv", reinterpret_cast<PyObject*>(&py_type));
  7093. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(DeformableConv::typeinfo(), &py_type).second);
  7094. }
  7095. PyOpDefBegin(DeformablePSROIPooling) // {
  7096. static PyGetSetDef py_getsetters[];
  7097. static PyMethodDef tp_methods[];
  7098. static PyObject* getstate(PyObject* self, PyObject*) {
  7099. auto& opdef = reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst();
  7100. static_cast<void>(opdef);
  7101. std::unordered_map<std::string, py::object> state {
  7102. {"no_trans", serialization<decltype(opdef.no_trans)>::dump(opdef.no_trans)},
  7103. {"spatial_scale", serialization<decltype(opdef.spatial_scale)>::dump(opdef.spatial_scale)},
  7104. {"trans_std", serialization<decltype(opdef.trans_std)>::dump(opdef.trans_std)},
  7105. {"pooled_h", serialization<decltype(opdef.pooled_h)>::dump(opdef.pooled_h)},
  7106. {"pooled_w", serialization<decltype(opdef.pooled_w)>::dump(opdef.pooled_w)},
  7107. {"part_size", serialization<decltype(opdef.part_size)>::dump(opdef.part_size)},
  7108. {"sample_per_part", serialization<decltype(opdef.sample_per_part)>::dump(opdef.sample_per_part)}
  7109. };
  7110. return py::cast(state).release().ptr();
  7111. }
  7112. static PyObject* setstate(PyObject* self, PyObject* args) {
  7113. PyObject* dict = PyTuple_GetItem(args, 0);
  7114. if (!dict) return NULL;
  7115. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  7116. auto& opdef = reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst();
  7117. static_cast<void>(opdef);
  7118. {
  7119. auto&& iter = state.find("no_trans");
  7120. if (iter != state.end()) {
  7121. opdef.no_trans = serialization<decltype(opdef.no_trans)>::load(iter->second);
  7122. }
  7123. }
  7124. {
  7125. auto&& iter = state.find("spatial_scale");
  7126. if (iter != state.end()) {
  7127. opdef.spatial_scale = serialization<decltype(opdef.spatial_scale)>::load(iter->second);
  7128. }
  7129. }
  7130. {
  7131. auto&& iter = state.find("trans_std");
  7132. if (iter != state.end()) {
  7133. opdef.trans_std = serialization<decltype(opdef.trans_std)>::load(iter->second);
  7134. }
  7135. }
  7136. {
  7137. auto&& iter = state.find("pooled_h");
  7138. if (iter != state.end()) {
  7139. opdef.pooled_h = serialization<decltype(opdef.pooled_h)>::load(iter->second);
  7140. }
  7141. }
  7142. {
  7143. auto&& iter = state.find("pooled_w");
  7144. if (iter != state.end()) {
  7145. opdef.pooled_w = serialization<decltype(opdef.pooled_w)>::load(iter->second);
  7146. }
  7147. }
  7148. {
  7149. auto&& iter = state.find("part_size");
  7150. if (iter != state.end()) {
  7151. opdef.part_size = serialization<decltype(opdef.part_size)>::load(iter->second);
  7152. }
  7153. }
  7154. {
  7155. auto&& iter = state.find("sample_per_part");
  7156. if (iter != state.end()) {
  7157. opdef.sample_per_part = serialization<decltype(opdef.sample_per_part)>::load(iter->second);
  7158. }
  7159. }
  7160. Py_RETURN_NONE;
  7161. }
  7162. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  7163. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  7164. static PyMethodDef py_init_methoddef;
  7165. // };
  7166. PyOpDefEnd(DeformablePSROIPooling)
  7167. int PyOp(DeformablePSROIPooling)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  7168. static const char* kwlist[] = {"no_trans", "spatial_scale", "trans_std", "pooled_h", "pooled_w", "part_size", "sample_per_part", "scope", NULL};
  7169. PyObject *no_trans = NULL, *spatial_scale = NULL, *trans_std = NULL, *pooled_h = NULL, *pooled_w = NULL, *part_size = NULL, *sample_per_part = NULL, *scope = NULL;
  7170. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOO", const_cast<char**>(kwlist), &no_trans, &spatial_scale, &trans_std, &pooled_h, &pooled_w, &part_size, &sample_per_part, &scope))
  7171. return -1;
  7172. if (no_trans) {
  7173. try {
  7174. // TODO: remove this guard which is used for pybind11 implicit conversion
  7175. py::detail::loader_life_support guard{};
  7176. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().no_trans =
  7177. py::cast<decltype(DeformablePSROIPooling::no_trans)>(py::handle(no_trans));
  7178. } CATCH_ALL(-1)
  7179. }
  7180. if (spatial_scale) {
  7181. try {
  7182. // TODO: remove this guard which is used for pybind11 implicit conversion
  7183. py::detail::loader_life_support guard{};
  7184. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().spatial_scale =
  7185. py::cast<decltype(DeformablePSROIPooling::spatial_scale)>(py::handle(spatial_scale));
  7186. } CATCH_ALL(-1)
  7187. }
  7188. if (trans_std) {
  7189. try {
  7190. // TODO: remove this guard which is used for pybind11 implicit conversion
  7191. py::detail::loader_life_support guard{};
  7192. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().trans_std =
  7193. py::cast<decltype(DeformablePSROIPooling::trans_std)>(py::handle(trans_std));
  7194. } CATCH_ALL(-1)
  7195. }
  7196. if (pooled_h) {
  7197. try {
  7198. // TODO: remove this guard which is used for pybind11 implicit conversion
  7199. py::detail::loader_life_support guard{};
  7200. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().pooled_h =
  7201. py::cast<decltype(DeformablePSROIPooling::pooled_h)>(py::handle(pooled_h));
  7202. } CATCH_ALL(-1)
  7203. }
  7204. if (pooled_w) {
  7205. try {
  7206. // TODO: remove this guard which is used for pybind11 implicit conversion
  7207. py::detail::loader_life_support guard{};
  7208. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().pooled_w =
  7209. py::cast<decltype(DeformablePSROIPooling::pooled_w)>(py::handle(pooled_w));
  7210. } CATCH_ALL(-1)
  7211. }
  7212. if (part_size) {
  7213. try {
  7214. // TODO: remove this guard which is used for pybind11 implicit conversion
  7215. py::detail::loader_life_support guard{};
  7216. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().part_size =
  7217. py::cast<decltype(DeformablePSROIPooling::part_size)>(py::handle(part_size));
  7218. } CATCH_ALL(-1)
  7219. }
  7220. if (sample_per_part) {
  7221. try {
  7222. // TODO: remove this guard which is used for pybind11 implicit conversion
  7223. py::detail::loader_life_support guard{};
  7224. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().sample_per_part =
  7225. py::cast<decltype(DeformablePSROIPooling::sample_per_part)>(py::handle(sample_per_part));
  7226. } CATCH_ALL(-1)
  7227. }
  7228. if (scope) {
  7229. try {
  7230. reinterpret_cast<PyOp(OpDef)*>(self)->op
  7231. ->set_scope(py::cast<std::string>(py::handle(scope)));
  7232. } CATCH_ALL(-1)
  7233. }
  7234. return 0;
  7235. }
  7236. PyGetSetDef PyOp(DeformablePSROIPooling)::py_getsetters[] = {
  7237. {const_cast<char*>("no_trans"), py_get_generic(DeformablePSROIPooling, no_trans), py_set_generic(DeformablePSROIPooling, no_trans), const_cast<char*>("no_trans"), NULL},
  7238. {const_cast<char*>("spatial_scale"), py_get_generic(DeformablePSROIPooling, spatial_scale), py_set_generic(DeformablePSROIPooling, spatial_scale), const_cast<char*>("spatial_scale"), NULL},
  7239. {const_cast<char*>("trans_std"), py_get_generic(DeformablePSROIPooling, trans_std), py_set_generic(DeformablePSROIPooling, trans_std), const_cast<char*>("trans_std"), NULL},
  7240. {const_cast<char*>("pooled_h"), py_get_generic(DeformablePSROIPooling, pooled_h), py_set_generic(DeformablePSROIPooling, pooled_h), const_cast<char*>("pooled_h"), NULL},
  7241. {const_cast<char*>("pooled_w"), py_get_generic(DeformablePSROIPooling, pooled_w), py_set_generic(DeformablePSROIPooling, pooled_w), const_cast<char*>("pooled_w"), NULL},
  7242. {const_cast<char*>("part_size"), py_get_generic(DeformablePSROIPooling, part_size), py_set_generic(DeformablePSROIPooling, part_size), const_cast<char*>("part_size"), NULL},
  7243. {const_cast<char*>("sample_per_part"), py_get_generic(DeformablePSROIPooling, sample_per_part), py_set_generic(DeformablePSROIPooling, sample_per_part), const_cast<char*>("sample_per_part"), NULL},
  7244. {NULL} /* Sentinel */
  7245. };
  7246. PyMethodDef PyOp(DeformablePSROIPooling)::tp_methods[] = {
  7247. {const_cast<char*>("__getstate__"), PyOp(DeformablePSROIPooling)::getstate, METH_NOARGS, "DeformablePSROIPooling getstate"},
  7248. {const_cast<char*>("__setstate__"), PyOp(DeformablePSROIPooling)::setstate, METH_VARARGS, "DeformablePSROIPooling setstate"},
  7249. {NULL} /* Sentinel */
  7250. };
  7251. PyObject *PyOp(DeformablePSROIPooling)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  7252. if (PyOp(DeformablePSROIPooling)::py_init(self, args, kwds) < 0) {
  7253. return NULL;
  7254. }
  7255. Py_RETURN_NONE;
  7256. }
  7257. PyMethodDef PyOp(DeformablePSROIPooling)::py_init_methoddef = {
  7258. "__init__",
  7259. (PyCFunction)PyOp(DeformablePSROIPooling)::py_init_proxy,
  7260. METH_VARARGS | METH_KEYWORDS,
  7261. "__init__(self, no_trans: bool = ..., spatial_scale: float = ..., trans_std: float = ..., pooled_h: int = ..., pooled_w: int = ..., part_size: int = ..., sample_per_part: int = ...) -> None\n"
  7262. };
  7263. void _init_py_DeformablePSROIPooling(py::module m) {
  7264. using py_op = PyOp(DeformablePSROIPooling);
  7265. auto& py_type = PyOpType(DeformablePSROIPooling);
  7266. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  7267. py_type.tp_name = "megengine.core._imperative_rt.ops.DeformablePSROIPooling";
  7268. py_type.tp_basicsize = sizeof(PyOp(DeformablePSROIPooling));
  7269. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  7270. py_type.tp_doc = "DeformablePSROIPooling";
  7271. py_type.tp_base = &PyOpType(OpDef);
  7272. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  7273. py_type.tp_new = py_new_generic<py_op>;
  7274. py_type.tp_init = py_op::py_init;
  7275. py_type.tp_methods = py_op::tp_methods;
  7276. py_type.tp_getset = py_op::py_getsetters;
  7277. py_type.tp_dict = PyDict_New();
  7278. PyObject* descr = PyDescr_NewMethod(&PyOpType(DeformablePSROIPooling), &PyOp(DeformablePSROIPooling)::py_init_methoddef);
  7279. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  7280. mgb_assert(PyType_Ready(&py_type) >= 0);
  7281. PyType_Modified(&py_type);
  7282. m.add_object("DeformablePSROIPooling", reinterpret_cast<PyObject*>(&py_type));
  7283. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(DeformablePSROIPooling::typeinfo(), &py_type).second);
  7284. }
  7285. PyOpDefBegin(Diag) // {
  7286. static PyGetSetDef py_getsetters[];
  7287. static PyMethodDef tp_methods[];
  7288. static PyObject* getstate(PyObject* self, PyObject*) {
  7289. auto& opdef = reinterpret_cast<PyOp(Diag)*>(self)->inst();
  7290. static_cast<void>(opdef);
  7291. std::unordered_map<std::string, py::object> state {
  7292. {"k", serialization<decltype(opdef.k)>::dump(opdef.k)}
  7293. };
  7294. return py::cast(state).release().ptr();
  7295. }
  7296. static PyObject* setstate(PyObject* self, PyObject* args) {
  7297. PyObject* dict = PyTuple_GetItem(args, 0);
  7298. if (!dict) return NULL;
  7299. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  7300. auto& opdef = reinterpret_cast<PyOp(Diag)*>(self)->inst();
  7301. static_cast<void>(opdef);
  7302. {
  7303. auto&& iter = state.find("k");
  7304. if (iter != state.end()) {
  7305. opdef.k = serialization<decltype(opdef.k)>::load(iter->second);
  7306. }
  7307. }
  7308. Py_RETURN_NONE;
  7309. }
  7310. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  7311. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  7312. static PyMethodDef py_init_methoddef;
  7313. // };
  7314. PyOpDefEnd(Diag)
  7315. int PyOp(Diag)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  7316. static const char* kwlist[] = {"k", "scope", NULL};
  7317. PyObject *k = NULL, *scope = NULL;
  7318. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &k, &scope))
  7319. return -1;
  7320. if (k) {
  7321. try {
  7322. // TODO: remove this guard which is used for pybind11 implicit conversion
  7323. py::detail::loader_life_support guard{};
  7324. reinterpret_cast<PyOp(Diag)*>(self)->inst().k =
  7325. py::cast<decltype(Diag::k)>(py::handle(k));
  7326. } CATCH_ALL(-1)
  7327. }
  7328. if (scope) {
  7329. try {
  7330. reinterpret_cast<PyOp(OpDef)*>(self)->op
  7331. ->set_scope(py::cast<std::string>(py::handle(scope)));
  7332. } CATCH_ALL(-1)
  7333. }
  7334. return 0;
  7335. }
  7336. PyGetSetDef PyOp(Diag)::py_getsetters[] = {
  7337. {const_cast<char*>("k"), py_get_generic(Diag, k), py_set_generic(Diag, k), const_cast<char*>("k"), NULL},
  7338. {NULL} /* Sentinel */
  7339. };
  7340. PyMethodDef PyOp(Diag)::tp_methods[] = {
  7341. {const_cast<char*>("__getstate__"), PyOp(Diag)::getstate, METH_NOARGS, "Diag getstate"},
  7342. {const_cast<char*>("__setstate__"), PyOp(Diag)::setstate, METH_VARARGS, "Diag setstate"},
  7343. {NULL} /* Sentinel */
  7344. };
  7345. PyObject *PyOp(Diag)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  7346. if (PyOp(Diag)::py_init(self, args, kwds) < 0) {
  7347. return NULL;
  7348. }
  7349. Py_RETURN_NONE;
  7350. }
  7351. PyMethodDef PyOp(Diag)::py_init_methoddef = {
  7352. "__init__",
  7353. (PyCFunction)PyOp(Diag)::py_init_proxy,
  7354. METH_VARARGS | METH_KEYWORDS,
  7355. "__init__(self, k: int = ...) -> None\n"
  7356. };
  7357. void _init_py_Diag(py::module m) {
  7358. using py_op = PyOp(Diag);
  7359. auto& py_type = PyOpType(Diag);
  7360. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  7361. py_type.tp_name = "megengine.core._imperative_rt.ops.Diag";
  7362. py_type.tp_basicsize = sizeof(PyOp(Diag));
  7363. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  7364. py_type.tp_doc = "Diag";
  7365. py_type.tp_base = &PyOpType(OpDef);
  7366. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  7367. py_type.tp_new = py_new_generic<py_op>;
  7368. py_type.tp_init = py_op::py_init;
  7369. py_type.tp_methods = py_op::tp_methods;
  7370. py_type.tp_getset = py_op::py_getsetters;
  7371. py_type.tp_dict = PyDict_New();
  7372. PyObject* descr = PyDescr_NewMethod(&PyOpType(Diag), &PyOp(Diag)::py_init_methoddef);
  7373. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  7374. mgb_assert(PyType_Ready(&py_type) >= 0);
  7375. PyType_Modified(&py_type);
  7376. m.add_object("Diag", reinterpret_cast<PyObject*>(&py_type));
  7377. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Diag::typeinfo(), &py_type).second);
  7378. }
  7379. PyOpDefBegin(Dimshuffle) // {
  7380. static PyGetSetDef py_getsetters[];
  7381. static PyMethodDef tp_methods[];
  7382. static PyObject* getstate(PyObject* self, PyObject*) {
  7383. auto& opdef = reinterpret_cast<PyOp(Dimshuffle)*>(self)->inst();
  7384. static_cast<void>(opdef);
  7385. std::unordered_map<std::string, py::object> state {
  7386. {"pattern", serialization<decltype(opdef.pattern)>::dump(opdef.pattern)}
  7387. };
  7388. return py::cast(state).release().ptr();
  7389. }
  7390. static PyObject* setstate(PyObject* self, PyObject* args) {
  7391. PyObject* dict = PyTuple_GetItem(args, 0);
  7392. if (!dict) return NULL;
  7393. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  7394. auto& opdef = reinterpret_cast<PyOp(Dimshuffle)*>(self)->inst();
  7395. static_cast<void>(opdef);
  7396. {
  7397. auto&& iter = state.find("pattern");
  7398. if (iter != state.end()) {
  7399. opdef.pattern = serialization<decltype(opdef.pattern)>::load(iter->second);
  7400. }
  7401. }
  7402. Py_RETURN_NONE;
  7403. }
  7404. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  7405. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  7406. static PyMethodDef py_init_methoddef;
  7407. // };
  7408. PyOpDefEnd(Dimshuffle)
  7409. int PyOp(Dimshuffle)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  7410. static const char* kwlist[] = {"pattern", "scope", NULL};
  7411. PyObject *pattern = NULL, *scope = NULL;
  7412. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &pattern, &scope))
  7413. return -1;
  7414. if (pattern) {
  7415. try {
  7416. // TODO: remove this guard which is used for pybind11 implicit conversion
  7417. py::detail::loader_life_support guard{};
  7418. reinterpret_cast<PyOp(Dimshuffle)*>(self)->inst().pattern =
  7419. py::cast<decltype(Dimshuffle::pattern)>(py::handle(pattern));
  7420. } CATCH_ALL(-1)
  7421. }
  7422. if (scope) {
  7423. try {
  7424. reinterpret_cast<PyOp(OpDef)*>(self)->op
  7425. ->set_scope(py::cast<std::string>(py::handle(scope)));
  7426. } CATCH_ALL(-1)
  7427. }
  7428. return 0;
  7429. }
  7430. PyGetSetDef PyOp(Dimshuffle)::py_getsetters[] = {
  7431. {const_cast<char*>("pattern"), py_get_generic(Dimshuffle, pattern), py_set_generic(Dimshuffle, pattern), const_cast<char*>("pattern"), NULL},
  7432. {NULL} /* Sentinel */
  7433. };
  7434. PyMethodDef PyOp(Dimshuffle)::tp_methods[] = {
  7435. {const_cast<char*>("__getstate__"), PyOp(Dimshuffle)::getstate, METH_NOARGS, "Dimshuffle getstate"},
  7436. {const_cast<char*>("__setstate__"), PyOp(Dimshuffle)::setstate, METH_VARARGS, "Dimshuffle setstate"},
  7437. {NULL} /* Sentinel */
  7438. };
  7439. PyObject *PyOp(Dimshuffle)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  7440. if (PyOp(Dimshuffle)::py_init(self, args, kwds) < 0) {
  7441. return NULL;
  7442. }
  7443. Py_RETURN_NONE;
  7444. }
  7445. PyMethodDef PyOp(Dimshuffle)::py_init_methoddef = {
  7446. "__init__",
  7447. (PyCFunction)PyOp(Dimshuffle)::py_init_proxy,
  7448. METH_VARARGS | METH_KEYWORDS,
  7449. "__init__(self, pattern: list[int] = ...) -> None\n"
  7450. };
  7451. void _init_py_Dimshuffle(py::module m) {
  7452. using py_op = PyOp(Dimshuffle);
  7453. auto& py_type = PyOpType(Dimshuffle);
  7454. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  7455. py_type.tp_name = "megengine.core._imperative_rt.ops.Dimshuffle";
  7456. py_type.tp_basicsize = sizeof(PyOp(Dimshuffle));
  7457. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  7458. py_type.tp_doc = "Dimshuffle";
  7459. py_type.tp_base = &PyOpType(OpDef);
  7460. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  7461. py_type.tp_new = py_new_generic<py_op>;
  7462. py_type.tp_init = py_op::py_init;
  7463. py_type.tp_methods = py_op::tp_methods;
  7464. py_type.tp_getset = py_op::py_getsetters;
  7465. py_type.tp_dict = PyDict_New();
  7466. PyObject* descr = PyDescr_NewMethod(&PyOpType(Dimshuffle), &PyOp(Dimshuffle)::py_init_methoddef);
  7467. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  7468. mgb_assert(PyType_Ready(&py_type) >= 0);
  7469. PyType_Modified(&py_type);
  7470. m.add_object("Dimshuffle", reinterpret_cast<PyObject*>(&py_type));
  7471. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Dimshuffle::typeinfo(), &py_type).second);
  7472. }
  7473. PyOpDefBegin(Dot) // {
  7474. static PyGetSetDef py_getsetters[];
  7475. static PyMethodDef tp_methods[];
  7476. static PyObject* getstate(PyObject* self, PyObject*) {
  7477. auto& opdef = reinterpret_cast<PyOp(Dot)*>(self)->inst();
  7478. static_cast<void>(opdef);
  7479. std::unordered_map<std::string, py::object> state {
  7480. };
  7481. return py::cast(state).release().ptr();
  7482. }
  7483. static PyObject* setstate(PyObject* self, PyObject* args) {
  7484. PyObject* dict = PyTuple_GetItem(args, 0);
  7485. if (!dict) return NULL;
  7486. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  7487. auto& opdef = reinterpret_cast<PyOp(Dot)*>(self)->inst();
  7488. static_cast<void>(opdef);
  7489. Py_RETURN_NONE;
  7490. }
  7491. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  7492. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  7493. static PyMethodDef py_init_methoddef;
  7494. // };
  7495. PyOpDefEnd(Dot)
  7496. int PyOp(Dot)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  7497. return 0;
  7498. }
  7499. PyGetSetDef PyOp(Dot)::py_getsetters[] = {
  7500. {NULL} /* Sentinel */
  7501. };
  7502. PyMethodDef PyOp(Dot)::tp_methods[] = {
  7503. {const_cast<char*>("__getstate__"), PyOp(Dot)::getstate, METH_NOARGS, "Dot getstate"},
  7504. {const_cast<char*>("__setstate__"), PyOp(Dot)::setstate, METH_VARARGS, "Dot setstate"},
  7505. {NULL} /* Sentinel */
  7506. };
  7507. PyObject *PyOp(Dot)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  7508. if (PyOp(Dot)::py_init(self, args, kwds) < 0) {
  7509. return NULL;
  7510. }
  7511. Py_RETURN_NONE;
  7512. }
  7513. PyMethodDef PyOp(Dot)::py_init_methoddef = {
  7514. "__init__",
  7515. (PyCFunction)PyOp(Dot)::py_init_proxy,
  7516. METH_VARARGS | METH_KEYWORDS,
  7517. "__init__(self) -> None\n"
  7518. };
  7519. void _init_py_Dot(py::module m) {
  7520. using py_op = PyOp(Dot);
  7521. auto& py_type = PyOpType(Dot);
  7522. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  7523. py_type.tp_name = "megengine.core._imperative_rt.ops.Dot";
  7524. py_type.tp_basicsize = sizeof(PyOp(Dot));
  7525. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  7526. py_type.tp_doc = "Dot";
  7527. py_type.tp_base = &PyOpType(OpDef);
  7528. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  7529. py_type.tp_new = py_new_generic<py_op>;
  7530. py_type.tp_init = py_op::py_init;
  7531. py_type.tp_methods = py_op::tp_methods;
  7532. py_type.tp_getset = py_op::py_getsetters;
  7533. py_type.tp_dict = PyDict_New();
  7534. PyObject* descr = PyDescr_NewMethod(&PyOpType(Dot), &PyOp(Dot)::py_init_methoddef);
  7535. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  7536. mgb_assert(PyType_Ready(&py_type) >= 0);
  7537. PyType_Modified(&py_type);
  7538. m.add_object("Dot", reinterpret_cast<PyObject*>(&py_type));
  7539. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Dot::typeinfo(), &py_type).second);
  7540. }
  7541. PyOpDefBegin(Dropout) // {
  7542. static PyGetSetDef py_getsetters[];
  7543. static PyMethodDef tp_methods[];
  7544. static PyObject* getstate(PyObject* self, PyObject*) {
  7545. auto& opdef = reinterpret_cast<PyOp(Dropout)*>(self)->inst();
  7546. static_cast<void>(opdef);
  7547. std::unordered_map<std::string, py::object> state {
  7548. {"drop_prob", serialization<decltype(opdef.drop_prob)>::dump(opdef.drop_prob)},
  7549. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  7550. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  7551. };
  7552. return py::cast(state).release().ptr();
  7553. }
  7554. static PyObject* setstate(PyObject* self, PyObject* args) {
  7555. PyObject* dict = PyTuple_GetItem(args, 0);
  7556. if (!dict) return NULL;
  7557. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  7558. auto& opdef = reinterpret_cast<PyOp(Dropout)*>(self)->inst();
  7559. static_cast<void>(opdef);
  7560. {
  7561. auto&& iter = state.find("drop_prob");
  7562. if (iter != state.end()) {
  7563. opdef.drop_prob = serialization<decltype(opdef.drop_prob)>::load(iter->second);
  7564. }
  7565. }
  7566. {
  7567. auto&& iter = state.find("seed");
  7568. if (iter != state.end()) {
  7569. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  7570. }
  7571. }
  7572. {
  7573. auto&& iter = state.find("handle");
  7574. if (iter != state.end()) {
  7575. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  7576. }
  7577. }
  7578. Py_RETURN_NONE;
  7579. }
  7580. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  7581. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  7582. static PyMethodDef py_init_methoddef;
  7583. // };
  7584. PyOpDefEnd(Dropout)
  7585. int PyOp(Dropout)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  7586. static const char* kwlist[] = {"drop_prob", "seed", "handle", "scope", NULL};
  7587. PyObject *drop_prob = NULL, *seed = NULL, *handle = NULL, *scope = NULL;
  7588. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &drop_prob, &seed, &handle, &scope))
  7589. return -1;
  7590. if (drop_prob) {
  7591. try {
  7592. // TODO: remove this guard which is used for pybind11 implicit conversion
  7593. py::detail::loader_life_support guard{};
  7594. reinterpret_cast<PyOp(Dropout)*>(self)->inst().drop_prob =
  7595. py::cast<decltype(Dropout::drop_prob)>(py::handle(drop_prob));
  7596. } CATCH_ALL(-1)
  7597. }
  7598. if (seed) {
  7599. try {
  7600. // TODO: remove this guard which is used for pybind11 implicit conversion
  7601. py::detail::loader_life_support guard{};
  7602. reinterpret_cast<PyOp(Dropout)*>(self)->inst().seed =
  7603. py::cast<decltype(Dropout::seed)>(py::handle(seed));
  7604. } CATCH_ALL(-1)
  7605. }
  7606. if (handle) {
  7607. try {
  7608. // TODO: remove this guard which is used for pybind11 implicit conversion
  7609. py::detail::loader_life_support guard{};
  7610. reinterpret_cast<PyOp(Dropout)*>(self)->inst().handle =
  7611. py::cast<decltype(Dropout::handle)>(py::handle(handle));
  7612. } CATCH_ALL(-1)
  7613. }
  7614. if (scope) {
  7615. try {
  7616. reinterpret_cast<PyOp(OpDef)*>(self)->op
  7617. ->set_scope(py::cast<std::string>(py::handle(scope)));
  7618. } CATCH_ALL(-1)
  7619. }
  7620. return 0;
  7621. }
  7622. PyGetSetDef PyOp(Dropout)::py_getsetters[] = {
  7623. {const_cast<char*>("drop_prob"), py_get_generic(Dropout, drop_prob), py_set_generic(Dropout, drop_prob), const_cast<char*>("drop_prob"), NULL},
  7624. {const_cast<char*>("seed"), py_get_generic(Dropout, seed), py_set_generic(Dropout, seed), const_cast<char*>("seed"), NULL},
  7625. {const_cast<char*>("handle"), py_get_generic(Dropout, handle), py_set_generic(Dropout, handle), const_cast<char*>("handle"), NULL},
  7626. {NULL} /* Sentinel */
  7627. };
  7628. PyMethodDef PyOp(Dropout)::tp_methods[] = {
  7629. {const_cast<char*>("__getstate__"), PyOp(Dropout)::getstate, METH_NOARGS, "Dropout getstate"},
  7630. {const_cast<char*>("__setstate__"), PyOp(Dropout)::setstate, METH_VARARGS, "Dropout setstate"},
  7631. {NULL} /* Sentinel */
  7632. };
  7633. PyObject *PyOp(Dropout)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  7634. if (PyOp(Dropout)::py_init(self, args, kwds) < 0) {
  7635. return NULL;
  7636. }
  7637. Py_RETURN_NONE;
  7638. }
  7639. PyMethodDef PyOp(Dropout)::py_init_methoddef = {
  7640. "__init__",
  7641. (PyCFunction)PyOp(Dropout)::py_init_proxy,
  7642. METH_VARARGS | METH_KEYWORDS,
  7643. "__init__(self, drop_prob: float = ..., seed: int = ..., handle: int = ...) -> None\n"
  7644. };
  7645. void _init_py_Dropout(py::module m) {
  7646. using py_op = PyOp(Dropout);
  7647. auto& py_type = PyOpType(Dropout);
  7648. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  7649. py_type.tp_name = "megengine.core._imperative_rt.ops.Dropout";
  7650. py_type.tp_basicsize = sizeof(PyOp(Dropout));
  7651. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  7652. py_type.tp_doc = "Dropout";
  7653. py_type.tp_base = &PyOpType(OpDef);
  7654. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  7655. py_type.tp_new = py_new_generic<py_op>;
  7656. py_type.tp_init = py_op::py_init;
  7657. py_type.tp_methods = py_op::tp_methods;
  7658. py_type.tp_getset = py_op::py_getsetters;
  7659. py_type.tp_dict = PyDict_New();
  7660. PyObject* descr = PyDescr_NewMethod(&PyOpType(Dropout), &PyOp(Dropout)::py_init_methoddef);
  7661. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  7662. mgb_assert(PyType_Ready(&py_type) >= 0);
  7663. PyType_Modified(&py_type);
  7664. m.add_object("Dropout", reinterpret_cast<PyObject*>(&py_type));
  7665. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Dropout::typeinfo(), &py_type).second);
  7666. }
  7667. template<> struct EnumTrait<Elemwise::Mode> {
  7668. static constexpr const char *name = "Elemwise.Mode";
  7669. static constexpr std::underlying_type_t<Elemwise::Mode> max = 64 - 1;
  7670. };
  7671. template<> PyTypeObject* EnumWrapper<Elemwise::Mode>::type = nullptr;
  7672. template<> const char*
  7673. EnumWrapper<Elemwise::Mode>::members[] = {"RELU", "ABS", "ACOS", "ASIN", "CEIL", "COS", "EXP", "EXPM1", "FLOOR", "LOG", "LOG1P", "NEGATE", "SIGMOID", "SIN", "TANH", "ABS_GRAD", "ADD", "FLOOR_DIV", "MAX", "MIN", "MOD", "MUL", "POW", "SIGMOID_GRAD", "SUB", "SWITCH_GT0", "TANH_GRAD", "TRUE_DIV", "LOG_SUM_EXP", "LT", "LEQ", "EQ", "SHL", "SHR", "COND_LEQ_MOV", "FUSE_MUL_ADD3", "FUSE_MUL_ADD4", "FUSE_ADD_RELU", "FUSE_ADD_SIGMOID", "FUSE_ADD_TANH", "FAST_TANH", "FAST_TANH_GRAD", "ROUND", "RMULH", "ATAN2", "ERF", "ERFINV", "ERFC", "ERFCINV", "H_SWISH", "H_SWISH_GRAD", "FUSE_ADD_H_SWISH", "NOT", "AND", "OR", "XOR", "SILU", "SILU_GRAD", "GELU", "GELU_GRAD", "COND_LT_MOV", "NEQ", "ISNAN", "ISINF"};
  7674. template<> std::unordered_map<std::string, Elemwise::Mode>
  7675. EnumWrapper<Elemwise::Mode>::mem2value = {{normalize_enum("RELU"), Elemwise::Mode::RELU}, {normalize_enum("ABS"), Elemwise::Mode::ABS}, {normalize_enum("ACOS"), Elemwise::Mode::ACOS}, {normalize_enum("ASIN"), Elemwise::Mode::ASIN}, {normalize_enum("CEIL"), Elemwise::Mode::CEIL}, {normalize_enum("COS"), Elemwise::Mode::COS}, {normalize_enum("EXP"), Elemwise::Mode::EXP}, {normalize_enum("EXPM1"), Elemwise::Mode::EXPM1}, {normalize_enum("FLOOR"), Elemwise::Mode::FLOOR}, {normalize_enum("LOG"), Elemwise::Mode::LOG}, {normalize_enum("LOG1P"), Elemwise::Mode::LOG1P}, {normalize_enum("NEGATE"), Elemwise::Mode::NEGATE}, {normalize_enum("SIGMOID"), Elemwise::Mode::SIGMOID}, {normalize_enum("SIN"), Elemwise::Mode::SIN}, {normalize_enum("TANH"), Elemwise::Mode::TANH}, {normalize_enum("ABS_GRAD"), Elemwise::Mode::ABS_GRAD}, {normalize_enum("ADD"), Elemwise::Mode::ADD}, {normalize_enum("FLOOR_DIV"), Elemwise::Mode::FLOOR_DIV}, {normalize_enum("MAX"), Elemwise::Mode::MAX}, {normalize_enum("MIN"), Elemwise::Mode::MIN}, {normalize_enum("MOD"), Elemwise::Mode::MOD}, {normalize_enum("MUL"), Elemwise::Mode::MUL}, {normalize_enum("POW"), Elemwise::Mode::POW}, {normalize_enum("SIGMOID_GRAD"), Elemwise::Mode::SIGMOID_GRAD}, {normalize_enum("SUB"), Elemwise::Mode::SUB}, {normalize_enum("SWITCH_GT0"), Elemwise::Mode::SWITCH_GT0}, {normalize_enum("TANH_GRAD"), Elemwise::Mode::TANH_GRAD}, {normalize_enum("TRUE_DIV"), Elemwise::Mode::TRUE_DIV}, {normalize_enum("LOG_SUM_EXP"), Elemwise::Mode::LOG_SUM_EXP}, {normalize_enum("LT"), Elemwise::Mode::LT}, {normalize_enum("LEQ"), Elemwise::Mode::LEQ}, {normalize_enum("EQ"), Elemwise::Mode::EQ}, {normalize_enum("SHL"), Elemwise::Mode::SHL}, {normalize_enum("SHR"), Elemwise::Mode::SHR}, {normalize_enum("COND_LEQ_MOV"), Elemwise::Mode::COND_LEQ_MOV}, {normalize_enum("FUSE_MUL_ADD3"), Elemwise::Mode::FUSE_MUL_ADD3}, {normalize_enum("FUSE_MUL_ADD4"), Elemwise::Mode::FUSE_MUL_ADD4}, {normalize_enum("FUSE_ADD_RELU"), Elemwise::Mode::FUSE_ADD_RELU}, {normalize_enum("FUSE_ADD_SIGMOID"), Elemwise::Mode::FUSE_ADD_SIGMOID}, {normalize_enum("FUSE_ADD_TANH"), Elemwise::Mode::FUSE_ADD_TANH}, {normalize_enum("FAST_TANH"), Elemwise::Mode::FAST_TANH}, {normalize_enum("FAST_TANH_GRAD"), Elemwise::Mode::FAST_TANH_GRAD}, {normalize_enum("ROUND"), Elemwise::Mode::ROUND}, {normalize_enum("RMULH"), Elemwise::Mode::RMULH}, {normalize_enum("ATAN2"), Elemwise::Mode::ATAN2}, {normalize_enum("ERF"), Elemwise::Mode::ERF}, {normalize_enum("ERFINV"), Elemwise::Mode::ERFINV}, {normalize_enum("ERFC"), Elemwise::Mode::ERFC}, {normalize_enum("ERFCINV"), Elemwise::Mode::ERFCINV}, {normalize_enum("H_SWISH"), Elemwise::Mode::H_SWISH}, {normalize_enum("H_SWISH_GRAD"), Elemwise::Mode::H_SWISH_GRAD}, {normalize_enum("FUSE_ADD_H_SWISH"), Elemwise::Mode::FUSE_ADD_H_SWISH}, {normalize_enum("NOT"), Elemwise::Mode::NOT}, {normalize_enum("AND"), Elemwise::Mode::AND}, {normalize_enum("OR"), Elemwise::Mode::OR}, {normalize_enum("XOR"), Elemwise::Mode::XOR}, {normalize_enum("SILU"), Elemwise::Mode::SILU}, {normalize_enum("SILU_GRAD"), Elemwise::Mode::SILU_GRAD}, {normalize_enum("GELU"), Elemwise::Mode::GELU}, {normalize_enum("GELU_GRAD"), Elemwise::Mode::GELU_GRAD}, {normalize_enum("COND_LT_MOV"), Elemwise::Mode::COND_LT_MOV}, {normalize_enum("NEQ"), Elemwise::Mode::NEQ}, {normalize_enum("ISNAN"), Elemwise::Mode::ISNAN}, {normalize_enum("ISINF"), Elemwise::Mode::ISINF}};
  7676. template<> PyObject* EnumWrapper<Elemwise::Mode>::pyobj_insts[64] = {nullptr};
  7677. void _init_py_Elemwise_Mode(PyTypeObject& py_type) {
  7678. auto& e_type = EnumWrapper<Elemwise::Mode>::type;
  7679. static PyMethodDef tp_methods[] = {
  7680. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Elemwise::Mode>::py_dump, METH_NOARGS, NULL},
  7681. {NULL} /* Sentinel */
  7682. };
  7683. static PyType_Slot slots[] = {
  7684. {Py_tp_repr, (void*)EnumWrapper<Elemwise::Mode>::py_repr},
  7685. {Py_tp_richcompare, (void*)EnumWrapper<Elemwise::Mode>::tp_richcompare},
  7686. {Py_tp_methods, tp_methods},
  7687. {0, NULL}
  7688. };
  7689. static PyType_Spec spec = {
  7690. // name
  7691. "megengine.core._imperative_rt.ops.Elemwise.Mode",
  7692. // basicsize
  7693. sizeof(EnumWrapper<Elemwise::Mode>),
  7694. // itemsize
  7695. 0,
  7696. // flags
  7697. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  7698. // slots
  7699. slots
  7700. };
  7701. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  7702. mgb_assert(
  7703. e_type->tp_setattro(
  7704. reinterpret_cast<PyObject*>(e_type),
  7705. py::cast("__name__").release().ptr(),
  7706. py::cast("Mode").release().ptr()) >= 0);
  7707. mgb_assert(
  7708. e_type->tp_setattro(
  7709. reinterpret_cast<PyObject*>(e_type),
  7710. py::cast("__module__").release().ptr(),
  7711. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  7712. mgb_assert(
  7713. e_type->tp_setattro(
  7714. reinterpret_cast<PyObject*>(e_type),
  7715. py::cast("__qualname__").release().ptr(),
  7716. py::cast("Elemwise.Mode").release().ptr()) >= 0);
  7717. {
  7718. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7719. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::RELU;
  7720. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RELU", inst) >= 0);
  7721. EnumWrapper<Elemwise::Mode>::pyobj_insts[0] = inst;
  7722. }{
  7723. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7724. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ABS;
  7725. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ABS", inst) >= 0);
  7726. EnumWrapper<Elemwise::Mode>::pyobj_insts[1] = inst;
  7727. }{
  7728. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7729. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ACOS;
  7730. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ACOS", inst) >= 0);
  7731. EnumWrapper<Elemwise::Mode>::pyobj_insts[2] = inst;
  7732. }{
  7733. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7734. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ASIN;
  7735. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ASIN", inst) >= 0);
  7736. EnumWrapper<Elemwise::Mode>::pyobj_insts[3] = inst;
  7737. }{
  7738. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7739. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::CEIL;
  7740. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CEIL", inst) >= 0);
  7741. EnumWrapper<Elemwise::Mode>::pyobj_insts[4] = inst;
  7742. }{
  7743. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7744. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::COS;
  7745. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "COS", inst) >= 0);
  7746. EnumWrapper<Elemwise::Mode>::pyobj_insts[5] = inst;
  7747. }{
  7748. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7749. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::EXP;
  7750. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "EXP", inst) >= 0);
  7751. EnumWrapper<Elemwise::Mode>::pyobj_insts[6] = inst;
  7752. }{
  7753. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7754. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::EXPM1;
  7755. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "EXPM1", inst) >= 0);
  7756. EnumWrapper<Elemwise::Mode>::pyobj_insts[7] = inst;
  7757. }{
  7758. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7759. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FLOOR;
  7760. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOOR", inst) >= 0);
  7761. EnumWrapper<Elemwise::Mode>::pyobj_insts[8] = inst;
  7762. }{
  7763. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7764. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LOG;
  7765. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LOG", inst) >= 0);
  7766. EnumWrapper<Elemwise::Mode>::pyobj_insts[9] = inst;
  7767. }{
  7768. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7769. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LOG1P;
  7770. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LOG1P", inst) >= 0);
  7771. EnumWrapper<Elemwise::Mode>::pyobj_insts[10] = inst;
  7772. }{
  7773. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7774. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::NEGATE;
  7775. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NEGATE", inst) >= 0);
  7776. EnumWrapper<Elemwise::Mode>::pyobj_insts[11] = inst;
  7777. }{
  7778. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7779. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SIGMOID;
  7780. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIGMOID", inst) >= 0);
  7781. EnumWrapper<Elemwise::Mode>::pyobj_insts[12] = inst;
  7782. }{
  7783. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7784. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SIN;
  7785. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIN", inst) >= 0);
  7786. EnumWrapper<Elemwise::Mode>::pyobj_insts[13] = inst;
  7787. }{
  7788. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7789. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::TANH;
  7790. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TANH", inst) >= 0);
  7791. EnumWrapper<Elemwise::Mode>::pyobj_insts[14] = inst;
  7792. }{
  7793. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7794. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ABS_GRAD;
  7795. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ABS_GRAD", inst) >= 0);
  7796. EnumWrapper<Elemwise::Mode>::pyobj_insts[15] = inst;
  7797. }{
  7798. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7799. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ADD;
  7800. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ADD", inst) >= 0);
  7801. EnumWrapper<Elemwise::Mode>::pyobj_insts[16] = inst;
  7802. }{
  7803. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7804. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FLOOR_DIV;
  7805. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOOR_DIV", inst) >= 0);
  7806. EnumWrapper<Elemwise::Mode>::pyobj_insts[17] = inst;
  7807. }{
  7808. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7809. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::MAX;
  7810. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0);
  7811. EnumWrapper<Elemwise::Mode>::pyobj_insts[18] = inst;
  7812. }{
  7813. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7814. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::MIN;
  7815. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MIN", inst) >= 0);
  7816. EnumWrapper<Elemwise::Mode>::pyobj_insts[19] = inst;
  7817. }{
  7818. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7819. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::MOD;
  7820. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MOD", inst) >= 0);
  7821. EnumWrapper<Elemwise::Mode>::pyobj_insts[20] = inst;
  7822. }{
  7823. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7824. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::MUL;
  7825. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MUL", inst) >= 0);
  7826. EnumWrapper<Elemwise::Mode>::pyobj_insts[21] = inst;
  7827. }{
  7828. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7829. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::POW;
  7830. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "POW", inst) >= 0);
  7831. EnumWrapper<Elemwise::Mode>::pyobj_insts[22] = inst;
  7832. }{
  7833. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7834. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SIGMOID_GRAD;
  7835. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIGMOID_GRAD", inst) >= 0);
  7836. EnumWrapper<Elemwise::Mode>::pyobj_insts[23] = inst;
  7837. }{
  7838. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7839. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SUB;
  7840. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SUB", inst) >= 0);
  7841. EnumWrapper<Elemwise::Mode>::pyobj_insts[24] = inst;
  7842. }{
  7843. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7844. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SWITCH_GT0;
  7845. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SWITCH_GT0", inst) >= 0);
  7846. EnumWrapper<Elemwise::Mode>::pyobj_insts[25] = inst;
  7847. }{
  7848. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7849. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::TANH_GRAD;
  7850. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TANH_GRAD", inst) >= 0);
  7851. EnumWrapper<Elemwise::Mode>::pyobj_insts[26] = inst;
  7852. }{
  7853. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7854. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::TRUE_DIV;
  7855. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TRUE_DIV", inst) >= 0);
  7856. EnumWrapper<Elemwise::Mode>::pyobj_insts[27] = inst;
  7857. }{
  7858. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7859. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LOG_SUM_EXP;
  7860. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LOG_SUM_EXP", inst) >= 0);
  7861. EnumWrapper<Elemwise::Mode>::pyobj_insts[28] = inst;
  7862. }{
  7863. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7864. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LT;
  7865. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LT", inst) >= 0);
  7866. EnumWrapper<Elemwise::Mode>::pyobj_insts[29] = inst;
  7867. }{
  7868. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7869. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LEQ;
  7870. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LEQ", inst) >= 0);
  7871. EnumWrapper<Elemwise::Mode>::pyobj_insts[30] = inst;
  7872. }{
  7873. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7874. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::EQ;
  7875. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "EQ", inst) >= 0);
  7876. EnumWrapper<Elemwise::Mode>::pyobj_insts[31] = inst;
  7877. }{
  7878. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7879. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SHL;
  7880. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SHL", inst) >= 0);
  7881. EnumWrapper<Elemwise::Mode>::pyobj_insts[32] = inst;
  7882. }{
  7883. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7884. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SHR;
  7885. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SHR", inst) >= 0);
  7886. EnumWrapper<Elemwise::Mode>::pyobj_insts[33] = inst;
  7887. }{
  7888. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7889. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::COND_LEQ_MOV;
  7890. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "COND_LEQ_MOV", inst) >= 0);
  7891. EnumWrapper<Elemwise::Mode>::pyobj_insts[34] = inst;
  7892. }{
  7893. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7894. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_MUL_ADD3;
  7895. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3", inst) >= 0);
  7896. EnumWrapper<Elemwise::Mode>::pyobj_insts[35] = inst;
  7897. }{
  7898. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7899. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_MUL_ADD4;
  7900. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD4", inst) >= 0);
  7901. EnumWrapper<Elemwise::Mode>::pyobj_insts[36] = inst;
  7902. }{
  7903. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7904. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_ADD_RELU;
  7905. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_RELU", inst) >= 0);
  7906. EnumWrapper<Elemwise::Mode>::pyobj_insts[37] = inst;
  7907. }{
  7908. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7909. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_ADD_SIGMOID;
  7910. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_SIGMOID", inst) >= 0);
  7911. EnumWrapper<Elemwise::Mode>::pyobj_insts[38] = inst;
  7912. }{
  7913. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7914. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_ADD_TANH;
  7915. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_TANH", inst) >= 0);
  7916. EnumWrapper<Elemwise::Mode>::pyobj_insts[39] = inst;
  7917. }{
  7918. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7919. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FAST_TANH;
  7920. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FAST_TANH", inst) >= 0);
  7921. EnumWrapper<Elemwise::Mode>::pyobj_insts[40] = inst;
  7922. }{
  7923. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7924. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FAST_TANH_GRAD;
  7925. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FAST_TANH_GRAD", inst) >= 0);
  7926. EnumWrapper<Elemwise::Mode>::pyobj_insts[41] = inst;
  7927. }{
  7928. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7929. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ROUND;
  7930. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ROUND", inst) >= 0);
  7931. EnumWrapper<Elemwise::Mode>::pyobj_insts[42] = inst;
  7932. }{
  7933. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7934. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::RMULH;
  7935. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RMULH", inst) >= 0);
  7936. EnumWrapper<Elemwise::Mode>::pyobj_insts[43] = inst;
  7937. }{
  7938. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7939. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ATAN2;
  7940. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ATAN2", inst) >= 0);
  7941. EnumWrapper<Elemwise::Mode>::pyobj_insts[44] = inst;
  7942. }{
  7943. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7944. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ERF;
  7945. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERF", inst) >= 0);
  7946. EnumWrapper<Elemwise::Mode>::pyobj_insts[45] = inst;
  7947. }{
  7948. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7949. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ERFINV;
  7950. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERFINV", inst) >= 0);
  7951. EnumWrapper<Elemwise::Mode>::pyobj_insts[46] = inst;
  7952. }{
  7953. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7954. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ERFC;
  7955. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERFC", inst) >= 0);
  7956. EnumWrapper<Elemwise::Mode>::pyobj_insts[47] = inst;
  7957. }{
  7958. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7959. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ERFCINV;
  7960. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERFCINV", inst) >= 0);
  7961. EnumWrapper<Elemwise::Mode>::pyobj_insts[48] = inst;
  7962. }{
  7963. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7964. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::H_SWISH;
  7965. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "H_SWISH", inst) >= 0);
  7966. EnumWrapper<Elemwise::Mode>::pyobj_insts[49] = inst;
  7967. }{
  7968. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7969. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::H_SWISH_GRAD;
  7970. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "H_SWISH_GRAD", inst) >= 0);
  7971. EnumWrapper<Elemwise::Mode>::pyobj_insts[50] = inst;
  7972. }{
  7973. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7974. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_ADD_H_SWISH;
  7975. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_H_SWISH", inst) >= 0);
  7976. EnumWrapper<Elemwise::Mode>::pyobj_insts[51] = inst;
  7977. }{
  7978. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7979. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::NOT;
  7980. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NOT", inst) >= 0);
  7981. EnumWrapper<Elemwise::Mode>::pyobj_insts[52] = inst;
  7982. }{
  7983. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7984. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::AND;
  7985. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AND", inst) >= 0);
  7986. EnumWrapper<Elemwise::Mode>::pyobj_insts[53] = inst;
  7987. }{
  7988. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7989. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::OR;
  7990. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "OR", inst) >= 0);
  7991. EnumWrapper<Elemwise::Mode>::pyobj_insts[54] = inst;
  7992. }{
  7993. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7994. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::XOR;
  7995. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "XOR", inst) >= 0);
  7996. EnumWrapper<Elemwise::Mode>::pyobj_insts[55] = inst;
  7997. }{
  7998. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7999. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SILU;
  8000. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SILU", inst) >= 0);
  8001. EnumWrapper<Elemwise::Mode>::pyobj_insts[56] = inst;
  8002. }{
  8003. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8004. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SILU_GRAD;
  8005. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SILU_GRAD", inst) >= 0);
  8006. EnumWrapper<Elemwise::Mode>::pyobj_insts[57] = inst;
  8007. }{
  8008. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8009. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::GELU;
  8010. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GELU", inst) >= 0);
  8011. EnumWrapper<Elemwise::Mode>::pyobj_insts[58] = inst;
  8012. }{
  8013. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8014. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::GELU_GRAD;
  8015. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GELU_GRAD", inst) >= 0);
  8016. EnumWrapper<Elemwise::Mode>::pyobj_insts[59] = inst;
  8017. }{
  8018. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8019. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::COND_LT_MOV;
  8020. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "COND_LT_MOV", inst) >= 0);
  8021. EnumWrapper<Elemwise::Mode>::pyobj_insts[60] = inst;
  8022. }{
  8023. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8024. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::NEQ;
  8025. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NEQ", inst) >= 0);
  8026. EnumWrapper<Elemwise::Mode>::pyobj_insts[61] = inst;
  8027. }{
  8028. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8029. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ISNAN;
  8030. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISNAN", inst) >= 0);
  8031. EnumWrapper<Elemwise::Mode>::pyobj_insts[62] = inst;
  8032. }{
  8033. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8034. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ISINF;
  8035. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISINF", inst) >= 0);
  8036. EnumWrapper<Elemwise::Mode>::pyobj_insts[63] = inst;
  8037. }
  8038. Py_INCREF(e_type);
  8039. mgb_assert(PyDict_SetItemString(
  8040. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  8041. }
  8042. PyOpDefBegin(Elemwise) // {
  8043. static PyGetSetDef py_getsetters[];
  8044. static PyMethodDef tp_methods[];
  8045. static PyObject* getstate(PyObject* self, PyObject*) {
  8046. auto& opdef = reinterpret_cast<PyOp(Elemwise)*>(self)->inst();
  8047. static_cast<void>(opdef);
  8048. std::unordered_map<std::string, py::object> state {
  8049. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)}
  8050. };
  8051. return py::cast(state).release().ptr();
  8052. }
  8053. static PyObject* setstate(PyObject* self, PyObject* args) {
  8054. PyObject* dict = PyTuple_GetItem(args, 0);
  8055. if (!dict) return NULL;
  8056. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8057. auto& opdef = reinterpret_cast<PyOp(Elemwise)*>(self)->inst();
  8058. static_cast<void>(opdef);
  8059. {
  8060. auto&& iter = state.find("mode");
  8061. if (iter != state.end()) {
  8062. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  8063. }
  8064. }
  8065. Py_RETURN_NONE;
  8066. }
  8067. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8068. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  8069. static PyMethodDef py_init_methoddef;
  8070. // };
  8071. PyOpDefEnd(Elemwise)
  8072. int PyOp(Elemwise)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8073. static const char* kwlist[] = {"mode", "scope", NULL};
  8074. PyObject *mode = NULL, *scope = NULL;
  8075. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &mode, &scope))
  8076. return -1;
  8077. if (mode) {
  8078. try {
  8079. // TODO: remove this guard which is used for pybind11 implicit conversion
  8080. py::detail::loader_life_support guard{};
  8081. reinterpret_cast<PyOp(Elemwise)*>(self)->inst().mode =
  8082. py::cast<decltype(Elemwise::mode)>(py::handle(mode));
  8083. } CATCH_ALL(-1)
  8084. }
  8085. if (scope) {
  8086. try {
  8087. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8088. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8089. } CATCH_ALL(-1)
  8090. }
  8091. return 0;
  8092. }
  8093. PyGetSetDef PyOp(Elemwise)::py_getsetters[] = {
  8094. {const_cast<char*>("mode"), py_get_generic(Elemwise, mode), py_set_generic(Elemwise, mode), const_cast<char*>("mode"), NULL},
  8095. {NULL} /* Sentinel */
  8096. };
  8097. PyMethodDef PyOp(Elemwise)::tp_methods[] = {
  8098. {const_cast<char*>("__getstate__"), PyOp(Elemwise)::getstate, METH_NOARGS, "Elemwise getstate"},
  8099. {const_cast<char*>("__setstate__"), PyOp(Elemwise)::setstate, METH_VARARGS, "Elemwise setstate"},
  8100. {NULL} /* Sentinel */
  8101. };
  8102. PyObject *PyOp(Elemwise)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  8103. if (PyOp(Elemwise)::py_init(self, args, kwds) < 0) {
  8104. return NULL;
  8105. }
  8106. Py_RETURN_NONE;
  8107. }
  8108. PyMethodDef PyOp(Elemwise)::py_init_methoddef = {
  8109. "__init__",
  8110. (PyCFunction)PyOp(Elemwise)::py_init_proxy,
  8111. METH_VARARGS | METH_KEYWORDS,
  8112. "__init__(self, mode: Union[str, Mode] = ...) -> None\n"
  8113. };
  8114. void _init_py_Elemwise(py::module m) {
  8115. using py_op = PyOp(Elemwise);
  8116. auto& py_type = PyOpType(Elemwise);
  8117. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8118. py_type.tp_name = "megengine.core._imperative_rt.ops.Elemwise";
  8119. py_type.tp_basicsize = sizeof(PyOp(Elemwise));
  8120. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8121. py_type.tp_doc = "Elemwise";
  8122. py_type.tp_base = &PyOpType(OpDef);
  8123. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8124. py_type.tp_new = py_new_generic<py_op>;
  8125. py_type.tp_init = py_op::py_init;
  8126. py_type.tp_methods = py_op::tp_methods;
  8127. py_type.tp_getset = py_op::py_getsetters;
  8128. py_type.tp_dict = PyDict_New();
  8129. PyObject* descr = PyDescr_NewMethod(&PyOpType(Elemwise), &PyOp(Elemwise)::py_init_methoddef);
  8130. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  8131. mgb_assert(PyType_Ready(&py_type) >= 0);
  8132. _init_py_Elemwise_Mode(py_type);
  8133. PyType_Modified(&py_type);
  8134. m.add_object("Elemwise", reinterpret_cast<PyObject*>(&py_type));
  8135. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Elemwise::typeinfo(), &py_type).second);
  8136. }
  8137. template<> struct EnumTrait<ElemwiseMultiType::Mode> {
  8138. static constexpr const char *name = "ElemwiseMultiType.Mode";
  8139. static constexpr std::underlying_type_t<ElemwiseMultiType::Mode> max = 64 - 1;
  8140. };
  8141. template<> PyTypeObject* EnumWrapper<ElemwiseMultiType::Mode>::type = nullptr;
  8142. template<> const char*
  8143. EnumWrapper<ElemwiseMultiType::Mode>::members[] = {"FUSE_MUL_ADD3_INT16x32x32x32", "FUSE_MUL_ADD3_IXxF32xF32xI8", "ROUND_SHR_SATURATE_IXxI8xI8", "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8", "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8", "ROUND_SHR_SATURATE_IXxI8xI16", "QADD", "QFUSE_ADD_RELU", "QMUL", "QMIN", "QMAX", "QSUB", "QTRUE_DIV", "QFUSE_ADD_SIGMOID", "QFUSE_ADD_TANH", "QRELU", "QABS", "QSIGMOID", "QEXP", "QTANH", "QFUSE_MUL_ADD3", "QFAST_TANH", "QNEGATE", "QACOS", "QASIN", "QCEIL", "QCOS", "QEXPM1", "QFLOOR", "QLOG", "QLOG1P", "QSIN", "QROUND", "QERF", "QERFINV", "QERFC", "QERFCINV", "QABS_GRAD", "QFLOOR_DIV", "QMOD", "QSIGMOID_GRAD", "QSWITCH_GT0", "QTANH_GRAD", "QLT", "QLEQ", "QEQ", "QPOW", "QLOG_SUM_EXP", "QFAST_TANH_GRAD", "QATAN2", "QCOND_LEQ_MOV", "QH_SWISH", "QFUSE_ADD_H_SWISH", "QH_SWISH_GRAD", "FUSE_MUL_ADD3_INT16xF32xF32xF32", "MUL_INT16xF32xF32", "FUSE_MUL_ADD3_UINT8xF32xF32xF32", "QCOND_LT_MOV", "EQ", "NEQ", "LT", "LEQ", "ISNAN", "ISINF"};
  8144. template<> std::unordered_map<std::string, ElemwiseMultiType::Mode>
  8145. EnumWrapper<ElemwiseMultiType::Mode>::mem2value = {{normalize_enum("FUSE_MUL_ADD3_INT16x32x32x32"), ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32}, {normalize_enum("FUSE_MUL_ADD3_IXxF32xF32xI8"), ElemwiseMultiType::Mode::FUSE_MUL_ADD3_IXxF32xF32xI8}, {normalize_enum("ROUND_SHR_SATURATE_IXxI8xI8"), ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI8}, {normalize_enum("FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8"), ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8}, {normalize_enum("FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8"), ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8}, {normalize_enum("ROUND_SHR_SATURATE_IXxI8xI16"), ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI16}, {normalize_enum("QADD"), ElemwiseMultiType::Mode::QADD}, {normalize_enum("QFUSE_ADD_RELU"), ElemwiseMultiType::Mode::QFUSE_ADD_RELU}, {normalize_enum("QMUL"), ElemwiseMultiType::Mode::QMUL}, {normalize_enum("QMIN"), ElemwiseMultiType::Mode::QMIN}, {normalize_enum("QMAX"), ElemwiseMultiType::Mode::QMAX}, {normalize_enum("QSUB"), ElemwiseMultiType::Mode::QSUB}, {normalize_enum("QTRUE_DIV"), ElemwiseMultiType::Mode::QTRUE_DIV}, {normalize_enum("QFUSE_ADD_SIGMOID"), ElemwiseMultiType::Mode::QFUSE_ADD_SIGMOID}, {normalize_enum("QFUSE_ADD_TANH"), ElemwiseMultiType::Mode::QFUSE_ADD_TANH}, {normalize_enum("QRELU"), ElemwiseMultiType::Mode::QRELU}, {normalize_enum("QABS"), ElemwiseMultiType::Mode::QABS}, {normalize_enum("QSIGMOID"), ElemwiseMultiType::Mode::QSIGMOID}, {normalize_enum("QEXP"), ElemwiseMultiType::Mode::QEXP}, {normalize_enum("QTANH"), ElemwiseMultiType::Mode::QTANH}, {normalize_enum("QFUSE_MUL_ADD3"), ElemwiseMultiType::Mode::QFUSE_MUL_ADD3}, {normalize_enum("QFAST_TANH"), ElemwiseMultiType::Mode::QFAST_TANH}, {normalize_enum("QNEGATE"), ElemwiseMultiType::Mode::QNEGATE}, {normalize_enum("QACOS"), ElemwiseMultiType::Mode::QACOS}, {normalize_enum("QASIN"), ElemwiseMultiType::Mode::QASIN}, {normalize_enum("QCEIL"), ElemwiseMultiType::Mode::QCEIL}, {normalize_enum("QCOS"), ElemwiseMultiType::Mode::QCOS}, {normalize_enum("QEXPM1"), ElemwiseMultiType::Mode::QEXPM1}, {normalize_enum("QFLOOR"), ElemwiseMultiType::Mode::QFLOOR}, {normalize_enum("QLOG"), ElemwiseMultiType::Mode::QLOG}, {normalize_enum("QLOG1P"), ElemwiseMultiType::Mode::QLOG1P}, {normalize_enum("QSIN"), ElemwiseMultiType::Mode::QSIN}, {normalize_enum("QROUND"), ElemwiseMultiType::Mode::QROUND}, {normalize_enum("QERF"), ElemwiseMultiType::Mode::QERF}, {normalize_enum("QERFINV"), ElemwiseMultiType::Mode::QERFINV}, {normalize_enum("QERFC"), ElemwiseMultiType::Mode::QERFC}, {normalize_enum("QERFCINV"), ElemwiseMultiType::Mode::QERFCINV}, {normalize_enum("QABS_GRAD"), ElemwiseMultiType::Mode::QABS_GRAD}, {normalize_enum("QFLOOR_DIV"), ElemwiseMultiType::Mode::QFLOOR_DIV}, {normalize_enum("QMOD"), ElemwiseMultiType::Mode::QMOD}, {normalize_enum("QSIGMOID_GRAD"), ElemwiseMultiType::Mode::QSIGMOID_GRAD}, {normalize_enum("QSWITCH_GT0"), ElemwiseMultiType::Mode::QSWITCH_GT0}, {normalize_enum("QTANH_GRAD"), ElemwiseMultiType::Mode::QTANH_GRAD}, {normalize_enum("QLT"), ElemwiseMultiType::Mode::QLT}, {normalize_enum("QLEQ"), ElemwiseMultiType::Mode::QLEQ}, {normalize_enum("QEQ"), ElemwiseMultiType::Mode::QEQ}, {normalize_enum("QPOW"), ElemwiseMultiType::Mode::QPOW}, {normalize_enum("QLOG_SUM_EXP"), ElemwiseMultiType::Mode::QLOG_SUM_EXP}, {normalize_enum("QFAST_TANH_GRAD"), ElemwiseMultiType::Mode::QFAST_TANH_GRAD}, {normalize_enum("QATAN2"), ElemwiseMultiType::Mode::QATAN2}, {normalize_enum("QCOND_LEQ_MOV"), ElemwiseMultiType::Mode::QCOND_LEQ_MOV}, {normalize_enum("QH_SWISH"), ElemwiseMultiType::Mode::QH_SWISH}, {normalize_enum("QFUSE_ADD_H_SWISH"), ElemwiseMultiType::Mode::QFUSE_ADD_H_SWISH}, {normalize_enum("QH_SWISH_GRAD"), ElemwiseMultiType::Mode::QH_SWISH_GRAD}, {normalize_enum("FUSE_MUL_ADD3_INT16xF32xF32xF32"), ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16xF32xF32xF32}, {normalize_enum("MUL_INT16xF32xF32"), ElemwiseMultiType::Mode::MUL_INT16xF32xF32}, {normalize_enum("FUSE_MUL_ADD3_UINT8xF32xF32xF32"), ElemwiseMultiType::Mode::FUSE_MUL_ADD3_UINT8xF32xF32xF32}, {normalize_enum("QCOND_LT_MOV"), ElemwiseMultiType::Mode::QCOND_LT_MOV}, {normalize_enum("EQ"), ElemwiseMultiType::Mode::EQ}, {normalize_enum("NEQ"), ElemwiseMultiType::Mode::NEQ}, {normalize_enum("LT"), ElemwiseMultiType::Mode::LT}, {normalize_enum("LEQ"), ElemwiseMultiType::Mode::LEQ}, {normalize_enum("ISNAN"), ElemwiseMultiType::Mode::ISNAN}, {normalize_enum("ISINF"), ElemwiseMultiType::Mode::ISINF}};
  8146. template<> PyObject* EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[64] = {nullptr};
  8147. void _init_py_ElemwiseMultiType_Mode(PyTypeObject& py_type) {
  8148. auto& e_type = EnumWrapper<ElemwiseMultiType::Mode>::type;
  8149. static PyMethodDef tp_methods[] = {
  8150. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<ElemwiseMultiType::Mode>::py_dump, METH_NOARGS, NULL},
  8151. {NULL} /* Sentinel */
  8152. };
  8153. static PyType_Slot slots[] = {
  8154. {Py_tp_repr, (void*)EnumWrapper<ElemwiseMultiType::Mode>::py_repr},
  8155. {Py_tp_richcompare, (void*)EnumWrapper<ElemwiseMultiType::Mode>::tp_richcompare},
  8156. {Py_tp_methods, tp_methods},
  8157. {0, NULL}
  8158. };
  8159. static PyType_Spec spec = {
  8160. // name
  8161. "megengine.core._imperative_rt.ops.ElemwiseMultiType.Mode",
  8162. // basicsize
  8163. sizeof(EnumWrapper<ElemwiseMultiType::Mode>),
  8164. // itemsize
  8165. 0,
  8166. // flags
  8167. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  8168. // slots
  8169. slots
  8170. };
  8171. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  8172. mgb_assert(
  8173. e_type->tp_setattro(
  8174. reinterpret_cast<PyObject*>(e_type),
  8175. py::cast("__name__").release().ptr(),
  8176. py::cast("Mode").release().ptr()) >= 0);
  8177. mgb_assert(
  8178. e_type->tp_setattro(
  8179. reinterpret_cast<PyObject*>(e_type),
  8180. py::cast("__module__").release().ptr(),
  8181. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  8182. mgb_assert(
  8183. e_type->tp_setattro(
  8184. reinterpret_cast<PyObject*>(e_type),
  8185. py::cast("__qualname__").release().ptr(),
  8186. py::cast("ElemwiseMultiType.Mode").release().ptr()) >= 0);
  8187. {
  8188. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8189. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32;
  8190. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_INT16x32x32x32", inst) >= 0);
  8191. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[0] = inst;
  8192. }{
  8193. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8194. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_IXxF32xF32xI8;
  8195. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_IXxF32xF32xI8", inst) >= 0);
  8196. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[1] = inst;
  8197. }{
  8198. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8199. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI8;
  8200. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ROUND_SHR_SATURATE_IXxI8xI8", inst) >= 0);
  8201. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[2] = inst;
  8202. }{
  8203. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8204. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8;
  8205. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8", inst) >= 0);
  8206. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[3] = inst;
  8207. }{
  8208. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8209. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8;
  8210. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8", inst) >= 0);
  8211. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[4] = inst;
  8212. }{
  8213. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8214. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI16;
  8215. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ROUND_SHR_SATURATE_IXxI8xI16", inst) >= 0);
  8216. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[5] = inst;
  8217. }{
  8218. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8219. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QADD;
  8220. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QADD", inst) >= 0);
  8221. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[6] = inst;
  8222. }{
  8223. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8224. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_RELU;
  8225. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_RELU", inst) >= 0);
  8226. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[7] = inst;
  8227. }{
  8228. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8229. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QMUL;
  8230. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMUL", inst) >= 0);
  8231. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[8] = inst;
  8232. }{
  8233. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8234. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QMIN;
  8235. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMIN", inst) >= 0);
  8236. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[9] = inst;
  8237. }{
  8238. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8239. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QMAX;
  8240. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMAX", inst) >= 0);
  8241. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[10] = inst;
  8242. }{
  8243. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8244. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QSUB;
  8245. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSUB", inst) >= 0);
  8246. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[11] = inst;
  8247. }{
  8248. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8249. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QTRUE_DIV;
  8250. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QTRUE_DIV", inst) >= 0);
  8251. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[12] = inst;
  8252. }{
  8253. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8254. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_SIGMOID;
  8255. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_SIGMOID", inst) >= 0);
  8256. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[13] = inst;
  8257. }{
  8258. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8259. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_TANH;
  8260. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_TANH", inst) >= 0);
  8261. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[14] = inst;
  8262. }{
  8263. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8264. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QRELU;
  8265. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QRELU", inst) >= 0);
  8266. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[15] = inst;
  8267. }{
  8268. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8269. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QABS;
  8270. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QABS", inst) >= 0);
  8271. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[16] = inst;
  8272. }{
  8273. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8274. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QSIGMOID;
  8275. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSIGMOID", inst) >= 0);
  8276. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[17] = inst;
  8277. }{
  8278. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8279. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QEXP;
  8280. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QEXP", inst) >= 0);
  8281. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[18] = inst;
  8282. }{
  8283. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8284. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QTANH;
  8285. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QTANH", inst) >= 0);
  8286. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[19] = inst;
  8287. }{
  8288. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8289. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_MUL_ADD3;
  8290. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_MUL_ADD3", inst) >= 0);
  8291. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[20] = inst;
  8292. }{
  8293. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8294. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFAST_TANH;
  8295. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFAST_TANH", inst) >= 0);
  8296. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[21] = inst;
  8297. }{
  8298. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8299. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QNEGATE;
  8300. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QNEGATE", inst) >= 0);
  8301. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[22] = inst;
  8302. }{
  8303. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8304. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QACOS;
  8305. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QACOS", inst) >= 0);
  8306. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[23] = inst;
  8307. }{
  8308. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8309. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QASIN;
  8310. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QASIN", inst) >= 0);
  8311. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[24] = inst;
  8312. }{
  8313. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8314. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QCEIL;
  8315. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCEIL", inst) >= 0);
  8316. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[25] = inst;
  8317. }{
  8318. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8319. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QCOS;
  8320. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCOS", inst) >= 0);
  8321. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[26] = inst;
  8322. }{
  8323. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8324. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QEXPM1;
  8325. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QEXPM1", inst) >= 0);
  8326. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[27] = inst;
  8327. }{
  8328. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8329. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFLOOR;
  8330. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFLOOR", inst) >= 0);
  8331. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[28] = inst;
  8332. }{
  8333. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8334. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QLOG;
  8335. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLOG", inst) >= 0);
  8336. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[29] = inst;
  8337. }{
  8338. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8339. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QLOG1P;
  8340. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLOG1P", inst) >= 0);
  8341. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[30] = inst;
  8342. }{
  8343. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8344. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QSIN;
  8345. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSIN", inst) >= 0);
  8346. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[31] = inst;
  8347. }{
  8348. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8349. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QROUND;
  8350. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QROUND", inst) >= 0);
  8351. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[32] = inst;
  8352. }{
  8353. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8354. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QERF;
  8355. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERF", inst) >= 0);
  8356. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[33] = inst;
  8357. }{
  8358. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8359. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QERFINV;
  8360. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERFINV", inst) >= 0);
  8361. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[34] = inst;
  8362. }{
  8363. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8364. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QERFC;
  8365. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERFC", inst) >= 0);
  8366. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[35] = inst;
  8367. }{
  8368. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8369. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QERFCINV;
  8370. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERFCINV", inst) >= 0);
  8371. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[36] = inst;
  8372. }{
  8373. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8374. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QABS_GRAD;
  8375. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QABS_GRAD", inst) >= 0);
  8376. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[37] = inst;
  8377. }{
  8378. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8379. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFLOOR_DIV;
  8380. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFLOOR_DIV", inst) >= 0);
  8381. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[38] = inst;
  8382. }{
  8383. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8384. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QMOD;
  8385. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMOD", inst) >= 0);
  8386. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[39] = inst;
  8387. }{
  8388. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8389. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QSIGMOID_GRAD;
  8390. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSIGMOID_GRAD", inst) >= 0);
  8391. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[40] = inst;
  8392. }{
  8393. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8394. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QSWITCH_GT0;
  8395. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSWITCH_GT0", inst) >= 0);
  8396. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[41] = inst;
  8397. }{
  8398. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8399. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QTANH_GRAD;
  8400. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QTANH_GRAD", inst) >= 0);
  8401. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[42] = inst;
  8402. }{
  8403. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8404. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QLT;
  8405. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLT", inst) >= 0);
  8406. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[43] = inst;
  8407. }{
  8408. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8409. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QLEQ;
  8410. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLEQ", inst) >= 0);
  8411. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[44] = inst;
  8412. }{
  8413. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8414. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QEQ;
  8415. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QEQ", inst) >= 0);
  8416. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[45] = inst;
  8417. }{
  8418. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8419. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QPOW;
  8420. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QPOW", inst) >= 0);
  8421. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[46] = inst;
  8422. }{
  8423. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8424. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QLOG_SUM_EXP;
  8425. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLOG_SUM_EXP", inst) >= 0);
  8426. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[47] = inst;
  8427. }{
  8428. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8429. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFAST_TANH_GRAD;
  8430. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFAST_TANH_GRAD", inst) >= 0);
  8431. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[48] = inst;
  8432. }{
  8433. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8434. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QATAN2;
  8435. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QATAN2", inst) >= 0);
  8436. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[49] = inst;
  8437. }{
  8438. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8439. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QCOND_LEQ_MOV;
  8440. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCOND_LEQ_MOV", inst) >= 0);
  8441. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[50] = inst;
  8442. }{
  8443. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8444. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QH_SWISH;
  8445. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QH_SWISH", inst) >= 0);
  8446. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[51] = inst;
  8447. }{
  8448. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8449. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_H_SWISH;
  8450. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_H_SWISH", inst) >= 0);
  8451. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[52] = inst;
  8452. }{
  8453. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8454. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QH_SWISH_GRAD;
  8455. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QH_SWISH_GRAD", inst) >= 0);
  8456. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[53] = inst;
  8457. }{
  8458. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8459. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16xF32xF32xF32;
  8460. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_INT16xF32xF32xF32", inst) >= 0);
  8461. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[54] = inst;
  8462. }{
  8463. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8464. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::MUL_INT16xF32xF32;
  8465. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MUL_INT16xF32xF32", inst) >= 0);
  8466. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[55] = inst;
  8467. }{
  8468. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8469. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_UINT8xF32xF32xF32;
  8470. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_UINT8xF32xF32xF32", inst) >= 0);
  8471. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[56] = inst;
  8472. }{
  8473. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8474. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QCOND_LT_MOV;
  8475. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCOND_LT_MOV", inst) >= 0);
  8476. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[57] = inst;
  8477. }{
  8478. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8479. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::EQ;
  8480. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "EQ", inst) >= 0);
  8481. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[58] = inst;
  8482. }{
  8483. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8484. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::NEQ;
  8485. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NEQ", inst) >= 0);
  8486. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[59] = inst;
  8487. }{
  8488. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8489. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::LT;
  8490. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LT", inst) >= 0);
  8491. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[60] = inst;
  8492. }{
  8493. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8494. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::LEQ;
  8495. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LEQ", inst) >= 0);
  8496. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[61] = inst;
  8497. }{
  8498. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8499. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::ISNAN;
  8500. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISNAN", inst) >= 0);
  8501. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[62] = inst;
  8502. }{
  8503. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8504. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::ISINF;
  8505. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISINF", inst) >= 0);
  8506. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[63] = inst;
  8507. }
  8508. Py_INCREF(e_type);
  8509. mgb_assert(PyDict_SetItemString(
  8510. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  8511. }
  8512. PyOpDefBegin(ElemwiseMultiType) // {
  8513. static PyGetSetDef py_getsetters[];
  8514. static PyMethodDef tp_methods[];
  8515. static PyObject* getstate(PyObject* self, PyObject*) {
  8516. auto& opdef = reinterpret_cast<PyOp(ElemwiseMultiType)*>(self)->inst();
  8517. static_cast<void>(opdef);
  8518. std::unordered_map<std::string, py::object> state {
  8519. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  8520. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)}
  8521. };
  8522. return py::cast(state).release().ptr();
  8523. }
  8524. static PyObject* setstate(PyObject* self, PyObject* args) {
  8525. PyObject* dict = PyTuple_GetItem(args, 0);
  8526. if (!dict) return NULL;
  8527. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8528. auto& opdef = reinterpret_cast<PyOp(ElemwiseMultiType)*>(self)->inst();
  8529. static_cast<void>(opdef);
  8530. {
  8531. auto&& iter = state.find("mode");
  8532. if (iter != state.end()) {
  8533. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  8534. }
  8535. }
  8536. {
  8537. auto&& iter = state.find("dtype");
  8538. if (iter != state.end()) {
  8539. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  8540. }
  8541. }
  8542. Py_RETURN_NONE;
  8543. }
  8544. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8545. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  8546. static PyMethodDef py_init_methoddef;
  8547. // };
  8548. PyOpDefEnd(ElemwiseMultiType)
  8549. int PyOp(ElemwiseMultiType)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8550. static const char* kwlist[] = {"mode", "dtype", "scope", NULL};
  8551. PyObject *mode = NULL, *dtype = NULL, *scope = NULL;
  8552. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &mode, &dtype, &scope))
  8553. return -1;
  8554. if (mode) {
  8555. try {
  8556. // TODO: remove this guard which is used for pybind11 implicit conversion
  8557. py::detail::loader_life_support guard{};
  8558. reinterpret_cast<PyOp(ElemwiseMultiType)*>(self)->inst().mode =
  8559. py::cast<decltype(ElemwiseMultiType::mode)>(py::handle(mode));
  8560. } CATCH_ALL(-1)
  8561. }
  8562. if (dtype) {
  8563. try {
  8564. // TODO: remove this guard which is used for pybind11 implicit conversion
  8565. py::detail::loader_life_support guard{};
  8566. reinterpret_cast<PyOp(ElemwiseMultiType)*>(self)->inst().dtype =
  8567. py::cast<decltype(ElemwiseMultiType::dtype)>(py::handle(dtype));
  8568. } CATCH_ALL(-1)
  8569. }
  8570. if (scope) {
  8571. try {
  8572. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8573. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8574. } CATCH_ALL(-1)
  8575. }
  8576. return 0;
  8577. }
  8578. PyGetSetDef PyOp(ElemwiseMultiType)::py_getsetters[] = {
  8579. {const_cast<char*>("mode"), py_get_generic(ElemwiseMultiType, mode), py_set_generic(ElemwiseMultiType, mode), const_cast<char*>("mode"), NULL},
  8580. {const_cast<char*>("dtype"), py_get_generic(ElemwiseMultiType, dtype), py_set_generic(ElemwiseMultiType, dtype), const_cast<char*>("dtype"), NULL},
  8581. {NULL} /* Sentinel */
  8582. };
  8583. PyMethodDef PyOp(ElemwiseMultiType)::tp_methods[] = {
  8584. {const_cast<char*>("__getstate__"), PyOp(ElemwiseMultiType)::getstate, METH_NOARGS, "ElemwiseMultiType getstate"},
  8585. {const_cast<char*>("__setstate__"), PyOp(ElemwiseMultiType)::setstate, METH_VARARGS, "ElemwiseMultiType setstate"},
  8586. {NULL} /* Sentinel */
  8587. };
  8588. PyObject *PyOp(ElemwiseMultiType)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  8589. if (PyOp(ElemwiseMultiType)::py_init(self, args, kwds) < 0) {
  8590. return NULL;
  8591. }
  8592. Py_RETURN_NONE;
  8593. }
  8594. PyMethodDef PyOp(ElemwiseMultiType)::py_init_methoddef = {
  8595. "__init__",
  8596. (PyCFunction)PyOp(ElemwiseMultiType)::py_init_proxy,
  8597. METH_VARARGS | METH_KEYWORDS,
  8598. "__init__(self, mode: Union[str, Mode] = ..., dtype: str = ...) -> None\n"
  8599. };
  8600. void _init_py_ElemwiseMultiType(py::module m) {
  8601. using py_op = PyOp(ElemwiseMultiType);
  8602. auto& py_type = PyOpType(ElemwiseMultiType);
  8603. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8604. py_type.tp_name = "megengine.core._imperative_rt.ops.ElemwiseMultiType";
  8605. py_type.tp_basicsize = sizeof(PyOp(ElemwiseMultiType));
  8606. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8607. py_type.tp_doc = "ElemwiseMultiType";
  8608. py_type.tp_base = &PyOpType(OpDef);
  8609. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8610. py_type.tp_new = py_new_generic<py_op>;
  8611. py_type.tp_init = py_op::py_init;
  8612. py_type.tp_methods = py_op::tp_methods;
  8613. py_type.tp_getset = py_op::py_getsetters;
  8614. py_type.tp_dict = PyDict_New();
  8615. PyObject* descr = PyDescr_NewMethod(&PyOpType(ElemwiseMultiType), &PyOp(ElemwiseMultiType)::py_init_methoddef);
  8616. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  8617. mgb_assert(PyType_Ready(&py_type) >= 0);
  8618. _init_py_ElemwiseMultiType_Mode(py_type);
  8619. PyType_Modified(&py_type);
  8620. m.add_object("ElemwiseMultiType", reinterpret_cast<PyObject*>(&py_type));
  8621. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ElemwiseMultiType::typeinfo(), &py_type).second);
  8622. }
  8623. PyOpDefBegin(ExternOpr) // {
  8624. static PyGetSetDef py_getsetters[];
  8625. static PyMethodDef tp_methods[];
  8626. static PyObject* getstate(PyObject* self, PyObject*) {
  8627. auto& opdef = reinterpret_cast<PyOp(ExternOpr)*>(self)->inst();
  8628. static_cast<void>(opdef);
  8629. std::unordered_map<std::string, py::object> state {
  8630. {"output_shapes", serialization<decltype(opdef.output_shapes)>::dump(opdef.output_shapes)},
  8631. {"name", serialization<decltype(opdef.name)>::dump(opdef.name)},
  8632. {"data", serialization<decltype(opdef.data)>::dump(opdef.data)},
  8633. {"data_len", serialization<decltype(opdef.data_len)>::dump(opdef.data_len)},
  8634. {"output_dtypes", serialization<decltype(opdef.output_dtypes)>::dump(opdef.output_dtypes)}
  8635. };
  8636. return py::cast(state).release().ptr();
  8637. }
  8638. static PyObject* setstate(PyObject* self, PyObject* args) {
  8639. PyObject* dict = PyTuple_GetItem(args, 0);
  8640. if (!dict) return NULL;
  8641. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8642. auto& opdef = reinterpret_cast<PyOp(ExternOpr)*>(self)->inst();
  8643. static_cast<void>(opdef);
  8644. {
  8645. auto&& iter = state.find("output_shapes");
  8646. if (iter != state.end()) {
  8647. opdef.output_shapes = serialization<decltype(opdef.output_shapes)>::load(iter->second);
  8648. }
  8649. }
  8650. {
  8651. auto&& iter = state.find("name");
  8652. if (iter != state.end()) {
  8653. opdef.name = serialization<decltype(opdef.name)>::load(iter->second);
  8654. }
  8655. }
  8656. {
  8657. auto&& iter = state.find("data");
  8658. if (iter != state.end()) {
  8659. opdef.data = serialization<decltype(opdef.data)>::load(iter->second);
  8660. }
  8661. }
  8662. {
  8663. auto&& iter = state.find("data_len");
  8664. if (iter != state.end()) {
  8665. opdef.data_len = serialization<decltype(opdef.data_len)>::load(iter->second);
  8666. }
  8667. }
  8668. {
  8669. auto&& iter = state.find("output_dtypes");
  8670. if (iter != state.end()) {
  8671. opdef.output_dtypes = serialization<decltype(opdef.output_dtypes)>::load(iter->second);
  8672. }
  8673. }
  8674. Py_RETURN_NONE;
  8675. }
  8676. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8677. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  8678. static PyMethodDef py_init_methoddef;
  8679. // };
  8680. PyOpDefEnd(ExternOpr)
  8681. int PyOp(ExternOpr)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8682. static const char* kwlist[] = {"output_shapes", "name", "data", "data_len", "output_dtypes", "scope", NULL};
  8683. PyObject *output_shapes = NULL, *name = NULL, *data = NULL, *data_len = NULL, *output_dtypes = NULL, *scope = NULL;
  8684. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOO", const_cast<char**>(kwlist), &output_shapes, &name, &data, &data_len, &output_dtypes, &scope))
  8685. return -1;
  8686. if (output_shapes) {
  8687. try {
  8688. // TODO: remove this guard which is used for pybind11 implicit conversion
  8689. py::detail::loader_life_support guard{};
  8690. reinterpret_cast<PyOp(ExternOpr)*>(self)->inst().output_shapes =
  8691. py::cast<decltype(ExternOpr::output_shapes)>(py::handle(output_shapes));
  8692. } CATCH_ALL(-1)
  8693. }
  8694. if (name) {
  8695. try {
  8696. // TODO: remove this guard which is used for pybind11 implicit conversion
  8697. py::detail::loader_life_support guard{};
  8698. reinterpret_cast<PyOp(ExternOpr)*>(self)->inst().name =
  8699. py::cast<decltype(ExternOpr::name)>(py::handle(name));
  8700. } CATCH_ALL(-1)
  8701. }
  8702. if (data) {
  8703. try {
  8704. // TODO: remove this guard which is used for pybind11 implicit conversion
  8705. py::detail::loader_life_support guard{};
  8706. reinterpret_cast<PyOp(ExternOpr)*>(self)->inst().data =
  8707. py::cast<decltype(ExternOpr::data)>(py::handle(data));
  8708. } CATCH_ALL(-1)
  8709. }
  8710. if (data_len) {
  8711. try {
  8712. // TODO: remove this guard which is used for pybind11 implicit conversion
  8713. py::detail::loader_life_support guard{};
  8714. reinterpret_cast<PyOp(ExternOpr)*>(self)->inst().data_len =
  8715. py::cast<decltype(ExternOpr::data_len)>(py::handle(data_len));
  8716. } CATCH_ALL(-1)
  8717. }
  8718. if (output_dtypes) {
  8719. try {
  8720. // TODO: remove this guard which is used for pybind11 implicit conversion
  8721. py::detail::loader_life_support guard{};
  8722. reinterpret_cast<PyOp(ExternOpr)*>(self)->inst().output_dtypes =
  8723. py::cast<decltype(ExternOpr::output_dtypes)>(py::handle(output_dtypes));
  8724. } CATCH_ALL(-1)
  8725. }
  8726. if (scope) {
  8727. try {
  8728. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8729. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8730. } CATCH_ALL(-1)
  8731. }
  8732. return 0;
  8733. }
  8734. PyGetSetDef PyOp(ExternOpr)::py_getsetters[] = {
  8735. {const_cast<char*>("output_shapes"), py_get_generic(ExternOpr, output_shapes), py_set_generic(ExternOpr, output_shapes), const_cast<char*>("output_shapes"), NULL},
  8736. {const_cast<char*>("name"), py_get_generic(ExternOpr, name), py_set_generic(ExternOpr, name), const_cast<char*>("name"), NULL},
  8737. {const_cast<char*>("data"), py_get_generic(ExternOpr, data), py_set_generic(ExternOpr, data), const_cast<char*>("data"), NULL},
  8738. {const_cast<char*>("data_len"), py_get_generic(ExternOpr, data_len), py_set_generic(ExternOpr, data_len), const_cast<char*>("data_len"), NULL},
  8739. {const_cast<char*>("output_dtypes"), py_get_generic(ExternOpr, output_dtypes), py_set_generic(ExternOpr, output_dtypes), const_cast<char*>("output_dtypes"), NULL},
  8740. {NULL} /* Sentinel */
  8741. };
  8742. PyMethodDef PyOp(ExternOpr)::tp_methods[] = {
  8743. {const_cast<char*>("__getstate__"), PyOp(ExternOpr)::getstate, METH_NOARGS, "ExternOpr getstate"},
  8744. {const_cast<char*>("__setstate__"), PyOp(ExternOpr)::setstate, METH_VARARGS, "ExternOpr setstate"},
  8745. {NULL} /* Sentinel */
  8746. };
  8747. PyObject *PyOp(ExternOpr)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  8748. if (PyOp(ExternOpr)::py_init(self, args, kwds) < 0) {
  8749. return NULL;
  8750. }
  8751. Py_RETURN_NONE;
  8752. }
  8753. PyMethodDef PyOp(ExternOpr)::py_init_methoddef = {
  8754. "__init__",
  8755. (PyCFunction)PyOp(ExternOpr)::py_init_proxy,
  8756. METH_VARARGS | METH_KEYWORDS,
  8757. "__init__(self, output_shapes: list[list[int]] = ..., name: str = ..., data: str = ..., data_len: int = ..., output_dtypes: list[str] = ...) -> None\n"
  8758. };
  8759. void _init_py_ExternOpr(py::module m) {
  8760. using py_op = PyOp(ExternOpr);
  8761. auto& py_type = PyOpType(ExternOpr);
  8762. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8763. py_type.tp_name = "megengine.core._imperative_rt.ops.ExternOpr";
  8764. py_type.tp_basicsize = sizeof(PyOp(ExternOpr));
  8765. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8766. py_type.tp_doc = "ExternOpr";
  8767. py_type.tp_base = &PyOpType(OpDef);
  8768. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8769. py_type.tp_new = py_new_generic<py_op>;
  8770. py_type.tp_init = py_op::py_init;
  8771. py_type.tp_methods = py_op::tp_methods;
  8772. py_type.tp_getset = py_op::py_getsetters;
  8773. py_type.tp_dict = PyDict_New();
  8774. PyObject* descr = PyDescr_NewMethod(&PyOpType(ExternOpr), &PyOp(ExternOpr)::py_init_methoddef);
  8775. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  8776. mgb_assert(PyType_Ready(&py_type) >= 0);
  8777. PyType_Modified(&py_type);
  8778. m.add_object("ExternOpr", reinterpret_cast<PyObject*>(&py_type));
  8779. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ExternOpr::typeinfo(), &py_type).second);
  8780. }
  8781. PyOpDefBegin(Eye) // {
  8782. static PyGetSetDef py_getsetters[];
  8783. static PyMethodDef tp_methods[];
  8784. static PyObject* getstate(PyObject* self, PyObject*) {
  8785. auto& opdef = reinterpret_cast<PyOp(Eye)*>(self)->inst();
  8786. static_cast<void>(opdef);
  8787. std::unordered_map<std::string, py::object> state {
  8788. {"k", serialization<decltype(opdef.k)>::dump(opdef.k)},
  8789. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  8790. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)}
  8791. };
  8792. return py::cast(state).release().ptr();
  8793. }
  8794. static PyObject* setstate(PyObject* self, PyObject* args) {
  8795. PyObject* dict = PyTuple_GetItem(args, 0);
  8796. if (!dict) return NULL;
  8797. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8798. auto& opdef = reinterpret_cast<PyOp(Eye)*>(self)->inst();
  8799. static_cast<void>(opdef);
  8800. {
  8801. auto&& iter = state.find("k");
  8802. if (iter != state.end()) {
  8803. opdef.k = serialization<decltype(opdef.k)>::load(iter->second);
  8804. }
  8805. }
  8806. {
  8807. auto&& iter = state.find("dtype");
  8808. if (iter != state.end()) {
  8809. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  8810. }
  8811. }
  8812. {
  8813. auto&& iter = state.find("comp_node");
  8814. if (iter != state.end()) {
  8815. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  8816. }
  8817. }
  8818. Py_RETURN_NONE;
  8819. }
  8820. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8821. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  8822. static PyMethodDef py_init_methoddef;
  8823. // };
  8824. PyOpDefEnd(Eye)
  8825. int PyOp(Eye)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8826. static const char* kwlist[] = {"k", "dtype", "comp_node", "scope", NULL};
  8827. PyObject *k = NULL, *dtype = NULL, *comp_node = NULL, *scope = NULL;
  8828. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &k, &dtype, &comp_node, &scope))
  8829. return -1;
  8830. if (k) {
  8831. try {
  8832. // TODO: remove this guard which is used for pybind11 implicit conversion
  8833. py::detail::loader_life_support guard{};
  8834. reinterpret_cast<PyOp(Eye)*>(self)->inst().k =
  8835. py::cast<decltype(Eye::k)>(py::handle(k));
  8836. } CATCH_ALL(-1)
  8837. }
  8838. if (dtype) {
  8839. try {
  8840. // TODO: remove this guard which is used for pybind11 implicit conversion
  8841. py::detail::loader_life_support guard{};
  8842. reinterpret_cast<PyOp(Eye)*>(self)->inst().dtype =
  8843. py::cast<decltype(Eye::dtype)>(py::handle(dtype));
  8844. } CATCH_ALL(-1)
  8845. }
  8846. if (comp_node) {
  8847. try {
  8848. // TODO: remove this guard which is used for pybind11 implicit conversion
  8849. py::detail::loader_life_support guard{};
  8850. reinterpret_cast<PyOp(Eye)*>(self)->inst().comp_node =
  8851. py::cast<decltype(Eye::comp_node)>(py::handle(comp_node));
  8852. } CATCH_ALL(-1)
  8853. }
  8854. if (scope) {
  8855. try {
  8856. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8857. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8858. } CATCH_ALL(-1)
  8859. }
  8860. return 0;
  8861. }
  8862. PyGetSetDef PyOp(Eye)::py_getsetters[] = {
  8863. {const_cast<char*>("k"), py_get_generic(Eye, k), py_set_generic(Eye, k), const_cast<char*>("k"), NULL},
  8864. {const_cast<char*>("dtype"), py_get_generic(Eye, dtype), py_set_generic(Eye, dtype), const_cast<char*>("dtype"), NULL},
  8865. {const_cast<char*>("comp_node"), py_get_generic(Eye, comp_node), py_set_generic(Eye, comp_node), const_cast<char*>("comp_node"), NULL},
  8866. {NULL} /* Sentinel */
  8867. };
  8868. PyMethodDef PyOp(Eye)::tp_methods[] = {
  8869. {const_cast<char*>("__getstate__"), PyOp(Eye)::getstate, METH_NOARGS, "Eye getstate"},
  8870. {const_cast<char*>("__setstate__"), PyOp(Eye)::setstate, METH_VARARGS, "Eye setstate"},
  8871. {NULL} /* Sentinel */
  8872. };
  8873. PyObject *PyOp(Eye)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  8874. if (PyOp(Eye)::py_init(self, args, kwds) < 0) {
  8875. return NULL;
  8876. }
  8877. Py_RETURN_NONE;
  8878. }
  8879. PyMethodDef PyOp(Eye)::py_init_methoddef = {
  8880. "__init__",
  8881. (PyCFunction)PyOp(Eye)::py_init_proxy,
  8882. METH_VARARGS | METH_KEYWORDS,
  8883. "__init__(self, k: int = ..., dtype: str = ..., comp_node: str = ...) -> None\n"
  8884. };
  8885. void _init_py_Eye(py::module m) {
  8886. using py_op = PyOp(Eye);
  8887. auto& py_type = PyOpType(Eye);
  8888. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8889. py_type.tp_name = "megengine.core._imperative_rt.ops.Eye";
  8890. py_type.tp_basicsize = sizeof(PyOp(Eye));
  8891. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8892. py_type.tp_doc = "Eye";
  8893. py_type.tp_base = &PyOpType(OpDef);
  8894. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8895. py_type.tp_new = py_new_generic<py_op>;
  8896. py_type.tp_init = py_op::py_init;
  8897. py_type.tp_methods = py_op::tp_methods;
  8898. py_type.tp_getset = py_op::py_getsetters;
  8899. py_type.tp_dict = PyDict_New();
  8900. PyObject* descr = PyDescr_NewMethod(&PyOpType(Eye), &PyOp(Eye)::py_init_methoddef);
  8901. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  8902. mgb_assert(PyType_Ready(&py_type) >= 0);
  8903. PyType_Modified(&py_type);
  8904. m.add_object("Eye", reinterpret_cast<PyObject*>(&py_type));
  8905. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Eye::typeinfo(), &py_type).second);
  8906. }
  8907. PyOpDefBegin(FakeQuant) // {
  8908. static PyGetSetDef py_getsetters[];
  8909. static PyMethodDef tp_methods[];
  8910. static PyObject* getstate(PyObject* self, PyObject*) {
  8911. auto& opdef = reinterpret_cast<PyOp(FakeQuant)*>(self)->inst();
  8912. static_cast<void>(opdef);
  8913. std::unordered_map<std::string, py::object> state {
  8914. {"qmin", serialization<decltype(opdef.qmin)>::dump(opdef.qmin)},
  8915. {"qmax", serialization<decltype(opdef.qmax)>::dump(opdef.qmax)}
  8916. };
  8917. return py::cast(state).release().ptr();
  8918. }
  8919. static PyObject* setstate(PyObject* self, PyObject* args) {
  8920. PyObject* dict = PyTuple_GetItem(args, 0);
  8921. if (!dict) return NULL;
  8922. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8923. auto& opdef = reinterpret_cast<PyOp(FakeQuant)*>(self)->inst();
  8924. static_cast<void>(opdef);
  8925. {
  8926. auto&& iter = state.find("qmin");
  8927. if (iter != state.end()) {
  8928. opdef.qmin = serialization<decltype(opdef.qmin)>::load(iter->second);
  8929. }
  8930. }
  8931. {
  8932. auto&& iter = state.find("qmax");
  8933. if (iter != state.end()) {
  8934. opdef.qmax = serialization<decltype(opdef.qmax)>::load(iter->second);
  8935. }
  8936. }
  8937. Py_RETURN_NONE;
  8938. }
  8939. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8940. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  8941. static PyMethodDef py_init_methoddef;
  8942. // };
  8943. PyOpDefEnd(FakeQuant)
  8944. int PyOp(FakeQuant)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8945. static const char* kwlist[] = {"qmin", "qmax", "scope", NULL};
  8946. PyObject *qmin = NULL, *qmax = NULL, *scope = NULL;
  8947. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &qmin, &qmax, &scope))
  8948. return -1;
  8949. if (qmin) {
  8950. try {
  8951. // TODO: remove this guard which is used for pybind11 implicit conversion
  8952. py::detail::loader_life_support guard{};
  8953. reinterpret_cast<PyOp(FakeQuant)*>(self)->inst().qmin =
  8954. py::cast<decltype(FakeQuant::qmin)>(py::handle(qmin));
  8955. } CATCH_ALL(-1)
  8956. }
  8957. if (qmax) {
  8958. try {
  8959. // TODO: remove this guard which is used for pybind11 implicit conversion
  8960. py::detail::loader_life_support guard{};
  8961. reinterpret_cast<PyOp(FakeQuant)*>(self)->inst().qmax =
  8962. py::cast<decltype(FakeQuant::qmax)>(py::handle(qmax));
  8963. } CATCH_ALL(-1)
  8964. }
  8965. if (scope) {
  8966. try {
  8967. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8968. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8969. } CATCH_ALL(-1)
  8970. }
  8971. return 0;
  8972. }
  8973. PyGetSetDef PyOp(FakeQuant)::py_getsetters[] = {
  8974. {const_cast<char*>("qmin"), py_get_generic(FakeQuant, qmin), py_set_generic(FakeQuant, qmin), const_cast<char*>("qmin"), NULL},
  8975. {const_cast<char*>("qmax"), py_get_generic(FakeQuant, qmax), py_set_generic(FakeQuant, qmax), const_cast<char*>("qmax"), NULL},
  8976. {NULL} /* Sentinel */
  8977. };
  8978. PyMethodDef PyOp(FakeQuant)::tp_methods[] = {
  8979. {const_cast<char*>("__getstate__"), PyOp(FakeQuant)::getstate, METH_NOARGS, "FakeQuant getstate"},
  8980. {const_cast<char*>("__setstate__"), PyOp(FakeQuant)::setstate, METH_VARARGS, "FakeQuant setstate"},
  8981. {NULL} /* Sentinel */
  8982. };
  8983. PyObject *PyOp(FakeQuant)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  8984. if (PyOp(FakeQuant)::py_init(self, args, kwds) < 0) {
  8985. return NULL;
  8986. }
  8987. Py_RETURN_NONE;
  8988. }
  8989. PyMethodDef PyOp(FakeQuant)::py_init_methoddef = {
  8990. "__init__",
  8991. (PyCFunction)PyOp(FakeQuant)::py_init_proxy,
  8992. METH_VARARGS | METH_KEYWORDS,
  8993. "__init__(self, qmin: int = ..., qmax: int = ...) -> None\n"
  8994. };
  8995. void _init_py_FakeQuant(py::module m) {
  8996. using py_op = PyOp(FakeQuant);
  8997. auto& py_type = PyOpType(FakeQuant);
  8998. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8999. py_type.tp_name = "megengine.core._imperative_rt.ops.FakeQuant";
  9000. py_type.tp_basicsize = sizeof(PyOp(FakeQuant));
  9001. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9002. py_type.tp_doc = "FakeQuant";
  9003. py_type.tp_base = &PyOpType(OpDef);
  9004. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9005. py_type.tp_new = py_new_generic<py_op>;
  9006. py_type.tp_init = py_op::py_init;
  9007. py_type.tp_methods = py_op::tp_methods;
  9008. py_type.tp_getset = py_op::py_getsetters;
  9009. py_type.tp_dict = PyDict_New();
  9010. PyObject* descr = PyDescr_NewMethod(&PyOpType(FakeQuant), &PyOp(FakeQuant)::py_init_methoddef);
  9011. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  9012. mgb_assert(PyType_Ready(&py_type) >= 0);
  9013. PyType_Modified(&py_type);
  9014. m.add_object("FakeQuant", reinterpret_cast<PyObject*>(&py_type));
  9015. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(FakeQuant::typeinfo(), &py_type).second);
  9016. }
  9017. PyOpDefBegin(FastpathCopy) // {
  9018. static PyGetSetDef py_getsetters[];
  9019. static PyMethodDef tp_methods[];
  9020. static PyObject* getstate(PyObject* self, PyObject*) {
  9021. auto& opdef = reinterpret_cast<PyOp(FastpathCopy)*>(self)->inst();
  9022. static_cast<void>(opdef);
  9023. std::unordered_map<std::string, py::object> state {
  9024. };
  9025. return py::cast(state).release().ptr();
  9026. }
  9027. static PyObject* setstate(PyObject* self, PyObject* args) {
  9028. PyObject* dict = PyTuple_GetItem(args, 0);
  9029. if (!dict) return NULL;
  9030. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9031. auto& opdef = reinterpret_cast<PyOp(FastpathCopy)*>(self)->inst();
  9032. static_cast<void>(opdef);
  9033. Py_RETURN_NONE;
  9034. }
  9035. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9036. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  9037. static PyMethodDef py_init_methoddef;
  9038. // };
  9039. PyOpDefEnd(FastpathCopy)
  9040. int PyOp(FastpathCopy)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9041. return 0;
  9042. }
  9043. PyGetSetDef PyOp(FastpathCopy)::py_getsetters[] = {
  9044. {NULL} /* Sentinel */
  9045. };
  9046. PyMethodDef PyOp(FastpathCopy)::tp_methods[] = {
  9047. {const_cast<char*>("__getstate__"), PyOp(FastpathCopy)::getstate, METH_NOARGS, "FastpathCopy getstate"},
  9048. {const_cast<char*>("__setstate__"), PyOp(FastpathCopy)::setstate, METH_VARARGS, "FastpathCopy setstate"},
  9049. {NULL} /* Sentinel */
  9050. };
  9051. PyObject *PyOp(FastpathCopy)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  9052. if (PyOp(FastpathCopy)::py_init(self, args, kwds) < 0) {
  9053. return NULL;
  9054. }
  9055. Py_RETURN_NONE;
  9056. }
  9057. PyMethodDef PyOp(FastpathCopy)::py_init_methoddef = {
  9058. "__init__",
  9059. (PyCFunction)PyOp(FastpathCopy)::py_init_proxy,
  9060. METH_VARARGS | METH_KEYWORDS,
  9061. "__init__(self) -> None\n"
  9062. };
  9063. void _init_py_FastpathCopy(py::module m) {
  9064. using py_op = PyOp(FastpathCopy);
  9065. auto& py_type = PyOpType(FastpathCopy);
  9066. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9067. py_type.tp_name = "megengine.core._imperative_rt.ops.FastpathCopy";
  9068. py_type.tp_basicsize = sizeof(PyOp(FastpathCopy));
  9069. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9070. py_type.tp_doc = "FastpathCopy";
  9071. py_type.tp_base = &PyOpType(OpDef);
  9072. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9073. py_type.tp_new = py_new_generic<py_op>;
  9074. py_type.tp_init = py_op::py_init;
  9075. py_type.tp_methods = py_op::tp_methods;
  9076. py_type.tp_getset = py_op::py_getsetters;
  9077. py_type.tp_dict = PyDict_New();
  9078. PyObject* descr = PyDescr_NewMethod(&PyOpType(FastpathCopy), &PyOp(FastpathCopy)::py_init_methoddef);
  9079. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  9080. mgb_assert(PyType_Ready(&py_type) >= 0);
  9081. PyType_Modified(&py_type);
  9082. m.add_object("FastpathCopy", reinterpret_cast<PyObject*>(&py_type));
  9083. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(FastpathCopy::typeinfo(), &py_type).second);
  9084. }
  9085. PyOpDefBegin(GammaRNG) // {
  9086. static PyGetSetDef py_getsetters[];
  9087. static PyMethodDef tp_methods[];
  9088. static PyObject* getstate(PyObject* self, PyObject*) {
  9089. auto& opdef = reinterpret_cast<PyOp(GammaRNG)*>(self)->inst();
  9090. static_cast<void>(opdef);
  9091. std::unordered_map<std::string, py::object> state {
  9092. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  9093. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  9094. };
  9095. return py::cast(state).release().ptr();
  9096. }
  9097. static PyObject* setstate(PyObject* self, PyObject* args) {
  9098. PyObject* dict = PyTuple_GetItem(args, 0);
  9099. if (!dict) return NULL;
  9100. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9101. auto& opdef = reinterpret_cast<PyOp(GammaRNG)*>(self)->inst();
  9102. static_cast<void>(opdef);
  9103. {
  9104. auto&& iter = state.find("seed");
  9105. if (iter != state.end()) {
  9106. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  9107. }
  9108. }
  9109. {
  9110. auto&& iter = state.find("handle");
  9111. if (iter != state.end()) {
  9112. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  9113. }
  9114. }
  9115. Py_RETURN_NONE;
  9116. }
  9117. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9118. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  9119. static PyMethodDef py_init_methoddef;
  9120. // };
  9121. PyOpDefEnd(GammaRNG)
  9122. int PyOp(GammaRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9123. static const char* kwlist[] = {"seed", "handle", "scope", NULL};
  9124. PyObject *seed = NULL, *handle = NULL, *scope = NULL;
  9125. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &seed, &handle, &scope))
  9126. return -1;
  9127. if (seed) {
  9128. try {
  9129. // TODO: remove this guard which is used for pybind11 implicit conversion
  9130. py::detail::loader_life_support guard{};
  9131. reinterpret_cast<PyOp(GammaRNG)*>(self)->inst().seed =
  9132. py::cast<decltype(GammaRNG::seed)>(py::handle(seed));
  9133. } CATCH_ALL(-1)
  9134. }
  9135. if (handle) {
  9136. try {
  9137. // TODO: remove this guard which is used for pybind11 implicit conversion
  9138. py::detail::loader_life_support guard{};
  9139. reinterpret_cast<PyOp(GammaRNG)*>(self)->inst().handle =
  9140. py::cast<decltype(GammaRNG::handle)>(py::handle(handle));
  9141. } CATCH_ALL(-1)
  9142. }
  9143. if (scope) {
  9144. try {
  9145. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9146. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9147. } CATCH_ALL(-1)
  9148. }
  9149. return 0;
  9150. }
  9151. PyGetSetDef PyOp(GammaRNG)::py_getsetters[] = {
  9152. {const_cast<char*>("seed"), py_get_generic(GammaRNG, seed), py_set_generic(GammaRNG, seed), const_cast<char*>("seed"), NULL},
  9153. {const_cast<char*>("handle"), py_get_generic(GammaRNG, handle), py_set_generic(GammaRNG, handle), const_cast<char*>("handle"), NULL},
  9154. {NULL} /* Sentinel */
  9155. };
  9156. PyMethodDef PyOp(GammaRNG)::tp_methods[] = {
  9157. {const_cast<char*>("__getstate__"), PyOp(GammaRNG)::getstate, METH_NOARGS, "GammaRNG getstate"},
  9158. {const_cast<char*>("__setstate__"), PyOp(GammaRNG)::setstate, METH_VARARGS, "GammaRNG setstate"},
  9159. {NULL} /* Sentinel */
  9160. };
  9161. PyObject *PyOp(GammaRNG)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  9162. if (PyOp(GammaRNG)::py_init(self, args, kwds) < 0) {
  9163. return NULL;
  9164. }
  9165. Py_RETURN_NONE;
  9166. }
  9167. PyMethodDef PyOp(GammaRNG)::py_init_methoddef = {
  9168. "__init__",
  9169. (PyCFunction)PyOp(GammaRNG)::py_init_proxy,
  9170. METH_VARARGS | METH_KEYWORDS,
  9171. "__init__(self, seed: int = ..., handle: int = ...) -> None\n"
  9172. };
  9173. void _init_py_GammaRNG(py::module m) {
  9174. using py_op = PyOp(GammaRNG);
  9175. auto& py_type = PyOpType(GammaRNG);
  9176. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9177. py_type.tp_name = "megengine.core._imperative_rt.ops.GammaRNG";
  9178. py_type.tp_basicsize = sizeof(PyOp(GammaRNG));
  9179. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9180. py_type.tp_doc = "GammaRNG";
  9181. py_type.tp_base = &PyOpType(OpDef);
  9182. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9183. py_type.tp_new = py_new_generic<py_op>;
  9184. py_type.tp_init = py_op::py_init;
  9185. py_type.tp_methods = py_op::tp_methods;
  9186. py_type.tp_getset = py_op::py_getsetters;
  9187. py_type.tp_dict = PyDict_New();
  9188. PyObject* descr = PyDescr_NewMethod(&PyOpType(GammaRNG), &PyOp(GammaRNG)::py_init_methoddef);
  9189. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  9190. mgb_assert(PyType_Ready(&py_type) >= 0);
  9191. PyType_Modified(&py_type);
  9192. m.add_object("GammaRNG", reinterpret_cast<PyObject*>(&py_type));
  9193. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GammaRNG::typeinfo(), &py_type).second);
  9194. }
  9195. PyOpDefBegin(GaussianRNG) // {
  9196. static PyGetSetDef py_getsetters[];
  9197. static PyMethodDef tp_methods[];
  9198. static PyObject* getstate(PyObject* self, PyObject*) {
  9199. auto& opdef = reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst();
  9200. static_cast<void>(opdef);
  9201. std::unordered_map<std::string, py::object> state {
  9202. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  9203. {"mean", serialization<decltype(opdef.mean)>::dump(opdef.mean)},
  9204. {"std", serialization<decltype(opdef.std)>::dump(opdef.std)},
  9205. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  9206. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  9207. };
  9208. return py::cast(state).release().ptr();
  9209. }
  9210. static PyObject* setstate(PyObject* self, PyObject* args) {
  9211. PyObject* dict = PyTuple_GetItem(args, 0);
  9212. if (!dict) return NULL;
  9213. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9214. auto& opdef = reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst();
  9215. static_cast<void>(opdef);
  9216. {
  9217. auto&& iter = state.find("seed");
  9218. if (iter != state.end()) {
  9219. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  9220. }
  9221. }
  9222. {
  9223. auto&& iter = state.find("mean");
  9224. if (iter != state.end()) {
  9225. opdef.mean = serialization<decltype(opdef.mean)>::load(iter->second);
  9226. }
  9227. }
  9228. {
  9229. auto&& iter = state.find("std");
  9230. if (iter != state.end()) {
  9231. opdef.std = serialization<decltype(opdef.std)>::load(iter->second);
  9232. }
  9233. }
  9234. {
  9235. auto&& iter = state.find("dtype");
  9236. if (iter != state.end()) {
  9237. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  9238. }
  9239. }
  9240. {
  9241. auto&& iter = state.find("handle");
  9242. if (iter != state.end()) {
  9243. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  9244. }
  9245. }
  9246. Py_RETURN_NONE;
  9247. }
  9248. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9249. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  9250. static PyMethodDef py_init_methoddef;
  9251. // };
  9252. PyOpDefEnd(GaussianRNG)
  9253. int PyOp(GaussianRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9254. static const char* kwlist[] = {"seed", "mean", "std", "dtype", "handle", "scope", NULL};
  9255. PyObject *seed = NULL, *mean = NULL, *std = NULL, *dtype = NULL, *handle = NULL, *scope = NULL;
  9256. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOO", const_cast<char**>(kwlist), &seed, &mean, &std, &dtype, &handle, &scope))
  9257. return -1;
  9258. if (seed) {
  9259. try {
  9260. // TODO: remove this guard which is used for pybind11 implicit conversion
  9261. py::detail::loader_life_support guard{};
  9262. reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst().seed =
  9263. py::cast<decltype(GaussianRNG::seed)>(py::handle(seed));
  9264. } CATCH_ALL(-1)
  9265. }
  9266. if (mean) {
  9267. try {
  9268. // TODO: remove this guard which is used for pybind11 implicit conversion
  9269. py::detail::loader_life_support guard{};
  9270. reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst().mean =
  9271. py::cast<decltype(GaussianRNG::mean)>(py::handle(mean));
  9272. } CATCH_ALL(-1)
  9273. }
  9274. if (std) {
  9275. try {
  9276. // TODO: remove this guard which is used for pybind11 implicit conversion
  9277. py::detail::loader_life_support guard{};
  9278. reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst().std =
  9279. py::cast<decltype(GaussianRNG::std)>(py::handle(std));
  9280. } CATCH_ALL(-1)
  9281. }
  9282. if (dtype) {
  9283. try {
  9284. // TODO: remove this guard which is used for pybind11 implicit conversion
  9285. py::detail::loader_life_support guard{};
  9286. reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst().dtype =
  9287. py::cast<decltype(GaussianRNG::dtype)>(py::handle(dtype));
  9288. } CATCH_ALL(-1)
  9289. }
  9290. if (handle) {
  9291. try {
  9292. // TODO: remove this guard which is used for pybind11 implicit conversion
  9293. py::detail::loader_life_support guard{};
  9294. reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst().handle =
  9295. py::cast<decltype(GaussianRNG::handle)>(py::handle(handle));
  9296. } CATCH_ALL(-1)
  9297. }
  9298. if (scope) {
  9299. try {
  9300. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9301. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9302. } CATCH_ALL(-1)
  9303. }
  9304. return 0;
  9305. }
  9306. PyGetSetDef PyOp(GaussianRNG)::py_getsetters[] = {
  9307. {const_cast<char*>("seed"), py_get_generic(GaussianRNG, seed), py_set_generic(GaussianRNG, seed), const_cast<char*>("seed"), NULL},
  9308. {const_cast<char*>("mean"), py_get_generic(GaussianRNG, mean), py_set_generic(GaussianRNG, mean), const_cast<char*>("mean"), NULL},
  9309. {const_cast<char*>("std"), py_get_generic(GaussianRNG, std), py_set_generic(GaussianRNG, std), const_cast<char*>("std"), NULL},
  9310. {const_cast<char*>("dtype"), py_get_generic(GaussianRNG, dtype), py_set_generic(GaussianRNG, dtype), const_cast<char*>("dtype"), NULL},
  9311. {const_cast<char*>("handle"), py_get_generic(GaussianRNG, handle), py_set_generic(GaussianRNG, handle), const_cast<char*>("handle"), NULL},
  9312. {NULL} /* Sentinel */
  9313. };
  9314. PyMethodDef PyOp(GaussianRNG)::tp_methods[] = {
  9315. {const_cast<char*>("__getstate__"), PyOp(GaussianRNG)::getstate, METH_NOARGS, "GaussianRNG getstate"},
  9316. {const_cast<char*>("__setstate__"), PyOp(GaussianRNG)::setstate, METH_VARARGS, "GaussianRNG setstate"},
  9317. {NULL} /* Sentinel */
  9318. };
  9319. PyObject *PyOp(GaussianRNG)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  9320. if (PyOp(GaussianRNG)::py_init(self, args, kwds) < 0) {
  9321. return NULL;
  9322. }
  9323. Py_RETURN_NONE;
  9324. }
  9325. PyMethodDef PyOp(GaussianRNG)::py_init_methoddef = {
  9326. "__init__",
  9327. (PyCFunction)PyOp(GaussianRNG)::py_init_proxy,
  9328. METH_VARARGS | METH_KEYWORDS,
  9329. "__init__(self, seed: int = ..., mean: float = ..., std: float = ..., dtype: str = ..., handle: int = ...) -> None\n"
  9330. };
  9331. void _init_py_GaussianRNG(py::module m) {
  9332. using py_op = PyOp(GaussianRNG);
  9333. auto& py_type = PyOpType(GaussianRNG);
  9334. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9335. py_type.tp_name = "megengine.core._imperative_rt.ops.GaussianRNG";
  9336. py_type.tp_basicsize = sizeof(PyOp(GaussianRNG));
  9337. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9338. py_type.tp_doc = "GaussianRNG";
  9339. py_type.tp_base = &PyOpType(OpDef);
  9340. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9341. py_type.tp_new = py_new_generic<py_op>;
  9342. py_type.tp_init = py_op::py_init;
  9343. py_type.tp_methods = py_op::tp_methods;
  9344. py_type.tp_getset = py_op::py_getsetters;
  9345. py_type.tp_dict = PyDict_New();
  9346. PyObject* descr = PyDescr_NewMethod(&PyOpType(GaussianRNG), &PyOp(GaussianRNG)::py_init_methoddef);
  9347. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  9348. mgb_assert(PyType_Ready(&py_type) >= 0);
  9349. PyType_Modified(&py_type);
  9350. m.add_object("GaussianRNG", reinterpret_cast<PyObject*>(&py_type));
  9351. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GaussianRNG::typeinfo(), &py_type).second);
  9352. }
  9353. PyOpDefBegin(GetVarShape) // {
  9354. static PyGetSetDef py_getsetters[];
  9355. static PyMethodDef tp_methods[];
  9356. static PyObject* getstate(PyObject* self, PyObject*) {
  9357. auto& opdef = reinterpret_cast<PyOp(GetVarShape)*>(self)->inst();
  9358. static_cast<void>(opdef);
  9359. std::unordered_map<std::string, py::object> state {
  9360. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)}
  9361. };
  9362. return py::cast(state).release().ptr();
  9363. }
  9364. static PyObject* setstate(PyObject* self, PyObject* args) {
  9365. PyObject* dict = PyTuple_GetItem(args, 0);
  9366. if (!dict) return NULL;
  9367. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9368. auto& opdef = reinterpret_cast<PyOp(GetVarShape)*>(self)->inst();
  9369. static_cast<void>(opdef);
  9370. {
  9371. auto&& iter = state.find("axis");
  9372. if (iter != state.end()) {
  9373. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  9374. }
  9375. }
  9376. Py_RETURN_NONE;
  9377. }
  9378. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9379. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  9380. static PyMethodDef py_init_methoddef;
  9381. // };
  9382. PyOpDefEnd(GetVarShape)
  9383. int PyOp(GetVarShape)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9384. static const char* kwlist[] = {"axis", "scope", NULL};
  9385. PyObject *axis = NULL, *scope = NULL;
  9386. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &axis, &scope))
  9387. return -1;
  9388. if (axis) {
  9389. try {
  9390. // TODO: remove this guard which is used for pybind11 implicit conversion
  9391. py::detail::loader_life_support guard{};
  9392. reinterpret_cast<PyOp(GetVarShape)*>(self)->inst().axis =
  9393. py::cast<decltype(GetVarShape::axis)>(py::handle(axis));
  9394. } CATCH_ALL(-1)
  9395. }
  9396. if (scope) {
  9397. try {
  9398. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9399. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9400. } CATCH_ALL(-1)
  9401. }
  9402. return 0;
  9403. }
  9404. PyGetSetDef PyOp(GetVarShape)::py_getsetters[] = {
  9405. {const_cast<char*>("axis"), py_get_generic(GetVarShape, axis), py_set_generic(GetVarShape, axis), const_cast<char*>("axis"), NULL},
  9406. {NULL} /* Sentinel */
  9407. };
  9408. PyMethodDef PyOp(GetVarShape)::tp_methods[] = {
  9409. {const_cast<char*>("__getstate__"), PyOp(GetVarShape)::getstate, METH_NOARGS, "GetVarShape getstate"},
  9410. {const_cast<char*>("__setstate__"), PyOp(GetVarShape)::setstate, METH_VARARGS, "GetVarShape setstate"},
  9411. {NULL} /* Sentinel */
  9412. };
  9413. PyObject *PyOp(GetVarShape)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  9414. if (PyOp(GetVarShape)::py_init(self, args, kwds) < 0) {
  9415. return NULL;
  9416. }
  9417. Py_RETURN_NONE;
  9418. }
  9419. PyMethodDef PyOp(GetVarShape)::py_init_methoddef = {
  9420. "__init__",
  9421. (PyCFunction)PyOp(GetVarShape)::py_init_proxy,
  9422. METH_VARARGS | METH_KEYWORDS,
  9423. "__init__(self, axis: int = ...) -> None\n"
  9424. };
  9425. void _init_py_GetVarShape(py::module m) {
  9426. using py_op = PyOp(GetVarShape);
  9427. auto& py_type = PyOpType(GetVarShape);
  9428. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9429. py_type.tp_name = "megengine.core._imperative_rt.ops.GetVarShape";
  9430. py_type.tp_basicsize = sizeof(PyOp(GetVarShape));
  9431. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9432. py_type.tp_doc = "GetVarShape";
  9433. py_type.tp_base = &PyOpType(OpDef);
  9434. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9435. py_type.tp_new = py_new_generic<py_op>;
  9436. py_type.tp_init = py_op::py_init;
  9437. py_type.tp_methods = py_op::tp_methods;
  9438. py_type.tp_getset = py_op::py_getsetters;
  9439. py_type.tp_dict = PyDict_New();
  9440. PyObject* descr = PyDescr_NewMethod(&PyOpType(GetVarShape), &PyOp(GetVarShape)::py_init_methoddef);
  9441. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  9442. mgb_assert(PyType_Ready(&py_type) >= 0);
  9443. PyType_Modified(&py_type);
  9444. m.add_object("GetVarShape", reinterpret_cast<PyObject*>(&py_type));
  9445. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GetVarShape::typeinfo(), &py_type).second);
  9446. }
  9447. void _init_py_GroupLocal_Mode(PyTypeObject& py_type) {
  9448. auto& e_type = EnumWrapper<GroupLocal::Mode>::type;
  9449. Py_INCREF(e_type);
  9450. mgb_assert(PyDict_SetItemString(
  9451. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  9452. }
  9453. void _init_py_GroupLocal_Sparse(PyTypeObject& py_type) {
  9454. auto& e_type = EnumWrapper<GroupLocal::Sparse>::type;
  9455. Py_INCREF(e_type);
  9456. mgb_assert(PyDict_SetItemString(
  9457. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  9458. }
  9459. void _init_py_GroupLocal_Format(PyTypeObject& py_type) {
  9460. auto& e_type = EnumWrapper<GroupLocal::Format>::type;
  9461. Py_INCREF(e_type);
  9462. mgb_assert(PyDict_SetItemString(
  9463. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  9464. }
  9465. void _init_py_GroupLocal_ComputeMode(PyTypeObject& py_type) {
  9466. auto& e_type = EnumWrapper<GroupLocal::ComputeMode>::type;
  9467. Py_INCREF(e_type);
  9468. mgb_assert(PyDict_SetItemString(
  9469. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  9470. }
  9471. PyOpDefBegin(GroupLocal) // {
  9472. static PyGetSetDef py_getsetters[];
  9473. static PyMethodDef tp_methods[];
  9474. static PyObject* getstate(PyObject* self, PyObject*) {
  9475. auto& opdef = reinterpret_cast<PyOp(GroupLocal)*>(self)->inst();
  9476. static_cast<void>(opdef);
  9477. std::unordered_map<std::string, py::object> state {
  9478. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  9479. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  9480. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  9481. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  9482. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  9483. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  9484. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  9485. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  9486. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  9487. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)}
  9488. };
  9489. return py::cast(state).release().ptr();
  9490. }
  9491. static PyObject* setstate(PyObject* self, PyObject* args) {
  9492. PyObject* dict = PyTuple_GetItem(args, 0);
  9493. if (!dict) return NULL;
  9494. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9495. auto& opdef = reinterpret_cast<PyOp(GroupLocal)*>(self)->inst();
  9496. static_cast<void>(opdef);
  9497. {
  9498. auto&& iter = state.find("mode");
  9499. if (iter != state.end()) {
  9500. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  9501. }
  9502. }
  9503. {
  9504. auto&& iter = state.find("pad_h");
  9505. if (iter != state.end()) {
  9506. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  9507. }
  9508. }
  9509. {
  9510. auto&& iter = state.find("pad_w");
  9511. if (iter != state.end()) {
  9512. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  9513. }
  9514. }
  9515. {
  9516. auto&& iter = state.find("stride_h");
  9517. if (iter != state.end()) {
  9518. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  9519. }
  9520. }
  9521. {
  9522. auto&& iter = state.find("stride_w");
  9523. if (iter != state.end()) {
  9524. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  9525. }
  9526. }
  9527. {
  9528. auto&& iter = state.find("dilate_h");
  9529. if (iter != state.end()) {
  9530. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  9531. }
  9532. }
  9533. {
  9534. auto&& iter = state.find("dilate_w");
  9535. if (iter != state.end()) {
  9536. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  9537. }
  9538. }
  9539. {
  9540. auto&& iter = state.find("sparse");
  9541. if (iter != state.end()) {
  9542. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  9543. }
  9544. }
  9545. {
  9546. auto&& iter = state.find("format");
  9547. if (iter != state.end()) {
  9548. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  9549. }
  9550. }
  9551. {
  9552. auto&& iter = state.find("compute_mode");
  9553. if (iter != state.end()) {
  9554. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  9555. }
  9556. }
  9557. Py_RETURN_NONE;
  9558. }
  9559. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9560. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  9561. static PyMethodDef py_init_methoddef;
  9562. // };
  9563. PyOpDefEnd(GroupLocal)
  9564. int PyOp(GroupLocal)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9565. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "scope", NULL};
  9566. PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *scope = NULL;
  9567. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &scope))
  9568. return -1;
  9569. if (mode) {
  9570. try {
  9571. // TODO: remove this guard which is used for pybind11 implicit conversion
  9572. py::detail::loader_life_support guard{};
  9573. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().mode =
  9574. py::cast<decltype(GroupLocal::mode)>(py::handle(mode));
  9575. } CATCH_ALL(-1)
  9576. }
  9577. if (pad_h) {
  9578. try {
  9579. // TODO: remove this guard which is used for pybind11 implicit conversion
  9580. py::detail::loader_life_support guard{};
  9581. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().pad_h =
  9582. py::cast<decltype(GroupLocal::pad_h)>(py::handle(pad_h));
  9583. } CATCH_ALL(-1)
  9584. }
  9585. if (pad_w) {
  9586. try {
  9587. // TODO: remove this guard which is used for pybind11 implicit conversion
  9588. py::detail::loader_life_support guard{};
  9589. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().pad_w =
  9590. py::cast<decltype(GroupLocal::pad_w)>(py::handle(pad_w));
  9591. } CATCH_ALL(-1)
  9592. }
  9593. if (stride_h) {
  9594. try {
  9595. // TODO: remove this guard which is used for pybind11 implicit conversion
  9596. py::detail::loader_life_support guard{};
  9597. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().stride_h =
  9598. py::cast<decltype(GroupLocal::stride_h)>(py::handle(stride_h));
  9599. } CATCH_ALL(-1)
  9600. }
  9601. if (stride_w) {
  9602. try {
  9603. // TODO: remove this guard which is used for pybind11 implicit conversion
  9604. py::detail::loader_life_support guard{};
  9605. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().stride_w =
  9606. py::cast<decltype(GroupLocal::stride_w)>(py::handle(stride_w));
  9607. } CATCH_ALL(-1)
  9608. }
  9609. if (dilate_h) {
  9610. try {
  9611. // TODO: remove this guard which is used for pybind11 implicit conversion
  9612. py::detail::loader_life_support guard{};
  9613. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().dilate_h =
  9614. py::cast<decltype(GroupLocal::dilate_h)>(py::handle(dilate_h));
  9615. } CATCH_ALL(-1)
  9616. }
  9617. if (dilate_w) {
  9618. try {
  9619. // TODO: remove this guard which is used for pybind11 implicit conversion
  9620. py::detail::loader_life_support guard{};
  9621. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().dilate_w =
  9622. py::cast<decltype(GroupLocal::dilate_w)>(py::handle(dilate_w));
  9623. } CATCH_ALL(-1)
  9624. }
  9625. if (sparse) {
  9626. try {
  9627. // TODO: remove this guard which is used for pybind11 implicit conversion
  9628. py::detail::loader_life_support guard{};
  9629. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().sparse =
  9630. py::cast<decltype(GroupLocal::sparse)>(py::handle(sparse));
  9631. } CATCH_ALL(-1)
  9632. }
  9633. if (format) {
  9634. try {
  9635. // TODO: remove this guard which is used for pybind11 implicit conversion
  9636. py::detail::loader_life_support guard{};
  9637. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().format =
  9638. py::cast<decltype(GroupLocal::format)>(py::handle(format));
  9639. } CATCH_ALL(-1)
  9640. }
  9641. if (compute_mode) {
  9642. try {
  9643. // TODO: remove this guard which is used for pybind11 implicit conversion
  9644. py::detail::loader_life_support guard{};
  9645. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().compute_mode =
  9646. py::cast<decltype(GroupLocal::compute_mode)>(py::handle(compute_mode));
  9647. } CATCH_ALL(-1)
  9648. }
  9649. if (scope) {
  9650. try {
  9651. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9652. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9653. } CATCH_ALL(-1)
  9654. }
  9655. return 0;
  9656. }
  9657. PyGetSetDef PyOp(GroupLocal)::py_getsetters[] = {
  9658. {const_cast<char*>("mode"), py_get_generic(GroupLocal, mode), py_set_generic(GroupLocal, mode), const_cast<char*>("mode"), NULL},
  9659. {const_cast<char*>("pad_h"), py_get_generic(GroupLocal, pad_h), py_set_generic(GroupLocal, pad_h), const_cast<char*>("pad_h"), NULL},
  9660. {const_cast<char*>("pad_w"), py_get_generic(GroupLocal, pad_w), py_set_generic(GroupLocal, pad_w), const_cast<char*>("pad_w"), NULL},
  9661. {const_cast<char*>("stride_h"), py_get_generic(GroupLocal, stride_h), py_set_generic(GroupLocal, stride_h), const_cast<char*>("stride_h"), NULL},
  9662. {const_cast<char*>("stride_w"), py_get_generic(GroupLocal, stride_w), py_set_generic(GroupLocal, stride_w), const_cast<char*>("stride_w"), NULL},
  9663. {const_cast<char*>("dilate_h"), py_get_generic(GroupLocal, dilate_h), py_set_generic(GroupLocal, dilate_h), const_cast<char*>("dilate_h"), NULL},
  9664. {const_cast<char*>("dilate_w"), py_get_generic(GroupLocal, dilate_w), py_set_generic(GroupLocal, dilate_w), const_cast<char*>("dilate_w"), NULL},
  9665. {const_cast<char*>("sparse"), py_get_generic(GroupLocal, sparse), py_set_generic(GroupLocal, sparse), const_cast<char*>("sparse"), NULL},
  9666. {const_cast<char*>("format"), py_get_generic(GroupLocal, format), py_set_generic(GroupLocal, format), const_cast<char*>("format"), NULL},
  9667. {const_cast<char*>("compute_mode"), py_get_generic(GroupLocal, compute_mode), py_set_generic(GroupLocal, compute_mode), const_cast<char*>("compute_mode"), NULL},
  9668. {NULL} /* Sentinel */
  9669. };
  9670. PyMethodDef PyOp(GroupLocal)::tp_methods[] = {
  9671. {const_cast<char*>("__getstate__"), PyOp(GroupLocal)::getstate, METH_NOARGS, "GroupLocal getstate"},
  9672. {const_cast<char*>("__setstate__"), PyOp(GroupLocal)::setstate, METH_VARARGS, "GroupLocal setstate"},
  9673. {NULL} /* Sentinel */
  9674. };
  9675. PyObject *PyOp(GroupLocal)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  9676. if (PyOp(GroupLocal)::py_init(self, args, kwds) < 0) {
  9677. return NULL;
  9678. }
  9679. Py_RETURN_NONE;
  9680. }
  9681. PyMethodDef PyOp(GroupLocal)::py_init_methoddef = {
  9682. "__init__",
  9683. (PyCFunction)PyOp(GroupLocal)::py_init_proxy,
  9684. METH_VARARGS | METH_KEYWORDS,
  9685. "__init__(self, mode: Union[str, Mode] = ..., pad_h: int = ..., pad_w: int = ..., stride_h: int = ..., stride_w: int = ..., dilate_h: int = ..., dilate_w: int = ..., sparse: Union[str, Sparse] = ..., format: Union[str, Format] = ..., compute_mode: Union[str, ComputeMode] = ...) -> None\n"
  9686. };
  9687. void _init_py_GroupLocal(py::module m) {
  9688. using py_op = PyOp(GroupLocal);
  9689. auto& py_type = PyOpType(GroupLocal);
  9690. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9691. py_type.tp_name = "megengine.core._imperative_rt.ops.GroupLocal";
  9692. py_type.tp_basicsize = sizeof(PyOp(GroupLocal));
  9693. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9694. py_type.tp_doc = "GroupLocal";
  9695. py_type.tp_base = &PyOpType(OpDef);
  9696. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9697. py_type.tp_new = py_new_generic<py_op>;
  9698. py_type.tp_init = py_op::py_init;
  9699. py_type.tp_methods = py_op::tp_methods;
  9700. py_type.tp_getset = py_op::py_getsetters;
  9701. py_type.tp_dict = PyDict_New();
  9702. PyObject* descr = PyDescr_NewMethod(&PyOpType(GroupLocal), &PyOp(GroupLocal)::py_init_methoddef);
  9703. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  9704. mgb_assert(PyType_Ready(&py_type) >= 0);
  9705. _init_py_GroupLocal_Mode(py_type);
  9706. _init_py_GroupLocal_Sparse(py_type);
  9707. _init_py_GroupLocal_Format(py_type);
  9708. _init_py_GroupLocal_ComputeMode(py_type);
  9709. PyType_Modified(&py_type);
  9710. m.add_object("GroupLocal", reinterpret_cast<PyObject*>(&py_type));
  9711. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GroupLocal::typeinfo(), &py_type).second);
  9712. }
  9713. void _init_py_GroupNorm_Format(PyTypeObject& py_type) {
  9714. auto& e_type = EnumWrapper<GroupNorm::Format>::type;
  9715. Py_INCREF(e_type);
  9716. mgb_assert(PyDict_SetItemString(
  9717. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  9718. }
  9719. PyOpDefBegin(GroupNorm) // {
  9720. static PyGetSetDef py_getsetters[];
  9721. static PyMethodDef tp_methods[];
  9722. static PyObject* getstate(PyObject* self, PyObject*) {
  9723. auto& opdef = reinterpret_cast<PyOp(GroupNorm)*>(self)->inst();
  9724. static_cast<void>(opdef);
  9725. std::unordered_map<std::string, py::object> state {
  9726. {"affine", serialization<decltype(opdef.affine)>::dump(opdef.affine)},
  9727. {"eps", serialization<decltype(opdef.eps)>::dump(opdef.eps)},
  9728. {"group", serialization<decltype(opdef.group)>::dump(opdef.group)},
  9729. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)}
  9730. };
  9731. return py::cast(state).release().ptr();
  9732. }
  9733. static PyObject* setstate(PyObject* self, PyObject* args) {
  9734. PyObject* dict = PyTuple_GetItem(args, 0);
  9735. if (!dict) return NULL;
  9736. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9737. auto& opdef = reinterpret_cast<PyOp(GroupNorm)*>(self)->inst();
  9738. static_cast<void>(opdef);
  9739. {
  9740. auto&& iter = state.find("affine");
  9741. if (iter != state.end()) {
  9742. opdef.affine = serialization<decltype(opdef.affine)>::load(iter->second);
  9743. }
  9744. }
  9745. {
  9746. auto&& iter = state.find("eps");
  9747. if (iter != state.end()) {
  9748. opdef.eps = serialization<decltype(opdef.eps)>::load(iter->second);
  9749. }
  9750. }
  9751. {
  9752. auto&& iter = state.find("group");
  9753. if (iter != state.end()) {
  9754. opdef.group = serialization<decltype(opdef.group)>::load(iter->second);
  9755. }
  9756. }
  9757. {
  9758. auto&& iter = state.find("format");
  9759. if (iter != state.end()) {
  9760. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  9761. }
  9762. }
  9763. Py_RETURN_NONE;
  9764. }
  9765. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9766. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  9767. static PyMethodDef py_init_methoddef;
  9768. // };
  9769. PyOpDefEnd(GroupNorm)
  9770. int PyOp(GroupNorm)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9771. static const char* kwlist[] = {"affine", "eps", "group", "format", "scope", NULL};
  9772. PyObject *affine = NULL, *eps = NULL, *group = NULL, *format = NULL, *scope = NULL;
  9773. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &affine, &eps, &group, &format, &scope))
  9774. return -1;
  9775. if (affine) {
  9776. try {
  9777. // TODO: remove this guard which is used for pybind11 implicit conversion
  9778. py::detail::loader_life_support guard{};
  9779. reinterpret_cast<PyOp(GroupNorm)*>(self)->inst().affine =
  9780. py::cast<decltype(GroupNorm::affine)>(py::handle(affine));
  9781. } CATCH_ALL(-1)
  9782. }
  9783. if (eps) {
  9784. try {
  9785. // TODO: remove this guard which is used for pybind11 implicit conversion
  9786. py::detail::loader_life_support guard{};
  9787. reinterpret_cast<PyOp(GroupNorm)*>(self)->inst().eps =
  9788. py::cast<decltype(GroupNorm::eps)>(py::handle(eps));
  9789. } CATCH_ALL(-1)
  9790. }
  9791. if (group) {
  9792. try {
  9793. // TODO: remove this guard which is used for pybind11 implicit conversion
  9794. py::detail::loader_life_support guard{};
  9795. reinterpret_cast<PyOp(GroupNorm)*>(self)->inst().group =
  9796. py::cast<decltype(GroupNorm::group)>(py::handle(group));
  9797. } CATCH_ALL(-1)
  9798. }
  9799. if (format) {
  9800. try {
  9801. // TODO: remove this guard which is used for pybind11 implicit conversion
  9802. py::detail::loader_life_support guard{};
  9803. reinterpret_cast<PyOp(GroupNorm)*>(self)->inst().format =
  9804. py::cast<decltype(GroupNorm::format)>(py::handle(format));
  9805. } CATCH_ALL(-1)
  9806. }
  9807. if (scope) {
  9808. try {
  9809. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9810. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9811. } CATCH_ALL(-1)
  9812. }
  9813. return 0;
  9814. }
  9815. PyGetSetDef PyOp(GroupNorm)::py_getsetters[] = {
  9816. {const_cast<char*>("affine"), py_get_generic(GroupNorm, affine), py_set_generic(GroupNorm, affine), const_cast<char*>("affine"), NULL},
  9817. {const_cast<char*>("eps"), py_get_generic(GroupNorm, eps), py_set_generic(GroupNorm, eps), const_cast<char*>("eps"), NULL},
  9818. {const_cast<char*>("group"), py_get_generic(GroupNorm, group), py_set_generic(GroupNorm, group), const_cast<char*>("group"), NULL},
  9819. {const_cast<char*>("format"), py_get_generic(GroupNorm, format), py_set_generic(GroupNorm, format), const_cast<char*>("format"), NULL},
  9820. {NULL} /* Sentinel */
  9821. };
  9822. PyMethodDef PyOp(GroupNorm)::tp_methods[] = {
  9823. {const_cast<char*>("__getstate__"), PyOp(GroupNorm)::getstate, METH_NOARGS, "GroupNorm getstate"},
  9824. {const_cast<char*>("__setstate__"), PyOp(GroupNorm)::setstate, METH_VARARGS, "GroupNorm setstate"},
  9825. {NULL} /* Sentinel */
  9826. };
  9827. PyObject *PyOp(GroupNorm)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  9828. if (PyOp(GroupNorm)::py_init(self, args, kwds) < 0) {
  9829. return NULL;
  9830. }
  9831. Py_RETURN_NONE;
  9832. }
  9833. PyMethodDef PyOp(GroupNorm)::py_init_methoddef = {
  9834. "__init__",
  9835. (PyCFunction)PyOp(GroupNorm)::py_init_proxy,
  9836. METH_VARARGS | METH_KEYWORDS,
  9837. "__init__(self, affine: bool = ..., eps: float = ..., group: int = ..., format: Union[str, Format] = ...) -> None\n"
  9838. };
  9839. void _init_py_GroupNorm(py::module m) {
  9840. using py_op = PyOp(GroupNorm);
  9841. auto& py_type = PyOpType(GroupNorm);
  9842. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9843. py_type.tp_name = "megengine.core._imperative_rt.ops.GroupNorm";
  9844. py_type.tp_basicsize = sizeof(PyOp(GroupNorm));
  9845. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9846. py_type.tp_doc = "GroupNorm";
  9847. py_type.tp_base = &PyOpType(OpDef);
  9848. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9849. py_type.tp_new = py_new_generic<py_op>;
  9850. py_type.tp_init = py_op::py_init;
  9851. py_type.tp_methods = py_op::tp_methods;
  9852. py_type.tp_getset = py_op::py_getsetters;
  9853. py_type.tp_dict = PyDict_New();
  9854. PyObject* descr = PyDescr_NewMethod(&PyOpType(GroupNorm), &PyOp(GroupNorm)::py_init_methoddef);
  9855. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  9856. mgb_assert(PyType_Ready(&py_type) >= 0);
  9857. _init_py_GroupNorm_Format(py_type);
  9858. PyType_Modified(&py_type);
  9859. m.add_object("GroupNorm", reinterpret_cast<PyObject*>(&py_type));
  9860. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GroupNorm::typeinfo(), &py_type).second);
  9861. }
  9862. PyOpDefBegin(Identity) // {
  9863. static PyGetSetDef py_getsetters[];
  9864. static PyMethodDef tp_methods[];
  9865. static PyObject* getstate(PyObject* self, PyObject*) {
  9866. auto& opdef = reinterpret_cast<PyOp(Identity)*>(self)->inst();
  9867. static_cast<void>(opdef);
  9868. std::unordered_map<std::string, py::object> state {
  9869. };
  9870. return py::cast(state).release().ptr();
  9871. }
  9872. static PyObject* setstate(PyObject* self, PyObject* args) {
  9873. PyObject* dict = PyTuple_GetItem(args, 0);
  9874. if (!dict) return NULL;
  9875. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9876. auto& opdef = reinterpret_cast<PyOp(Identity)*>(self)->inst();
  9877. static_cast<void>(opdef);
  9878. Py_RETURN_NONE;
  9879. }
  9880. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9881. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  9882. static PyMethodDef py_init_methoddef;
  9883. // };
  9884. PyOpDefEnd(Identity)
  9885. int PyOp(Identity)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9886. return 0;
  9887. }
  9888. PyGetSetDef PyOp(Identity)::py_getsetters[] = {
  9889. {NULL} /* Sentinel */
  9890. };
  9891. PyMethodDef PyOp(Identity)::tp_methods[] = {
  9892. {const_cast<char*>("__getstate__"), PyOp(Identity)::getstate, METH_NOARGS, "Identity getstate"},
  9893. {const_cast<char*>("__setstate__"), PyOp(Identity)::setstate, METH_VARARGS, "Identity setstate"},
  9894. {NULL} /* Sentinel */
  9895. };
  9896. PyObject *PyOp(Identity)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  9897. if (PyOp(Identity)::py_init(self, args, kwds) < 0) {
  9898. return NULL;
  9899. }
  9900. Py_RETURN_NONE;
  9901. }
  9902. PyMethodDef PyOp(Identity)::py_init_methoddef = {
  9903. "__init__",
  9904. (PyCFunction)PyOp(Identity)::py_init_proxy,
  9905. METH_VARARGS | METH_KEYWORDS,
  9906. "__init__(self) -> None\n"
  9907. };
  9908. void _init_py_Identity(py::module m) {
  9909. using py_op = PyOp(Identity);
  9910. auto& py_type = PyOpType(Identity);
  9911. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9912. py_type.tp_name = "megengine.core._imperative_rt.ops.Identity";
  9913. py_type.tp_basicsize = sizeof(PyOp(Identity));
  9914. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9915. py_type.tp_doc = "Identity";
  9916. py_type.tp_base = &PyOpType(OpDef);
  9917. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9918. py_type.tp_new = py_new_generic<py_op>;
  9919. py_type.tp_init = py_op::py_init;
  9920. py_type.tp_methods = py_op::tp_methods;
  9921. py_type.tp_getset = py_op::py_getsetters;
  9922. py_type.tp_dict = PyDict_New();
  9923. PyObject* descr = PyDescr_NewMethod(&PyOpType(Identity), &PyOp(Identity)::py_init_methoddef);
  9924. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  9925. mgb_assert(PyType_Ready(&py_type) >= 0);
  9926. PyType_Modified(&py_type);
  9927. m.add_object("Identity", reinterpret_cast<PyObject*>(&py_type));
  9928. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Identity::typeinfo(), &py_type).second);
  9929. }
  9930. PyOpDefBegin(Images2Neibs) // {
  9931. static PyGetSetDef py_getsetters[];
  9932. static PyMethodDef tp_methods[];
  9933. static PyObject* getstate(PyObject* self, PyObject*) {
  9934. auto& opdef = reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst();
  9935. static_cast<void>(opdef);
  9936. std::unordered_map<std::string, py::object> state {
  9937. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  9938. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  9939. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  9940. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  9941. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  9942. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  9943. {"window_h", serialization<decltype(opdef.window_h)>::dump(opdef.window_h)},
  9944. {"window_w", serialization<decltype(opdef.window_w)>::dump(opdef.window_w)}
  9945. };
  9946. return py::cast(state).release().ptr();
  9947. }
  9948. static PyObject* setstate(PyObject* self, PyObject* args) {
  9949. PyObject* dict = PyTuple_GetItem(args, 0);
  9950. if (!dict) return NULL;
  9951. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9952. auto& opdef = reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst();
  9953. static_cast<void>(opdef);
  9954. {
  9955. auto&& iter = state.find("pad_h");
  9956. if (iter != state.end()) {
  9957. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  9958. }
  9959. }
  9960. {
  9961. auto&& iter = state.find("pad_w");
  9962. if (iter != state.end()) {
  9963. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  9964. }
  9965. }
  9966. {
  9967. auto&& iter = state.find("stride_h");
  9968. if (iter != state.end()) {
  9969. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  9970. }
  9971. }
  9972. {
  9973. auto&& iter = state.find("stride_w");
  9974. if (iter != state.end()) {
  9975. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  9976. }
  9977. }
  9978. {
  9979. auto&& iter = state.find("dilate_h");
  9980. if (iter != state.end()) {
  9981. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  9982. }
  9983. }
  9984. {
  9985. auto&& iter = state.find("dilate_w");
  9986. if (iter != state.end()) {
  9987. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  9988. }
  9989. }
  9990. {
  9991. auto&& iter = state.find("window_h");
  9992. if (iter != state.end()) {
  9993. opdef.window_h = serialization<decltype(opdef.window_h)>::load(iter->second);
  9994. }
  9995. }
  9996. {
  9997. auto&& iter = state.find("window_w");
  9998. if (iter != state.end()) {
  9999. opdef.window_w = serialization<decltype(opdef.window_w)>::load(iter->second);
  10000. }
  10001. }
  10002. Py_RETURN_NONE;
  10003. }
  10004. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10005. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  10006. static PyMethodDef py_init_methoddef;
  10007. // };
  10008. PyOpDefEnd(Images2Neibs)
  10009. int PyOp(Images2Neibs)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10010. static const char* kwlist[] = {"pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "window_h", "window_w", "scope", NULL};
  10011. PyObject *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *window_h = NULL, *window_w = NULL, *scope = NULL;
  10012. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &window_h, &window_w, &scope))
  10013. return -1;
  10014. if (pad_h) {
  10015. try {
  10016. // TODO: remove this guard which is used for pybind11 implicit conversion
  10017. py::detail::loader_life_support guard{};
  10018. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().pad_h =
  10019. py::cast<decltype(Images2Neibs::pad_h)>(py::handle(pad_h));
  10020. } CATCH_ALL(-1)
  10021. }
  10022. if (pad_w) {
  10023. try {
  10024. // TODO: remove this guard which is used for pybind11 implicit conversion
  10025. py::detail::loader_life_support guard{};
  10026. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().pad_w =
  10027. py::cast<decltype(Images2Neibs::pad_w)>(py::handle(pad_w));
  10028. } CATCH_ALL(-1)
  10029. }
  10030. if (stride_h) {
  10031. try {
  10032. // TODO: remove this guard which is used for pybind11 implicit conversion
  10033. py::detail::loader_life_support guard{};
  10034. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().stride_h =
  10035. py::cast<decltype(Images2Neibs::stride_h)>(py::handle(stride_h));
  10036. } CATCH_ALL(-1)
  10037. }
  10038. if (stride_w) {
  10039. try {
  10040. // TODO: remove this guard which is used for pybind11 implicit conversion
  10041. py::detail::loader_life_support guard{};
  10042. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().stride_w =
  10043. py::cast<decltype(Images2Neibs::stride_w)>(py::handle(stride_w));
  10044. } CATCH_ALL(-1)
  10045. }
  10046. if (dilate_h) {
  10047. try {
  10048. // TODO: remove this guard which is used for pybind11 implicit conversion
  10049. py::detail::loader_life_support guard{};
  10050. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().dilate_h =
  10051. py::cast<decltype(Images2Neibs::dilate_h)>(py::handle(dilate_h));
  10052. } CATCH_ALL(-1)
  10053. }
  10054. if (dilate_w) {
  10055. try {
  10056. // TODO: remove this guard which is used for pybind11 implicit conversion
  10057. py::detail::loader_life_support guard{};
  10058. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().dilate_w =
  10059. py::cast<decltype(Images2Neibs::dilate_w)>(py::handle(dilate_w));
  10060. } CATCH_ALL(-1)
  10061. }
  10062. if (window_h) {
  10063. try {
  10064. // TODO: remove this guard which is used for pybind11 implicit conversion
  10065. py::detail::loader_life_support guard{};
  10066. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().window_h =
  10067. py::cast<decltype(Images2Neibs::window_h)>(py::handle(window_h));
  10068. } CATCH_ALL(-1)
  10069. }
  10070. if (window_w) {
  10071. try {
  10072. // TODO: remove this guard which is used for pybind11 implicit conversion
  10073. py::detail::loader_life_support guard{};
  10074. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().window_w =
  10075. py::cast<decltype(Images2Neibs::window_w)>(py::handle(window_w));
  10076. } CATCH_ALL(-1)
  10077. }
  10078. if (scope) {
  10079. try {
  10080. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10081. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10082. } CATCH_ALL(-1)
  10083. }
  10084. return 0;
  10085. }
  10086. PyGetSetDef PyOp(Images2Neibs)::py_getsetters[] = {
  10087. {const_cast<char*>("pad_h"), py_get_generic(Images2Neibs, pad_h), py_set_generic(Images2Neibs, pad_h), const_cast<char*>("pad_h"), NULL},
  10088. {const_cast<char*>("pad_w"), py_get_generic(Images2Neibs, pad_w), py_set_generic(Images2Neibs, pad_w), const_cast<char*>("pad_w"), NULL},
  10089. {const_cast<char*>("stride_h"), py_get_generic(Images2Neibs, stride_h), py_set_generic(Images2Neibs, stride_h), const_cast<char*>("stride_h"), NULL},
  10090. {const_cast<char*>("stride_w"), py_get_generic(Images2Neibs, stride_w), py_set_generic(Images2Neibs, stride_w), const_cast<char*>("stride_w"), NULL},
  10091. {const_cast<char*>("dilate_h"), py_get_generic(Images2Neibs, dilate_h), py_set_generic(Images2Neibs, dilate_h), const_cast<char*>("dilate_h"), NULL},
  10092. {const_cast<char*>("dilate_w"), py_get_generic(Images2Neibs, dilate_w), py_set_generic(Images2Neibs, dilate_w), const_cast<char*>("dilate_w"), NULL},
  10093. {const_cast<char*>("window_h"), py_get_generic(Images2Neibs, window_h), py_set_generic(Images2Neibs, window_h), const_cast<char*>("window_h"), NULL},
  10094. {const_cast<char*>("window_w"), py_get_generic(Images2Neibs, window_w), py_set_generic(Images2Neibs, window_w), const_cast<char*>("window_w"), NULL},
  10095. {NULL} /* Sentinel */
  10096. };
  10097. PyMethodDef PyOp(Images2Neibs)::tp_methods[] = {
  10098. {const_cast<char*>("__getstate__"), PyOp(Images2Neibs)::getstate, METH_NOARGS, "Images2Neibs getstate"},
  10099. {const_cast<char*>("__setstate__"), PyOp(Images2Neibs)::setstate, METH_VARARGS, "Images2Neibs setstate"},
  10100. {NULL} /* Sentinel */
  10101. };
  10102. PyObject *PyOp(Images2Neibs)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  10103. if (PyOp(Images2Neibs)::py_init(self, args, kwds) < 0) {
  10104. return NULL;
  10105. }
  10106. Py_RETURN_NONE;
  10107. }
  10108. PyMethodDef PyOp(Images2Neibs)::py_init_methoddef = {
  10109. "__init__",
  10110. (PyCFunction)PyOp(Images2Neibs)::py_init_proxy,
  10111. METH_VARARGS | METH_KEYWORDS,
  10112. "__init__(self, pad_h: int = ..., pad_w: int = ..., stride_h: int = ..., stride_w: int = ..., dilate_h: int = ..., dilate_w: int = ..., window_h: int = ..., window_w: int = ...) -> None\n"
  10113. };
  10114. void _init_py_Images2Neibs(py::module m) {
  10115. using py_op = PyOp(Images2Neibs);
  10116. auto& py_type = PyOpType(Images2Neibs);
  10117. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10118. py_type.tp_name = "megengine.core._imperative_rt.ops.Images2Neibs";
  10119. py_type.tp_basicsize = sizeof(PyOp(Images2Neibs));
  10120. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10121. py_type.tp_doc = "Images2Neibs";
  10122. py_type.tp_base = &PyOpType(OpDef);
  10123. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10124. py_type.tp_new = py_new_generic<py_op>;
  10125. py_type.tp_init = py_op::py_init;
  10126. py_type.tp_methods = py_op::tp_methods;
  10127. py_type.tp_getset = py_op::py_getsetters;
  10128. py_type.tp_dict = PyDict_New();
  10129. PyObject* descr = PyDescr_NewMethod(&PyOpType(Images2Neibs), &PyOp(Images2Neibs)::py_init_methoddef);
  10130. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  10131. mgb_assert(PyType_Ready(&py_type) >= 0);
  10132. PyType_Modified(&py_type);
  10133. m.add_object("Images2Neibs", reinterpret_cast<PyObject*>(&py_type));
  10134. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Images2Neibs::typeinfo(), &py_type).second);
  10135. }
  10136. PyOpDefBegin(IncrMeshIndexing) // {
  10137. static PyGetSetDef py_getsetters[];
  10138. static PyMethodDef tp_methods[];
  10139. static PyObject* getstate(PyObject* self, PyObject*) {
  10140. auto& opdef = reinterpret_cast<PyOp(IncrMeshIndexing)*>(self)->inst();
  10141. static_cast<void>(opdef);
  10142. std::unordered_map<std::string, py::object> state {
  10143. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  10144. };
  10145. return py::cast(state).release().ptr();
  10146. }
  10147. static PyObject* setstate(PyObject* self, PyObject* args) {
  10148. PyObject* dict = PyTuple_GetItem(args, 0);
  10149. if (!dict) return NULL;
  10150. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10151. auto& opdef = reinterpret_cast<PyOp(IncrMeshIndexing)*>(self)->inst();
  10152. static_cast<void>(opdef);
  10153. {
  10154. auto&& iter = state.find("items");
  10155. if (iter != state.end()) {
  10156. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  10157. }
  10158. }
  10159. Py_RETURN_NONE;
  10160. }
  10161. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10162. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  10163. static PyMethodDef py_init_methoddef;
  10164. // };
  10165. PyOpDefEnd(IncrMeshIndexing)
  10166. int PyOp(IncrMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10167. static const char* kwlist[] = {"items", "scope", NULL};
  10168. PyObject *items = NULL, *scope = NULL;
  10169. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  10170. return -1;
  10171. if (items) {
  10172. try {
  10173. // TODO: remove this guard which is used for pybind11 implicit conversion
  10174. py::detail::loader_life_support guard{};
  10175. reinterpret_cast<PyOp(IncrMeshIndexing)*>(self)->inst().items =
  10176. py::cast<decltype(IncrMeshIndexing::items)>(py::handle(items));
  10177. } CATCH_ALL(-1)
  10178. }
  10179. if (scope) {
  10180. try {
  10181. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10182. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10183. } CATCH_ALL(-1)
  10184. }
  10185. return 0;
  10186. }
  10187. PyGetSetDef PyOp(IncrMeshIndexing)::py_getsetters[] = {
  10188. {const_cast<char*>("items"), py_get_generic(IncrMeshIndexing, items), py_set_generic(IncrMeshIndexing, items), const_cast<char*>("items"), NULL},
  10189. {NULL} /* Sentinel */
  10190. };
  10191. PyMethodDef PyOp(IncrMeshIndexing)::tp_methods[] = {
  10192. {const_cast<char*>("__getstate__"), PyOp(IncrMeshIndexing)::getstate, METH_NOARGS, "IncrMeshIndexing getstate"},
  10193. {const_cast<char*>("__setstate__"), PyOp(IncrMeshIndexing)::setstate, METH_VARARGS, "IncrMeshIndexing setstate"},
  10194. {NULL} /* Sentinel */
  10195. };
  10196. PyObject *PyOp(IncrMeshIndexing)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  10197. if (PyOp(IncrMeshIndexing)::py_init(self, args, kwds) < 0) {
  10198. return NULL;
  10199. }
  10200. Py_RETURN_NONE;
  10201. }
  10202. PyMethodDef PyOp(IncrMeshIndexing)::py_init_methoddef = {
  10203. "__init__",
  10204. (PyCFunction)PyOp(IncrMeshIndexing)::py_init_proxy,
  10205. METH_VARARGS | METH_KEYWORDS,
  10206. "__init__(self, items: list[tuple[int, bool, bool, bool, bool]] = ...) -> None\n"
  10207. };
  10208. void _init_py_IncrMeshIndexing(py::module m) {
  10209. using py_op = PyOp(IncrMeshIndexing);
  10210. auto& py_type = PyOpType(IncrMeshIndexing);
  10211. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10212. py_type.tp_name = "megengine.core._imperative_rt.ops.IncrMeshIndexing";
  10213. py_type.tp_basicsize = sizeof(PyOp(IncrMeshIndexing));
  10214. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10215. py_type.tp_doc = "IncrMeshIndexing";
  10216. py_type.tp_base = &PyOpType(OpDef);
  10217. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10218. py_type.tp_new = py_new_generic<py_op>;
  10219. py_type.tp_init = py_op::py_init;
  10220. py_type.tp_methods = py_op::tp_methods;
  10221. py_type.tp_getset = py_op::py_getsetters;
  10222. py_type.tp_dict = PyDict_New();
  10223. PyObject* descr = PyDescr_NewMethod(&PyOpType(IncrMeshIndexing), &PyOp(IncrMeshIndexing)::py_init_methoddef);
  10224. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  10225. mgb_assert(PyType_Ready(&py_type) >= 0);
  10226. PyType_Modified(&py_type);
  10227. m.add_object("IncrMeshIndexing", reinterpret_cast<PyObject*>(&py_type));
  10228. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IncrMeshIndexing::typeinfo(), &py_type).second);
  10229. }
  10230. PyOpDefBegin(IncrSubtensor) // {
  10231. static PyGetSetDef py_getsetters[];
  10232. static PyMethodDef tp_methods[];
  10233. static PyObject* getstate(PyObject* self, PyObject*) {
  10234. auto& opdef = reinterpret_cast<PyOp(IncrSubtensor)*>(self)->inst();
  10235. static_cast<void>(opdef);
  10236. std::unordered_map<std::string, py::object> state {
  10237. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  10238. };
  10239. return py::cast(state).release().ptr();
  10240. }
  10241. static PyObject* setstate(PyObject* self, PyObject* args) {
  10242. PyObject* dict = PyTuple_GetItem(args, 0);
  10243. if (!dict) return NULL;
  10244. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10245. auto& opdef = reinterpret_cast<PyOp(IncrSubtensor)*>(self)->inst();
  10246. static_cast<void>(opdef);
  10247. {
  10248. auto&& iter = state.find("items");
  10249. if (iter != state.end()) {
  10250. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  10251. }
  10252. }
  10253. Py_RETURN_NONE;
  10254. }
  10255. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10256. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  10257. static PyMethodDef py_init_methoddef;
  10258. // };
  10259. PyOpDefEnd(IncrSubtensor)
  10260. int PyOp(IncrSubtensor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10261. static const char* kwlist[] = {"items", "scope", NULL};
  10262. PyObject *items = NULL, *scope = NULL;
  10263. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  10264. return -1;
  10265. if (items) {
  10266. try {
  10267. // TODO: remove this guard which is used for pybind11 implicit conversion
  10268. py::detail::loader_life_support guard{};
  10269. reinterpret_cast<PyOp(IncrSubtensor)*>(self)->inst().items =
  10270. py::cast<decltype(IncrSubtensor::items)>(py::handle(items));
  10271. } CATCH_ALL(-1)
  10272. }
  10273. if (scope) {
  10274. try {
  10275. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10276. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10277. } CATCH_ALL(-1)
  10278. }
  10279. return 0;
  10280. }
  10281. PyGetSetDef PyOp(IncrSubtensor)::py_getsetters[] = {
  10282. {const_cast<char*>("items"), py_get_generic(IncrSubtensor, items), py_set_generic(IncrSubtensor, items), const_cast<char*>("items"), NULL},
  10283. {NULL} /* Sentinel */
  10284. };
  10285. PyMethodDef PyOp(IncrSubtensor)::tp_methods[] = {
  10286. {const_cast<char*>("__getstate__"), PyOp(IncrSubtensor)::getstate, METH_NOARGS, "IncrSubtensor getstate"},
  10287. {const_cast<char*>("__setstate__"), PyOp(IncrSubtensor)::setstate, METH_VARARGS, "IncrSubtensor setstate"},
  10288. {NULL} /* Sentinel */
  10289. };
  10290. PyObject *PyOp(IncrSubtensor)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  10291. if (PyOp(IncrSubtensor)::py_init(self, args, kwds) < 0) {
  10292. return NULL;
  10293. }
  10294. Py_RETURN_NONE;
  10295. }
  10296. PyMethodDef PyOp(IncrSubtensor)::py_init_methoddef = {
  10297. "__init__",
  10298. (PyCFunction)PyOp(IncrSubtensor)::py_init_proxy,
  10299. METH_VARARGS | METH_KEYWORDS,
  10300. "__init__(self, items: list[tuple[int, bool, bool, bool, bool]] = ...) -> None\n"
  10301. };
  10302. void _init_py_IncrSubtensor(py::module m) {
  10303. using py_op = PyOp(IncrSubtensor);
  10304. auto& py_type = PyOpType(IncrSubtensor);
  10305. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10306. py_type.tp_name = "megengine.core._imperative_rt.ops.IncrSubtensor";
  10307. py_type.tp_basicsize = sizeof(PyOp(IncrSubtensor));
  10308. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10309. py_type.tp_doc = "IncrSubtensor";
  10310. py_type.tp_base = &PyOpType(OpDef);
  10311. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10312. py_type.tp_new = py_new_generic<py_op>;
  10313. py_type.tp_init = py_op::py_init;
  10314. py_type.tp_methods = py_op::tp_methods;
  10315. py_type.tp_getset = py_op::py_getsetters;
  10316. py_type.tp_dict = PyDict_New();
  10317. PyObject* descr = PyDescr_NewMethod(&PyOpType(IncrSubtensor), &PyOp(IncrSubtensor)::py_init_methoddef);
  10318. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  10319. mgb_assert(PyType_Ready(&py_type) >= 0);
  10320. PyType_Modified(&py_type);
  10321. m.add_object("IncrSubtensor", reinterpret_cast<PyObject*>(&py_type));
  10322. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IncrSubtensor::typeinfo(), &py_type).second);
  10323. }
  10324. PyOpDefBegin(IndexingIncrMultiAxisVec) // {
  10325. static PyGetSetDef py_getsetters[];
  10326. static PyMethodDef tp_methods[];
  10327. static PyObject* getstate(PyObject* self, PyObject*) {
  10328. auto& opdef = reinterpret_cast<PyOp(IndexingIncrMultiAxisVec)*>(self)->inst();
  10329. static_cast<void>(opdef);
  10330. std::unordered_map<std::string, py::object> state {
  10331. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  10332. };
  10333. return py::cast(state).release().ptr();
  10334. }
  10335. static PyObject* setstate(PyObject* self, PyObject* args) {
  10336. PyObject* dict = PyTuple_GetItem(args, 0);
  10337. if (!dict) return NULL;
  10338. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10339. auto& opdef = reinterpret_cast<PyOp(IndexingIncrMultiAxisVec)*>(self)->inst();
  10340. static_cast<void>(opdef);
  10341. {
  10342. auto&& iter = state.find("items");
  10343. if (iter != state.end()) {
  10344. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  10345. }
  10346. }
  10347. Py_RETURN_NONE;
  10348. }
  10349. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10350. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  10351. static PyMethodDef py_init_methoddef;
  10352. // };
  10353. PyOpDefEnd(IndexingIncrMultiAxisVec)
  10354. int PyOp(IndexingIncrMultiAxisVec)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10355. static const char* kwlist[] = {"items", "scope", NULL};
  10356. PyObject *items = NULL, *scope = NULL;
  10357. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  10358. return -1;
  10359. if (items) {
  10360. try {
  10361. // TODO: remove this guard which is used for pybind11 implicit conversion
  10362. py::detail::loader_life_support guard{};
  10363. reinterpret_cast<PyOp(IndexingIncrMultiAxisVec)*>(self)->inst().items =
  10364. py::cast<decltype(IndexingIncrMultiAxisVec::items)>(py::handle(items));
  10365. } CATCH_ALL(-1)
  10366. }
  10367. if (scope) {
  10368. try {
  10369. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10370. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10371. } CATCH_ALL(-1)
  10372. }
  10373. return 0;
  10374. }
  10375. PyGetSetDef PyOp(IndexingIncrMultiAxisVec)::py_getsetters[] = {
  10376. {const_cast<char*>("items"), py_get_generic(IndexingIncrMultiAxisVec, items), py_set_generic(IndexingIncrMultiAxisVec, items), const_cast<char*>("items"), NULL},
  10377. {NULL} /* Sentinel */
  10378. };
  10379. PyMethodDef PyOp(IndexingIncrMultiAxisVec)::tp_methods[] = {
  10380. {const_cast<char*>("__getstate__"), PyOp(IndexingIncrMultiAxisVec)::getstate, METH_NOARGS, "IndexingIncrMultiAxisVec getstate"},
  10381. {const_cast<char*>("__setstate__"), PyOp(IndexingIncrMultiAxisVec)::setstate, METH_VARARGS, "IndexingIncrMultiAxisVec setstate"},
  10382. {NULL} /* Sentinel */
  10383. };
  10384. PyObject *PyOp(IndexingIncrMultiAxisVec)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  10385. if (PyOp(IndexingIncrMultiAxisVec)::py_init(self, args, kwds) < 0) {
  10386. return NULL;
  10387. }
  10388. Py_RETURN_NONE;
  10389. }
  10390. PyMethodDef PyOp(IndexingIncrMultiAxisVec)::py_init_methoddef = {
  10391. "__init__",
  10392. (PyCFunction)PyOp(IndexingIncrMultiAxisVec)::py_init_proxy,
  10393. METH_VARARGS | METH_KEYWORDS,
  10394. "__init__(self, items: list[tuple[int, bool, bool, bool, bool]] = ...) -> None\n"
  10395. };
  10396. void _init_py_IndexingIncrMultiAxisVec(py::module m) {
  10397. using py_op = PyOp(IndexingIncrMultiAxisVec);
  10398. auto& py_type = PyOpType(IndexingIncrMultiAxisVec);
  10399. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10400. py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingIncrMultiAxisVec";
  10401. py_type.tp_basicsize = sizeof(PyOp(IndexingIncrMultiAxisVec));
  10402. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10403. py_type.tp_doc = "IndexingIncrMultiAxisVec";
  10404. py_type.tp_base = &PyOpType(OpDef);
  10405. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10406. py_type.tp_new = py_new_generic<py_op>;
  10407. py_type.tp_init = py_op::py_init;
  10408. py_type.tp_methods = py_op::tp_methods;
  10409. py_type.tp_getset = py_op::py_getsetters;
  10410. py_type.tp_dict = PyDict_New();
  10411. PyObject* descr = PyDescr_NewMethod(&PyOpType(IndexingIncrMultiAxisVec), &PyOp(IndexingIncrMultiAxisVec)::py_init_methoddef);
  10412. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  10413. mgb_assert(PyType_Ready(&py_type) >= 0);
  10414. PyType_Modified(&py_type);
  10415. m.add_object("IndexingIncrMultiAxisVec", reinterpret_cast<PyObject*>(&py_type));
  10416. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingIncrMultiAxisVec::typeinfo(), &py_type).second);
  10417. }
  10418. PyOpDefBegin(IndexingMultiAxisVec) // {
  10419. static PyGetSetDef py_getsetters[];
  10420. static PyMethodDef tp_methods[];
  10421. static PyObject* getstate(PyObject* self, PyObject*) {
  10422. auto& opdef = reinterpret_cast<PyOp(IndexingMultiAxisVec)*>(self)->inst();
  10423. static_cast<void>(opdef);
  10424. std::unordered_map<std::string, py::object> state {
  10425. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  10426. };
  10427. return py::cast(state).release().ptr();
  10428. }
  10429. static PyObject* setstate(PyObject* self, PyObject* args) {
  10430. PyObject* dict = PyTuple_GetItem(args, 0);
  10431. if (!dict) return NULL;
  10432. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10433. auto& opdef = reinterpret_cast<PyOp(IndexingMultiAxisVec)*>(self)->inst();
  10434. static_cast<void>(opdef);
  10435. {
  10436. auto&& iter = state.find("items");
  10437. if (iter != state.end()) {
  10438. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  10439. }
  10440. }
  10441. Py_RETURN_NONE;
  10442. }
  10443. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10444. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  10445. static PyMethodDef py_init_methoddef;
  10446. // };
  10447. PyOpDefEnd(IndexingMultiAxisVec)
  10448. int PyOp(IndexingMultiAxisVec)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10449. static const char* kwlist[] = {"items", "scope", NULL};
  10450. PyObject *items = NULL, *scope = NULL;
  10451. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  10452. return -1;
  10453. if (items) {
  10454. try {
  10455. // TODO: remove this guard which is used for pybind11 implicit conversion
  10456. py::detail::loader_life_support guard{};
  10457. reinterpret_cast<PyOp(IndexingMultiAxisVec)*>(self)->inst().items =
  10458. py::cast<decltype(IndexingMultiAxisVec::items)>(py::handle(items));
  10459. } CATCH_ALL(-1)
  10460. }
  10461. if (scope) {
  10462. try {
  10463. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10464. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10465. } CATCH_ALL(-1)
  10466. }
  10467. return 0;
  10468. }
  10469. PyGetSetDef PyOp(IndexingMultiAxisVec)::py_getsetters[] = {
  10470. {const_cast<char*>("items"), py_get_generic(IndexingMultiAxisVec, items), py_set_generic(IndexingMultiAxisVec, items), const_cast<char*>("items"), NULL},
  10471. {NULL} /* Sentinel */
  10472. };
  10473. PyMethodDef PyOp(IndexingMultiAxisVec)::tp_methods[] = {
  10474. {const_cast<char*>("__getstate__"), PyOp(IndexingMultiAxisVec)::getstate, METH_NOARGS, "IndexingMultiAxisVec getstate"},
  10475. {const_cast<char*>("__setstate__"), PyOp(IndexingMultiAxisVec)::setstate, METH_VARARGS, "IndexingMultiAxisVec setstate"},
  10476. {NULL} /* Sentinel */
  10477. };
  10478. PyObject *PyOp(IndexingMultiAxisVec)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  10479. if (PyOp(IndexingMultiAxisVec)::py_init(self, args, kwds) < 0) {
  10480. return NULL;
  10481. }
  10482. Py_RETURN_NONE;
  10483. }
  10484. PyMethodDef PyOp(IndexingMultiAxisVec)::py_init_methoddef = {
  10485. "__init__",
  10486. (PyCFunction)PyOp(IndexingMultiAxisVec)::py_init_proxy,
  10487. METH_VARARGS | METH_KEYWORDS,
  10488. "__init__(self, items: list[tuple[int, bool, bool, bool, bool]] = ...) -> None\n"
  10489. };
  10490. void _init_py_IndexingMultiAxisVec(py::module m) {
  10491. using py_op = PyOp(IndexingMultiAxisVec);
  10492. auto& py_type = PyOpType(IndexingMultiAxisVec);
  10493. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10494. py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingMultiAxisVec";
  10495. py_type.tp_basicsize = sizeof(PyOp(IndexingMultiAxisVec));
  10496. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10497. py_type.tp_doc = "IndexingMultiAxisVec";
  10498. py_type.tp_base = &PyOpType(OpDef);
  10499. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10500. py_type.tp_new = py_new_generic<py_op>;
  10501. py_type.tp_init = py_op::py_init;
  10502. py_type.tp_methods = py_op::tp_methods;
  10503. py_type.tp_getset = py_op::py_getsetters;
  10504. py_type.tp_dict = PyDict_New();
  10505. PyObject* descr = PyDescr_NewMethod(&PyOpType(IndexingMultiAxisVec), &PyOp(IndexingMultiAxisVec)::py_init_methoddef);
  10506. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  10507. mgb_assert(PyType_Ready(&py_type) >= 0);
  10508. PyType_Modified(&py_type);
  10509. m.add_object("IndexingMultiAxisVec", reinterpret_cast<PyObject*>(&py_type));
  10510. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingMultiAxisVec::typeinfo(), &py_type).second);
  10511. }
  10512. PyOpDefBegin(IndexingOneHot) // {
  10513. static PyGetSetDef py_getsetters[];
  10514. static PyMethodDef tp_methods[];
  10515. static PyObject* getstate(PyObject* self, PyObject*) {
  10516. auto& opdef = reinterpret_cast<PyOp(IndexingOneHot)*>(self)->inst();
  10517. static_cast<void>(opdef);
  10518. std::unordered_map<std::string, py::object> state {
  10519. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  10520. {"ndim", serialization<decltype(opdef.ndim)>::dump(opdef.ndim)}
  10521. };
  10522. return py::cast(state).release().ptr();
  10523. }
  10524. static PyObject* setstate(PyObject* self, PyObject* args) {
  10525. PyObject* dict = PyTuple_GetItem(args, 0);
  10526. if (!dict) return NULL;
  10527. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10528. auto& opdef = reinterpret_cast<PyOp(IndexingOneHot)*>(self)->inst();
  10529. static_cast<void>(opdef);
  10530. {
  10531. auto&& iter = state.find("axis");
  10532. if (iter != state.end()) {
  10533. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  10534. }
  10535. }
  10536. {
  10537. auto&& iter = state.find("ndim");
  10538. if (iter != state.end()) {
  10539. opdef.ndim = serialization<decltype(opdef.ndim)>::load(iter->second);
  10540. }
  10541. }
  10542. Py_RETURN_NONE;
  10543. }
  10544. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10545. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  10546. static PyMethodDef py_init_methoddef;
  10547. // };
  10548. PyOpDefEnd(IndexingOneHot)
  10549. int PyOp(IndexingOneHot)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10550. static const char* kwlist[] = {"axis", "ndim", "scope", NULL};
  10551. PyObject *axis = NULL, *ndim = NULL, *scope = NULL;
  10552. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &axis, &ndim, &scope))
  10553. return -1;
  10554. if (axis) {
  10555. try {
  10556. // TODO: remove this guard which is used for pybind11 implicit conversion
  10557. py::detail::loader_life_support guard{};
  10558. reinterpret_cast<PyOp(IndexingOneHot)*>(self)->inst().axis =
  10559. py::cast<decltype(IndexingOneHot::axis)>(py::handle(axis));
  10560. } CATCH_ALL(-1)
  10561. }
  10562. if (ndim) {
  10563. try {
  10564. // TODO: remove this guard which is used for pybind11 implicit conversion
  10565. py::detail::loader_life_support guard{};
  10566. reinterpret_cast<PyOp(IndexingOneHot)*>(self)->inst().ndim =
  10567. py::cast<decltype(IndexingOneHot::ndim)>(py::handle(ndim));
  10568. } CATCH_ALL(-1)
  10569. }
  10570. if (scope) {
  10571. try {
  10572. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10573. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10574. } CATCH_ALL(-1)
  10575. }
  10576. return 0;
  10577. }
  10578. PyGetSetDef PyOp(IndexingOneHot)::py_getsetters[] = {
  10579. {const_cast<char*>("axis"), py_get_generic(IndexingOneHot, axis), py_set_generic(IndexingOneHot, axis), const_cast<char*>("axis"), NULL},
  10580. {const_cast<char*>("ndim"), py_get_generic(IndexingOneHot, ndim), py_set_generic(IndexingOneHot, ndim), const_cast<char*>("ndim"), NULL},
  10581. {NULL} /* Sentinel */
  10582. };
  10583. PyMethodDef PyOp(IndexingOneHot)::tp_methods[] = {
  10584. {const_cast<char*>("__getstate__"), PyOp(IndexingOneHot)::getstate, METH_NOARGS, "IndexingOneHot getstate"},
  10585. {const_cast<char*>("__setstate__"), PyOp(IndexingOneHot)::setstate, METH_VARARGS, "IndexingOneHot setstate"},
  10586. {NULL} /* Sentinel */
  10587. };
  10588. PyObject *PyOp(IndexingOneHot)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  10589. if (PyOp(IndexingOneHot)::py_init(self, args, kwds) < 0) {
  10590. return NULL;
  10591. }
  10592. Py_RETURN_NONE;
  10593. }
  10594. PyMethodDef PyOp(IndexingOneHot)::py_init_methoddef = {
  10595. "__init__",
  10596. (PyCFunction)PyOp(IndexingOneHot)::py_init_proxy,
  10597. METH_VARARGS | METH_KEYWORDS,
  10598. "__init__(self, axis: int = ..., ndim: int = ...) -> None\n"
  10599. };
  10600. void _init_py_IndexingOneHot(py::module m) {
  10601. using py_op = PyOp(IndexingOneHot);
  10602. auto& py_type = PyOpType(IndexingOneHot);
  10603. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10604. py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingOneHot";
  10605. py_type.tp_basicsize = sizeof(PyOp(IndexingOneHot));
  10606. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10607. py_type.tp_doc = "IndexingOneHot";
  10608. py_type.tp_base = &PyOpType(OpDef);
  10609. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10610. py_type.tp_new = py_new_generic<py_op>;
  10611. py_type.tp_init = py_op::py_init;
  10612. py_type.tp_methods = py_op::tp_methods;
  10613. py_type.tp_getset = py_op::py_getsetters;
  10614. py_type.tp_dict = PyDict_New();
  10615. PyObject* descr = PyDescr_NewMethod(&PyOpType(IndexingOneHot), &PyOp(IndexingOneHot)::py_init_methoddef);
  10616. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  10617. mgb_assert(PyType_Ready(&py_type) >= 0);
  10618. PyType_Modified(&py_type);
  10619. m.add_object("IndexingOneHot", reinterpret_cast<PyObject*>(&py_type));
  10620. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingOneHot::typeinfo(), &py_type).second);
  10621. }
  10622. PyOpDefBegin(IndexingSetMultiAxisVec) // {
  10623. static PyGetSetDef py_getsetters[];
  10624. static PyMethodDef tp_methods[];
  10625. static PyObject* getstate(PyObject* self, PyObject*) {
  10626. auto& opdef = reinterpret_cast<PyOp(IndexingSetMultiAxisVec)*>(self)->inst();
  10627. static_cast<void>(opdef);
  10628. std::unordered_map<std::string, py::object> state {
  10629. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  10630. };
  10631. return py::cast(state).release().ptr();
  10632. }
  10633. static PyObject* setstate(PyObject* self, PyObject* args) {
  10634. PyObject* dict = PyTuple_GetItem(args, 0);
  10635. if (!dict) return NULL;
  10636. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10637. auto& opdef = reinterpret_cast<PyOp(IndexingSetMultiAxisVec)*>(self)->inst();
  10638. static_cast<void>(opdef);
  10639. {
  10640. auto&& iter = state.find("items");
  10641. if (iter != state.end()) {
  10642. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  10643. }
  10644. }
  10645. Py_RETURN_NONE;
  10646. }
  10647. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10648. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  10649. static PyMethodDef py_init_methoddef;
  10650. // };
  10651. PyOpDefEnd(IndexingSetMultiAxisVec)
  10652. int PyOp(IndexingSetMultiAxisVec)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10653. static const char* kwlist[] = {"items", "scope", NULL};
  10654. PyObject *items = NULL, *scope = NULL;
  10655. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  10656. return -1;
  10657. if (items) {
  10658. try {
  10659. // TODO: remove this guard which is used for pybind11 implicit conversion
  10660. py::detail::loader_life_support guard{};
  10661. reinterpret_cast<PyOp(IndexingSetMultiAxisVec)*>(self)->inst().items =
  10662. py::cast<decltype(IndexingSetMultiAxisVec::items)>(py::handle(items));
  10663. } CATCH_ALL(-1)
  10664. }
  10665. if (scope) {
  10666. try {
  10667. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10668. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10669. } CATCH_ALL(-1)
  10670. }
  10671. return 0;
  10672. }
  10673. PyGetSetDef PyOp(IndexingSetMultiAxisVec)::py_getsetters[] = {
  10674. {const_cast<char*>("items"), py_get_generic(IndexingSetMultiAxisVec, items), py_set_generic(IndexingSetMultiAxisVec, items), const_cast<char*>("items"), NULL},
  10675. {NULL} /* Sentinel */
  10676. };
  10677. PyMethodDef PyOp(IndexingSetMultiAxisVec)::tp_methods[] = {
  10678. {const_cast<char*>("__getstate__"), PyOp(IndexingSetMultiAxisVec)::getstate, METH_NOARGS, "IndexingSetMultiAxisVec getstate"},
  10679. {const_cast<char*>("__setstate__"), PyOp(IndexingSetMultiAxisVec)::setstate, METH_VARARGS, "IndexingSetMultiAxisVec setstate"},
  10680. {NULL} /* Sentinel */
  10681. };
  10682. PyObject *PyOp(IndexingSetMultiAxisVec)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  10683. if (PyOp(IndexingSetMultiAxisVec)::py_init(self, args, kwds) < 0) {
  10684. return NULL;
  10685. }
  10686. Py_RETURN_NONE;
  10687. }
  10688. PyMethodDef PyOp(IndexingSetMultiAxisVec)::py_init_methoddef = {
  10689. "__init__",
  10690. (PyCFunction)PyOp(IndexingSetMultiAxisVec)::py_init_proxy,
  10691. METH_VARARGS | METH_KEYWORDS,
  10692. "__init__(self, items: list[tuple[int, bool, bool, bool, bool]] = ...) -> None\n"
  10693. };
  10694. void _init_py_IndexingSetMultiAxisVec(py::module m) {
  10695. using py_op = PyOp(IndexingSetMultiAxisVec);
  10696. auto& py_type = PyOpType(IndexingSetMultiAxisVec);
  10697. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10698. py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingSetMultiAxisVec";
  10699. py_type.tp_basicsize = sizeof(PyOp(IndexingSetMultiAxisVec));
  10700. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10701. py_type.tp_doc = "IndexingSetMultiAxisVec";
  10702. py_type.tp_base = &PyOpType(OpDef);
  10703. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10704. py_type.tp_new = py_new_generic<py_op>;
  10705. py_type.tp_init = py_op::py_init;
  10706. py_type.tp_methods = py_op::tp_methods;
  10707. py_type.tp_getset = py_op::py_getsetters;
  10708. py_type.tp_dict = PyDict_New();
  10709. PyObject* descr = PyDescr_NewMethod(&PyOpType(IndexingSetMultiAxisVec), &PyOp(IndexingSetMultiAxisVec)::py_init_methoddef);
  10710. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  10711. mgb_assert(PyType_Ready(&py_type) >= 0);
  10712. PyType_Modified(&py_type);
  10713. m.add_object("IndexingSetMultiAxisVec", reinterpret_cast<PyObject*>(&py_type));
  10714. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingSetMultiAxisVec::typeinfo(), &py_type).second);
  10715. }
  10716. PyOpDefBegin(IndexingSetOneHot) // {
  10717. static PyGetSetDef py_getsetters[];
  10718. static PyMethodDef tp_methods[];
  10719. static PyObject* getstate(PyObject* self, PyObject*) {
  10720. auto& opdef = reinterpret_cast<PyOp(IndexingSetOneHot)*>(self)->inst();
  10721. static_cast<void>(opdef);
  10722. std::unordered_map<std::string, py::object> state {
  10723. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  10724. {"ndim", serialization<decltype(opdef.ndim)>::dump(opdef.ndim)}
  10725. };
  10726. return py::cast(state).release().ptr();
  10727. }
  10728. static PyObject* setstate(PyObject* self, PyObject* args) {
  10729. PyObject* dict = PyTuple_GetItem(args, 0);
  10730. if (!dict) return NULL;
  10731. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10732. auto& opdef = reinterpret_cast<PyOp(IndexingSetOneHot)*>(self)->inst();
  10733. static_cast<void>(opdef);
  10734. {
  10735. auto&& iter = state.find("axis");
  10736. if (iter != state.end()) {
  10737. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  10738. }
  10739. }
  10740. {
  10741. auto&& iter = state.find("ndim");
  10742. if (iter != state.end()) {
  10743. opdef.ndim = serialization<decltype(opdef.ndim)>::load(iter->second);
  10744. }
  10745. }
  10746. Py_RETURN_NONE;
  10747. }
  10748. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10749. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  10750. static PyMethodDef py_init_methoddef;
  10751. // };
  10752. PyOpDefEnd(IndexingSetOneHot)
  10753. int PyOp(IndexingSetOneHot)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10754. static const char* kwlist[] = {"axis", "ndim", "scope", NULL};
  10755. PyObject *axis = NULL, *ndim = NULL, *scope = NULL;
  10756. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &axis, &ndim, &scope))
  10757. return -1;
  10758. if (axis) {
  10759. try {
  10760. // TODO: remove this guard which is used for pybind11 implicit conversion
  10761. py::detail::loader_life_support guard{};
  10762. reinterpret_cast<PyOp(IndexingSetOneHot)*>(self)->inst().axis =
  10763. py::cast<decltype(IndexingSetOneHot::axis)>(py::handle(axis));
  10764. } CATCH_ALL(-1)
  10765. }
  10766. if (ndim) {
  10767. try {
  10768. // TODO: remove this guard which is used for pybind11 implicit conversion
  10769. py::detail::loader_life_support guard{};
  10770. reinterpret_cast<PyOp(IndexingSetOneHot)*>(self)->inst().ndim =
  10771. py::cast<decltype(IndexingSetOneHot::ndim)>(py::handle(ndim));
  10772. } CATCH_ALL(-1)
  10773. }
  10774. if (scope) {
  10775. try {
  10776. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10777. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10778. } CATCH_ALL(-1)
  10779. }
  10780. return 0;
  10781. }
  10782. PyGetSetDef PyOp(IndexingSetOneHot)::py_getsetters[] = {
  10783. {const_cast<char*>("axis"), py_get_generic(IndexingSetOneHot, axis), py_set_generic(IndexingSetOneHot, axis), const_cast<char*>("axis"), NULL},
  10784. {const_cast<char*>("ndim"), py_get_generic(IndexingSetOneHot, ndim), py_set_generic(IndexingSetOneHot, ndim), const_cast<char*>("ndim"), NULL},
  10785. {NULL} /* Sentinel */
  10786. };
  10787. PyMethodDef PyOp(IndexingSetOneHot)::tp_methods[] = {
  10788. {const_cast<char*>("__getstate__"), PyOp(IndexingSetOneHot)::getstate, METH_NOARGS, "IndexingSetOneHot getstate"},
  10789. {const_cast<char*>("__setstate__"), PyOp(IndexingSetOneHot)::setstate, METH_VARARGS, "IndexingSetOneHot setstate"},
  10790. {NULL} /* Sentinel */
  10791. };
  10792. PyObject *PyOp(IndexingSetOneHot)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  10793. if (PyOp(IndexingSetOneHot)::py_init(self, args, kwds) < 0) {
  10794. return NULL;
  10795. }
  10796. Py_RETURN_NONE;
  10797. }
  10798. PyMethodDef PyOp(IndexingSetOneHot)::py_init_methoddef = {
  10799. "__init__",
  10800. (PyCFunction)PyOp(IndexingSetOneHot)::py_init_proxy,
  10801. METH_VARARGS | METH_KEYWORDS,
  10802. "__init__(self, axis: int = ..., ndim: int = ...) -> None\n"
  10803. };
  10804. void _init_py_IndexingSetOneHot(py::module m) {
  10805. using py_op = PyOp(IndexingSetOneHot);
  10806. auto& py_type = PyOpType(IndexingSetOneHot);
  10807. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10808. py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingSetOneHot";
  10809. py_type.tp_basicsize = sizeof(PyOp(IndexingSetOneHot));
  10810. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10811. py_type.tp_doc = "IndexingSetOneHot";
  10812. py_type.tp_base = &PyOpType(OpDef);
  10813. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10814. py_type.tp_new = py_new_generic<py_op>;
  10815. py_type.tp_init = py_op::py_init;
  10816. py_type.tp_methods = py_op::tp_methods;
  10817. py_type.tp_getset = py_op::py_getsetters;
  10818. py_type.tp_dict = PyDict_New();
  10819. PyObject* descr = PyDescr_NewMethod(&PyOpType(IndexingSetOneHot), &PyOp(IndexingSetOneHot)::py_init_methoddef);
  10820. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  10821. mgb_assert(PyType_Ready(&py_type) >= 0);
  10822. PyType_Modified(&py_type);
  10823. m.add_object("IndexingSetOneHot", reinterpret_cast<PyObject*>(&py_type));
  10824. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingSetOneHot::typeinfo(), &py_type).second);
  10825. }
  10826. PyOpDefBegin(InplaceAdd) // {
  10827. static PyGetSetDef py_getsetters[];
  10828. static PyMethodDef tp_methods[];
  10829. static PyObject* getstate(PyObject* self, PyObject*) {
  10830. auto& opdef = reinterpret_cast<PyOp(InplaceAdd)*>(self)->inst();
  10831. static_cast<void>(opdef);
  10832. std::unordered_map<std::string, py::object> state {
  10833. };
  10834. return py::cast(state).release().ptr();
  10835. }
  10836. static PyObject* setstate(PyObject* self, PyObject* args) {
  10837. PyObject* dict = PyTuple_GetItem(args, 0);
  10838. if (!dict) return NULL;
  10839. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10840. auto& opdef = reinterpret_cast<PyOp(InplaceAdd)*>(self)->inst();
  10841. static_cast<void>(opdef);
  10842. Py_RETURN_NONE;
  10843. }
  10844. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10845. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  10846. static PyMethodDef py_init_methoddef;
  10847. // };
  10848. PyOpDefEnd(InplaceAdd)
  10849. int PyOp(InplaceAdd)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10850. return 0;
  10851. }
  10852. PyGetSetDef PyOp(InplaceAdd)::py_getsetters[] = {
  10853. {NULL} /* Sentinel */
  10854. };
  10855. PyMethodDef PyOp(InplaceAdd)::tp_methods[] = {
  10856. {const_cast<char*>("__getstate__"), PyOp(InplaceAdd)::getstate, METH_NOARGS, "InplaceAdd getstate"},
  10857. {const_cast<char*>("__setstate__"), PyOp(InplaceAdd)::setstate, METH_VARARGS, "InplaceAdd setstate"},
  10858. {NULL} /* Sentinel */
  10859. };
  10860. PyObject *PyOp(InplaceAdd)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  10861. if (PyOp(InplaceAdd)::py_init(self, args, kwds) < 0) {
  10862. return NULL;
  10863. }
  10864. Py_RETURN_NONE;
  10865. }
  10866. PyMethodDef PyOp(InplaceAdd)::py_init_methoddef = {
  10867. "__init__",
  10868. (PyCFunction)PyOp(InplaceAdd)::py_init_proxy,
  10869. METH_VARARGS | METH_KEYWORDS,
  10870. "__init__(self) -> None\n"
  10871. };
  10872. void _init_py_InplaceAdd(py::module m) {
  10873. using py_op = PyOp(InplaceAdd);
  10874. auto& py_type = PyOpType(InplaceAdd);
  10875. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10876. py_type.tp_name = "megengine.core._imperative_rt.ops.InplaceAdd";
  10877. py_type.tp_basicsize = sizeof(PyOp(InplaceAdd));
  10878. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10879. py_type.tp_doc = "InplaceAdd";
  10880. py_type.tp_base = &PyOpType(OpDef);
  10881. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10882. py_type.tp_new = py_new_generic<py_op>;
  10883. py_type.tp_init = py_op::py_init;
  10884. py_type.tp_methods = py_op::tp_methods;
  10885. py_type.tp_getset = py_op::py_getsetters;
  10886. py_type.tp_dict = PyDict_New();
  10887. PyObject* descr = PyDescr_NewMethod(&PyOpType(InplaceAdd), &PyOp(InplaceAdd)::py_init_methoddef);
  10888. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  10889. mgb_assert(PyType_Ready(&py_type) >= 0);
  10890. PyType_Modified(&py_type);
  10891. m.add_object("InplaceAdd", reinterpret_cast<PyObject*>(&py_type));
  10892. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(InplaceAdd::typeinfo(), &py_type).second);
  10893. }
  10894. PyOpDefBegin(LAMBUpdate) // {
  10895. static PyGetSetDef py_getsetters[];
  10896. static PyMethodDef tp_methods[];
  10897. static PyObject* getstate(PyObject* self, PyObject*) {
  10898. auto& opdef = reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst();
  10899. static_cast<void>(opdef);
  10900. std::unordered_map<std::string, py::object> state {
  10901. {"beta_1", serialization<decltype(opdef.beta_1)>::dump(opdef.beta_1)},
  10902. {"beta_2", serialization<decltype(opdef.beta_2)>::dump(opdef.beta_2)},
  10903. {"step", serialization<decltype(opdef.step)>::dump(opdef.step)},
  10904. {"lr", serialization<decltype(opdef.lr)>::dump(opdef.lr)},
  10905. {"weight_decay", serialization<decltype(opdef.weight_decay)>::dump(opdef.weight_decay)},
  10906. {"eps", serialization<decltype(opdef.eps)>::dump(opdef.eps)},
  10907. {"bias_correction", serialization<decltype(opdef.bias_correction)>::dump(opdef.bias_correction)},
  10908. {"always_adapt", serialization<decltype(opdef.always_adapt)>::dump(opdef.always_adapt)}
  10909. };
  10910. return py::cast(state).release().ptr();
  10911. }
  10912. static PyObject* setstate(PyObject* self, PyObject* args) {
  10913. PyObject* dict = PyTuple_GetItem(args, 0);
  10914. if (!dict) return NULL;
  10915. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10916. auto& opdef = reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst();
  10917. static_cast<void>(opdef);
  10918. {
  10919. auto&& iter = state.find("beta_1");
  10920. if (iter != state.end()) {
  10921. opdef.beta_1 = serialization<decltype(opdef.beta_1)>::load(iter->second);
  10922. }
  10923. }
  10924. {
  10925. auto&& iter = state.find("beta_2");
  10926. if (iter != state.end()) {
  10927. opdef.beta_2 = serialization<decltype(opdef.beta_2)>::load(iter->second);
  10928. }
  10929. }
  10930. {
  10931. auto&& iter = state.find("step");
  10932. if (iter != state.end()) {
  10933. opdef.step = serialization<decltype(opdef.step)>::load(iter->second);
  10934. }
  10935. }
  10936. {
  10937. auto&& iter = state.find("lr");
  10938. if (iter != state.end()) {
  10939. opdef.lr = serialization<decltype(opdef.lr)>::load(iter->second);
  10940. }
  10941. }
  10942. {
  10943. auto&& iter = state.find("weight_decay");
  10944. if (iter != state.end()) {
  10945. opdef.weight_decay = serialization<decltype(opdef.weight_decay)>::load(iter->second);
  10946. }
  10947. }
  10948. {
  10949. auto&& iter = state.find("eps");
  10950. if (iter != state.end()) {
  10951. opdef.eps = serialization<decltype(opdef.eps)>::load(iter->second);
  10952. }
  10953. }
  10954. {
  10955. auto&& iter = state.find("bias_correction");
  10956. if (iter != state.end()) {
  10957. opdef.bias_correction = serialization<decltype(opdef.bias_correction)>::load(iter->second);
  10958. }
  10959. }
  10960. {
  10961. auto&& iter = state.find("always_adapt");
  10962. if (iter != state.end()) {
  10963. opdef.always_adapt = serialization<decltype(opdef.always_adapt)>::load(iter->second);
  10964. }
  10965. }
  10966. Py_RETURN_NONE;
  10967. }
  10968. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10969. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  10970. static PyMethodDef py_init_methoddef;
  10971. // };
  10972. PyOpDefEnd(LAMBUpdate)
  10973. int PyOp(LAMBUpdate)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10974. static const char* kwlist[] = {"beta_1", "beta_2", "step", "lr", "weight_decay", "eps", "bias_correction", "always_adapt", "scope", NULL};
  10975. PyObject *beta_1 = NULL, *beta_2 = NULL, *step = NULL, *lr = NULL, *weight_decay = NULL, *eps = NULL, *bias_correction = NULL, *always_adapt = NULL, *scope = NULL;
  10976. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &beta_1, &beta_2, &step, &lr, &weight_decay, &eps, &bias_correction, &always_adapt, &scope))
  10977. return -1;
  10978. if (beta_1) {
  10979. try {
  10980. // TODO: remove this guard which is used for pybind11 implicit conversion
  10981. py::detail::loader_life_support guard{};
  10982. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().beta_1 =
  10983. py::cast<decltype(LAMBUpdate::beta_1)>(py::handle(beta_1));
  10984. } CATCH_ALL(-1)
  10985. }
  10986. if (beta_2) {
  10987. try {
  10988. // TODO: remove this guard which is used for pybind11 implicit conversion
  10989. py::detail::loader_life_support guard{};
  10990. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().beta_2 =
  10991. py::cast<decltype(LAMBUpdate::beta_2)>(py::handle(beta_2));
  10992. } CATCH_ALL(-1)
  10993. }
  10994. if (step) {
  10995. try {
  10996. // TODO: remove this guard which is used for pybind11 implicit conversion
  10997. py::detail::loader_life_support guard{};
  10998. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().step =
  10999. py::cast<decltype(LAMBUpdate::step)>(py::handle(step));
  11000. } CATCH_ALL(-1)
  11001. }
  11002. if (lr) {
  11003. try {
  11004. // TODO: remove this guard which is used for pybind11 implicit conversion
  11005. py::detail::loader_life_support guard{};
  11006. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().lr =
  11007. py::cast<decltype(LAMBUpdate::lr)>(py::handle(lr));
  11008. } CATCH_ALL(-1)
  11009. }
  11010. if (weight_decay) {
  11011. try {
  11012. // TODO: remove this guard which is used for pybind11 implicit conversion
  11013. py::detail::loader_life_support guard{};
  11014. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().weight_decay =
  11015. py::cast<decltype(LAMBUpdate::weight_decay)>(py::handle(weight_decay));
  11016. } CATCH_ALL(-1)
  11017. }
  11018. if (eps) {
  11019. try {
  11020. // TODO: remove this guard which is used for pybind11 implicit conversion
  11021. py::detail::loader_life_support guard{};
  11022. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().eps =
  11023. py::cast<decltype(LAMBUpdate::eps)>(py::handle(eps));
  11024. } CATCH_ALL(-1)
  11025. }
  11026. if (bias_correction) {
  11027. try {
  11028. // TODO: remove this guard which is used for pybind11 implicit conversion
  11029. py::detail::loader_life_support guard{};
  11030. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().bias_correction =
  11031. py::cast<decltype(LAMBUpdate::bias_correction)>(py::handle(bias_correction));
  11032. } CATCH_ALL(-1)
  11033. }
  11034. if (always_adapt) {
  11035. try {
  11036. // TODO: remove this guard which is used for pybind11 implicit conversion
  11037. py::detail::loader_life_support guard{};
  11038. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().always_adapt =
  11039. py::cast<decltype(LAMBUpdate::always_adapt)>(py::handle(always_adapt));
  11040. } CATCH_ALL(-1)
  11041. }
  11042. if (scope) {
  11043. try {
  11044. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11045. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11046. } CATCH_ALL(-1)
  11047. }
  11048. return 0;
  11049. }
  11050. PyGetSetDef PyOp(LAMBUpdate)::py_getsetters[] = {
  11051. {const_cast<char*>("beta_1"), py_get_generic(LAMBUpdate, beta_1), py_set_generic(LAMBUpdate, beta_1), const_cast<char*>("beta_1"), NULL},
  11052. {const_cast<char*>("beta_2"), py_get_generic(LAMBUpdate, beta_2), py_set_generic(LAMBUpdate, beta_2), const_cast<char*>("beta_2"), NULL},
  11053. {const_cast<char*>("step"), py_get_generic(LAMBUpdate, step), py_set_generic(LAMBUpdate, step), const_cast<char*>("step"), NULL},
  11054. {const_cast<char*>("lr"), py_get_generic(LAMBUpdate, lr), py_set_generic(LAMBUpdate, lr), const_cast<char*>("lr"), NULL},
  11055. {const_cast<char*>("weight_decay"), py_get_generic(LAMBUpdate, weight_decay), py_set_generic(LAMBUpdate, weight_decay), const_cast<char*>("weight_decay"), NULL},
  11056. {const_cast<char*>("eps"), py_get_generic(LAMBUpdate, eps), py_set_generic(LAMBUpdate, eps), const_cast<char*>("eps"), NULL},
  11057. {const_cast<char*>("bias_correction"), py_get_generic(LAMBUpdate, bias_correction), py_set_generic(LAMBUpdate, bias_correction), const_cast<char*>("bias_correction"), NULL},
  11058. {const_cast<char*>("always_adapt"), py_get_generic(LAMBUpdate, always_adapt), py_set_generic(LAMBUpdate, always_adapt), const_cast<char*>("always_adapt"), NULL},
  11059. {NULL} /* Sentinel */
  11060. };
  11061. PyMethodDef PyOp(LAMBUpdate)::tp_methods[] = {
  11062. {const_cast<char*>("__getstate__"), PyOp(LAMBUpdate)::getstate, METH_NOARGS, "LAMBUpdate getstate"},
  11063. {const_cast<char*>("__setstate__"), PyOp(LAMBUpdate)::setstate, METH_VARARGS, "LAMBUpdate setstate"},
  11064. {NULL} /* Sentinel */
  11065. };
  11066. PyObject *PyOp(LAMBUpdate)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  11067. if (PyOp(LAMBUpdate)::py_init(self, args, kwds) < 0) {
  11068. return NULL;
  11069. }
  11070. Py_RETURN_NONE;
  11071. }
  11072. PyMethodDef PyOp(LAMBUpdate)::py_init_methoddef = {
  11073. "__init__",
  11074. (PyCFunction)PyOp(LAMBUpdate)::py_init_proxy,
  11075. METH_VARARGS | METH_KEYWORDS,
  11076. "__init__(self, beta_1: float = ..., beta_2: float = ..., step: float = ..., lr: float = ..., weight_decay: float = ..., eps: float = ..., bias_correction: bool = ..., always_adapt: bool = ...) -> None\n"
  11077. };
  11078. void _init_py_LAMBUpdate(py::module m) {
  11079. using py_op = PyOp(LAMBUpdate);
  11080. auto& py_type = PyOpType(LAMBUpdate);
  11081. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11082. py_type.tp_name = "megengine.core._imperative_rt.ops.LAMBUpdate";
  11083. py_type.tp_basicsize = sizeof(PyOp(LAMBUpdate));
  11084. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11085. py_type.tp_doc = "LAMBUpdate";
  11086. py_type.tp_base = &PyOpType(OpDef);
  11087. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11088. py_type.tp_new = py_new_generic<py_op>;
  11089. py_type.tp_init = py_op::py_init;
  11090. py_type.tp_methods = py_op::tp_methods;
  11091. py_type.tp_getset = py_op::py_getsetters;
  11092. py_type.tp_dict = PyDict_New();
  11093. PyObject* descr = PyDescr_NewMethod(&PyOpType(LAMBUpdate), &PyOp(LAMBUpdate)::py_init_methoddef);
  11094. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  11095. mgb_assert(PyType_Ready(&py_type) >= 0);
  11096. PyType_Modified(&py_type);
  11097. m.add_object("LAMBUpdate", reinterpret_cast<PyObject*>(&py_type));
  11098. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LAMBUpdate::typeinfo(), &py_type).second);
  11099. }
  11100. PyOpDefBegin(LRN) // {
  11101. static PyGetSetDef py_getsetters[];
  11102. static PyMethodDef tp_methods[];
  11103. static PyObject* getstate(PyObject* self, PyObject*) {
  11104. auto& opdef = reinterpret_cast<PyOp(LRN)*>(self)->inst();
  11105. static_cast<void>(opdef);
  11106. std::unordered_map<std::string, py::object> state {
  11107. {"n", serialization<decltype(opdef.n)>::dump(opdef.n)},
  11108. {"k", serialization<decltype(opdef.k)>::dump(opdef.k)},
  11109. {"alpha", serialization<decltype(opdef.alpha)>::dump(opdef.alpha)},
  11110. {"beta", serialization<decltype(opdef.beta)>::dump(opdef.beta)}
  11111. };
  11112. return py::cast(state).release().ptr();
  11113. }
  11114. static PyObject* setstate(PyObject* self, PyObject* args) {
  11115. PyObject* dict = PyTuple_GetItem(args, 0);
  11116. if (!dict) return NULL;
  11117. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11118. auto& opdef = reinterpret_cast<PyOp(LRN)*>(self)->inst();
  11119. static_cast<void>(opdef);
  11120. {
  11121. auto&& iter = state.find("n");
  11122. if (iter != state.end()) {
  11123. opdef.n = serialization<decltype(opdef.n)>::load(iter->second);
  11124. }
  11125. }
  11126. {
  11127. auto&& iter = state.find("k");
  11128. if (iter != state.end()) {
  11129. opdef.k = serialization<decltype(opdef.k)>::load(iter->second);
  11130. }
  11131. }
  11132. {
  11133. auto&& iter = state.find("alpha");
  11134. if (iter != state.end()) {
  11135. opdef.alpha = serialization<decltype(opdef.alpha)>::load(iter->second);
  11136. }
  11137. }
  11138. {
  11139. auto&& iter = state.find("beta");
  11140. if (iter != state.end()) {
  11141. opdef.beta = serialization<decltype(opdef.beta)>::load(iter->second);
  11142. }
  11143. }
  11144. Py_RETURN_NONE;
  11145. }
  11146. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11147. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  11148. static PyMethodDef py_init_methoddef;
  11149. // };
  11150. PyOpDefEnd(LRN)
  11151. int PyOp(LRN)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11152. static const char* kwlist[] = {"n", "k", "alpha", "beta", "scope", NULL};
  11153. PyObject *n = NULL, *k = NULL, *alpha = NULL, *beta = NULL, *scope = NULL;
  11154. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &n, &k, &alpha, &beta, &scope))
  11155. return -1;
  11156. if (n) {
  11157. try {
  11158. // TODO: remove this guard which is used for pybind11 implicit conversion
  11159. py::detail::loader_life_support guard{};
  11160. reinterpret_cast<PyOp(LRN)*>(self)->inst().n =
  11161. py::cast<decltype(LRN::n)>(py::handle(n));
  11162. } CATCH_ALL(-1)
  11163. }
  11164. if (k) {
  11165. try {
  11166. // TODO: remove this guard which is used for pybind11 implicit conversion
  11167. py::detail::loader_life_support guard{};
  11168. reinterpret_cast<PyOp(LRN)*>(self)->inst().k =
  11169. py::cast<decltype(LRN::k)>(py::handle(k));
  11170. } CATCH_ALL(-1)
  11171. }
  11172. if (alpha) {
  11173. try {
  11174. // TODO: remove this guard which is used for pybind11 implicit conversion
  11175. py::detail::loader_life_support guard{};
  11176. reinterpret_cast<PyOp(LRN)*>(self)->inst().alpha =
  11177. py::cast<decltype(LRN::alpha)>(py::handle(alpha));
  11178. } CATCH_ALL(-1)
  11179. }
  11180. if (beta) {
  11181. try {
  11182. // TODO: remove this guard which is used for pybind11 implicit conversion
  11183. py::detail::loader_life_support guard{};
  11184. reinterpret_cast<PyOp(LRN)*>(self)->inst().beta =
  11185. py::cast<decltype(LRN::beta)>(py::handle(beta));
  11186. } CATCH_ALL(-1)
  11187. }
  11188. if (scope) {
  11189. try {
  11190. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11191. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11192. } CATCH_ALL(-1)
  11193. }
  11194. return 0;
  11195. }
  11196. PyGetSetDef PyOp(LRN)::py_getsetters[] = {
  11197. {const_cast<char*>("n"), py_get_generic(LRN, n), py_set_generic(LRN, n), const_cast<char*>("n"), NULL},
  11198. {const_cast<char*>("k"), py_get_generic(LRN, k), py_set_generic(LRN, k), const_cast<char*>("k"), NULL},
  11199. {const_cast<char*>("alpha"), py_get_generic(LRN, alpha), py_set_generic(LRN, alpha), const_cast<char*>("alpha"), NULL},
  11200. {const_cast<char*>("beta"), py_get_generic(LRN, beta), py_set_generic(LRN, beta), const_cast<char*>("beta"), NULL},
  11201. {NULL} /* Sentinel */
  11202. };
  11203. PyMethodDef PyOp(LRN)::tp_methods[] = {
  11204. {const_cast<char*>("__getstate__"), PyOp(LRN)::getstate, METH_NOARGS, "LRN getstate"},
  11205. {const_cast<char*>("__setstate__"), PyOp(LRN)::setstate, METH_VARARGS, "LRN setstate"},
  11206. {NULL} /* Sentinel */
  11207. };
  11208. PyObject *PyOp(LRN)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  11209. if (PyOp(LRN)::py_init(self, args, kwds) < 0) {
  11210. return NULL;
  11211. }
  11212. Py_RETURN_NONE;
  11213. }
  11214. PyMethodDef PyOp(LRN)::py_init_methoddef = {
  11215. "__init__",
  11216. (PyCFunction)PyOp(LRN)::py_init_proxy,
  11217. METH_VARARGS | METH_KEYWORDS,
  11218. "__init__(self, n: int = ..., k: float = ..., alpha: float = ..., beta: float = ...) -> None\n"
  11219. };
  11220. void _init_py_LRN(py::module m) {
  11221. using py_op = PyOp(LRN);
  11222. auto& py_type = PyOpType(LRN);
  11223. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11224. py_type.tp_name = "megengine.core._imperative_rt.ops.LRN";
  11225. py_type.tp_basicsize = sizeof(PyOp(LRN));
  11226. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11227. py_type.tp_doc = "LRN";
  11228. py_type.tp_base = &PyOpType(OpDef);
  11229. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11230. py_type.tp_new = py_new_generic<py_op>;
  11231. py_type.tp_init = py_op::py_init;
  11232. py_type.tp_methods = py_op::tp_methods;
  11233. py_type.tp_getset = py_op::py_getsetters;
  11234. py_type.tp_dict = PyDict_New();
  11235. PyObject* descr = PyDescr_NewMethod(&PyOpType(LRN), &PyOp(LRN)::py_init_methoddef);
  11236. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  11237. mgb_assert(PyType_Ready(&py_type) >= 0);
  11238. PyType_Modified(&py_type);
  11239. m.add_object("LRN", reinterpret_cast<PyObject*>(&py_type));
  11240. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LRN::typeinfo(), &py_type).second);
  11241. }
  11242. PyOpDefBegin(LSQ) // {
  11243. static PyGetSetDef py_getsetters[];
  11244. static PyMethodDef tp_methods[];
  11245. static PyObject* getstate(PyObject* self, PyObject*) {
  11246. auto& opdef = reinterpret_cast<PyOp(LSQ)*>(self)->inst();
  11247. static_cast<void>(opdef);
  11248. std::unordered_map<std::string, py::object> state {
  11249. {"qmin", serialization<decltype(opdef.qmin)>::dump(opdef.qmin)},
  11250. {"qmax", serialization<decltype(opdef.qmax)>::dump(opdef.qmax)}
  11251. };
  11252. return py::cast(state).release().ptr();
  11253. }
  11254. static PyObject* setstate(PyObject* self, PyObject* args) {
  11255. PyObject* dict = PyTuple_GetItem(args, 0);
  11256. if (!dict) return NULL;
  11257. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11258. auto& opdef = reinterpret_cast<PyOp(LSQ)*>(self)->inst();
  11259. static_cast<void>(opdef);
  11260. {
  11261. auto&& iter = state.find("qmin");
  11262. if (iter != state.end()) {
  11263. opdef.qmin = serialization<decltype(opdef.qmin)>::load(iter->second);
  11264. }
  11265. }
  11266. {
  11267. auto&& iter = state.find("qmax");
  11268. if (iter != state.end()) {
  11269. opdef.qmax = serialization<decltype(opdef.qmax)>::load(iter->second);
  11270. }
  11271. }
  11272. Py_RETURN_NONE;
  11273. }
  11274. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11275. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  11276. static PyMethodDef py_init_methoddef;
  11277. // };
  11278. PyOpDefEnd(LSQ)
  11279. int PyOp(LSQ)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11280. static const char* kwlist[] = {"qmin", "qmax", "scope", NULL};
  11281. PyObject *qmin = NULL, *qmax = NULL, *scope = NULL;
  11282. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &qmin, &qmax, &scope))
  11283. return -1;
  11284. if (qmin) {
  11285. try {
  11286. // TODO: remove this guard which is used for pybind11 implicit conversion
  11287. py::detail::loader_life_support guard{};
  11288. reinterpret_cast<PyOp(LSQ)*>(self)->inst().qmin =
  11289. py::cast<decltype(LSQ::qmin)>(py::handle(qmin));
  11290. } CATCH_ALL(-1)
  11291. }
  11292. if (qmax) {
  11293. try {
  11294. // TODO: remove this guard which is used for pybind11 implicit conversion
  11295. py::detail::loader_life_support guard{};
  11296. reinterpret_cast<PyOp(LSQ)*>(self)->inst().qmax =
  11297. py::cast<decltype(LSQ::qmax)>(py::handle(qmax));
  11298. } CATCH_ALL(-1)
  11299. }
  11300. if (scope) {
  11301. try {
  11302. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11303. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11304. } CATCH_ALL(-1)
  11305. }
  11306. return 0;
  11307. }
  11308. PyGetSetDef PyOp(LSQ)::py_getsetters[] = {
  11309. {const_cast<char*>("qmin"), py_get_generic(LSQ, qmin), py_set_generic(LSQ, qmin), const_cast<char*>("qmin"), NULL},
  11310. {const_cast<char*>("qmax"), py_get_generic(LSQ, qmax), py_set_generic(LSQ, qmax), const_cast<char*>("qmax"), NULL},
  11311. {NULL} /* Sentinel */
  11312. };
  11313. PyMethodDef PyOp(LSQ)::tp_methods[] = {
  11314. {const_cast<char*>("__getstate__"), PyOp(LSQ)::getstate, METH_NOARGS, "LSQ getstate"},
  11315. {const_cast<char*>("__setstate__"), PyOp(LSQ)::setstate, METH_VARARGS, "LSQ setstate"},
  11316. {NULL} /* Sentinel */
  11317. };
  11318. PyObject *PyOp(LSQ)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  11319. if (PyOp(LSQ)::py_init(self, args, kwds) < 0) {
  11320. return NULL;
  11321. }
  11322. Py_RETURN_NONE;
  11323. }
  11324. PyMethodDef PyOp(LSQ)::py_init_methoddef = {
  11325. "__init__",
  11326. (PyCFunction)PyOp(LSQ)::py_init_proxy,
  11327. METH_VARARGS | METH_KEYWORDS,
  11328. "__init__(self, qmin: int = ..., qmax: int = ...) -> None\n"
  11329. };
  11330. void _init_py_LSQ(py::module m) {
  11331. using py_op = PyOp(LSQ);
  11332. auto& py_type = PyOpType(LSQ);
  11333. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11334. py_type.tp_name = "megengine.core._imperative_rt.ops.LSQ";
  11335. py_type.tp_basicsize = sizeof(PyOp(LSQ));
  11336. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11337. py_type.tp_doc = "LSQ";
  11338. py_type.tp_base = &PyOpType(OpDef);
  11339. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11340. py_type.tp_new = py_new_generic<py_op>;
  11341. py_type.tp_init = py_op::py_init;
  11342. py_type.tp_methods = py_op::tp_methods;
  11343. py_type.tp_getset = py_op::py_getsetters;
  11344. py_type.tp_dict = PyDict_New();
  11345. PyObject* descr = PyDescr_NewMethod(&PyOpType(LSQ), &PyOp(LSQ)::py_init_methoddef);
  11346. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  11347. mgb_assert(PyType_Ready(&py_type) >= 0);
  11348. PyType_Modified(&py_type);
  11349. m.add_object("LSQ", reinterpret_cast<PyObject*>(&py_type));
  11350. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LSQ::typeinfo(), &py_type).second);
  11351. }
  11352. void _init_py_LSTM_FwdMode(PyTypeObject& py_type) {
  11353. auto& e_type = EnumWrapper<LSTM::FwdMode>::type;
  11354. Py_INCREF(e_type);
  11355. mgb_assert(PyDict_SetItemString(
  11356. py_type.tp_dict, "FwdMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  11357. }
  11358. PyOpDefBegin(LSTM) // {
  11359. static PyGetSetDef py_getsetters[];
  11360. static PyMethodDef tp_methods[];
  11361. static PyObject* getstate(PyObject* self, PyObject*) {
  11362. auto& opdef = reinterpret_cast<PyOp(LSTM)*>(self)->inst();
  11363. static_cast<void>(opdef);
  11364. std::unordered_map<std::string, py::object> state {
  11365. {"num_layers", serialization<decltype(opdef.num_layers)>::dump(opdef.num_layers)},
  11366. {"bidirectional", serialization<decltype(opdef.bidirectional)>::dump(opdef.bidirectional)},
  11367. {"bias", serialization<decltype(opdef.bias)>::dump(opdef.bias)},
  11368. {"hidden_size", serialization<decltype(opdef.hidden_size)>::dump(opdef.hidden_size)},
  11369. {"proj_size", serialization<decltype(opdef.proj_size)>::dump(opdef.proj_size)},
  11370. {"dropout", serialization<decltype(opdef.dropout)>::dump(opdef.dropout)},
  11371. {"fwd_mode", serialization<decltype(opdef.fwd_mode)>::dump(opdef.fwd_mode)}
  11372. };
  11373. return py::cast(state).release().ptr();
  11374. }
  11375. static PyObject* setstate(PyObject* self, PyObject* args) {
  11376. PyObject* dict = PyTuple_GetItem(args, 0);
  11377. if (!dict) return NULL;
  11378. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11379. auto& opdef = reinterpret_cast<PyOp(LSTM)*>(self)->inst();
  11380. static_cast<void>(opdef);
  11381. {
  11382. auto&& iter = state.find("num_layers");
  11383. if (iter != state.end()) {
  11384. opdef.num_layers = serialization<decltype(opdef.num_layers)>::load(iter->second);
  11385. }
  11386. }
  11387. {
  11388. auto&& iter = state.find("bidirectional");
  11389. if (iter != state.end()) {
  11390. opdef.bidirectional = serialization<decltype(opdef.bidirectional)>::load(iter->second);
  11391. }
  11392. }
  11393. {
  11394. auto&& iter = state.find("bias");
  11395. if (iter != state.end()) {
  11396. opdef.bias = serialization<decltype(opdef.bias)>::load(iter->second);
  11397. }
  11398. }
  11399. {
  11400. auto&& iter = state.find("hidden_size");
  11401. if (iter != state.end()) {
  11402. opdef.hidden_size = serialization<decltype(opdef.hidden_size)>::load(iter->second);
  11403. }
  11404. }
  11405. {
  11406. auto&& iter = state.find("proj_size");
  11407. if (iter != state.end()) {
  11408. opdef.proj_size = serialization<decltype(opdef.proj_size)>::load(iter->second);
  11409. }
  11410. }
  11411. {
  11412. auto&& iter = state.find("dropout");
  11413. if (iter != state.end()) {
  11414. opdef.dropout = serialization<decltype(opdef.dropout)>::load(iter->second);
  11415. }
  11416. }
  11417. {
  11418. auto&& iter = state.find("fwd_mode");
  11419. if (iter != state.end()) {
  11420. opdef.fwd_mode = serialization<decltype(opdef.fwd_mode)>::load(iter->second);
  11421. }
  11422. }
  11423. Py_RETURN_NONE;
  11424. }
  11425. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11426. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  11427. static PyMethodDef py_init_methoddef;
  11428. // };
  11429. PyOpDefEnd(LSTM)
  11430. int PyOp(LSTM)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11431. static const char* kwlist[] = {"num_layers", "bidirectional", "bias", "hidden_size", "proj_size", "dropout", "fwd_mode", "scope", NULL};
  11432. PyObject *num_layers = NULL, *bidirectional = NULL, *bias = NULL, *hidden_size = NULL, *proj_size = NULL, *dropout = NULL, *fwd_mode = NULL, *scope = NULL;
  11433. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOO", const_cast<char**>(kwlist), &num_layers, &bidirectional, &bias, &hidden_size, &proj_size, &dropout, &fwd_mode, &scope))
  11434. return -1;
  11435. if (num_layers) {
  11436. try {
  11437. // TODO: remove this guard which is used for pybind11 implicit conversion
  11438. py::detail::loader_life_support guard{};
  11439. reinterpret_cast<PyOp(LSTM)*>(self)->inst().num_layers =
  11440. py::cast<decltype(LSTM::num_layers)>(py::handle(num_layers));
  11441. } CATCH_ALL(-1)
  11442. }
  11443. if (bidirectional) {
  11444. try {
  11445. // TODO: remove this guard which is used for pybind11 implicit conversion
  11446. py::detail::loader_life_support guard{};
  11447. reinterpret_cast<PyOp(LSTM)*>(self)->inst().bidirectional =
  11448. py::cast<decltype(LSTM::bidirectional)>(py::handle(bidirectional));
  11449. } CATCH_ALL(-1)
  11450. }
  11451. if (bias) {
  11452. try {
  11453. // TODO: remove this guard which is used for pybind11 implicit conversion
  11454. py::detail::loader_life_support guard{};
  11455. reinterpret_cast<PyOp(LSTM)*>(self)->inst().bias =
  11456. py::cast<decltype(LSTM::bias)>(py::handle(bias));
  11457. } CATCH_ALL(-1)
  11458. }
  11459. if (hidden_size) {
  11460. try {
  11461. // TODO: remove this guard which is used for pybind11 implicit conversion
  11462. py::detail::loader_life_support guard{};
  11463. reinterpret_cast<PyOp(LSTM)*>(self)->inst().hidden_size =
  11464. py::cast<decltype(LSTM::hidden_size)>(py::handle(hidden_size));
  11465. } CATCH_ALL(-1)
  11466. }
  11467. if (proj_size) {
  11468. try {
  11469. // TODO: remove this guard which is used for pybind11 implicit conversion
  11470. py::detail::loader_life_support guard{};
  11471. reinterpret_cast<PyOp(LSTM)*>(self)->inst().proj_size =
  11472. py::cast<decltype(LSTM::proj_size)>(py::handle(proj_size));
  11473. } CATCH_ALL(-1)
  11474. }
  11475. if (dropout) {
  11476. try {
  11477. // TODO: remove this guard which is used for pybind11 implicit conversion
  11478. py::detail::loader_life_support guard{};
  11479. reinterpret_cast<PyOp(LSTM)*>(self)->inst().dropout =
  11480. py::cast<decltype(LSTM::dropout)>(py::handle(dropout));
  11481. } CATCH_ALL(-1)
  11482. }
  11483. if (fwd_mode) {
  11484. try {
  11485. // TODO: remove this guard which is used for pybind11 implicit conversion
  11486. py::detail::loader_life_support guard{};
  11487. reinterpret_cast<PyOp(LSTM)*>(self)->inst().fwd_mode =
  11488. py::cast<decltype(LSTM::fwd_mode)>(py::handle(fwd_mode));
  11489. } CATCH_ALL(-1)
  11490. }
  11491. if (scope) {
  11492. try {
  11493. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11494. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11495. } CATCH_ALL(-1)
  11496. }
  11497. return 0;
  11498. }
  11499. PyGetSetDef PyOp(LSTM)::py_getsetters[] = {
  11500. {const_cast<char*>("num_layers"), py_get_generic(LSTM, num_layers), py_set_generic(LSTM, num_layers), const_cast<char*>("num_layers"), NULL},
  11501. {const_cast<char*>("bidirectional"), py_get_generic(LSTM, bidirectional), py_set_generic(LSTM, bidirectional), const_cast<char*>("bidirectional"), NULL},
  11502. {const_cast<char*>("bias"), py_get_generic(LSTM, bias), py_set_generic(LSTM, bias), const_cast<char*>("bias"), NULL},
  11503. {const_cast<char*>("hidden_size"), py_get_generic(LSTM, hidden_size), py_set_generic(LSTM, hidden_size), const_cast<char*>("hidden_size"), NULL},
  11504. {const_cast<char*>("proj_size"), py_get_generic(LSTM, proj_size), py_set_generic(LSTM, proj_size), const_cast<char*>("proj_size"), NULL},
  11505. {const_cast<char*>("dropout"), py_get_generic(LSTM, dropout), py_set_generic(LSTM, dropout), const_cast<char*>("dropout"), NULL},
  11506. {const_cast<char*>("fwd_mode"), py_get_generic(LSTM, fwd_mode), py_set_generic(LSTM, fwd_mode), const_cast<char*>("fwd_mode"), NULL},
  11507. {NULL} /* Sentinel */
  11508. };
  11509. PyMethodDef PyOp(LSTM)::tp_methods[] = {
  11510. {const_cast<char*>("__getstate__"), PyOp(LSTM)::getstate, METH_NOARGS, "LSTM getstate"},
  11511. {const_cast<char*>("__setstate__"), PyOp(LSTM)::setstate, METH_VARARGS, "LSTM setstate"},
  11512. {NULL} /* Sentinel */
  11513. };
  11514. PyObject *PyOp(LSTM)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  11515. if (PyOp(LSTM)::py_init(self, args, kwds) < 0) {
  11516. return NULL;
  11517. }
  11518. Py_RETURN_NONE;
  11519. }
  11520. PyMethodDef PyOp(LSTM)::py_init_methoddef = {
  11521. "__init__",
  11522. (PyCFunction)PyOp(LSTM)::py_init_proxy,
  11523. METH_VARARGS | METH_KEYWORDS,
  11524. "__init__(self, num_layers: int = ..., bidirectional: bool = ..., bias: bool = ..., hidden_size: int = ..., proj_size: int = ..., dropout: float = ..., fwd_mode: Union[str, FwdMode] = ...) -> None\n"
  11525. };
  11526. void _init_py_LSTM(py::module m) {
  11527. using py_op = PyOp(LSTM);
  11528. auto& py_type = PyOpType(LSTM);
  11529. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11530. py_type.tp_name = "megengine.core._imperative_rt.ops.LSTM";
  11531. py_type.tp_basicsize = sizeof(PyOp(LSTM));
  11532. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11533. py_type.tp_doc = "LSTM";
  11534. py_type.tp_base = &PyOpType(OpDef);
  11535. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11536. py_type.tp_new = py_new_generic<py_op>;
  11537. py_type.tp_init = py_op::py_init;
  11538. py_type.tp_methods = py_op::tp_methods;
  11539. py_type.tp_getset = py_op::py_getsetters;
  11540. py_type.tp_dict = PyDict_New();
  11541. PyObject* descr = PyDescr_NewMethod(&PyOpType(LSTM), &PyOp(LSTM)::py_init_methoddef);
  11542. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  11543. mgb_assert(PyType_Ready(&py_type) >= 0);
  11544. _init_py_LSTM_FwdMode(py_type);
  11545. PyType_Modified(&py_type);
  11546. m.add_object("LSTM", reinterpret_cast<PyObject*>(&py_type));
  11547. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LSTM::typeinfo(), &py_type).second);
  11548. }
  11549. PyOpDefBegin(LSTMCell) // {
  11550. static PyGetSetDef py_getsetters[];
  11551. static PyMethodDef tp_methods[];
  11552. static PyObject* getstate(PyObject* self, PyObject*) {
  11553. auto& opdef = reinterpret_cast<PyOp(LSTMCell)*>(self)->inst();
  11554. static_cast<void>(opdef);
  11555. std::unordered_map<std::string, py::object> state {
  11556. };
  11557. return py::cast(state).release().ptr();
  11558. }
  11559. static PyObject* setstate(PyObject* self, PyObject* args) {
  11560. PyObject* dict = PyTuple_GetItem(args, 0);
  11561. if (!dict) return NULL;
  11562. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11563. auto& opdef = reinterpret_cast<PyOp(LSTMCell)*>(self)->inst();
  11564. static_cast<void>(opdef);
  11565. Py_RETURN_NONE;
  11566. }
  11567. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11568. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  11569. static PyMethodDef py_init_methoddef;
  11570. // };
  11571. PyOpDefEnd(LSTMCell)
  11572. int PyOp(LSTMCell)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11573. return 0;
  11574. }
  11575. PyGetSetDef PyOp(LSTMCell)::py_getsetters[] = {
  11576. {NULL} /* Sentinel */
  11577. };
  11578. PyMethodDef PyOp(LSTMCell)::tp_methods[] = {
  11579. {const_cast<char*>("__getstate__"), PyOp(LSTMCell)::getstate, METH_NOARGS, "LSTMCell getstate"},
  11580. {const_cast<char*>("__setstate__"), PyOp(LSTMCell)::setstate, METH_VARARGS, "LSTMCell setstate"},
  11581. {NULL} /* Sentinel */
  11582. };
  11583. PyObject *PyOp(LSTMCell)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  11584. if (PyOp(LSTMCell)::py_init(self, args, kwds) < 0) {
  11585. return NULL;
  11586. }
  11587. Py_RETURN_NONE;
  11588. }
  11589. PyMethodDef PyOp(LSTMCell)::py_init_methoddef = {
  11590. "__init__",
  11591. (PyCFunction)PyOp(LSTMCell)::py_init_proxy,
  11592. METH_VARARGS | METH_KEYWORDS,
  11593. "__init__(self) -> None\n"
  11594. };
  11595. void _init_py_LSTMCell(py::module m) {
  11596. using py_op = PyOp(LSTMCell);
  11597. auto& py_type = PyOpType(LSTMCell);
  11598. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11599. py_type.tp_name = "megengine.core._imperative_rt.ops.LSTMCell";
  11600. py_type.tp_basicsize = sizeof(PyOp(LSTMCell));
  11601. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11602. py_type.tp_doc = "LSTMCell";
  11603. py_type.tp_base = &PyOpType(OpDef);
  11604. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11605. py_type.tp_new = py_new_generic<py_op>;
  11606. py_type.tp_init = py_op::py_init;
  11607. py_type.tp_methods = py_op::tp_methods;
  11608. py_type.tp_getset = py_op::py_getsetters;
  11609. py_type.tp_dict = PyDict_New();
  11610. PyObject* descr = PyDescr_NewMethod(&PyOpType(LSTMCell), &PyOp(LSTMCell)::py_init_methoddef);
  11611. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  11612. mgb_assert(PyType_Ready(&py_type) >= 0);
  11613. PyType_Modified(&py_type);
  11614. m.add_object("LSTMCell", reinterpret_cast<PyObject*>(&py_type));
  11615. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LSTMCell::typeinfo(), &py_type).second);
  11616. }
  11617. PyOpDefBegin(LayerNorm) // {
  11618. static PyGetSetDef py_getsetters[];
  11619. static PyMethodDef tp_methods[];
  11620. static PyObject* getstate(PyObject* self, PyObject*) {
  11621. auto& opdef = reinterpret_cast<PyOp(LayerNorm)*>(self)->inst();
  11622. static_cast<void>(opdef);
  11623. std::unordered_map<std::string, py::object> state {
  11624. {"affine", serialization<decltype(opdef.affine)>::dump(opdef.affine)},
  11625. {"eps", serialization<decltype(opdef.eps)>::dump(opdef.eps)},
  11626. {"normalized_dim", serialization<decltype(opdef.normalized_dim)>::dump(opdef.normalized_dim)},
  11627. {"normalized_size", serialization<decltype(opdef.normalized_size)>::dump(opdef.normalized_size)}
  11628. };
  11629. return py::cast(state).release().ptr();
  11630. }
  11631. static PyObject* setstate(PyObject* self, PyObject* args) {
  11632. PyObject* dict = PyTuple_GetItem(args, 0);
  11633. if (!dict) return NULL;
  11634. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11635. auto& opdef = reinterpret_cast<PyOp(LayerNorm)*>(self)->inst();
  11636. static_cast<void>(opdef);
  11637. {
  11638. auto&& iter = state.find("affine");
  11639. if (iter != state.end()) {
  11640. opdef.affine = serialization<decltype(opdef.affine)>::load(iter->second);
  11641. }
  11642. }
  11643. {
  11644. auto&& iter = state.find("eps");
  11645. if (iter != state.end()) {
  11646. opdef.eps = serialization<decltype(opdef.eps)>::load(iter->second);
  11647. }
  11648. }
  11649. {
  11650. auto&& iter = state.find("normalized_dim");
  11651. if (iter != state.end()) {
  11652. opdef.normalized_dim = serialization<decltype(opdef.normalized_dim)>::load(iter->second);
  11653. }
  11654. }
  11655. {
  11656. auto&& iter = state.find("normalized_size");
  11657. if (iter != state.end()) {
  11658. opdef.normalized_size = serialization<decltype(opdef.normalized_size)>::load(iter->second);
  11659. }
  11660. }
  11661. Py_RETURN_NONE;
  11662. }
  11663. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11664. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  11665. static PyMethodDef py_init_methoddef;
  11666. // };
  11667. PyOpDefEnd(LayerNorm)
  11668. int PyOp(LayerNorm)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11669. static const char* kwlist[] = {"affine", "eps", "normalized_dim", "normalized_size", "scope", NULL};
  11670. PyObject *affine = NULL, *eps = NULL, *normalized_dim = NULL, *normalized_size = NULL, *scope = NULL;
  11671. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &affine, &eps, &normalized_dim, &normalized_size, &scope))
  11672. return -1;
  11673. if (affine) {
  11674. try {
  11675. // TODO: remove this guard which is used for pybind11 implicit conversion
  11676. py::detail::loader_life_support guard{};
  11677. reinterpret_cast<PyOp(LayerNorm)*>(self)->inst().affine =
  11678. py::cast<decltype(LayerNorm::affine)>(py::handle(affine));
  11679. } CATCH_ALL(-1)
  11680. }
  11681. if (eps) {
  11682. try {
  11683. // TODO: remove this guard which is used for pybind11 implicit conversion
  11684. py::detail::loader_life_support guard{};
  11685. reinterpret_cast<PyOp(LayerNorm)*>(self)->inst().eps =
  11686. py::cast<decltype(LayerNorm::eps)>(py::handle(eps));
  11687. } CATCH_ALL(-1)
  11688. }
  11689. if (normalized_dim) {
  11690. try {
  11691. // TODO: remove this guard which is used for pybind11 implicit conversion
  11692. py::detail::loader_life_support guard{};
  11693. reinterpret_cast<PyOp(LayerNorm)*>(self)->inst().normalized_dim =
  11694. py::cast<decltype(LayerNorm::normalized_dim)>(py::handle(normalized_dim));
  11695. } CATCH_ALL(-1)
  11696. }
  11697. if (normalized_size) {
  11698. try {
  11699. // TODO: remove this guard which is used for pybind11 implicit conversion
  11700. py::detail::loader_life_support guard{};
  11701. reinterpret_cast<PyOp(LayerNorm)*>(self)->inst().normalized_size =
  11702. py::cast<decltype(LayerNorm::normalized_size)>(py::handle(normalized_size));
  11703. } CATCH_ALL(-1)
  11704. }
  11705. if (scope) {
  11706. try {
  11707. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11708. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11709. } CATCH_ALL(-1)
  11710. }
  11711. return 0;
  11712. }
  11713. PyGetSetDef PyOp(LayerNorm)::py_getsetters[] = {
  11714. {const_cast<char*>("affine"), py_get_generic(LayerNorm, affine), py_set_generic(LayerNorm, affine), const_cast<char*>("affine"), NULL},
  11715. {const_cast<char*>("eps"), py_get_generic(LayerNorm, eps), py_set_generic(LayerNorm, eps), const_cast<char*>("eps"), NULL},
  11716. {const_cast<char*>("normalized_dim"), py_get_generic(LayerNorm, normalized_dim), py_set_generic(LayerNorm, normalized_dim), const_cast<char*>("normalized_dim"), NULL},
  11717. {const_cast<char*>("normalized_size"), py_get_generic(LayerNorm, normalized_size), py_set_generic(LayerNorm, normalized_size), const_cast<char*>("normalized_size"), NULL},
  11718. {NULL} /* Sentinel */
  11719. };
  11720. PyMethodDef PyOp(LayerNorm)::tp_methods[] = {
  11721. {const_cast<char*>("__getstate__"), PyOp(LayerNorm)::getstate, METH_NOARGS, "LayerNorm getstate"},
  11722. {const_cast<char*>("__setstate__"), PyOp(LayerNorm)::setstate, METH_VARARGS, "LayerNorm setstate"},
  11723. {NULL} /* Sentinel */
  11724. };
  11725. PyObject *PyOp(LayerNorm)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  11726. if (PyOp(LayerNorm)::py_init(self, args, kwds) < 0) {
  11727. return NULL;
  11728. }
  11729. Py_RETURN_NONE;
  11730. }
  11731. PyMethodDef PyOp(LayerNorm)::py_init_methoddef = {
  11732. "__init__",
  11733. (PyCFunction)PyOp(LayerNorm)::py_init_proxy,
  11734. METH_VARARGS | METH_KEYWORDS,
  11735. "__init__(self, affine: bool = ..., eps: float = ..., normalized_dim: int = ..., normalized_size: int = ...) -> None\n"
  11736. };
  11737. void _init_py_LayerNorm(py::module m) {
  11738. using py_op = PyOp(LayerNorm);
  11739. auto& py_type = PyOpType(LayerNorm);
  11740. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11741. py_type.tp_name = "megengine.core._imperative_rt.ops.LayerNorm";
  11742. py_type.tp_basicsize = sizeof(PyOp(LayerNorm));
  11743. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11744. py_type.tp_doc = "LayerNorm";
  11745. py_type.tp_base = &PyOpType(OpDef);
  11746. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11747. py_type.tp_new = py_new_generic<py_op>;
  11748. py_type.tp_init = py_op::py_init;
  11749. py_type.tp_methods = py_op::tp_methods;
  11750. py_type.tp_getset = py_op::py_getsetters;
  11751. py_type.tp_dict = PyDict_New();
  11752. PyObject* descr = PyDescr_NewMethod(&PyOpType(LayerNorm), &PyOp(LayerNorm)::py_init_methoddef);
  11753. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  11754. mgb_assert(PyType_Ready(&py_type) >= 0);
  11755. PyType_Modified(&py_type);
  11756. m.add_object("LayerNorm", reinterpret_cast<PyObject*>(&py_type));
  11757. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LayerNorm::typeinfo(), &py_type).second);
  11758. }
  11759. PyOpDefBegin(Linspace) // {
  11760. static PyGetSetDef py_getsetters[];
  11761. static PyMethodDef tp_methods[];
  11762. static PyObject* getstate(PyObject* self, PyObject*) {
  11763. auto& opdef = reinterpret_cast<PyOp(Linspace)*>(self)->inst();
  11764. static_cast<void>(opdef);
  11765. std::unordered_map<std::string, py::object> state {
  11766. {"endpoint", serialization<decltype(opdef.endpoint)>::dump(opdef.endpoint)},
  11767. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)}
  11768. };
  11769. return py::cast(state).release().ptr();
  11770. }
  11771. static PyObject* setstate(PyObject* self, PyObject* args) {
  11772. PyObject* dict = PyTuple_GetItem(args, 0);
  11773. if (!dict) return NULL;
  11774. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11775. auto& opdef = reinterpret_cast<PyOp(Linspace)*>(self)->inst();
  11776. static_cast<void>(opdef);
  11777. {
  11778. auto&& iter = state.find("endpoint");
  11779. if (iter != state.end()) {
  11780. opdef.endpoint = serialization<decltype(opdef.endpoint)>::load(iter->second);
  11781. }
  11782. }
  11783. {
  11784. auto&& iter = state.find("comp_node");
  11785. if (iter != state.end()) {
  11786. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  11787. }
  11788. }
  11789. Py_RETURN_NONE;
  11790. }
  11791. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11792. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  11793. static PyMethodDef py_init_methoddef;
  11794. // };
  11795. PyOpDefEnd(Linspace)
  11796. int PyOp(Linspace)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11797. static const char* kwlist[] = {"endpoint", "comp_node", "scope", NULL};
  11798. PyObject *endpoint = NULL, *comp_node = NULL, *scope = NULL;
  11799. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &endpoint, &comp_node, &scope))
  11800. return -1;
  11801. if (endpoint) {
  11802. try {
  11803. // TODO: remove this guard which is used for pybind11 implicit conversion
  11804. py::detail::loader_life_support guard{};
  11805. reinterpret_cast<PyOp(Linspace)*>(self)->inst().endpoint =
  11806. py::cast<decltype(Linspace::endpoint)>(py::handle(endpoint));
  11807. } CATCH_ALL(-1)
  11808. }
  11809. if (comp_node) {
  11810. try {
  11811. // TODO: remove this guard which is used for pybind11 implicit conversion
  11812. py::detail::loader_life_support guard{};
  11813. reinterpret_cast<PyOp(Linspace)*>(self)->inst().comp_node =
  11814. py::cast<decltype(Linspace::comp_node)>(py::handle(comp_node));
  11815. } CATCH_ALL(-1)
  11816. }
  11817. if (scope) {
  11818. try {
  11819. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11820. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11821. } CATCH_ALL(-1)
  11822. }
  11823. return 0;
  11824. }
  11825. PyGetSetDef PyOp(Linspace)::py_getsetters[] = {
  11826. {const_cast<char*>("endpoint"), py_get_generic(Linspace, endpoint), py_set_generic(Linspace, endpoint), const_cast<char*>("endpoint"), NULL},
  11827. {const_cast<char*>("comp_node"), py_get_generic(Linspace, comp_node), py_set_generic(Linspace, comp_node), const_cast<char*>("comp_node"), NULL},
  11828. {NULL} /* Sentinel */
  11829. };
  11830. PyMethodDef PyOp(Linspace)::tp_methods[] = {
  11831. {const_cast<char*>("__getstate__"), PyOp(Linspace)::getstate, METH_NOARGS, "Linspace getstate"},
  11832. {const_cast<char*>("__setstate__"), PyOp(Linspace)::setstate, METH_VARARGS, "Linspace setstate"},
  11833. {NULL} /* Sentinel */
  11834. };
  11835. PyObject *PyOp(Linspace)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  11836. if (PyOp(Linspace)::py_init(self, args, kwds) < 0) {
  11837. return NULL;
  11838. }
  11839. Py_RETURN_NONE;
  11840. }
  11841. PyMethodDef PyOp(Linspace)::py_init_methoddef = {
  11842. "__init__",
  11843. (PyCFunction)PyOp(Linspace)::py_init_proxy,
  11844. METH_VARARGS | METH_KEYWORDS,
  11845. "__init__(self, endpoint: bool = ..., comp_node: str = ...) -> None\n"
  11846. };
  11847. void _init_py_Linspace(py::module m) {
  11848. using py_op = PyOp(Linspace);
  11849. auto& py_type = PyOpType(Linspace);
  11850. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11851. py_type.tp_name = "megengine.core._imperative_rt.ops.Linspace";
  11852. py_type.tp_basicsize = sizeof(PyOp(Linspace));
  11853. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11854. py_type.tp_doc = "Linspace";
  11855. py_type.tp_base = &PyOpType(OpDef);
  11856. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11857. py_type.tp_new = py_new_generic<py_op>;
  11858. py_type.tp_init = py_op::py_init;
  11859. py_type.tp_methods = py_op::tp_methods;
  11860. py_type.tp_getset = py_op::py_getsetters;
  11861. py_type.tp_dict = PyDict_New();
  11862. PyObject* descr = PyDescr_NewMethod(&PyOpType(Linspace), &PyOp(Linspace)::py_init_methoddef);
  11863. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  11864. mgb_assert(PyType_Ready(&py_type) >= 0);
  11865. PyType_Modified(&py_type);
  11866. m.add_object("Linspace", reinterpret_cast<PyObject*>(&py_type));
  11867. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Linspace::typeinfo(), &py_type).second);
  11868. }
  11869. PyOpDefBegin(MagicMindRuntime) // {
  11870. static PyGetSetDef py_getsetters[];
  11871. static PyMethodDef tp_methods[];
  11872. static PyObject* getstate(PyObject* self, PyObject*) {
  11873. auto& opdef = reinterpret_cast<PyOp(MagicMindRuntime)*>(self)->inst();
  11874. static_cast<void>(opdef);
  11875. std::unordered_map<std::string, py::object> state {
  11876. {"buf", serialization<decltype(opdef.buf)>::dump(opdef.buf)},
  11877. {"buf_size", serialization<decltype(opdef.buf_size)>::dump(opdef.buf_size)}
  11878. };
  11879. return py::cast(state).release().ptr();
  11880. }
  11881. static PyObject* setstate(PyObject* self, PyObject* args) {
  11882. PyObject* dict = PyTuple_GetItem(args, 0);
  11883. if (!dict) return NULL;
  11884. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11885. auto& opdef = reinterpret_cast<PyOp(MagicMindRuntime)*>(self)->inst();
  11886. static_cast<void>(opdef);
  11887. {
  11888. auto&& iter = state.find("buf");
  11889. if (iter != state.end()) {
  11890. opdef.buf = serialization<decltype(opdef.buf)>::load(iter->second);
  11891. }
  11892. }
  11893. {
  11894. auto&& iter = state.find("buf_size");
  11895. if (iter != state.end()) {
  11896. opdef.buf_size = serialization<decltype(opdef.buf_size)>::load(iter->second);
  11897. }
  11898. }
  11899. Py_RETURN_NONE;
  11900. }
  11901. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11902. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  11903. static PyMethodDef py_init_methoddef;
  11904. // };
  11905. PyOpDefEnd(MagicMindRuntime)
  11906. int PyOp(MagicMindRuntime)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11907. static const char* kwlist[] = {"buf", "buf_size", "scope", NULL};
  11908. PyObject *buf = NULL, *buf_size = NULL, *scope = NULL;
  11909. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &buf, &buf_size, &scope))
  11910. return -1;
  11911. if (buf) {
  11912. try {
  11913. // TODO: remove this guard which is used for pybind11 implicit conversion
  11914. py::detail::loader_life_support guard{};
  11915. reinterpret_cast<PyOp(MagicMindRuntime)*>(self)->inst().buf =
  11916. py::cast<decltype(MagicMindRuntime::buf)>(py::handle(buf));
  11917. } CATCH_ALL(-1)
  11918. }
  11919. if (buf_size) {
  11920. try {
  11921. // TODO: remove this guard which is used for pybind11 implicit conversion
  11922. py::detail::loader_life_support guard{};
  11923. reinterpret_cast<PyOp(MagicMindRuntime)*>(self)->inst().buf_size =
  11924. py::cast<decltype(MagicMindRuntime::buf_size)>(py::handle(buf_size));
  11925. } CATCH_ALL(-1)
  11926. }
  11927. if (scope) {
  11928. try {
  11929. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11930. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11931. } CATCH_ALL(-1)
  11932. }
  11933. return 0;
  11934. }
  11935. PyGetSetDef PyOp(MagicMindRuntime)::py_getsetters[] = {
  11936. {const_cast<char*>("buf"), py_get_generic(MagicMindRuntime, buf), py_set_generic(MagicMindRuntime, buf), const_cast<char*>("buf"), NULL},
  11937. {const_cast<char*>("buf_size"), py_get_generic(MagicMindRuntime, buf_size), py_set_generic(MagicMindRuntime, buf_size), const_cast<char*>("buf_size"), NULL},
  11938. {NULL} /* Sentinel */
  11939. };
  11940. PyMethodDef PyOp(MagicMindRuntime)::tp_methods[] = {
  11941. {const_cast<char*>("__getstate__"), PyOp(MagicMindRuntime)::getstate, METH_NOARGS, "MagicMindRuntime getstate"},
  11942. {const_cast<char*>("__setstate__"), PyOp(MagicMindRuntime)::setstate, METH_VARARGS, "MagicMindRuntime setstate"},
  11943. {NULL} /* Sentinel */
  11944. };
  11945. PyObject *PyOp(MagicMindRuntime)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  11946. if (PyOp(MagicMindRuntime)::py_init(self, args, kwds) < 0) {
  11947. return NULL;
  11948. }
  11949. Py_RETURN_NONE;
  11950. }
  11951. PyMethodDef PyOp(MagicMindRuntime)::py_init_methoddef = {
  11952. "__init__",
  11953. (PyCFunction)PyOp(MagicMindRuntime)::py_init_proxy,
  11954. METH_VARARGS | METH_KEYWORDS,
  11955. "__init__(self, buf: str = ..., buf_size: int = ...) -> None\n"
  11956. };
  11957. void _init_py_MagicMindRuntime(py::module m) {
  11958. using py_op = PyOp(MagicMindRuntime);
  11959. auto& py_type = PyOpType(MagicMindRuntime);
  11960. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11961. py_type.tp_name = "megengine.core._imperative_rt.ops.MagicMindRuntime";
  11962. py_type.tp_basicsize = sizeof(PyOp(MagicMindRuntime));
  11963. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11964. py_type.tp_doc = "MagicMindRuntime";
  11965. py_type.tp_base = &PyOpType(OpDef);
  11966. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11967. py_type.tp_new = py_new_generic<py_op>;
  11968. py_type.tp_init = py_op::py_init;
  11969. py_type.tp_methods = py_op::tp_methods;
  11970. py_type.tp_getset = py_op::py_getsetters;
  11971. py_type.tp_dict = PyDict_New();
  11972. PyObject* descr = PyDescr_NewMethod(&PyOpType(MagicMindRuntime), &PyOp(MagicMindRuntime)::py_init_methoddef);
  11973. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  11974. mgb_assert(PyType_Ready(&py_type) >= 0);
  11975. PyType_Modified(&py_type);
  11976. m.add_object("MagicMindRuntime", reinterpret_cast<PyObject*>(&py_type));
  11977. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MagicMindRuntime::typeinfo(), &py_type).second);
  11978. }
  11979. PyOpDefBegin(MatrixInverse) // {
  11980. static PyGetSetDef py_getsetters[];
  11981. static PyMethodDef tp_methods[];
  11982. static PyObject* getstate(PyObject* self, PyObject*) {
  11983. auto& opdef = reinterpret_cast<PyOp(MatrixInverse)*>(self)->inst();
  11984. static_cast<void>(opdef);
  11985. std::unordered_map<std::string, py::object> state {
  11986. };
  11987. return py::cast(state).release().ptr();
  11988. }
  11989. static PyObject* setstate(PyObject* self, PyObject* args) {
  11990. PyObject* dict = PyTuple_GetItem(args, 0);
  11991. if (!dict) return NULL;
  11992. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11993. auto& opdef = reinterpret_cast<PyOp(MatrixInverse)*>(self)->inst();
  11994. static_cast<void>(opdef);
  11995. Py_RETURN_NONE;
  11996. }
  11997. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11998. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  11999. static PyMethodDef py_init_methoddef;
  12000. // };
  12001. PyOpDefEnd(MatrixInverse)
  12002. int PyOp(MatrixInverse)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12003. return 0;
  12004. }
  12005. PyGetSetDef PyOp(MatrixInverse)::py_getsetters[] = {
  12006. {NULL} /* Sentinel */
  12007. };
  12008. PyMethodDef PyOp(MatrixInverse)::tp_methods[] = {
  12009. {const_cast<char*>("__getstate__"), PyOp(MatrixInverse)::getstate, METH_NOARGS, "MatrixInverse getstate"},
  12010. {const_cast<char*>("__setstate__"), PyOp(MatrixInverse)::setstate, METH_VARARGS, "MatrixInverse setstate"},
  12011. {NULL} /* Sentinel */
  12012. };
  12013. PyObject *PyOp(MatrixInverse)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  12014. if (PyOp(MatrixInverse)::py_init(self, args, kwds) < 0) {
  12015. return NULL;
  12016. }
  12017. Py_RETURN_NONE;
  12018. }
  12019. PyMethodDef PyOp(MatrixInverse)::py_init_methoddef = {
  12020. "__init__",
  12021. (PyCFunction)PyOp(MatrixInverse)::py_init_proxy,
  12022. METH_VARARGS | METH_KEYWORDS,
  12023. "__init__(self) -> None\n"
  12024. };
  12025. void _init_py_MatrixInverse(py::module m) {
  12026. using py_op = PyOp(MatrixInverse);
  12027. auto& py_type = PyOpType(MatrixInverse);
  12028. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12029. py_type.tp_name = "megengine.core._imperative_rt.ops.MatrixInverse";
  12030. py_type.tp_basicsize = sizeof(PyOp(MatrixInverse));
  12031. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12032. py_type.tp_doc = "MatrixInverse";
  12033. py_type.tp_base = &PyOpType(OpDef);
  12034. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12035. py_type.tp_new = py_new_generic<py_op>;
  12036. py_type.tp_init = py_op::py_init;
  12037. py_type.tp_methods = py_op::tp_methods;
  12038. py_type.tp_getset = py_op::py_getsetters;
  12039. py_type.tp_dict = PyDict_New();
  12040. PyObject* descr = PyDescr_NewMethod(&PyOpType(MatrixInverse), &PyOp(MatrixInverse)::py_init_methoddef);
  12041. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  12042. mgb_assert(PyType_Ready(&py_type) >= 0);
  12043. PyType_Modified(&py_type);
  12044. m.add_object("MatrixInverse", reinterpret_cast<PyObject*>(&py_type));
  12045. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MatrixInverse::typeinfo(), &py_type).second);
  12046. }
  12047. void _init_py_MatrixMul_ComputeMode(PyTypeObject& py_type) {
  12048. auto& e_type = EnumWrapper<MatrixMul::ComputeMode>::type;
  12049. Py_INCREF(e_type);
  12050. mgb_assert(PyDict_SetItemString(
  12051. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12052. }
  12053. void _init_py_MatrixMul_Format(PyTypeObject& py_type) {
  12054. auto& e_type = EnumWrapper<MatrixMul::Format>::type;
  12055. Py_INCREF(e_type);
  12056. mgb_assert(PyDict_SetItemString(
  12057. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12058. }
  12059. void _init_py_MatrixMul_Strategy(PyTypeObject& py_type) {
  12060. auto& e_type = BitCombinedEnumWrapper<MatrixMul::Strategy>::type;
  12061. Py_INCREF(e_type);
  12062. mgb_assert(PyDict_SetItemString(
  12063. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12064. }
  12065. PyOpDefBegin(MatrixMul) // {
  12066. static PyGetSetDef py_getsetters[];
  12067. static PyMethodDef tp_methods[];
  12068. static PyObject* getstate(PyObject* self, PyObject*) {
  12069. auto& opdef = reinterpret_cast<PyOp(MatrixMul)*>(self)->inst();
  12070. static_cast<void>(opdef);
  12071. std::unordered_map<std::string, py::object> state {
  12072. {"transposeA", serialization<decltype(opdef.transposeA)>::dump(opdef.transposeA)},
  12073. {"transposeB", serialization<decltype(opdef.transposeB)>::dump(opdef.transposeB)},
  12074. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  12075. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  12076. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  12077. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)},
  12078. {"dimA", serialization<decltype(opdef.dimA)>::dump(opdef.dimA)},
  12079. {"dimB", serialization<decltype(opdef.dimB)>::dump(opdef.dimB)}
  12080. };
  12081. return py::cast(state).release().ptr();
  12082. }
  12083. static PyObject* setstate(PyObject* self, PyObject* args) {
  12084. PyObject* dict = PyTuple_GetItem(args, 0);
  12085. if (!dict) return NULL;
  12086. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12087. auto& opdef = reinterpret_cast<PyOp(MatrixMul)*>(self)->inst();
  12088. static_cast<void>(opdef);
  12089. {
  12090. auto&& iter = state.find("transposeA");
  12091. if (iter != state.end()) {
  12092. opdef.transposeA = serialization<decltype(opdef.transposeA)>::load(iter->second);
  12093. }
  12094. }
  12095. {
  12096. auto&& iter = state.find("transposeB");
  12097. if (iter != state.end()) {
  12098. opdef.transposeB = serialization<decltype(opdef.transposeB)>::load(iter->second);
  12099. }
  12100. }
  12101. {
  12102. auto&& iter = state.find("compute_mode");
  12103. if (iter != state.end()) {
  12104. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  12105. }
  12106. }
  12107. {
  12108. auto&& iter = state.find("format");
  12109. if (iter != state.end()) {
  12110. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  12111. }
  12112. }
  12113. {
  12114. auto&& iter = state.find("strategy");
  12115. if (iter != state.end()) {
  12116. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  12117. }
  12118. }
  12119. {
  12120. auto&& iter = state.find("workspace_limit");
  12121. if (iter != state.end()) {
  12122. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  12123. }
  12124. }
  12125. {
  12126. auto&& iter = state.find("dimA");
  12127. if (iter != state.end()) {
  12128. opdef.dimA = serialization<decltype(opdef.dimA)>::load(iter->second);
  12129. }
  12130. }
  12131. {
  12132. auto&& iter = state.find("dimB");
  12133. if (iter != state.end()) {
  12134. opdef.dimB = serialization<decltype(opdef.dimB)>::load(iter->second);
  12135. }
  12136. }
  12137. Py_RETURN_NONE;
  12138. }
  12139. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12140. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  12141. static PyMethodDef py_init_methoddef;
  12142. // };
  12143. PyOpDefEnd(MatrixMul)
  12144. int PyOp(MatrixMul)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12145. static const char* kwlist[] = {"transposeA", "transposeB", "compute_mode", "format", "strategy", "workspace_limit", "dimA", "dimB", "scope", NULL};
  12146. PyObject *transposeA = NULL, *transposeB = NULL, *compute_mode = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *dimA = NULL, *dimB = NULL, *scope = NULL;
  12147. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &transposeA, &transposeB, &compute_mode, &format, &strategy, &workspace_limit, &dimA, &dimB, &scope))
  12148. return -1;
  12149. if (transposeA) {
  12150. try {
  12151. // TODO: remove this guard which is used for pybind11 implicit conversion
  12152. py::detail::loader_life_support guard{};
  12153. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().transposeA =
  12154. py::cast<decltype(MatrixMul::transposeA)>(py::handle(transposeA));
  12155. } CATCH_ALL(-1)
  12156. }
  12157. if (transposeB) {
  12158. try {
  12159. // TODO: remove this guard which is used for pybind11 implicit conversion
  12160. py::detail::loader_life_support guard{};
  12161. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().transposeB =
  12162. py::cast<decltype(MatrixMul::transposeB)>(py::handle(transposeB));
  12163. } CATCH_ALL(-1)
  12164. }
  12165. if (compute_mode) {
  12166. try {
  12167. // TODO: remove this guard which is used for pybind11 implicit conversion
  12168. py::detail::loader_life_support guard{};
  12169. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().compute_mode =
  12170. py::cast<decltype(MatrixMul::compute_mode)>(py::handle(compute_mode));
  12171. } CATCH_ALL(-1)
  12172. }
  12173. if (format) {
  12174. try {
  12175. // TODO: remove this guard which is used for pybind11 implicit conversion
  12176. py::detail::loader_life_support guard{};
  12177. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().format =
  12178. py::cast<decltype(MatrixMul::format)>(py::handle(format));
  12179. } CATCH_ALL(-1)
  12180. }
  12181. if (strategy) {
  12182. try {
  12183. // TODO: remove this guard which is used for pybind11 implicit conversion
  12184. py::detail::loader_life_support guard{};
  12185. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().strategy =
  12186. py::cast<decltype(MatrixMul::strategy)>(py::handle(strategy));
  12187. } CATCH_ALL(-1)
  12188. }
  12189. if (workspace_limit) {
  12190. try {
  12191. // TODO: remove this guard which is used for pybind11 implicit conversion
  12192. py::detail::loader_life_support guard{};
  12193. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().workspace_limit =
  12194. py::cast<decltype(MatrixMul::workspace_limit)>(py::handle(workspace_limit));
  12195. } CATCH_ALL(-1)
  12196. }
  12197. if (dimA) {
  12198. try {
  12199. // TODO: remove this guard which is used for pybind11 implicit conversion
  12200. py::detail::loader_life_support guard{};
  12201. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().dimA =
  12202. py::cast<decltype(MatrixMul::dimA)>(py::handle(dimA));
  12203. } CATCH_ALL(-1)
  12204. }
  12205. if (dimB) {
  12206. try {
  12207. // TODO: remove this guard which is used for pybind11 implicit conversion
  12208. py::detail::loader_life_support guard{};
  12209. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().dimB =
  12210. py::cast<decltype(MatrixMul::dimB)>(py::handle(dimB));
  12211. } CATCH_ALL(-1)
  12212. }
  12213. if (scope) {
  12214. try {
  12215. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12216. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12217. } CATCH_ALL(-1)
  12218. }
  12219. return 0;
  12220. }
  12221. PyGetSetDef PyOp(MatrixMul)::py_getsetters[] = {
  12222. {const_cast<char*>("transposeA"), py_get_generic(MatrixMul, transposeA), py_set_generic(MatrixMul, transposeA), const_cast<char*>("transposeA"), NULL},
  12223. {const_cast<char*>("transposeB"), py_get_generic(MatrixMul, transposeB), py_set_generic(MatrixMul, transposeB), const_cast<char*>("transposeB"), NULL},
  12224. {const_cast<char*>("compute_mode"), py_get_generic(MatrixMul, compute_mode), py_set_generic(MatrixMul, compute_mode), const_cast<char*>("compute_mode"), NULL},
  12225. {const_cast<char*>("format"), py_get_generic(MatrixMul, format), py_set_generic(MatrixMul, format), const_cast<char*>("format"), NULL},
  12226. {const_cast<char*>("strategy"), py_get_generic(MatrixMul, strategy), py_set_generic(MatrixMul, strategy), const_cast<char*>("strategy"), NULL},
  12227. {const_cast<char*>("workspace_limit"), py_get_generic(MatrixMul, workspace_limit), py_set_generic(MatrixMul, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  12228. {const_cast<char*>("dimA"), py_get_generic(MatrixMul, dimA), py_set_generic(MatrixMul, dimA), const_cast<char*>("dimA"), NULL},
  12229. {const_cast<char*>("dimB"), py_get_generic(MatrixMul, dimB), py_set_generic(MatrixMul, dimB), const_cast<char*>("dimB"), NULL},
  12230. {NULL} /* Sentinel */
  12231. };
  12232. PyMethodDef PyOp(MatrixMul)::tp_methods[] = {
  12233. {const_cast<char*>("__getstate__"), PyOp(MatrixMul)::getstate, METH_NOARGS, "MatrixMul getstate"},
  12234. {const_cast<char*>("__setstate__"), PyOp(MatrixMul)::setstate, METH_VARARGS, "MatrixMul setstate"},
  12235. {NULL} /* Sentinel */
  12236. };
  12237. PyObject *PyOp(MatrixMul)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  12238. if (PyOp(MatrixMul)::py_init(self, args, kwds) < 0) {
  12239. return NULL;
  12240. }
  12241. Py_RETURN_NONE;
  12242. }
  12243. PyMethodDef PyOp(MatrixMul)::py_init_methoddef = {
  12244. "__init__",
  12245. (PyCFunction)PyOp(MatrixMul)::py_init_proxy,
  12246. METH_VARARGS | METH_KEYWORDS,
  12247. "__init__(self, transposeA: bool = ..., transposeB: bool = ..., compute_mode: Union[str, ComputeMode] = ..., format: Union[str, Format] = ..., strategy: Union[str, Strategy] = ..., dimA: int = ..., dimB: int = ...) -> None\n"
  12248. };
  12249. void _init_py_MatrixMul(py::module m) {
  12250. using py_op = PyOp(MatrixMul);
  12251. auto& py_type = PyOpType(MatrixMul);
  12252. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12253. py_type.tp_name = "megengine.core._imperative_rt.ops.MatrixMul";
  12254. py_type.tp_basicsize = sizeof(PyOp(MatrixMul));
  12255. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12256. py_type.tp_doc = "MatrixMul";
  12257. py_type.tp_base = &PyOpType(OpDef);
  12258. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12259. py_type.tp_new = py_new_generic<py_op>;
  12260. py_type.tp_init = py_op::py_init;
  12261. py_type.tp_methods = py_op::tp_methods;
  12262. py_type.tp_getset = py_op::py_getsetters;
  12263. py_type.tp_dict = PyDict_New();
  12264. PyObject* descr = PyDescr_NewMethod(&PyOpType(MatrixMul), &PyOp(MatrixMul)::py_init_methoddef);
  12265. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  12266. mgb_assert(PyType_Ready(&py_type) >= 0);
  12267. _init_py_MatrixMul_ComputeMode(py_type);
  12268. _init_py_MatrixMul_Format(py_type);
  12269. _init_py_MatrixMul_Strategy(py_type);
  12270. PyType_Modified(&py_type);
  12271. m.add_object("MatrixMul", reinterpret_cast<PyObject*>(&py_type));
  12272. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MatrixMul::typeinfo(), &py_type).second);
  12273. }
  12274. PyOpDefBegin(MeshGrid) // {
  12275. static PyGetSetDef py_getsetters[];
  12276. static PyMethodDef tp_methods[];
  12277. static PyObject* getstate(PyObject* self, PyObject*) {
  12278. auto& opdef = reinterpret_cast<PyOp(MeshGrid)*>(self)->inst();
  12279. static_cast<void>(opdef);
  12280. std::unordered_map<std::string, py::object> state {
  12281. {"indexing", serialization<decltype(opdef.indexing)>::dump(opdef.indexing)}
  12282. };
  12283. return py::cast(state).release().ptr();
  12284. }
  12285. static PyObject* setstate(PyObject* self, PyObject* args) {
  12286. PyObject* dict = PyTuple_GetItem(args, 0);
  12287. if (!dict) return NULL;
  12288. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12289. auto& opdef = reinterpret_cast<PyOp(MeshGrid)*>(self)->inst();
  12290. static_cast<void>(opdef);
  12291. {
  12292. auto&& iter = state.find("indexing");
  12293. if (iter != state.end()) {
  12294. opdef.indexing = serialization<decltype(opdef.indexing)>::load(iter->second);
  12295. }
  12296. }
  12297. Py_RETURN_NONE;
  12298. }
  12299. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12300. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  12301. static PyMethodDef py_init_methoddef;
  12302. // };
  12303. PyOpDefEnd(MeshGrid)
  12304. int PyOp(MeshGrid)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12305. static const char* kwlist[] = {"indexing", "scope", NULL};
  12306. PyObject *indexing = NULL, *scope = NULL;
  12307. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &indexing, &scope))
  12308. return -1;
  12309. if (indexing) {
  12310. try {
  12311. // TODO: remove this guard which is used for pybind11 implicit conversion
  12312. py::detail::loader_life_support guard{};
  12313. reinterpret_cast<PyOp(MeshGrid)*>(self)->inst().indexing =
  12314. py::cast<decltype(MeshGrid::indexing)>(py::handle(indexing));
  12315. } CATCH_ALL(-1)
  12316. }
  12317. if (scope) {
  12318. try {
  12319. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12320. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12321. } CATCH_ALL(-1)
  12322. }
  12323. return 0;
  12324. }
  12325. PyGetSetDef PyOp(MeshGrid)::py_getsetters[] = {
  12326. {const_cast<char*>("indexing"), py_get_generic(MeshGrid, indexing), py_set_generic(MeshGrid, indexing), const_cast<char*>("indexing"), NULL},
  12327. {NULL} /* Sentinel */
  12328. };
  12329. PyMethodDef PyOp(MeshGrid)::tp_methods[] = {
  12330. {const_cast<char*>("__getstate__"), PyOp(MeshGrid)::getstate, METH_NOARGS, "MeshGrid getstate"},
  12331. {const_cast<char*>("__setstate__"), PyOp(MeshGrid)::setstate, METH_VARARGS, "MeshGrid setstate"},
  12332. {NULL} /* Sentinel */
  12333. };
  12334. PyObject *PyOp(MeshGrid)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  12335. if (PyOp(MeshGrid)::py_init(self, args, kwds) < 0) {
  12336. return NULL;
  12337. }
  12338. Py_RETURN_NONE;
  12339. }
  12340. PyMethodDef PyOp(MeshGrid)::py_init_methoddef = {
  12341. "__init__",
  12342. (PyCFunction)PyOp(MeshGrid)::py_init_proxy,
  12343. METH_VARARGS | METH_KEYWORDS,
  12344. "__init__(self, indexing: str = ...) -> None\n"
  12345. };
  12346. void _init_py_MeshGrid(py::module m) {
  12347. using py_op = PyOp(MeshGrid);
  12348. auto& py_type = PyOpType(MeshGrid);
  12349. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12350. py_type.tp_name = "megengine.core._imperative_rt.ops.MeshGrid";
  12351. py_type.tp_basicsize = sizeof(PyOp(MeshGrid));
  12352. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12353. py_type.tp_doc = "MeshGrid";
  12354. py_type.tp_base = &PyOpType(OpDef);
  12355. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12356. py_type.tp_new = py_new_generic<py_op>;
  12357. py_type.tp_init = py_op::py_init;
  12358. py_type.tp_methods = py_op::tp_methods;
  12359. py_type.tp_getset = py_op::py_getsetters;
  12360. py_type.tp_dict = PyDict_New();
  12361. PyObject* descr = PyDescr_NewMethod(&PyOpType(MeshGrid), &PyOp(MeshGrid)::py_init_methoddef);
  12362. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  12363. mgb_assert(PyType_Ready(&py_type) >= 0);
  12364. PyType_Modified(&py_type);
  12365. m.add_object("MeshGrid", reinterpret_cast<PyObject*>(&py_type));
  12366. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MeshGrid::typeinfo(), &py_type).second);
  12367. }
  12368. PyOpDefBegin(MeshIndexing) // {
  12369. static PyGetSetDef py_getsetters[];
  12370. static PyMethodDef tp_methods[];
  12371. static PyObject* getstate(PyObject* self, PyObject*) {
  12372. auto& opdef = reinterpret_cast<PyOp(MeshIndexing)*>(self)->inst();
  12373. static_cast<void>(opdef);
  12374. std::unordered_map<std::string, py::object> state {
  12375. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  12376. };
  12377. return py::cast(state).release().ptr();
  12378. }
  12379. static PyObject* setstate(PyObject* self, PyObject* args) {
  12380. PyObject* dict = PyTuple_GetItem(args, 0);
  12381. if (!dict) return NULL;
  12382. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12383. auto& opdef = reinterpret_cast<PyOp(MeshIndexing)*>(self)->inst();
  12384. static_cast<void>(opdef);
  12385. {
  12386. auto&& iter = state.find("items");
  12387. if (iter != state.end()) {
  12388. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  12389. }
  12390. }
  12391. Py_RETURN_NONE;
  12392. }
  12393. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12394. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  12395. static PyMethodDef py_init_methoddef;
  12396. // };
  12397. PyOpDefEnd(MeshIndexing)
  12398. int PyOp(MeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12399. static const char* kwlist[] = {"items", "scope", NULL};
  12400. PyObject *items = NULL, *scope = NULL;
  12401. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  12402. return -1;
  12403. if (items) {
  12404. try {
  12405. // TODO: remove this guard which is used for pybind11 implicit conversion
  12406. py::detail::loader_life_support guard{};
  12407. reinterpret_cast<PyOp(MeshIndexing)*>(self)->inst().items =
  12408. py::cast<decltype(MeshIndexing::items)>(py::handle(items));
  12409. } CATCH_ALL(-1)
  12410. }
  12411. if (scope) {
  12412. try {
  12413. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12414. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12415. } CATCH_ALL(-1)
  12416. }
  12417. return 0;
  12418. }
  12419. PyGetSetDef PyOp(MeshIndexing)::py_getsetters[] = {
  12420. {const_cast<char*>("items"), py_get_generic(MeshIndexing, items), py_set_generic(MeshIndexing, items), const_cast<char*>("items"), NULL},
  12421. {NULL} /* Sentinel */
  12422. };
  12423. PyMethodDef PyOp(MeshIndexing)::tp_methods[] = {
  12424. {const_cast<char*>("__getstate__"), PyOp(MeshIndexing)::getstate, METH_NOARGS, "MeshIndexing getstate"},
  12425. {const_cast<char*>("__setstate__"), PyOp(MeshIndexing)::setstate, METH_VARARGS, "MeshIndexing setstate"},
  12426. {NULL} /* Sentinel */
  12427. };
  12428. PyObject *PyOp(MeshIndexing)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  12429. if (PyOp(MeshIndexing)::py_init(self, args, kwds) < 0) {
  12430. return NULL;
  12431. }
  12432. Py_RETURN_NONE;
  12433. }
  12434. PyMethodDef PyOp(MeshIndexing)::py_init_methoddef = {
  12435. "__init__",
  12436. (PyCFunction)PyOp(MeshIndexing)::py_init_proxy,
  12437. METH_VARARGS | METH_KEYWORDS,
  12438. "__init__(self, items: list[tuple[int, bool, bool, bool, bool]] = ...) -> None\n"
  12439. };
  12440. void _init_py_MeshIndexing(py::module m) {
  12441. using py_op = PyOp(MeshIndexing);
  12442. auto& py_type = PyOpType(MeshIndexing);
  12443. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12444. py_type.tp_name = "megengine.core._imperative_rt.ops.MeshIndexing";
  12445. py_type.tp_basicsize = sizeof(PyOp(MeshIndexing));
  12446. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12447. py_type.tp_doc = "MeshIndexing";
  12448. py_type.tp_base = &PyOpType(OpDef);
  12449. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12450. py_type.tp_new = py_new_generic<py_op>;
  12451. py_type.tp_init = py_op::py_init;
  12452. py_type.tp_methods = py_op::tp_methods;
  12453. py_type.tp_getset = py_op::py_getsetters;
  12454. py_type.tp_dict = PyDict_New();
  12455. PyObject* descr = PyDescr_NewMethod(&PyOpType(MeshIndexing), &PyOp(MeshIndexing)::py_init_methoddef);
  12456. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  12457. mgb_assert(PyType_Ready(&py_type) >= 0);
  12458. PyType_Modified(&py_type);
  12459. m.add_object("MeshIndexing", reinterpret_cast<PyObject*>(&py_type));
  12460. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MeshIndexing::typeinfo(), &py_type).second);
  12461. }
  12462. PyOpDefBegin(NMSKeep) // {
  12463. static PyGetSetDef py_getsetters[];
  12464. static PyMethodDef tp_methods[];
  12465. static PyObject* getstate(PyObject* self, PyObject*) {
  12466. auto& opdef = reinterpret_cast<PyOp(NMSKeep)*>(self)->inst();
  12467. static_cast<void>(opdef);
  12468. std::unordered_map<std::string, py::object> state {
  12469. {"iou_thresh", serialization<decltype(opdef.iou_thresh)>::dump(opdef.iou_thresh)},
  12470. {"max_output", serialization<decltype(opdef.max_output)>::dump(opdef.max_output)}
  12471. };
  12472. return py::cast(state).release().ptr();
  12473. }
  12474. static PyObject* setstate(PyObject* self, PyObject* args) {
  12475. PyObject* dict = PyTuple_GetItem(args, 0);
  12476. if (!dict) return NULL;
  12477. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12478. auto& opdef = reinterpret_cast<PyOp(NMSKeep)*>(self)->inst();
  12479. static_cast<void>(opdef);
  12480. {
  12481. auto&& iter = state.find("iou_thresh");
  12482. if (iter != state.end()) {
  12483. opdef.iou_thresh = serialization<decltype(opdef.iou_thresh)>::load(iter->second);
  12484. }
  12485. }
  12486. {
  12487. auto&& iter = state.find("max_output");
  12488. if (iter != state.end()) {
  12489. opdef.max_output = serialization<decltype(opdef.max_output)>::load(iter->second);
  12490. }
  12491. }
  12492. Py_RETURN_NONE;
  12493. }
  12494. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12495. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  12496. static PyMethodDef py_init_methoddef;
  12497. // };
  12498. PyOpDefEnd(NMSKeep)
  12499. int PyOp(NMSKeep)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12500. static const char* kwlist[] = {"iou_thresh", "max_output", "scope", NULL};
  12501. PyObject *iou_thresh = NULL, *max_output = NULL, *scope = NULL;
  12502. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &iou_thresh, &max_output, &scope))
  12503. return -1;
  12504. if (iou_thresh) {
  12505. try {
  12506. // TODO: remove this guard which is used for pybind11 implicit conversion
  12507. py::detail::loader_life_support guard{};
  12508. reinterpret_cast<PyOp(NMSKeep)*>(self)->inst().iou_thresh =
  12509. py::cast<decltype(NMSKeep::iou_thresh)>(py::handle(iou_thresh));
  12510. } CATCH_ALL(-1)
  12511. }
  12512. if (max_output) {
  12513. try {
  12514. // TODO: remove this guard which is used for pybind11 implicit conversion
  12515. py::detail::loader_life_support guard{};
  12516. reinterpret_cast<PyOp(NMSKeep)*>(self)->inst().max_output =
  12517. py::cast<decltype(NMSKeep::max_output)>(py::handle(max_output));
  12518. } CATCH_ALL(-1)
  12519. }
  12520. if (scope) {
  12521. try {
  12522. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12523. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12524. } CATCH_ALL(-1)
  12525. }
  12526. return 0;
  12527. }
  12528. PyGetSetDef PyOp(NMSKeep)::py_getsetters[] = {
  12529. {const_cast<char*>("iou_thresh"), py_get_generic(NMSKeep, iou_thresh), py_set_generic(NMSKeep, iou_thresh), const_cast<char*>("iou_thresh"), NULL},
  12530. {const_cast<char*>("max_output"), py_get_generic(NMSKeep, max_output), py_set_generic(NMSKeep, max_output), const_cast<char*>("max_output"), NULL},
  12531. {NULL} /* Sentinel */
  12532. };
  12533. PyMethodDef PyOp(NMSKeep)::tp_methods[] = {
  12534. {const_cast<char*>("__getstate__"), PyOp(NMSKeep)::getstate, METH_NOARGS, "NMSKeep getstate"},
  12535. {const_cast<char*>("__setstate__"), PyOp(NMSKeep)::setstate, METH_VARARGS, "NMSKeep setstate"},
  12536. {NULL} /* Sentinel */
  12537. };
  12538. PyObject *PyOp(NMSKeep)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  12539. if (PyOp(NMSKeep)::py_init(self, args, kwds) < 0) {
  12540. return NULL;
  12541. }
  12542. Py_RETURN_NONE;
  12543. }
  12544. PyMethodDef PyOp(NMSKeep)::py_init_methoddef = {
  12545. "__init__",
  12546. (PyCFunction)PyOp(NMSKeep)::py_init_proxy,
  12547. METH_VARARGS | METH_KEYWORDS,
  12548. "__init__(self, iou_thresh: float = ..., max_output: int = ...) -> None\n"
  12549. };
  12550. void _init_py_NMSKeep(py::module m) {
  12551. using py_op = PyOp(NMSKeep);
  12552. auto& py_type = PyOpType(NMSKeep);
  12553. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12554. py_type.tp_name = "megengine.core._imperative_rt.ops.NMSKeep";
  12555. py_type.tp_basicsize = sizeof(PyOp(NMSKeep));
  12556. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12557. py_type.tp_doc = "NMSKeep";
  12558. py_type.tp_base = &PyOpType(OpDef);
  12559. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12560. py_type.tp_new = py_new_generic<py_op>;
  12561. py_type.tp_init = py_op::py_init;
  12562. py_type.tp_methods = py_op::tp_methods;
  12563. py_type.tp_getset = py_op::py_getsetters;
  12564. py_type.tp_dict = PyDict_New();
  12565. PyObject* descr = PyDescr_NewMethod(&PyOpType(NMSKeep), &PyOp(NMSKeep)::py_init_methoddef);
  12566. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  12567. mgb_assert(PyType_Ready(&py_type) >= 0);
  12568. PyType_Modified(&py_type);
  12569. m.add_object("NMSKeep", reinterpret_cast<PyObject*>(&py_type));
  12570. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(NMSKeep::typeinfo(), &py_type).second);
  12571. }
  12572. PyOpDefBegin(NvOf) // {
  12573. static PyGetSetDef py_getsetters[];
  12574. static PyMethodDef tp_methods[];
  12575. static PyObject* getstate(PyObject* self, PyObject*) {
  12576. auto& opdef = reinterpret_cast<PyOp(NvOf)*>(self)->inst();
  12577. static_cast<void>(opdef);
  12578. std::unordered_map<std::string, py::object> state {
  12579. {"precision", serialization<decltype(opdef.precision)>::dump(opdef.precision)}
  12580. };
  12581. return py::cast(state).release().ptr();
  12582. }
  12583. static PyObject* setstate(PyObject* self, PyObject* args) {
  12584. PyObject* dict = PyTuple_GetItem(args, 0);
  12585. if (!dict) return NULL;
  12586. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12587. auto& opdef = reinterpret_cast<PyOp(NvOf)*>(self)->inst();
  12588. static_cast<void>(opdef);
  12589. {
  12590. auto&& iter = state.find("precision");
  12591. if (iter != state.end()) {
  12592. opdef.precision = serialization<decltype(opdef.precision)>::load(iter->second);
  12593. }
  12594. }
  12595. Py_RETURN_NONE;
  12596. }
  12597. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12598. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  12599. static PyMethodDef py_init_methoddef;
  12600. // };
  12601. PyOpDefEnd(NvOf)
  12602. int PyOp(NvOf)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12603. static const char* kwlist[] = {"precision", "scope", NULL};
  12604. PyObject *precision = NULL, *scope = NULL;
  12605. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &precision, &scope))
  12606. return -1;
  12607. if (precision) {
  12608. try {
  12609. // TODO: remove this guard which is used for pybind11 implicit conversion
  12610. py::detail::loader_life_support guard{};
  12611. reinterpret_cast<PyOp(NvOf)*>(self)->inst().precision =
  12612. py::cast<decltype(NvOf::precision)>(py::handle(precision));
  12613. } CATCH_ALL(-1)
  12614. }
  12615. if (scope) {
  12616. try {
  12617. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12618. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12619. } CATCH_ALL(-1)
  12620. }
  12621. return 0;
  12622. }
  12623. PyGetSetDef PyOp(NvOf)::py_getsetters[] = {
  12624. {const_cast<char*>("precision"), py_get_generic(NvOf, precision), py_set_generic(NvOf, precision), const_cast<char*>("precision"), NULL},
  12625. {NULL} /* Sentinel */
  12626. };
  12627. PyMethodDef PyOp(NvOf)::tp_methods[] = {
  12628. {const_cast<char*>("__getstate__"), PyOp(NvOf)::getstate, METH_NOARGS, "NvOf getstate"},
  12629. {const_cast<char*>("__setstate__"), PyOp(NvOf)::setstate, METH_VARARGS, "NvOf setstate"},
  12630. {NULL} /* Sentinel */
  12631. };
  12632. PyObject *PyOp(NvOf)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  12633. if (PyOp(NvOf)::py_init(self, args, kwds) < 0) {
  12634. return NULL;
  12635. }
  12636. Py_RETURN_NONE;
  12637. }
  12638. PyMethodDef PyOp(NvOf)::py_init_methoddef = {
  12639. "__init__",
  12640. (PyCFunction)PyOp(NvOf)::py_init_proxy,
  12641. METH_VARARGS | METH_KEYWORDS,
  12642. "__init__(self, precision: int = ...) -> None\n"
  12643. };
  12644. void _init_py_NvOf(py::module m) {
  12645. using py_op = PyOp(NvOf);
  12646. auto& py_type = PyOpType(NvOf);
  12647. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12648. py_type.tp_name = "megengine.core._imperative_rt.ops.NvOf";
  12649. py_type.tp_basicsize = sizeof(PyOp(NvOf));
  12650. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12651. py_type.tp_doc = "NvOf";
  12652. py_type.tp_base = &PyOpType(OpDef);
  12653. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12654. py_type.tp_new = py_new_generic<py_op>;
  12655. py_type.tp_init = py_op::py_init;
  12656. py_type.tp_methods = py_op::tp_methods;
  12657. py_type.tp_getset = py_op::py_getsetters;
  12658. py_type.tp_dict = PyDict_New();
  12659. PyObject* descr = PyDescr_NewMethod(&PyOpType(NvOf), &PyOp(NvOf)::py_init_methoddef);
  12660. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  12661. mgb_assert(PyType_Ready(&py_type) >= 0);
  12662. PyType_Modified(&py_type);
  12663. m.add_object("NvOf", reinterpret_cast<PyObject*>(&py_type));
  12664. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(NvOf::typeinfo(), &py_type).second);
  12665. }
  12666. template<> struct EnumTrait<Padding::PaddingMode> {
  12667. static constexpr const char *name = "Padding.PaddingMode";
  12668. static constexpr std::underlying_type_t<Padding::PaddingMode> max = 3 - 1;
  12669. };
  12670. template<> PyTypeObject* EnumWrapper<Padding::PaddingMode>::type = nullptr;
  12671. template<> const char*
  12672. EnumWrapper<Padding::PaddingMode>::members[] = {"REPLICATE", "REFLECT", "CONSTANT"};
  12673. template<> std::unordered_map<std::string, Padding::PaddingMode>
  12674. EnumWrapper<Padding::PaddingMode>::mem2value = {{normalize_enum("REPLICATE"), Padding::PaddingMode::REPLICATE}, {normalize_enum("REFLECT"), Padding::PaddingMode::REFLECT}, {normalize_enum("CONSTANT"), Padding::PaddingMode::CONSTANT}};
  12675. template<> PyObject* EnumWrapper<Padding::PaddingMode>::pyobj_insts[3] = {nullptr};
  12676. void _init_py_Padding_PaddingMode(PyTypeObject& py_type) {
  12677. auto& e_type = EnumWrapper<Padding::PaddingMode>::type;
  12678. static PyMethodDef tp_methods[] = {
  12679. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Padding::PaddingMode>::py_dump, METH_NOARGS, NULL},
  12680. {NULL} /* Sentinel */
  12681. };
  12682. static PyType_Slot slots[] = {
  12683. {Py_tp_repr, (void*)EnumWrapper<Padding::PaddingMode>::py_repr},
  12684. {Py_tp_richcompare, (void*)EnumWrapper<Padding::PaddingMode>::tp_richcompare},
  12685. {Py_tp_methods, tp_methods},
  12686. {0, NULL}
  12687. };
  12688. static PyType_Spec spec = {
  12689. // name
  12690. "megengine.core._imperative_rt.ops.Padding.PaddingMode",
  12691. // basicsize
  12692. sizeof(EnumWrapper<Padding::PaddingMode>),
  12693. // itemsize
  12694. 0,
  12695. // flags
  12696. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  12697. // slots
  12698. slots
  12699. };
  12700. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  12701. mgb_assert(
  12702. e_type->tp_setattro(
  12703. reinterpret_cast<PyObject*>(e_type),
  12704. py::cast("__name__").release().ptr(),
  12705. py::cast("PaddingMode").release().ptr()) >= 0);
  12706. mgb_assert(
  12707. e_type->tp_setattro(
  12708. reinterpret_cast<PyObject*>(e_type),
  12709. py::cast("__module__").release().ptr(),
  12710. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  12711. mgb_assert(
  12712. e_type->tp_setattro(
  12713. reinterpret_cast<PyObject*>(e_type),
  12714. py::cast("__qualname__").release().ptr(),
  12715. py::cast("Padding.PaddingMode").release().ptr()) >= 0);
  12716. {
  12717. PyObject* inst = e_type->tp_alloc(e_type, 0);
  12718. reinterpret_cast<EnumWrapper<Padding::PaddingMode>*>(inst)->value = Padding::PaddingMode::REPLICATE;
  12719. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REPLICATE", inst) >= 0);
  12720. EnumWrapper<Padding::PaddingMode>::pyobj_insts[0] = inst;
  12721. }{
  12722. PyObject* inst = e_type->tp_alloc(e_type, 0);
  12723. reinterpret_cast<EnumWrapper<Padding::PaddingMode>*>(inst)->value = Padding::PaddingMode::REFLECT;
  12724. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REFLECT", inst) >= 0);
  12725. EnumWrapper<Padding::PaddingMode>::pyobj_insts[1] = inst;
  12726. }{
  12727. PyObject* inst = e_type->tp_alloc(e_type, 0);
  12728. reinterpret_cast<EnumWrapper<Padding::PaddingMode>*>(inst)->value = Padding::PaddingMode::CONSTANT;
  12729. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CONSTANT", inst) >= 0);
  12730. EnumWrapper<Padding::PaddingMode>::pyobj_insts[2] = inst;
  12731. }
  12732. Py_INCREF(e_type);
  12733. mgb_assert(PyDict_SetItemString(
  12734. py_type.tp_dict, "PaddingMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12735. }
  12736. PyOpDefBegin(Padding) // {
  12737. static PyGetSetDef py_getsetters[];
  12738. static PyMethodDef tp_methods[];
  12739. static PyObject* getstate(PyObject* self, PyObject*) {
  12740. auto& opdef = reinterpret_cast<PyOp(Padding)*>(self)->inst();
  12741. static_cast<void>(opdef);
  12742. std::unordered_map<std::string, py::object> state {
  12743. {"front_offset_dim0", serialization<decltype(opdef.front_offset_dim0)>::dump(opdef.front_offset_dim0)},
  12744. {"front_offset_dim1", serialization<decltype(opdef.front_offset_dim1)>::dump(opdef.front_offset_dim1)},
  12745. {"front_offset_dim2", serialization<decltype(opdef.front_offset_dim2)>::dump(opdef.front_offset_dim2)},
  12746. {"front_offset_dim3", serialization<decltype(opdef.front_offset_dim3)>::dump(opdef.front_offset_dim3)},
  12747. {"front_offset_dim4", serialization<decltype(opdef.front_offset_dim4)>::dump(opdef.front_offset_dim4)},
  12748. {"front_offset_dim5", serialization<decltype(opdef.front_offset_dim5)>::dump(opdef.front_offset_dim5)},
  12749. {"front_offset_dim6", serialization<decltype(opdef.front_offset_dim6)>::dump(opdef.front_offset_dim6)},
  12750. {"back_offset_dim0", serialization<decltype(opdef.back_offset_dim0)>::dump(opdef.back_offset_dim0)},
  12751. {"back_offset_dim1", serialization<decltype(opdef.back_offset_dim1)>::dump(opdef.back_offset_dim1)},
  12752. {"back_offset_dim2", serialization<decltype(opdef.back_offset_dim2)>::dump(opdef.back_offset_dim2)},
  12753. {"back_offset_dim3", serialization<decltype(opdef.back_offset_dim3)>::dump(opdef.back_offset_dim3)},
  12754. {"back_offset_dim4", serialization<decltype(opdef.back_offset_dim4)>::dump(opdef.back_offset_dim4)},
  12755. {"back_offset_dim5", serialization<decltype(opdef.back_offset_dim5)>::dump(opdef.back_offset_dim5)},
  12756. {"back_offset_dim6", serialization<decltype(opdef.back_offset_dim6)>::dump(opdef.back_offset_dim6)},
  12757. {"padding_val", serialization<decltype(opdef.padding_val)>::dump(opdef.padding_val)},
  12758. {"padding_mode", serialization<decltype(opdef.padding_mode)>::dump(opdef.padding_mode)}
  12759. };
  12760. return py::cast(state).release().ptr();
  12761. }
  12762. static PyObject* setstate(PyObject* self, PyObject* args) {
  12763. PyObject* dict = PyTuple_GetItem(args, 0);
  12764. if (!dict) return NULL;
  12765. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12766. auto& opdef = reinterpret_cast<PyOp(Padding)*>(self)->inst();
  12767. static_cast<void>(opdef);
  12768. {
  12769. auto&& iter = state.find("front_offset_dim0");
  12770. if (iter != state.end()) {
  12771. opdef.front_offset_dim0 = serialization<decltype(opdef.front_offset_dim0)>::load(iter->second);
  12772. }
  12773. }
  12774. {
  12775. auto&& iter = state.find("front_offset_dim1");
  12776. if (iter != state.end()) {
  12777. opdef.front_offset_dim1 = serialization<decltype(opdef.front_offset_dim1)>::load(iter->second);
  12778. }
  12779. }
  12780. {
  12781. auto&& iter = state.find("front_offset_dim2");
  12782. if (iter != state.end()) {
  12783. opdef.front_offset_dim2 = serialization<decltype(opdef.front_offset_dim2)>::load(iter->second);
  12784. }
  12785. }
  12786. {
  12787. auto&& iter = state.find("front_offset_dim3");
  12788. if (iter != state.end()) {
  12789. opdef.front_offset_dim3 = serialization<decltype(opdef.front_offset_dim3)>::load(iter->second);
  12790. }
  12791. }
  12792. {
  12793. auto&& iter = state.find("front_offset_dim4");
  12794. if (iter != state.end()) {
  12795. opdef.front_offset_dim4 = serialization<decltype(opdef.front_offset_dim4)>::load(iter->second);
  12796. }
  12797. }
  12798. {
  12799. auto&& iter = state.find("front_offset_dim5");
  12800. if (iter != state.end()) {
  12801. opdef.front_offset_dim5 = serialization<decltype(opdef.front_offset_dim5)>::load(iter->second);
  12802. }
  12803. }
  12804. {
  12805. auto&& iter = state.find("front_offset_dim6");
  12806. if (iter != state.end()) {
  12807. opdef.front_offset_dim6 = serialization<decltype(opdef.front_offset_dim6)>::load(iter->second);
  12808. }
  12809. }
  12810. {
  12811. auto&& iter = state.find("back_offset_dim0");
  12812. if (iter != state.end()) {
  12813. opdef.back_offset_dim0 = serialization<decltype(opdef.back_offset_dim0)>::load(iter->second);
  12814. }
  12815. }
  12816. {
  12817. auto&& iter = state.find("back_offset_dim1");
  12818. if (iter != state.end()) {
  12819. opdef.back_offset_dim1 = serialization<decltype(opdef.back_offset_dim1)>::load(iter->second);
  12820. }
  12821. }
  12822. {
  12823. auto&& iter = state.find("back_offset_dim2");
  12824. if (iter != state.end()) {
  12825. opdef.back_offset_dim2 = serialization<decltype(opdef.back_offset_dim2)>::load(iter->second);
  12826. }
  12827. }
  12828. {
  12829. auto&& iter = state.find("back_offset_dim3");
  12830. if (iter != state.end()) {
  12831. opdef.back_offset_dim3 = serialization<decltype(opdef.back_offset_dim3)>::load(iter->second);
  12832. }
  12833. }
  12834. {
  12835. auto&& iter = state.find("back_offset_dim4");
  12836. if (iter != state.end()) {
  12837. opdef.back_offset_dim4 = serialization<decltype(opdef.back_offset_dim4)>::load(iter->second);
  12838. }
  12839. }
  12840. {
  12841. auto&& iter = state.find("back_offset_dim5");
  12842. if (iter != state.end()) {
  12843. opdef.back_offset_dim5 = serialization<decltype(opdef.back_offset_dim5)>::load(iter->second);
  12844. }
  12845. }
  12846. {
  12847. auto&& iter = state.find("back_offset_dim6");
  12848. if (iter != state.end()) {
  12849. opdef.back_offset_dim6 = serialization<decltype(opdef.back_offset_dim6)>::load(iter->second);
  12850. }
  12851. }
  12852. {
  12853. auto&& iter = state.find("padding_val");
  12854. if (iter != state.end()) {
  12855. opdef.padding_val = serialization<decltype(opdef.padding_val)>::load(iter->second);
  12856. }
  12857. }
  12858. {
  12859. auto&& iter = state.find("padding_mode");
  12860. if (iter != state.end()) {
  12861. opdef.padding_mode = serialization<decltype(opdef.padding_mode)>::load(iter->second);
  12862. }
  12863. }
  12864. Py_RETURN_NONE;
  12865. }
  12866. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12867. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  12868. static PyMethodDef py_init_methoddef;
  12869. // };
  12870. PyOpDefEnd(Padding)
  12871. int PyOp(Padding)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12872. static const char* kwlist[] = {"front_offset_dim0", "front_offset_dim1", "front_offset_dim2", "front_offset_dim3", "front_offset_dim4", "front_offset_dim5", "front_offset_dim6", "back_offset_dim0", "back_offset_dim1", "back_offset_dim2", "back_offset_dim3", "back_offset_dim4", "back_offset_dim5", "back_offset_dim6", "padding_val", "padding_mode", "scope", NULL};
  12873. PyObject *front_offset_dim0 = NULL, *front_offset_dim1 = NULL, *front_offset_dim2 = NULL, *front_offset_dim3 = NULL, *front_offset_dim4 = NULL, *front_offset_dim5 = NULL, *front_offset_dim6 = NULL, *back_offset_dim0 = NULL, *back_offset_dim1 = NULL, *back_offset_dim2 = NULL, *back_offset_dim3 = NULL, *back_offset_dim4 = NULL, *back_offset_dim5 = NULL, *back_offset_dim6 = NULL, *padding_val = NULL, *padding_mode = NULL, *scope = NULL;
  12874. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOOOOO", const_cast<char**>(kwlist), &front_offset_dim0, &front_offset_dim1, &front_offset_dim2, &front_offset_dim3, &front_offset_dim4, &front_offset_dim5, &front_offset_dim6, &back_offset_dim0, &back_offset_dim1, &back_offset_dim2, &back_offset_dim3, &back_offset_dim4, &back_offset_dim5, &back_offset_dim6, &padding_val, &padding_mode, &scope))
  12875. return -1;
  12876. if (front_offset_dim0) {
  12877. try {
  12878. // TODO: remove this guard which is used for pybind11 implicit conversion
  12879. py::detail::loader_life_support guard{};
  12880. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim0 =
  12881. py::cast<decltype(Padding::front_offset_dim0)>(py::handle(front_offset_dim0));
  12882. } CATCH_ALL(-1)
  12883. }
  12884. if (front_offset_dim1) {
  12885. try {
  12886. // TODO: remove this guard which is used for pybind11 implicit conversion
  12887. py::detail::loader_life_support guard{};
  12888. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim1 =
  12889. py::cast<decltype(Padding::front_offset_dim1)>(py::handle(front_offset_dim1));
  12890. } CATCH_ALL(-1)
  12891. }
  12892. if (front_offset_dim2) {
  12893. try {
  12894. // TODO: remove this guard which is used for pybind11 implicit conversion
  12895. py::detail::loader_life_support guard{};
  12896. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim2 =
  12897. py::cast<decltype(Padding::front_offset_dim2)>(py::handle(front_offset_dim2));
  12898. } CATCH_ALL(-1)
  12899. }
  12900. if (front_offset_dim3) {
  12901. try {
  12902. // TODO: remove this guard which is used for pybind11 implicit conversion
  12903. py::detail::loader_life_support guard{};
  12904. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim3 =
  12905. py::cast<decltype(Padding::front_offset_dim3)>(py::handle(front_offset_dim3));
  12906. } CATCH_ALL(-1)
  12907. }
  12908. if (front_offset_dim4) {
  12909. try {
  12910. // TODO: remove this guard which is used for pybind11 implicit conversion
  12911. py::detail::loader_life_support guard{};
  12912. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim4 =
  12913. py::cast<decltype(Padding::front_offset_dim4)>(py::handle(front_offset_dim4));
  12914. } CATCH_ALL(-1)
  12915. }
  12916. if (front_offset_dim5) {
  12917. try {
  12918. // TODO: remove this guard which is used for pybind11 implicit conversion
  12919. py::detail::loader_life_support guard{};
  12920. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim5 =
  12921. py::cast<decltype(Padding::front_offset_dim5)>(py::handle(front_offset_dim5));
  12922. } CATCH_ALL(-1)
  12923. }
  12924. if (front_offset_dim6) {
  12925. try {
  12926. // TODO: remove this guard which is used for pybind11 implicit conversion
  12927. py::detail::loader_life_support guard{};
  12928. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim6 =
  12929. py::cast<decltype(Padding::front_offset_dim6)>(py::handle(front_offset_dim6));
  12930. } CATCH_ALL(-1)
  12931. }
  12932. if (back_offset_dim0) {
  12933. try {
  12934. // TODO: remove this guard which is used for pybind11 implicit conversion
  12935. py::detail::loader_life_support guard{};
  12936. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim0 =
  12937. py::cast<decltype(Padding::back_offset_dim0)>(py::handle(back_offset_dim0));
  12938. } CATCH_ALL(-1)
  12939. }
  12940. if (back_offset_dim1) {
  12941. try {
  12942. // TODO: remove this guard which is used for pybind11 implicit conversion
  12943. py::detail::loader_life_support guard{};
  12944. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim1 =
  12945. py::cast<decltype(Padding::back_offset_dim1)>(py::handle(back_offset_dim1));
  12946. } CATCH_ALL(-1)
  12947. }
  12948. if (back_offset_dim2) {
  12949. try {
  12950. // TODO: remove this guard which is used for pybind11 implicit conversion
  12951. py::detail::loader_life_support guard{};
  12952. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim2 =
  12953. py::cast<decltype(Padding::back_offset_dim2)>(py::handle(back_offset_dim2));
  12954. } CATCH_ALL(-1)
  12955. }
  12956. if (back_offset_dim3) {
  12957. try {
  12958. // TODO: remove this guard which is used for pybind11 implicit conversion
  12959. py::detail::loader_life_support guard{};
  12960. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim3 =
  12961. py::cast<decltype(Padding::back_offset_dim3)>(py::handle(back_offset_dim3));
  12962. } CATCH_ALL(-1)
  12963. }
  12964. if (back_offset_dim4) {
  12965. try {
  12966. // TODO: remove this guard which is used for pybind11 implicit conversion
  12967. py::detail::loader_life_support guard{};
  12968. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim4 =
  12969. py::cast<decltype(Padding::back_offset_dim4)>(py::handle(back_offset_dim4));
  12970. } CATCH_ALL(-1)
  12971. }
  12972. if (back_offset_dim5) {
  12973. try {
  12974. // TODO: remove this guard which is used for pybind11 implicit conversion
  12975. py::detail::loader_life_support guard{};
  12976. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim5 =
  12977. py::cast<decltype(Padding::back_offset_dim5)>(py::handle(back_offset_dim5));
  12978. } CATCH_ALL(-1)
  12979. }
  12980. if (back_offset_dim6) {
  12981. try {
  12982. // TODO: remove this guard which is used for pybind11 implicit conversion
  12983. py::detail::loader_life_support guard{};
  12984. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim6 =
  12985. py::cast<decltype(Padding::back_offset_dim6)>(py::handle(back_offset_dim6));
  12986. } CATCH_ALL(-1)
  12987. }
  12988. if (padding_val) {
  12989. try {
  12990. // TODO: remove this guard which is used for pybind11 implicit conversion
  12991. py::detail::loader_life_support guard{};
  12992. reinterpret_cast<PyOp(Padding)*>(self)->inst().padding_val =
  12993. py::cast<decltype(Padding::padding_val)>(py::handle(padding_val));
  12994. } CATCH_ALL(-1)
  12995. }
  12996. if (padding_mode) {
  12997. try {
  12998. // TODO: remove this guard which is used for pybind11 implicit conversion
  12999. py::detail::loader_life_support guard{};
  13000. reinterpret_cast<PyOp(Padding)*>(self)->inst().padding_mode =
  13001. py::cast<decltype(Padding::padding_mode)>(py::handle(padding_mode));
  13002. } CATCH_ALL(-1)
  13003. }
  13004. if (scope) {
  13005. try {
  13006. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13007. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13008. } CATCH_ALL(-1)
  13009. }
  13010. return 0;
  13011. }
  13012. PyGetSetDef PyOp(Padding)::py_getsetters[] = {
  13013. {const_cast<char*>("front_offset_dim0"), py_get_generic(Padding, front_offset_dim0), py_set_generic(Padding, front_offset_dim0), const_cast<char*>("front_offset_dim0"), NULL},
  13014. {const_cast<char*>("front_offset_dim1"), py_get_generic(Padding, front_offset_dim1), py_set_generic(Padding, front_offset_dim1), const_cast<char*>("front_offset_dim1"), NULL},
  13015. {const_cast<char*>("front_offset_dim2"), py_get_generic(Padding, front_offset_dim2), py_set_generic(Padding, front_offset_dim2), const_cast<char*>("front_offset_dim2"), NULL},
  13016. {const_cast<char*>("front_offset_dim3"), py_get_generic(Padding, front_offset_dim3), py_set_generic(Padding, front_offset_dim3), const_cast<char*>("front_offset_dim3"), NULL},
  13017. {const_cast<char*>("front_offset_dim4"), py_get_generic(Padding, front_offset_dim4), py_set_generic(Padding, front_offset_dim4), const_cast<char*>("front_offset_dim4"), NULL},
  13018. {const_cast<char*>("front_offset_dim5"), py_get_generic(Padding, front_offset_dim5), py_set_generic(Padding, front_offset_dim5), const_cast<char*>("front_offset_dim5"), NULL},
  13019. {const_cast<char*>("front_offset_dim6"), py_get_generic(Padding, front_offset_dim6), py_set_generic(Padding, front_offset_dim6), const_cast<char*>("front_offset_dim6"), NULL},
  13020. {const_cast<char*>("back_offset_dim0"), py_get_generic(Padding, back_offset_dim0), py_set_generic(Padding, back_offset_dim0), const_cast<char*>("back_offset_dim0"), NULL},
  13021. {const_cast<char*>("back_offset_dim1"), py_get_generic(Padding, back_offset_dim1), py_set_generic(Padding, back_offset_dim1), const_cast<char*>("back_offset_dim1"), NULL},
  13022. {const_cast<char*>("back_offset_dim2"), py_get_generic(Padding, back_offset_dim2), py_set_generic(Padding, back_offset_dim2), const_cast<char*>("back_offset_dim2"), NULL},
  13023. {const_cast<char*>("back_offset_dim3"), py_get_generic(Padding, back_offset_dim3), py_set_generic(Padding, back_offset_dim3), const_cast<char*>("back_offset_dim3"), NULL},
  13024. {const_cast<char*>("back_offset_dim4"), py_get_generic(Padding, back_offset_dim4), py_set_generic(Padding, back_offset_dim4), const_cast<char*>("back_offset_dim4"), NULL},
  13025. {const_cast<char*>("back_offset_dim5"), py_get_generic(Padding, back_offset_dim5), py_set_generic(Padding, back_offset_dim5), const_cast<char*>("back_offset_dim5"), NULL},
  13026. {const_cast<char*>("back_offset_dim6"), py_get_generic(Padding, back_offset_dim6), py_set_generic(Padding, back_offset_dim6), const_cast<char*>("back_offset_dim6"), NULL},
  13027. {const_cast<char*>("padding_val"), py_get_generic(Padding, padding_val), py_set_generic(Padding, padding_val), const_cast<char*>("padding_val"), NULL},
  13028. {const_cast<char*>("padding_mode"), py_get_generic(Padding, padding_mode), py_set_generic(Padding, padding_mode), const_cast<char*>("padding_mode"), NULL},
  13029. {NULL} /* Sentinel */
  13030. };
  13031. PyMethodDef PyOp(Padding)::tp_methods[] = {
  13032. {const_cast<char*>("__getstate__"), PyOp(Padding)::getstate, METH_NOARGS, "Padding getstate"},
  13033. {const_cast<char*>("__setstate__"), PyOp(Padding)::setstate, METH_VARARGS, "Padding setstate"},
  13034. {NULL} /* Sentinel */
  13035. };
  13036. PyObject *PyOp(Padding)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  13037. if (PyOp(Padding)::py_init(self, args, kwds) < 0) {
  13038. return NULL;
  13039. }
  13040. Py_RETURN_NONE;
  13041. }
  13042. PyMethodDef PyOp(Padding)::py_init_methoddef = {
  13043. "__init__",
  13044. (PyCFunction)PyOp(Padding)::py_init_proxy,
  13045. METH_VARARGS | METH_KEYWORDS,
  13046. "__init__(self, front_offset_dim0: int = ..., front_offset_dim1: int = ..., front_offset_dim2: int = ..., front_offset_dim3: int = ..., front_offset_dim4: int = ..., front_offset_dim5: int = ..., front_offset_dim6: int = ..., back_offset_dim0: int = ..., back_offset_dim1: int = ..., back_offset_dim2: int = ..., back_offset_dim3: int = ..., back_offset_dim4: int = ..., back_offset_dim5: int = ..., back_offset_dim6: int = ..., padding_val: float = ..., padding_mode: Union[str, PaddingMode] = ...) -> None\n"
  13047. };
  13048. void _init_py_Padding(py::module m) {
  13049. using py_op = PyOp(Padding);
  13050. auto& py_type = PyOpType(Padding);
  13051. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13052. py_type.tp_name = "megengine.core._imperative_rt.ops.Padding";
  13053. py_type.tp_basicsize = sizeof(PyOp(Padding));
  13054. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13055. py_type.tp_doc = "Padding";
  13056. py_type.tp_base = &PyOpType(OpDef);
  13057. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13058. py_type.tp_new = py_new_generic<py_op>;
  13059. py_type.tp_init = py_op::py_init;
  13060. py_type.tp_methods = py_op::tp_methods;
  13061. py_type.tp_getset = py_op::py_getsetters;
  13062. py_type.tp_dict = PyDict_New();
  13063. PyObject* descr = PyDescr_NewMethod(&PyOpType(Padding), &PyOp(Padding)::py_init_methoddef);
  13064. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  13065. mgb_assert(PyType_Ready(&py_type) >= 0);
  13066. _init_py_Padding_PaddingMode(py_type);
  13067. PyType_Modified(&py_type);
  13068. m.add_object("Padding", reinterpret_cast<PyObject*>(&py_type));
  13069. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Padding::typeinfo(), &py_type).second);
  13070. }
  13071. PyOpDefBegin(ParamPackConcat) // {
  13072. static PyGetSetDef py_getsetters[];
  13073. static PyMethodDef tp_methods[];
  13074. static PyObject* getstate(PyObject* self, PyObject*) {
  13075. auto& opdef = reinterpret_cast<PyOp(ParamPackConcat)*>(self)->inst();
  13076. static_cast<void>(opdef);
  13077. std::unordered_map<std::string, py::object> state {
  13078. {"offsets", serialization<decltype(opdef.offsets)>::dump(opdef.offsets)}
  13079. };
  13080. return py::cast(state).release().ptr();
  13081. }
  13082. static PyObject* setstate(PyObject* self, PyObject* args) {
  13083. PyObject* dict = PyTuple_GetItem(args, 0);
  13084. if (!dict) return NULL;
  13085. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13086. auto& opdef = reinterpret_cast<PyOp(ParamPackConcat)*>(self)->inst();
  13087. static_cast<void>(opdef);
  13088. {
  13089. auto&& iter = state.find("offsets");
  13090. if (iter != state.end()) {
  13091. opdef.offsets = serialization<decltype(opdef.offsets)>::load(iter->second);
  13092. }
  13093. }
  13094. Py_RETURN_NONE;
  13095. }
  13096. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13097. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  13098. static PyMethodDef py_init_methoddef;
  13099. // };
  13100. PyOpDefEnd(ParamPackConcat)
  13101. int PyOp(ParamPackConcat)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13102. static const char* kwlist[] = {"offsets", "scope", NULL};
  13103. PyObject *offsets = NULL, *scope = NULL;
  13104. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &offsets, &scope))
  13105. return -1;
  13106. if (offsets) {
  13107. try {
  13108. // TODO: remove this guard which is used for pybind11 implicit conversion
  13109. py::detail::loader_life_support guard{};
  13110. reinterpret_cast<PyOp(ParamPackConcat)*>(self)->inst().offsets =
  13111. py::cast<decltype(ParamPackConcat::offsets)>(py::handle(offsets));
  13112. } CATCH_ALL(-1)
  13113. }
  13114. if (scope) {
  13115. try {
  13116. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13117. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13118. } CATCH_ALL(-1)
  13119. }
  13120. return 0;
  13121. }
  13122. PyGetSetDef PyOp(ParamPackConcat)::py_getsetters[] = {
  13123. {const_cast<char*>("offsets"), py_get_generic(ParamPackConcat, offsets), py_set_generic(ParamPackConcat, offsets), const_cast<char*>("offsets"), NULL},
  13124. {NULL} /* Sentinel */
  13125. };
  13126. PyMethodDef PyOp(ParamPackConcat)::tp_methods[] = {
  13127. {const_cast<char*>("__getstate__"), PyOp(ParamPackConcat)::getstate, METH_NOARGS, "ParamPackConcat getstate"},
  13128. {const_cast<char*>("__setstate__"), PyOp(ParamPackConcat)::setstate, METH_VARARGS, "ParamPackConcat setstate"},
  13129. {NULL} /* Sentinel */
  13130. };
  13131. PyObject *PyOp(ParamPackConcat)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  13132. if (PyOp(ParamPackConcat)::py_init(self, args, kwds) < 0) {
  13133. return NULL;
  13134. }
  13135. Py_RETURN_NONE;
  13136. }
  13137. PyMethodDef PyOp(ParamPackConcat)::py_init_methoddef = {
  13138. "__init__",
  13139. (PyCFunction)PyOp(ParamPackConcat)::py_init_proxy,
  13140. METH_VARARGS | METH_KEYWORDS,
  13141. "__init__(self, offsets: list[int] = ...) -> None\n"
  13142. };
  13143. void _init_py_ParamPackConcat(py::module m) {
  13144. using py_op = PyOp(ParamPackConcat);
  13145. auto& py_type = PyOpType(ParamPackConcat);
  13146. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13147. py_type.tp_name = "megengine.core._imperative_rt.ops.ParamPackConcat";
  13148. py_type.tp_basicsize = sizeof(PyOp(ParamPackConcat));
  13149. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13150. py_type.tp_doc = "ParamPackConcat";
  13151. py_type.tp_base = &PyOpType(OpDef);
  13152. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13153. py_type.tp_new = py_new_generic<py_op>;
  13154. py_type.tp_init = py_op::py_init;
  13155. py_type.tp_methods = py_op::tp_methods;
  13156. py_type.tp_getset = py_op::py_getsetters;
  13157. py_type.tp_dict = PyDict_New();
  13158. PyObject* descr = PyDescr_NewMethod(&PyOpType(ParamPackConcat), &PyOp(ParamPackConcat)::py_init_methoddef);
  13159. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  13160. mgb_assert(PyType_Ready(&py_type) >= 0);
  13161. PyType_Modified(&py_type);
  13162. m.add_object("ParamPackConcat", reinterpret_cast<PyObject*>(&py_type));
  13163. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ParamPackConcat::typeinfo(), &py_type).second);
  13164. }
  13165. PyOpDefBegin(ParamPackSplit) // {
  13166. static PyGetSetDef py_getsetters[];
  13167. static PyMethodDef tp_methods[];
  13168. static PyObject* getstate(PyObject* self, PyObject*) {
  13169. auto& opdef = reinterpret_cast<PyOp(ParamPackSplit)*>(self)->inst();
  13170. static_cast<void>(opdef);
  13171. std::unordered_map<std::string, py::object> state {
  13172. {"offsets", serialization<decltype(opdef.offsets)>::dump(opdef.offsets)},
  13173. {"shapes", serialization<decltype(opdef.shapes)>::dump(opdef.shapes)}
  13174. };
  13175. return py::cast(state).release().ptr();
  13176. }
  13177. static PyObject* setstate(PyObject* self, PyObject* args) {
  13178. PyObject* dict = PyTuple_GetItem(args, 0);
  13179. if (!dict) return NULL;
  13180. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13181. auto& opdef = reinterpret_cast<PyOp(ParamPackSplit)*>(self)->inst();
  13182. static_cast<void>(opdef);
  13183. {
  13184. auto&& iter = state.find("offsets");
  13185. if (iter != state.end()) {
  13186. opdef.offsets = serialization<decltype(opdef.offsets)>::load(iter->second);
  13187. }
  13188. }
  13189. {
  13190. auto&& iter = state.find("shapes");
  13191. if (iter != state.end()) {
  13192. opdef.shapes = serialization<decltype(opdef.shapes)>::load(iter->second);
  13193. }
  13194. }
  13195. Py_RETURN_NONE;
  13196. }
  13197. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13198. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  13199. static PyMethodDef py_init_methoddef;
  13200. // };
  13201. PyOpDefEnd(ParamPackSplit)
  13202. int PyOp(ParamPackSplit)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13203. static const char* kwlist[] = {"offsets", "shapes", "scope", NULL};
  13204. PyObject *offsets = NULL, *shapes = NULL, *scope = NULL;
  13205. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &offsets, &shapes, &scope))
  13206. return -1;
  13207. if (offsets) {
  13208. try {
  13209. // TODO: remove this guard which is used for pybind11 implicit conversion
  13210. py::detail::loader_life_support guard{};
  13211. reinterpret_cast<PyOp(ParamPackSplit)*>(self)->inst().offsets =
  13212. py::cast<decltype(ParamPackSplit::offsets)>(py::handle(offsets));
  13213. } CATCH_ALL(-1)
  13214. }
  13215. if (shapes) {
  13216. try {
  13217. // TODO: remove this guard which is used for pybind11 implicit conversion
  13218. py::detail::loader_life_support guard{};
  13219. reinterpret_cast<PyOp(ParamPackSplit)*>(self)->inst().shapes =
  13220. py::cast<decltype(ParamPackSplit::shapes)>(py::handle(shapes));
  13221. } CATCH_ALL(-1)
  13222. }
  13223. if (scope) {
  13224. try {
  13225. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13226. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13227. } CATCH_ALL(-1)
  13228. }
  13229. return 0;
  13230. }
  13231. PyGetSetDef PyOp(ParamPackSplit)::py_getsetters[] = {
  13232. {const_cast<char*>("offsets"), py_get_generic(ParamPackSplit, offsets), py_set_generic(ParamPackSplit, offsets), const_cast<char*>("offsets"), NULL},
  13233. {const_cast<char*>("shapes"), py_get_generic(ParamPackSplit, shapes), py_set_generic(ParamPackSplit, shapes), const_cast<char*>("shapes"), NULL},
  13234. {NULL} /* Sentinel */
  13235. };
  13236. PyMethodDef PyOp(ParamPackSplit)::tp_methods[] = {
  13237. {const_cast<char*>("__getstate__"), PyOp(ParamPackSplit)::getstate, METH_NOARGS, "ParamPackSplit getstate"},
  13238. {const_cast<char*>("__setstate__"), PyOp(ParamPackSplit)::setstate, METH_VARARGS, "ParamPackSplit setstate"},
  13239. {NULL} /* Sentinel */
  13240. };
  13241. PyObject *PyOp(ParamPackSplit)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  13242. if (PyOp(ParamPackSplit)::py_init(self, args, kwds) < 0) {
  13243. return NULL;
  13244. }
  13245. Py_RETURN_NONE;
  13246. }
  13247. PyMethodDef PyOp(ParamPackSplit)::py_init_methoddef = {
  13248. "__init__",
  13249. (PyCFunction)PyOp(ParamPackSplit)::py_init_proxy,
  13250. METH_VARARGS | METH_KEYWORDS,
  13251. "__init__(self, offsets: list[int] = ..., shapes: list[list[int]] = ...) -> None\n"
  13252. };
  13253. void _init_py_ParamPackSplit(py::module m) {
  13254. using py_op = PyOp(ParamPackSplit);
  13255. auto& py_type = PyOpType(ParamPackSplit);
  13256. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13257. py_type.tp_name = "megengine.core._imperative_rt.ops.ParamPackSplit";
  13258. py_type.tp_basicsize = sizeof(PyOp(ParamPackSplit));
  13259. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13260. py_type.tp_doc = "ParamPackSplit";
  13261. py_type.tp_base = &PyOpType(OpDef);
  13262. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13263. py_type.tp_new = py_new_generic<py_op>;
  13264. py_type.tp_init = py_op::py_init;
  13265. py_type.tp_methods = py_op::tp_methods;
  13266. py_type.tp_getset = py_op::py_getsetters;
  13267. py_type.tp_dict = PyDict_New();
  13268. PyObject* descr = PyDescr_NewMethod(&PyOpType(ParamPackSplit), &PyOp(ParamPackSplit)::py_init_methoddef);
  13269. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  13270. mgb_assert(PyType_Ready(&py_type) >= 0);
  13271. PyType_Modified(&py_type);
  13272. m.add_object("ParamPackSplit", reinterpret_cast<PyObject*>(&py_type));
  13273. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ParamPackSplit::typeinfo(), &py_type).second);
  13274. }
  13275. PyOpDefBegin(PermutationRNG) // {
  13276. static PyGetSetDef py_getsetters[];
  13277. static PyMethodDef tp_methods[];
  13278. static PyObject* getstate(PyObject* self, PyObject*) {
  13279. auto& opdef = reinterpret_cast<PyOp(PermutationRNG)*>(self)->inst();
  13280. static_cast<void>(opdef);
  13281. std::unordered_map<std::string, py::object> state {
  13282. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  13283. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  13284. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  13285. };
  13286. return py::cast(state).release().ptr();
  13287. }
  13288. static PyObject* setstate(PyObject* self, PyObject* args) {
  13289. PyObject* dict = PyTuple_GetItem(args, 0);
  13290. if (!dict) return NULL;
  13291. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13292. auto& opdef = reinterpret_cast<PyOp(PermutationRNG)*>(self)->inst();
  13293. static_cast<void>(opdef);
  13294. {
  13295. auto&& iter = state.find("seed");
  13296. if (iter != state.end()) {
  13297. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  13298. }
  13299. }
  13300. {
  13301. auto&& iter = state.find("dtype");
  13302. if (iter != state.end()) {
  13303. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  13304. }
  13305. }
  13306. {
  13307. auto&& iter = state.find("handle");
  13308. if (iter != state.end()) {
  13309. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  13310. }
  13311. }
  13312. Py_RETURN_NONE;
  13313. }
  13314. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13315. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  13316. static PyMethodDef py_init_methoddef;
  13317. // };
  13318. PyOpDefEnd(PermutationRNG)
  13319. int PyOp(PermutationRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13320. static const char* kwlist[] = {"seed", "dtype", "handle", "scope", NULL};
  13321. PyObject *seed = NULL, *dtype = NULL, *handle = NULL, *scope = NULL;
  13322. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &seed, &dtype, &handle, &scope))
  13323. return -1;
  13324. if (seed) {
  13325. try {
  13326. // TODO: remove this guard which is used for pybind11 implicit conversion
  13327. py::detail::loader_life_support guard{};
  13328. reinterpret_cast<PyOp(PermutationRNG)*>(self)->inst().seed =
  13329. py::cast<decltype(PermutationRNG::seed)>(py::handle(seed));
  13330. } CATCH_ALL(-1)
  13331. }
  13332. if (dtype) {
  13333. try {
  13334. // TODO: remove this guard which is used for pybind11 implicit conversion
  13335. py::detail::loader_life_support guard{};
  13336. reinterpret_cast<PyOp(PermutationRNG)*>(self)->inst().dtype =
  13337. py::cast<decltype(PermutationRNG::dtype)>(py::handle(dtype));
  13338. } CATCH_ALL(-1)
  13339. }
  13340. if (handle) {
  13341. try {
  13342. // TODO: remove this guard which is used for pybind11 implicit conversion
  13343. py::detail::loader_life_support guard{};
  13344. reinterpret_cast<PyOp(PermutationRNG)*>(self)->inst().handle =
  13345. py::cast<decltype(PermutationRNG::handle)>(py::handle(handle));
  13346. } CATCH_ALL(-1)
  13347. }
  13348. if (scope) {
  13349. try {
  13350. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13351. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13352. } CATCH_ALL(-1)
  13353. }
  13354. return 0;
  13355. }
  13356. PyGetSetDef PyOp(PermutationRNG)::py_getsetters[] = {
  13357. {const_cast<char*>("seed"), py_get_generic(PermutationRNG, seed), py_set_generic(PermutationRNG, seed), const_cast<char*>("seed"), NULL},
  13358. {const_cast<char*>("dtype"), py_get_generic(PermutationRNG, dtype), py_set_generic(PermutationRNG, dtype), const_cast<char*>("dtype"), NULL},
  13359. {const_cast<char*>("handle"), py_get_generic(PermutationRNG, handle), py_set_generic(PermutationRNG, handle), const_cast<char*>("handle"), NULL},
  13360. {NULL} /* Sentinel */
  13361. };
  13362. PyMethodDef PyOp(PermutationRNG)::tp_methods[] = {
  13363. {const_cast<char*>("__getstate__"), PyOp(PermutationRNG)::getstate, METH_NOARGS, "PermutationRNG getstate"},
  13364. {const_cast<char*>("__setstate__"), PyOp(PermutationRNG)::setstate, METH_VARARGS, "PermutationRNG setstate"},
  13365. {NULL} /* Sentinel */
  13366. };
  13367. PyObject *PyOp(PermutationRNG)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  13368. if (PyOp(PermutationRNG)::py_init(self, args, kwds) < 0) {
  13369. return NULL;
  13370. }
  13371. Py_RETURN_NONE;
  13372. }
  13373. PyMethodDef PyOp(PermutationRNG)::py_init_methoddef = {
  13374. "__init__",
  13375. (PyCFunction)PyOp(PermutationRNG)::py_init_proxy,
  13376. METH_VARARGS | METH_KEYWORDS,
  13377. "__init__(self, seed: int = ..., dtype: str = ..., handle: int = ...) -> None\n"
  13378. };
  13379. void _init_py_PermutationRNG(py::module m) {
  13380. using py_op = PyOp(PermutationRNG);
  13381. auto& py_type = PyOpType(PermutationRNG);
  13382. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13383. py_type.tp_name = "megengine.core._imperative_rt.ops.PermutationRNG";
  13384. py_type.tp_basicsize = sizeof(PyOp(PermutationRNG));
  13385. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13386. py_type.tp_doc = "PermutationRNG";
  13387. py_type.tp_base = &PyOpType(OpDef);
  13388. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13389. py_type.tp_new = py_new_generic<py_op>;
  13390. py_type.tp_init = py_op::py_init;
  13391. py_type.tp_methods = py_op::tp_methods;
  13392. py_type.tp_getset = py_op::py_getsetters;
  13393. py_type.tp_dict = PyDict_New();
  13394. PyObject* descr = PyDescr_NewMethod(&PyOpType(PermutationRNG), &PyOp(PermutationRNG)::py_init_methoddef);
  13395. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  13396. mgb_assert(PyType_Ready(&py_type) >= 0);
  13397. PyType_Modified(&py_type);
  13398. m.add_object("PermutationRNG", reinterpret_cast<PyObject*>(&py_type));
  13399. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PermutationRNG::typeinfo(), &py_type).second);
  13400. }
  13401. PyOpDefBegin(PixelShuffle) // {
  13402. static PyGetSetDef py_getsetters[];
  13403. static PyMethodDef tp_methods[];
  13404. static PyObject* getstate(PyObject* self, PyObject*) {
  13405. auto& opdef = reinterpret_cast<PyOp(PixelShuffle)*>(self)->inst();
  13406. static_cast<void>(opdef);
  13407. std::unordered_map<std::string, py::object> state {
  13408. {"factor", serialization<decltype(opdef.factor)>::dump(opdef.factor)}
  13409. };
  13410. return py::cast(state).release().ptr();
  13411. }
  13412. static PyObject* setstate(PyObject* self, PyObject* args) {
  13413. PyObject* dict = PyTuple_GetItem(args, 0);
  13414. if (!dict) return NULL;
  13415. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13416. auto& opdef = reinterpret_cast<PyOp(PixelShuffle)*>(self)->inst();
  13417. static_cast<void>(opdef);
  13418. {
  13419. auto&& iter = state.find("factor");
  13420. if (iter != state.end()) {
  13421. opdef.factor = serialization<decltype(opdef.factor)>::load(iter->second);
  13422. }
  13423. }
  13424. Py_RETURN_NONE;
  13425. }
  13426. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13427. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  13428. static PyMethodDef py_init_methoddef;
  13429. // };
  13430. PyOpDefEnd(PixelShuffle)
  13431. int PyOp(PixelShuffle)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13432. static const char* kwlist[] = {"factor", "scope", NULL};
  13433. PyObject *factor = NULL, *scope = NULL;
  13434. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &factor, &scope))
  13435. return -1;
  13436. if (factor) {
  13437. try {
  13438. // TODO: remove this guard which is used for pybind11 implicit conversion
  13439. py::detail::loader_life_support guard{};
  13440. reinterpret_cast<PyOp(PixelShuffle)*>(self)->inst().factor =
  13441. py::cast<decltype(PixelShuffle::factor)>(py::handle(factor));
  13442. } CATCH_ALL(-1)
  13443. }
  13444. if (scope) {
  13445. try {
  13446. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13447. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13448. } CATCH_ALL(-1)
  13449. }
  13450. return 0;
  13451. }
  13452. PyGetSetDef PyOp(PixelShuffle)::py_getsetters[] = {
  13453. {const_cast<char*>("factor"), py_get_generic(PixelShuffle, factor), py_set_generic(PixelShuffle, factor), const_cast<char*>("factor"), NULL},
  13454. {NULL} /* Sentinel */
  13455. };
  13456. PyMethodDef PyOp(PixelShuffle)::tp_methods[] = {
  13457. {const_cast<char*>("__getstate__"), PyOp(PixelShuffle)::getstate, METH_NOARGS, "PixelShuffle getstate"},
  13458. {const_cast<char*>("__setstate__"), PyOp(PixelShuffle)::setstate, METH_VARARGS, "PixelShuffle setstate"},
  13459. {NULL} /* Sentinel */
  13460. };
  13461. PyObject *PyOp(PixelShuffle)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  13462. if (PyOp(PixelShuffle)::py_init(self, args, kwds) < 0) {
  13463. return NULL;
  13464. }
  13465. Py_RETURN_NONE;
  13466. }
  13467. PyMethodDef PyOp(PixelShuffle)::py_init_methoddef = {
  13468. "__init__",
  13469. (PyCFunction)PyOp(PixelShuffle)::py_init_proxy,
  13470. METH_VARARGS | METH_KEYWORDS,
  13471. "__init__(self, factor: int = ...) -> None\n"
  13472. };
  13473. void _init_py_PixelShuffle(py::module m) {
  13474. using py_op = PyOp(PixelShuffle);
  13475. auto& py_type = PyOpType(PixelShuffle);
  13476. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13477. py_type.tp_name = "megengine.core._imperative_rt.ops.PixelShuffle";
  13478. py_type.tp_basicsize = sizeof(PyOp(PixelShuffle));
  13479. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13480. py_type.tp_doc = "PixelShuffle";
  13481. py_type.tp_base = &PyOpType(OpDef);
  13482. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13483. py_type.tp_new = py_new_generic<py_op>;
  13484. py_type.tp_init = py_op::py_init;
  13485. py_type.tp_methods = py_op::tp_methods;
  13486. py_type.tp_getset = py_op::py_getsetters;
  13487. py_type.tp_dict = PyDict_New();
  13488. PyObject* descr = PyDescr_NewMethod(&PyOpType(PixelShuffle), &PyOp(PixelShuffle)::py_init_methoddef);
  13489. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  13490. mgb_assert(PyType_Ready(&py_type) >= 0);
  13491. PyType_Modified(&py_type);
  13492. m.add_object("PixelShuffle", reinterpret_cast<PyObject*>(&py_type));
  13493. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PixelShuffle::typeinfo(), &py_type).second);
  13494. }
  13495. PyOpDefBegin(PixelShuffleBackward) // {
  13496. static PyGetSetDef py_getsetters[];
  13497. static PyMethodDef tp_methods[];
  13498. static PyObject* getstate(PyObject* self, PyObject*) {
  13499. auto& opdef = reinterpret_cast<PyOp(PixelShuffleBackward)*>(self)->inst();
  13500. static_cast<void>(opdef);
  13501. std::unordered_map<std::string, py::object> state {
  13502. {"factor", serialization<decltype(opdef.factor)>::dump(opdef.factor)}
  13503. };
  13504. return py::cast(state).release().ptr();
  13505. }
  13506. static PyObject* setstate(PyObject* self, PyObject* args) {
  13507. PyObject* dict = PyTuple_GetItem(args, 0);
  13508. if (!dict) return NULL;
  13509. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13510. auto& opdef = reinterpret_cast<PyOp(PixelShuffleBackward)*>(self)->inst();
  13511. static_cast<void>(opdef);
  13512. {
  13513. auto&& iter = state.find("factor");
  13514. if (iter != state.end()) {
  13515. opdef.factor = serialization<decltype(opdef.factor)>::load(iter->second);
  13516. }
  13517. }
  13518. Py_RETURN_NONE;
  13519. }
  13520. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13521. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  13522. static PyMethodDef py_init_methoddef;
  13523. // };
  13524. PyOpDefEnd(PixelShuffleBackward)
  13525. int PyOp(PixelShuffleBackward)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13526. static const char* kwlist[] = {"factor", "scope", NULL};
  13527. PyObject *factor = NULL, *scope = NULL;
  13528. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &factor, &scope))
  13529. return -1;
  13530. if (factor) {
  13531. try {
  13532. // TODO: remove this guard which is used for pybind11 implicit conversion
  13533. py::detail::loader_life_support guard{};
  13534. reinterpret_cast<PyOp(PixelShuffleBackward)*>(self)->inst().factor =
  13535. py::cast<decltype(PixelShuffleBackward::factor)>(py::handle(factor));
  13536. } CATCH_ALL(-1)
  13537. }
  13538. if (scope) {
  13539. try {
  13540. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13541. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13542. } CATCH_ALL(-1)
  13543. }
  13544. return 0;
  13545. }
  13546. PyGetSetDef PyOp(PixelShuffleBackward)::py_getsetters[] = {
  13547. {const_cast<char*>("factor"), py_get_generic(PixelShuffleBackward, factor), py_set_generic(PixelShuffleBackward, factor), const_cast<char*>("factor"), NULL},
  13548. {NULL} /* Sentinel */
  13549. };
  13550. PyMethodDef PyOp(PixelShuffleBackward)::tp_methods[] = {
  13551. {const_cast<char*>("__getstate__"), PyOp(PixelShuffleBackward)::getstate, METH_NOARGS, "PixelShuffleBackward getstate"},
  13552. {const_cast<char*>("__setstate__"), PyOp(PixelShuffleBackward)::setstate, METH_VARARGS, "PixelShuffleBackward setstate"},
  13553. {NULL} /* Sentinel */
  13554. };
  13555. PyObject *PyOp(PixelShuffleBackward)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  13556. if (PyOp(PixelShuffleBackward)::py_init(self, args, kwds) < 0) {
  13557. return NULL;
  13558. }
  13559. Py_RETURN_NONE;
  13560. }
  13561. PyMethodDef PyOp(PixelShuffleBackward)::py_init_methoddef = {
  13562. "__init__",
  13563. (PyCFunction)PyOp(PixelShuffleBackward)::py_init_proxy,
  13564. METH_VARARGS | METH_KEYWORDS,
  13565. "__init__(self, factor: int = ...) -> None\n"
  13566. };
  13567. void _init_py_PixelShuffleBackward(py::module m) {
  13568. using py_op = PyOp(PixelShuffleBackward);
  13569. auto& py_type = PyOpType(PixelShuffleBackward);
  13570. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13571. py_type.tp_name = "megengine.core._imperative_rt.ops.PixelShuffleBackward";
  13572. py_type.tp_basicsize = sizeof(PyOp(PixelShuffleBackward));
  13573. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13574. py_type.tp_doc = "PixelShuffleBackward";
  13575. py_type.tp_base = &PyOpType(OpDef);
  13576. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13577. py_type.tp_new = py_new_generic<py_op>;
  13578. py_type.tp_init = py_op::py_init;
  13579. py_type.tp_methods = py_op::tp_methods;
  13580. py_type.tp_getset = py_op::py_getsetters;
  13581. py_type.tp_dict = PyDict_New();
  13582. PyObject* descr = PyDescr_NewMethod(&PyOpType(PixelShuffleBackward), &PyOp(PixelShuffleBackward)::py_init_methoddef);
  13583. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  13584. mgb_assert(PyType_Ready(&py_type) >= 0);
  13585. PyType_Modified(&py_type);
  13586. m.add_object("PixelShuffleBackward", reinterpret_cast<PyObject*>(&py_type));
  13587. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PixelShuffleBackward::typeinfo(), &py_type).second);
  13588. }
  13589. PyOpDefBegin(PoissonRNG) // {
  13590. static PyGetSetDef py_getsetters[];
  13591. static PyMethodDef tp_methods[];
  13592. static PyObject* getstate(PyObject* self, PyObject*) {
  13593. auto& opdef = reinterpret_cast<PyOp(PoissonRNG)*>(self)->inst();
  13594. static_cast<void>(opdef);
  13595. std::unordered_map<std::string, py::object> state {
  13596. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  13597. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  13598. };
  13599. return py::cast(state).release().ptr();
  13600. }
  13601. static PyObject* setstate(PyObject* self, PyObject* args) {
  13602. PyObject* dict = PyTuple_GetItem(args, 0);
  13603. if (!dict) return NULL;
  13604. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13605. auto& opdef = reinterpret_cast<PyOp(PoissonRNG)*>(self)->inst();
  13606. static_cast<void>(opdef);
  13607. {
  13608. auto&& iter = state.find("seed");
  13609. if (iter != state.end()) {
  13610. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  13611. }
  13612. }
  13613. {
  13614. auto&& iter = state.find("handle");
  13615. if (iter != state.end()) {
  13616. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  13617. }
  13618. }
  13619. Py_RETURN_NONE;
  13620. }
  13621. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13622. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  13623. static PyMethodDef py_init_methoddef;
  13624. // };
  13625. PyOpDefEnd(PoissonRNG)
  13626. int PyOp(PoissonRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13627. static const char* kwlist[] = {"seed", "handle", "scope", NULL};
  13628. PyObject *seed = NULL, *handle = NULL, *scope = NULL;
  13629. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &seed, &handle, &scope))
  13630. return -1;
  13631. if (seed) {
  13632. try {
  13633. // TODO: remove this guard which is used for pybind11 implicit conversion
  13634. py::detail::loader_life_support guard{};
  13635. reinterpret_cast<PyOp(PoissonRNG)*>(self)->inst().seed =
  13636. py::cast<decltype(PoissonRNG::seed)>(py::handle(seed));
  13637. } CATCH_ALL(-1)
  13638. }
  13639. if (handle) {
  13640. try {
  13641. // TODO: remove this guard which is used for pybind11 implicit conversion
  13642. py::detail::loader_life_support guard{};
  13643. reinterpret_cast<PyOp(PoissonRNG)*>(self)->inst().handle =
  13644. py::cast<decltype(PoissonRNG::handle)>(py::handle(handle));
  13645. } CATCH_ALL(-1)
  13646. }
  13647. if (scope) {
  13648. try {
  13649. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13650. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13651. } CATCH_ALL(-1)
  13652. }
  13653. return 0;
  13654. }
  13655. PyGetSetDef PyOp(PoissonRNG)::py_getsetters[] = {
  13656. {const_cast<char*>("seed"), py_get_generic(PoissonRNG, seed), py_set_generic(PoissonRNG, seed), const_cast<char*>("seed"), NULL},
  13657. {const_cast<char*>("handle"), py_get_generic(PoissonRNG, handle), py_set_generic(PoissonRNG, handle), const_cast<char*>("handle"), NULL},
  13658. {NULL} /* Sentinel */
  13659. };
  13660. PyMethodDef PyOp(PoissonRNG)::tp_methods[] = {
  13661. {const_cast<char*>("__getstate__"), PyOp(PoissonRNG)::getstate, METH_NOARGS, "PoissonRNG getstate"},
  13662. {const_cast<char*>("__setstate__"), PyOp(PoissonRNG)::setstate, METH_VARARGS, "PoissonRNG setstate"},
  13663. {NULL} /* Sentinel */
  13664. };
  13665. PyObject *PyOp(PoissonRNG)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  13666. if (PyOp(PoissonRNG)::py_init(self, args, kwds) < 0) {
  13667. return NULL;
  13668. }
  13669. Py_RETURN_NONE;
  13670. }
  13671. PyMethodDef PyOp(PoissonRNG)::py_init_methoddef = {
  13672. "__init__",
  13673. (PyCFunction)PyOp(PoissonRNG)::py_init_proxy,
  13674. METH_VARARGS | METH_KEYWORDS,
  13675. "__init__(self, seed: int = ..., handle: int = ...) -> None\n"
  13676. };
  13677. void _init_py_PoissonRNG(py::module m) {
  13678. using py_op = PyOp(PoissonRNG);
  13679. auto& py_type = PyOpType(PoissonRNG);
  13680. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13681. py_type.tp_name = "megengine.core._imperative_rt.ops.PoissonRNG";
  13682. py_type.tp_basicsize = sizeof(PyOp(PoissonRNG));
  13683. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13684. py_type.tp_doc = "PoissonRNG";
  13685. py_type.tp_base = &PyOpType(OpDef);
  13686. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13687. py_type.tp_new = py_new_generic<py_op>;
  13688. py_type.tp_init = py_op::py_init;
  13689. py_type.tp_methods = py_op::tp_methods;
  13690. py_type.tp_getset = py_op::py_getsetters;
  13691. py_type.tp_dict = PyDict_New();
  13692. PyObject* descr = PyDescr_NewMethod(&PyOpType(PoissonRNG), &PyOp(PoissonRNG)::py_init_methoddef);
  13693. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  13694. mgb_assert(PyType_Ready(&py_type) >= 0);
  13695. PyType_Modified(&py_type);
  13696. m.add_object("PoissonRNG", reinterpret_cast<PyObject*>(&py_type));
  13697. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PoissonRNG::typeinfo(), &py_type).second);
  13698. }
  13699. void _init_py_Pooling_Mode(PyTypeObject& py_type) {
  13700. auto& e_type = EnumWrapper<Pooling::Mode>::type;
  13701. Py_INCREF(e_type);
  13702. mgb_assert(PyDict_SetItemString(
  13703. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13704. }
  13705. void _init_py_Pooling_Format(PyTypeObject& py_type) {
  13706. auto& e_type = EnumWrapper<Pooling::Format>::type;
  13707. Py_INCREF(e_type);
  13708. mgb_assert(PyDict_SetItemString(
  13709. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13710. }
  13711. void _init_py_Pooling_Strategy(PyTypeObject& py_type) {
  13712. auto& e_type = BitCombinedEnumWrapper<Pooling::Strategy>::type;
  13713. Py_INCREF(e_type);
  13714. mgb_assert(PyDict_SetItemString(
  13715. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13716. }
  13717. PyOpDefBegin(Pooling) // {
  13718. static PyGetSetDef py_getsetters[];
  13719. static PyMethodDef tp_methods[];
  13720. static PyObject* getstate(PyObject* self, PyObject*) {
  13721. auto& opdef = reinterpret_cast<PyOp(Pooling)*>(self)->inst();
  13722. static_cast<void>(opdef);
  13723. std::unordered_map<std::string, py::object> state {
  13724. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  13725. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  13726. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  13727. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  13728. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  13729. {"window_h", serialization<decltype(opdef.window_h)>::dump(opdef.window_h)},
  13730. {"window_w", serialization<decltype(opdef.window_w)>::dump(opdef.window_w)},
  13731. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  13732. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  13733. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)}
  13734. };
  13735. return py::cast(state).release().ptr();
  13736. }
  13737. static PyObject* setstate(PyObject* self, PyObject* args) {
  13738. PyObject* dict = PyTuple_GetItem(args, 0);
  13739. if (!dict) return NULL;
  13740. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13741. auto& opdef = reinterpret_cast<PyOp(Pooling)*>(self)->inst();
  13742. static_cast<void>(opdef);
  13743. {
  13744. auto&& iter = state.find("mode");
  13745. if (iter != state.end()) {
  13746. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  13747. }
  13748. }
  13749. {
  13750. auto&& iter = state.find("pad_h");
  13751. if (iter != state.end()) {
  13752. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  13753. }
  13754. }
  13755. {
  13756. auto&& iter = state.find("pad_w");
  13757. if (iter != state.end()) {
  13758. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  13759. }
  13760. }
  13761. {
  13762. auto&& iter = state.find("stride_h");
  13763. if (iter != state.end()) {
  13764. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  13765. }
  13766. }
  13767. {
  13768. auto&& iter = state.find("stride_w");
  13769. if (iter != state.end()) {
  13770. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  13771. }
  13772. }
  13773. {
  13774. auto&& iter = state.find("window_h");
  13775. if (iter != state.end()) {
  13776. opdef.window_h = serialization<decltype(opdef.window_h)>::load(iter->second);
  13777. }
  13778. }
  13779. {
  13780. auto&& iter = state.find("window_w");
  13781. if (iter != state.end()) {
  13782. opdef.window_w = serialization<decltype(opdef.window_w)>::load(iter->second);
  13783. }
  13784. }
  13785. {
  13786. auto&& iter = state.find("format");
  13787. if (iter != state.end()) {
  13788. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  13789. }
  13790. }
  13791. {
  13792. auto&& iter = state.find("strategy");
  13793. if (iter != state.end()) {
  13794. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  13795. }
  13796. }
  13797. {
  13798. auto&& iter = state.find("workspace_limit");
  13799. if (iter != state.end()) {
  13800. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  13801. }
  13802. }
  13803. Py_RETURN_NONE;
  13804. }
  13805. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13806. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  13807. static PyMethodDef py_init_methoddef;
  13808. // };
  13809. PyOpDefEnd(Pooling)
  13810. int PyOp(Pooling)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13811. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "window_h", "window_w", "format", "strategy", "workspace_limit", "scope", NULL};
  13812. PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *window_h = NULL, *window_w = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *scope = NULL;
  13813. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &window_h, &window_w, &format, &strategy, &workspace_limit, &scope))
  13814. return -1;
  13815. if (mode) {
  13816. try {
  13817. // TODO: remove this guard which is used for pybind11 implicit conversion
  13818. py::detail::loader_life_support guard{};
  13819. reinterpret_cast<PyOp(Pooling)*>(self)->inst().mode =
  13820. py::cast<decltype(Pooling::mode)>(py::handle(mode));
  13821. } CATCH_ALL(-1)
  13822. }
  13823. if (pad_h) {
  13824. try {
  13825. // TODO: remove this guard which is used for pybind11 implicit conversion
  13826. py::detail::loader_life_support guard{};
  13827. reinterpret_cast<PyOp(Pooling)*>(self)->inst().pad_h =
  13828. py::cast<decltype(Pooling::pad_h)>(py::handle(pad_h));
  13829. } CATCH_ALL(-1)
  13830. }
  13831. if (pad_w) {
  13832. try {
  13833. // TODO: remove this guard which is used for pybind11 implicit conversion
  13834. py::detail::loader_life_support guard{};
  13835. reinterpret_cast<PyOp(Pooling)*>(self)->inst().pad_w =
  13836. py::cast<decltype(Pooling::pad_w)>(py::handle(pad_w));
  13837. } CATCH_ALL(-1)
  13838. }
  13839. if (stride_h) {
  13840. try {
  13841. // TODO: remove this guard which is used for pybind11 implicit conversion
  13842. py::detail::loader_life_support guard{};
  13843. reinterpret_cast<PyOp(Pooling)*>(self)->inst().stride_h =
  13844. py::cast<decltype(Pooling::stride_h)>(py::handle(stride_h));
  13845. } CATCH_ALL(-1)
  13846. }
  13847. if (stride_w) {
  13848. try {
  13849. // TODO: remove this guard which is used for pybind11 implicit conversion
  13850. py::detail::loader_life_support guard{};
  13851. reinterpret_cast<PyOp(Pooling)*>(self)->inst().stride_w =
  13852. py::cast<decltype(Pooling::stride_w)>(py::handle(stride_w));
  13853. } CATCH_ALL(-1)
  13854. }
  13855. if (window_h) {
  13856. try {
  13857. // TODO: remove this guard which is used for pybind11 implicit conversion
  13858. py::detail::loader_life_support guard{};
  13859. reinterpret_cast<PyOp(Pooling)*>(self)->inst().window_h =
  13860. py::cast<decltype(Pooling::window_h)>(py::handle(window_h));
  13861. } CATCH_ALL(-1)
  13862. }
  13863. if (window_w) {
  13864. try {
  13865. // TODO: remove this guard which is used for pybind11 implicit conversion
  13866. py::detail::loader_life_support guard{};
  13867. reinterpret_cast<PyOp(Pooling)*>(self)->inst().window_w =
  13868. py::cast<decltype(Pooling::window_w)>(py::handle(window_w));
  13869. } CATCH_ALL(-1)
  13870. }
  13871. if (format) {
  13872. try {
  13873. // TODO: remove this guard which is used for pybind11 implicit conversion
  13874. py::detail::loader_life_support guard{};
  13875. reinterpret_cast<PyOp(Pooling)*>(self)->inst().format =
  13876. py::cast<decltype(Pooling::format)>(py::handle(format));
  13877. } CATCH_ALL(-1)
  13878. }
  13879. if (strategy) {
  13880. try {
  13881. // TODO: remove this guard which is used for pybind11 implicit conversion
  13882. py::detail::loader_life_support guard{};
  13883. reinterpret_cast<PyOp(Pooling)*>(self)->inst().strategy =
  13884. py::cast<decltype(Pooling::strategy)>(py::handle(strategy));
  13885. } CATCH_ALL(-1)
  13886. }
  13887. if (workspace_limit) {
  13888. try {
  13889. // TODO: remove this guard which is used for pybind11 implicit conversion
  13890. py::detail::loader_life_support guard{};
  13891. reinterpret_cast<PyOp(Pooling)*>(self)->inst().workspace_limit =
  13892. py::cast<decltype(Pooling::workspace_limit)>(py::handle(workspace_limit));
  13893. } CATCH_ALL(-1)
  13894. }
  13895. if (scope) {
  13896. try {
  13897. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13898. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13899. } CATCH_ALL(-1)
  13900. }
  13901. return 0;
  13902. }
  13903. PyGetSetDef PyOp(Pooling)::py_getsetters[] = {
  13904. {const_cast<char*>("mode"), py_get_generic(Pooling, mode), py_set_generic(Pooling, mode), const_cast<char*>("mode"), NULL},
  13905. {const_cast<char*>("pad_h"), py_get_generic(Pooling, pad_h), py_set_generic(Pooling, pad_h), const_cast<char*>("pad_h"), NULL},
  13906. {const_cast<char*>("pad_w"), py_get_generic(Pooling, pad_w), py_set_generic(Pooling, pad_w), const_cast<char*>("pad_w"), NULL},
  13907. {const_cast<char*>("stride_h"), py_get_generic(Pooling, stride_h), py_set_generic(Pooling, stride_h), const_cast<char*>("stride_h"), NULL},
  13908. {const_cast<char*>("stride_w"), py_get_generic(Pooling, stride_w), py_set_generic(Pooling, stride_w), const_cast<char*>("stride_w"), NULL},
  13909. {const_cast<char*>("window_h"), py_get_generic(Pooling, window_h), py_set_generic(Pooling, window_h), const_cast<char*>("window_h"), NULL},
  13910. {const_cast<char*>("window_w"), py_get_generic(Pooling, window_w), py_set_generic(Pooling, window_w), const_cast<char*>("window_w"), NULL},
  13911. {const_cast<char*>("format"), py_get_generic(Pooling, format), py_set_generic(Pooling, format), const_cast<char*>("format"), NULL},
  13912. {const_cast<char*>("strategy"), py_get_generic(Pooling, strategy), py_set_generic(Pooling, strategy), const_cast<char*>("strategy"), NULL},
  13913. {const_cast<char*>("workspace_limit"), py_get_generic(Pooling, workspace_limit), py_set_generic(Pooling, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  13914. {NULL} /* Sentinel */
  13915. };
  13916. PyMethodDef PyOp(Pooling)::tp_methods[] = {
  13917. {const_cast<char*>("__getstate__"), PyOp(Pooling)::getstate, METH_NOARGS, "Pooling getstate"},
  13918. {const_cast<char*>("__setstate__"), PyOp(Pooling)::setstate, METH_VARARGS, "Pooling setstate"},
  13919. {NULL} /* Sentinel */
  13920. };
  13921. PyObject *PyOp(Pooling)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  13922. if (PyOp(Pooling)::py_init(self, args, kwds) < 0) {
  13923. return NULL;
  13924. }
  13925. Py_RETURN_NONE;
  13926. }
  13927. PyMethodDef PyOp(Pooling)::py_init_methoddef = {
  13928. "__init__",
  13929. (PyCFunction)PyOp(Pooling)::py_init_proxy,
  13930. METH_VARARGS | METH_KEYWORDS,
  13931. "__init__(self, mode: Union[str, Mode] = ..., pad_h: int = ..., pad_w: int = ..., stride_h: int = ..., stride_w: int = ..., window_h: int = ..., window_w: int = ..., format: Union[str, Format] = ..., strategy: Union[str, Strategy] = ...) -> None\n"
  13932. };
  13933. void _init_py_Pooling(py::module m) {
  13934. using py_op = PyOp(Pooling);
  13935. auto& py_type = PyOpType(Pooling);
  13936. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13937. py_type.tp_name = "megengine.core._imperative_rt.ops.Pooling";
  13938. py_type.tp_basicsize = sizeof(PyOp(Pooling));
  13939. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13940. py_type.tp_doc = "Pooling";
  13941. py_type.tp_base = &PyOpType(OpDef);
  13942. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13943. py_type.tp_new = py_new_generic<py_op>;
  13944. py_type.tp_init = py_op::py_init;
  13945. py_type.tp_methods = py_op::tp_methods;
  13946. py_type.tp_getset = py_op::py_getsetters;
  13947. py_type.tp_dict = PyDict_New();
  13948. PyObject* descr = PyDescr_NewMethod(&PyOpType(Pooling), &PyOp(Pooling)::py_init_methoddef);
  13949. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  13950. mgb_assert(PyType_Ready(&py_type) >= 0);
  13951. _init_py_Pooling_Mode(py_type);
  13952. _init_py_Pooling_Format(py_type);
  13953. _init_py_Pooling_Strategy(py_type);
  13954. PyType_Modified(&py_type);
  13955. m.add_object("Pooling", reinterpret_cast<PyObject*>(&py_type));
  13956. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Pooling::typeinfo(), &py_type).second);
  13957. }
  13958. template<> struct EnumTrait<RNN::NonlineMode> {
  13959. static constexpr const char *name = "RNN.NonlineMode";
  13960. static constexpr std::underlying_type_t<RNN::NonlineMode> max = 3 - 1;
  13961. };
  13962. template<> PyTypeObject* EnumWrapper<RNN::NonlineMode>::type = nullptr;
  13963. template<> const char*
  13964. EnumWrapper<RNN::NonlineMode>::members[] = {"IDENTITY", "RELU", "TANH"};
  13965. template<> std::unordered_map<std::string, RNN::NonlineMode>
  13966. EnumWrapper<RNN::NonlineMode>::mem2value = {{normalize_enum("IDENTITY"), RNN::NonlineMode::IDENTITY}, {normalize_enum("RELU"), RNN::NonlineMode::RELU}, {normalize_enum("TANH"), RNN::NonlineMode::TANH}};
  13967. template<> PyObject* EnumWrapper<RNN::NonlineMode>::pyobj_insts[3] = {nullptr};
  13968. void _init_py_RNN_NonlineMode(PyTypeObject& py_type) {
  13969. auto& e_type = EnumWrapper<RNN::NonlineMode>::type;
  13970. static PyMethodDef tp_methods[] = {
  13971. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<RNN::NonlineMode>::py_dump, METH_NOARGS, NULL},
  13972. {NULL} /* Sentinel */
  13973. };
  13974. static PyType_Slot slots[] = {
  13975. {Py_tp_repr, (void*)EnumWrapper<RNN::NonlineMode>::py_repr},
  13976. {Py_tp_richcompare, (void*)EnumWrapper<RNN::NonlineMode>::tp_richcompare},
  13977. {Py_tp_methods, tp_methods},
  13978. {0, NULL}
  13979. };
  13980. static PyType_Spec spec = {
  13981. // name
  13982. "megengine.core._imperative_rt.ops.RNN.NonlineMode",
  13983. // basicsize
  13984. sizeof(EnumWrapper<RNN::NonlineMode>),
  13985. // itemsize
  13986. 0,
  13987. // flags
  13988. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  13989. // slots
  13990. slots
  13991. };
  13992. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  13993. mgb_assert(
  13994. e_type->tp_setattro(
  13995. reinterpret_cast<PyObject*>(e_type),
  13996. py::cast("__name__").release().ptr(),
  13997. py::cast("NonlineMode").release().ptr()) >= 0);
  13998. mgb_assert(
  13999. e_type->tp_setattro(
  14000. reinterpret_cast<PyObject*>(e_type),
  14001. py::cast("__module__").release().ptr(),
  14002. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  14003. mgb_assert(
  14004. e_type->tp_setattro(
  14005. reinterpret_cast<PyObject*>(e_type),
  14006. py::cast("__qualname__").release().ptr(),
  14007. py::cast("RNN.NonlineMode").release().ptr()) >= 0);
  14008. {
  14009. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14010. reinterpret_cast<EnumWrapper<RNN::NonlineMode>*>(inst)->value = RNN::NonlineMode::IDENTITY;
  14011. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "IDENTITY", inst) >= 0);
  14012. EnumWrapper<RNN::NonlineMode>::pyobj_insts[0] = inst;
  14013. }{
  14014. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14015. reinterpret_cast<EnumWrapper<RNN::NonlineMode>*>(inst)->value = RNN::NonlineMode::RELU;
  14016. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RELU", inst) >= 0);
  14017. EnumWrapper<RNN::NonlineMode>::pyobj_insts[1] = inst;
  14018. }{
  14019. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14020. reinterpret_cast<EnumWrapper<RNN::NonlineMode>*>(inst)->value = RNN::NonlineMode::TANH;
  14021. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TANH", inst) >= 0);
  14022. EnumWrapper<RNN::NonlineMode>::pyobj_insts[2] = inst;
  14023. }
  14024. Py_INCREF(e_type);
  14025. mgb_assert(PyDict_SetItemString(
  14026. py_type.tp_dict, "NonlineMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  14027. }
  14028. void _init_py_RNN_FwdMode(PyTypeObject& py_type) {
  14029. auto& e_type = EnumWrapper<RNN::FwdMode>::type;
  14030. Py_INCREF(e_type);
  14031. mgb_assert(PyDict_SetItemString(
  14032. py_type.tp_dict, "FwdMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  14033. }
  14034. PyOpDefBegin(RNN) // {
  14035. static PyGetSetDef py_getsetters[];
  14036. static PyMethodDef tp_methods[];
  14037. static PyObject* getstate(PyObject* self, PyObject*) {
  14038. auto& opdef = reinterpret_cast<PyOp(RNN)*>(self)->inst();
  14039. static_cast<void>(opdef);
  14040. std::unordered_map<std::string, py::object> state {
  14041. {"num_layers", serialization<decltype(opdef.num_layers)>::dump(opdef.num_layers)},
  14042. {"bidirectional", serialization<decltype(opdef.bidirectional)>::dump(opdef.bidirectional)},
  14043. {"bias", serialization<decltype(opdef.bias)>::dump(opdef.bias)},
  14044. {"hidden_size", serialization<decltype(opdef.hidden_size)>::dump(opdef.hidden_size)},
  14045. {"dropout", serialization<decltype(opdef.dropout)>::dump(opdef.dropout)},
  14046. {"nonlineMode", serialization<decltype(opdef.nonlineMode)>::dump(opdef.nonlineMode)},
  14047. {"fwd_mode", serialization<decltype(opdef.fwd_mode)>::dump(opdef.fwd_mode)}
  14048. };
  14049. return py::cast(state).release().ptr();
  14050. }
  14051. static PyObject* setstate(PyObject* self, PyObject* args) {
  14052. PyObject* dict = PyTuple_GetItem(args, 0);
  14053. if (!dict) return NULL;
  14054. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14055. auto& opdef = reinterpret_cast<PyOp(RNN)*>(self)->inst();
  14056. static_cast<void>(opdef);
  14057. {
  14058. auto&& iter = state.find("num_layers");
  14059. if (iter != state.end()) {
  14060. opdef.num_layers = serialization<decltype(opdef.num_layers)>::load(iter->second);
  14061. }
  14062. }
  14063. {
  14064. auto&& iter = state.find("bidirectional");
  14065. if (iter != state.end()) {
  14066. opdef.bidirectional = serialization<decltype(opdef.bidirectional)>::load(iter->second);
  14067. }
  14068. }
  14069. {
  14070. auto&& iter = state.find("bias");
  14071. if (iter != state.end()) {
  14072. opdef.bias = serialization<decltype(opdef.bias)>::load(iter->second);
  14073. }
  14074. }
  14075. {
  14076. auto&& iter = state.find("hidden_size");
  14077. if (iter != state.end()) {
  14078. opdef.hidden_size = serialization<decltype(opdef.hidden_size)>::load(iter->second);
  14079. }
  14080. }
  14081. {
  14082. auto&& iter = state.find("dropout");
  14083. if (iter != state.end()) {
  14084. opdef.dropout = serialization<decltype(opdef.dropout)>::load(iter->second);
  14085. }
  14086. }
  14087. {
  14088. auto&& iter = state.find("nonlineMode");
  14089. if (iter != state.end()) {
  14090. opdef.nonlineMode = serialization<decltype(opdef.nonlineMode)>::load(iter->second);
  14091. }
  14092. }
  14093. {
  14094. auto&& iter = state.find("fwd_mode");
  14095. if (iter != state.end()) {
  14096. opdef.fwd_mode = serialization<decltype(opdef.fwd_mode)>::load(iter->second);
  14097. }
  14098. }
  14099. Py_RETURN_NONE;
  14100. }
  14101. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14102. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  14103. static PyMethodDef py_init_methoddef;
  14104. // };
  14105. PyOpDefEnd(RNN)
  14106. int PyOp(RNN)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14107. static const char* kwlist[] = {"num_layers", "bidirectional", "bias", "hidden_size", "dropout", "nonlineMode", "fwd_mode", "scope", NULL};
  14108. PyObject *num_layers = NULL, *bidirectional = NULL, *bias = NULL, *hidden_size = NULL, *dropout = NULL, *nonlineMode = NULL, *fwd_mode = NULL, *scope = NULL;
  14109. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOO", const_cast<char**>(kwlist), &num_layers, &bidirectional, &bias, &hidden_size, &dropout, &nonlineMode, &fwd_mode, &scope))
  14110. return -1;
  14111. if (num_layers) {
  14112. try {
  14113. // TODO: remove this guard which is used for pybind11 implicit conversion
  14114. py::detail::loader_life_support guard{};
  14115. reinterpret_cast<PyOp(RNN)*>(self)->inst().num_layers =
  14116. py::cast<decltype(RNN::num_layers)>(py::handle(num_layers));
  14117. } CATCH_ALL(-1)
  14118. }
  14119. if (bidirectional) {
  14120. try {
  14121. // TODO: remove this guard which is used for pybind11 implicit conversion
  14122. py::detail::loader_life_support guard{};
  14123. reinterpret_cast<PyOp(RNN)*>(self)->inst().bidirectional =
  14124. py::cast<decltype(RNN::bidirectional)>(py::handle(bidirectional));
  14125. } CATCH_ALL(-1)
  14126. }
  14127. if (bias) {
  14128. try {
  14129. // TODO: remove this guard which is used for pybind11 implicit conversion
  14130. py::detail::loader_life_support guard{};
  14131. reinterpret_cast<PyOp(RNN)*>(self)->inst().bias =
  14132. py::cast<decltype(RNN::bias)>(py::handle(bias));
  14133. } CATCH_ALL(-1)
  14134. }
  14135. if (hidden_size) {
  14136. try {
  14137. // TODO: remove this guard which is used for pybind11 implicit conversion
  14138. py::detail::loader_life_support guard{};
  14139. reinterpret_cast<PyOp(RNN)*>(self)->inst().hidden_size =
  14140. py::cast<decltype(RNN::hidden_size)>(py::handle(hidden_size));
  14141. } CATCH_ALL(-1)
  14142. }
  14143. if (dropout) {
  14144. try {
  14145. // TODO: remove this guard which is used for pybind11 implicit conversion
  14146. py::detail::loader_life_support guard{};
  14147. reinterpret_cast<PyOp(RNN)*>(self)->inst().dropout =
  14148. py::cast<decltype(RNN::dropout)>(py::handle(dropout));
  14149. } CATCH_ALL(-1)
  14150. }
  14151. if (nonlineMode) {
  14152. try {
  14153. // TODO: remove this guard which is used for pybind11 implicit conversion
  14154. py::detail::loader_life_support guard{};
  14155. reinterpret_cast<PyOp(RNN)*>(self)->inst().nonlineMode =
  14156. py::cast<decltype(RNN::nonlineMode)>(py::handle(nonlineMode));
  14157. } CATCH_ALL(-1)
  14158. }
  14159. if (fwd_mode) {
  14160. try {
  14161. // TODO: remove this guard which is used for pybind11 implicit conversion
  14162. py::detail::loader_life_support guard{};
  14163. reinterpret_cast<PyOp(RNN)*>(self)->inst().fwd_mode =
  14164. py::cast<decltype(RNN::fwd_mode)>(py::handle(fwd_mode));
  14165. } CATCH_ALL(-1)
  14166. }
  14167. if (scope) {
  14168. try {
  14169. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14170. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14171. } CATCH_ALL(-1)
  14172. }
  14173. return 0;
  14174. }
  14175. PyGetSetDef PyOp(RNN)::py_getsetters[] = {
  14176. {const_cast<char*>("num_layers"), py_get_generic(RNN, num_layers), py_set_generic(RNN, num_layers), const_cast<char*>("num_layers"), NULL},
  14177. {const_cast<char*>("bidirectional"), py_get_generic(RNN, bidirectional), py_set_generic(RNN, bidirectional), const_cast<char*>("bidirectional"), NULL},
  14178. {const_cast<char*>("bias"), py_get_generic(RNN, bias), py_set_generic(RNN, bias), const_cast<char*>("bias"), NULL},
  14179. {const_cast<char*>("hidden_size"), py_get_generic(RNN, hidden_size), py_set_generic(RNN, hidden_size), const_cast<char*>("hidden_size"), NULL},
  14180. {const_cast<char*>("dropout"), py_get_generic(RNN, dropout), py_set_generic(RNN, dropout), const_cast<char*>("dropout"), NULL},
  14181. {const_cast<char*>("nonlineMode"), py_get_generic(RNN, nonlineMode), py_set_generic(RNN, nonlineMode), const_cast<char*>("nonlineMode"), NULL},
  14182. {const_cast<char*>("fwd_mode"), py_get_generic(RNN, fwd_mode), py_set_generic(RNN, fwd_mode), const_cast<char*>("fwd_mode"), NULL},
  14183. {NULL} /* Sentinel */
  14184. };
  14185. PyMethodDef PyOp(RNN)::tp_methods[] = {
  14186. {const_cast<char*>("__getstate__"), PyOp(RNN)::getstate, METH_NOARGS, "RNN getstate"},
  14187. {const_cast<char*>("__setstate__"), PyOp(RNN)::setstate, METH_VARARGS, "RNN setstate"},
  14188. {NULL} /* Sentinel */
  14189. };
  14190. PyObject *PyOp(RNN)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  14191. if (PyOp(RNN)::py_init(self, args, kwds) < 0) {
  14192. return NULL;
  14193. }
  14194. Py_RETURN_NONE;
  14195. }
  14196. PyMethodDef PyOp(RNN)::py_init_methoddef = {
  14197. "__init__",
  14198. (PyCFunction)PyOp(RNN)::py_init_proxy,
  14199. METH_VARARGS | METH_KEYWORDS,
  14200. "__init__(self, num_layers: int = ..., bidirectional: bool = ..., bias: bool = ..., hidden_size: int = ..., dropout: float = ..., nonlineMode: Union[str, NonlineMode] = ..., fwd_mode: Union[str, FwdMode] = ...) -> None\n"
  14201. };
  14202. void _init_py_RNN(py::module m) {
  14203. using py_op = PyOp(RNN);
  14204. auto& py_type = PyOpType(RNN);
  14205. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14206. py_type.tp_name = "megengine.core._imperative_rt.ops.RNN";
  14207. py_type.tp_basicsize = sizeof(PyOp(RNN));
  14208. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14209. py_type.tp_doc = "RNN";
  14210. py_type.tp_base = &PyOpType(OpDef);
  14211. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14212. py_type.tp_new = py_new_generic<py_op>;
  14213. py_type.tp_init = py_op::py_init;
  14214. py_type.tp_methods = py_op::tp_methods;
  14215. py_type.tp_getset = py_op::py_getsetters;
  14216. py_type.tp_dict = PyDict_New();
  14217. PyObject* descr = PyDescr_NewMethod(&PyOpType(RNN), &PyOp(RNN)::py_init_methoddef);
  14218. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  14219. mgb_assert(PyType_Ready(&py_type) >= 0);
  14220. _init_py_RNN_NonlineMode(py_type);
  14221. _init_py_RNN_FwdMode(py_type);
  14222. PyType_Modified(&py_type);
  14223. m.add_object("RNN", reinterpret_cast<PyObject*>(&py_type));
  14224. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RNN::typeinfo(), &py_type).second);
  14225. }
  14226. void _init_py_RNNCell_NonlineMode(PyTypeObject& py_type) {
  14227. auto& e_type = EnumWrapper<RNNCell::NonlineMode>::type;
  14228. Py_INCREF(e_type);
  14229. mgb_assert(PyDict_SetItemString(
  14230. py_type.tp_dict, "NonlineMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  14231. }
  14232. PyOpDefBegin(RNNCell) // {
  14233. static PyGetSetDef py_getsetters[];
  14234. static PyMethodDef tp_methods[];
  14235. static PyObject* getstate(PyObject* self, PyObject*) {
  14236. auto& opdef = reinterpret_cast<PyOp(RNNCell)*>(self)->inst();
  14237. static_cast<void>(opdef);
  14238. std::unordered_map<std::string, py::object> state {
  14239. {"nonlineMode", serialization<decltype(opdef.nonlineMode)>::dump(opdef.nonlineMode)}
  14240. };
  14241. return py::cast(state).release().ptr();
  14242. }
  14243. static PyObject* setstate(PyObject* self, PyObject* args) {
  14244. PyObject* dict = PyTuple_GetItem(args, 0);
  14245. if (!dict) return NULL;
  14246. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14247. auto& opdef = reinterpret_cast<PyOp(RNNCell)*>(self)->inst();
  14248. static_cast<void>(opdef);
  14249. {
  14250. auto&& iter = state.find("nonlineMode");
  14251. if (iter != state.end()) {
  14252. opdef.nonlineMode = serialization<decltype(opdef.nonlineMode)>::load(iter->second);
  14253. }
  14254. }
  14255. Py_RETURN_NONE;
  14256. }
  14257. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14258. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  14259. static PyMethodDef py_init_methoddef;
  14260. // };
  14261. PyOpDefEnd(RNNCell)
  14262. int PyOp(RNNCell)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14263. static const char* kwlist[] = {"nonlineMode", "scope", NULL};
  14264. PyObject *nonlineMode = NULL, *scope = NULL;
  14265. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &nonlineMode, &scope))
  14266. return -1;
  14267. if (nonlineMode) {
  14268. try {
  14269. // TODO: remove this guard which is used for pybind11 implicit conversion
  14270. py::detail::loader_life_support guard{};
  14271. reinterpret_cast<PyOp(RNNCell)*>(self)->inst().nonlineMode =
  14272. py::cast<decltype(RNNCell::nonlineMode)>(py::handle(nonlineMode));
  14273. } CATCH_ALL(-1)
  14274. }
  14275. if (scope) {
  14276. try {
  14277. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14278. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14279. } CATCH_ALL(-1)
  14280. }
  14281. return 0;
  14282. }
  14283. PyGetSetDef PyOp(RNNCell)::py_getsetters[] = {
  14284. {const_cast<char*>("nonlineMode"), py_get_generic(RNNCell, nonlineMode), py_set_generic(RNNCell, nonlineMode), const_cast<char*>("nonlineMode"), NULL},
  14285. {NULL} /* Sentinel */
  14286. };
  14287. PyMethodDef PyOp(RNNCell)::tp_methods[] = {
  14288. {const_cast<char*>("__getstate__"), PyOp(RNNCell)::getstate, METH_NOARGS, "RNNCell getstate"},
  14289. {const_cast<char*>("__setstate__"), PyOp(RNNCell)::setstate, METH_VARARGS, "RNNCell setstate"},
  14290. {NULL} /* Sentinel */
  14291. };
  14292. PyObject *PyOp(RNNCell)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  14293. if (PyOp(RNNCell)::py_init(self, args, kwds) < 0) {
  14294. return NULL;
  14295. }
  14296. Py_RETURN_NONE;
  14297. }
  14298. PyMethodDef PyOp(RNNCell)::py_init_methoddef = {
  14299. "__init__",
  14300. (PyCFunction)PyOp(RNNCell)::py_init_proxy,
  14301. METH_VARARGS | METH_KEYWORDS,
  14302. "__init__(self, nonlineMode: Union[str, NonlineMode] = ...) -> None\n"
  14303. };
  14304. void _init_py_RNNCell(py::module m) {
  14305. using py_op = PyOp(RNNCell);
  14306. auto& py_type = PyOpType(RNNCell);
  14307. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14308. py_type.tp_name = "megengine.core._imperative_rt.ops.RNNCell";
  14309. py_type.tp_basicsize = sizeof(PyOp(RNNCell));
  14310. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14311. py_type.tp_doc = "RNNCell";
  14312. py_type.tp_base = &PyOpType(OpDef);
  14313. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14314. py_type.tp_new = py_new_generic<py_op>;
  14315. py_type.tp_init = py_op::py_init;
  14316. py_type.tp_methods = py_op::tp_methods;
  14317. py_type.tp_getset = py_op::py_getsetters;
  14318. py_type.tp_dict = PyDict_New();
  14319. PyObject* descr = PyDescr_NewMethod(&PyOpType(RNNCell), &PyOp(RNNCell)::py_init_methoddef);
  14320. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  14321. mgb_assert(PyType_Ready(&py_type) >= 0);
  14322. _init_py_RNNCell_NonlineMode(py_type);
  14323. PyType_Modified(&py_type);
  14324. m.add_object("RNNCell", reinterpret_cast<PyObject*>(&py_type));
  14325. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RNNCell::typeinfo(), &py_type).second);
  14326. }
  14327. template<> struct EnumTrait<ROIAlign::Mode> {
  14328. static constexpr const char *name = "ROIAlign.Mode";
  14329. static constexpr std::underlying_type_t<ROIAlign::Mode> max = 2 - 1;
  14330. };
  14331. template<> PyTypeObject* EnumWrapper<ROIAlign::Mode>::type = nullptr;
  14332. template<> const char*
  14333. EnumWrapper<ROIAlign::Mode>::members[] = {"MAX", "AVERAGE"};
  14334. template<> std::unordered_map<std::string, ROIAlign::Mode>
  14335. EnumWrapper<ROIAlign::Mode>::mem2value = {{normalize_enum("MAX"), ROIAlign::Mode::MAX}, {normalize_enum("AVERAGE"), ROIAlign::Mode::AVERAGE}};
  14336. template<> PyObject* EnumWrapper<ROIAlign::Mode>::pyobj_insts[2] = {nullptr};
  14337. void _init_py_ROIAlign_Mode(PyTypeObject& py_type) {
  14338. auto& e_type = EnumWrapper<ROIAlign::Mode>::type;
  14339. static PyMethodDef tp_methods[] = {
  14340. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<ROIAlign::Mode>::py_dump, METH_NOARGS, NULL},
  14341. {NULL} /* Sentinel */
  14342. };
  14343. static PyType_Slot slots[] = {
  14344. {Py_tp_repr, (void*)EnumWrapper<ROIAlign::Mode>::py_repr},
  14345. {Py_tp_richcompare, (void*)EnumWrapper<ROIAlign::Mode>::tp_richcompare},
  14346. {Py_tp_methods, tp_methods},
  14347. {0, NULL}
  14348. };
  14349. static PyType_Spec spec = {
  14350. // name
  14351. "megengine.core._imperative_rt.ops.ROIAlign.Mode",
  14352. // basicsize
  14353. sizeof(EnumWrapper<ROIAlign::Mode>),
  14354. // itemsize
  14355. 0,
  14356. // flags
  14357. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  14358. // slots
  14359. slots
  14360. };
  14361. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  14362. mgb_assert(
  14363. e_type->tp_setattro(
  14364. reinterpret_cast<PyObject*>(e_type),
  14365. py::cast("__name__").release().ptr(),
  14366. py::cast("Mode").release().ptr()) >= 0);
  14367. mgb_assert(
  14368. e_type->tp_setattro(
  14369. reinterpret_cast<PyObject*>(e_type),
  14370. py::cast("__module__").release().ptr(),
  14371. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  14372. mgb_assert(
  14373. e_type->tp_setattro(
  14374. reinterpret_cast<PyObject*>(e_type),
  14375. py::cast("__qualname__").release().ptr(),
  14376. py::cast("ROIAlign.Mode").release().ptr()) >= 0);
  14377. {
  14378. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14379. reinterpret_cast<EnumWrapper<ROIAlign::Mode>*>(inst)->value = ROIAlign::Mode::MAX;
  14380. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0);
  14381. EnumWrapper<ROIAlign::Mode>::pyobj_insts[0] = inst;
  14382. }{
  14383. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14384. reinterpret_cast<EnumWrapper<ROIAlign::Mode>*>(inst)->value = ROIAlign::Mode::AVERAGE;
  14385. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AVERAGE", inst) >= 0);
  14386. EnumWrapper<ROIAlign::Mode>::pyobj_insts[1] = inst;
  14387. }
  14388. Py_INCREF(e_type);
  14389. mgb_assert(PyDict_SetItemString(
  14390. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  14391. }
  14392. void _init_py_ROIAlign_Format(PyTypeObject& py_type) {
  14393. auto& e_type = EnumWrapper<ROIAlign::Format>::type;
  14394. Py_INCREF(e_type);
  14395. mgb_assert(PyDict_SetItemString(
  14396. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  14397. }
  14398. PyOpDefBegin(ROIAlign) // {
  14399. static PyGetSetDef py_getsetters[];
  14400. static PyMethodDef tp_methods[];
  14401. static PyObject* getstate(PyObject* self, PyObject*) {
  14402. auto& opdef = reinterpret_cast<PyOp(ROIAlign)*>(self)->inst();
  14403. static_cast<void>(opdef);
  14404. std::unordered_map<std::string, py::object> state {
  14405. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  14406. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  14407. {"spatial_scale", serialization<decltype(opdef.spatial_scale)>::dump(opdef.spatial_scale)},
  14408. {"offset", serialization<decltype(opdef.offset)>::dump(opdef.offset)},
  14409. {"pooled_height", serialization<decltype(opdef.pooled_height)>::dump(opdef.pooled_height)},
  14410. {"pooled_width", serialization<decltype(opdef.pooled_width)>::dump(opdef.pooled_width)},
  14411. {"sample_height", serialization<decltype(opdef.sample_height)>::dump(opdef.sample_height)},
  14412. {"sample_width", serialization<decltype(opdef.sample_width)>::dump(opdef.sample_width)}
  14413. };
  14414. return py::cast(state).release().ptr();
  14415. }
  14416. static PyObject* setstate(PyObject* self, PyObject* args) {
  14417. PyObject* dict = PyTuple_GetItem(args, 0);
  14418. if (!dict) return NULL;
  14419. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14420. auto& opdef = reinterpret_cast<PyOp(ROIAlign)*>(self)->inst();
  14421. static_cast<void>(opdef);
  14422. {
  14423. auto&& iter = state.find("mode");
  14424. if (iter != state.end()) {
  14425. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  14426. }
  14427. }
  14428. {
  14429. auto&& iter = state.find("format");
  14430. if (iter != state.end()) {
  14431. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  14432. }
  14433. }
  14434. {
  14435. auto&& iter = state.find("spatial_scale");
  14436. if (iter != state.end()) {
  14437. opdef.spatial_scale = serialization<decltype(opdef.spatial_scale)>::load(iter->second);
  14438. }
  14439. }
  14440. {
  14441. auto&& iter = state.find("offset");
  14442. if (iter != state.end()) {
  14443. opdef.offset = serialization<decltype(opdef.offset)>::load(iter->second);
  14444. }
  14445. }
  14446. {
  14447. auto&& iter = state.find("pooled_height");
  14448. if (iter != state.end()) {
  14449. opdef.pooled_height = serialization<decltype(opdef.pooled_height)>::load(iter->second);
  14450. }
  14451. }
  14452. {
  14453. auto&& iter = state.find("pooled_width");
  14454. if (iter != state.end()) {
  14455. opdef.pooled_width = serialization<decltype(opdef.pooled_width)>::load(iter->second);
  14456. }
  14457. }
  14458. {
  14459. auto&& iter = state.find("sample_height");
  14460. if (iter != state.end()) {
  14461. opdef.sample_height = serialization<decltype(opdef.sample_height)>::load(iter->second);
  14462. }
  14463. }
  14464. {
  14465. auto&& iter = state.find("sample_width");
  14466. if (iter != state.end()) {
  14467. opdef.sample_width = serialization<decltype(opdef.sample_width)>::load(iter->second);
  14468. }
  14469. }
  14470. Py_RETURN_NONE;
  14471. }
  14472. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14473. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  14474. static PyMethodDef py_init_methoddef;
  14475. // };
  14476. PyOpDefEnd(ROIAlign)
  14477. int PyOp(ROIAlign)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14478. static const char* kwlist[] = {"mode", "format", "spatial_scale", "offset", "pooled_height", "pooled_width", "sample_height", "sample_width", "scope", NULL};
  14479. PyObject *mode = NULL, *format = NULL, *spatial_scale = NULL, *offset = NULL, *pooled_height = NULL, *pooled_width = NULL, *sample_height = NULL, *sample_width = NULL, *scope = NULL;
  14480. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &mode, &format, &spatial_scale, &offset, &pooled_height, &pooled_width, &sample_height, &sample_width, &scope))
  14481. return -1;
  14482. if (mode) {
  14483. try {
  14484. // TODO: remove this guard which is used for pybind11 implicit conversion
  14485. py::detail::loader_life_support guard{};
  14486. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().mode =
  14487. py::cast<decltype(ROIAlign::mode)>(py::handle(mode));
  14488. } CATCH_ALL(-1)
  14489. }
  14490. if (format) {
  14491. try {
  14492. // TODO: remove this guard which is used for pybind11 implicit conversion
  14493. py::detail::loader_life_support guard{};
  14494. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().format =
  14495. py::cast<decltype(ROIAlign::format)>(py::handle(format));
  14496. } CATCH_ALL(-1)
  14497. }
  14498. if (spatial_scale) {
  14499. try {
  14500. // TODO: remove this guard which is used for pybind11 implicit conversion
  14501. py::detail::loader_life_support guard{};
  14502. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().spatial_scale =
  14503. py::cast<decltype(ROIAlign::spatial_scale)>(py::handle(spatial_scale));
  14504. } CATCH_ALL(-1)
  14505. }
  14506. if (offset) {
  14507. try {
  14508. // TODO: remove this guard which is used for pybind11 implicit conversion
  14509. py::detail::loader_life_support guard{};
  14510. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().offset =
  14511. py::cast<decltype(ROIAlign::offset)>(py::handle(offset));
  14512. } CATCH_ALL(-1)
  14513. }
  14514. if (pooled_height) {
  14515. try {
  14516. // TODO: remove this guard which is used for pybind11 implicit conversion
  14517. py::detail::loader_life_support guard{};
  14518. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().pooled_height =
  14519. py::cast<decltype(ROIAlign::pooled_height)>(py::handle(pooled_height));
  14520. } CATCH_ALL(-1)
  14521. }
  14522. if (pooled_width) {
  14523. try {
  14524. // TODO: remove this guard which is used for pybind11 implicit conversion
  14525. py::detail::loader_life_support guard{};
  14526. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().pooled_width =
  14527. py::cast<decltype(ROIAlign::pooled_width)>(py::handle(pooled_width));
  14528. } CATCH_ALL(-1)
  14529. }
  14530. if (sample_height) {
  14531. try {
  14532. // TODO: remove this guard which is used for pybind11 implicit conversion
  14533. py::detail::loader_life_support guard{};
  14534. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().sample_height =
  14535. py::cast<decltype(ROIAlign::sample_height)>(py::handle(sample_height));
  14536. } CATCH_ALL(-1)
  14537. }
  14538. if (sample_width) {
  14539. try {
  14540. // TODO: remove this guard which is used for pybind11 implicit conversion
  14541. py::detail::loader_life_support guard{};
  14542. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().sample_width =
  14543. py::cast<decltype(ROIAlign::sample_width)>(py::handle(sample_width));
  14544. } CATCH_ALL(-1)
  14545. }
  14546. if (scope) {
  14547. try {
  14548. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14549. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14550. } CATCH_ALL(-1)
  14551. }
  14552. return 0;
  14553. }
  14554. PyGetSetDef PyOp(ROIAlign)::py_getsetters[] = {
  14555. {const_cast<char*>("mode"), py_get_generic(ROIAlign, mode), py_set_generic(ROIAlign, mode), const_cast<char*>("mode"), NULL},
  14556. {const_cast<char*>("format"), py_get_generic(ROIAlign, format), py_set_generic(ROIAlign, format), const_cast<char*>("format"), NULL},
  14557. {const_cast<char*>("spatial_scale"), py_get_generic(ROIAlign, spatial_scale), py_set_generic(ROIAlign, spatial_scale), const_cast<char*>("spatial_scale"), NULL},
  14558. {const_cast<char*>("offset"), py_get_generic(ROIAlign, offset), py_set_generic(ROIAlign, offset), const_cast<char*>("offset"), NULL},
  14559. {const_cast<char*>("pooled_height"), py_get_generic(ROIAlign, pooled_height), py_set_generic(ROIAlign, pooled_height), const_cast<char*>("pooled_height"), NULL},
  14560. {const_cast<char*>("pooled_width"), py_get_generic(ROIAlign, pooled_width), py_set_generic(ROIAlign, pooled_width), const_cast<char*>("pooled_width"), NULL},
  14561. {const_cast<char*>("sample_height"), py_get_generic(ROIAlign, sample_height), py_set_generic(ROIAlign, sample_height), const_cast<char*>("sample_height"), NULL},
  14562. {const_cast<char*>("sample_width"), py_get_generic(ROIAlign, sample_width), py_set_generic(ROIAlign, sample_width), const_cast<char*>("sample_width"), NULL},
  14563. {NULL} /* Sentinel */
  14564. };
  14565. PyMethodDef PyOp(ROIAlign)::tp_methods[] = {
  14566. {const_cast<char*>("__getstate__"), PyOp(ROIAlign)::getstate, METH_NOARGS, "ROIAlign getstate"},
  14567. {const_cast<char*>("__setstate__"), PyOp(ROIAlign)::setstate, METH_VARARGS, "ROIAlign setstate"},
  14568. {NULL} /* Sentinel */
  14569. };
  14570. PyObject *PyOp(ROIAlign)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  14571. if (PyOp(ROIAlign)::py_init(self, args, kwds) < 0) {
  14572. return NULL;
  14573. }
  14574. Py_RETURN_NONE;
  14575. }
  14576. PyMethodDef PyOp(ROIAlign)::py_init_methoddef = {
  14577. "__init__",
  14578. (PyCFunction)PyOp(ROIAlign)::py_init_proxy,
  14579. METH_VARARGS | METH_KEYWORDS,
  14580. "__init__(self, mode: Union[str, Mode] = ..., format: Union[str, Format] = ..., spatial_scale: float = ..., offset: float = ..., pooled_height: int = ..., pooled_width: int = ..., sample_height: int = ..., sample_width: int = ...) -> None\n"
  14581. };
  14582. void _init_py_ROIAlign(py::module m) {
  14583. using py_op = PyOp(ROIAlign);
  14584. auto& py_type = PyOpType(ROIAlign);
  14585. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14586. py_type.tp_name = "megengine.core._imperative_rt.ops.ROIAlign";
  14587. py_type.tp_basicsize = sizeof(PyOp(ROIAlign));
  14588. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14589. py_type.tp_doc = "ROIAlign";
  14590. py_type.tp_base = &PyOpType(OpDef);
  14591. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14592. py_type.tp_new = py_new_generic<py_op>;
  14593. py_type.tp_init = py_op::py_init;
  14594. py_type.tp_methods = py_op::tp_methods;
  14595. py_type.tp_getset = py_op::py_getsetters;
  14596. py_type.tp_dict = PyDict_New();
  14597. PyObject* descr = PyDescr_NewMethod(&PyOpType(ROIAlign), &PyOp(ROIAlign)::py_init_methoddef);
  14598. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  14599. mgb_assert(PyType_Ready(&py_type) >= 0);
  14600. _init_py_ROIAlign_Mode(py_type);
  14601. _init_py_ROIAlign_Format(py_type);
  14602. PyType_Modified(&py_type);
  14603. m.add_object("ROIAlign", reinterpret_cast<PyObject*>(&py_type));
  14604. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ROIAlign::typeinfo(), &py_type).second);
  14605. }
  14606. template<> struct EnumTrait<ROIPooling::Mode> {
  14607. static constexpr const char *name = "ROIPooling.Mode";
  14608. static constexpr std::underlying_type_t<ROIPooling::Mode> max = 2 - 1;
  14609. };
  14610. template<> PyTypeObject* EnumWrapper<ROIPooling::Mode>::type = nullptr;
  14611. template<> const char*
  14612. EnumWrapper<ROIPooling::Mode>::members[] = {"MAX", "AVERAGE"};
  14613. template<> std::unordered_map<std::string, ROIPooling::Mode>
  14614. EnumWrapper<ROIPooling::Mode>::mem2value = {{normalize_enum("MAX"), ROIPooling::Mode::MAX}, {normalize_enum("AVERAGE"), ROIPooling::Mode::AVERAGE}};
  14615. template<> PyObject* EnumWrapper<ROIPooling::Mode>::pyobj_insts[2] = {nullptr};
  14616. void _init_py_ROIPooling_Mode(PyTypeObject& py_type) {
  14617. auto& e_type = EnumWrapper<ROIPooling::Mode>::type;
  14618. static PyMethodDef tp_methods[] = {
  14619. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<ROIPooling::Mode>::py_dump, METH_NOARGS, NULL},
  14620. {NULL} /* Sentinel */
  14621. };
  14622. static PyType_Slot slots[] = {
  14623. {Py_tp_repr, (void*)EnumWrapper<ROIPooling::Mode>::py_repr},
  14624. {Py_tp_richcompare, (void*)EnumWrapper<ROIPooling::Mode>::tp_richcompare},
  14625. {Py_tp_methods, tp_methods},
  14626. {0, NULL}
  14627. };
  14628. static PyType_Spec spec = {
  14629. // name
  14630. "megengine.core._imperative_rt.ops.ROIPooling.Mode",
  14631. // basicsize
  14632. sizeof(EnumWrapper<ROIPooling::Mode>),
  14633. // itemsize
  14634. 0,
  14635. // flags
  14636. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  14637. // slots
  14638. slots
  14639. };
  14640. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  14641. mgb_assert(
  14642. e_type->tp_setattro(
  14643. reinterpret_cast<PyObject*>(e_type),
  14644. py::cast("__name__").release().ptr(),
  14645. py::cast("Mode").release().ptr()) >= 0);
  14646. mgb_assert(
  14647. e_type->tp_setattro(
  14648. reinterpret_cast<PyObject*>(e_type),
  14649. py::cast("__module__").release().ptr(),
  14650. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  14651. mgb_assert(
  14652. e_type->tp_setattro(
  14653. reinterpret_cast<PyObject*>(e_type),
  14654. py::cast("__qualname__").release().ptr(),
  14655. py::cast("ROIPooling.Mode").release().ptr()) >= 0);
  14656. {
  14657. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14658. reinterpret_cast<EnumWrapper<ROIPooling::Mode>*>(inst)->value = ROIPooling::Mode::MAX;
  14659. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0);
  14660. EnumWrapper<ROIPooling::Mode>::pyobj_insts[0] = inst;
  14661. }{
  14662. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14663. reinterpret_cast<EnumWrapper<ROIPooling::Mode>*>(inst)->value = ROIPooling::Mode::AVERAGE;
  14664. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AVERAGE", inst) >= 0);
  14665. EnumWrapper<ROIPooling::Mode>::pyobj_insts[1] = inst;
  14666. }
  14667. Py_INCREF(e_type);
  14668. mgb_assert(PyDict_SetItemString(
  14669. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  14670. }
  14671. PyOpDefBegin(ROIPooling) // {
  14672. static PyGetSetDef py_getsetters[];
  14673. static PyMethodDef tp_methods[];
  14674. static PyObject* getstate(PyObject* self, PyObject*) {
  14675. auto& opdef = reinterpret_cast<PyOp(ROIPooling)*>(self)->inst();
  14676. static_cast<void>(opdef);
  14677. std::unordered_map<std::string, py::object> state {
  14678. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  14679. {"scale", serialization<decltype(opdef.scale)>::dump(opdef.scale)}
  14680. };
  14681. return py::cast(state).release().ptr();
  14682. }
  14683. static PyObject* setstate(PyObject* self, PyObject* args) {
  14684. PyObject* dict = PyTuple_GetItem(args, 0);
  14685. if (!dict) return NULL;
  14686. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14687. auto& opdef = reinterpret_cast<PyOp(ROIPooling)*>(self)->inst();
  14688. static_cast<void>(opdef);
  14689. {
  14690. auto&& iter = state.find("mode");
  14691. if (iter != state.end()) {
  14692. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  14693. }
  14694. }
  14695. {
  14696. auto&& iter = state.find("scale");
  14697. if (iter != state.end()) {
  14698. opdef.scale = serialization<decltype(opdef.scale)>::load(iter->second);
  14699. }
  14700. }
  14701. Py_RETURN_NONE;
  14702. }
  14703. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14704. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  14705. static PyMethodDef py_init_methoddef;
  14706. // };
  14707. PyOpDefEnd(ROIPooling)
  14708. int PyOp(ROIPooling)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14709. static const char* kwlist[] = {"mode", "scale", "scope", NULL};
  14710. PyObject *mode = NULL, *scale = NULL, *scope = NULL;
  14711. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &mode, &scale, &scope))
  14712. return -1;
  14713. if (mode) {
  14714. try {
  14715. // TODO: remove this guard which is used for pybind11 implicit conversion
  14716. py::detail::loader_life_support guard{};
  14717. reinterpret_cast<PyOp(ROIPooling)*>(self)->inst().mode =
  14718. py::cast<decltype(ROIPooling::mode)>(py::handle(mode));
  14719. } CATCH_ALL(-1)
  14720. }
  14721. if (scale) {
  14722. try {
  14723. // TODO: remove this guard which is used for pybind11 implicit conversion
  14724. py::detail::loader_life_support guard{};
  14725. reinterpret_cast<PyOp(ROIPooling)*>(self)->inst().scale =
  14726. py::cast<decltype(ROIPooling::scale)>(py::handle(scale));
  14727. } CATCH_ALL(-1)
  14728. }
  14729. if (scope) {
  14730. try {
  14731. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14732. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14733. } CATCH_ALL(-1)
  14734. }
  14735. return 0;
  14736. }
  14737. PyGetSetDef PyOp(ROIPooling)::py_getsetters[] = {
  14738. {const_cast<char*>("mode"), py_get_generic(ROIPooling, mode), py_set_generic(ROIPooling, mode), const_cast<char*>("mode"), NULL},
  14739. {const_cast<char*>("scale"), py_get_generic(ROIPooling, scale), py_set_generic(ROIPooling, scale), const_cast<char*>("scale"), NULL},
  14740. {NULL} /* Sentinel */
  14741. };
  14742. PyMethodDef PyOp(ROIPooling)::tp_methods[] = {
  14743. {const_cast<char*>("__getstate__"), PyOp(ROIPooling)::getstate, METH_NOARGS, "ROIPooling getstate"},
  14744. {const_cast<char*>("__setstate__"), PyOp(ROIPooling)::setstate, METH_VARARGS, "ROIPooling setstate"},
  14745. {NULL} /* Sentinel */
  14746. };
  14747. PyObject *PyOp(ROIPooling)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  14748. if (PyOp(ROIPooling)::py_init(self, args, kwds) < 0) {
  14749. return NULL;
  14750. }
  14751. Py_RETURN_NONE;
  14752. }
  14753. PyMethodDef PyOp(ROIPooling)::py_init_methoddef = {
  14754. "__init__",
  14755. (PyCFunction)PyOp(ROIPooling)::py_init_proxy,
  14756. METH_VARARGS | METH_KEYWORDS,
  14757. "__init__(self, mode: Union[str, Mode] = ..., scale: float = ...) -> None\n"
  14758. };
  14759. void _init_py_ROIPooling(py::module m) {
  14760. using py_op = PyOp(ROIPooling);
  14761. auto& py_type = PyOpType(ROIPooling);
  14762. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14763. py_type.tp_name = "megengine.core._imperative_rt.ops.ROIPooling";
  14764. py_type.tp_basicsize = sizeof(PyOp(ROIPooling));
  14765. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14766. py_type.tp_doc = "ROIPooling";
  14767. py_type.tp_base = &PyOpType(OpDef);
  14768. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14769. py_type.tp_new = py_new_generic<py_op>;
  14770. py_type.tp_init = py_op::py_init;
  14771. py_type.tp_methods = py_op::tp_methods;
  14772. py_type.tp_getset = py_op::py_getsetters;
  14773. py_type.tp_dict = PyDict_New();
  14774. PyObject* descr = PyDescr_NewMethod(&PyOpType(ROIPooling), &PyOp(ROIPooling)::py_init_methoddef);
  14775. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  14776. mgb_assert(PyType_Ready(&py_type) >= 0);
  14777. _init_py_ROIPooling_Mode(py_type);
  14778. PyType_Modified(&py_type);
  14779. m.add_object("ROIPooling", reinterpret_cast<PyObject*>(&py_type));
  14780. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ROIPooling::typeinfo(), &py_type).second);
  14781. }
  14782. template<> struct EnumTrait<Reduce::Mode> {
  14783. static constexpr const char *name = "Reduce.Mode";
  14784. static constexpr std::underlying_type_t<Reduce::Mode> max = 6 - 1;
  14785. };
  14786. template<> PyTypeObject* EnumWrapper<Reduce::Mode>::type = nullptr;
  14787. template<> const char*
  14788. EnumWrapper<Reduce::Mode>::members[] = {"SUM", "SUM_SQR", "PRODUCT", "MIN", "MAX", "MEAN"};
  14789. template<> std::unordered_map<std::string, Reduce::Mode>
  14790. EnumWrapper<Reduce::Mode>::mem2value = {{normalize_enum("SUM"), Reduce::Mode::SUM}, {normalize_enum("SUM_SQR"), Reduce::Mode::SUM_SQR}, {normalize_enum("PRODUCT"), Reduce::Mode::PRODUCT}, {normalize_enum("MIN"), Reduce::Mode::MIN}, {normalize_enum("MAX"), Reduce::Mode::MAX}, {normalize_enum("MEAN"), Reduce::Mode::MEAN}};
  14791. template<> PyObject* EnumWrapper<Reduce::Mode>::pyobj_insts[6] = {nullptr};
  14792. void _init_py_Reduce_Mode(PyTypeObject& py_type) {
  14793. auto& e_type = EnumWrapper<Reduce::Mode>::type;
  14794. static PyMethodDef tp_methods[] = {
  14795. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Reduce::Mode>::py_dump, METH_NOARGS, NULL},
  14796. {NULL} /* Sentinel */
  14797. };
  14798. static PyType_Slot slots[] = {
  14799. {Py_tp_repr, (void*)EnumWrapper<Reduce::Mode>::py_repr},
  14800. {Py_tp_richcompare, (void*)EnumWrapper<Reduce::Mode>::tp_richcompare},
  14801. {Py_tp_methods, tp_methods},
  14802. {0, NULL}
  14803. };
  14804. static PyType_Spec spec = {
  14805. // name
  14806. "megengine.core._imperative_rt.ops.Reduce.Mode",
  14807. // basicsize
  14808. sizeof(EnumWrapper<Reduce::Mode>),
  14809. // itemsize
  14810. 0,
  14811. // flags
  14812. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  14813. // slots
  14814. slots
  14815. };
  14816. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  14817. mgb_assert(
  14818. e_type->tp_setattro(
  14819. reinterpret_cast<PyObject*>(e_type),
  14820. py::cast("__name__").release().ptr(),
  14821. py::cast("Mode").release().ptr()) >= 0);
  14822. mgb_assert(
  14823. e_type->tp_setattro(
  14824. reinterpret_cast<PyObject*>(e_type),
  14825. py::cast("__module__").release().ptr(),
  14826. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  14827. mgb_assert(
  14828. e_type->tp_setattro(
  14829. reinterpret_cast<PyObject*>(e_type),
  14830. py::cast("__qualname__").release().ptr(),
  14831. py::cast("Reduce.Mode").release().ptr()) >= 0);
  14832. {
  14833. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14834. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::SUM;
  14835. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SUM", inst) >= 0);
  14836. EnumWrapper<Reduce::Mode>::pyobj_insts[0] = inst;
  14837. }{
  14838. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14839. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::SUM_SQR;
  14840. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SUM_SQR", inst) >= 0);
  14841. EnumWrapper<Reduce::Mode>::pyobj_insts[1] = inst;
  14842. }{
  14843. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14844. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::PRODUCT;
  14845. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "PRODUCT", inst) >= 0);
  14846. EnumWrapper<Reduce::Mode>::pyobj_insts[2] = inst;
  14847. }{
  14848. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14849. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::MIN;
  14850. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MIN", inst) >= 0);
  14851. EnumWrapper<Reduce::Mode>::pyobj_insts[3] = inst;
  14852. }{
  14853. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14854. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::MAX;
  14855. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0);
  14856. EnumWrapper<Reduce::Mode>::pyobj_insts[4] = inst;
  14857. }{
  14858. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14859. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::MEAN;
  14860. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MEAN", inst) >= 0);
  14861. EnumWrapper<Reduce::Mode>::pyobj_insts[5] = inst;
  14862. }
  14863. Py_INCREF(e_type);
  14864. mgb_assert(PyDict_SetItemString(
  14865. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  14866. }
  14867. template<> struct EnumTrait<Reduce::DataType> {
  14868. static constexpr const char *name = "Reduce.DataType";
  14869. static constexpr std::underlying_type_t<Reduce::DataType> max = 6 - 1;
  14870. };
  14871. template<> PyTypeObject* EnumWrapper<Reduce::DataType>::type = nullptr;
  14872. template<> const char*
  14873. EnumWrapper<Reduce::DataType>::members[] = {"DEFAULT", "FLOAT_IO16xC32", "FLOAT_O32xC32", "FLOAT_O16xC32", "QUINT_I8xO32", "QINT_I8xO32"};
  14874. template<> std::unordered_map<std::string, Reduce::DataType>
  14875. EnumWrapper<Reduce::DataType>::mem2value = {{normalize_enum("DEFAULT"), Reduce::DataType::DEFAULT}, {normalize_enum("FLOAT_IO16xC32"), Reduce::DataType::FLOAT_IO16xC32}, {normalize_enum("FLOAT_O32xC32"), Reduce::DataType::FLOAT_O32xC32}, {normalize_enum("FLOAT_O16xC32"), Reduce::DataType::FLOAT_O16xC32}, {normalize_enum("QUINT_I8xO32"), Reduce::DataType::QUINT_I8xO32}, {normalize_enum("QINT_I8xO32"), Reduce::DataType::QINT_I8xO32}};
  14876. template<> PyObject* EnumWrapper<Reduce::DataType>::pyobj_insts[6] = {nullptr};
  14877. void _init_py_Reduce_DataType(PyTypeObject& py_type) {
  14878. auto& e_type = EnumWrapper<Reduce::DataType>::type;
  14879. static PyMethodDef tp_methods[] = {
  14880. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Reduce::DataType>::py_dump, METH_NOARGS, NULL},
  14881. {NULL} /* Sentinel */
  14882. };
  14883. static PyType_Slot slots[] = {
  14884. {Py_tp_repr, (void*)EnumWrapper<Reduce::DataType>::py_repr},
  14885. {Py_tp_richcompare, (void*)EnumWrapper<Reduce::DataType>::tp_richcompare},
  14886. {Py_tp_methods, tp_methods},
  14887. {0, NULL}
  14888. };
  14889. static PyType_Spec spec = {
  14890. // name
  14891. "megengine.core._imperative_rt.ops.Reduce.DataType",
  14892. // basicsize
  14893. sizeof(EnumWrapper<Reduce::DataType>),
  14894. // itemsize
  14895. 0,
  14896. // flags
  14897. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  14898. // slots
  14899. slots
  14900. };
  14901. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  14902. mgb_assert(
  14903. e_type->tp_setattro(
  14904. reinterpret_cast<PyObject*>(e_type),
  14905. py::cast("__name__").release().ptr(),
  14906. py::cast("DataType").release().ptr()) >= 0);
  14907. mgb_assert(
  14908. e_type->tp_setattro(
  14909. reinterpret_cast<PyObject*>(e_type),
  14910. py::cast("__module__").release().ptr(),
  14911. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  14912. mgb_assert(
  14913. e_type->tp_setattro(
  14914. reinterpret_cast<PyObject*>(e_type),
  14915. py::cast("__qualname__").release().ptr(),
  14916. py::cast("Reduce.DataType").release().ptr()) >= 0);
  14917. {
  14918. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14919. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::DEFAULT;
  14920. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DEFAULT", inst) >= 0);
  14921. EnumWrapper<Reduce::DataType>::pyobj_insts[0] = inst;
  14922. }{
  14923. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14924. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::FLOAT_IO16xC32;
  14925. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT_IO16xC32", inst) >= 0);
  14926. EnumWrapper<Reduce::DataType>::pyobj_insts[1] = inst;
  14927. }{
  14928. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14929. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::FLOAT_O32xC32;
  14930. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT_O32xC32", inst) >= 0);
  14931. EnumWrapper<Reduce::DataType>::pyobj_insts[2] = inst;
  14932. }{
  14933. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14934. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::FLOAT_O16xC32;
  14935. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT_O16xC32", inst) >= 0);
  14936. EnumWrapper<Reduce::DataType>::pyobj_insts[3] = inst;
  14937. }{
  14938. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14939. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::QUINT_I8xO32;
  14940. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QUINT_I8xO32", inst) >= 0);
  14941. EnumWrapper<Reduce::DataType>::pyobj_insts[4] = inst;
  14942. }{
  14943. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14944. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::QINT_I8xO32;
  14945. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QINT_I8xO32", inst) >= 0);
  14946. EnumWrapper<Reduce::DataType>::pyobj_insts[5] = inst;
  14947. }
  14948. Py_INCREF(e_type);
  14949. mgb_assert(PyDict_SetItemString(
  14950. py_type.tp_dict, "DataType", reinterpret_cast<PyObject*>(e_type)) >= 0);
  14951. }
  14952. PyOpDefBegin(Reduce) // {
  14953. static PyGetSetDef py_getsetters[];
  14954. static PyMethodDef tp_methods[];
  14955. static PyObject* getstate(PyObject* self, PyObject*) {
  14956. auto& opdef = reinterpret_cast<PyOp(Reduce)*>(self)->inst();
  14957. static_cast<void>(opdef);
  14958. std::unordered_map<std::string, py::object> state {
  14959. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  14960. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  14961. {"data_type", serialization<decltype(opdef.data_type)>::dump(opdef.data_type)},
  14962. {"keepdim", serialization<decltype(opdef.keepdim)>::dump(opdef.keepdim)}
  14963. };
  14964. return py::cast(state).release().ptr();
  14965. }
  14966. static PyObject* setstate(PyObject* self, PyObject* args) {
  14967. PyObject* dict = PyTuple_GetItem(args, 0);
  14968. if (!dict) return NULL;
  14969. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14970. auto& opdef = reinterpret_cast<PyOp(Reduce)*>(self)->inst();
  14971. static_cast<void>(opdef);
  14972. {
  14973. auto&& iter = state.find("mode");
  14974. if (iter != state.end()) {
  14975. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  14976. }
  14977. }
  14978. {
  14979. auto&& iter = state.find("axis");
  14980. if (iter != state.end()) {
  14981. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  14982. }
  14983. }
  14984. {
  14985. auto&& iter = state.find("data_type");
  14986. if (iter != state.end()) {
  14987. opdef.data_type = serialization<decltype(opdef.data_type)>::load(iter->second);
  14988. }
  14989. }
  14990. {
  14991. auto&& iter = state.find("keepdim");
  14992. if (iter != state.end()) {
  14993. opdef.keepdim = serialization<decltype(opdef.keepdim)>::load(iter->second);
  14994. }
  14995. }
  14996. Py_RETURN_NONE;
  14997. }
  14998. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14999. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  15000. static PyMethodDef py_init_methoddef;
  15001. // };
  15002. PyOpDefEnd(Reduce)
  15003. int PyOp(Reduce)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15004. static const char* kwlist[] = {"mode", "axis", "data_type", "keepdim", "scope", NULL};
  15005. PyObject *mode = NULL, *axis = NULL, *data_type = NULL, *keepdim = NULL, *scope = NULL;
  15006. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &mode, &axis, &data_type, &keepdim, &scope))
  15007. return -1;
  15008. if (mode) {
  15009. try {
  15010. // TODO: remove this guard which is used for pybind11 implicit conversion
  15011. py::detail::loader_life_support guard{};
  15012. reinterpret_cast<PyOp(Reduce)*>(self)->inst().mode =
  15013. py::cast<decltype(Reduce::mode)>(py::handle(mode));
  15014. } CATCH_ALL(-1)
  15015. }
  15016. if (axis) {
  15017. try {
  15018. // TODO: remove this guard which is used for pybind11 implicit conversion
  15019. py::detail::loader_life_support guard{};
  15020. reinterpret_cast<PyOp(Reduce)*>(self)->inst().axis =
  15021. py::cast<decltype(Reduce::axis)>(py::handle(axis));
  15022. } CATCH_ALL(-1)
  15023. }
  15024. if (data_type) {
  15025. try {
  15026. // TODO: remove this guard which is used for pybind11 implicit conversion
  15027. py::detail::loader_life_support guard{};
  15028. reinterpret_cast<PyOp(Reduce)*>(self)->inst().data_type =
  15029. py::cast<decltype(Reduce::data_type)>(py::handle(data_type));
  15030. } CATCH_ALL(-1)
  15031. }
  15032. if (keepdim) {
  15033. try {
  15034. // TODO: remove this guard which is used for pybind11 implicit conversion
  15035. py::detail::loader_life_support guard{};
  15036. reinterpret_cast<PyOp(Reduce)*>(self)->inst().keepdim =
  15037. py::cast<decltype(Reduce::keepdim)>(py::handle(keepdim));
  15038. } CATCH_ALL(-1)
  15039. }
  15040. if (scope) {
  15041. try {
  15042. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15043. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15044. } CATCH_ALL(-1)
  15045. }
  15046. return 0;
  15047. }
  15048. PyGetSetDef PyOp(Reduce)::py_getsetters[] = {
  15049. {const_cast<char*>("mode"), py_get_generic(Reduce, mode), py_set_generic(Reduce, mode), const_cast<char*>("mode"), NULL},
  15050. {const_cast<char*>("axis"), py_get_generic(Reduce, axis), py_set_generic(Reduce, axis), const_cast<char*>("axis"), NULL},
  15051. {const_cast<char*>("data_type"), py_get_generic(Reduce, data_type), py_set_generic(Reduce, data_type), const_cast<char*>("data_type"), NULL},
  15052. {const_cast<char*>("keepdim"), py_get_generic(Reduce, keepdim), py_set_generic(Reduce, keepdim), const_cast<char*>("keepdim"), NULL},
  15053. {NULL} /* Sentinel */
  15054. };
  15055. PyMethodDef PyOp(Reduce)::tp_methods[] = {
  15056. {const_cast<char*>("__getstate__"), PyOp(Reduce)::getstate, METH_NOARGS, "Reduce getstate"},
  15057. {const_cast<char*>("__setstate__"), PyOp(Reduce)::setstate, METH_VARARGS, "Reduce setstate"},
  15058. {NULL} /* Sentinel */
  15059. };
  15060. PyObject *PyOp(Reduce)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  15061. if (PyOp(Reduce)::py_init(self, args, kwds) < 0) {
  15062. return NULL;
  15063. }
  15064. Py_RETURN_NONE;
  15065. }
  15066. PyMethodDef PyOp(Reduce)::py_init_methoddef = {
  15067. "__init__",
  15068. (PyCFunction)PyOp(Reduce)::py_init_proxy,
  15069. METH_VARARGS | METH_KEYWORDS,
  15070. "__init__(self, mode: Union[str, Mode] = ..., axis: int = ..., data_type: Union[str, DataType] = ..., keepdim: bool = ...) -> None\n"
  15071. };
  15072. void _init_py_Reduce(py::module m) {
  15073. using py_op = PyOp(Reduce);
  15074. auto& py_type = PyOpType(Reduce);
  15075. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15076. py_type.tp_name = "megengine.core._imperative_rt.ops.Reduce";
  15077. py_type.tp_basicsize = sizeof(PyOp(Reduce));
  15078. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15079. py_type.tp_doc = "Reduce";
  15080. py_type.tp_base = &PyOpType(OpDef);
  15081. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15082. py_type.tp_new = py_new_generic<py_op>;
  15083. py_type.tp_init = py_op::py_init;
  15084. py_type.tp_methods = py_op::tp_methods;
  15085. py_type.tp_getset = py_op::py_getsetters;
  15086. py_type.tp_dict = PyDict_New();
  15087. PyObject* descr = PyDescr_NewMethod(&PyOpType(Reduce), &PyOp(Reduce)::py_init_methoddef);
  15088. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  15089. mgb_assert(PyType_Ready(&py_type) >= 0);
  15090. _init_py_Reduce_Mode(py_type);
  15091. _init_py_Reduce_DataType(py_type);
  15092. PyType_Modified(&py_type);
  15093. m.add_object("Reduce", reinterpret_cast<PyObject*>(&py_type));
  15094. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Reduce::typeinfo(), &py_type).second);
  15095. }
  15096. void _init_py_RegionRestrictedConvolution_Mode(PyTypeObject& py_type) {
  15097. auto& e_type = EnumWrapper<RegionRestrictedConvolution::Mode>::type;
  15098. Py_INCREF(e_type);
  15099. mgb_assert(PyDict_SetItemString(
  15100. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  15101. }
  15102. void _init_py_RegionRestrictedConvolution_Sparse(PyTypeObject& py_type) {
  15103. auto& e_type = EnumWrapper<RegionRestrictedConvolution::Sparse>::type;
  15104. Py_INCREF(e_type);
  15105. mgb_assert(PyDict_SetItemString(
  15106. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  15107. }
  15108. void _init_py_RegionRestrictedConvolution_Format(PyTypeObject& py_type) {
  15109. auto& e_type = EnumWrapper<RegionRestrictedConvolution::Format>::type;
  15110. Py_INCREF(e_type);
  15111. mgb_assert(PyDict_SetItemString(
  15112. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  15113. }
  15114. void _init_py_RegionRestrictedConvolution_ComputeMode(PyTypeObject& py_type) {
  15115. auto& e_type = EnumWrapper<RegionRestrictedConvolution::ComputeMode>::type;
  15116. Py_INCREF(e_type);
  15117. mgb_assert(PyDict_SetItemString(
  15118. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  15119. }
  15120. PyOpDefBegin(RegionRestrictedConvolution) // {
  15121. static PyGetSetDef py_getsetters[];
  15122. static PyMethodDef tp_methods[];
  15123. static PyObject* getstate(PyObject* self, PyObject*) {
  15124. auto& opdef = reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst();
  15125. static_cast<void>(opdef);
  15126. std::unordered_map<std::string, py::object> state {
  15127. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  15128. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  15129. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  15130. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  15131. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  15132. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  15133. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  15134. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  15135. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  15136. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)}
  15137. };
  15138. return py::cast(state).release().ptr();
  15139. }
  15140. static PyObject* setstate(PyObject* self, PyObject* args) {
  15141. PyObject* dict = PyTuple_GetItem(args, 0);
  15142. if (!dict) return NULL;
  15143. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15144. auto& opdef = reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst();
  15145. static_cast<void>(opdef);
  15146. {
  15147. auto&& iter = state.find("mode");
  15148. if (iter != state.end()) {
  15149. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  15150. }
  15151. }
  15152. {
  15153. auto&& iter = state.find("pad_h");
  15154. if (iter != state.end()) {
  15155. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  15156. }
  15157. }
  15158. {
  15159. auto&& iter = state.find("pad_w");
  15160. if (iter != state.end()) {
  15161. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  15162. }
  15163. }
  15164. {
  15165. auto&& iter = state.find("stride_h");
  15166. if (iter != state.end()) {
  15167. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  15168. }
  15169. }
  15170. {
  15171. auto&& iter = state.find("stride_w");
  15172. if (iter != state.end()) {
  15173. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  15174. }
  15175. }
  15176. {
  15177. auto&& iter = state.find("dilate_h");
  15178. if (iter != state.end()) {
  15179. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  15180. }
  15181. }
  15182. {
  15183. auto&& iter = state.find("dilate_w");
  15184. if (iter != state.end()) {
  15185. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  15186. }
  15187. }
  15188. {
  15189. auto&& iter = state.find("sparse");
  15190. if (iter != state.end()) {
  15191. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  15192. }
  15193. }
  15194. {
  15195. auto&& iter = state.find("format");
  15196. if (iter != state.end()) {
  15197. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  15198. }
  15199. }
  15200. {
  15201. auto&& iter = state.find("compute_mode");
  15202. if (iter != state.end()) {
  15203. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  15204. }
  15205. }
  15206. Py_RETURN_NONE;
  15207. }
  15208. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15209. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  15210. static PyMethodDef py_init_methoddef;
  15211. // };
  15212. PyOpDefEnd(RegionRestrictedConvolution)
  15213. int PyOp(RegionRestrictedConvolution)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15214. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "scope", NULL};
  15215. PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *scope = NULL;
  15216. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &scope))
  15217. return -1;
  15218. if (mode) {
  15219. try {
  15220. // TODO: remove this guard which is used for pybind11 implicit conversion
  15221. py::detail::loader_life_support guard{};
  15222. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().mode =
  15223. py::cast<decltype(RegionRestrictedConvolution::mode)>(py::handle(mode));
  15224. } CATCH_ALL(-1)
  15225. }
  15226. if (pad_h) {
  15227. try {
  15228. // TODO: remove this guard which is used for pybind11 implicit conversion
  15229. py::detail::loader_life_support guard{};
  15230. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().pad_h =
  15231. py::cast<decltype(RegionRestrictedConvolution::pad_h)>(py::handle(pad_h));
  15232. } CATCH_ALL(-1)
  15233. }
  15234. if (pad_w) {
  15235. try {
  15236. // TODO: remove this guard which is used for pybind11 implicit conversion
  15237. py::detail::loader_life_support guard{};
  15238. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().pad_w =
  15239. py::cast<decltype(RegionRestrictedConvolution::pad_w)>(py::handle(pad_w));
  15240. } CATCH_ALL(-1)
  15241. }
  15242. if (stride_h) {
  15243. try {
  15244. // TODO: remove this guard which is used for pybind11 implicit conversion
  15245. py::detail::loader_life_support guard{};
  15246. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().stride_h =
  15247. py::cast<decltype(RegionRestrictedConvolution::stride_h)>(py::handle(stride_h));
  15248. } CATCH_ALL(-1)
  15249. }
  15250. if (stride_w) {
  15251. try {
  15252. // TODO: remove this guard which is used for pybind11 implicit conversion
  15253. py::detail::loader_life_support guard{};
  15254. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().stride_w =
  15255. py::cast<decltype(RegionRestrictedConvolution::stride_w)>(py::handle(stride_w));
  15256. } CATCH_ALL(-1)
  15257. }
  15258. if (dilate_h) {
  15259. try {
  15260. // TODO: remove this guard which is used for pybind11 implicit conversion
  15261. py::detail::loader_life_support guard{};
  15262. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().dilate_h =
  15263. py::cast<decltype(RegionRestrictedConvolution::dilate_h)>(py::handle(dilate_h));
  15264. } CATCH_ALL(-1)
  15265. }
  15266. if (dilate_w) {
  15267. try {
  15268. // TODO: remove this guard which is used for pybind11 implicit conversion
  15269. py::detail::loader_life_support guard{};
  15270. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().dilate_w =
  15271. py::cast<decltype(RegionRestrictedConvolution::dilate_w)>(py::handle(dilate_w));
  15272. } CATCH_ALL(-1)
  15273. }
  15274. if (sparse) {
  15275. try {
  15276. // TODO: remove this guard which is used for pybind11 implicit conversion
  15277. py::detail::loader_life_support guard{};
  15278. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().sparse =
  15279. py::cast<decltype(RegionRestrictedConvolution::sparse)>(py::handle(sparse));
  15280. } CATCH_ALL(-1)
  15281. }
  15282. if (format) {
  15283. try {
  15284. // TODO: remove this guard which is used for pybind11 implicit conversion
  15285. py::detail::loader_life_support guard{};
  15286. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().format =
  15287. py::cast<decltype(RegionRestrictedConvolution::format)>(py::handle(format));
  15288. } CATCH_ALL(-1)
  15289. }
  15290. if (compute_mode) {
  15291. try {
  15292. // TODO: remove this guard which is used for pybind11 implicit conversion
  15293. py::detail::loader_life_support guard{};
  15294. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().compute_mode =
  15295. py::cast<decltype(RegionRestrictedConvolution::compute_mode)>(py::handle(compute_mode));
  15296. } CATCH_ALL(-1)
  15297. }
  15298. if (scope) {
  15299. try {
  15300. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15301. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15302. } CATCH_ALL(-1)
  15303. }
  15304. return 0;
  15305. }
  15306. PyGetSetDef PyOp(RegionRestrictedConvolution)::py_getsetters[] = {
  15307. {const_cast<char*>("mode"), py_get_generic(RegionRestrictedConvolution, mode), py_set_generic(RegionRestrictedConvolution, mode), const_cast<char*>("mode"), NULL},
  15308. {const_cast<char*>("pad_h"), py_get_generic(RegionRestrictedConvolution, pad_h), py_set_generic(RegionRestrictedConvolution, pad_h), const_cast<char*>("pad_h"), NULL},
  15309. {const_cast<char*>("pad_w"), py_get_generic(RegionRestrictedConvolution, pad_w), py_set_generic(RegionRestrictedConvolution, pad_w), const_cast<char*>("pad_w"), NULL},
  15310. {const_cast<char*>("stride_h"), py_get_generic(RegionRestrictedConvolution, stride_h), py_set_generic(RegionRestrictedConvolution, stride_h), const_cast<char*>("stride_h"), NULL},
  15311. {const_cast<char*>("stride_w"), py_get_generic(RegionRestrictedConvolution, stride_w), py_set_generic(RegionRestrictedConvolution, stride_w), const_cast<char*>("stride_w"), NULL},
  15312. {const_cast<char*>("dilate_h"), py_get_generic(RegionRestrictedConvolution, dilate_h), py_set_generic(RegionRestrictedConvolution, dilate_h), const_cast<char*>("dilate_h"), NULL},
  15313. {const_cast<char*>("dilate_w"), py_get_generic(RegionRestrictedConvolution, dilate_w), py_set_generic(RegionRestrictedConvolution, dilate_w), const_cast<char*>("dilate_w"), NULL},
  15314. {const_cast<char*>("sparse"), py_get_generic(RegionRestrictedConvolution, sparse), py_set_generic(RegionRestrictedConvolution, sparse), const_cast<char*>("sparse"), NULL},
  15315. {const_cast<char*>("format"), py_get_generic(RegionRestrictedConvolution, format), py_set_generic(RegionRestrictedConvolution, format), const_cast<char*>("format"), NULL},
  15316. {const_cast<char*>("compute_mode"), py_get_generic(RegionRestrictedConvolution, compute_mode), py_set_generic(RegionRestrictedConvolution, compute_mode), const_cast<char*>("compute_mode"), NULL},
  15317. {NULL} /* Sentinel */
  15318. };
  15319. PyMethodDef PyOp(RegionRestrictedConvolution)::tp_methods[] = {
  15320. {const_cast<char*>("__getstate__"), PyOp(RegionRestrictedConvolution)::getstate, METH_NOARGS, "RegionRestrictedConvolution getstate"},
  15321. {const_cast<char*>("__setstate__"), PyOp(RegionRestrictedConvolution)::setstate, METH_VARARGS, "RegionRestrictedConvolution setstate"},
  15322. {NULL} /* Sentinel */
  15323. };
  15324. PyObject *PyOp(RegionRestrictedConvolution)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  15325. if (PyOp(RegionRestrictedConvolution)::py_init(self, args, kwds) < 0) {
  15326. return NULL;
  15327. }
  15328. Py_RETURN_NONE;
  15329. }
  15330. PyMethodDef PyOp(RegionRestrictedConvolution)::py_init_methoddef = {
  15331. "__init__",
  15332. (PyCFunction)PyOp(RegionRestrictedConvolution)::py_init_proxy,
  15333. METH_VARARGS | METH_KEYWORDS,
  15334. "__init__(self, mode: Union[str, Mode] = ..., pad_h: int = ..., pad_w: int = ..., stride_h: int = ..., stride_w: int = ..., dilate_h: int = ..., dilate_w: int = ..., sparse: Union[str, Sparse] = ..., format: Union[str, Format] = ..., compute_mode: Union[str, ComputeMode] = ...) -> None\n"
  15335. };
  15336. void _init_py_RegionRestrictedConvolution(py::module m) {
  15337. using py_op = PyOp(RegionRestrictedConvolution);
  15338. auto& py_type = PyOpType(RegionRestrictedConvolution);
  15339. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15340. py_type.tp_name = "megengine.core._imperative_rt.ops.RegionRestrictedConvolution";
  15341. py_type.tp_basicsize = sizeof(PyOp(RegionRestrictedConvolution));
  15342. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15343. py_type.tp_doc = "RegionRestrictedConvolution";
  15344. py_type.tp_base = &PyOpType(OpDef);
  15345. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15346. py_type.tp_new = py_new_generic<py_op>;
  15347. py_type.tp_init = py_op::py_init;
  15348. py_type.tp_methods = py_op::tp_methods;
  15349. py_type.tp_getset = py_op::py_getsetters;
  15350. py_type.tp_dict = PyDict_New();
  15351. PyObject* descr = PyDescr_NewMethod(&PyOpType(RegionRestrictedConvolution), &PyOp(RegionRestrictedConvolution)::py_init_methoddef);
  15352. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  15353. mgb_assert(PyType_Ready(&py_type) >= 0);
  15354. _init_py_RegionRestrictedConvolution_Mode(py_type);
  15355. _init_py_RegionRestrictedConvolution_Sparse(py_type);
  15356. _init_py_RegionRestrictedConvolution_Format(py_type);
  15357. _init_py_RegionRestrictedConvolution_ComputeMode(py_type);
  15358. PyType_Modified(&py_type);
  15359. m.add_object("RegionRestrictedConvolution", reinterpret_cast<PyObject*>(&py_type));
  15360. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RegionRestrictedConvolution::typeinfo(), &py_type).second);
  15361. }
  15362. void _init_py_RegionRestrictedConvolutionBackwardData_Mode(PyTypeObject& py_type) {
  15363. auto& e_type = EnumWrapper<RegionRestrictedConvolutionBackwardData::Mode>::type;
  15364. Py_INCREF(e_type);
  15365. mgb_assert(PyDict_SetItemString(
  15366. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  15367. }
  15368. void _init_py_RegionRestrictedConvolutionBackwardData_Sparse(PyTypeObject& py_type) {
  15369. auto& e_type = EnumWrapper<RegionRestrictedConvolutionBackwardData::Sparse>::type;
  15370. Py_INCREF(e_type);
  15371. mgb_assert(PyDict_SetItemString(
  15372. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  15373. }
  15374. void _init_py_RegionRestrictedConvolutionBackwardData_Format(PyTypeObject& py_type) {
  15375. auto& e_type = EnumWrapper<RegionRestrictedConvolutionBackwardData::Format>::type;
  15376. Py_INCREF(e_type);
  15377. mgb_assert(PyDict_SetItemString(
  15378. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  15379. }
  15380. void _init_py_RegionRestrictedConvolutionBackwardData_ComputeMode(PyTypeObject& py_type) {
  15381. auto& e_type = EnumWrapper<RegionRestrictedConvolutionBackwardData::ComputeMode>::type;
  15382. Py_INCREF(e_type);
  15383. mgb_assert(PyDict_SetItemString(
  15384. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  15385. }
  15386. PyOpDefBegin(RegionRestrictedConvolutionBackwardData) // {
  15387. static PyGetSetDef py_getsetters[];
  15388. static PyMethodDef tp_methods[];
  15389. static PyObject* getstate(PyObject* self, PyObject*) {
  15390. auto& opdef = reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst();
  15391. static_cast<void>(opdef);
  15392. std::unordered_map<std::string, py::object> state {
  15393. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  15394. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  15395. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  15396. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  15397. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  15398. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  15399. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  15400. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  15401. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  15402. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)}
  15403. };
  15404. return py::cast(state).release().ptr();
  15405. }
  15406. static PyObject* setstate(PyObject* self, PyObject* args) {
  15407. PyObject* dict = PyTuple_GetItem(args, 0);
  15408. if (!dict) return NULL;
  15409. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15410. auto& opdef = reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst();
  15411. static_cast<void>(opdef);
  15412. {
  15413. auto&& iter = state.find("mode");
  15414. if (iter != state.end()) {
  15415. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  15416. }
  15417. }
  15418. {
  15419. auto&& iter = state.find("pad_h");
  15420. if (iter != state.end()) {
  15421. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  15422. }
  15423. }
  15424. {
  15425. auto&& iter = state.find("pad_w");
  15426. if (iter != state.end()) {
  15427. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  15428. }
  15429. }
  15430. {
  15431. auto&& iter = state.find("stride_h");
  15432. if (iter != state.end()) {
  15433. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  15434. }
  15435. }
  15436. {
  15437. auto&& iter = state.find("stride_w");
  15438. if (iter != state.end()) {
  15439. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  15440. }
  15441. }
  15442. {
  15443. auto&& iter = state.find("dilate_h");
  15444. if (iter != state.end()) {
  15445. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  15446. }
  15447. }
  15448. {
  15449. auto&& iter = state.find("dilate_w");
  15450. if (iter != state.end()) {
  15451. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  15452. }
  15453. }
  15454. {
  15455. auto&& iter = state.find("sparse");
  15456. if (iter != state.end()) {
  15457. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  15458. }
  15459. }
  15460. {
  15461. auto&& iter = state.find("format");
  15462. if (iter != state.end()) {
  15463. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  15464. }
  15465. }
  15466. {
  15467. auto&& iter = state.find("compute_mode");
  15468. if (iter != state.end()) {
  15469. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  15470. }
  15471. }
  15472. Py_RETURN_NONE;
  15473. }
  15474. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15475. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  15476. static PyMethodDef py_init_methoddef;
  15477. // };
  15478. PyOpDefEnd(RegionRestrictedConvolutionBackwardData)
  15479. int PyOp(RegionRestrictedConvolutionBackwardData)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15480. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "scope", NULL};
  15481. PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *scope = NULL;
  15482. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &scope))
  15483. return -1;
  15484. if (mode) {
  15485. try {
  15486. // TODO: remove this guard which is used for pybind11 implicit conversion
  15487. py::detail::loader_life_support guard{};
  15488. reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst().mode =
  15489. py::cast<decltype(RegionRestrictedConvolutionBackwardData::mode)>(py::handle(mode));
  15490. } CATCH_ALL(-1)
  15491. }
  15492. if (pad_h) {
  15493. try {
  15494. // TODO: remove this guard which is used for pybind11 implicit conversion
  15495. py::detail::loader_life_support guard{};
  15496. reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst().pad_h =
  15497. py::cast<decltype(RegionRestrictedConvolutionBackwardData::pad_h)>(py::handle(pad_h));
  15498. } CATCH_ALL(-1)
  15499. }
  15500. if (pad_w) {
  15501. try {
  15502. // TODO: remove this guard which is used for pybind11 implicit conversion
  15503. py::detail::loader_life_support guard{};
  15504. reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst().pad_w =
  15505. py::cast<decltype(RegionRestrictedConvolutionBackwardData::pad_w)>(py::handle(pad_w));
  15506. } CATCH_ALL(-1)
  15507. }
  15508. if (stride_h) {
  15509. try {
  15510. // TODO: remove this guard which is used for pybind11 implicit conversion
  15511. py::detail::loader_life_support guard{};
  15512. reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst().stride_h =
  15513. py::cast<decltype(RegionRestrictedConvolutionBackwardData::stride_h)>(py::handle(stride_h));
  15514. } CATCH_ALL(-1)
  15515. }
  15516. if (stride_w) {
  15517. try {
  15518. // TODO: remove this guard which is used for pybind11 implicit conversion
  15519. py::detail::loader_life_support guard{};
  15520. reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst().stride_w =
  15521. py::cast<decltype(RegionRestrictedConvolutionBackwardData::stride_w)>(py::handle(stride_w));
  15522. } CATCH_ALL(-1)
  15523. }
  15524. if (dilate_h) {
  15525. try {
  15526. // TODO: remove this guard which is used for pybind11 implicit conversion
  15527. py::detail::loader_life_support guard{};
  15528. reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst().dilate_h =
  15529. py::cast<decltype(RegionRestrictedConvolutionBackwardData::dilate_h)>(py::handle(dilate_h));
  15530. } CATCH_ALL(-1)
  15531. }
  15532. if (dilate_w) {
  15533. try {
  15534. // TODO: remove this guard which is used for pybind11 implicit conversion
  15535. py::detail::loader_life_support guard{};
  15536. reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst().dilate_w =
  15537. py::cast<decltype(RegionRestrictedConvolutionBackwardData::dilate_w)>(py::handle(dilate_w));
  15538. } CATCH_ALL(-1)
  15539. }
  15540. if (sparse) {
  15541. try {
  15542. // TODO: remove this guard which is used for pybind11 implicit conversion
  15543. py::detail::loader_life_support guard{};
  15544. reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst().sparse =
  15545. py::cast<decltype(RegionRestrictedConvolutionBackwardData::sparse)>(py::handle(sparse));
  15546. } CATCH_ALL(-1)
  15547. }
  15548. if (format) {
  15549. try {
  15550. // TODO: remove this guard which is used for pybind11 implicit conversion
  15551. py::detail::loader_life_support guard{};
  15552. reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst().format =
  15553. py::cast<decltype(RegionRestrictedConvolutionBackwardData::format)>(py::handle(format));
  15554. } CATCH_ALL(-1)
  15555. }
  15556. if (compute_mode) {
  15557. try {
  15558. // TODO: remove this guard which is used for pybind11 implicit conversion
  15559. py::detail::loader_life_support guard{};
  15560. reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst().compute_mode =
  15561. py::cast<decltype(RegionRestrictedConvolutionBackwardData::compute_mode)>(py::handle(compute_mode));
  15562. } CATCH_ALL(-1)
  15563. }
  15564. if (scope) {
  15565. try {
  15566. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15567. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15568. } CATCH_ALL(-1)
  15569. }
  15570. return 0;
  15571. }
  15572. PyGetSetDef PyOp(RegionRestrictedConvolutionBackwardData)::py_getsetters[] = {
  15573. {const_cast<char*>("mode"), py_get_generic(RegionRestrictedConvolutionBackwardData, mode), py_set_generic(RegionRestrictedConvolutionBackwardData, mode), const_cast<char*>("mode"), NULL},
  15574. {const_cast<char*>("pad_h"), py_get_generic(RegionRestrictedConvolutionBackwardData, pad_h), py_set_generic(RegionRestrictedConvolutionBackwardData, pad_h), const_cast<char*>("pad_h"), NULL},
  15575. {const_cast<char*>("pad_w"), py_get_generic(RegionRestrictedConvolutionBackwardData, pad_w), py_set_generic(RegionRestrictedConvolutionBackwardData, pad_w), const_cast<char*>("pad_w"), NULL},
  15576. {const_cast<char*>("stride_h"), py_get_generic(RegionRestrictedConvolutionBackwardData, stride_h), py_set_generic(RegionRestrictedConvolutionBackwardData, stride_h), const_cast<char*>("stride_h"), NULL},
  15577. {const_cast<char*>("stride_w"), py_get_generic(RegionRestrictedConvolutionBackwardData, stride_w), py_set_generic(RegionRestrictedConvolutionBackwardData, stride_w), const_cast<char*>("stride_w"), NULL},
  15578. {const_cast<char*>("dilate_h"), py_get_generic(RegionRestrictedConvolutionBackwardData, dilate_h), py_set_generic(RegionRestrictedConvolutionBackwardData, dilate_h), const_cast<char*>("dilate_h"), NULL},
  15579. {const_cast<char*>("dilate_w"), py_get_generic(RegionRestrictedConvolutionBackwardData, dilate_w), py_set_generic(RegionRestrictedConvolutionBackwardData, dilate_w), const_cast<char*>("dilate_w"), NULL},
  15580. {const_cast<char*>("sparse"), py_get_generic(RegionRestrictedConvolutionBackwardData, sparse), py_set_generic(RegionRestrictedConvolutionBackwardData, sparse), const_cast<char*>("sparse"), NULL},
  15581. {const_cast<char*>("format"), py_get_generic(RegionRestrictedConvolutionBackwardData, format), py_set_generic(RegionRestrictedConvolutionBackwardData, format), const_cast<char*>("format"), NULL},
  15582. {const_cast<char*>("compute_mode"), py_get_generic(RegionRestrictedConvolutionBackwardData, compute_mode), py_set_generic(RegionRestrictedConvolutionBackwardData, compute_mode), const_cast<char*>("compute_mode"), NULL},
  15583. {NULL} /* Sentinel */
  15584. };
  15585. PyMethodDef PyOp(RegionRestrictedConvolutionBackwardData)::tp_methods[] = {
  15586. {const_cast<char*>("__getstate__"), PyOp(RegionRestrictedConvolutionBackwardData)::getstate, METH_NOARGS, "RegionRestrictedConvolutionBackwardData getstate"},
  15587. {const_cast<char*>("__setstate__"), PyOp(RegionRestrictedConvolutionBackwardData)::setstate, METH_VARARGS, "RegionRestrictedConvolutionBackwardData setstate"},
  15588. {NULL} /* Sentinel */
  15589. };
  15590. PyObject *PyOp(RegionRestrictedConvolutionBackwardData)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  15591. if (PyOp(RegionRestrictedConvolutionBackwardData)::py_init(self, args, kwds) < 0) {
  15592. return NULL;
  15593. }
  15594. Py_RETURN_NONE;
  15595. }
  15596. PyMethodDef PyOp(RegionRestrictedConvolutionBackwardData)::py_init_methoddef = {
  15597. "__init__",
  15598. (PyCFunction)PyOp(RegionRestrictedConvolutionBackwardData)::py_init_proxy,
  15599. METH_VARARGS | METH_KEYWORDS,
  15600. "__init__(self, mode: Union[str, Mode] = ..., pad_h: int = ..., pad_w: int = ..., stride_h: int = ..., stride_w: int = ..., dilate_h: int = ..., dilate_w: int = ..., sparse: Union[str, Sparse] = ..., format: Union[str, Format] = ..., compute_mode: Union[str, ComputeMode] = ...) -> None\n"
  15601. };
  15602. void _init_py_RegionRestrictedConvolutionBackwardData(py::module m) {
  15603. using py_op = PyOp(RegionRestrictedConvolutionBackwardData);
  15604. auto& py_type = PyOpType(RegionRestrictedConvolutionBackwardData);
  15605. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15606. py_type.tp_name = "megengine.core._imperative_rt.ops.RegionRestrictedConvolutionBackwardData";
  15607. py_type.tp_basicsize = sizeof(PyOp(RegionRestrictedConvolutionBackwardData));
  15608. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15609. py_type.tp_doc = "RegionRestrictedConvolutionBackwardData";
  15610. py_type.tp_base = &PyOpType(OpDef);
  15611. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15612. py_type.tp_new = py_new_generic<py_op>;
  15613. py_type.tp_init = py_op::py_init;
  15614. py_type.tp_methods = py_op::tp_methods;
  15615. py_type.tp_getset = py_op::py_getsetters;
  15616. py_type.tp_dict = PyDict_New();
  15617. PyObject* descr = PyDescr_NewMethod(&PyOpType(RegionRestrictedConvolutionBackwardData), &PyOp(RegionRestrictedConvolutionBackwardData)::py_init_methoddef);
  15618. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  15619. mgb_assert(PyType_Ready(&py_type) >= 0);
  15620. _init_py_RegionRestrictedConvolutionBackwardData_Mode(py_type);
  15621. _init_py_RegionRestrictedConvolutionBackwardData_Sparse(py_type);
  15622. _init_py_RegionRestrictedConvolutionBackwardData_Format(py_type);
  15623. _init_py_RegionRestrictedConvolutionBackwardData_ComputeMode(py_type);
  15624. PyType_Modified(&py_type);
  15625. m.add_object("RegionRestrictedConvolutionBackwardData", reinterpret_cast<PyObject*>(&py_type));
  15626. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RegionRestrictedConvolutionBackwardData::typeinfo(), &py_type).second);
  15627. }
  15628. template<> struct EnumTrait<Remap::InterpolationMode> {
  15629. static constexpr const char *name = "Remap.InterpolationMode";
  15630. static constexpr std::underlying_type_t<Remap::InterpolationMode> max = 5 - 1;
  15631. };
  15632. template<> PyTypeObject* EnumWrapper<Remap::InterpolationMode>::type = nullptr;
  15633. template<> const char*
  15634. EnumWrapper<Remap::InterpolationMode>::members[] = {"NEAREST", "LINEAR", "AREA", "CUBIC", "LANCZOS4"};
  15635. template<> std::unordered_map<std::string, Remap::InterpolationMode>
  15636. EnumWrapper<Remap::InterpolationMode>::mem2value = {{normalize_enum("NEAREST"), Remap::InterpolationMode::NEAREST}, {normalize_enum("LINEAR"), Remap::InterpolationMode::LINEAR}, {normalize_enum("AREA"), Remap::InterpolationMode::AREA}, {normalize_enum("CUBIC"), Remap::InterpolationMode::CUBIC}, {normalize_enum("LANCZOS4"), Remap::InterpolationMode::LANCZOS4}};
  15637. template<> PyObject* EnumWrapper<Remap::InterpolationMode>::pyobj_insts[5] = {nullptr};
  15638. void _init_py_Remap_InterpolationMode(PyTypeObject& py_type) {
  15639. auto& e_type = EnumWrapper<Remap::InterpolationMode>::type;
  15640. static PyMethodDef tp_methods[] = {
  15641. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Remap::InterpolationMode>::py_dump, METH_NOARGS, NULL},
  15642. {NULL} /* Sentinel */
  15643. };
  15644. static PyType_Slot slots[] = {
  15645. {Py_tp_repr, (void*)EnumWrapper<Remap::InterpolationMode>::py_repr},
  15646. {Py_tp_richcompare, (void*)EnumWrapper<Remap::InterpolationMode>::tp_richcompare},
  15647. {Py_tp_methods, tp_methods},
  15648. {0, NULL}
  15649. };
  15650. static PyType_Spec spec = {
  15651. // name
  15652. "megengine.core._imperative_rt.ops.Remap.InterpolationMode",
  15653. // basicsize
  15654. sizeof(EnumWrapper<Remap::InterpolationMode>),
  15655. // itemsize
  15656. 0,
  15657. // flags
  15658. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  15659. // slots
  15660. slots
  15661. };
  15662. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  15663. mgb_assert(
  15664. e_type->tp_setattro(
  15665. reinterpret_cast<PyObject*>(e_type),
  15666. py::cast("__name__").release().ptr(),
  15667. py::cast("InterpolationMode").release().ptr()) >= 0);
  15668. mgb_assert(
  15669. e_type->tp_setattro(
  15670. reinterpret_cast<PyObject*>(e_type),
  15671. py::cast("__module__").release().ptr(),
  15672. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  15673. mgb_assert(
  15674. e_type->tp_setattro(
  15675. reinterpret_cast<PyObject*>(e_type),
  15676. py::cast("__qualname__").release().ptr(),
  15677. py::cast("Remap.InterpolationMode").release().ptr()) >= 0);
  15678. {
  15679. PyObject* inst = e_type->tp_alloc(e_type, 0);
  15680. reinterpret_cast<EnumWrapper<Remap::InterpolationMode>*>(inst)->value = Remap::InterpolationMode::NEAREST;
  15681. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NEAREST", inst) >= 0);
  15682. EnumWrapper<Remap::InterpolationMode>::pyobj_insts[0] = inst;
  15683. }{
  15684. PyObject* inst = e_type->tp_alloc(e_type, 0);
  15685. reinterpret_cast<EnumWrapper<Remap::InterpolationMode>*>(inst)->value = Remap::InterpolationMode::LINEAR;
  15686. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LINEAR", inst) >= 0);
  15687. EnumWrapper<Remap::InterpolationMode>::pyobj_insts[1] = inst;
  15688. }{
  15689. PyObject* inst = e_type->tp_alloc(e_type, 0);
  15690. reinterpret_cast<EnumWrapper<Remap::InterpolationMode>*>(inst)->value = Remap::InterpolationMode::AREA;
  15691. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AREA", inst) >= 0);
  15692. EnumWrapper<Remap::InterpolationMode>::pyobj_insts[2] = inst;
  15693. }{
  15694. PyObject* inst = e_type->tp_alloc(e_type, 0);
  15695. reinterpret_cast<EnumWrapper<Remap::InterpolationMode>*>(inst)->value = Remap::InterpolationMode::CUBIC;
  15696. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CUBIC", inst) >= 0);
  15697. EnumWrapper<Remap::InterpolationMode>::pyobj_insts[3] = inst;
  15698. }{
  15699. PyObject* inst = e_type->tp_alloc(e_type, 0);
  15700. reinterpret_cast<EnumWrapper<Remap::InterpolationMode>*>(inst)->value = Remap::InterpolationMode::LANCZOS4;
  15701. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LANCZOS4", inst) >= 0);
  15702. EnumWrapper<Remap::InterpolationMode>::pyobj_insts[4] = inst;
  15703. }
  15704. Py_INCREF(e_type);
  15705. mgb_assert(PyDict_SetItemString(
  15706. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  15707. }
  15708. template<> struct EnumTrait<Remap::BorderMode> {
  15709. static constexpr const char *name = "Remap.BorderMode";
  15710. static constexpr std::underlying_type_t<Remap::BorderMode> max = 7 - 1;
  15711. };
  15712. template<> PyTypeObject* EnumWrapper<Remap::BorderMode>::type = nullptr;
  15713. template<> const char*
  15714. EnumWrapper<Remap::BorderMode>::members[] = {"REPLICATE", "REFLECT", "REFLECT_101", "WRAP", "CONSTANT", "TRANSPARENT", "ISOLATED"};
  15715. template<> std::unordered_map<std::string, Remap::BorderMode>
  15716. EnumWrapper<Remap::BorderMode>::mem2value = {{normalize_enum("REPLICATE"), Remap::BorderMode::REPLICATE}, {normalize_enum("REFLECT"), Remap::BorderMode::REFLECT}, {normalize_enum("REFLECT_101"), Remap::BorderMode::REFLECT_101}, {normalize_enum("WRAP"), Remap::BorderMode::WRAP}, {normalize_enum("CONSTANT"), Remap::BorderMode::CONSTANT}, {normalize_enum("TRANSPARENT"), Remap::BorderMode::TRANSPARENT}, {normalize_enum("ISOLATED"), Remap::BorderMode::ISOLATED}};
  15717. template<> PyObject* EnumWrapper<Remap::BorderMode>::pyobj_insts[7] = {nullptr};
  15718. void _init_py_Remap_BorderMode(PyTypeObject& py_type) {
  15719. auto& e_type = EnumWrapper<Remap::BorderMode>::type;
  15720. static PyMethodDef tp_methods[] = {
  15721. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Remap::BorderMode>::py_dump, METH_NOARGS, NULL},
  15722. {NULL} /* Sentinel */
  15723. };
  15724. static PyType_Slot slots[] = {
  15725. {Py_tp_repr, (void*)EnumWrapper<Remap::BorderMode>::py_repr},
  15726. {Py_tp_richcompare, (void*)EnumWrapper<Remap::BorderMode>::tp_richcompare},
  15727. {Py_tp_methods, tp_methods},
  15728. {0, NULL}
  15729. };
  15730. static PyType_Spec spec = {
  15731. // name
  15732. "megengine.core._imperative_rt.ops.Remap.BorderMode",
  15733. // basicsize
  15734. sizeof(EnumWrapper<Remap::BorderMode>),
  15735. // itemsize
  15736. 0,
  15737. // flags
  15738. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  15739. // slots
  15740. slots
  15741. };
  15742. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  15743. mgb_assert(
  15744. e_type->tp_setattro(
  15745. reinterpret_cast<PyObject*>(e_type),
  15746. py::cast("__name__").release().ptr(),
  15747. py::cast("BorderMode").release().ptr()) >= 0);
  15748. mgb_assert(
  15749. e_type->tp_setattro(
  15750. reinterpret_cast<PyObject*>(e_type),
  15751. py::cast("__module__").release().ptr(),
  15752. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  15753. mgb_assert(
  15754. e_type->tp_setattro(
  15755. reinterpret_cast<PyObject*>(e_type),
  15756. py::cast("__qualname__").release().ptr(),
  15757. py::cast("Remap.BorderMode").release().ptr()) >= 0);
  15758. {
  15759. PyObject* inst = e_type->tp_alloc(e_type, 0);
  15760. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::REPLICATE;
  15761. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REPLICATE", inst) >= 0);
  15762. EnumWrapper<Remap::BorderMode>::pyobj_insts[0] = inst;
  15763. }{
  15764. PyObject* inst = e_type->tp_alloc(e_type, 0);
  15765. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::REFLECT;
  15766. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REFLECT", inst) >= 0);
  15767. EnumWrapper<Remap::BorderMode>::pyobj_insts[1] = inst;
  15768. }{
  15769. PyObject* inst = e_type->tp_alloc(e_type, 0);
  15770. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::REFLECT_101;
  15771. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REFLECT_101", inst) >= 0);
  15772. EnumWrapper<Remap::BorderMode>::pyobj_insts[2] = inst;
  15773. }{
  15774. PyObject* inst = e_type->tp_alloc(e_type, 0);
  15775. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::WRAP;
  15776. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "WRAP", inst) >= 0);
  15777. EnumWrapper<Remap::BorderMode>::pyobj_insts[3] = inst;
  15778. }{
  15779. PyObject* inst = e_type->tp_alloc(e_type, 0);
  15780. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::CONSTANT;
  15781. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CONSTANT", inst) >= 0);
  15782. EnumWrapper<Remap::BorderMode>::pyobj_insts[4] = inst;
  15783. }{
  15784. PyObject* inst = e_type->tp_alloc(e_type, 0);
  15785. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::TRANSPARENT;
  15786. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TRANSPARENT", inst) >= 0);
  15787. EnumWrapper<Remap::BorderMode>::pyobj_insts[5] = inst;
  15788. }{
  15789. PyObject* inst = e_type->tp_alloc(e_type, 0);
  15790. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::ISOLATED;
  15791. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISOLATED", inst) >= 0);
  15792. EnumWrapper<Remap::BorderMode>::pyobj_insts[6] = inst;
  15793. }
  15794. Py_INCREF(e_type);
  15795. mgb_assert(PyDict_SetItemString(
  15796. py_type.tp_dict, "BorderMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  15797. }
  15798. void _init_py_Remap_Format(PyTypeObject& py_type) {
  15799. auto& e_type = EnumWrapper<Remap::Format>::type;
  15800. Py_INCREF(e_type);
  15801. mgb_assert(PyDict_SetItemString(
  15802. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  15803. }
  15804. PyOpDefBegin(Remap) // {
  15805. static PyGetSetDef py_getsetters[];
  15806. static PyMethodDef tp_methods[];
  15807. static PyObject* getstate(PyObject* self, PyObject*) {
  15808. auto& opdef = reinterpret_cast<PyOp(Remap)*>(self)->inst();
  15809. static_cast<void>(opdef);
  15810. std::unordered_map<std::string, py::object> state {
  15811. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  15812. {"border_type", serialization<decltype(opdef.border_type)>::dump(opdef.border_type)},
  15813. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  15814. {"scalar", serialization<decltype(opdef.scalar)>::dump(opdef.scalar)}
  15815. };
  15816. return py::cast(state).release().ptr();
  15817. }
  15818. static PyObject* setstate(PyObject* self, PyObject* args) {
  15819. PyObject* dict = PyTuple_GetItem(args, 0);
  15820. if (!dict) return NULL;
  15821. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15822. auto& opdef = reinterpret_cast<PyOp(Remap)*>(self)->inst();
  15823. static_cast<void>(opdef);
  15824. {
  15825. auto&& iter = state.find("imode");
  15826. if (iter != state.end()) {
  15827. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  15828. }
  15829. }
  15830. {
  15831. auto&& iter = state.find("border_type");
  15832. if (iter != state.end()) {
  15833. opdef.border_type = serialization<decltype(opdef.border_type)>::load(iter->second);
  15834. }
  15835. }
  15836. {
  15837. auto&& iter = state.find("format");
  15838. if (iter != state.end()) {
  15839. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  15840. }
  15841. }
  15842. {
  15843. auto&& iter = state.find("scalar");
  15844. if (iter != state.end()) {
  15845. opdef.scalar = serialization<decltype(opdef.scalar)>::load(iter->second);
  15846. }
  15847. }
  15848. Py_RETURN_NONE;
  15849. }
  15850. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15851. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  15852. static PyMethodDef py_init_methoddef;
  15853. // };
  15854. PyOpDefEnd(Remap)
  15855. int PyOp(Remap)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15856. static const char* kwlist[] = {"imode", "border_type", "format", "scalar", "scope", NULL};
  15857. PyObject *imode = NULL, *border_type = NULL, *format = NULL, *scalar = NULL, *scope = NULL;
  15858. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &imode, &border_type, &format, &scalar, &scope))
  15859. return -1;
  15860. if (imode) {
  15861. try {
  15862. // TODO: remove this guard which is used for pybind11 implicit conversion
  15863. py::detail::loader_life_support guard{};
  15864. reinterpret_cast<PyOp(Remap)*>(self)->inst().imode =
  15865. py::cast<decltype(Remap::imode)>(py::handle(imode));
  15866. } CATCH_ALL(-1)
  15867. }
  15868. if (border_type) {
  15869. try {
  15870. // TODO: remove this guard which is used for pybind11 implicit conversion
  15871. py::detail::loader_life_support guard{};
  15872. reinterpret_cast<PyOp(Remap)*>(self)->inst().border_type =
  15873. py::cast<decltype(Remap::border_type)>(py::handle(border_type));
  15874. } CATCH_ALL(-1)
  15875. }
  15876. if (format) {
  15877. try {
  15878. // TODO: remove this guard which is used for pybind11 implicit conversion
  15879. py::detail::loader_life_support guard{};
  15880. reinterpret_cast<PyOp(Remap)*>(self)->inst().format =
  15881. py::cast<decltype(Remap::format)>(py::handle(format));
  15882. } CATCH_ALL(-1)
  15883. }
  15884. if (scalar) {
  15885. try {
  15886. // TODO: remove this guard which is used for pybind11 implicit conversion
  15887. py::detail::loader_life_support guard{};
  15888. reinterpret_cast<PyOp(Remap)*>(self)->inst().scalar =
  15889. py::cast<decltype(Remap::scalar)>(py::handle(scalar));
  15890. } CATCH_ALL(-1)
  15891. }
  15892. if (scope) {
  15893. try {
  15894. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15895. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15896. } CATCH_ALL(-1)
  15897. }
  15898. return 0;
  15899. }
  15900. PyGetSetDef PyOp(Remap)::py_getsetters[] = {
  15901. {const_cast<char*>("imode"), py_get_generic(Remap, imode), py_set_generic(Remap, imode), const_cast<char*>("imode"), NULL},
  15902. {const_cast<char*>("border_type"), py_get_generic(Remap, border_type), py_set_generic(Remap, border_type), const_cast<char*>("border_type"), NULL},
  15903. {const_cast<char*>("format"), py_get_generic(Remap, format), py_set_generic(Remap, format), const_cast<char*>("format"), NULL},
  15904. {const_cast<char*>("scalar"), py_get_generic(Remap, scalar), py_set_generic(Remap, scalar), const_cast<char*>("scalar"), NULL},
  15905. {NULL} /* Sentinel */
  15906. };
  15907. PyMethodDef PyOp(Remap)::tp_methods[] = {
  15908. {const_cast<char*>("__getstate__"), PyOp(Remap)::getstate, METH_NOARGS, "Remap getstate"},
  15909. {const_cast<char*>("__setstate__"), PyOp(Remap)::setstate, METH_VARARGS, "Remap setstate"},
  15910. {NULL} /* Sentinel */
  15911. };
  15912. PyObject *PyOp(Remap)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  15913. if (PyOp(Remap)::py_init(self, args, kwds) < 0) {
  15914. return NULL;
  15915. }
  15916. Py_RETURN_NONE;
  15917. }
  15918. PyMethodDef PyOp(Remap)::py_init_methoddef = {
  15919. "__init__",
  15920. (PyCFunction)PyOp(Remap)::py_init_proxy,
  15921. METH_VARARGS | METH_KEYWORDS,
  15922. "__init__(self, imode: Union[str, InterpolationMode] = ..., border_type: Union[str, BorderMode] = ..., format: Union[str, Format] = ..., scalar: float = ...) -> None\n"
  15923. };
  15924. void _init_py_Remap(py::module m) {
  15925. using py_op = PyOp(Remap);
  15926. auto& py_type = PyOpType(Remap);
  15927. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15928. py_type.tp_name = "megengine.core._imperative_rt.ops.Remap";
  15929. py_type.tp_basicsize = sizeof(PyOp(Remap));
  15930. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15931. py_type.tp_doc = "Remap";
  15932. py_type.tp_base = &PyOpType(OpDef);
  15933. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15934. py_type.tp_new = py_new_generic<py_op>;
  15935. py_type.tp_init = py_op::py_init;
  15936. py_type.tp_methods = py_op::tp_methods;
  15937. py_type.tp_getset = py_op::py_getsetters;
  15938. py_type.tp_dict = PyDict_New();
  15939. PyObject* descr = PyDescr_NewMethod(&PyOpType(Remap), &PyOp(Remap)::py_init_methoddef);
  15940. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  15941. mgb_assert(PyType_Ready(&py_type) >= 0);
  15942. _init_py_Remap_InterpolationMode(py_type);
  15943. _init_py_Remap_BorderMode(py_type);
  15944. _init_py_Remap_Format(py_type);
  15945. PyType_Modified(&py_type);
  15946. m.add_object("Remap", reinterpret_cast<PyObject*>(&py_type));
  15947. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Remap::typeinfo(), &py_type).second);
  15948. }
  15949. PyOpDefBegin(RemoteRecv) // {
  15950. static PyGetSetDef py_getsetters[];
  15951. static PyMethodDef tp_methods[];
  15952. static PyObject* getstate(PyObject* self, PyObject*) {
  15953. auto& opdef = reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst();
  15954. static_cast<void>(opdef);
  15955. std::unordered_map<std::string, py::object> state {
  15956. {"key", serialization<decltype(opdef.key)>::dump(opdef.key)},
  15957. {"addr", serialization<decltype(opdef.addr)>::dump(opdef.addr)},
  15958. {"port", serialization<decltype(opdef.port)>::dump(opdef.port)},
  15959. {"rank_from", serialization<decltype(opdef.rank_from)>::dump(opdef.rank_from)},
  15960. {"cn", serialization<decltype(opdef.cn)>::dump(opdef.cn)},
  15961. {"shape", serialization<decltype(opdef.shape)>::dump(opdef.shape)},
  15962. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  15963. {"backend", serialization<decltype(opdef.backend)>::dump(opdef.backend)}
  15964. };
  15965. return py::cast(state).release().ptr();
  15966. }
  15967. static PyObject* setstate(PyObject* self, PyObject* args) {
  15968. PyObject* dict = PyTuple_GetItem(args, 0);
  15969. if (!dict) return NULL;
  15970. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15971. auto& opdef = reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst();
  15972. static_cast<void>(opdef);
  15973. {
  15974. auto&& iter = state.find("key");
  15975. if (iter != state.end()) {
  15976. opdef.key = serialization<decltype(opdef.key)>::load(iter->second);
  15977. }
  15978. }
  15979. {
  15980. auto&& iter = state.find("addr");
  15981. if (iter != state.end()) {
  15982. opdef.addr = serialization<decltype(opdef.addr)>::load(iter->second);
  15983. }
  15984. }
  15985. {
  15986. auto&& iter = state.find("port");
  15987. if (iter != state.end()) {
  15988. opdef.port = serialization<decltype(opdef.port)>::load(iter->second);
  15989. }
  15990. }
  15991. {
  15992. auto&& iter = state.find("rank_from");
  15993. if (iter != state.end()) {
  15994. opdef.rank_from = serialization<decltype(opdef.rank_from)>::load(iter->second);
  15995. }
  15996. }
  15997. {
  15998. auto&& iter = state.find("cn");
  15999. if (iter != state.end()) {
  16000. opdef.cn = serialization<decltype(opdef.cn)>::load(iter->second);
  16001. }
  16002. }
  16003. {
  16004. auto&& iter = state.find("shape");
  16005. if (iter != state.end()) {
  16006. opdef.shape = serialization<decltype(opdef.shape)>::load(iter->second);
  16007. }
  16008. }
  16009. {
  16010. auto&& iter = state.find("dtype");
  16011. if (iter != state.end()) {
  16012. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  16013. }
  16014. }
  16015. {
  16016. auto&& iter = state.find("backend");
  16017. if (iter != state.end()) {
  16018. opdef.backend = serialization<decltype(opdef.backend)>::load(iter->second);
  16019. }
  16020. }
  16021. Py_RETURN_NONE;
  16022. }
  16023. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16024. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  16025. static PyMethodDef py_init_methoddef;
  16026. // };
  16027. PyOpDefEnd(RemoteRecv)
  16028. int PyOp(RemoteRecv)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16029. static const char* kwlist[] = {"key", "addr", "port", "rank_from", "cn", "shape", "dtype", "backend", "scope", NULL};
  16030. PyObject *key = NULL, *addr = NULL, *port = NULL, *rank_from = NULL, *cn = NULL, *shape = NULL, *dtype = NULL, *backend = NULL, *scope = NULL;
  16031. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &key, &addr, &port, &rank_from, &cn, &shape, &dtype, &backend, &scope))
  16032. return -1;
  16033. if (key) {
  16034. try {
  16035. // TODO: remove this guard which is used for pybind11 implicit conversion
  16036. py::detail::loader_life_support guard{};
  16037. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().key =
  16038. py::cast<decltype(RemoteRecv::key)>(py::handle(key));
  16039. } CATCH_ALL(-1)
  16040. }
  16041. if (addr) {
  16042. try {
  16043. // TODO: remove this guard which is used for pybind11 implicit conversion
  16044. py::detail::loader_life_support guard{};
  16045. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().addr =
  16046. py::cast<decltype(RemoteRecv::addr)>(py::handle(addr));
  16047. } CATCH_ALL(-1)
  16048. }
  16049. if (port) {
  16050. try {
  16051. // TODO: remove this guard which is used for pybind11 implicit conversion
  16052. py::detail::loader_life_support guard{};
  16053. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().port =
  16054. py::cast<decltype(RemoteRecv::port)>(py::handle(port));
  16055. } CATCH_ALL(-1)
  16056. }
  16057. if (rank_from) {
  16058. try {
  16059. // TODO: remove this guard which is used for pybind11 implicit conversion
  16060. py::detail::loader_life_support guard{};
  16061. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().rank_from =
  16062. py::cast<decltype(RemoteRecv::rank_from)>(py::handle(rank_from));
  16063. } CATCH_ALL(-1)
  16064. }
  16065. if (cn) {
  16066. try {
  16067. // TODO: remove this guard which is used for pybind11 implicit conversion
  16068. py::detail::loader_life_support guard{};
  16069. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().cn =
  16070. py::cast<decltype(RemoteRecv::cn)>(py::handle(cn));
  16071. } CATCH_ALL(-1)
  16072. }
  16073. if (shape) {
  16074. try {
  16075. // TODO: remove this guard which is used for pybind11 implicit conversion
  16076. py::detail::loader_life_support guard{};
  16077. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().shape =
  16078. py::cast<decltype(RemoteRecv::shape)>(py::handle(shape));
  16079. } CATCH_ALL(-1)
  16080. }
  16081. if (dtype) {
  16082. try {
  16083. // TODO: remove this guard which is used for pybind11 implicit conversion
  16084. py::detail::loader_life_support guard{};
  16085. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().dtype =
  16086. py::cast<decltype(RemoteRecv::dtype)>(py::handle(dtype));
  16087. } CATCH_ALL(-1)
  16088. }
  16089. if (backend) {
  16090. try {
  16091. // TODO: remove this guard which is used for pybind11 implicit conversion
  16092. py::detail::loader_life_support guard{};
  16093. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().backend =
  16094. py::cast<decltype(RemoteRecv::backend)>(py::handle(backend));
  16095. } CATCH_ALL(-1)
  16096. }
  16097. if (scope) {
  16098. try {
  16099. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16100. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16101. } CATCH_ALL(-1)
  16102. }
  16103. return 0;
  16104. }
  16105. PyGetSetDef PyOp(RemoteRecv)::py_getsetters[] = {
  16106. {const_cast<char*>("key"), py_get_generic(RemoteRecv, key), py_set_generic(RemoteRecv, key), const_cast<char*>("key"), NULL},
  16107. {const_cast<char*>("addr"), py_get_generic(RemoteRecv, addr), py_set_generic(RemoteRecv, addr), const_cast<char*>("addr"), NULL},
  16108. {const_cast<char*>("port"), py_get_generic(RemoteRecv, port), py_set_generic(RemoteRecv, port), const_cast<char*>("port"), NULL},
  16109. {const_cast<char*>("rank_from"), py_get_generic(RemoteRecv, rank_from), py_set_generic(RemoteRecv, rank_from), const_cast<char*>("rank_from"), NULL},
  16110. {const_cast<char*>("cn"), py_get_generic(RemoteRecv, cn), py_set_generic(RemoteRecv, cn), const_cast<char*>("cn"), NULL},
  16111. {const_cast<char*>("shape"), py_get_generic(RemoteRecv, shape), py_set_generic(RemoteRecv, shape), const_cast<char*>("shape"), NULL},
  16112. {const_cast<char*>("dtype"), py_get_generic(RemoteRecv, dtype), py_set_generic(RemoteRecv, dtype), const_cast<char*>("dtype"), NULL},
  16113. {const_cast<char*>("backend"), py_get_generic(RemoteRecv, backend), py_set_generic(RemoteRecv, backend), const_cast<char*>("backend"), NULL},
  16114. {NULL} /* Sentinel */
  16115. };
  16116. PyMethodDef PyOp(RemoteRecv)::tp_methods[] = {
  16117. {const_cast<char*>("__getstate__"), PyOp(RemoteRecv)::getstate, METH_NOARGS, "RemoteRecv getstate"},
  16118. {const_cast<char*>("__setstate__"), PyOp(RemoteRecv)::setstate, METH_VARARGS, "RemoteRecv setstate"},
  16119. {NULL} /* Sentinel */
  16120. };
  16121. PyObject *PyOp(RemoteRecv)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  16122. if (PyOp(RemoteRecv)::py_init(self, args, kwds) < 0) {
  16123. return NULL;
  16124. }
  16125. Py_RETURN_NONE;
  16126. }
  16127. PyMethodDef PyOp(RemoteRecv)::py_init_methoddef = {
  16128. "__init__",
  16129. (PyCFunction)PyOp(RemoteRecv)::py_init_proxy,
  16130. METH_VARARGS | METH_KEYWORDS,
  16131. "__init__(self, key: str = ..., addr: str = ..., port: int = ..., rank_from: int = ..., cn: str = ..., shape: list[int] = ..., dtype: str = ..., backend: str = ...) -> None\n"
  16132. };
  16133. void _init_py_RemoteRecv(py::module m) {
  16134. using py_op = PyOp(RemoteRecv);
  16135. auto& py_type = PyOpType(RemoteRecv);
  16136. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16137. py_type.tp_name = "megengine.core._imperative_rt.ops.RemoteRecv";
  16138. py_type.tp_basicsize = sizeof(PyOp(RemoteRecv));
  16139. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16140. py_type.tp_doc = "RemoteRecv";
  16141. py_type.tp_base = &PyOpType(OpDef);
  16142. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16143. py_type.tp_new = py_new_generic<py_op>;
  16144. py_type.tp_init = py_op::py_init;
  16145. py_type.tp_methods = py_op::tp_methods;
  16146. py_type.tp_getset = py_op::py_getsetters;
  16147. py_type.tp_dict = PyDict_New();
  16148. PyObject* descr = PyDescr_NewMethod(&PyOpType(RemoteRecv), &PyOp(RemoteRecv)::py_init_methoddef);
  16149. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  16150. mgb_assert(PyType_Ready(&py_type) >= 0);
  16151. PyType_Modified(&py_type);
  16152. m.add_object("RemoteRecv", reinterpret_cast<PyObject*>(&py_type));
  16153. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RemoteRecv::typeinfo(), &py_type).second);
  16154. }
  16155. PyOpDefBegin(RemoteSend) // {
  16156. static PyGetSetDef py_getsetters[];
  16157. static PyMethodDef tp_methods[];
  16158. static PyObject* getstate(PyObject* self, PyObject*) {
  16159. auto& opdef = reinterpret_cast<PyOp(RemoteSend)*>(self)->inst();
  16160. static_cast<void>(opdef);
  16161. std::unordered_map<std::string, py::object> state {
  16162. {"key", serialization<decltype(opdef.key)>::dump(opdef.key)},
  16163. {"addr", serialization<decltype(opdef.addr)>::dump(opdef.addr)},
  16164. {"port", serialization<decltype(opdef.port)>::dump(opdef.port)},
  16165. {"rank_to", serialization<decltype(opdef.rank_to)>::dump(opdef.rank_to)},
  16166. {"backend", serialization<decltype(opdef.backend)>::dump(opdef.backend)}
  16167. };
  16168. return py::cast(state).release().ptr();
  16169. }
  16170. static PyObject* setstate(PyObject* self, PyObject* args) {
  16171. PyObject* dict = PyTuple_GetItem(args, 0);
  16172. if (!dict) return NULL;
  16173. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16174. auto& opdef = reinterpret_cast<PyOp(RemoteSend)*>(self)->inst();
  16175. static_cast<void>(opdef);
  16176. {
  16177. auto&& iter = state.find("key");
  16178. if (iter != state.end()) {
  16179. opdef.key = serialization<decltype(opdef.key)>::load(iter->second);
  16180. }
  16181. }
  16182. {
  16183. auto&& iter = state.find("addr");
  16184. if (iter != state.end()) {
  16185. opdef.addr = serialization<decltype(opdef.addr)>::load(iter->second);
  16186. }
  16187. }
  16188. {
  16189. auto&& iter = state.find("port");
  16190. if (iter != state.end()) {
  16191. opdef.port = serialization<decltype(opdef.port)>::load(iter->second);
  16192. }
  16193. }
  16194. {
  16195. auto&& iter = state.find("rank_to");
  16196. if (iter != state.end()) {
  16197. opdef.rank_to = serialization<decltype(opdef.rank_to)>::load(iter->second);
  16198. }
  16199. }
  16200. {
  16201. auto&& iter = state.find("backend");
  16202. if (iter != state.end()) {
  16203. opdef.backend = serialization<decltype(opdef.backend)>::load(iter->second);
  16204. }
  16205. }
  16206. Py_RETURN_NONE;
  16207. }
  16208. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16209. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  16210. static PyMethodDef py_init_methoddef;
  16211. // };
  16212. PyOpDefEnd(RemoteSend)
  16213. int PyOp(RemoteSend)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16214. static const char* kwlist[] = {"key", "addr", "port", "rank_to", "backend", "scope", NULL};
  16215. PyObject *key = NULL, *addr = NULL, *port = NULL, *rank_to = NULL, *backend = NULL, *scope = NULL;
  16216. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOO", const_cast<char**>(kwlist), &key, &addr, &port, &rank_to, &backend, &scope))
  16217. return -1;
  16218. if (key) {
  16219. try {
  16220. // TODO: remove this guard which is used for pybind11 implicit conversion
  16221. py::detail::loader_life_support guard{};
  16222. reinterpret_cast<PyOp(RemoteSend)*>(self)->inst().key =
  16223. py::cast<decltype(RemoteSend::key)>(py::handle(key));
  16224. } CATCH_ALL(-1)
  16225. }
  16226. if (addr) {
  16227. try {
  16228. // TODO: remove this guard which is used for pybind11 implicit conversion
  16229. py::detail::loader_life_support guard{};
  16230. reinterpret_cast<PyOp(RemoteSend)*>(self)->inst().addr =
  16231. py::cast<decltype(RemoteSend::addr)>(py::handle(addr));
  16232. } CATCH_ALL(-1)
  16233. }
  16234. if (port) {
  16235. try {
  16236. // TODO: remove this guard which is used for pybind11 implicit conversion
  16237. py::detail::loader_life_support guard{};
  16238. reinterpret_cast<PyOp(RemoteSend)*>(self)->inst().port =
  16239. py::cast<decltype(RemoteSend::port)>(py::handle(port));
  16240. } CATCH_ALL(-1)
  16241. }
  16242. if (rank_to) {
  16243. try {
  16244. // TODO: remove this guard which is used for pybind11 implicit conversion
  16245. py::detail::loader_life_support guard{};
  16246. reinterpret_cast<PyOp(RemoteSend)*>(self)->inst().rank_to =
  16247. py::cast<decltype(RemoteSend::rank_to)>(py::handle(rank_to));
  16248. } CATCH_ALL(-1)
  16249. }
  16250. if (backend) {
  16251. try {
  16252. // TODO: remove this guard which is used for pybind11 implicit conversion
  16253. py::detail::loader_life_support guard{};
  16254. reinterpret_cast<PyOp(RemoteSend)*>(self)->inst().backend =
  16255. py::cast<decltype(RemoteSend::backend)>(py::handle(backend));
  16256. } CATCH_ALL(-1)
  16257. }
  16258. if (scope) {
  16259. try {
  16260. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16261. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16262. } CATCH_ALL(-1)
  16263. }
  16264. return 0;
  16265. }
  16266. PyGetSetDef PyOp(RemoteSend)::py_getsetters[] = {
  16267. {const_cast<char*>("key"), py_get_generic(RemoteSend, key), py_set_generic(RemoteSend, key), const_cast<char*>("key"), NULL},
  16268. {const_cast<char*>("addr"), py_get_generic(RemoteSend, addr), py_set_generic(RemoteSend, addr), const_cast<char*>("addr"), NULL},
  16269. {const_cast<char*>("port"), py_get_generic(RemoteSend, port), py_set_generic(RemoteSend, port), const_cast<char*>("port"), NULL},
  16270. {const_cast<char*>("rank_to"), py_get_generic(RemoteSend, rank_to), py_set_generic(RemoteSend, rank_to), const_cast<char*>("rank_to"), NULL},
  16271. {const_cast<char*>("backend"), py_get_generic(RemoteSend, backend), py_set_generic(RemoteSend, backend), const_cast<char*>("backend"), NULL},
  16272. {NULL} /* Sentinel */
  16273. };
  16274. PyMethodDef PyOp(RemoteSend)::tp_methods[] = {
  16275. {const_cast<char*>("__getstate__"), PyOp(RemoteSend)::getstate, METH_NOARGS, "RemoteSend getstate"},
  16276. {const_cast<char*>("__setstate__"), PyOp(RemoteSend)::setstate, METH_VARARGS, "RemoteSend setstate"},
  16277. {NULL} /* Sentinel */
  16278. };
  16279. PyObject *PyOp(RemoteSend)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  16280. if (PyOp(RemoteSend)::py_init(self, args, kwds) < 0) {
  16281. return NULL;
  16282. }
  16283. Py_RETURN_NONE;
  16284. }
  16285. PyMethodDef PyOp(RemoteSend)::py_init_methoddef = {
  16286. "__init__",
  16287. (PyCFunction)PyOp(RemoteSend)::py_init_proxy,
  16288. METH_VARARGS | METH_KEYWORDS,
  16289. "__init__(self, key: str = ..., addr: str = ..., port: int = ..., rank_to: int = ..., backend: str = ...) -> None\n"
  16290. };
  16291. void _init_py_RemoteSend(py::module m) {
  16292. using py_op = PyOp(RemoteSend);
  16293. auto& py_type = PyOpType(RemoteSend);
  16294. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16295. py_type.tp_name = "megengine.core._imperative_rt.ops.RemoteSend";
  16296. py_type.tp_basicsize = sizeof(PyOp(RemoteSend));
  16297. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16298. py_type.tp_doc = "RemoteSend";
  16299. py_type.tp_base = &PyOpType(OpDef);
  16300. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16301. py_type.tp_new = py_new_generic<py_op>;
  16302. py_type.tp_init = py_op::py_init;
  16303. py_type.tp_methods = py_op::tp_methods;
  16304. py_type.tp_getset = py_op::py_getsetters;
  16305. py_type.tp_dict = PyDict_New();
  16306. PyObject* descr = PyDescr_NewMethod(&PyOpType(RemoteSend), &PyOp(RemoteSend)::py_init_methoddef);
  16307. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  16308. mgb_assert(PyType_Ready(&py_type) >= 0);
  16309. PyType_Modified(&py_type);
  16310. m.add_object("RemoteSend", reinterpret_cast<PyObject*>(&py_type));
  16311. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RemoteSend::typeinfo(), &py_type).second);
  16312. }
  16313. PyOpDefBegin(RemoveAxis) // {
  16314. static PyGetSetDef py_getsetters[];
  16315. static PyMethodDef tp_methods[];
  16316. static PyObject* getstate(PyObject* self, PyObject*) {
  16317. auto& opdef = reinterpret_cast<PyOp(RemoveAxis)*>(self)->inst();
  16318. static_cast<void>(opdef);
  16319. std::unordered_map<std::string, py::object> state {
  16320. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)}
  16321. };
  16322. return py::cast(state).release().ptr();
  16323. }
  16324. static PyObject* setstate(PyObject* self, PyObject* args) {
  16325. PyObject* dict = PyTuple_GetItem(args, 0);
  16326. if (!dict) return NULL;
  16327. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16328. auto& opdef = reinterpret_cast<PyOp(RemoveAxis)*>(self)->inst();
  16329. static_cast<void>(opdef);
  16330. {
  16331. auto&& iter = state.find("axis");
  16332. if (iter != state.end()) {
  16333. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  16334. }
  16335. }
  16336. Py_RETURN_NONE;
  16337. }
  16338. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16339. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  16340. static PyMethodDef py_init_methoddef;
  16341. // };
  16342. PyOpDefEnd(RemoveAxis)
  16343. int PyOp(RemoveAxis)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16344. static const char* kwlist[] = {"axis", "scope", NULL};
  16345. PyObject *axis = NULL, *scope = NULL;
  16346. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &axis, &scope))
  16347. return -1;
  16348. if (axis) {
  16349. try {
  16350. // TODO: remove this guard which is used for pybind11 implicit conversion
  16351. py::detail::loader_life_support guard{};
  16352. reinterpret_cast<PyOp(RemoveAxis)*>(self)->inst().axis =
  16353. py::cast<decltype(RemoveAxis::axis)>(py::handle(axis));
  16354. } CATCH_ALL(-1)
  16355. }
  16356. if (scope) {
  16357. try {
  16358. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16359. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16360. } CATCH_ALL(-1)
  16361. }
  16362. return 0;
  16363. }
  16364. PyGetSetDef PyOp(RemoveAxis)::py_getsetters[] = {
  16365. {const_cast<char*>("axis"), py_get_generic(RemoveAxis, axis), py_set_generic(RemoveAxis, axis), const_cast<char*>("axis"), NULL},
  16366. {NULL} /* Sentinel */
  16367. };
  16368. PyMethodDef PyOp(RemoveAxis)::tp_methods[] = {
  16369. {const_cast<char*>("__getstate__"), PyOp(RemoveAxis)::getstate, METH_NOARGS, "RemoveAxis getstate"},
  16370. {const_cast<char*>("__setstate__"), PyOp(RemoveAxis)::setstate, METH_VARARGS, "RemoveAxis setstate"},
  16371. {NULL} /* Sentinel */
  16372. };
  16373. PyObject *PyOp(RemoveAxis)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  16374. if (PyOp(RemoveAxis)::py_init(self, args, kwds) < 0) {
  16375. return NULL;
  16376. }
  16377. Py_RETURN_NONE;
  16378. }
  16379. PyMethodDef PyOp(RemoveAxis)::py_init_methoddef = {
  16380. "__init__",
  16381. (PyCFunction)PyOp(RemoveAxis)::py_init_proxy,
  16382. METH_VARARGS | METH_KEYWORDS,
  16383. "__init__(self, axis: list[int] = ...) -> None\n"
  16384. };
  16385. void _init_py_RemoveAxis(py::module m) {
  16386. using py_op = PyOp(RemoveAxis);
  16387. auto& py_type = PyOpType(RemoveAxis);
  16388. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16389. py_type.tp_name = "megengine.core._imperative_rt.ops.RemoveAxis";
  16390. py_type.tp_basicsize = sizeof(PyOp(RemoveAxis));
  16391. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16392. py_type.tp_doc = "RemoveAxis";
  16393. py_type.tp_base = &PyOpType(OpDef);
  16394. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16395. py_type.tp_new = py_new_generic<py_op>;
  16396. py_type.tp_init = py_op::py_init;
  16397. py_type.tp_methods = py_op::tp_methods;
  16398. py_type.tp_getset = py_op::py_getsetters;
  16399. py_type.tp_dict = PyDict_New();
  16400. PyObject* descr = PyDescr_NewMethod(&PyOpType(RemoveAxis), &PyOp(RemoveAxis)::py_init_methoddef);
  16401. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  16402. mgb_assert(PyType_Ready(&py_type) >= 0);
  16403. PyType_Modified(&py_type);
  16404. m.add_object("RemoveAxis", reinterpret_cast<PyObject*>(&py_type));
  16405. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RemoveAxis::typeinfo(), &py_type).second);
  16406. }
  16407. PyOpDefBegin(Reshape) // {
  16408. static PyGetSetDef py_getsetters[];
  16409. static PyMethodDef tp_methods[];
  16410. static PyObject* getstate(PyObject* self, PyObject*) {
  16411. auto& opdef = reinterpret_cast<PyOp(Reshape)*>(self)->inst();
  16412. static_cast<void>(opdef);
  16413. std::unordered_map<std::string, py::object> state {
  16414. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  16415. {"shape", serialization<decltype(opdef.shape)>::dump(opdef.shape)}
  16416. };
  16417. return py::cast(state).release().ptr();
  16418. }
  16419. static PyObject* setstate(PyObject* self, PyObject* args) {
  16420. PyObject* dict = PyTuple_GetItem(args, 0);
  16421. if (!dict) return NULL;
  16422. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16423. auto& opdef = reinterpret_cast<PyOp(Reshape)*>(self)->inst();
  16424. static_cast<void>(opdef);
  16425. {
  16426. auto&& iter = state.find("axis");
  16427. if (iter != state.end()) {
  16428. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  16429. }
  16430. }
  16431. {
  16432. auto&& iter = state.find("shape");
  16433. if (iter != state.end()) {
  16434. opdef.shape = serialization<decltype(opdef.shape)>::load(iter->second);
  16435. }
  16436. }
  16437. Py_RETURN_NONE;
  16438. }
  16439. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16440. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  16441. static PyMethodDef py_init_methoddef;
  16442. // };
  16443. PyOpDefEnd(Reshape)
  16444. int PyOp(Reshape)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16445. static const char* kwlist[] = {"axis", "shape", "scope", NULL};
  16446. PyObject *axis = NULL, *shape = NULL, *scope = NULL;
  16447. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &axis, &shape, &scope))
  16448. return -1;
  16449. if (axis) {
  16450. try {
  16451. // TODO: remove this guard which is used for pybind11 implicit conversion
  16452. py::detail::loader_life_support guard{};
  16453. reinterpret_cast<PyOp(Reshape)*>(self)->inst().axis =
  16454. py::cast<decltype(Reshape::axis)>(py::handle(axis));
  16455. } CATCH_ALL(-1)
  16456. }
  16457. if (shape) {
  16458. try {
  16459. // TODO: remove this guard which is used for pybind11 implicit conversion
  16460. py::detail::loader_life_support guard{};
  16461. reinterpret_cast<PyOp(Reshape)*>(self)->inst().shape =
  16462. py::cast<decltype(Reshape::shape)>(py::handle(shape));
  16463. } CATCH_ALL(-1)
  16464. }
  16465. if (scope) {
  16466. try {
  16467. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16468. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16469. } CATCH_ALL(-1)
  16470. }
  16471. return 0;
  16472. }
  16473. PyGetSetDef PyOp(Reshape)::py_getsetters[] = {
  16474. {const_cast<char*>("axis"), py_get_generic(Reshape, axis), py_set_generic(Reshape, axis), const_cast<char*>("axis"), NULL},
  16475. {const_cast<char*>("shape"), py_get_generic(Reshape, shape), py_set_generic(Reshape, shape), const_cast<char*>("shape"), NULL},
  16476. {NULL} /* Sentinel */
  16477. };
  16478. PyMethodDef PyOp(Reshape)::tp_methods[] = {
  16479. {const_cast<char*>("__getstate__"), PyOp(Reshape)::getstate, METH_NOARGS, "Reshape getstate"},
  16480. {const_cast<char*>("__setstate__"), PyOp(Reshape)::setstate, METH_VARARGS, "Reshape setstate"},
  16481. {NULL} /* Sentinel */
  16482. };
  16483. PyObject *PyOp(Reshape)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  16484. if (PyOp(Reshape)::py_init(self, args, kwds) < 0) {
  16485. return NULL;
  16486. }
  16487. Py_RETURN_NONE;
  16488. }
  16489. PyMethodDef PyOp(Reshape)::py_init_methoddef = {
  16490. "__init__",
  16491. (PyCFunction)PyOp(Reshape)::py_init_proxy,
  16492. METH_VARARGS | METH_KEYWORDS,
  16493. "__init__(self, axis: int = ..., shape: list[int] = ...) -> None\n"
  16494. };
  16495. void _init_py_Reshape(py::module m) {
  16496. using py_op = PyOp(Reshape);
  16497. auto& py_type = PyOpType(Reshape);
  16498. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16499. py_type.tp_name = "megengine.core._imperative_rt.ops.Reshape";
  16500. py_type.tp_basicsize = sizeof(PyOp(Reshape));
  16501. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16502. py_type.tp_doc = "Reshape";
  16503. py_type.tp_base = &PyOpType(OpDef);
  16504. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16505. py_type.tp_new = py_new_generic<py_op>;
  16506. py_type.tp_init = py_op::py_init;
  16507. py_type.tp_methods = py_op::tp_methods;
  16508. py_type.tp_getset = py_op::py_getsetters;
  16509. py_type.tp_dict = PyDict_New();
  16510. PyObject* descr = PyDescr_NewMethod(&PyOpType(Reshape), &PyOp(Reshape)::py_init_methoddef);
  16511. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  16512. mgb_assert(PyType_Ready(&py_type) >= 0);
  16513. PyType_Modified(&py_type);
  16514. m.add_object("Reshape", reinterpret_cast<PyObject*>(&py_type));
  16515. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Reshape::typeinfo(), &py_type).second);
  16516. }
  16517. void _init_py_Resize_InterpolationMode(PyTypeObject& py_type) {
  16518. auto& e_type = EnumWrapper<Resize::InterpolationMode>::type;
  16519. Py_INCREF(e_type);
  16520. mgb_assert(PyDict_SetItemString(
  16521. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16522. }
  16523. void _init_py_Resize_Format(PyTypeObject& py_type) {
  16524. auto& e_type = EnumWrapper<Resize::Format>::type;
  16525. Py_INCREF(e_type);
  16526. mgb_assert(PyDict_SetItemString(
  16527. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16528. }
  16529. PyOpDefBegin(Resize) // {
  16530. static PyGetSetDef py_getsetters[];
  16531. static PyMethodDef tp_methods[];
  16532. static PyObject* getstate(PyObject* self, PyObject*) {
  16533. auto& opdef = reinterpret_cast<PyOp(Resize)*>(self)->inst();
  16534. static_cast<void>(opdef);
  16535. std::unordered_map<std::string, py::object> state {
  16536. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  16537. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)}
  16538. };
  16539. return py::cast(state).release().ptr();
  16540. }
  16541. static PyObject* setstate(PyObject* self, PyObject* args) {
  16542. PyObject* dict = PyTuple_GetItem(args, 0);
  16543. if (!dict) return NULL;
  16544. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16545. auto& opdef = reinterpret_cast<PyOp(Resize)*>(self)->inst();
  16546. static_cast<void>(opdef);
  16547. {
  16548. auto&& iter = state.find("imode");
  16549. if (iter != state.end()) {
  16550. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  16551. }
  16552. }
  16553. {
  16554. auto&& iter = state.find("format");
  16555. if (iter != state.end()) {
  16556. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  16557. }
  16558. }
  16559. Py_RETURN_NONE;
  16560. }
  16561. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16562. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  16563. static PyMethodDef py_init_methoddef;
  16564. // };
  16565. PyOpDefEnd(Resize)
  16566. int PyOp(Resize)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16567. static const char* kwlist[] = {"imode", "format", "scope", NULL};
  16568. PyObject *imode = NULL, *format = NULL, *scope = NULL;
  16569. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &imode, &format, &scope))
  16570. return -1;
  16571. if (imode) {
  16572. try {
  16573. // TODO: remove this guard which is used for pybind11 implicit conversion
  16574. py::detail::loader_life_support guard{};
  16575. reinterpret_cast<PyOp(Resize)*>(self)->inst().imode =
  16576. py::cast<decltype(Resize::imode)>(py::handle(imode));
  16577. } CATCH_ALL(-1)
  16578. }
  16579. if (format) {
  16580. try {
  16581. // TODO: remove this guard which is used for pybind11 implicit conversion
  16582. py::detail::loader_life_support guard{};
  16583. reinterpret_cast<PyOp(Resize)*>(self)->inst().format =
  16584. py::cast<decltype(Resize::format)>(py::handle(format));
  16585. } CATCH_ALL(-1)
  16586. }
  16587. if (scope) {
  16588. try {
  16589. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16590. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16591. } CATCH_ALL(-1)
  16592. }
  16593. return 0;
  16594. }
  16595. PyGetSetDef PyOp(Resize)::py_getsetters[] = {
  16596. {const_cast<char*>("imode"), py_get_generic(Resize, imode), py_set_generic(Resize, imode), const_cast<char*>("imode"), NULL},
  16597. {const_cast<char*>("format"), py_get_generic(Resize, format), py_set_generic(Resize, format), const_cast<char*>("format"), NULL},
  16598. {NULL} /* Sentinel */
  16599. };
  16600. PyMethodDef PyOp(Resize)::tp_methods[] = {
  16601. {const_cast<char*>("__getstate__"), PyOp(Resize)::getstate, METH_NOARGS, "Resize getstate"},
  16602. {const_cast<char*>("__setstate__"), PyOp(Resize)::setstate, METH_VARARGS, "Resize setstate"},
  16603. {NULL} /* Sentinel */
  16604. };
  16605. PyObject *PyOp(Resize)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  16606. if (PyOp(Resize)::py_init(self, args, kwds) < 0) {
  16607. return NULL;
  16608. }
  16609. Py_RETURN_NONE;
  16610. }
  16611. PyMethodDef PyOp(Resize)::py_init_methoddef = {
  16612. "__init__",
  16613. (PyCFunction)PyOp(Resize)::py_init_proxy,
  16614. METH_VARARGS | METH_KEYWORDS,
  16615. "__init__(self, imode: Union[str, InterpolationMode] = ..., format: Union[str, Format] = ...) -> None\n"
  16616. };
  16617. void _init_py_Resize(py::module m) {
  16618. using py_op = PyOp(Resize);
  16619. auto& py_type = PyOpType(Resize);
  16620. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16621. py_type.tp_name = "megengine.core._imperative_rt.ops.Resize";
  16622. py_type.tp_basicsize = sizeof(PyOp(Resize));
  16623. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16624. py_type.tp_doc = "Resize";
  16625. py_type.tp_base = &PyOpType(OpDef);
  16626. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16627. py_type.tp_new = py_new_generic<py_op>;
  16628. py_type.tp_init = py_op::py_init;
  16629. py_type.tp_methods = py_op::tp_methods;
  16630. py_type.tp_getset = py_op::py_getsetters;
  16631. py_type.tp_dict = PyDict_New();
  16632. PyObject* descr = PyDescr_NewMethod(&PyOpType(Resize), &PyOp(Resize)::py_init_methoddef);
  16633. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  16634. mgb_assert(PyType_Ready(&py_type) >= 0);
  16635. _init_py_Resize_InterpolationMode(py_type);
  16636. _init_py_Resize_Format(py_type);
  16637. PyType_Modified(&py_type);
  16638. m.add_object("Resize", reinterpret_cast<PyObject*>(&py_type));
  16639. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Resize::typeinfo(), &py_type).second);
  16640. }
  16641. PyOpDefBegin(SVD) // {
  16642. static PyGetSetDef py_getsetters[];
  16643. static PyMethodDef tp_methods[];
  16644. static PyObject* getstate(PyObject* self, PyObject*) {
  16645. auto& opdef = reinterpret_cast<PyOp(SVD)*>(self)->inst();
  16646. static_cast<void>(opdef);
  16647. std::unordered_map<std::string, py::object> state {
  16648. {"full_matrices", serialization<decltype(opdef.full_matrices)>::dump(opdef.full_matrices)},
  16649. {"compute_uv", serialization<decltype(opdef.compute_uv)>::dump(opdef.compute_uv)}
  16650. };
  16651. return py::cast(state).release().ptr();
  16652. }
  16653. static PyObject* setstate(PyObject* self, PyObject* args) {
  16654. PyObject* dict = PyTuple_GetItem(args, 0);
  16655. if (!dict) return NULL;
  16656. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16657. auto& opdef = reinterpret_cast<PyOp(SVD)*>(self)->inst();
  16658. static_cast<void>(opdef);
  16659. {
  16660. auto&& iter = state.find("full_matrices");
  16661. if (iter != state.end()) {
  16662. opdef.full_matrices = serialization<decltype(opdef.full_matrices)>::load(iter->second);
  16663. }
  16664. }
  16665. {
  16666. auto&& iter = state.find("compute_uv");
  16667. if (iter != state.end()) {
  16668. opdef.compute_uv = serialization<decltype(opdef.compute_uv)>::load(iter->second);
  16669. }
  16670. }
  16671. Py_RETURN_NONE;
  16672. }
  16673. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16674. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  16675. static PyMethodDef py_init_methoddef;
  16676. // };
  16677. PyOpDefEnd(SVD)
  16678. int PyOp(SVD)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16679. static const char* kwlist[] = {"full_matrices", "compute_uv", "scope", NULL};
  16680. PyObject *full_matrices = NULL, *compute_uv = NULL, *scope = NULL;
  16681. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &full_matrices, &compute_uv, &scope))
  16682. return -1;
  16683. if (full_matrices) {
  16684. try {
  16685. // TODO: remove this guard which is used for pybind11 implicit conversion
  16686. py::detail::loader_life_support guard{};
  16687. reinterpret_cast<PyOp(SVD)*>(self)->inst().full_matrices =
  16688. py::cast<decltype(SVD::full_matrices)>(py::handle(full_matrices));
  16689. } CATCH_ALL(-1)
  16690. }
  16691. if (compute_uv) {
  16692. try {
  16693. // TODO: remove this guard which is used for pybind11 implicit conversion
  16694. py::detail::loader_life_support guard{};
  16695. reinterpret_cast<PyOp(SVD)*>(self)->inst().compute_uv =
  16696. py::cast<decltype(SVD::compute_uv)>(py::handle(compute_uv));
  16697. } CATCH_ALL(-1)
  16698. }
  16699. if (scope) {
  16700. try {
  16701. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16702. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16703. } CATCH_ALL(-1)
  16704. }
  16705. return 0;
  16706. }
  16707. PyGetSetDef PyOp(SVD)::py_getsetters[] = {
  16708. {const_cast<char*>("full_matrices"), py_get_generic(SVD, full_matrices), py_set_generic(SVD, full_matrices), const_cast<char*>("full_matrices"), NULL},
  16709. {const_cast<char*>("compute_uv"), py_get_generic(SVD, compute_uv), py_set_generic(SVD, compute_uv), const_cast<char*>("compute_uv"), NULL},
  16710. {NULL} /* Sentinel */
  16711. };
  16712. PyMethodDef PyOp(SVD)::tp_methods[] = {
  16713. {const_cast<char*>("__getstate__"), PyOp(SVD)::getstate, METH_NOARGS, "SVD getstate"},
  16714. {const_cast<char*>("__setstate__"), PyOp(SVD)::setstate, METH_VARARGS, "SVD setstate"},
  16715. {NULL} /* Sentinel */
  16716. };
  16717. PyObject *PyOp(SVD)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  16718. if (PyOp(SVD)::py_init(self, args, kwds) < 0) {
  16719. return NULL;
  16720. }
  16721. Py_RETURN_NONE;
  16722. }
  16723. PyMethodDef PyOp(SVD)::py_init_methoddef = {
  16724. "__init__",
  16725. (PyCFunction)PyOp(SVD)::py_init_proxy,
  16726. METH_VARARGS | METH_KEYWORDS,
  16727. "__init__(self, full_matrices: bool = ..., compute_uv: bool = ...) -> None\n"
  16728. };
  16729. void _init_py_SVD(py::module m) {
  16730. using py_op = PyOp(SVD);
  16731. auto& py_type = PyOpType(SVD);
  16732. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16733. py_type.tp_name = "megengine.core._imperative_rt.ops.SVD";
  16734. py_type.tp_basicsize = sizeof(PyOp(SVD));
  16735. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16736. py_type.tp_doc = "SVD";
  16737. py_type.tp_base = &PyOpType(OpDef);
  16738. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16739. py_type.tp_new = py_new_generic<py_op>;
  16740. py_type.tp_init = py_op::py_init;
  16741. py_type.tp_methods = py_op::tp_methods;
  16742. py_type.tp_getset = py_op::py_getsetters;
  16743. py_type.tp_dict = PyDict_New();
  16744. PyObject* descr = PyDescr_NewMethod(&PyOpType(SVD), &PyOp(SVD)::py_init_methoddef);
  16745. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  16746. mgb_assert(PyType_Ready(&py_type) >= 0);
  16747. PyType_Modified(&py_type);
  16748. m.add_object("SVD", reinterpret_cast<PyObject*>(&py_type));
  16749. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SVD::typeinfo(), &py_type).second);
  16750. }
  16751. PyOpDefBegin(SetMeshIndexing) // {
  16752. static PyGetSetDef py_getsetters[];
  16753. static PyMethodDef tp_methods[];
  16754. static PyObject* getstate(PyObject* self, PyObject*) {
  16755. auto& opdef = reinterpret_cast<PyOp(SetMeshIndexing)*>(self)->inst();
  16756. static_cast<void>(opdef);
  16757. std::unordered_map<std::string, py::object> state {
  16758. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  16759. };
  16760. return py::cast(state).release().ptr();
  16761. }
  16762. static PyObject* setstate(PyObject* self, PyObject* args) {
  16763. PyObject* dict = PyTuple_GetItem(args, 0);
  16764. if (!dict) return NULL;
  16765. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16766. auto& opdef = reinterpret_cast<PyOp(SetMeshIndexing)*>(self)->inst();
  16767. static_cast<void>(opdef);
  16768. {
  16769. auto&& iter = state.find("items");
  16770. if (iter != state.end()) {
  16771. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  16772. }
  16773. }
  16774. Py_RETURN_NONE;
  16775. }
  16776. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16777. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  16778. static PyMethodDef py_init_methoddef;
  16779. // };
  16780. PyOpDefEnd(SetMeshIndexing)
  16781. int PyOp(SetMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16782. static const char* kwlist[] = {"items", "scope", NULL};
  16783. PyObject *items = NULL, *scope = NULL;
  16784. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  16785. return -1;
  16786. if (items) {
  16787. try {
  16788. // TODO: remove this guard which is used for pybind11 implicit conversion
  16789. py::detail::loader_life_support guard{};
  16790. reinterpret_cast<PyOp(SetMeshIndexing)*>(self)->inst().items =
  16791. py::cast<decltype(SetMeshIndexing::items)>(py::handle(items));
  16792. } CATCH_ALL(-1)
  16793. }
  16794. if (scope) {
  16795. try {
  16796. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16797. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16798. } CATCH_ALL(-1)
  16799. }
  16800. return 0;
  16801. }
  16802. PyGetSetDef PyOp(SetMeshIndexing)::py_getsetters[] = {
  16803. {const_cast<char*>("items"), py_get_generic(SetMeshIndexing, items), py_set_generic(SetMeshIndexing, items), const_cast<char*>("items"), NULL},
  16804. {NULL} /* Sentinel */
  16805. };
  16806. PyMethodDef PyOp(SetMeshIndexing)::tp_methods[] = {
  16807. {const_cast<char*>("__getstate__"), PyOp(SetMeshIndexing)::getstate, METH_NOARGS, "SetMeshIndexing getstate"},
  16808. {const_cast<char*>("__setstate__"), PyOp(SetMeshIndexing)::setstate, METH_VARARGS, "SetMeshIndexing setstate"},
  16809. {NULL} /* Sentinel */
  16810. };
  16811. PyObject *PyOp(SetMeshIndexing)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  16812. if (PyOp(SetMeshIndexing)::py_init(self, args, kwds) < 0) {
  16813. return NULL;
  16814. }
  16815. Py_RETURN_NONE;
  16816. }
  16817. PyMethodDef PyOp(SetMeshIndexing)::py_init_methoddef = {
  16818. "__init__",
  16819. (PyCFunction)PyOp(SetMeshIndexing)::py_init_proxy,
  16820. METH_VARARGS | METH_KEYWORDS,
  16821. "__init__(self, items: list[tuple[int, bool, bool, bool, bool]] = ...) -> None\n"
  16822. };
  16823. void _init_py_SetMeshIndexing(py::module m) {
  16824. using py_op = PyOp(SetMeshIndexing);
  16825. auto& py_type = PyOpType(SetMeshIndexing);
  16826. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16827. py_type.tp_name = "megengine.core._imperative_rt.ops.SetMeshIndexing";
  16828. py_type.tp_basicsize = sizeof(PyOp(SetMeshIndexing));
  16829. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16830. py_type.tp_doc = "SetMeshIndexing";
  16831. py_type.tp_base = &PyOpType(OpDef);
  16832. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16833. py_type.tp_new = py_new_generic<py_op>;
  16834. py_type.tp_init = py_op::py_init;
  16835. py_type.tp_methods = py_op::tp_methods;
  16836. py_type.tp_getset = py_op::py_getsetters;
  16837. py_type.tp_dict = PyDict_New();
  16838. PyObject* descr = PyDescr_NewMethod(&PyOpType(SetMeshIndexing), &PyOp(SetMeshIndexing)::py_init_methoddef);
  16839. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  16840. mgb_assert(PyType_Ready(&py_type) >= 0);
  16841. PyType_Modified(&py_type);
  16842. m.add_object("SetMeshIndexing", reinterpret_cast<PyObject*>(&py_type));
  16843. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SetMeshIndexing::typeinfo(), &py_type).second);
  16844. }
  16845. PyOpDefBegin(SetSubtensor) // {
  16846. static PyGetSetDef py_getsetters[];
  16847. static PyMethodDef tp_methods[];
  16848. static PyObject* getstate(PyObject* self, PyObject*) {
  16849. auto& opdef = reinterpret_cast<PyOp(SetSubtensor)*>(self)->inst();
  16850. static_cast<void>(opdef);
  16851. std::unordered_map<std::string, py::object> state {
  16852. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  16853. };
  16854. return py::cast(state).release().ptr();
  16855. }
  16856. static PyObject* setstate(PyObject* self, PyObject* args) {
  16857. PyObject* dict = PyTuple_GetItem(args, 0);
  16858. if (!dict) return NULL;
  16859. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16860. auto& opdef = reinterpret_cast<PyOp(SetSubtensor)*>(self)->inst();
  16861. static_cast<void>(opdef);
  16862. {
  16863. auto&& iter = state.find("items");
  16864. if (iter != state.end()) {
  16865. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  16866. }
  16867. }
  16868. Py_RETURN_NONE;
  16869. }
  16870. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16871. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  16872. static PyMethodDef py_init_methoddef;
  16873. // };
  16874. PyOpDefEnd(SetSubtensor)
  16875. int PyOp(SetSubtensor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16876. static const char* kwlist[] = {"items", "scope", NULL};
  16877. PyObject *items = NULL, *scope = NULL;
  16878. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  16879. return -1;
  16880. if (items) {
  16881. try {
  16882. // TODO: remove this guard which is used for pybind11 implicit conversion
  16883. py::detail::loader_life_support guard{};
  16884. reinterpret_cast<PyOp(SetSubtensor)*>(self)->inst().items =
  16885. py::cast<decltype(SetSubtensor::items)>(py::handle(items));
  16886. } CATCH_ALL(-1)
  16887. }
  16888. if (scope) {
  16889. try {
  16890. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16891. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16892. } CATCH_ALL(-1)
  16893. }
  16894. return 0;
  16895. }
  16896. PyGetSetDef PyOp(SetSubtensor)::py_getsetters[] = {
  16897. {const_cast<char*>("items"), py_get_generic(SetSubtensor, items), py_set_generic(SetSubtensor, items), const_cast<char*>("items"), NULL},
  16898. {NULL} /* Sentinel */
  16899. };
  16900. PyMethodDef PyOp(SetSubtensor)::tp_methods[] = {
  16901. {const_cast<char*>("__getstate__"), PyOp(SetSubtensor)::getstate, METH_NOARGS, "SetSubtensor getstate"},
  16902. {const_cast<char*>("__setstate__"), PyOp(SetSubtensor)::setstate, METH_VARARGS, "SetSubtensor setstate"},
  16903. {NULL} /* Sentinel */
  16904. };
  16905. PyObject *PyOp(SetSubtensor)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  16906. if (PyOp(SetSubtensor)::py_init(self, args, kwds) < 0) {
  16907. return NULL;
  16908. }
  16909. Py_RETURN_NONE;
  16910. }
  16911. PyMethodDef PyOp(SetSubtensor)::py_init_methoddef = {
  16912. "__init__",
  16913. (PyCFunction)PyOp(SetSubtensor)::py_init_proxy,
  16914. METH_VARARGS | METH_KEYWORDS,
  16915. "__init__(self, items: list[tuple[int, bool, bool, bool, bool]] = ...) -> None\n"
  16916. };
  16917. void _init_py_SetSubtensor(py::module m) {
  16918. using py_op = PyOp(SetSubtensor);
  16919. auto& py_type = PyOpType(SetSubtensor);
  16920. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16921. py_type.tp_name = "megengine.core._imperative_rt.ops.SetSubtensor";
  16922. py_type.tp_basicsize = sizeof(PyOp(SetSubtensor));
  16923. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16924. py_type.tp_doc = "SetSubtensor";
  16925. py_type.tp_base = &PyOpType(OpDef);
  16926. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16927. py_type.tp_new = py_new_generic<py_op>;
  16928. py_type.tp_init = py_op::py_init;
  16929. py_type.tp_methods = py_op::tp_methods;
  16930. py_type.tp_getset = py_op::py_getsetters;
  16931. py_type.tp_dict = PyDict_New();
  16932. PyObject* descr = PyDescr_NewMethod(&PyOpType(SetSubtensor), &PyOp(SetSubtensor)::py_init_methoddef);
  16933. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  16934. mgb_assert(PyType_Ready(&py_type) >= 0);
  16935. PyType_Modified(&py_type);
  16936. m.add_object("SetSubtensor", reinterpret_cast<PyObject*>(&py_type));
  16937. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SetSubtensor::typeinfo(), &py_type).second);
  16938. }
  16939. PyOpDefBegin(ShuffleRNG) // {
  16940. static PyGetSetDef py_getsetters[];
  16941. static PyMethodDef tp_methods[];
  16942. static PyObject* getstate(PyObject* self, PyObject*) {
  16943. auto& opdef = reinterpret_cast<PyOp(ShuffleRNG)*>(self)->inst();
  16944. static_cast<void>(opdef);
  16945. std::unordered_map<std::string, py::object> state {
  16946. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  16947. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  16948. };
  16949. return py::cast(state).release().ptr();
  16950. }
  16951. static PyObject* setstate(PyObject* self, PyObject* args) {
  16952. PyObject* dict = PyTuple_GetItem(args, 0);
  16953. if (!dict) return NULL;
  16954. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16955. auto& opdef = reinterpret_cast<PyOp(ShuffleRNG)*>(self)->inst();
  16956. static_cast<void>(opdef);
  16957. {
  16958. auto&& iter = state.find("seed");
  16959. if (iter != state.end()) {
  16960. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  16961. }
  16962. }
  16963. {
  16964. auto&& iter = state.find("handle");
  16965. if (iter != state.end()) {
  16966. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  16967. }
  16968. }
  16969. Py_RETURN_NONE;
  16970. }
  16971. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16972. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  16973. static PyMethodDef py_init_methoddef;
  16974. // };
  16975. PyOpDefEnd(ShuffleRNG)
  16976. int PyOp(ShuffleRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16977. static const char* kwlist[] = {"seed", "handle", "scope", NULL};
  16978. PyObject *seed = NULL, *handle = NULL, *scope = NULL;
  16979. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &seed, &handle, &scope))
  16980. return -1;
  16981. if (seed) {
  16982. try {
  16983. // TODO: remove this guard which is used for pybind11 implicit conversion
  16984. py::detail::loader_life_support guard{};
  16985. reinterpret_cast<PyOp(ShuffleRNG)*>(self)->inst().seed =
  16986. py::cast<decltype(ShuffleRNG::seed)>(py::handle(seed));
  16987. } CATCH_ALL(-1)
  16988. }
  16989. if (handle) {
  16990. try {
  16991. // TODO: remove this guard which is used for pybind11 implicit conversion
  16992. py::detail::loader_life_support guard{};
  16993. reinterpret_cast<PyOp(ShuffleRNG)*>(self)->inst().handle =
  16994. py::cast<decltype(ShuffleRNG::handle)>(py::handle(handle));
  16995. } CATCH_ALL(-1)
  16996. }
  16997. if (scope) {
  16998. try {
  16999. reinterpret_cast<PyOp(OpDef)*>(self)->op
  17000. ->set_scope(py::cast<std::string>(py::handle(scope)));
  17001. } CATCH_ALL(-1)
  17002. }
  17003. return 0;
  17004. }
  17005. PyGetSetDef PyOp(ShuffleRNG)::py_getsetters[] = {
  17006. {const_cast<char*>("seed"), py_get_generic(ShuffleRNG, seed), py_set_generic(ShuffleRNG, seed), const_cast<char*>("seed"), NULL},
  17007. {const_cast<char*>("handle"), py_get_generic(ShuffleRNG, handle), py_set_generic(ShuffleRNG, handle), const_cast<char*>("handle"), NULL},
  17008. {NULL} /* Sentinel */
  17009. };
  17010. PyMethodDef PyOp(ShuffleRNG)::tp_methods[] = {
  17011. {const_cast<char*>("__getstate__"), PyOp(ShuffleRNG)::getstate, METH_NOARGS, "ShuffleRNG getstate"},
  17012. {const_cast<char*>("__setstate__"), PyOp(ShuffleRNG)::setstate, METH_VARARGS, "ShuffleRNG setstate"},
  17013. {NULL} /* Sentinel */
  17014. };
  17015. PyObject *PyOp(ShuffleRNG)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  17016. if (PyOp(ShuffleRNG)::py_init(self, args, kwds) < 0) {
  17017. return NULL;
  17018. }
  17019. Py_RETURN_NONE;
  17020. }
  17021. PyMethodDef PyOp(ShuffleRNG)::py_init_methoddef = {
  17022. "__init__",
  17023. (PyCFunction)PyOp(ShuffleRNG)::py_init_proxy,
  17024. METH_VARARGS | METH_KEYWORDS,
  17025. "__init__(self, seed: int = ..., handle: int = ...) -> None\n"
  17026. };
  17027. void _init_py_ShuffleRNG(py::module m) {
  17028. using py_op = PyOp(ShuffleRNG);
  17029. auto& py_type = PyOpType(ShuffleRNG);
  17030. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  17031. py_type.tp_name = "megengine.core._imperative_rt.ops.ShuffleRNG";
  17032. py_type.tp_basicsize = sizeof(PyOp(ShuffleRNG));
  17033. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  17034. py_type.tp_doc = "ShuffleRNG";
  17035. py_type.tp_base = &PyOpType(OpDef);
  17036. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  17037. py_type.tp_new = py_new_generic<py_op>;
  17038. py_type.tp_init = py_op::py_init;
  17039. py_type.tp_methods = py_op::tp_methods;
  17040. py_type.tp_getset = py_op::py_getsetters;
  17041. py_type.tp_dict = PyDict_New();
  17042. PyObject* descr = PyDescr_NewMethod(&PyOpType(ShuffleRNG), &PyOp(ShuffleRNG)::py_init_methoddef);
  17043. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  17044. mgb_assert(PyType_Ready(&py_type) >= 0);
  17045. PyType_Modified(&py_type);
  17046. m.add_object("ShuffleRNG", reinterpret_cast<PyObject*>(&py_type));
  17047. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ShuffleRNG::typeinfo(), &py_type).second);
  17048. }
  17049. PyOpDefBegin(SlidingWindowTranspose) // {
  17050. static PyGetSetDef py_getsetters[];
  17051. static PyMethodDef tp_methods[];
  17052. static PyObject* getstate(PyObject* self, PyObject*) {
  17053. auto& opdef = reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst();
  17054. static_cast<void>(opdef);
  17055. std::unordered_map<std::string, py::object> state {
  17056. {"out_h", serialization<decltype(opdef.out_h)>::dump(opdef.out_h)},
  17057. {"out_w", serialization<decltype(opdef.out_w)>::dump(opdef.out_w)},
  17058. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  17059. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  17060. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  17061. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  17062. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  17063. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  17064. {"window_h", serialization<decltype(opdef.window_h)>::dump(opdef.window_h)},
  17065. {"window_w", serialization<decltype(opdef.window_w)>::dump(opdef.window_w)}
  17066. };
  17067. return py::cast(state).release().ptr();
  17068. }
  17069. static PyObject* setstate(PyObject* self, PyObject* args) {
  17070. PyObject* dict = PyTuple_GetItem(args, 0);
  17071. if (!dict) return NULL;
  17072. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  17073. auto& opdef = reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst();
  17074. static_cast<void>(opdef);
  17075. {
  17076. auto&& iter = state.find("out_h");
  17077. if (iter != state.end()) {
  17078. opdef.out_h = serialization<decltype(opdef.out_h)>::load(iter->second);
  17079. }
  17080. }
  17081. {
  17082. auto&& iter = state.find("out_w");
  17083. if (iter != state.end()) {
  17084. opdef.out_w = serialization<decltype(opdef.out_w)>::load(iter->second);
  17085. }
  17086. }
  17087. {
  17088. auto&& iter = state.find("pad_h");
  17089. if (iter != state.end()) {
  17090. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  17091. }
  17092. }
  17093. {
  17094. auto&& iter = state.find("pad_w");
  17095. if (iter != state.end()) {
  17096. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  17097. }
  17098. }
  17099. {
  17100. auto&& iter = state.find("stride_h");
  17101. if (iter != state.end()) {
  17102. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  17103. }
  17104. }
  17105. {
  17106. auto&& iter = state.find("stride_w");
  17107. if (iter != state.end()) {
  17108. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  17109. }
  17110. }
  17111. {
  17112. auto&& iter = state.find("dilate_h");
  17113. if (iter != state.end()) {
  17114. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  17115. }
  17116. }
  17117. {
  17118. auto&& iter = state.find("dilate_w");
  17119. if (iter != state.end()) {
  17120. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  17121. }
  17122. }
  17123. {
  17124. auto&& iter = state.find("window_h");
  17125. if (iter != state.end()) {
  17126. opdef.window_h = serialization<decltype(opdef.window_h)>::load(iter->second);
  17127. }
  17128. }
  17129. {
  17130. auto&& iter = state.find("window_w");
  17131. if (iter != state.end()) {
  17132. opdef.window_w = serialization<decltype(opdef.window_w)>::load(iter->second);
  17133. }
  17134. }
  17135. Py_RETURN_NONE;
  17136. }
  17137. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  17138. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  17139. static PyMethodDef py_init_methoddef;
  17140. // };
  17141. PyOpDefEnd(SlidingWindowTranspose)
  17142. int PyOp(SlidingWindowTranspose)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  17143. static const char* kwlist[] = {"out_h", "out_w", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "window_h", "window_w", "scope", NULL};
  17144. PyObject *out_h = NULL, *out_w = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *window_h = NULL, *window_w = NULL, *scope = NULL;
  17145. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOO", const_cast<char**>(kwlist), &out_h, &out_w, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &window_h, &window_w, &scope))
  17146. return -1;
  17147. if (out_h) {
  17148. try {
  17149. // TODO: remove this guard which is used for pybind11 implicit conversion
  17150. py::detail::loader_life_support guard{};
  17151. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().out_h =
  17152. py::cast<decltype(SlidingWindowTranspose::out_h)>(py::handle(out_h));
  17153. } CATCH_ALL(-1)
  17154. }
  17155. if (out_w) {
  17156. try {
  17157. // TODO: remove this guard which is used for pybind11 implicit conversion
  17158. py::detail::loader_life_support guard{};
  17159. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().out_w =
  17160. py::cast<decltype(SlidingWindowTranspose::out_w)>(py::handle(out_w));
  17161. } CATCH_ALL(-1)
  17162. }
  17163. if (pad_h) {
  17164. try {
  17165. // TODO: remove this guard which is used for pybind11 implicit conversion
  17166. py::detail::loader_life_support guard{};
  17167. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().pad_h =
  17168. py::cast<decltype(SlidingWindowTranspose::pad_h)>(py::handle(pad_h));
  17169. } CATCH_ALL(-1)
  17170. }
  17171. if (pad_w) {
  17172. try {
  17173. // TODO: remove this guard which is used for pybind11 implicit conversion
  17174. py::detail::loader_life_support guard{};
  17175. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().pad_w =
  17176. py::cast<decltype(SlidingWindowTranspose::pad_w)>(py::handle(pad_w));
  17177. } CATCH_ALL(-1)
  17178. }
  17179. if (stride_h) {
  17180. try {
  17181. // TODO: remove this guard which is used for pybind11 implicit conversion
  17182. py::detail::loader_life_support guard{};
  17183. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().stride_h =
  17184. py::cast<decltype(SlidingWindowTranspose::stride_h)>(py::handle(stride_h));
  17185. } CATCH_ALL(-1)
  17186. }
  17187. if (stride_w) {
  17188. try {
  17189. // TODO: remove this guard which is used for pybind11 implicit conversion
  17190. py::detail::loader_life_support guard{};
  17191. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().stride_w =
  17192. py::cast<decltype(SlidingWindowTranspose::stride_w)>(py::handle(stride_w));
  17193. } CATCH_ALL(-1)
  17194. }
  17195. if (dilate_h) {
  17196. try {
  17197. // TODO: remove this guard which is used for pybind11 implicit conversion
  17198. py::detail::loader_life_support guard{};
  17199. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().dilate_h =
  17200. py::cast<decltype(SlidingWindowTranspose::dilate_h)>(py::handle(dilate_h));
  17201. } CATCH_ALL(-1)
  17202. }
  17203. if (dilate_w) {
  17204. try {
  17205. // TODO: remove this guard which is used for pybind11 implicit conversion
  17206. py::detail::loader_life_support guard{};
  17207. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().dilate_w =
  17208. py::cast<decltype(SlidingWindowTranspose::dilate_w)>(py::handle(dilate_w));
  17209. } CATCH_ALL(-1)
  17210. }
  17211. if (window_h) {
  17212. try {
  17213. // TODO: remove this guard which is used for pybind11 implicit conversion
  17214. py::detail::loader_life_support guard{};
  17215. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().window_h =
  17216. py::cast<decltype(SlidingWindowTranspose::window_h)>(py::handle(window_h));
  17217. } CATCH_ALL(-1)
  17218. }
  17219. if (window_w) {
  17220. try {
  17221. // TODO: remove this guard which is used for pybind11 implicit conversion
  17222. py::detail::loader_life_support guard{};
  17223. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().window_w =
  17224. py::cast<decltype(SlidingWindowTranspose::window_w)>(py::handle(window_w));
  17225. } CATCH_ALL(-1)
  17226. }
  17227. if (scope) {
  17228. try {
  17229. reinterpret_cast<PyOp(OpDef)*>(self)->op
  17230. ->set_scope(py::cast<std::string>(py::handle(scope)));
  17231. } CATCH_ALL(-1)
  17232. }
  17233. return 0;
  17234. }
  17235. PyGetSetDef PyOp(SlidingWindowTranspose)::py_getsetters[] = {
  17236. {const_cast<char*>("out_h"), py_get_generic(SlidingWindowTranspose, out_h), py_set_generic(SlidingWindowTranspose, out_h), const_cast<char*>("out_h"), NULL},
  17237. {const_cast<char*>("out_w"), py_get_generic(SlidingWindowTranspose, out_w), py_set_generic(SlidingWindowTranspose, out_w), const_cast<char*>("out_w"), NULL},
  17238. {const_cast<char*>("pad_h"), py_get_generic(SlidingWindowTranspose, pad_h), py_set_generic(SlidingWindowTranspose, pad_h), const_cast<char*>("pad_h"), NULL},
  17239. {const_cast<char*>("pad_w"), py_get_generic(SlidingWindowTranspose, pad_w), py_set_generic(SlidingWindowTranspose, pad_w), const_cast<char*>("pad_w"), NULL},
  17240. {const_cast<char*>("stride_h"), py_get_generic(SlidingWindowTranspose, stride_h), py_set_generic(SlidingWindowTranspose, stride_h), const_cast<char*>("stride_h"), NULL},
  17241. {const_cast<char*>("stride_w"), py_get_generic(SlidingWindowTranspose, stride_w), py_set_generic(SlidingWindowTranspose, stride_w), const_cast<char*>("stride_w"), NULL},
  17242. {const_cast<char*>("dilate_h"), py_get_generic(SlidingWindowTranspose, dilate_h), py_set_generic(SlidingWindowTranspose, dilate_h), const_cast<char*>("dilate_h"), NULL},
  17243. {const_cast<char*>("dilate_w"), py_get_generic(SlidingWindowTranspose, dilate_w), py_set_generic(SlidingWindowTranspose, dilate_w), const_cast<char*>("dilate_w"), NULL},
  17244. {const_cast<char*>("window_h"), py_get_generic(SlidingWindowTranspose, window_h), py_set_generic(SlidingWindowTranspose, window_h), const_cast<char*>("window_h"), NULL},
  17245. {const_cast<char*>("window_w"), py_get_generic(SlidingWindowTranspose, window_w), py_set_generic(SlidingWindowTranspose, window_w), const_cast<char*>("window_w"), NULL},
  17246. {NULL} /* Sentinel */
  17247. };
  17248. PyMethodDef PyOp(SlidingWindowTranspose)::tp_methods[] = {
  17249. {const_cast<char*>("__getstate__"), PyOp(SlidingWindowTranspose)::getstate, METH_NOARGS, "SlidingWindowTranspose getstate"},
  17250. {const_cast<char*>("__setstate__"), PyOp(SlidingWindowTranspose)::setstate, METH_VARARGS, "SlidingWindowTranspose setstate"},
  17251. {NULL} /* Sentinel */
  17252. };
  17253. PyObject *PyOp(SlidingWindowTranspose)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  17254. if (PyOp(SlidingWindowTranspose)::py_init(self, args, kwds) < 0) {
  17255. return NULL;
  17256. }
  17257. Py_RETURN_NONE;
  17258. }
  17259. PyMethodDef PyOp(SlidingWindowTranspose)::py_init_methoddef = {
  17260. "__init__",
  17261. (PyCFunction)PyOp(SlidingWindowTranspose)::py_init_proxy,
  17262. METH_VARARGS | METH_KEYWORDS,
  17263. "__init__(self, out_h: int = ..., out_w: int = ..., pad_h: int = ..., pad_w: int = ..., stride_h: int = ..., stride_w: int = ..., dilate_h: int = ..., dilate_w: int = ..., window_h: int = ..., window_w: int = ...) -> None\n"
  17264. };
  17265. void _init_py_SlidingWindowTranspose(py::module m) {
  17266. using py_op = PyOp(SlidingWindowTranspose);
  17267. auto& py_type = PyOpType(SlidingWindowTranspose);
  17268. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  17269. py_type.tp_name = "megengine.core._imperative_rt.ops.SlidingWindowTranspose";
  17270. py_type.tp_basicsize = sizeof(PyOp(SlidingWindowTranspose));
  17271. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  17272. py_type.tp_doc = "SlidingWindowTranspose";
  17273. py_type.tp_base = &PyOpType(OpDef);
  17274. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  17275. py_type.tp_new = py_new_generic<py_op>;
  17276. py_type.tp_init = py_op::py_init;
  17277. py_type.tp_methods = py_op::tp_methods;
  17278. py_type.tp_getset = py_op::py_getsetters;
  17279. py_type.tp_dict = PyDict_New();
  17280. PyObject* descr = PyDescr_NewMethod(&PyOpType(SlidingWindowTranspose), &PyOp(SlidingWindowTranspose)::py_init_methoddef);
  17281. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  17282. mgb_assert(PyType_Ready(&py_type) >= 0);
  17283. PyType_Modified(&py_type);
  17284. m.add_object("SlidingWindowTranspose", reinterpret_cast<PyObject*>(&py_type));
  17285. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SlidingWindowTranspose::typeinfo(), &py_type).second);
  17286. }
  17287. PyOpDefBegin(Softmax) // {
  17288. static PyGetSetDef py_getsetters[];
  17289. static PyMethodDef tp_methods[];
  17290. static PyObject* getstate(PyObject* self, PyObject*) {
  17291. auto& opdef = reinterpret_cast<PyOp(Softmax)*>(self)->inst();
  17292. static_cast<void>(opdef);
  17293. std::unordered_map<std::string, py::object> state {
  17294. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)}
  17295. };
  17296. return py::cast(state).release().ptr();
  17297. }
  17298. static PyObject* setstate(PyObject* self, PyObject* args) {
  17299. PyObject* dict = PyTuple_GetItem(args, 0);
  17300. if (!dict) return NULL;
  17301. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  17302. auto& opdef = reinterpret_cast<PyOp(Softmax)*>(self)->inst();
  17303. static_cast<void>(opdef);
  17304. {
  17305. auto&& iter = state.find("axis");
  17306. if (iter != state.end()) {
  17307. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  17308. }
  17309. }
  17310. Py_RETURN_NONE;
  17311. }
  17312. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  17313. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  17314. static PyMethodDef py_init_methoddef;
  17315. // };
  17316. PyOpDefEnd(Softmax)
  17317. int PyOp(Softmax)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  17318. static const char* kwlist[] = {"axis", "scope", NULL};
  17319. PyObject *axis = NULL, *scope = NULL;
  17320. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &axis, &scope))
  17321. return -1;
  17322. if (axis) {
  17323. try {
  17324. // TODO: remove this guard which is used for pybind11 implicit conversion
  17325. py::detail::loader_life_support guard{};
  17326. reinterpret_cast<PyOp(Softmax)*>(self)->inst().axis =
  17327. py::cast<decltype(Softmax::axis)>(py::handle(axis));
  17328. } CATCH_ALL(-1)
  17329. }
  17330. if (scope) {
  17331. try {
  17332. reinterpret_cast<PyOp(OpDef)*>(self)->op
  17333. ->set_scope(py::cast<std::string>(py::handle(scope)));
  17334. } CATCH_ALL(-1)
  17335. }
  17336. return 0;
  17337. }
  17338. PyGetSetDef PyOp(Softmax)::py_getsetters[] = {
  17339. {const_cast<char*>("axis"), py_get_generic(Softmax, axis), py_set_generic(Softmax, axis), const_cast<char*>("axis"), NULL},
  17340. {NULL} /* Sentinel */
  17341. };
  17342. PyMethodDef PyOp(Softmax)::tp_methods[] = {
  17343. {const_cast<char*>("__getstate__"), PyOp(Softmax)::getstate, METH_NOARGS, "Softmax getstate"},
  17344. {const_cast<char*>("__setstate__"), PyOp(Softmax)::setstate, METH_VARARGS, "Softmax setstate"},
  17345. {NULL} /* Sentinel */
  17346. };
  17347. PyObject *PyOp(Softmax)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  17348. if (PyOp(Softmax)::py_init(self, args, kwds) < 0) {
  17349. return NULL;
  17350. }
  17351. Py_RETURN_NONE;
  17352. }
  17353. PyMethodDef PyOp(Softmax)::py_init_methoddef = {
  17354. "__init__",
  17355. (PyCFunction)PyOp(Softmax)::py_init_proxy,
  17356. METH_VARARGS | METH_KEYWORDS,
  17357. "__init__(self, axis: int = ...) -> None\n"
  17358. };
  17359. void _init_py_Softmax(py::module m) {
  17360. using py_op = PyOp(Softmax);
  17361. auto& py_type = PyOpType(Softmax);
  17362. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  17363. py_type.tp_name = "megengine.core._imperative_rt.ops.Softmax";
  17364. py_type.tp_basicsize = sizeof(PyOp(Softmax));
  17365. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  17366. py_type.tp_doc = "Softmax";
  17367. py_type.tp_base = &PyOpType(OpDef);
  17368. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  17369. py_type.tp_new = py_new_generic<py_op>;
  17370. py_type.tp_init = py_op::py_init;
  17371. py_type.tp_methods = py_op::tp_methods;
  17372. py_type.tp_getset = py_op::py_getsetters;
  17373. py_type.tp_dict = PyDict_New();
  17374. PyObject* descr = PyDescr_NewMethod(&PyOpType(Softmax), &PyOp(Softmax)::py_init_methoddef);
  17375. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  17376. mgb_assert(PyType_Ready(&py_type) >= 0);
  17377. PyType_Modified(&py_type);
  17378. m.add_object("Softmax", reinterpret_cast<PyObject*>(&py_type));
  17379. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Softmax::typeinfo(), &py_type).second);
  17380. }
  17381. PyOpDefBegin(Split) // {
  17382. static PyGetSetDef py_getsetters[];
  17383. static PyMethodDef tp_methods[];
  17384. static PyObject* getstate(PyObject* self, PyObject*) {
  17385. auto& opdef = reinterpret_cast<PyOp(Split)*>(self)->inst();
  17386. static_cast<void>(opdef);
  17387. std::unordered_map<std::string, py::object> state {
  17388. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  17389. {"nsections", serialization<decltype(opdef.nsections)>::dump(opdef.nsections)}
  17390. };
  17391. return py::cast(state).release().ptr();
  17392. }
  17393. static PyObject* setstate(PyObject* self, PyObject* args) {
  17394. PyObject* dict = PyTuple_GetItem(args, 0);
  17395. if (!dict) return NULL;
  17396. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  17397. auto& opdef = reinterpret_cast<PyOp(Split)*>(self)->inst();
  17398. static_cast<void>(opdef);
  17399. {
  17400. auto&& iter = state.find("axis");
  17401. if (iter != state.end()) {
  17402. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  17403. }
  17404. }
  17405. {
  17406. auto&& iter = state.find("nsections");
  17407. if (iter != state.end()) {
  17408. opdef.nsections = serialization<decltype(opdef.nsections)>::load(iter->second);
  17409. }
  17410. }
  17411. Py_RETURN_NONE;
  17412. }
  17413. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  17414. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  17415. static PyMethodDef py_init_methoddef;
  17416. // };
  17417. PyOpDefEnd(Split)
  17418. int PyOp(Split)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  17419. static const char* kwlist[] = {"axis", "nsections", "scope", NULL};
  17420. PyObject *axis = NULL, *nsections = NULL, *scope = NULL;
  17421. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &axis, &nsections, &scope))
  17422. return -1;
  17423. if (axis) {
  17424. try {
  17425. // TODO: remove this guard which is used for pybind11 implicit conversion
  17426. py::detail::loader_life_support guard{};
  17427. reinterpret_cast<PyOp(Split)*>(self)->inst().axis =
  17428. py::cast<decltype(Split::axis)>(py::handle(axis));
  17429. } CATCH_ALL(-1)
  17430. }
  17431. if (nsections) {
  17432. try {
  17433. // TODO: remove this guard which is used for pybind11 implicit conversion
  17434. py::detail::loader_life_support guard{};
  17435. reinterpret_cast<PyOp(Split)*>(self)->inst().nsections =
  17436. py::cast<decltype(Split::nsections)>(py::handle(nsections));
  17437. } CATCH_ALL(-1)
  17438. }
  17439. if (scope) {
  17440. try {
  17441. reinterpret_cast<PyOp(OpDef)*>(self)->op
  17442. ->set_scope(py::cast<std::string>(py::handle(scope)));
  17443. } CATCH_ALL(-1)
  17444. }
  17445. return 0;
  17446. }
  17447. PyGetSetDef PyOp(Split)::py_getsetters[] = {
  17448. {const_cast<char*>("axis"), py_get_generic(Split, axis), py_set_generic(Split, axis), const_cast<char*>("axis"), NULL},
  17449. {const_cast<char*>("nsections"), py_get_generic(Split, nsections), py_set_generic(Split, nsections), const_cast<char*>("nsections"), NULL},
  17450. {NULL} /* Sentinel */
  17451. };
  17452. PyMethodDef PyOp(Split)::tp_methods[] = {
  17453. {const_cast<char*>("__getstate__"), PyOp(Split)::getstate, METH_NOARGS, "Split getstate"},
  17454. {const_cast<char*>("__setstate__"), PyOp(Split)::setstate, METH_VARARGS, "Split setstate"},
  17455. {NULL} /* Sentinel */
  17456. };
  17457. PyObject *PyOp(Split)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  17458. if (PyOp(Split)::py_init(self, args, kwds) < 0) {
  17459. return NULL;
  17460. }
  17461. Py_RETURN_NONE;
  17462. }
  17463. PyMethodDef PyOp(Split)::py_init_methoddef = {
  17464. "__init__",
  17465. (PyCFunction)PyOp(Split)::py_init_proxy,
  17466. METH_VARARGS | METH_KEYWORDS,
  17467. "__init__(self, axis: int = ..., nsections: int = ...) -> None\n"
  17468. };
  17469. void _init_py_Split(py::module m) {
  17470. using py_op = PyOp(Split);
  17471. auto& py_type = PyOpType(Split);
  17472. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  17473. py_type.tp_name = "megengine.core._imperative_rt.ops.Split";
  17474. py_type.tp_basicsize = sizeof(PyOp(Split));
  17475. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  17476. py_type.tp_doc = "Split";
  17477. py_type.tp_base = &PyOpType(OpDef);
  17478. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  17479. py_type.tp_new = py_new_generic<py_op>;
  17480. py_type.tp_init = py_op::py_init;
  17481. py_type.tp_methods = py_op::tp_methods;
  17482. py_type.tp_getset = py_op::py_getsetters;
  17483. py_type.tp_dict = PyDict_New();
  17484. PyObject* descr = PyDescr_NewMethod(&PyOpType(Split), &PyOp(Split)::py_init_methoddef);
  17485. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  17486. mgb_assert(PyType_Ready(&py_type) >= 0);
  17487. PyType_Modified(&py_type);
  17488. m.add_object("Split", reinterpret_cast<PyObject*>(&py_type));
  17489. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Split::typeinfo(), &py_type).second);
  17490. }
  17491. PyOpDefBegin(Subtensor) // {
  17492. static PyGetSetDef py_getsetters[];
  17493. static PyMethodDef tp_methods[];
  17494. static PyObject* getstate(PyObject* self, PyObject*) {
  17495. auto& opdef = reinterpret_cast<PyOp(Subtensor)*>(self)->inst();
  17496. static_cast<void>(opdef);
  17497. std::unordered_map<std::string, py::object> state {
  17498. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  17499. };
  17500. return py::cast(state).release().ptr();
  17501. }
  17502. static PyObject* setstate(PyObject* self, PyObject* args) {
  17503. PyObject* dict = PyTuple_GetItem(args, 0);
  17504. if (!dict) return NULL;
  17505. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  17506. auto& opdef = reinterpret_cast<PyOp(Subtensor)*>(self)->inst();
  17507. static_cast<void>(opdef);
  17508. {
  17509. auto&& iter = state.find("items");
  17510. if (iter != state.end()) {
  17511. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  17512. }
  17513. }
  17514. Py_RETURN_NONE;
  17515. }
  17516. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  17517. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  17518. static PyMethodDef py_init_methoddef;
  17519. // };
  17520. PyOpDefEnd(Subtensor)
  17521. int PyOp(Subtensor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  17522. static const char* kwlist[] = {"items", "scope", NULL};
  17523. PyObject *items = NULL, *scope = NULL;
  17524. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  17525. return -1;
  17526. if (items) {
  17527. try {
  17528. // TODO: remove this guard which is used for pybind11 implicit conversion
  17529. py::detail::loader_life_support guard{};
  17530. reinterpret_cast<PyOp(Subtensor)*>(self)->inst().items =
  17531. py::cast<decltype(Subtensor::items)>(py::handle(items));
  17532. } CATCH_ALL(-1)
  17533. }
  17534. if (scope) {
  17535. try {
  17536. reinterpret_cast<PyOp(OpDef)*>(self)->op
  17537. ->set_scope(py::cast<std::string>(py::handle(scope)));
  17538. } CATCH_ALL(-1)
  17539. }
  17540. return 0;
  17541. }
  17542. PyGetSetDef PyOp(Subtensor)::py_getsetters[] = {
  17543. {const_cast<char*>("items"), py_get_generic(Subtensor, items), py_set_generic(Subtensor, items), const_cast<char*>("items"), NULL},
  17544. {NULL} /* Sentinel */
  17545. };
  17546. PyMethodDef PyOp(Subtensor)::tp_methods[] = {
  17547. {const_cast<char*>("__getstate__"), PyOp(Subtensor)::getstate, METH_NOARGS, "Subtensor getstate"},
  17548. {const_cast<char*>("__setstate__"), PyOp(Subtensor)::setstate, METH_VARARGS, "Subtensor setstate"},
  17549. {NULL} /* Sentinel */
  17550. };
  17551. PyObject *PyOp(Subtensor)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  17552. if (PyOp(Subtensor)::py_init(self, args, kwds) < 0) {
  17553. return NULL;
  17554. }
  17555. Py_RETURN_NONE;
  17556. }
  17557. PyMethodDef PyOp(Subtensor)::py_init_methoddef = {
  17558. "__init__",
  17559. (PyCFunction)PyOp(Subtensor)::py_init_proxy,
  17560. METH_VARARGS | METH_KEYWORDS,
  17561. "__init__(self, items: list[tuple[int, bool, bool, bool, bool]] = ...) -> None\n"
  17562. };
  17563. void _init_py_Subtensor(py::module m) {
  17564. using py_op = PyOp(Subtensor);
  17565. auto& py_type = PyOpType(Subtensor);
  17566. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  17567. py_type.tp_name = "megengine.core._imperative_rt.ops.Subtensor";
  17568. py_type.tp_basicsize = sizeof(PyOp(Subtensor));
  17569. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  17570. py_type.tp_doc = "Subtensor";
  17571. py_type.tp_base = &PyOpType(OpDef);
  17572. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  17573. py_type.tp_new = py_new_generic<py_op>;
  17574. py_type.tp_init = py_op::py_init;
  17575. py_type.tp_methods = py_op::tp_methods;
  17576. py_type.tp_getset = py_op::py_getsetters;
  17577. py_type.tp_dict = PyDict_New();
  17578. PyObject* descr = PyDescr_NewMethod(&PyOpType(Subtensor), &PyOp(Subtensor)::py_init_methoddef);
  17579. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  17580. mgb_assert(PyType_Ready(&py_type) >= 0);
  17581. PyType_Modified(&py_type);
  17582. m.add_object("Subtensor", reinterpret_cast<PyObject*>(&py_type));
  17583. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Subtensor::typeinfo(), &py_type).second);
  17584. }
  17585. PyOpDefBegin(TQT) // {
  17586. static PyGetSetDef py_getsetters[];
  17587. static PyMethodDef tp_methods[];
  17588. static PyObject* getstate(PyObject* self, PyObject*) {
  17589. auto& opdef = reinterpret_cast<PyOp(TQT)*>(self)->inst();
  17590. static_cast<void>(opdef);
  17591. std::unordered_map<std::string, py::object> state {
  17592. {"qmin", serialization<decltype(opdef.qmin)>::dump(opdef.qmin)},
  17593. {"qmax", serialization<decltype(opdef.qmax)>::dump(opdef.qmax)}
  17594. };
  17595. return py::cast(state).release().ptr();
  17596. }
  17597. static PyObject* setstate(PyObject* self, PyObject* args) {
  17598. PyObject* dict = PyTuple_GetItem(args, 0);
  17599. if (!dict) return NULL;
  17600. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  17601. auto& opdef = reinterpret_cast<PyOp(TQT)*>(self)->inst();
  17602. static_cast<void>(opdef);
  17603. {
  17604. auto&& iter = state.find("qmin");
  17605. if (iter != state.end()) {
  17606. opdef.qmin = serialization<decltype(opdef.qmin)>::load(iter->second);
  17607. }
  17608. }
  17609. {
  17610. auto&& iter = state.find("qmax");
  17611. if (iter != state.end()) {
  17612. opdef.qmax = serialization<decltype(opdef.qmax)>::load(iter->second);
  17613. }
  17614. }
  17615. Py_RETURN_NONE;
  17616. }
  17617. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  17618. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  17619. static PyMethodDef py_init_methoddef;
  17620. // };
  17621. PyOpDefEnd(TQT)
  17622. int PyOp(TQT)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  17623. static const char* kwlist[] = {"qmin", "qmax", "scope", NULL};
  17624. PyObject *qmin = NULL, *qmax = NULL, *scope = NULL;
  17625. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &qmin, &qmax, &scope))
  17626. return -1;
  17627. if (qmin) {
  17628. try {
  17629. // TODO: remove this guard which is used for pybind11 implicit conversion
  17630. py::detail::loader_life_support guard{};
  17631. reinterpret_cast<PyOp(TQT)*>(self)->inst().qmin =
  17632. py::cast<decltype(TQT::qmin)>(py::handle(qmin));
  17633. } CATCH_ALL(-1)
  17634. }
  17635. if (qmax) {
  17636. try {
  17637. // TODO: remove this guard which is used for pybind11 implicit conversion
  17638. py::detail::loader_life_support guard{};
  17639. reinterpret_cast<PyOp(TQT)*>(self)->inst().qmax =
  17640. py::cast<decltype(TQT::qmax)>(py::handle(qmax));
  17641. } CATCH_ALL(-1)
  17642. }
  17643. if (scope) {
  17644. try {
  17645. reinterpret_cast<PyOp(OpDef)*>(self)->op
  17646. ->set_scope(py::cast<std::string>(py::handle(scope)));
  17647. } CATCH_ALL(-1)
  17648. }
  17649. return 0;
  17650. }
  17651. PyGetSetDef PyOp(TQT)::py_getsetters[] = {
  17652. {const_cast<char*>("qmin"), py_get_generic(TQT, qmin), py_set_generic(TQT, qmin), const_cast<char*>("qmin"), NULL},
  17653. {const_cast<char*>("qmax"), py_get_generic(TQT, qmax), py_set_generic(TQT, qmax), const_cast<char*>("qmax"), NULL},
  17654. {NULL} /* Sentinel */
  17655. };
  17656. PyMethodDef PyOp(TQT)::tp_methods[] = {
  17657. {const_cast<char*>("__getstate__"), PyOp(TQT)::getstate, METH_NOARGS, "TQT getstate"},
  17658. {const_cast<char*>("__setstate__"), PyOp(TQT)::setstate, METH_VARARGS, "TQT setstate"},
  17659. {NULL} /* Sentinel */
  17660. };
  17661. PyObject *PyOp(TQT)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  17662. if (PyOp(TQT)::py_init(self, args, kwds) < 0) {
  17663. return NULL;
  17664. }
  17665. Py_RETURN_NONE;
  17666. }
  17667. PyMethodDef PyOp(TQT)::py_init_methoddef = {
  17668. "__init__",
  17669. (PyCFunction)PyOp(TQT)::py_init_proxy,
  17670. METH_VARARGS | METH_KEYWORDS,
  17671. "__init__(self, qmin: int = ..., qmax: int = ...) -> None\n"
  17672. };
  17673. void _init_py_TQT(py::module m) {
  17674. using py_op = PyOp(TQT);
  17675. auto& py_type = PyOpType(TQT);
  17676. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  17677. py_type.tp_name = "megengine.core._imperative_rt.ops.TQT";
  17678. py_type.tp_basicsize = sizeof(PyOp(TQT));
  17679. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  17680. py_type.tp_doc = "TQT";
  17681. py_type.tp_base = &PyOpType(OpDef);
  17682. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  17683. py_type.tp_new = py_new_generic<py_op>;
  17684. py_type.tp_init = py_op::py_init;
  17685. py_type.tp_methods = py_op::tp_methods;
  17686. py_type.tp_getset = py_op::py_getsetters;
  17687. py_type.tp_dict = PyDict_New();
  17688. PyObject* descr = PyDescr_NewMethod(&PyOpType(TQT), &PyOp(TQT)::py_init_methoddef);
  17689. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  17690. mgb_assert(PyType_Ready(&py_type) >= 0);
  17691. PyType_Modified(&py_type);
  17692. m.add_object("TQT", reinterpret_cast<PyObject*>(&py_type));
  17693. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TQT::typeinfo(), &py_type).second);
  17694. }
  17695. PyOpDefBegin(TensorRTRuntime) // {
  17696. static PyGetSetDef py_getsetters[];
  17697. static PyMethodDef tp_methods[];
  17698. static PyObject* getstate(PyObject* self, PyObject*) {
  17699. auto& opdef = reinterpret_cast<PyOp(TensorRTRuntime)*>(self)->inst();
  17700. static_cast<void>(opdef);
  17701. std::unordered_map<std::string, py::object> state {
  17702. {"buf", serialization<decltype(opdef.buf)>::dump(opdef.buf)},
  17703. {"buf_size", serialization<decltype(opdef.buf_size)>::dump(opdef.buf_size)}
  17704. };
  17705. return py::cast(state).release().ptr();
  17706. }
  17707. static PyObject* setstate(PyObject* self, PyObject* args) {
  17708. PyObject* dict = PyTuple_GetItem(args, 0);
  17709. if (!dict) return NULL;
  17710. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  17711. auto& opdef = reinterpret_cast<PyOp(TensorRTRuntime)*>(self)->inst();
  17712. static_cast<void>(opdef);
  17713. {
  17714. auto&& iter = state.find("buf");
  17715. if (iter != state.end()) {
  17716. opdef.buf = serialization<decltype(opdef.buf)>::load(iter->second);
  17717. }
  17718. }
  17719. {
  17720. auto&& iter = state.find("buf_size");
  17721. if (iter != state.end()) {
  17722. opdef.buf_size = serialization<decltype(opdef.buf_size)>::load(iter->second);
  17723. }
  17724. }
  17725. Py_RETURN_NONE;
  17726. }
  17727. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  17728. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  17729. static PyMethodDef py_init_methoddef;
  17730. // };
  17731. PyOpDefEnd(TensorRTRuntime)
  17732. int PyOp(TensorRTRuntime)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  17733. static const char* kwlist[] = {"buf", "buf_size", "scope", NULL};
  17734. PyObject *buf = NULL, *buf_size = NULL, *scope = NULL;
  17735. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &buf, &buf_size, &scope))
  17736. return -1;
  17737. if (buf) {
  17738. try {
  17739. // TODO: remove this guard which is used for pybind11 implicit conversion
  17740. py::detail::loader_life_support guard{};
  17741. reinterpret_cast<PyOp(TensorRTRuntime)*>(self)->inst().buf =
  17742. py::cast<decltype(TensorRTRuntime::buf)>(py::handle(buf));
  17743. } CATCH_ALL(-1)
  17744. }
  17745. if (buf_size) {
  17746. try {
  17747. // TODO: remove this guard which is used for pybind11 implicit conversion
  17748. py::detail::loader_life_support guard{};
  17749. reinterpret_cast<PyOp(TensorRTRuntime)*>(self)->inst().buf_size =
  17750. py::cast<decltype(TensorRTRuntime::buf_size)>(py::handle(buf_size));
  17751. } CATCH_ALL(-1)
  17752. }
  17753. if (scope) {
  17754. try {
  17755. reinterpret_cast<PyOp(OpDef)*>(self)->op
  17756. ->set_scope(py::cast<std::string>(py::handle(scope)));
  17757. } CATCH_ALL(-1)
  17758. }
  17759. return 0;
  17760. }
  17761. PyGetSetDef PyOp(TensorRTRuntime)::py_getsetters[] = {
  17762. {const_cast<char*>("buf"), py_get_generic(TensorRTRuntime, buf), py_set_generic(TensorRTRuntime, buf), const_cast<char*>("buf"), NULL},
  17763. {const_cast<char*>("buf_size"), py_get_generic(TensorRTRuntime, buf_size), py_set_generic(TensorRTRuntime, buf_size), const_cast<char*>("buf_size"), NULL},
  17764. {NULL} /* Sentinel */
  17765. };
  17766. PyMethodDef PyOp(TensorRTRuntime)::tp_methods[] = {
  17767. {const_cast<char*>("__getstate__"), PyOp(TensorRTRuntime)::getstate, METH_NOARGS, "TensorRTRuntime getstate"},
  17768. {const_cast<char*>("__setstate__"), PyOp(TensorRTRuntime)::setstate, METH_VARARGS, "TensorRTRuntime setstate"},
  17769. {NULL} /* Sentinel */
  17770. };
  17771. PyObject *PyOp(TensorRTRuntime)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  17772. if (PyOp(TensorRTRuntime)::py_init(self, args, kwds) < 0) {
  17773. return NULL;
  17774. }
  17775. Py_RETURN_NONE;
  17776. }
  17777. PyMethodDef PyOp(TensorRTRuntime)::py_init_methoddef = {
  17778. "__init__",
  17779. (PyCFunction)PyOp(TensorRTRuntime)::py_init_proxy,
  17780. METH_VARARGS | METH_KEYWORDS,
  17781. "__init__(self, buf: str = ..., buf_size: int = ...) -> None\n"
  17782. };
  17783. void _init_py_TensorRTRuntime(py::module m) {
  17784. using py_op = PyOp(TensorRTRuntime);
  17785. auto& py_type = PyOpType(TensorRTRuntime);
  17786. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  17787. py_type.tp_name = "megengine.core._imperative_rt.ops.TensorRTRuntime";
  17788. py_type.tp_basicsize = sizeof(PyOp(TensorRTRuntime));
  17789. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  17790. py_type.tp_doc = "TensorRTRuntime";
  17791. py_type.tp_base = &PyOpType(OpDef);
  17792. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  17793. py_type.tp_new = py_new_generic<py_op>;
  17794. py_type.tp_init = py_op::py_init;
  17795. py_type.tp_methods = py_op::tp_methods;
  17796. py_type.tp_getset = py_op::py_getsetters;
  17797. py_type.tp_dict = PyDict_New();
  17798. PyObject* descr = PyDescr_NewMethod(&PyOpType(TensorRTRuntime), &PyOp(TensorRTRuntime)::py_init_methoddef);
  17799. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  17800. mgb_assert(PyType_Ready(&py_type) >= 0);
  17801. PyType_Modified(&py_type);
  17802. m.add_object("TensorRTRuntime", reinterpret_cast<PyObject*>(&py_type));
  17803. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TensorRTRuntime::typeinfo(), &py_type).second);
  17804. }
  17805. template<> struct EnumTrait<TopK::Mode> {
  17806. static constexpr const char *name = "TopK.Mode";
  17807. static constexpr std::underlying_type_t<TopK::Mode> max = 3 - 1;
  17808. };
  17809. template<> PyTypeObject* EnumWrapper<TopK::Mode>::type = nullptr;
  17810. template<> const char*
  17811. EnumWrapper<TopK::Mode>::members[] = {"KTH_ONLY", "VALUE_IDX_NOSORT", "VALUE_IDX_SORTED"};
  17812. template<> std::unordered_map<std::string, TopK::Mode>
  17813. EnumWrapper<TopK::Mode>::mem2value = {{normalize_enum("KTH_ONLY"), TopK::Mode::KTH_ONLY}, {normalize_enum("VALUE_IDX_NOSORT"), TopK::Mode::VALUE_IDX_NOSORT}, {normalize_enum("VALUE_IDX_SORTED"), TopK::Mode::VALUE_IDX_SORTED}};
  17814. template<> PyObject* EnumWrapper<TopK::Mode>::pyobj_insts[3] = {nullptr};
  17815. void _init_py_TopK_Mode(PyTypeObject& py_type) {
  17816. auto& e_type = EnumWrapper<TopK::Mode>::type;
  17817. static PyMethodDef tp_methods[] = {
  17818. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<TopK::Mode>::py_dump, METH_NOARGS, NULL},
  17819. {NULL} /* Sentinel */
  17820. };
  17821. static PyType_Slot slots[] = {
  17822. {Py_tp_repr, (void*)EnumWrapper<TopK::Mode>::py_repr},
  17823. {Py_tp_richcompare, (void*)EnumWrapper<TopK::Mode>::tp_richcompare},
  17824. {Py_tp_methods, tp_methods},
  17825. {0, NULL}
  17826. };
  17827. static PyType_Spec spec = {
  17828. // name
  17829. "megengine.core._imperative_rt.ops.TopK.Mode",
  17830. // basicsize
  17831. sizeof(EnumWrapper<TopK::Mode>),
  17832. // itemsize
  17833. 0,
  17834. // flags
  17835. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  17836. // slots
  17837. slots
  17838. };
  17839. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  17840. mgb_assert(
  17841. e_type->tp_setattro(
  17842. reinterpret_cast<PyObject*>(e_type),
  17843. py::cast("__name__").release().ptr(),
  17844. py::cast("Mode").release().ptr()) >= 0);
  17845. mgb_assert(
  17846. e_type->tp_setattro(
  17847. reinterpret_cast<PyObject*>(e_type),
  17848. py::cast("__module__").release().ptr(),
  17849. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  17850. mgb_assert(
  17851. e_type->tp_setattro(
  17852. reinterpret_cast<PyObject*>(e_type),
  17853. py::cast("__qualname__").release().ptr(),
  17854. py::cast("TopK.Mode").release().ptr()) >= 0);
  17855. {
  17856. PyObject* inst = e_type->tp_alloc(e_type, 0);
  17857. reinterpret_cast<EnumWrapper<TopK::Mode>*>(inst)->value = TopK::Mode::KTH_ONLY;
  17858. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "KTH_ONLY", inst) >= 0);
  17859. EnumWrapper<TopK::Mode>::pyobj_insts[0] = inst;
  17860. }{
  17861. PyObject* inst = e_type->tp_alloc(e_type, 0);
  17862. reinterpret_cast<EnumWrapper<TopK::Mode>*>(inst)->value = TopK::Mode::VALUE_IDX_NOSORT;
  17863. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "VALUE_IDX_NOSORT", inst) >= 0);
  17864. EnumWrapper<TopK::Mode>::pyobj_insts[1] = inst;
  17865. }{
  17866. PyObject* inst = e_type->tp_alloc(e_type, 0);
  17867. reinterpret_cast<EnumWrapper<TopK::Mode>*>(inst)->value = TopK::Mode::VALUE_IDX_SORTED;
  17868. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "VALUE_IDX_SORTED", inst) >= 0);
  17869. EnumWrapper<TopK::Mode>::pyobj_insts[2] = inst;
  17870. }
  17871. Py_INCREF(e_type);
  17872. mgb_assert(PyDict_SetItemString(
  17873. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  17874. }
  17875. PyOpDefBegin(TopK) // {
  17876. static PyGetSetDef py_getsetters[];
  17877. static PyMethodDef tp_methods[];
  17878. static PyObject* getstate(PyObject* self, PyObject*) {
  17879. auto& opdef = reinterpret_cast<PyOp(TopK)*>(self)->inst();
  17880. static_cast<void>(opdef);
  17881. std::unordered_map<std::string, py::object> state {
  17882. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)}
  17883. };
  17884. return py::cast(state).release().ptr();
  17885. }
  17886. static PyObject* setstate(PyObject* self, PyObject* args) {
  17887. PyObject* dict = PyTuple_GetItem(args, 0);
  17888. if (!dict) return NULL;
  17889. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  17890. auto& opdef = reinterpret_cast<PyOp(TopK)*>(self)->inst();
  17891. static_cast<void>(opdef);
  17892. {
  17893. auto&& iter = state.find("mode");
  17894. if (iter != state.end()) {
  17895. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  17896. }
  17897. }
  17898. Py_RETURN_NONE;
  17899. }
  17900. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  17901. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  17902. static PyMethodDef py_init_methoddef;
  17903. // };
  17904. PyOpDefEnd(TopK)
  17905. int PyOp(TopK)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  17906. static const char* kwlist[] = {"mode", "scope", NULL};
  17907. PyObject *mode = NULL, *scope = NULL;
  17908. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &mode, &scope))
  17909. return -1;
  17910. if (mode) {
  17911. try {
  17912. // TODO: remove this guard which is used for pybind11 implicit conversion
  17913. py::detail::loader_life_support guard{};
  17914. reinterpret_cast<PyOp(TopK)*>(self)->inst().mode =
  17915. py::cast<decltype(TopK::mode)>(py::handle(mode));
  17916. } CATCH_ALL(-1)
  17917. }
  17918. if (scope) {
  17919. try {
  17920. reinterpret_cast<PyOp(OpDef)*>(self)->op
  17921. ->set_scope(py::cast<std::string>(py::handle(scope)));
  17922. } CATCH_ALL(-1)
  17923. }
  17924. return 0;
  17925. }
  17926. PyGetSetDef PyOp(TopK)::py_getsetters[] = {
  17927. {const_cast<char*>("mode"), py_get_generic(TopK, mode), py_set_generic(TopK, mode), const_cast<char*>("mode"), NULL},
  17928. {NULL} /* Sentinel */
  17929. };
  17930. PyMethodDef PyOp(TopK)::tp_methods[] = {
  17931. {const_cast<char*>("__getstate__"), PyOp(TopK)::getstate, METH_NOARGS, "TopK getstate"},
  17932. {const_cast<char*>("__setstate__"), PyOp(TopK)::setstate, METH_VARARGS, "TopK setstate"},
  17933. {NULL} /* Sentinel */
  17934. };
  17935. PyObject *PyOp(TopK)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  17936. if (PyOp(TopK)::py_init(self, args, kwds) < 0) {
  17937. return NULL;
  17938. }
  17939. Py_RETURN_NONE;
  17940. }
  17941. PyMethodDef PyOp(TopK)::py_init_methoddef = {
  17942. "__init__",
  17943. (PyCFunction)PyOp(TopK)::py_init_proxy,
  17944. METH_VARARGS | METH_KEYWORDS,
  17945. "__init__(self, mode: Union[str, Mode] = ...) -> None\n"
  17946. };
  17947. void _init_py_TopK(py::module m) {
  17948. using py_op = PyOp(TopK);
  17949. auto& py_type = PyOpType(TopK);
  17950. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  17951. py_type.tp_name = "megengine.core._imperative_rt.ops.TopK";
  17952. py_type.tp_basicsize = sizeof(PyOp(TopK));
  17953. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  17954. py_type.tp_doc = "TopK";
  17955. py_type.tp_base = &PyOpType(OpDef);
  17956. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  17957. py_type.tp_new = py_new_generic<py_op>;
  17958. py_type.tp_init = py_op::py_init;
  17959. py_type.tp_methods = py_op::tp_methods;
  17960. py_type.tp_getset = py_op::py_getsetters;
  17961. py_type.tp_dict = PyDict_New();
  17962. PyObject* descr = PyDescr_NewMethod(&PyOpType(TopK), &PyOp(TopK)::py_init_methoddef);
  17963. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  17964. mgb_assert(PyType_Ready(&py_type) >= 0);
  17965. _init_py_TopK_Mode(py_type);
  17966. PyType_Modified(&py_type);
  17967. m.add_object("TopK", reinterpret_cast<PyObject*>(&py_type));
  17968. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TopK::typeinfo(), &py_type).second);
  17969. }
  17970. PyOpDefBegin(TypeCvt) // {
  17971. static PyGetSetDef py_getsetters[];
  17972. static PyMethodDef tp_methods[];
  17973. static PyObject* getstate(PyObject* self, PyObject*) {
  17974. auto& opdef = reinterpret_cast<PyOp(TypeCvt)*>(self)->inst();
  17975. static_cast<void>(opdef);
  17976. std::unordered_map<std::string, py::object> state {
  17977. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)}
  17978. };
  17979. return py::cast(state).release().ptr();
  17980. }
  17981. static PyObject* setstate(PyObject* self, PyObject* args) {
  17982. PyObject* dict = PyTuple_GetItem(args, 0);
  17983. if (!dict) return NULL;
  17984. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  17985. auto& opdef = reinterpret_cast<PyOp(TypeCvt)*>(self)->inst();
  17986. static_cast<void>(opdef);
  17987. {
  17988. auto&& iter = state.find("dtype");
  17989. if (iter != state.end()) {
  17990. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  17991. }
  17992. }
  17993. Py_RETURN_NONE;
  17994. }
  17995. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  17996. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  17997. static PyMethodDef py_init_methoddef;
  17998. // };
  17999. PyOpDefEnd(TypeCvt)
  18000. int PyOp(TypeCvt)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  18001. static const char* kwlist[] = {"dtype", "scope", NULL};
  18002. PyObject *dtype = NULL, *scope = NULL;
  18003. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &dtype, &scope))
  18004. return -1;
  18005. if (dtype) {
  18006. try {
  18007. // TODO: remove this guard which is used for pybind11 implicit conversion
  18008. py::detail::loader_life_support guard{};
  18009. reinterpret_cast<PyOp(TypeCvt)*>(self)->inst().dtype =
  18010. py::cast<decltype(TypeCvt::dtype)>(py::handle(dtype));
  18011. } CATCH_ALL(-1)
  18012. }
  18013. if (scope) {
  18014. try {
  18015. reinterpret_cast<PyOp(OpDef)*>(self)->op
  18016. ->set_scope(py::cast<std::string>(py::handle(scope)));
  18017. } CATCH_ALL(-1)
  18018. }
  18019. return 0;
  18020. }
  18021. PyGetSetDef PyOp(TypeCvt)::py_getsetters[] = {
  18022. {const_cast<char*>("dtype"), py_get_generic(TypeCvt, dtype), py_set_generic(TypeCvt, dtype), const_cast<char*>("dtype"), NULL},
  18023. {NULL} /* Sentinel */
  18024. };
  18025. PyMethodDef PyOp(TypeCvt)::tp_methods[] = {
  18026. {const_cast<char*>("__getstate__"), PyOp(TypeCvt)::getstate, METH_NOARGS, "TypeCvt getstate"},
  18027. {const_cast<char*>("__setstate__"), PyOp(TypeCvt)::setstate, METH_VARARGS, "TypeCvt setstate"},
  18028. {NULL} /* Sentinel */
  18029. };
  18030. PyObject *PyOp(TypeCvt)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  18031. if (PyOp(TypeCvt)::py_init(self, args, kwds) < 0) {
  18032. return NULL;
  18033. }
  18034. Py_RETURN_NONE;
  18035. }
  18036. PyMethodDef PyOp(TypeCvt)::py_init_methoddef = {
  18037. "__init__",
  18038. (PyCFunction)PyOp(TypeCvt)::py_init_proxy,
  18039. METH_VARARGS | METH_KEYWORDS,
  18040. "__init__(self, dtype: str = ...) -> None\n"
  18041. };
  18042. void _init_py_TypeCvt(py::module m) {
  18043. using py_op = PyOp(TypeCvt);
  18044. auto& py_type = PyOpType(TypeCvt);
  18045. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  18046. py_type.tp_name = "megengine.core._imperative_rt.ops.TypeCvt";
  18047. py_type.tp_basicsize = sizeof(PyOp(TypeCvt));
  18048. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  18049. py_type.tp_doc = "TypeCvt";
  18050. py_type.tp_base = &PyOpType(OpDef);
  18051. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  18052. py_type.tp_new = py_new_generic<py_op>;
  18053. py_type.tp_init = py_op::py_init;
  18054. py_type.tp_methods = py_op::tp_methods;
  18055. py_type.tp_getset = py_op::py_getsetters;
  18056. py_type.tp_dict = PyDict_New();
  18057. PyObject* descr = PyDescr_NewMethod(&PyOpType(TypeCvt), &PyOp(TypeCvt)::py_init_methoddef);
  18058. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  18059. mgb_assert(PyType_Ready(&py_type) >= 0);
  18060. PyType_Modified(&py_type);
  18061. m.add_object("TypeCvt", reinterpret_cast<PyObject*>(&py_type));
  18062. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TypeCvt::typeinfo(), &py_type).second);
  18063. }
  18064. PyOpDefBegin(UniformRNG) // {
  18065. static PyGetSetDef py_getsetters[];
  18066. static PyMethodDef tp_methods[];
  18067. static PyObject* getstate(PyObject* self, PyObject*) {
  18068. auto& opdef = reinterpret_cast<PyOp(UniformRNG)*>(self)->inst();
  18069. static_cast<void>(opdef);
  18070. std::unordered_map<std::string, py::object> state {
  18071. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  18072. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  18073. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  18074. };
  18075. return py::cast(state).release().ptr();
  18076. }
  18077. static PyObject* setstate(PyObject* self, PyObject* args) {
  18078. PyObject* dict = PyTuple_GetItem(args, 0);
  18079. if (!dict) return NULL;
  18080. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  18081. auto& opdef = reinterpret_cast<PyOp(UniformRNG)*>(self)->inst();
  18082. static_cast<void>(opdef);
  18083. {
  18084. auto&& iter = state.find("seed");
  18085. if (iter != state.end()) {
  18086. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  18087. }
  18088. }
  18089. {
  18090. auto&& iter = state.find("dtype");
  18091. if (iter != state.end()) {
  18092. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  18093. }
  18094. }
  18095. {
  18096. auto&& iter = state.find("handle");
  18097. if (iter != state.end()) {
  18098. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  18099. }
  18100. }
  18101. Py_RETURN_NONE;
  18102. }
  18103. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  18104. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  18105. static PyMethodDef py_init_methoddef;
  18106. // };
  18107. PyOpDefEnd(UniformRNG)
  18108. int PyOp(UniformRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  18109. static const char* kwlist[] = {"seed", "dtype", "handle", "scope", NULL};
  18110. PyObject *seed = NULL, *dtype = NULL, *handle = NULL, *scope = NULL;
  18111. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &seed, &dtype, &handle, &scope))
  18112. return -1;
  18113. if (seed) {
  18114. try {
  18115. // TODO: remove this guard which is used for pybind11 implicit conversion
  18116. py::detail::loader_life_support guard{};
  18117. reinterpret_cast<PyOp(UniformRNG)*>(self)->inst().seed =
  18118. py::cast<decltype(UniformRNG::seed)>(py::handle(seed));
  18119. } CATCH_ALL(-1)
  18120. }
  18121. if (dtype) {
  18122. try {
  18123. // TODO: remove this guard which is used for pybind11 implicit conversion
  18124. py::detail::loader_life_support guard{};
  18125. reinterpret_cast<PyOp(UniformRNG)*>(self)->inst().dtype =
  18126. py::cast<decltype(UniformRNG::dtype)>(py::handle(dtype));
  18127. } CATCH_ALL(-1)
  18128. }
  18129. if (handle) {
  18130. try {
  18131. // TODO: remove this guard which is used for pybind11 implicit conversion
  18132. py::detail::loader_life_support guard{};
  18133. reinterpret_cast<PyOp(UniformRNG)*>(self)->inst().handle =
  18134. py::cast<decltype(UniformRNG::handle)>(py::handle(handle));
  18135. } CATCH_ALL(-1)
  18136. }
  18137. if (scope) {
  18138. try {
  18139. reinterpret_cast<PyOp(OpDef)*>(self)->op
  18140. ->set_scope(py::cast<std::string>(py::handle(scope)));
  18141. } CATCH_ALL(-1)
  18142. }
  18143. return 0;
  18144. }
  18145. PyGetSetDef PyOp(UniformRNG)::py_getsetters[] = {
  18146. {const_cast<char*>("seed"), py_get_generic(UniformRNG, seed), py_set_generic(UniformRNG, seed), const_cast<char*>("seed"), NULL},
  18147. {const_cast<char*>("dtype"), py_get_generic(UniformRNG, dtype), py_set_generic(UniformRNG, dtype), const_cast<char*>("dtype"), NULL},
  18148. {const_cast<char*>("handle"), py_get_generic(UniformRNG, handle), py_set_generic(UniformRNG, handle), const_cast<char*>("handle"), NULL},
  18149. {NULL} /* Sentinel */
  18150. };
  18151. PyMethodDef PyOp(UniformRNG)::tp_methods[] = {
  18152. {const_cast<char*>("__getstate__"), PyOp(UniformRNG)::getstate, METH_NOARGS, "UniformRNG getstate"},
  18153. {const_cast<char*>("__setstate__"), PyOp(UniformRNG)::setstate, METH_VARARGS, "UniformRNG setstate"},
  18154. {NULL} /* Sentinel */
  18155. };
  18156. PyObject *PyOp(UniformRNG)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  18157. if (PyOp(UniformRNG)::py_init(self, args, kwds) < 0) {
  18158. return NULL;
  18159. }
  18160. Py_RETURN_NONE;
  18161. }
  18162. PyMethodDef PyOp(UniformRNG)::py_init_methoddef = {
  18163. "__init__",
  18164. (PyCFunction)PyOp(UniformRNG)::py_init_proxy,
  18165. METH_VARARGS | METH_KEYWORDS,
  18166. "__init__(self, seed: int = ..., dtype: str = ..., handle: int = ...) -> None\n"
  18167. };
  18168. void _init_py_UniformRNG(py::module m) {
  18169. using py_op = PyOp(UniformRNG);
  18170. auto& py_type = PyOpType(UniformRNG);
  18171. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  18172. py_type.tp_name = "megengine.core._imperative_rt.ops.UniformRNG";
  18173. py_type.tp_basicsize = sizeof(PyOp(UniformRNG));
  18174. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  18175. py_type.tp_doc = "UniformRNG";
  18176. py_type.tp_base = &PyOpType(OpDef);
  18177. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  18178. py_type.tp_new = py_new_generic<py_op>;
  18179. py_type.tp_init = py_op::py_init;
  18180. py_type.tp_methods = py_op::tp_methods;
  18181. py_type.tp_getset = py_op::py_getsetters;
  18182. py_type.tp_dict = PyDict_New();
  18183. PyObject* descr = PyDescr_NewMethod(&PyOpType(UniformRNG), &PyOp(UniformRNG)::py_init_methoddef);
  18184. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  18185. mgb_assert(PyType_Ready(&py_type) >= 0);
  18186. PyType_Modified(&py_type);
  18187. m.add_object("UniformRNG", reinterpret_cast<PyObject*>(&py_type));
  18188. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(UniformRNG::typeinfo(), &py_type).second);
  18189. }
  18190. void _init_py_WarpAffine_InterpolationMode(PyTypeObject& py_type) {
  18191. auto& e_type = EnumWrapper<WarpAffine::InterpolationMode>::type;
  18192. Py_INCREF(e_type);
  18193. mgb_assert(PyDict_SetItemString(
  18194. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  18195. }
  18196. void _init_py_WarpAffine_BorderMode(PyTypeObject& py_type) {
  18197. auto& e_type = EnumWrapper<WarpAffine::BorderMode>::type;
  18198. Py_INCREF(e_type);
  18199. mgb_assert(PyDict_SetItemString(
  18200. py_type.tp_dict, "BorderMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  18201. }
  18202. void _init_py_WarpAffine_Format(PyTypeObject& py_type) {
  18203. auto& e_type = EnumWrapper<WarpAffine::Format>::type;
  18204. Py_INCREF(e_type);
  18205. mgb_assert(PyDict_SetItemString(
  18206. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  18207. }
  18208. PyOpDefBegin(WarpAffine) // {
  18209. static PyGetSetDef py_getsetters[];
  18210. static PyMethodDef tp_methods[];
  18211. static PyObject* getstate(PyObject* self, PyObject*) {
  18212. auto& opdef = reinterpret_cast<PyOp(WarpAffine)*>(self)->inst();
  18213. static_cast<void>(opdef);
  18214. std::unordered_map<std::string, py::object> state {
  18215. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  18216. {"border_mode", serialization<decltype(opdef.border_mode)>::dump(opdef.border_mode)},
  18217. {"border_val", serialization<decltype(opdef.border_val)>::dump(opdef.border_val)},
  18218. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)}
  18219. };
  18220. return py::cast(state).release().ptr();
  18221. }
  18222. static PyObject* setstate(PyObject* self, PyObject* args) {
  18223. PyObject* dict = PyTuple_GetItem(args, 0);
  18224. if (!dict) return NULL;
  18225. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  18226. auto& opdef = reinterpret_cast<PyOp(WarpAffine)*>(self)->inst();
  18227. static_cast<void>(opdef);
  18228. {
  18229. auto&& iter = state.find("imode");
  18230. if (iter != state.end()) {
  18231. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  18232. }
  18233. }
  18234. {
  18235. auto&& iter = state.find("border_mode");
  18236. if (iter != state.end()) {
  18237. opdef.border_mode = serialization<decltype(opdef.border_mode)>::load(iter->second);
  18238. }
  18239. }
  18240. {
  18241. auto&& iter = state.find("border_val");
  18242. if (iter != state.end()) {
  18243. opdef.border_val = serialization<decltype(opdef.border_val)>::load(iter->second);
  18244. }
  18245. }
  18246. {
  18247. auto&& iter = state.find("format");
  18248. if (iter != state.end()) {
  18249. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  18250. }
  18251. }
  18252. Py_RETURN_NONE;
  18253. }
  18254. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  18255. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  18256. static PyMethodDef py_init_methoddef;
  18257. // };
  18258. PyOpDefEnd(WarpAffine)
  18259. int PyOp(WarpAffine)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  18260. static const char* kwlist[] = {"imode", "border_mode", "border_val", "format", "scope", NULL};
  18261. PyObject *imode = NULL, *border_mode = NULL, *border_val = NULL, *format = NULL, *scope = NULL;
  18262. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &imode, &border_mode, &border_val, &format, &scope))
  18263. return -1;
  18264. if (imode) {
  18265. try {
  18266. // TODO: remove this guard which is used for pybind11 implicit conversion
  18267. py::detail::loader_life_support guard{};
  18268. reinterpret_cast<PyOp(WarpAffine)*>(self)->inst().imode =
  18269. py::cast<decltype(WarpAffine::imode)>(py::handle(imode));
  18270. } CATCH_ALL(-1)
  18271. }
  18272. if (border_mode) {
  18273. try {
  18274. // TODO: remove this guard which is used for pybind11 implicit conversion
  18275. py::detail::loader_life_support guard{};
  18276. reinterpret_cast<PyOp(WarpAffine)*>(self)->inst().border_mode =
  18277. py::cast<decltype(WarpAffine::border_mode)>(py::handle(border_mode));
  18278. } CATCH_ALL(-1)
  18279. }
  18280. if (border_val) {
  18281. try {
  18282. // TODO: remove this guard which is used for pybind11 implicit conversion
  18283. py::detail::loader_life_support guard{};
  18284. reinterpret_cast<PyOp(WarpAffine)*>(self)->inst().border_val =
  18285. py::cast<decltype(WarpAffine::border_val)>(py::handle(border_val));
  18286. } CATCH_ALL(-1)
  18287. }
  18288. if (format) {
  18289. try {
  18290. // TODO: remove this guard which is used for pybind11 implicit conversion
  18291. py::detail::loader_life_support guard{};
  18292. reinterpret_cast<PyOp(WarpAffine)*>(self)->inst().format =
  18293. py::cast<decltype(WarpAffine::format)>(py::handle(format));
  18294. } CATCH_ALL(-1)
  18295. }
  18296. if (scope) {
  18297. try {
  18298. reinterpret_cast<PyOp(OpDef)*>(self)->op
  18299. ->set_scope(py::cast<std::string>(py::handle(scope)));
  18300. } CATCH_ALL(-1)
  18301. }
  18302. return 0;
  18303. }
  18304. PyGetSetDef PyOp(WarpAffine)::py_getsetters[] = {
  18305. {const_cast<char*>("imode"), py_get_generic(WarpAffine, imode), py_set_generic(WarpAffine, imode), const_cast<char*>("imode"), NULL},
  18306. {const_cast<char*>("border_mode"), py_get_generic(WarpAffine, border_mode), py_set_generic(WarpAffine, border_mode), const_cast<char*>("border_mode"), NULL},
  18307. {const_cast<char*>("border_val"), py_get_generic(WarpAffine, border_val), py_set_generic(WarpAffine, border_val), const_cast<char*>("border_val"), NULL},
  18308. {const_cast<char*>("format"), py_get_generic(WarpAffine, format), py_set_generic(WarpAffine, format), const_cast<char*>("format"), NULL},
  18309. {NULL} /* Sentinel */
  18310. };
  18311. PyMethodDef PyOp(WarpAffine)::tp_methods[] = {
  18312. {const_cast<char*>("__getstate__"), PyOp(WarpAffine)::getstate, METH_NOARGS, "WarpAffine getstate"},
  18313. {const_cast<char*>("__setstate__"), PyOp(WarpAffine)::setstate, METH_VARARGS, "WarpAffine setstate"},
  18314. {NULL} /* Sentinel */
  18315. };
  18316. PyObject *PyOp(WarpAffine)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  18317. if (PyOp(WarpAffine)::py_init(self, args, kwds) < 0) {
  18318. return NULL;
  18319. }
  18320. Py_RETURN_NONE;
  18321. }
  18322. PyMethodDef PyOp(WarpAffine)::py_init_methoddef = {
  18323. "__init__",
  18324. (PyCFunction)PyOp(WarpAffine)::py_init_proxy,
  18325. METH_VARARGS | METH_KEYWORDS,
  18326. "__init__(self, imode: Union[str, InterpolationMode] = ..., border_mode: Union[str, BorderMode] = ..., border_val: float = ..., format: Union[str, Format] = ...) -> None\n"
  18327. };
  18328. void _init_py_WarpAffine(py::module m) {
  18329. using py_op = PyOp(WarpAffine);
  18330. auto& py_type = PyOpType(WarpAffine);
  18331. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  18332. py_type.tp_name = "megengine.core._imperative_rt.ops.WarpAffine";
  18333. py_type.tp_basicsize = sizeof(PyOp(WarpAffine));
  18334. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  18335. py_type.tp_doc = "WarpAffine";
  18336. py_type.tp_base = &PyOpType(OpDef);
  18337. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  18338. py_type.tp_new = py_new_generic<py_op>;
  18339. py_type.tp_init = py_op::py_init;
  18340. py_type.tp_methods = py_op::tp_methods;
  18341. py_type.tp_getset = py_op::py_getsetters;
  18342. py_type.tp_dict = PyDict_New();
  18343. PyObject* descr = PyDescr_NewMethod(&PyOpType(WarpAffine), &PyOp(WarpAffine)::py_init_methoddef);
  18344. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  18345. mgb_assert(PyType_Ready(&py_type) >= 0);
  18346. _init_py_WarpAffine_InterpolationMode(py_type);
  18347. _init_py_WarpAffine_BorderMode(py_type);
  18348. _init_py_WarpAffine_Format(py_type);
  18349. PyType_Modified(&py_type);
  18350. m.add_object("WarpAffine", reinterpret_cast<PyObject*>(&py_type));
  18351. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(WarpAffine::typeinfo(), &py_type).second);
  18352. }
  18353. void _init_py_WarpPerspective_InterpolationMode(PyTypeObject& py_type) {
  18354. auto& e_type = EnumWrapper<WarpPerspective::InterpolationMode>::type;
  18355. Py_INCREF(e_type);
  18356. mgb_assert(PyDict_SetItemString(
  18357. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  18358. }
  18359. void _init_py_WarpPerspective_BorderMode(PyTypeObject& py_type) {
  18360. auto& e_type = EnumWrapper<WarpPerspective::BorderMode>::type;
  18361. Py_INCREF(e_type);
  18362. mgb_assert(PyDict_SetItemString(
  18363. py_type.tp_dict, "BorderMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  18364. }
  18365. void _init_py_WarpPerspective_Format(PyTypeObject& py_type) {
  18366. auto& e_type = EnumWrapper<WarpPerspective::Format>::type;
  18367. Py_INCREF(e_type);
  18368. mgb_assert(PyDict_SetItemString(
  18369. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  18370. }
  18371. PyOpDefBegin(WarpPerspective) // {
  18372. static PyGetSetDef py_getsetters[];
  18373. static PyMethodDef tp_methods[];
  18374. static PyObject* getstate(PyObject* self, PyObject*) {
  18375. auto& opdef = reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst();
  18376. static_cast<void>(opdef);
  18377. std::unordered_map<std::string, py::object> state {
  18378. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  18379. {"bmode", serialization<decltype(opdef.bmode)>::dump(opdef.bmode)},
  18380. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  18381. {"border_val", serialization<decltype(opdef.border_val)>::dump(opdef.border_val)}
  18382. };
  18383. return py::cast(state).release().ptr();
  18384. }
  18385. static PyObject* setstate(PyObject* self, PyObject* args) {
  18386. PyObject* dict = PyTuple_GetItem(args, 0);
  18387. if (!dict) return NULL;
  18388. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  18389. auto& opdef = reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst();
  18390. static_cast<void>(opdef);
  18391. {
  18392. auto&& iter = state.find("imode");
  18393. if (iter != state.end()) {
  18394. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  18395. }
  18396. }
  18397. {
  18398. auto&& iter = state.find("bmode");
  18399. if (iter != state.end()) {
  18400. opdef.bmode = serialization<decltype(opdef.bmode)>::load(iter->second);
  18401. }
  18402. }
  18403. {
  18404. auto&& iter = state.find("format");
  18405. if (iter != state.end()) {
  18406. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  18407. }
  18408. }
  18409. {
  18410. auto&& iter = state.find("border_val");
  18411. if (iter != state.end()) {
  18412. opdef.border_val = serialization<decltype(opdef.border_val)>::load(iter->second);
  18413. }
  18414. }
  18415. Py_RETURN_NONE;
  18416. }
  18417. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  18418. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  18419. static PyMethodDef py_init_methoddef;
  18420. // };
  18421. PyOpDefEnd(WarpPerspective)
  18422. int PyOp(WarpPerspective)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  18423. static const char* kwlist[] = {"imode", "bmode", "format", "border_val", "scope", NULL};
  18424. PyObject *imode = NULL, *bmode = NULL, *format = NULL, *border_val = NULL, *scope = NULL;
  18425. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &imode, &bmode, &format, &border_val, &scope))
  18426. return -1;
  18427. if (imode) {
  18428. try {
  18429. // TODO: remove this guard which is used for pybind11 implicit conversion
  18430. py::detail::loader_life_support guard{};
  18431. reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst().imode =
  18432. py::cast<decltype(WarpPerspective::imode)>(py::handle(imode));
  18433. } CATCH_ALL(-1)
  18434. }
  18435. if (bmode) {
  18436. try {
  18437. // TODO: remove this guard which is used for pybind11 implicit conversion
  18438. py::detail::loader_life_support guard{};
  18439. reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst().bmode =
  18440. py::cast<decltype(WarpPerspective::bmode)>(py::handle(bmode));
  18441. } CATCH_ALL(-1)
  18442. }
  18443. if (format) {
  18444. try {
  18445. // TODO: remove this guard which is used for pybind11 implicit conversion
  18446. py::detail::loader_life_support guard{};
  18447. reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst().format =
  18448. py::cast<decltype(WarpPerspective::format)>(py::handle(format));
  18449. } CATCH_ALL(-1)
  18450. }
  18451. if (border_val) {
  18452. try {
  18453. // TODO: remove this guard which is used for pybind11 implicit conversion
  18454. py::detail::loader_life_support guard{};
  18455. reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst().border_val =
  18456. py::cast<decltype(WarpPerspective::border_val)>(py::handle(border_val));
  18457. } CATCH_ALL(-1)
  18458. }
  18459. if (scope) {
  18460. try {
  18461. reinterpret_cast<PyOp(OpDef)*>(self)->op
  18462. ->set_scope(py::cast<std::string>(py::handle(scope)));
  18463. } CATCH_ALL(-1)
  18464. }
  18465. return 0;
  18466. }
  18467. PyGetSetDef PyOp(WarpPerspective)::py_getsetters[] = {
  18468. {const_cast<char*>("imode"), py_get_generic(WarpPerspective, imode), py_set_generic(WarpPerspective, imode), const_cast<char*>("imode"), NULL},
  18469. {const_cast<char*>("bmode"), py_get_generic(WarpPerspective, bmode), py_set_generic(WarpPerspective, bmode), const_cast<char*>("bmode"), NULL},
  18470. {const_cast<char*>("format"), py_get_generic(WarpPerspective, format), py_set_generic(WarpPerspective, format), const_cast<char*>("format"), NULL},
  18471. {const_cast<char*>("border_val"), py_get_generic(WarpPerspective, border_val), py_set_generic(WarpPerspective, border_val), const_cast<char*>("border_val"), NULL},
  18472. {NULL} /* Sentinel */
  18473. };
  18474. PyMethodDef PyOp(WarpPerspective)::tp_methods[] = {
  18475. {const_cast<char*>("__getstate__"), PyOp(WarpPerspective)::getstate, METH_NOARGS, "WarpPerspective getstate"},
  18476. {const_cast<char*>("__setstate__"), PyOp(WarpPerspective)::setstate, METH_VARARGS, "WarpPerspective setstate"},
  18477. {NULL} /* Sentinel */
  18478. };
  18479. PyObject *PyOp(WarpPerspective)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  18480. if (PyOp(WarpPerspective)::py_init(self, args, kwds) < 0) {
  18481. return NULL;
  18482. }
  18483. Py_RETURN_NONE;
  18484. }
  18485. PyMethodDef PyOp(WarpPerspective)::py_init_methoddef = {
  18486. "__init__",
  18487. (PyCFunction)PyOp(WarpPerspective)::py_init_proxy,
  18488. METH_VARARGS | METH_KEYWORDS,
  18489. "__init__(self, imode: Union[str, InterpolationMode] = ..., bmode: Union[str, BorderMode] = ..., format: Union[str, Format] = ..., border_val: float = ...) -> None\n"
  18490. };
  18491. void _init_py_WarpPerspective(py::module m) {
  18492. using py_op = PyOp(WarpPerspective);
  18493. auto& py_type = PyOpType(WarpPerspective);
  18494. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  18495. py_type.tp_name = "megengine.core._imperative_rt.ops.WarpPerspective";
  18496. py_type.tp_basicsize = sizeof(PyOp(WarpPerspective));
  18497. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  18498. py_type.tp_doc = "WarpPerspective";
  18499. py_type.tp_base = &PyOpType(OpDef);
  18500. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  18501. py_type.tp_new = py_new_generic<py_op>;
  18502. py_type.tp_init = py_op::py_init;
  18503. py_type.tp_methods = py_op::tp_methods;
  18504. py_type.tp_getset = py_op::py_getsetters;
  18505. py_type.tp_dict = PyDict_New();
  18506. PyObject* descr = PyDescr_NewMethod(&PyOpType(WarpPerspective), &PyOp(WarpPerspective)::py_init_methoddef);
  18507. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  18508. mgb_assert(PyType_Ready(&py_type) >= 0);
  18509. _init_py_WarpPerspective_InterpolationMode(py_type);
  18510. _init_py_WarpPerspective_BorderMode(py_type);
  18511. _init_py_WarpPerspective_Format(py_type);
  18512. PyType_Modified(&py_type);
  18513. m.add_object("WarpPerspective", reinterpret_cast<PyObject*>(&py_type));
  18514. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(WarpPerspective::typeinfo(), &py_type).second);
  18515. }
  18516. void _init_py_WarpPerspectiveBackwardData_InterpolationMode(PyTypeObject& py_type) {
  18517. auto& e_type = EnumWrapper<WarpPerspectiveBackwardData::InterpolationMode>::type;
  18518. Py_INCREF(e_type);
  18519. mgb_assert(PyDict_SetItemString(
  18520. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  18521. }
  18522. void _init_py_WarpPerspectiveBackwardData_BorderMode(PyTypeObject& py_type) {
  18523. auto& e_type = EnumWrapper<WarpPerspectiveBackwardData::BorderMode>::type;
  18524. Py_INCREF(e_type);
  18525. mgb_assert(PyDict_SetItemString(
  18526. py_type.tp_dict, "BorderMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  18527. }
  18528. void _init_py_WarpPerspectiveBackwardData_Format(PyTypeObject& py_type) {
  18529. auto& e_type = EnumWrapper<WarpPerspectiveBackwardData::Format>::type;
  18530. Py_INCREF(e_type);
  18531. mgb_assert(PyDict_SetItemString(
  18532. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  18533. }
  18534. PyOpDefBegin(WarpPerspectiveBackwardData) // {
  18535. static PyGetSetDef py_getsetters[];
  18536. static PyMethodDef tp_methods[];
  18537. static PyObject* getstate(PyObject* self, PyObject*) {
  18538. auto& opdef = reinterpret_cast<PyOp(WarpPerspectiveBackwardData)*>(self)->inst();
  18539. static_cast<void>(opdef);
  18540. std::unordered_map<std::string, py::object> state {
  18541. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  18542. {"bmode", serialization<decltype(opdef.bmode)>::dump(opdef.bmode)},
  18543. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  18544. {"border_val", serialization<decltype(opdef.border_val)>::dump(opdef.border_val)}
  18545. };
  18546. return py::cast(state).release().ptr();
  18547. }
  18548. static PyObject* setstate(PyObject* self, PyObject* args) {
  18549. PyObject* dict = PyTuple_GetItem(args, 0);
  18550. if (!dict) return NULL;
  18551. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  18552. auto& opdef = reinterpret_cast<PyOp(WarpPerspectiveBackwardData)*>(self)->inst();
  18553. static_cast<void>(opdef);
  18554. {
  18555. auto&& iter = state.find("imode");
  18556. if (iter != state.end()) {
  18557. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  18558. }
  18559. }
  18560. {
  18561. auto&& iter = state.find("bmode");
  18562. if (iter != state.end()) {
  18563. opdef.bmode = serialization<decltype(opdef.bmode)>::load(iter->second);
  18564. }
  18565. }
  18566. {
  18567. auto&& iter = state.find("format");
  18568. if (iter != state.end()) {
  18569. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  18570. }
  18571. }
  18572. {
  18573. auto&& iter = state.find("border_val");
  18574. if (iter != state.end()) {
  18575. opdef.border_val = serialization<decltype(opdef.border_val)>::load(iter->second);
  18576. }
  18577. }
  18578. Py_RETURN_NONE;
  18579. }
  18580. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  18581. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  18582. static PyMethodDef py_init_methoddef;
  18583. // };
  18584. PyOpDefEnd(WarpPerspectiveBackwardData)
  18585. int PyOp(WarpPerspectiveBackwardData)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  18586. static const char* kwlist[] = {"imode", "bmode", "format", "border_val", "scope", NULL};
  18587. PyObject *imode = NULL, *bmode = NULL, *format = NULL, *border_val = NULL, *scope = NULL;
  18588. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &imode, &bmode, &format, &border_val, &scope))
  18589. return -1;
  18590. if (imode) {
  18591. try {
  18592. // TODO: remove this guard which is used for pybind11 implicit conversion
  18593. py::detail::loader_life_support guard{};
  18594. reinterpret_cast<PyOp(WarpPerspectiveBackwardData)*>(self)->inst().imode =
  18595. py::cast<decltype(WarpPerspectiveBackwardData::imode)>(py::handle(imode));
  18596. } CATCH_ALL(-1)
  18597. }
  18598. if (bmode) {
  18599. try {
  18600. // TODO: remove this guard which is used for pybind11 implicit conversion
  18601. py::detail::loader_life_support guard{};
  18602. reinterpret_cast<PyOp(WarpPerspectiveBackwardData)*>(self)->inst().bmode =
  18603. py::cast<decltype(WarpPerspectiveBackwardData::bmode)>(py::handle(bmode));
  18604. } CATCH_ALL(-1)
  18605. }
  18606. if (format) {
  18607. try {
  18608. // TODO: remove this guard which is used for pybind11 implicit conversion
  18609. py::detail::loader_life_support guard{};
  18610. reinterpret_cast<PyOp(WarpPerspectiveBackwardData)*>(self)->inst().format =
  18611. py::cast<decltype(WarpPerspectiveBackwardData::format)>(py::handle(format));
  18612. } CATCH_ALL(-1)
  18613. }
  18614. if (border_val) {
  18615. try {
  18616. // TODO: remove this guard which is used for pybind11 implicit conversion
  18617. py::detail::loader_life_support guard{};
  18618. reinterpret_cast<PyOp(WarpPerspectiveBackwardData)*>(self)->inst().border_val =
  18619. py::cast<decltype(WarpPerspectiveBackwardData::border_val)>(py::handle(border_val));
  18620. } CATCH_ALL(-1)
  18621. }
  18622. if (scope) {
  18623. try {
  18624. reinterpret_cast<PyOp(OpDef)*>(self)->op
  18625. ->set_scope(py::cast<std::string>(py::handle(scope)));
  18626. } CATCH_ALL(-1)
  18627. }
  18628. return 0;
  18629. }
  18630. PyGetSetDef PyOp(WarpPerspectiveBackwardData)::py_getsetters[] = {
  18631. {const_cast<char*>("imode"), py_get_generic(WarpPerspectiveBackwardData, imode), py_set_generic(WarpPerspectiveBackwardData, imode), const_cast<char*>("imode"), NULL},
  18632. {const_cast<char*>("bmode"), py_get_generic(WarpPerspectiveBackwardData, bmode), py_set_generic(WarpPerspectiveBackwardData, bmode), const_cast<char*>("bmode"), NULL},
  18633. {const_cast<char*>("format"), py_get_generic(WarpPerspectiveBackwardData, format), py_set_generic(WarpPerspectiveBackwardData, format), const_cast<char*>("format"), NULL},
  18634. {const_cast<char*>("border_val"), py_get_generic(WarpPerspectiveBackwardData, border_val), py_set_generic(WarpPerspectiveBackwardData, border_val), const_cast<char*>("border_val"), NULL},
  18635. {NULL} /* Sentinel */
  18636. };
  18637. PyMethodDef PyOp(WarpPerspectiveBackwardData)::tp_methods[] = {
  18638. {const_cast<char*>("__getstate__"), PyOp(WarpPerspectiveBackwardData)::getstate, METH_NOARGS, "WarpPerspectiveBackwardData getstate"},
  18639. {const_cast<char*>("__setstate__"), PyOp(WarpPerspectiveBackwardData)::setstate, METH_VARARGS, "WarpPerspectiveBackwardData setstate"},
  18640. {NULL} /* Sentinel */
  18641. };
  18642. PyObject *PyOp(WarpPerspectiveBackwardData)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  18643. if (PyOp(WarpPerspectiveBackwardData)::py_init(self, args, kwds) < 0) {
  18644. return NULL;
  18645. }
  18646. Py_RETURN_NONE;
  18647. }
  18648. PyMethodDef PyOp(WarpPerspectiveBackwardData)::py_init_methoddef = {
  18649. "__init__",
  18650. (PyCFunction)PyOp(WarpPerspectiveBackwardData)::py_init_proxy,
  18651. METH_VARARGS | METH_KEYWORDS,
  18652. "__init__(self, imode: Union[str, InterpolationMode] = ..., bmode: Union[str, BorderMode] = ..., format: Union[str, Format] = ..., border_val: float = ...) -> None\n"
  18653. };
  18654. void _init_py_WarpPerspectiveBackwardData(py::module m) {
  18655. using py_op = PyOp(WarpPerspectiveBackwardData);
  18656. auto& py_type = PyOpType(WarpPerspectiveBackwardData);
  18657. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  18658. py_type.tp_name = "megengine.core._imperative_rt.ops.WarpPerspectiveBackwardData";
  18659. py_type.tp_basicsize = sizeof(PyOp(WarpPerspectiveBackwardData));
  18660. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  18661. py_type.tp_doc = "WarpPerspectiveBackwardData";
  18662. py_type.tp_base = &PyOpType(OpDef);
  18663. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  18664. py_type.tp_new = py_new_generic<py_op>;
  18665. py_type.tp_init = py_op::py_init;
  18666. py_type.tp_methods = py_op::tp_methods;
  18667. py_type.tp_getset = py_op::py_getsetters;
  18668. py_type.tp_dict = PyDict_New();
  18669. PyObject* descr = PyDescr_NewMethod(&PyOpType(WarpPerspectiveBackwardData), &PyOp(WarpPerspectiveBackwardData)::py_init_methoddef);
  18670. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  18671. mgb_assert(PyType_Ready(&py_type) >= 0);
  18672. _init_py_WarpPerspectiveBackwardData_InterpolationMode(py_type);
  18673. _init_py_WarpPerspectiveBackwardData_BorderMode(py_type);
  18674. _init_py_WarpPerspectiveBackwardData_Format(py_type);
  18675. PyType_Modified(&py_type);
  18676. m.add_object("WarpPerspectiveBackwardData", reinterpret_cast<PyObject*>(&py_type));
  18677. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(WarpPerspectiveBackwardData::typeinfo(), &py_type).second);
  18678. }
  18679. void _init_py_WarpPerspectiveBackwardMat_InterpolationMode(PyTypeObject& py_type) {
  18680. auto& e_type = EnumWrapper<WarpPerspectiveBackwardMat::InterpolationMode>::type;
  18681. Py_INCREF(e_type);
  18682. mgb_assert(PyDict_SetItemString(
  18683. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  18684. }
  18685. void _init_py_WarpPerspectiveBackwardMat_BorderMode(PyTypeObject& py_type) {
  18686. auto& e_type = EnumWrapper<WarpPerspectiveBackwardMat::BorderMode>::type;
  18687. Py_INCREF(e_type);
  18688. mgb_assert(PyDict_SetItemString(
  18689. py_type.tp_dict, "BorderMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  18690. }
  18691. void _init_py_WarpPerspectiveBackwardMat_Format(PyTypeObject& py_type) {
  18692. auto& e_type = EnumWrapper<WarpPerspectiveBackwardMat::Format>::type;
  18693. Py_INCREF(e_type);
  18694. mgb_assert(PyDict_SetItemString(
  18695. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  18696. }
  18697. PyOpDefBegin(WarpPerspectiveBackwardMat) // {
  18698. static PyGetSetDef py_getsetters[];
  18699. static PyMethodDef tp_methods[];
  18700. static PyObject* getstate(PyObject* self, PyObject*) {
  18701. auto& opdef = reinterpret_cast<PyOp(WarpPerspectiveBackwardMat)*>(self)->inst();
  18702. static_cast<void>(opdef);
  18703. std::unordered_map<std::string, py::object> state {
  18704. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  18705. {"bmode", serialization<decltype(opdef.bmode)>::dump(opdef.bmode)},
  18706. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  18707. {"border_val", serialization<decltype(opdef.border_val)>::dump(opdef.border_val)}
  18708. };
  18709. return py::cast(state).release().ptr();
  18710. }
  18711. static PyObject* setstate(PyObject* self, PyObject* args) {
  18712. PyObject* dict = PyTuple_GetItem(args, 0);
  18713. if (!dict) return NULL;
  18714. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  18715. auto& opdef = reinterpret_cast<PyOp(WarpPerspectiveBackwardMat)*>(self)->inst();
  18716. static_cast<void>(opdef);
  18717. {
  18718. auto&& iter = state.find("imode");
  18719. if (iter != state.end()) {
  18720. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  18721. }
  18722. }
  18723. {
  18724. auto&& iter = state.find("bmode");
  18725. if (iter != state.end()) {
  18726. opdef.bmode = serialization<decltype(opdef.bmode)>::load(iter->second);
  18727. }
  18728. }
  18729. {
  18730. auto&& iter = state.find("format");
  18731. if (iter != state.end()) {
  18732. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  18733. }
  18734. }
  18735. {
  18736. auto&& iter = state.find("border_val");
  18737. if (iter != state.end()) {
  18738. opdef.border_val = serialization<decltype(opdef.border_val)>::load(iter->second);
  18739. }
  18740. }
  18741. Py_RETURN_NONE;
  18742. }
  18743. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  18744. static PyObject* py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds);
  18745. static PyMethodDef py_init_methoddef;
  18746. // };
  18747. PyOpDefEnd(WarpPerspectiveBackwardMat)
  18748. int PyOp(WarpPerspectiveBackwardMat)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  18749. static const char* kwlist[] = {"imode", "bmode", "format", "border_val", "scope", NULL};
  18750. PyObject *imode = NULL, *bmode = NULL, *format = NULL, *border_val = NULL, *scope = NULL;
  18751. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &imode, &bmode, &format, &border_val, &scope))
  18752. return -1;
  18753. if (imode) {
  18754. try {
  18755. // TODO: remove this guard which is used for pybind11 implicit conversion
  18756. py::detail::loader_life_support guard{};
  18757. reinterpret_cast<PyOp(WarpPerspectiveBackwardMat)*>(self)->inst().imode =
  18758. py::cast<decltype(WarpPerspectiveBackwardMat::imode)>(py::handle(imode));
  18759. } CATCH_ALL(-1)
  18760. }
  18761. if (bmode) {
  18762. try {
  18763. // TODO: remove this guard which is used for pybind11 implicit conversion
  18764. py::detail::loader_life_support guard{};
  18765. reinterpret_cast<PyOp(WarpPerspectiveBackwardMat)*>(self)->inst().bmode =
  18766. py::cast<decltype(WarpPerspectiveBackwardMat::bmode)>(py::handle(bmode));
  18767. } CATCH_ALL(-1)
  18768. }
  18769. if (format) {
  18770. try {
  18771. // TODO: remove this guard which is used for pybind11 implicit conversion
  18772. py::detail::loader_life_support guard{};
  18773. reinterpret_cast<PyOp(WarpPerspectiveBackwardMat)*>(self)->inst().format =
  18774. py::cast<decltype(WarpPerspectiveBackwardMat::format)>(py::handle(format));
  18775. } CATCH_ALL(-1)
  18776. }
  18777. if (border_val) {
  18778. try {
  18779. // TODO: remove this guard which is used for pybind11 implicit conversion
  18780. py::detail::loader_life_support guard{};
  18781. reinterpret_cast<PyOp(WarpPerspectiveBackwardMat)*>(self)->inst().border_val =
  18782. py::cast<decltype(WarpPerspectiveBackwardMat::border_val)>(py::handle(border_val));
  18783. } CATCH_ALL(-1)
  18784. }
  18785. if (scope) {
  18786. try {
  18787. reinterpret_cast<PyOp(OpDef)*>(self)->op
  18788. ->set_scope(py::cast<std::string>(py::handle(scope)));
  18789. } CATCH_ALL(-1)
  18790. }
  18791. return 0;
  18792. }
  18793. PyGetSetDef PyOp(WarpPerspectiveBackwardMat)::py_getsetters[] = {
  18794. {const_cast<char*>("imode"), py_get_generic(WarpPerspectiveBackwardMat, imode), py_set_generic(WarpPerspectiveBackwardMat, imode), const_cast<char*>("imode"), NULL},
  18795. {const_cast<char*>("bmode"), py_get_generic(WarpPerspectiveBackwardMat, bmode), py_set_generic(WarpPerspectiveBackwardMat, bmode), const_cast<char*>("bmode"), NULL},
  18796. {const_cast<char*>("format"), py_get_generic(WarpPerspectiveBackwardMat, format), py_set_generic(WarpPerspectiveBackwardMat, format), const_cast<char*>("format"), NULL},
  18797. {const_cast<char*>("border_val"), py_get_generic(WarpPerspectiveBackwardMat, border_val), py_set_generic(WarpPerspectiveBackwardMat, border_val), const_cast<char*>("border_val"), NULL},
  18798. {NULL} /* Sentinel */
  18799. };
  18800. PyMethodDef PyOp(WarpPerspectiveBackwardMat)::tp_methods[] = {
  18801. {const_cast<char*>("__getstate__"), PyOp(WarpPerspectiveBackwardMat)::getstate, METH_NOARGS, "WarpPerspectiveBackwardMat getstate"},
  18802. {const_cast<char*>("__setstate__"), PyOp(WarpPerspectiveBackwardMat)::setstate, METH_VARARGS, "WarpPerspectiveBackwardMat setstate"},
  18803. {NULL} /* Sentinel */
  18804. };
  18805. PyObject *PyOp(WarpPerspectiveBackwardMat)::py_init_proxy(PyObject *self, PyObject *args, PyObject *kwds) {
  18806. if (PyOp(WarpPerspectiveBackwardMat)::py_init(self, args, kwds) < 0) {
  18807. return NULL;
  18808. }
  18809. Py_RETURN_NONE;
  18810. }
  18811. PyMethodDef PyOp(WarpPerspectiveBackwardMat)::py_init_methoddef = {
  18812. "__init__",
  18813. (PyCFunction)PyOp(WarpPerspectiveBackwardMat)::py_init_proxy,
  18814. METH_VARARGS | METH_KEYWORDS,
  18815. "__init__(self, imode: Union[str, InterpolationMode] = ..., bmode: Union[str, BorderMode] = ..., format: Union[str, Format] = ..., border_val: float = ...) -> None\n"
  18816. };
  18817. void _init_py_WarpPerspectiveBackwardMat(py::module m) {
  18818. using py_op = PyOp(WarpPerspectiveBackwardMat);
  18819. auto& py_type = PyOpType(WarpPerspectiveBackwardMat);
  18820. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  18821. py_type.tp_name = "megengine.core._imperative_rt.ops.WarpPerspectiveBackwardMat";
  18822. py_type.tp_basicsize = sizeof(PyOp(WarpPerspectiveBackwardMat));
  18823. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  18824. py_type.tp_doc = "WarpPerspectiveBackwardMat";
  18825. py_type.tp_base = &PyOpType(OpDef);
  18826. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  18827. py_type.tp_new = py_new_generic<py_op>;
  18828. py_type.tp_init = py_op::py_init;
  18829. py_type.tp_methods = py_op::tp_methods;
  18830. py_type.tp_getset = py_op::py_getsetters;
  18831. py_type.tp_dict = PyDict_New();
  18832. PyObject* descr = PyDescr_NewMethod(&PyOpType(WarpPerspectiveBackwardMat), &PyOp(WarpPerspectiveBackwardMat)::py_init_methoddef);
  18833. PyDict_SetItemString(py_type.tp_dict, "__init__", descr);
  18834. mgb_assert(PyType_Ready(&py_type) >= 0);
  18835. _init_py_WarpPerspectiveBackwardMat_InterpolationMode(py_type);
  18836. _init_py_WarpPerspectiveBackwardMat_BorderMode(py_type);
  18837. _init_py_WarpPerspectiveBackwardMat_Format(py_type);
  18838. PyType_Modified(&py_type);
  18839. m.add_object("WarpPerspectiveBackwardMat", reinterpret_cast<PyObject*>(&py_type));
  18840. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(WarpPerspectiveBackwardMat::typeinfo(), &py_type).second);
  18841. }
  18842. #define INIT_ALL_OP(m) \
  18843. _init_py_AdaptivePooling(m); \
  18844. _init_py_AddAxis(m); \
  18845. _init_py_Argmax(m); \
  18846. _init_py_Argmin(m); \
  18847. _init_py_Argsort(m); \
  18848. _init_py_AssertEqual(m); \
  18849. _init_py_AtlasRuntime(m); \
  18850. _init_py_Barrier(m); \
  18851. _init_py_BatchConvBias(m); \
  18852. _init_py_BatchNorm(m); \
  18853. _init_py_BatchNormBackward(m); \
  18854. _init_py_BatchedIncrMeshIndexing(m); \
  18855. _init_py_BatchedMatrixMul(m); \
  18856. _init_py_BatchedMeshIndexing(m); \
  18857. _init_py_BatchedSetMeshIndexing(m); \
  18858. _init_py_BetaRNG(m); \
  18859. _init_py_Borrow(m); \
  18860. _init_py_Broadcast(m); \
  18861. _init_py_CambriconRuntime(m); \
  18862. _init_py_CheckNonFinite(m); \
  18863. _init_py_CollectiveComm(m); \
  18864. _init_py_Concat(m); \
  18865. _init_py_CondTake(m); \
  18866. _init_py_ConvBias(m); \
  18867. _init_py_Convolution(m); \
  18868. _init_py_Convolution3D(m); \
  18869. _init_py_Convolution3DBackwardData(m); \
  18870. _init_py_ConvolutionBackwardData(m); \
  18871. _init_py_Copy(m); \
  18872. _init_py_Correlation(m); \
  18873. _init_py_Cumsum(m); \
  18874. _init_py_CvtColor(m); \
  18875. _init_py_DeformableConv(m); \
  18876. _init_py_DeformablePSROIPooling(m); \
  18877. _init_py_Diag(m); \
  18878. _init_py_Dimshuffle(m); \
  18879. _init_py_Dot(m); \
  18880. _init_py_Dropout(m); \
  18881. _init_py_Elemwise(m); \
  18882. _init_py_ElemwiseMultiType(m); \
  18883. _init_py_ExternOpr(m); \
  18884. _init_py_Eye(m); \
  18885. _init_py_FakeQuant(m); \
  18886. _init_py_FastpathCopy(m); \
  18887. _init_py_GammaRNG(m); \
  18888. _init_py_GaussianRNG(m); \
  18889. _init_py_GetVarShape(m); \
  18890. _init_py_GroupLocal(m); \
  18891. _init_py_GroupNorm(m); \
  18892. _init_py_Identity(m); \
  18893. _init_py_Images2Neibs(m); \
  18894. _init_py_IncrMeshIndexing(m); \
  18895. _init_py_IncrSubtensor(m); \
  18896. _init_py_IndexingIncrMultiAxisVec(m); \
  18897. _init_py_IndexingMultiAxisVec(m); \
  18898. _init_py_IndexingOneHot(m); \
  18899. _init_py_IndexingSetMultiAxisVec(m); \
  18900. _init_py_IndexingSetOneHot(m); \
  18901. _init_py_InplaceAdd(m); \
  18902. _init_py_LAMBUpdate(m); \
  18903. _init_py_LRN(m); \
  18904. _init_py_LSQ(m); \
  18905. _init_py_LSTM(m); \
  18906. _init_py_LSTMCell(m); \
  18907. _init_py_LayerNorm(m); \
  18908. _init_py_Linspace(m); \
  18909. _init_py_MagicMindRuntime(m); \
  18910. _init_py_MatrixInverse(m); \
  18911. _init_py_MatrixMul(m); \
  18912. _init_py_MeshGrid(m); \
  18913. _init_py_MeshIndexing(m); \
  18914. _init_py_NMSKeep(m); \
  18915. _init_py_NvOf(m); \
  18916. _init_py_Padding(m); \
  18917. _init_py_ParamPackConcat(m); \
  18918. _init_py_ParamPackSplit(m); \
  18919. _init_py_PermutationRNG(m); \
  18920. _init_py_PixelShuffle(m); \
  18921. _init_py_PixelShuffleBackward(m); \
  18922. _init_py_PoissonRNG(m); \
  18923. _init_py_Pooling(m); \
  18924. _init_py_RNN(m); \
  18925. _init_py_RNNCell(m); \
  18926. _init_py_ROIAlign(m); \
  18927. _init_py_ROIPooling(m); \
  18928. _init_py_Reduce(m); \
  18929. _init_py_RegionRestrictedConvolution(m); \
  18930. _init_py_RegionRestrictedConvolutionBackwardData(m); \
  18931. _init_py_Remap(m); \
  18932. _init_py_RemoteRecv(m); \
  18933. _init_py_RemoteSend(m); \
  18934. _init_py_RemoveAxis(m); \
  18935. _init_py_Reshape(m); \
  18936. _init_py_Resize(m); \
  18937. _init_py_SVD(m); \
  18938. _init_py_SetMeshIndexing(m); \
  18939. _init_py_SetSubtensor(m); \
  18940. _init_py_ShuffleRNG(m); \
  18941. _init_py_SlidingWindowTranspose(m); \
  18942. _init_py_Softmax(m); \
  18943. _init_py_Split(m); \
  18944. _init_py_Subtensor(m); \
  18945. _init_py_TQT(m); \
  18946. _init_py_TensorRTRuntime(m); \
  18947. _init_py_TopK(m); \
  18948. _init_py_TypeCvt(m); \
  18949. _init_py_UniformRNG(m); \
  18950. _init_py_WarpAffine(m); \
  18951. _init_py_WarpPerspective(m); \
  18952. _init_py_WarpPerspectiveBackwardData(m); \
  18953. _init_py_WarpPerspectiveBackwardMat(m);
  18954. // clang-format on